diff --git a/src/86box.c b/src/86box.c index 97c211bee..246d06b16 100644 --- a/src/86box.c +++ b/src/86box.c @@ -11,6 +11,7 @@ * Authors: Sarah Walker, * Miran Grca, * Fred N. van Kempen, + * Jasmine Iwanek, * * Copyright 2008-2020 Sarah Walker. * Copyright 2016-2020 Miran Grca. @@ -18,7 +19,7 @@ * Copyright 2021 Laci bá' * Copyright 2021 dob205 * Copyright 2021 Andreas J. Reichel. - * Copyright 2021-2022 Jasmine Iwanek. + * Copyright 2021-2025 Jasmine Iwanek. */ #include #include @@ -178,6 +179,7 @@ int bugger_enabled = 0; /* (C) enable int novell_keycard_enabled = 0; /* (C) enable Novell NetWare 2.x key card emulation. */ int postcard_enabled = 0; /* (C) enable POST card */ int unittester_enabled = 0; /* (C) enable unit tester device */ +int gameport_type[GAMEPORT_MAX] = { 0, 0 }; /* (C) enable gameports */ int isamem_type[ISAMEM_MAX] = { 0, 0, 0, 0 }; /* (C) enable ISA mem cards */ int isartc_type = 0; /* (C) enable ISA RTC card */ int gfxcard[GFXCARD_MAX] = { 0, 0 }; /* (C) graphics/video card */ @@ -291,7 +293,7 @@ void pclog_ensure_stdlog_open(void) * being logged, and catch repeating entries. */ void -pclog_ex(const char *fmt, va_list ap) +pclog_ex(UNUSED(const char *fmt), UNUSED(va_list ap)) { #ifndef RELEASE_BUILD char temp[LOG_SIZE_BUFFER]; @@ -328,7 +330,7 @@ pclog_toggle_suppr(void) /* Log something. We only do this in non-release builds. */ void -pclog(const char *fmt, ...) +pclog(UNUSED(const char *fmt), ...) { #ifndef RELEASE_BUILD va_list ap; diff --git a/src/acpi.c b/src/acpi.c index 339ea7dcf..2850a340d 100644 --- a/src/acpi.c +++ b/src/acpi.c @@ -89,7 +89,7 @@ acpi_timer_get(acpi_t *dev) } static uint8_t -acpi_gp_timer_get(acpi_t *dev) +acpi_gp_timer_get(UNUSED(acpi_t *dev)) { uint64_t clock = acpi_clock_get(); clock -= acpi_last_clock; @@ -2576,7 +2576,7 @@ const device_t acpi_ali_device = { .init = acpi_init, .close = acpi_close, .reset = acpi_reset, - { .available = NULL }, + .available = NULL, .speed_changed = acpi_speed_changed, .force_redraw = NULL, .config = NULL @@ -2590,7 +2590,7 @@ const device_t acpi_intel_device = { .init = acpi_init, .close = acpi_close, .reset = acpi_reset, - { .available = NULL }, + .available = NULL, .speed_changed = acpi_speed_changed, .force_redraw = NULL, .config = NULL @@ -2604,7 +2604,7 @@ const device_t acpi_via_device = { .init = acpi_init, .close = acpi_close, .reset = acpi_reset, - { .available = NULL }, + .available = NULL, .speed_changed = acpi_speed_changed, .force_redraw = NULL, .config = NULL @@ -2618,7 +2618,7 @@ const device_t acpi_via_596b_device = { .init = acpi_init, .close = acpi_close, .reset = acpi_reset, - { .available = NULL }, + .available = NULL, .speed_changed = acpi_speed_changed, .force_redraw = NULL, .config = NULL @@ -2632,7 +2632,7 @@ const device_t acpi_smc_device = { .init = acpi_init, .close = acpi_close, .reset = acpi_reset, - { .available = NULL }, + .available = NULL, .speed_changed = acpi_speed_changed, .force_redraw = NULL, .config = NULL @@ -2646,7 +2646,7 @@ const device_t acpi_sis_5582_device = { .init = acpi_init, .close = acpi_close, .reset = acpi_reset, - { .available = NULL }, + .available = NULL, .speed_changed = acpi_speed_changed, .force_redraw = NULL, .config = NULL @@ -2660,7 +2660,7 @@ const device_t acpi_sis_5595_1997_device = { .init = acpi_init, .close = acpi_close, .reset = acpi_reset, - { .available = NULL }, + .available = NULL, .speed_changed = acpi_speed_changed, .force_redraw = NULL, .config = NULL @@ -2674,7 +2674,7 @@ const device_t acpi_sis_5595_device = { .init = acpi_init, .close = acpi_close, .reset = acpi_reset, - { .available = NULL }, + .available = NULL, .speed_changed = acpi_speed_changed, .force_redraw = NULL, .config = NULL diff --git a/src/apm.c b/src/apm.c index d7ce262a3..3973f2b23 100644 --- a/src/apm.c +++ b/src/apm.c @@ -122,7 +122,7 @@ const device_t apm_device = { .init = apm_init, .close = apm_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -136,7 +136,7 @@ const device_t apm_pci_device = { .init = apm_init, .close = apm_close, .reset = apm_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -150,7 +150,7 @@ const device_t apm_pci_acpi_device = { .init = apm_init, .close = apm_close, .reset = apm_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/cdrom/CMakeLists.txt b/src/cdrom/CMakeLists.txt index 2f0f1cd23..621b069b0 100644 --- a/src/cdrom/CMakeLists.txt +++ b/src/cdrom/CMakeLists.txt @@ -21,10 +21,8 @@ pkg_check_modules(SNDFILE REQUIRED IMPORTED_TARGET sndfile) add_library(cdrom OBJECT cdrom.c - cdrom_image_backend.c - cdrom_image_viso.c cdrom_image.c - cdrom_ioctl.c + cdrom_image_viso.c ) target_link_libraries(86Box PkgConfig::SNDFILE) diff --git a/src/cdrom/cdrom.c b/src/cdrom/cdrom.c index 6d993f24a..2cdcc5a22 100644 --- a/src/cdrom/cdrom.c +++ b/src/cdrom/cdrom.c @@ -15,105 +15,86 @@ * Copyright 2018-2021 Miran Grca. */ #include +#ifdef ENABLE_CDROM_LOG #include +#endif #include #include #include #include #include -#define HAVE_STDARG_H #include <86box/86box.h> #include <86box/device.h> #include <86box/config.h> #include <86box/cdrom.h> #include <86box/cdrom_image.h> #include <86box/cdrom_interface.h> -#include <86box/cdrom_mitsumi.h> +#include <86box/log.h> #include <86box/plat.h> +#include <86box/plat_cdrom_ioctl.h> #include <86box/scsi.h> #include <86box/scsi_device.h> +#include <86box/scsi_cdrom.h> #include <86box/sound.h> - -/* 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. */ -#undef MSFtoLBA -#define MSFtoLBA(m, s, f) ((((m * 60) + s) * 75) + f) +#include <86box/ui.h> #define RAW_SECTOR_SIZE 2352 -#define COOKED_SECTOR_SIZE 2048 #define MIN_SEEK 2000 #define MAX_SEEK 333333 -#pragma pack(push, 1) -typedef struct { - uint8_t user_data[2048], - ecc[288]; -} m1_data_t; - -typedef struct { - uint8_t sub_header[8], - user_data[2328]; -} m2_data_t; - -typedef union { - m1_data_t m1_data; - m2_data_t m2_data; - uint8_t raw_data[2336]; -} sector_data_t; - -typedef struct { - uint8_t sync[12]; - uint8_t header[4]; - sector_data_t data; -} sector_raw_data_t; - -typedef union { - sector_raw_data_t sector_data; - uint8_t raw_data[2352]; -} sector_t; - -typedef struct { - sector_t sector; - uint8_t c2[296]; - uint8_t subchannel_raw[96]; - uint8_t subchannel_q[16]; - uint8_t subchannel_rw[96]; -} cdrom_sector_t; - -typedef union { - cdrom_sector_t cdrom_sector; - uint8_t buffer[2856]; -} sector_buffer_t; -#pragma pack(pop) - -static int cdrom_sector_size; -static uint8_t raw_buffer[2856]; /* Needs to be the same size as sector_buffer_t in the structs. */ -static uint8_t extra_buffer[296]; - -cdrom_t cdrom[CDROM_NUM]; +cdrom_t cdrom[CDROM_NUM] = { 0 }; int cdrom_interface_current; #ifdef ENABLE_CDROM_LOG int cdrom_do_log = ENABLE_CDROM_LOG; -void -cdrom_log(const char *fmt, ...) +static void +cdrom_log(void *priv, const char *fmt, ...) { - va_list ap; - if (cdrom_do_log) { + va_list ap; va_start(ap, fmt); - pclog_ex(fmt, ap); + log_out(priv, fmt, ap); va_end(ap); } } #else -# define cdrom_log(fmt, ...) +# define cdrom_log(priv, fmt, ...) #endif +static void process_mode1(cdrom_t *dev, const int cdrom_sector_flags, + uint8_t *b); +static void process_mode2_non_xa(cdrom_t *dev, const int cdrom_sector_flags, + uint8_t *b); +static void process_mode2_xa_form1(cdrom_t *dev, const int cdrom_sector_flags, + uint8_t *b); +static void process_mode2_xa_form2(cdrom_t *dev, const int cdrom_sector_flags, + uint8_t *b); + +typedef void (*cdrom_process_data_t)(cdrom_t *dev, const int cdrom_sector_flags, + uint8_t *b); + +static cdrom_process_data_t cdrom_process_data[4] = { process_mode1, process_mode2_non_xa, + process_mode2_xa_form1, process_mode2_xa_form2 }; +#ifdef ENABLE_CDROM_LOG +static char * cdrom_req_modes[14] = { "Any", "Audio", "Mode 1", "Mode 2", + "CD-I/XA Mode 2 Form 1", "CD-I/XA Mode 2 Form 2", "Unk", "Unk", + "Any Data", "Any Data - 4", + "CD-I/XA Mode 2 Form 1", "CD-I/XA Mode 2 Form 1 - 4", + "Any CD-I/XA Data", "Any CD-I/XA Data - 4" }; +static char * cdrom_modes[4] = { "Mode 1", "Mode 2", "CD-I/XA Mode 2 Form 1", "CD-I/XA Mode 2 Form 2" }; +#endif +static uint8_t cdrom_mode_masks[14] = { 0x0f, 0x00, 0x01, 0x02, 0x04, 0x08, 0x00, 0x00, + 0x05, 0x05, 0x04, 0x04, 0x0c, 0x0c }; + +static uint8_t status_codes[2][8] = { { 0x13, 0x15, 0x15, 0x15, 0x12, 0x11, 0x13, 0x13 }, + { 0x00, 0x00, 0x00, 0x00, 0x15, 0x11, 0x00, 0x00 } }; +static int mult = 1; +static int part = 0; +static int ecc_diff = 288; + static const device_t cdrom_interface_none_device = { .name = "None", .internal_name = "none", @@ -137,146 +118,57 @@ static const struct { // clang-format on }; -/* Reset the CD-ROM Interface, whichever one that is. */ -void -cdrom_interface_reset(void) +/* Private functions. */ +static void +cdrom_generate_name(const int type, char *name, const int internal) { - cdrom_log("CD-ROM Interface: reset(current=%d)\n", - cdrom_interface_current); + char elements[3][2048] = { 0 }; - /* If we have a valid controller, add its device. */ - if ((cdrom_interface_current > 0) && controllers[cdrom_interface_current].device) - device_add(controllers[cdrom_interface_current].device); -} + memcpy(elements[0], cdrom_drive_types[type].vendor, + strlen(cdrom_drive_types[type].vendor) + 1); + if (internal) for (int i = 0; i < strlen(elements[0]); i++) + if (elements[0][i] == ' ') + elements[0][i] = '_'; -const char * -cdrom_interface_get_internal_name(int cdinterface) -{ - return device_get_internal_name(controllers[cdinterface].device); -} + if (internal) { + int j = 0; + for (int i = 0; i <= strlen(cdrom_drive_types[type].model); i++) + if (cdrom_drive_types[type].model[i] != ':') + elements[1][j++] = cdrom_drive_types[type].model[i]; + } else + memcpy(elements[1], cdrom_drive_types[type].model, + strlen(cdrom_drive_types[type].model) + 1); + char *s = strstr(elements[1], " "); + if (s != NULL) + s[0] = 0x00; + if (internal) for (int i = 0; i < strlen(elements[1]); i++) + if (elements[1][i] == ' ') + elements[1][i] = '_'; -int -cdrom_interface_get_from_internal_name(char *s) -{ - int c = 0; + memcpy(elements[2], cdrom_drive_types[type].revision, + strlen(cdrom_drive_types[type].revision) + 1); + s = strstr(elements[2], " "); + if (s != NULL) + s[0] = 0x00; + if (internal) for (int i = 0; i < strlen(elements[2]); i++) + if (elements[2][i] == ' ') + elements[2][i] = '_'; - while (controllers[c].device != NULL) { - if (!strcmp(controllers[c].device->internal_name, s)) - return c; - c++; - } - - return 0; -} - -const device_t * -cdrom_interface_get_device(int cdinterface) -{ - return (controllers[cdinterface].device); -} - -int -cdrom_interface_has_config(int cdinterface) -{ - const device_t *dev = cdrom_interface_get_device(cdinterface); - - if (dev == NULL) - return 0; - - if (!device_has_config(dev)) - return 0; - - return 1; -} - -int -cdrom_interface_get_flags(int cdinterface) -{ - return (controllers[cdinterface].device->flags); -} - -int -cdrom_interface_available(int cdinterface) -{ - return (device_available(controllers[cdinterface].device)); -} - -char * -cdrom_getname(int type) -{ - return (char *) cdrom_drive_types[type].name; -} - -char * -cdrom_get_internal_name(int type) -{ - return (char *) cdrom_drive_types[type].internal_name; -} - -int -cdrom_get_from_internal_name(char *s) -{ - int c = 0; - - while (strlen(cdrom_drive_types[c].internal_name)) { - if (!strcmp((char *) cdrom_drive_types[c].internal_name, s)) - return c; - c++; - } - - return 0; -} - -void -cdrom_set_type(int model, int type) -{ - cdrom[model].type = type; -} - -int -cdrom_get_type(int model) -{ - return cdrom[model].type; -} - -static __inline int -bin2bcd(int x) -{ - return (x % 10) | ((x / 10) << 4); -} - -static __inline int -bcd2bin(int x) -{ - return (x >> 4) * 10 + (x & 0x0f); -} - -int -cdrom_lba_to_msf_accurate(int lba) -{ - int pos; - int m; - int s; - int f; - - 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); + if (internal) + sprintf(name, "%s_%s_%s", elements[0], elements[1], elements[2]); + else if (cdrom_drive_types[type].speed == -1) + sprintf(name, "%s %s %s", elements[0], elements[1], elements[2]); + else + sprintf(name, "%s %s %s (%ix)", elements[0], elements[1], + elements[2], cdrom_drive_types[type].speed); } static double -cdrom_get_short_seek(cdrom_t *dev) +cdrom_get_short_seek(const cdrom_t *dev) { switch (dev->cur_speed) { case 0: - fatal("CD-ROM %i: 0x speed\n", dev->id); + log_fatal(dev->log, "0x speed\n"); return 0.0; case 1: return 240.0; @@ -324,11 +216,11 @@ cdrom_get_short_seek(cdrom_t *dev) } static double -cdrom_get_long_seek(cdrom_t *dev) +cdrom_get_long_seek(const cdrom_t *dev) { switch (dev->cur_speed) { case 0: - fatal("CD-ROM %i: 0x speed\n", dev->id); + log_fatal(dev->log, "0x speed\n"); return 0.0; case 1: return 1446.0; @@ -375,113 +267,6 @@ cdrom_get_long_seek(cdrom_t *dev) } } -double -cdrom_seek_time(cdrom_t *dev) -{ - uint32_t diff = dev->seek_diff; - double sd = (double) (MAX_SEEK - MIN_SEEK); - - if (diff < MIN_SEEK) - return 0.0; - if (diff > MAX_SEEK) - diff = MAX_SEEK; - - diff -= MIN_SEEK; - - return cdrom_get_short_seek(dev) + ((cdrom_get_long_seek(dev) * ((double) diff)) / sd); -} - -void -cdrom_stop(cdrom_t *dev) -{ - if (dev->cd_status > CD_STATUS_DATA_ONLY) - dev->cd_status = CD_STATUS_STOPPED; -} - -void -cdrom_seek(cdrom_t *dev, uint32_t pos, uint8_t vendor_type) -{ - int m; - int s; - int f; - - if (!dev) - return; - - cdrom_log("CD-ROM %i: Seek to LBA %08X, vendor type = %02x.\n", dev->id, pos, vendor_type); - - switch (vendor_type) { - case 0x40: - m = bcd2bin((pos >> 24) & 0xff); - s = bcd2bin((pos >> 16) & 0xff); - f = bcd2bin((pos >> 8) & 0xff); - pos = MSFtoLBA(m, s, f) - 150; - break; - case 0x80: - pos = bcd2bin((pos >> 24) & 0xff); - break; - default: - break; - } - - dev->seek_pos = pos; - cdrom_stop(dev); -} - -int -cdrom_is_pre(cdrom_t *dev, uint32_t lba) -{ - if (dev->ops && dev->ops->is_track_pre) - return dev->ops->is_track_pre(dev, lba); - - return 0; -} - -int -cdrom_audio_callback(cdrom_t *dev, int16_t *output, int len) -{ - int ret = 1; - - if (!dev->sound_on || (dev->cd_status != CD_STATUS_PLAYING) || dev->audio_muted_soft) { - // cdrom_log("CD-ROM %i: Audio callback while not playing\n", dev->id); - if (dev->cd_status == CD_STATUS_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 (dev->ops->read_sector(dev, (uint8_t *) &(dev->cd_buffer[dev->cd_buflen]), dev->seek_pos)) { - cdrom_log("CD-ROM %i: Read LBA %08X successful\n", dev->id, dev->seek_pos); - memcpy(dev->subch_buffer, ((uint8_t *) &(dev->cd_buffer[dev->cd_buflen])) + 2352, 96); - dev->seek_pos++; - dev->cd_buflen += (RAW_SECTOR_SIZE / 2); - ret = 1; - } else { - cdrom_log("CD-ROM %i: Read LBA %08X failed\n", dev->id, dev->seek_pos); - memset(&(dev->cd_buffer[dev->cd_buflen]), 0x00, (BUF_SIZE - dev->cd_buflen) * 2); - dev->cd_status = CD_STATUS_STOPPED; - dev->cd_buflen = len; - ret = 0; - } - } else { - cdrom_log("CD-ROM %i: Playing completed\n", dev->id); - memset(&dev->cd_buffer[dev->cd_buflen], 0x00, (BUF_SIZE - dev->cd_buflen) * 2); - dev->cd_status = CD_STATUS_PLAYING_COMPLETED; - dev->cd_buflen = len; - ret = 0; - } - } - - memcpy(output, dev->cd_buffer, len * 2); - memmove(dev->cd_buffer, &dev->cd_buffer[len], (BUF_SIZE - len) * 2); - dev->cd_buflen -= len; - - cdrom_log("CD-ROM %i: Audio callback returning %i\n", dev->id, ret); - return ret; -} - static void msf_from_bcd(int *m, int *s, int *f) { @@ -498,386 +283,1397 @@ msf_to_bcd(int *m, int *s, int *f) *f = bin2bcd(*f); } -uint8_t -cdrom_audio_play(cdrom_t *dev, uint32_t pos, uint32_t len, int ismsf) +static int +read_data(cdrom_t *dev, const uint32_t lba) { - track_info_t ti; - int m = 0; - int s = 0; - int f = 0; - - if (dev->cd_status == CD_STATUS_DATA_ONLY) - return 0; - - cdrom_log("CD-ROM %i: Play audio - %08X %08X %i\n", dev->id, pos, len, ismsf); - if (ismsf & 0x100) { - /* Track-relative audio play. */ - dev->ops->get_track_info(dev, ismsf & 0xff, 0, &ti); - pos += MSFtoLBA(ti.m, ti.s, ti.f) - 150; - } else if ((ismsf == 2) || (ismsf == 3)) { - dev->ops->get_track_info(dev, pos, 0, &ti); - pos = MSFtoLBA(ti.m, ti.s, ti.f) - 150; - if (ismsf == 2) { - /* We have to end at the *end* of the specified track, - not at the beginning. */ - dev->ops->get_track_info(dev, len, 1, &ti); - len = MSFtoLBA(ti.m, ti.s, ti.f) - 150; - } - } else if (ismsf == 1) { - m = (pos >> 16) & 0xff; - s = (pos >> 8) & 0xff; - f = pos & 0xff; - - /* NEC CDR-260 speaks BCD. */ - if ((dev->type == CDROM_TYPE_NEC_260_100) || (dev->type == CDROM_TYPE_NEC_260_101)) /*NEC*/ - msf_from_bcd(&m, &s, &f); - - if (pos == 0xffffff) { - cdrom_log("CD-ROM %i: Playing from current position (MSF)\n", dev->id); - pos = dev->seek_pos; - } else - pos = MSFtoLBA(m, s, f) - 150; - - m = (len >> 16) & 0xff; - s = (len >> 8) & 0xff; - f = len & 0xff; - - /* NEC CDR-260 speaks BCD. */ - if ((dev->type == CDROM_TYPE_NEC_260_100) || (dev->type == CDROM_TYPE_NEC_260_101)) /*NEC*/ - msf_from_bcd(&m, &s, &f); - - len = MSFtoLBA(m, s, f) - 150; - - cdrom_log("CD-ROM %i: MSF - pos = %08X len = %08X\n", dev->id, pos, len); - } else if (ismsf == 0) { - if (pos == 0xffffffff) { - cdrom_log("CD-ROM %i: Playing from current position\n", dev->id); - pos = dev->seek_pos; - } - len += pos; - } - - dev->audio_muted_soft = 0; - /* Do this at this point, since it's at this point that we know the - actual LBA position to start playing from. */ - if (!(dev->ops->track_type(dev, pos) & CD_TRACK_AUDIO)) { - cdrom_log("CD-ROM %i: LBA %08X not on an audio track\n", dev->id, pos); - cdrom_stop(dev); - return 0; - } - - dev->seek_pos = pos; - dev->cd_end = len; - dev->cd_status = CD_STATUS_PLAYING; - dev->cd_buflen = 0; - return 1; -} - -uint8_t -cdrom_audio_track_search(cdrom_t *dev, uint32_t pos, int type, uint8_t playbit) -{ - int m = 0; - int s = 0; - int f = 0; - uint32_t pos2 = 0; - - if (dev->cd_status == CD_STATUS_DATA_ONLY) - return 0; - - cdrom_log("Audio Track Search: MSF = %06x, type = %02x, playbit = %02x\n", pos, type, playbit); - switch (type) { - case 0x00: - if (pos == 0xffffffff) { - cdrom_log("CD-ROM %i: (type 0) Search from current position\n", dev->id); - pos = dev->seek_pos; - } - dev->seek_pos = pos; - break; - case 0x40: - m = bcd2bin((pos >> 24) & 0xff); - s = bcd2bin((pos >> 16) & 0xff); - f = bcd2bin((pos >> 8) & 0xff); - if (pos == 0xffffffff) { - cdrom_log("CD-ROM %i: (type 1) Search from current position\n", dev->id); - pos = dev->seek_pos; - } else - pos = MSFtoLBA(m, s, f) - 150; - - dev->seek_pos = pos; - break; - case 0x80: - if (pos == 0xffffffff) { - cdrom_log("CD-ROM %i: (type 2) Search from current position\n", dev->id); - pos = dev->seek_pos; - } - dev->seek_pos = (pos >> 24) & 0xff; - break; - default: - break; - } - - pos2 = pos - 1; - if (pos2 == 0xffffffff) - pos2 = pos + 1; - - /* Do this at this point, since it's at this point that we know the - actual LBA position to start playing from. */ - if (!(dev->ops->track_type(dev, pos2) & CD_TRACK_AUDIO)) { - cdrom_log("CD-ROM %i: Track Search: LBA %08X not on an audio track\n", dev->id, pos); - dev->audio_muted_soft = 1; - if (dev->ops->track_type(dev, pos) & CD_TRACK_AUDIO) - dev->audio_muted_soft = 0; - } else - dev->audio_muted_soft = 0; - - cdrom_log("Track Search Toshiba: Muted?=%d, LBA=%08X.\n", dev->audio_muted_soft, pos); - dev->cd_buflen = 0; - dev->cd_status = playbit ? CD_STATUS_PLAYING : CD_STATUS_PAUSED; - return 1; -} - -uint8_t -cdrom_audio_track_search_pioneer(cdrom_t *dev, uint32_t pos, uint8_t playbit) -{ - int m = 0; - int s = 0; - int f = 0; - - if (dev->cd_status == CD_STATUS_DATA_ONLY) - return 0; - - f = bcd2bin((pos >> 24) & 0xff); - s = bcd2bin((pos >> 16) & 0xff); - m = bcd2bin((pos >> 8) & 0xff); - if (pos == 0xffffffff) { - pos = dev->seek_pos; - } else - pos = MSFtoLBA(m, s, f) - 150; - - dev->seek_pos = pos; - - dev->audio_muted_soft = 0; - /* Do this at this point, since it's at this point that we know the - actual LBA position to start playing from. */ - if (!(dev->ops->track_type(dev, pos) & CD_TRACK_AUDIO)) { - cdrom_log("CD-ROM %i: LBA %08X not on an audio track\n", dev->id, pos); - cdrom_stop(dev); - return 0; - } - - dev->cd_buflen = 0; - dev->cd_status = playbit ? CD_STATUS_PLAYING : CD_STATUS_PAUSED; - return 1; -} - -uint8_t -cdrom_audio_play_pioneer(cdrom_t *dev, uint32_t pos) -{ - int m = 0; - int s = 0; - int f = 0; - - if (dev->cd_status == CD_STATUS_DATA_ONLY) - return 0; - - f = bcd2bin((pos >> 24) & 0xff); - s = bcd2bin((pos >> 16) & 0xff); - m = bcd2bin((pos >> 8) & 0xff); - pos = MSFtoLBA(m, s, f) - 150; - dev->cd_end = pos; - - dev->audio_muted_soft = 0; - dev->cd_buflen = 0; - dev->cd_status = CD_STATUS_PLAYING; - return 1; -} - -uint8_t -cdrom_audio_play_toshiba(cdrom_t *dev, uint32_t pos, int type) -{ - int m = 0; - int s = 0; - int f = 0; - - if (dev->cd_status == CD_STATUS_DATA_ONLY) - return 0; - - /*Preliminary support, revert if too incomplete*/ - switch (type) { - case 0x00: - dev->cd_end = pos; - break; - case 0x40: - m = bcd2bin((pos >> 24) & 0xff); - s = bcd2bin((pos >> 16) & 0xff); - f = bcd2bin((pos >> 8) & 0xff); - pos = MSFtoLBA(m, s, f) - 150; - dev->cd_end = pos; - break; - case 0x80: - dev->cd_end = (pos >> 24) & 0xff; - break; - case 0xc0: - if (pos == 0xffffffff) { - cdrom_log("CD-ROM %i: Playing from current position\n", dev->id); - pos = dev->cd_end; - } - dev->cd_end = pos; - break; - default: - break; - } - - cdrom_log("Toshiba Play Audio: Muted?=%d, LBA=%08X.\n", dev->audio_muted_soft, pos); - dev->cd_buflen = 0; - dev->cd_status = CD_STATUS_PLAYING; - return 1; -} - -uint8_t -cdrom_audio_scan(cdrom_t *dev, uint32_t pos, int type) -{ - int m = 0; - int s = 0; - int f = 0; - - if (dev->cd_status == CD_STATUS_DATA_ONLY) - return 0; - - cdrom_log("Audio Scan: MSF = %06x, type = %02x\n", pos, type); - switch (type) { - case 0x00: - if (pos == 0xffffffff) { - cdrom_log("CD-ROM %i: (type 0) Search from current position\n", dev->id); - pos = dev->seek_pos; - } - dev->seek_pos = pos; - break; - case 0x40: - m = bcd2bin((pos >> 24) & 0xff); - s = bcd2bin((pos >> 16) & 0xff); - f = bcd2bin((pos >> 8) & 0xff); - if (pos == 0xffffffff) { - cdrom_log("CD-ROM %i: (type 1) Search from current position\n", dev->id); - pos = dev->seek_pos; - } else - pos = MSFtoLBA(m, s, f) - 150; - - dev->seek_pos = pos; - break; - case 0x80: - dev->seek_pos = (pos >> 24) & 0xff; - break; - default: - break; - } - - dev->audio_muted_soft = 0; - /* Do this at this point, since it's at this point that we know the - actual LBA position to start playing from. */ - if (!(dev->ops->track_type(dev, pos) & CD_TRACK_AUDIO)) { - cdrom_log("CD-ROM %i: LBA %08X not on an audio track\n", dev->id, pos); - cdrom_stop(dev); - return 0; - } - - dev->cd_buflen = 0; - return 1; -} - -void -cdrom_audio_pause_resume(cdrom_t *dev, uint8_t resume) -{ - if ((dev->cd_status == CD_STATUS_PLAYING) || (dev->cd_status == CD_STATUS_PAUSED)) - dev->cd_status = (dev->cd_status & 0xfe) | (resume & 0x01); + return dev->ops->read_sector(dev->local, dev->raw_buffer, lba); } static void -cdrom_get_subchannel(cdrom_t *dev, uint32_t lba, subchannel_t *subc, int cooked) +cdrom_get_subchannel(cdrom_t *dev, const uint32_t lba, + subchannel_t *subc, const int cooked) { - uint8_t *scb = dev->subch_buffer; - uint8_t q[16] = { 0 }; + const uint8_t *scb; + uint32_t scb_offs = 0; + uint8_t q[16] = { 0 }; - if ((lba == dev->seek_pos) && (dev->cd_status == CD_STATUS_PLAYING)) { - for (int i = 0; i < 12; i++) - for (int j = 0; j < 8; j++) - q[i] |= ((scb[(i << 3) + j] >> 6) & 0x01) << (7 - j); + if ((lba == dev->seek_pos) && + ((dev->cd_status == CD_STATUS_PLAYING) || (dev->cd_status == CD_STATUS_PAUSED))) + scb = dev->subch_buffer; + else { + scb = (const uint8_t *) dev->raw_buffer; + scb_offs = 2352; - if (cooked) { - uint8_t temp = (q[0] >> 4) | ((q[0] & 0xf) << 4); - q[0] = temp; + memset(dev->raw_buffer, 0, 2448); - for (int i = 1; i < 10; i++) { - temp = bcd2bin(q[i]); - q[i] = temp; - } + (void) read_data(dev, lba); + } + + for (int i = 0; i < 12; i++) + for (int j = 0; j < 8; j++) + q[i] |= ((scb[scb_offs + (i << 3) + j] >> 6) & 0x01) << (7 - j); + + if (cooked) { + uint8_t temp = (q[0] >> 4) | ((q[0] & 0xf) << 4); + q[0] = temp; + + for (int i = 1; i < 10; i++) { + temp = bcd2bin(q[i]); + q[i] = temp; } + } - subc->attr = q[0]; - subc->track = q[1]; - subc->index = q[2]; - subc->rel_m = q[3]; - subc->rel_s = q[4]; - subc->rel_f = q[5]; - subc->abs_m = q[7]; - subc->abs_s = q[8]; - subc->abs_f = q[9]; - } else if ((dev->ops != NULL) && (dev->ops->get_subchannel != NULL)) { - dev->ops->get_subchannel(dev, lba, subc); + subc->attr = q[0]; + subc->track = q[1]; + subc->index = q[2]; + subc->rel_m = q[3]; + subc->rel_s = q[4]; + subc->rel_f = q[5]; + subc->abs_m = q[7]; + subc->abs_s = q[8]; + subc->abs_f = q[9]; +} - if (!cooked) { - uint8_t temp = (q[0] >> 4) | ((q[0] & 0xf) << 4); - q[0] = temp; +static void +read_toc_identify_sessions(const raw_track_info_t *rti, const int num, unsigned char *b) +{ + /* Bytes 2 and 3 = Number of first and last sessions */ + b[2] = 0xff; + b[3] = 0x00; - subc->attr = (subc->attr >> 4) | ((subc->attr & 0xf) << 4); - subc->track = bin2bcd(subc->track); - subc->index = bin2bcd(subc->index); - subc->rel_m = bin2bcd(subc->rel_m); - subc->rel_s = bin2bcd(subc->rel_s); - subc->rel_f = bin2bcd(subc->rel_f); - subc->abs_m = bin2bcd(subc->abs_m); - subc->abs_s = bin2bcd(subc->abs_s); - subc->abs_f = bin2bcd(subc->abs_f); - } + for (int i = (num - 1); i >= 0; i--) { + if (rti[i].session < b[2]) + b[2] = rti[i].session; + } + + for (int i = 0; i < num; i++) { + if (rti[i].session > b[3]) + b[3] = rti[i].session; } } -uint8_t -cdrom_get_current_status(cdrom_t *dev) +static int +find_track(const raw_track_info_t *trti, const int num, const int first) { - uint8_t ret; + int ret = -1; - if (dev->cd_status == CD_STATUS_DATA_ONLY) - ret = 0x15; - else { - if (dev->cd_status == CD_STATUS_PLAYING) - ret = 0x11; - else if (dev->cd_status == CD_STATUS_PAUSED) - ret = 0x12; + if (first) { + for (int i = 0; i < num; i++) + if ((trti[i].point >= 1) && (trti[i].point <= 99)) { + ret = i; + break; + } + } else { + for (int i = (num - 1); i >= 0; i--) + if ((trti[i].point >= 1) && (trti[i].point <= 99)) { + ret = i; + break; + } + } + + return ret; +} + +static int +find_last_lead_out(const raw_track_info_t *trti, const int num) +{ + int ret = -1; + + for (int i = (num - 1); i >= 0; i--) + if (trti[i].point == 0xa2) { + ret = i; + break; + } + + return ret; +} + +static int +find_specific_track(const raw_track_info_t *trti, const int num, const int track) +{ + int ret = -1; + + if ((track >= 1) && (track <= 99)) { + for (int i = (num - 1); i >= 0; i--) + if (trti[i].point == track) { + ret = i; + break; + } + } + + return ret; +} + +static int +read_toc_normal(const cdrom_t *dev, unsigned char *b, + const unsigned char start_track, const int msf, + const int sony) +{ + uint8_t rti[65536] = { 0 }; + uint8_t prti[65536] = { 0 }; + const raw_track_info_t *trti = (raw_track_info_t *) rti; + raw_track_info_t * tprti = (raw_track_info_t *) prti; + int num = 0; + int len = 4; + int t = -1; + + cdrom_log(dev->log, "read_toc_normal(%016" PRIXPTR ", %016" PRIXPTR ", %02X, %i)\n", + (uintptr_t) dev, (uintptr_t) b, start_track, msf, sony); + + dev->ops->get_raw_track_info(dev->local, &num, rti); + + if (num > 0) { + int j = 0; + for (int i = 0; i < num; i++) { + if ((trti[i].point >= 0x01) && (trti[i].point <= 0x63)) { + tprti[j] = trti[i]; + if ((t == -1) && (tprti[j].point >= start_track)) + t = j; + cdrom_log(dev->log, "Sorted %03i = Unsorted %03i\n", j, i); + j++; + } + } + + /* Bytes 2 and 3 = Number of first and last tracks found before lead out */ + b[2] = tprti[0].point; + b[3] = tprti[j - 1].point; + + for (int i = (num - 1); i >= 0; i--) { + if (trti[i].point == 0xa2) { + tprti[j] = trti[i]; + tprti[j].point = 0xaa; + if ((t == -1) && (tprti[j].point >= start_track)) + t = j; + cdrom_log(dev->log, "Sorted %03i = Unsorted %03i\n", j, i); + j++; + break; + } + } + + if (t != -1) for (int i = t; i < j; i++) { +#ifdef ENABLE_CDROM_LOG + uint8_t *c = &(b[len]); +#endif + + if (!sony) + b[len++] = 0; /* Reserved */ + b[len++] = tprti[i].adr_ctl; /* ADR/CTL */ + b[len++] = tprti[i].point; /* Track number */ + if (!sony) + b[len++] = 0; /* Reserved */ + + if (msf) { + b[len++] = 0; + + /* NEC CDR-260 speaks BCD. */ + if (dev->is_early) { + int m = tprti[i].pm; + int s = tprti[i].ps; + int f = tprti[i].pf; + msf_to_bcd(&m, &s, &f); + b[len++] = m; + b[len++] = s; + b[len++] = f; + } else { + b[len++] = tprti[i].pm; + b[len++] = tprti[i].ps; + b[len++] = tprti[i].pf; + } + } else { + const uint32_t temp = MSFtoLBA(tprti[i].pm, tprti[i].ps, + tprti[i].pf) - 150; + + b[len++] = temp >> 24; + b[len++] = temp >> 16; + b[len++] = temp >> 8; + b[len++] = temp; + } + +#ifdef ENABLE_CDROM_LOG + cdrom_log(dev->log, "Track %02X: %02X %02X %02X %02X %02X %02X %02X %02X\n", + i, c[0], c[1], c[2], c[3], c[4], c[5], c[6], c[7]); +#endif + } + } else + b[2] = b[3] = 0; + + return len; +} + +static int +read_toc_session(const cdrom_t *dev, unsigned char *b, const int msf) +{ + uint8_t rti[65536] = { 0 }; + const raw_track_info_t *t = (raw_track_info_t *) rti; + const raw_track_info_t *first = NULL; + int num = 0; + int len = 4; + + dev->ops->get_raw_track_info(dev->local, &num, rti); + + /* Bytes 2 and 3 = Number of first and last sessions */ + read_toc_identify_sessions((raw_track_info_t *) rti, num, b); + + cdrom_log(dev->log, "read_toc_session(%016" PRIXPTR ", %016" PRIXPTR ", %i)\n", + (uintptr_t) dev, (uintptr_t) b, msf); + + if (num != 0) { + for (int i = 0; i < num; i++) { + if ((t[i].session == b[3]) && (t[i].point >= 0x01) && (t[i].point <= 0x63)) { + first = &(t[i]); + break; + } + } + if (first != NULL) { + b[len++] = 0x00; + b[len++] = first->adr_ctl; + b[len++] = first->point; + b[len++] = 0x00; + + if (msf) { + b[len++] = 0x00; + + /* NEC CDR-260 speaks BCD. */ + if (dev->is_early) { + int m = first->pm; + int s = first->ps; + int f = first->pf; + + msf_to_bcd(&m, &s, &f); + + b[len++] = m; + b[len++] = s; + b[len++] = f; + } else { + b[len++] = first->pm; + b[len++] = first->ps; + b[len++] = first->pf; + } + } else { + const uint32_t temp = MSFtoLBA(first->pm, first->ps, + first->pf) - 150; + + b[len++] = temp >> 24; + b[len++] = temp >> 16; + b[len++] = temp >> 8; + b[len++] = temp; + } + } + } + + if (len == 4) + memset(&(b[len += 8]), 0x00, 8); + + return len; +} + +static int +read_toc_raw(const cdrom_t *dev, unsigned char *b, const unsigned char start_track) +{ + uint8_t rti[65536] = { 0 }; + const raw_track_info_t *t = (raw_track_info_t *) rti; + int num = 0; + int len = 4; + + /* Bytes 2 and 3 = Number of first and last sessions */ + read_toc_identify_sessions((raw_track_info_t *) rti, num, b); + + cdrom_log(dev->log, "read_toc_raw(%016" PRIXPTR ", %016" PRIXPTR ", %02X)\n", + (uintptr_t) dev, (uintptr_t) b, start_track); + + dev->ops->get_raw_track_info(dev->local, &num, rti); + + if (num != 0) for (int i = 0; i < num; i++) + if (t[i].session >= start_track) { + memcpy(&(b[len]), &(t[i]), 11); + len += 11; + } + + return len; +} + +static int +track_type_is_valid(UNUSED(const cdrom_t *dev), const int type, const int flags, const int audio, + const int mode2) +{ + if (!(flags & 0x70) && (flags & 0xf8)) { /* 0x08/0x80/0x88 are illegal modes */ + cdrom_log(dev->log, "[Any Mode] 0x08/0x80/0x88 are illegal modes\n"); + return 0; + } + + if ((type != 1) && !audio) { + if ((flags & 0x06) == 0x06) { + cdrom_log(dev->log, "[Any Data Mode] Invalid error flags\n"); + return 0; + } + + if (((flags & 0x700) == 0x300) || ((flags & 0x700) > 0x400)) { + cdrom_log(dev->log, "[Any Data Mode] Invalid subchannel data flags (%02X)\n", + flags & 0x700); + return 0; + } + + if ((flags & 0x18) == 0x08) { /* EDC/ECC without user data is an illegal mode */ + cdrom_log(dev->log, "[Any Data Mode] EDC/ECC without user data is an " + "illegal mode\n"); + return 0; + } + + if (((flags & 0xf0) == 0x90) || ((flags & 0xf0) == 0xc0)) { /* 0x90/0x98/0xC0/0xC8 are illegal modes */ + cdrom_log(dev->log, "[Any Data Mode] 0x90/0x98/0xC0/0xC8 are illegal modes\n"); + return 0; + } + + if (((type > 3) && (type != 8)) || (mode2 && (mode2 & 0x03))) { + if ((flags & 0xf0) == 0x30) { /* 0x30/0x38 are illegal modes */ + cdrom_log(dev->log, "[Any XA Mode 2] 0x30/0x38 are illegal modes\n"); + return 0; + } + if (((flags & 0xf0) == 0xb0) || ((flags & 0xf0) == 0xd0)) { /* 0xBx and 0xDx are illegal modes */ + cdrom_log(dev->log, "[Any XA Mode 2] 0xBx and 0xDx are illegal modes\n"); + return 0; + } + } + } + + return 1; +} + +static int +read_audio(cdrom_t *dev, const uint32_t lba, uint8_t *b) +{ + const int ret = dev->ops->read_sector(dev->local, dev->raw_buffer, lba); + + memcpy(b, dev->raw_buffer, 2352); + + dev->cdrom_sector_size = 2352; + + return ret; +} + + +static void +process_mode1(cdrom_t *dev, const int cdrom_sector_flags, uint8_t *b) +{ + dev->cdrom_sector_size = 0; + + if (cdrom_sector_flags & 0x80) { + /* Sync */ + cdrom_log(dev->log, "[Mode 1] Sync\n"); + memcpy(b, dev->raw_buffer, 12); + dev->cdrom_sector_size += 12; + b += 12; + } + + if (cdrom_sector_flags & 0x20) { + /* Header */ + cdrom_log(dev->log, "[Mode 1] Header\n"); + memcpy(b, dev->raw_buffer + 12, 4); + dev->cdrom_sector_size += 4; + b += 4; + } + + if (cdrom_sector_flags & 0x40) { + /* Sub-header */ + if (!(cdrom_sector_flags & 0x10)) { + /* No user data */ + cdrom_log(dev->log, "[Mode 1] Sub-header\n"); + memcpy(b, dev->raw_buffer + 16, 8); + dev->cdrom_sector_size += 8; + b += 8; + } + } + + if (cdrom_sector_flags & 0x10) { + /* User data */ + cdrom_log(dev->log, "[Mode 1] User data\n"); + if (mult > 1) { + memcpy(b, dev->raw_buffer + 16 + (part * dev->sector_size), + dev->sector_size); + dev->cdrom_sector_size += dev->sector_size; + b += dev->sector_size; + } else { + memcpy(b, dev->raw_buffer + 16, 2048); + dev->cdrom_sector_size += 2048; + b += 2048; + } + } + + if (cdrom_sector_flags & 0x08) { + /* EDC/ECC */ + cdrom_log(dev->log, "[Mode 1] EDC/ECC\n"); + memcpy(b, dev->raw_buffer + 2064, (288 - ecc_diff)); + dev->cdrom_sector_size += (288 - ecc_diff); + } +} + +static void +process_mode2_non_xa(cdrom_t *dev, const int cdrom_sector_flags, + uint8_t *b) +{ + dev->cdrom_sector_size = 0; + + if (cdrom_sector_flags & 0x80) { + /* Sync */ + cdrom_log(dev->log, "[Mode 2 Formless] Sync\n"); + memcpy(b, dev->raw_buffer, 12); + dev->cdrom_sector_size += 12; + b += 12; + } + + if (cdrom_sector_flags & 0x20) { + /* Header */ + cdrom_log(dev->log, "[Mode 2 Formless] Header\n"); + memcpy(b, dev->raw_buffer + 12, 4); + dev->cdrom_sector_size += 4; + b += 4; + } + + /* Mode 1 sector, expected type is 1 type. */ + if (cdrom_sector_flags & 0x40) { + /* Sub-header */ + cdrom_log(dev->log, "[Mode 2 Formless] Sub-header\n"); + memcpy(b, dev->raw_buffer + 16, 8); + dev->cdrom_sector_size += 8; + b += 8; + } + + if (cdrom_sector_flags & 0x10) { + /* User data */ + cdrom_log(dev->log, "[Mode 2 Formless] User data\n"); + memcpy(b, dev->raw_buffer + 24, (2336 - ecc_diff)); + dev->cdrom_sector_size += (2336 - ecc_diff); + } +} + +static void +process_mode2_xa_form1(cdrom_t *dev, const int cdrom_sector_flags, + uint8_t *b) +{ + dev->cdrom_sector_size = 0; + + if (cdrom_sector_flags & 0x80) { + /* Sync */ + cdrom_log(dev->log, "[XA Mode 2 Form 1] Sync\n"); + memcpy(b, dev->raw_buffer, 12); + dev->cdrom_sector_size += 12; + b += 12; + } + + if (cdrom_sector_flags & 0x20) { + /* Header */ + cdrom_log(dev->log, "[XA Mode 2 Form 1] Header\n"); + memcpy(b, dev->raw_buffer + 12, 4); + dev->cdrom_sector_size += 4; + b += 4; + } + + if (cdrom_sector_flags & 0x40) { + /* Sub-header */ + cdrom_log(dev->log, "[XA Mode 2 Form 1] Sub-header\n"); + memcpy(b, dev->raw_buffer + 16, 8); + dev->cdrom_sector_size += 8; + b += 8; + } + + if (cdrom_sector_flags & 0x10) { + /* User data */ + cdrom_log(dev->log, "[XA Mode 2 Form 1] User data\n"); + if (mult > 1) { + memcpy(b, dev->raw_buffer + 24 + (part * dev->sector_size), + dev->sector_size); + dev->cdrom_sector_size += dev->sector_size; + b += dev->sector_size; + } else { + memcpy(b, dev->raw_buffer + 24, 2048); + dev->cdrom_sector_size += 2048; + b += 2048; + } + } + + if (cdrom_sector_flags & 0x08) { + /* EDC/ECC */ + cdrom_log(dev->log, "[XA Mode 2 Form 1] EDC/ECC\n"); + memcpy(b, dev->raw_buffer + 2072, (280 - ecc_diff)); + dev->cdrom_sector_size += (280 - ecc_diff); + } +} + +static void +process_mode2_xa_form2(cdrom_t *dev, const int cdrom_sector_flags, + uint8_t *b) +{ + dev->cdrom_sector_size = 0; + + if (cdrom_sector_flags & 0x80) { + /* Sync */ + cdrom_log(dev->log, "[XA Mode 2 Form 2] Sync\n"); + memcpy(b, dev->raw_buffer, 12); + dev->cdrom_sector_size += 12; + b += 12; + } + + if (cdrom_sector_flags & 0x20) { + /* Header */ + cdrom_log(dev->log, "[XA Mode 2 Form 2] Header\n"); + memcpy(b, dev->raw_buffer + 12, 4); + dev->cdrom_sector_size += 4; + b += 4; + } + + if (cdrom_sector_flags & 0x40) { + /* Sub-header */ + cdrom_log(dev->log, "[XA Mode 2 Form 2] Sub-header\n"); + memcpy(b, dev->raw_buffer + 16, 8); + dev->cdrom_sector_size += 8; + b += 8; + } + + if (cdrom_sector_flags & 0x10) { + /* User data */ + cdrom_log(dev->log, "[XA Mode 2 Form 2] User data\n"); + memcpy(b, dev->raw_buffer + 24, (2328 - ecc_diff)); + dev->cdrom_sector_size += (2328 - ecc_diff); + } +} + +static void +process_ecc_and_subch(cdrom_t *dev, const int cdrom_sector_flags, + uint8_t *b) +{ + if ((cdrom_sector_flags & 0x06) == 0x02) { + /* Add error flags. */ + cdrom_log(dev->log, "Error flags\n"); + memcpy(b + dev->cdrom_sector_size, dev->extra_buffer, 294); + dev->cdrom_sector_size += 294; + } else if ((cdrom_sector_flags & 0x06) == 0x04) { + /* Add error flags. */ + cdrom_log(dev->log, "Full error flags\n"); + memcpy(b + dev->cdrom_sector_size, dev->extra_buffer, 296); + dev->cdrom_sector_size += 296; + } + + if ((cdrom_sector_flags & 0x700) == 0x100) { + cdrom_log(dev->log, "Raw subchannel data\n"); + memcpy(b + dev->cdrom_sector_size, dev->raw_buffer + 2352, 96); + dev->cdrom_sector_size += 96; + } else if ((cdrom_sector_flags & 0x700) == 0x200) { + cdrom_log(dev->log, "Q subchannel data\n"); + memcpy(b + dev->cdrom_sector_size, dev->raw_buffer + 2352, 16); + dev->cdrom_sector_size += 16; + } else if ((cdrom_sector_flags & 0x700) == 0x400) { + cdrom_log(dev->log, "R/W subchannel data\n"); + memcpy(b + dev->cdrom_sector_size, dev->raw_buffer + 2352, 96); + dev->cdrom_sector_size += 96; + } +} + +static void +cdrom_drive_reset(cdrom_t *dev) +{ + dev->priv = NULL; + dev->insert = NULL; + dev->close = NULL; + dev->get_volume = NULL; + dev->get_channel = NULL; + + if (cdrom_drive_types[dev->type].speed == -1) + dev->real_speed = dev->speed; + else + dev->real_speed = cdrom_drive_types[dev->type].speed; +} + +static void +cdrom_unload(cdrom_t *dev) +{ + if (dev->log != NULL) { + cdrom_log(dev->log, "CDROM: cdrom_unload(%s)\n", dev->image_path); + } + + dev->cd_status = CD_STATUS_EMPTY; + + if (dev->local != NULL) { + dev->ops->close(dev->local); + dev->local = NULL; + } + + dev->ops = NULL; +} + +/* Reset the CD-ROM Interface, whichever one that is. */ +void +cdrom_interface_reset(void) +{ + /* If we have a valid controller, add its device. */ + if ((cdrom_interface_current > 0) && + controllers[cdrom_interface_current].device) + device_add(controllers[cdrom_interface_current].device); +} + +const char * +cdrom_interface_get_internal_name(const int cdinterface) +{ + return device_get_internal_name(controllers[cdinterface].device); +} + +int +cdrom_interface_get_from_internal_name(const char *s) +{ + int c = 0; + + while (controllers[c].device != NULL) { + if (!strcmp(controllers[c].device->internal_name, s)) + return c; + c++; + } + + return 0; +} + +const device_t * +cdrom_interface_get_device(const int cdinterface) +{ + return (controllers[cdinterface].device); +} + +int +cdrom_interface_has_config(const int cdinterface) +{ + const device_t *dev = cdrom_interface_get_device(cdinterface); + + if (dev == NULL) + return 0; + + if (!device_has_config(dev)) + return 0; + + return 1; +} + +int +cdrom_interface_get_flags(const int cdinterface) +{ + return (controllers[cdinterface].device->flags); +} + +int +cdrom_interface_available(const int cdinterface) +{ + return (device_available(controllers[cdinterface].device)); +} + +char * +cdrom_get_vendor(const int type) +{ + return (char *) cdrom_drive_types[type].vendor; +} + +void +cdrom_get_model(const int type, char *name, const int id) +{ + if (!strcmp(cdrom_drive_types[type].vendor, EMU_NAME)) + sprintf(name, "%s%02i", cdrom_drive_types[type].model, id); + else + sprintf(name, "%s", cdrom_drive_types[type].model); +} + +char * +cdrom_get_revision(const int type) +{ + return (char *) cdrom_drive_types[type].revision; +} + +int +cdrom_get_scsi_std(const int type) +{ + return cdrom_drive_types[type].scsi_std; +} + +int +cdrom_is_early(const int type) +{ + return (cdrom_drive_types[type].scsi_std == 1); +} + +int +cdrom_is_generic(const int type) +{ + return (cdrom_drive_types[type].speed == -1); +} + +int +cdrom_has_date(const int type) +{ + /* This will do for now. */ + return !strcmp(cdrom_drive_types[type].vendor, "PIONEER"); +} + +int +cdrom_is_sony(const int type) +{ + /* This will do for now. */ + return (cdrom_drive_types[type].bus_type == BUS_TYPE_SCSI) && + (!strcmp(cdrom_drive_types[type].vendor, "DEC") || + !strcmp(cdrom_drive_types[type].vendor, "ShinaKen") || + !strcmp(cdrom_drive_types[type].vendor, "SONY") || + !strcmp(cdrom_drive_types[type].vendor, "TEXEL")); +} + +int +cdrom_is_caddy(const int type) +{ + return cdrom_drive_types[type].caddy; +} + +int +cdrom_get_speed(const int type) +{ + return cdrom_drive_types[type].speed; +} + +int +cdrom_get_inquiry_len(const int type) +{ + return cdrom_drive_types[type].inquiry_len; +} + +int +cdrom_get_transfer_max(const int type, const int mode) +{ + return cdrom_drive_types[type].transfer_max[mode]; +} + +int +cdrom_has_dma(const int type) +{ + return (cdrom_drive_types[type].transfer_max[2] != -1); +} + +int +cdrom_get_type_count(void) +{ + int count = 0; + + while (1) { + if (strlen(cdrom_drive_types[count].vendor) == 0) + break; else - ret = 0x13; + count++; + } + + return count; +} + +void +cdrom_get_identify_model(const int type, char *name, const int id) +{ + char elements[2][2048] = { 0 }; + + memcpy(elements[0], cdrom_drive_types[type].vendor, + strlen(cdrom_drive_types[type].vendor) + 1); + + memcpy(elements[1], cdrom_drive_types[type].model, + strlen(cdrom_drive_types[type].model) + 1); + + char *s = strstr(elements[1], " "); + + if (s != NULL) + s[0] = 0x00; + + if (!strcmp(cdrom_drive_types[type].vendor, EMU_NAME)) + sprintf(name, "%s%02i", elements[1], id); + else if (!strcmp(cdrom_drive_types[type].vendor, "ASUS")) + sprintf(name, "%s %s", elements[0], elements[1]); + else if (!strcmp(cdrom_drive_types[type].vendor, "NEC")) + sprintf(name, "%s %s", elements[0], elements[1]); + else if (!strcmp(cdrom_drive_types[type].vendor, "LITE-ON")) + sprintf(name, "%s", elements[1]); + else + sprintf(name, "%s %s", elements[0], elements[1]); +} + +void +cdrom_get_name(const int type, char *name) +{ + char n[2048] = { 0 }; + + cdrom_generate_name(type, n, 0); + + if (cdrom_drive_types[type].bus_type == BUS_TYPE_SCSI) + sprintf(name, "[SCSI-%i] %s", cdrom_drive_types[type].scsi_std, n); + else + sprintf(name, "%s", n); +} + +char * +cdrom_get_internal_name(const int type) +{ + return (char *) cdrom_drive_types[type].internal_name; +} + +int +cdrom_get_from_internal_name(const char *s) +{ + int c = 0; + int found = 0; + + while (strlen(cdrom_drive_types[c].internal_name) > 0) { + if (!strcmp((char *) cdrom_drive_types[c].internal_name, s)) { + found = 1; + break; + } + c++; + } + + if (!found) + c = -1; + + return c; +} + +/* TODO: Configuration migration, remove when no longer needed. */ +int +cdrom_get_from_name(const char *s) +{ + int c = 0; + int found = 0; + char n[2048] = { 0 }; + + if (strcmp(s, "none")) { + while (strlen(cdrom_drive_types[c].internal_name) > 0) { + memset(n, 0x00, 2048); + cdrom_generate_name(c, n, 1); + /* Special case some names. */ + if ((!strcmp(s, "86BOX_CD-ROM_1.00") && !strcmp(n, "86Box_86B_CD_3.50")) || + (!strcmp(s, "TEAC_CD_532E_2.0A") && !strcmp(n, "TEAC_CD-532E_2.0A")) || + !strcmp(n, s)) { + found = 1; + break; + } + c++; + } + } + + if (!found) { + if (strcmp(s, "none")) { + wchar_t tempmsg[2048]; + sprintf(n, "WARNING: CD-ROM \"%s\" not found - contact 86Box support\n", s); + swprintf(tempmsg, sizeof_w(tempmsg), L"%hs", n); + pclog(n); + ui_msgbox_header(MBX_INFO, + plat_get_string(STRING_HW_NOT_AVAILABLE_TITLE), + tempmsg); + } + c = -1; + } + + return c; +} + +void +cdrom_set_type(const int model, const int type) +{ + cdrom[model].type = type; +} + +int +cdrom_get_type(const int model) +{ + return cdrom[model].type; +} + +int +cdrom_lba_to_msf_accurate(const int lba) +{ + int pos = lba + 150; + const int f = pos % 75; + pos -= f; + pos /= 75; + const int s = pos % 60; + pos -= s; + pos /= 60; + const int m = pos; + + return ((m << 16) | (s << 8) | f); +} + +double +cdrom_seek_time(const cdrom_t *dev) +{ + uint32_t diff = dev->seek_diff; + const double sd = (double) (MAX_SEEK - MIN_SEEK); + + if (diff < MIN_SEEK) + return 0.0; + if (diff > MAX_SEEK) + diff = MAX_SEEK; + + diff -= MIN_SEEK; + + return cdrom_get_short_seek(dev) + + ((cdrom_get_long_seek(dev) * ((double) diff)) / sd); +} + +void +cdrom_stop(cdrom_t *dev) +{ + if (dev->cd_status > CD_STATUS_DVD) + dev->cd_status = CD_STATUS_STOPPED; +} + +void +cdrom_seek(cdrom_t *dev, const uint32_t pos, const uint8_t vendor_type) +{ + int m; + int s; + int f; + uint32_t real_pos = pos; + + if (dev == NULL) + return; + + cdrom_log(dev->log, "Seek to LBA %08X, vendor type = %02x.\n", pos, vendor_type); + + switch (vendor_type) { + case 0x40: + m = bcd2bin((pos >> 24) & 0xff); + s = bcd2bin((pos >> 16) & 0xff); + f = bcd2bin((pos >> 8) & 0xff); + real_pos = MSFtoLBA(m, s, f) - 150; + break; + case 0x80: + real_pos = bcd2bin((pos >> 24) & 0xff); + break; + default: + break; + } + + dev->seek_pos = real_pos; + cdrom_stop(dev); +} + +int +cdrom_is_pre(const cdrom_t *dev, const uint32_t lba) +{ + if (dev->ops && dev->ops->is_track_pre) + return dev->ops->is_track_pre(dev->local, lba); + + return 0; +} + +int +cdrom_audio_callback(cdrom_t *dev, int16_t *output, const int len) +{ + int ret = 1; + + if (!dev->sound_on || (dev->cd_status != CD_STATUS_PLAYING) || dev->audio_muted_soft) { + // cdrom_log(dev->log, "Audio callback while not playing\n"); + if (dev->cd_status == CD_STATUS_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 (dev->ops->read_sector(dev->local, + (uint8_t *) &(dev->cd_buffer[dev->cd_buflen]), dev->seek_pos)) { + cdrom_log(dev->log, "Read LBA %08X successful\n", dev->seek_pos); + memcpy(dev->subch_buffer, + ((uint8_t *) &(dev->cd_buffer[dev->cd_buflen])) + 2352, 96); + dev->seek_pos++; + dev->cd_buflen += (RAW_SECTOR_SIZE / 2); + ret = 1; + } else { + cdrom_log(dev->log, "Read LBA %08X failed\n", dev->seek_pos); + memset(&(dev->cd_buffer[dev->cd_buflen]), 0x00, + (BUF_SIZE - dev->cd_buflen) * 2); + dev->cd_status = CD_STATUS_STOPPED; + dev->cd_buflen = len; + ret = 0; + } + } else { + cdrom_log(dev->log, "Playing completed\n"); + memset(&dev->cd_buffer[dev->cd_buflen], 0x00, (BUF_SIZE - dev->cd_buflen) * 2); + dev->cd_status = CD_STATUS_PLAYING_COMPLETED; + dev->cd_buflen = len; + ret = 0; + } + } + + memcpy(output, dev->cd_buffer, len * 2); + memmove(dev->cd_buffer, &dev->cd_buffer[len], (BUF_SIZE - len) * 2); + dev->cd_buflen -= len; + + cdrom_log(dev->log, "Audio callback returning %i\n", ret); + return ret; +} + +uint8_t +cdrom_audio_play(cdrom_t *dev, const uint32_t pos, const uint32_t len, const int ismsf) +{ + track_info_t ti; + uint32_t pos2 = pos; + uint32_t len2 = len; + int ret = 0; + + if (dev->cd_status & CD_STATUS_HAS_AUDIO) { + cdrom_log(dev->log, "Play audio - %08X %08X %i\n", pos2, len, ismsf); + + if (ismsf & 0x100) { + /* Track-relative audio play. */ + ret = dev->ops->get_track_info(dev->local, ismsf & 0xff, 0, &ti); + if (ret) + pos2 += MSFtoLBA(ti.m, ti.s, ti.f) - 150; + else { + cdrom_log(dev->log, "Unable to get the starting position for " + "track %08X\n", ismsf & 0xff); + cdrom_stop(dev); + } + } else if ((ismsf == 2) || (ismsf == 3)) { + ret = dev->ops->get_track_info(dev->local, pos2, 0, &ti); + if (ret) { + pos2 = MSFtoLBA(ti.m, ti.s, ti.f) - 150; + if (ismsf == 2) { + /* We have to end at the *end* of the specified track, + not at the beginning. */ + ret = dev->ops->get_track_info(dev->local, len, 1, &ti); + if (ret) + len2 = MSFtoLBA(ti.m, ti.s, ti.f) - 150; + else { + cdrom_log(dev->log, "Unable to get the ending position for " + "track %08X\n", pos2); + cdrom_stop(dev); + } + } + } else { + cdrom_log(dev->log, "Unable to get the starting position for " + "track %08X\n", pos2); + cdrom_stop(dev); + } + } else if (ismsf == 1) { + int m = (pos >> 16) & 0xff; + int s = (pos >> 8) & 0xff; + int f = pos & 0xff; + + /* NEC CDR-260 speaks BCD. */ + if (dev->is_early) + msf_from_bcd(&m, &s, &f); + + if (pos == 0xffffff) { + cdrom_log(dev->log, "Playing from current position (MSF)\n"); + pos2 = dev->seek_pos; + } else + pos2 = MSFtoLBA(m, s, f) - 150; + + m = (len >> 16) & 0xff; + s = (len >> 8) & 0xff; + f = len & 0xff; + + /* NEC CDR-260 speaks BCD. */ + if (dev->is_early) + msf_from_bcd(&m, &s, &f); + + len2 = MSFtoLBA(m, s, f) - 150; + + ret = 1; + + cdrom_log(dev->log, "MSF - pos = %08X len = %08X\n", pos2, len); + } else if (ismsf == 0) { + if (pos == 0xffffffff) { + cdrom_log(dev->log, "Playing from current position\n"); + pos2 = dev->seek_pos; + } + len2 += pos2; + + ret = 1; + } + } + + if (ret) { + dev->audio_muted_soft = 0; + + /* + Do this at this point, since it's at this point that we know the + actual LBA position to start playing from. + */ + ret = (dev->ops->get_track_type(dev->local, pos2) == CD_TRACK_AUDIO); + + if (ret) { + dev->seek_pos = pos2; + dev->cd_end = len2; + dev->cd_status = CD_STATUS_PLAYING; + dev->cd_buflen = 0; + } else { + cdrom_log(dev->log, "LBA %08X not on an audio track\n", pos); + cdrom_stop(dev); + } + } + + return ret; +} + +uint8_t +cdrom_audio_track_search(cdrom_t *dev, const uint32_t pos, + const int type, const uint8_t playbit) +{ + uint32_t pos2 = pos; + uint8_t ret = 0; + + if (dev->cd_status & CD_STATUS_HAS_AUDIO) { + cdrom_log(dev->log, "Audio Track Search: MSF = %06x, type = %02x, " + "playbit = %02x\n", pos, type, playbit); + + switch (type) { + case 0x00: + if (pos == 0xffffffff) { + cdrom_log(dev->log, "(Type 0) Search from current position\n"); + pos2 = dev->seek_pos; + } + dev->seek_pos = pos2; + break; + case 0x40: { + const int m = bcd2bin((pos >> 24) & 0xff); + const int s = bcd2bin((pos >> 16) & 0xff); + const int f = bcd2bin((pos >> 8) & 0xff); + if (pos == 0xffffffff) { + cdrom_log(dev->log, "(Type 1) Search from current position\n"); + pos2 = dev->seek_pos; + } else + pos2 = MSFtoLBA(m, s, f) - 150; + + dev->seek_pos = pos2; + break; + } case 0x80: + if (pos == 0xffffffff) { + cdrom_log(dev->log, "(Type 2) Search from current position\n"); + pos2 = dev->seek_pos; + } + dev->seek_pos = (pos2 >> 24) & 0xff; + break; + default: + break; + } + + if (pos2 != 0x00000000) + pos2--; + + /* + Do this at this point, since it's at this point that we know the + actual LBA position to start playing from. + */ + if (dev->ops->get_track_type(dev->local, pos2) & CD_TRACK_AUDIO) + dev->audio_muted_soft = 0; + else { + cdrom_log(dev->log, "Track Search: LBA %08X not on an audio track\n", pos); + dev->audio_muted_soft = 1; + if (dev->ops->get_track_type(dev->local, pos) & CD_TRACK_AUDIO) + dev->audio_muted_soft = 0; + } + + cdrom_log(dev->log, "Track Search Toshiba: Muted?=%d, LBA=%08X.\n", + dev->audio_muted_soft, pos); + dev->cd_buflen = 0; + + dev->cd_status = playbit ? CD_STATUS_PLAYING : CD_STATUS_PAUSED; + + ret = 1; + } + + return ret; +} + +uint8_t +cdrom_audio_track_search_pioneer(cdrom_t *dev, const uint32_t pos, const uint8_t playbit) +{ + uint8_t ret = 0; + + if (dev->cd_status &= CD_STATUS_HAS_AUDIO) { + const int f = bcd2bin((pos >> 24) & 0xff); + const int s = bcd2bin((pos >> 16) & 0xff); + const int m = bcd2bin((pos >> 8) & 0xff); + uint32_t pos2; + + if (pos == 0xffffffff) + pos2 = dev->seek_pos; + else + pos2 = MSFtoLBA(m, s, f) - 150; + + dev->seek_pos = pos2; + + dev->audio_muted_soft = 0; + + /* + Do this at this point, since it's at this point that we know the + actual LBA position to start playing from. + */ + if (dev->ops->get_track_type(dev->local, pos2) & CD_TRACK_AUDIO) { + dev->cd_buflen = 0; + dev->cd_status = playbit ? CD_STATUS_PLAYING : CD_STATUS_PAUSED; + + ret = 1; + } else { + cdrom_log(dev->log, "LBA %08X not on an audio track\n", pos); + cdrom_stop(dev); + } + } + + return ret; +} + +uint8_t +cdrom_audio_play_pioneer(cdrom_t *dev, const uint32_t pos) +{ + uint8_t ret = 0; + + if (dev->cd_status & CD_STATUS_HAS_AUDIO) { + const int f = bcd2bin((pos >> 24) & 0xff); + const int s = bcd2bin((pos >> 16) & 0xff); + const int m = bcd2bin((pos >> 8) & 0xff); + uint32_t pos2 = MSFtoLBA(m, s, f) - 150; + dev->cd_end = pos2; + + dev->audio_muted_soft = 0; + dev->cd_buflen = 0; + + dev->cd_status = CD_STATUS_PLAYING; + + ret = 1; + } + + return ret; +} + +uint8_t +cdrom_audio_play_toshiba(cdrom_t *dev, const uint32_t pos, const int type) +{ + uint32_t pos2 = pos; + uint8_t ret = 0; + + if (dev->cd_status & CD_STATUS_HAS_AUDIO) { + /* Preliminary support, revert if too incomplete. */ + switch (type) { + case 0x00: + dev->cd_end = pos2; + break; + case 0x40: { + const int m = bcd2bin((pos >> 24) & 0xff); + const int s = bcd2bin((pos >> 16) & 0xff); + const int f = bcd2bin((pos >> 8) & 0xff); + pos2 = MSFtoLBA(m, s, f) - 150; + dev->cd_end = pos2; + break; + } case 0x80: + dev->cd_end = (pos2 >> 24) & 0xff; + break; + case 0xc0: + if (pos == 0xffffffff) { + cdrom_log(dev->log, "Playing from current position\n"); + pos2 = dev->cd_end; + } + dev->cd_end = pos2; + break; + default: + break; + } + + cdrom_log(dev->log, "Toshiba Play Audio: Muted?=%d, LBA=%08X.\n", + dev->audio_muted_soft, pos2); + dev->cd_buflen = 0; + + dev->cd_status = CD_STATUS_PLAYING; + + ret = 1; + } + + return ret; +} + +uint8_t +cdrom_audio_scan(cdrom_t *dev, const uint32_t pos, const int type) +{ + uint32_t pos2 = pos; + uint8_t ret = 0; + + if (dev->cd_status & CD_STATUS_HAS_AUDIO) { + cdrom_log(dev->log, "Audio Scan: MSF = %06x, type = %02x\n", pos, type); + + switch (type) { + case 0x00: + if (pos == 0xffffffff) { + cdrom_log(dev->log, "(Type 0) Search from current position\n"); + pos2 = dev->seek_pos; + } + dev->seek_pos = pos2; + break; + case 0x40: { + const int m = bcd2bin((pos >> 24) & 0xff); + const int s = bcd2bin((pos >> 16) & 0xff); + const int f = bcd2bin((pos >> 8) & 0xff); + if (pos == 0xffffffff) { + cdrom_log(dev->log, "(Type 1) Search from current position\n"); + pos2 = dev->seek_pos; + } else + pos2 = MSFtoLBA(m, s, f) - 150; + + dev->seek_pos = pos2; + break; + } case 0x80: + dev->seek_pos = (pos >> 24) & 0xff; + break; + default: + break; + } + + dev->audio_muted_soft = 0; + /* Do this at this point, since it's at this point that we know the + actual LBA position to start playing from. */ + if (dev->ops->get_track_type(dev->local, pos) & CD_TRACK_AUDIO) { + dev->cd_buflen = 0; + ret = 1; + } else { + cdrom_log(dev->log, "LBA %08X not on an audio track\n", pos); + cdrom_stop(dev); + } } return ret; } void -cdrom_get_current_subchannel(cdrom_t *dev, uint8_t *b, int msf) +cdrom_audio_pause_resume(cdrom_t *dev, const uint8_t resume) +{ + if ((dev->cd_status == CD_STATUS_PLAYING) || (dev->cd_status == CD_STATUS_PAUSED)) + dev->cd_status = (dev->cd_status & 0xfe) | (resume & 0x01); +} + +uint8_t +cdrom_get_current_status(const cdrom_t *dev) +{ + const uint8_t is_chinon = !strcmp(cdrom_drive_types[dev->type].vendor, "CHINON"); + const uint8_t ret = status_codes[is_chinon][dev->cd_status & CD_STATUS_MASK]; + + return ret; +} + +void +cdrom_get_current_subchannel(cdrom_t *dev, uint8_t *b, const int msf) { subchannel_t subc; - uint32_t dat; cdrom_get_subchannel(dev, dev->seek_pos, &subc, 1); - cdrom_log("CD-ROM %i: Returned subchannel absolute at %02i:%02i.%02i, " + cdrom_log(dev->log, "Returned subchannel absolute at %02i:%02i.%02i, " "relative at %02i:%02i.%02i, seek pos = %08x, cd_end = %08x.\n", - dev->id, subc.abs_m, subc.abs_s, subc.abs_f, subc.rel_m, subc.rel_s, subc.rel_f, + subc.abs_m, subc.abs_s, subc.abs_f, subc.rel_m, subc.rel_s, subc.rel_f, dev->seek_pos, dev->cd_end); /* Format code. */ switch (b[0]) { - /* Mode 0 = Q subchannel mode, first 16 bytes are indentical to mode 1 (current position), - the rest are stuff like ISRC etc., which can be all zeroes. */ + /* + Mode 0 = Q subchannel mode, first 16 bytes are indentical to mode 1 (current + position), the rest are stuff like ISRC etc., which can be all zeroes. + */ case 0x01: /* Current position. */ b[1] = subc.attr; @@ -888,8 +1684,7 @@ cdrom_get_current_subchannel(cdrom_t *dev, uint8_t *b, int msf) b[4] = b[8] = 0x00; /* NEC CDR-260 speaks BCD. */ - if ((dev->type == CDROM_TYPE_NEC_260_100) || (dev->type == CDROM_TYPE_NEC_260_101)) { - /* NEC */ + if (dev->is_early) { b[5] = bin2bcd(subc.abs_m); b[6] = bin2bcd(subc.abs_s); b[7] = bin2bcd(subc.abs_f); @@ -907,7 +1702,7 @@ cdrom_get_current_subchannel(cdrom_t *dev, uint8_t *b, int msf) b[11] = subc.rel_f; } } else { - dat = MSFtoLBA(subc.abs_m, subc.abs_s, subc.abs_f) - 150; + uint32_t dat = MSFtoLBA(subc.abs_m, subc.abs_s, subc.abs_f) - 150; b[4] = (dat >> 24) & 0xff; b[5] = (dat >> 16) & 0xff; b[6] = (dat >> 8) & 0xff; @@ -925,8 +1720,7 @@ cdrom_get_current_subchannel(cdrom_t *dev, uint8_t *b, int msf) memset(&(b[1]), 0x00, 19); memset(&(b[5]), 0x30, 13); /* NEC CDR-260 speaks BCD. */ - if ((dev->type == CDROM_TYPE_NEC_260_100) || (dev->type == CDROM_TYPE_NEC_260_101)) - /* NEC */ + if (dev->is_early) b[19] = bin2bcd(subc.abs_f); else b[19] = subc.abs_f; @@ -936,27 +1730,27 @@ cdrom_get_current_subchannel(cdrom_t *dev, uint8_t *b, int msf) memset(&(b[1]), 0x00, 19); memset(&(b[5]), 0x30, 12); /* NEC CDR-260 speaks BCD. */ - if ((dev->type == CDROM_TYPE_NEC_260_100) || (dev->type == CDROM_TYPE_NEC_260_101)) - /* NEC */ + if (dev->is_early) b[18] = bin2bcd(subc.abs_f); else b[18] = subc.abs_f; break; default: - cdrom_log("b[0] = %02X\n", b[0]); + cdrom_log(dev->log, "b[0] = %02X\n", b[0]); break; } } void -cdrom_get_current_subchannel_sony(cdrom_t *dev, uint8_t *b, int msf) +cdrom_get_current_subchannel_sony(cdrom_t *dev, uint8_t *b, const int msf) { subchannel_t subc; - uint32_t dat; cdrom_get_subchannel(dev, dev->seek_pos, &subc, 1); - cdrom_log("CD-ROM %i: Returned subchannel at %02i:%02i.%02i, seek pos = %08x, cd_end = %08x, msf = %x.\n", dev->id, subc.abs_m, subc.abs_s, subc.abs_f, dev->seek_pos, dev->cd_end, msf); + cdrom_log(dev->log, "Returned subchannel at %02i:%02i.%02i, seek pos = %08x, " + "cd_end = %08x, msf = %x.\n", + subc.abs_m, subc.abs_s, subc.abs_f, dev->seek_pos, dev->cd_end, msf); b[0] = subc.attr; b[1] = subc.track; @@ -970,7 +1764,7 @@ cdrom_get_current_subchannel_sony(cdrom_t *dev, uint8_t *b, int msf) b[7] = subc.abs_s; b[8] = subc.abs_f; } else { - dat = MSFtoLBA(subc.rel_m, subc.rel_s, subc.rel_f); + uint32_t dat = MSFtoLBA(subc.rel_m, subc.rel_s, subc.rel_f); b[3] = (dat >> 16) & 0xff; b[4] = (dat >> 8) & 0xff; b[5] = dat & 0xff; @@ -989,16 +1783,15 @@ cdrom_get_audio_status_pioneer(cdrom_t *dev, uint8_t *b) cdrom_get_subchannel(dev, dev->seek_pos, &subc, 0); - if (dev->cd_status == CD_STATUS_DATA_ONLY) - ret = 0x05; - else { + if (dev->cd_status & CD_STATUS_HAS_AUDIO) { if (dev->cd_status == CD_STATUS_PLAYING) ret = dev->sound_on ? 0x00 : 0x02; else if (dev->cd_status == CD_STATUS_PAUSED) ret = 0x01; else ret = 0x03; - } + } else + ret = 0x05; b[0] = 0; b[1] = subc.abs_m; @@ -1009,24 +1802,22 @@ cdrom_get_audio_status_pioneer(cdrom_t *dev, uint8_t *b) } uint8_t -cdrom_get_audio_status_sony(cdrom_t *dev, uint8_t *b, int msf) +cdrom_get_audio_status_sony(cdrom_t *dev, uint8_t *b, const int msf) { uint8_t ret; subchannel_t subc; - uint32_t dat; cdrom_get_subchannel(dev, dev->seek_pos, &subc, 1); - if (dev->cd_status == CD_STATUS_DATA_ONLY) - ret = 0x05; - else { + if (dev->cd_status & CD_STATUS_HAS_AUDIO) { if (dev->cd_status == CD_STATUS_PLAYING) ret = dev->sound_on ? 0x00 : 0x02; else if (dev->cd_status == CD_STATUS_PAUSED) ret = 0x01; else ret = 0x03; - } + } else + ret = 0x05; if (msf) { b[0] = 0; @@ -1034,7 +1825,7 @@ cdrom_get_audio_status_sony(cdrom_t *dev, uint8_t *b, int msf) b[2] = subc.abs_s; b[3] = subc.abs_f; } else { - dat = MSFtoLBA(subc.abs_m, subc.abs_s, subc.abs_f) - 150; + const uint32_t dat = MSFtoLBA(subc.abs_m, subc.abs_s, subc.abs_f) - 150; b[0] = (dat >> 24) & 0xff; b[1] = (dat >> 16) & 0xff; b[2] = (dat >> 8) & 0xff; @@ -1070,6 +1861,7 @@ cdrom_get_current_subcodeq_playstatus(cdrom_t *dev, uint8_t *b) cdrom_get_current_subcodeq(dev, b); if ((dev->cd_status == CD_STATUS_DATA_ONLY) || + (dev->cd_status == CD_STATUS_DVD) || (dev->cd_status == CD_STATUS_PLAYING_COMPLETED) || (dev->cd_status == CD_STATUS_STOPPED)) ret = 0x03; @@ -1077,268 +1869,17 @@ cdrom_get_current_subcodeq_playstatus(cdrom_t *dev, uint8_t *b) ret = (dev->cd_status == CD_STATUS_PLAYING) ? 0x00 : dev->audio_op; /*If a valid audio track is detected with audio on, unmute it.*/ - if (dev->ops->track_type(dev, dev->seek_pos) & CD_TRACK_AUDIO) + if (dev->ops->get_track_type(dev->local, dev->seek_pos) & CD_TRACK_AUDIO) dev->audio_muted_soft = 0; - cdrom_log("SubCodeQ: Play Status: Seek LBA=%08x, CDEND=%08x, mute=%d.\n", + cdrom_log(dev->log, "SubCodeQ: Play Status: Seek LBA=%08x, CDEND=%08x, mute=%d.\n", dev->seek_pos, dev->cd_end, dev->audio_muted_soft); return ret; } -static void -read_toc_identify_sessions(raw_track_info_t *rti, int num, unsigned char *b) -{ - /* Bytes 2 and 3 = Number of first and last sessions */ - b[2] = 0xff; - b[3] = 0x00; - - for (int i = (num - 1); i >= 0; i--) { - if (rti[i].session < b[2]) - b[2] = rti[i].session; - } - - for (int i = 0; i < num; i++) { - if (rti[i].session > b[3]) - b[3] = rti[i].session; - } -} - -static int -find_track(raw_track_info_t *trti, int num, int first) -{ - int ret = -1; - - if (first) { - for (int i = 0; i < num; i++) - if ((trti[i].point >= 1) && (trti[i].point <= 99)) { - ret = i; - break; - } - } else { - for (int i = (num - 1); i >= 0; i--) - if ((trti[i].point >= 1) && (trti[i].point <= 99)) { - ret = i; - break; - } - } - - return ret; -} - -static int -find_last_lead_out(raw_track_info_t *trti, int num) -{ - int ret = -1; - - for (int i = (num - 1); i >= 0; i--) - if (trti[i].point == 0xa2) { - ret = i; - break; - } - - return ret; -} - -static int -find_specific_track(raw_track_info_t *trti, int num, int track) -{ - int ret = -1; - - if ((track >= 1) && (track <= 99)) { - for (int i = (num - 1); i >= 0; i--) - if (trti[i].point == track) { - ret = i; - break; - } - } - - return ret; -} - -static int -read_toc_normal(cdrom_t *dev, unsigned char *b, unsigned char start_track, int msf, int sony) -{ - uint8_t rti[65536] = { 0 }; - uint8_t prti[65536] = { 0 }; - raw_track_info_t *trti = (raw_track_info_t *) rti; - raw_track_info_t *tprti = (raw_track_info_t *) prti; - int num = 0; - int len = 4; - int s = -1; - - cdrom_log("read_toc_normal(%016" PRIXPTR ", %016" PRIXPTR ", %02X, %i)\n", - (uintptr_t) dev, (uintptr_t) b, start_track, msf, sony); - - dev->ops->get_raw_track_info(dev, &num, (raw_track_info_t *) rti); - - if (num > 0) { - int j = 0; - for (int i = 0; i < num; i++) { - if ((trti[i].point >= 0x01) && (trti[i].point <= 0x63)) { - tprti[j] = trti[i]; - if ((s == -1) && (tprti[j].point >= start_track)) - s = j; - cdrom_log("Sorted %03i = Unsorted %03i (s = %03i)\n", j, i, s); - j++; - } - } - - /* Bytes 2 and 3 = Number of first and last tracks found before lead out */ - b[2] = tprti[0].point; - b[3] = tprti[j - 1].point; - - for (int i = (num - 1); i >= 0; i--) { - if (trti[i].point == 0xa2) { - tprti[j] = trti[i]; - tprti[j].point = 0xaa; - if ((s == -1) && (tprti[j].point >= start_track)) - s = j; - cdrom_log("Sorted %03i = Unsorted %03i (s = %03i)\n", j, i, s); - j++; - break; - } - } - - if (s != -1) for (int i = s; i < j; i++) { -#ifdef ENABLE_CDROM_LOG - uint8_t *c = &(b[len]); -#endif - - if (!sony) - b[len++] = 0; /* Reserved */ - b[len++] = tprti[i].adr_ctl; /* ADR/CTL */ - b[len++] = tprti[i].point; /* Track number */ - if (!sony) - b[len++] = 0; /* Reserved */ - - if (msf) { - b[len++] = 0; - - /* NEC CDR-260 speaks BCD. */ - if ((dev->type == CDROM_TYPE_NEC_260_100) || (dev->type == CDROM_TYPE_NEC_260_101)) { - int m = tprti[i].pm; - int s = tprti[i].ps; - int f = tprti[i].pf; - msf_to_bcd(&m, &s, &f); - b[len++] = m; - b[len++] = s; - b[len++] = f; - } else { - b[len++] = tprti[i].pm; - b[len++] = tprti[i].ps; - b[len++] = tprti[i].pf; - } - } else { - uint32_t temp = MSFtoLBA(tprti[i].pm, tprti[i].ps, tprti[i].pf) - 150; - - b[len++] = temp >> 24; - b[len++] = temp >> 16; - b[len++] = temp >> 8; - b[len++] = temp; - } - -#ifdef ENABLE_CDROM_LOG - cdrom_log("Track %02X: %02X %02X %02X %02X %02X %02X %02X %02X\n", - i, c[0], c[1], c[2], c[3], c[4], c[5], c[6], c[7]); -#endif - } - } else - b[2] = b[3] = 0; - - return len; -} - -static int -read_toc_session(cdrom_t *dev, unsigned char *b, int msf) -{ - uint8_t rti[65536] = { 0 }; - raw_track_info_t *t = (raw_track_info_t *) rti; - raw_track_info_t *first = NULL; - int num = 0; - int len = 4; - - dev->ops->get_raw_track_info(dev, &num, (raw_track_info_t *) rti); - - /* Bytes 2 and 3 = Number of first and last sessions */ - read_toc_identify_sessions((raw_track_info_t *) rti, num, b); - - cdrom_log("read_toc_session(%016" PRIXPTR ", %016" PRIXPTR ", %i)\n", - (uintptr_t) dev, (uintptr_t) b, msf); - - if (num != 0) { - for (int i = 0; i < num; i++) if ((t[i].session == b[3]) && (t[i].point >= 0x01) && (t[i].point <= 0x63)) { - first = &(t[i]); - break; - } - if (first != NULL) { - b[len++] = 0x00; - b[len++] = first->adr_ctl; - b[len++] = first->point; - b[len++] = 0x00; - - if (msf) { - b[len++] = 0x00; - - /* NEC CDR-260 speaks BCD. */ - if ((dev->type == CDROM_TYPE_NEC_260_100) || (dev->type == CDROM_TYPE_NEC_260_101)) { /*NEC*/ - int m = first->pm; - int s = first->ps; - int f = first->pf; - - msf_to_bcd(&m, &s, &f); - - b[len++] = m; - b[len++] = s; - b[len++] = f; - } else { - b[len++] = first->pm; - b[len++] = first->ps; - b[len++] = first->pf; - } - } else { - uint32_t temp = MSFtoLBA(first->pm, first->ps, first->pf) - 150; - - b[len++] = temp >> 24; - b[len++] = temp >> 16; - b[len++] = temp >> 8; - b[len++] = temp; - } - } - } - - if (len == 4) - memset(&(b[len += 8]), 0x00, 8); - - return len; -} - -static int -read_toc_raw(cdrom_t *dev, unsigned char *b, unsigned char start_track) -{ - uint8_t rti[65536] = { 0 }; - raw_track_info_t *t = (raw_track_info_t *) rti; - int num = 0; - int len = 4; - - /* Bytes 2 and 3 = Number of first and last sessions */ - read_toc_identify_sessions((raw_track_info_t *) rti, num, b); - - cdrom_log("read_toc_raw(%016" PRIXPTR ", %016" PRIXPTR ", %02X)\n", - (uintptr_t) dev, (uintptr_t) b, start_track); - - dev->ops->get_raw_track_info(dev, &num, (raw_track_info_t *) rti); - - if (num != 0) for (int i = 0; i < num; i++) - if (t[i].session >= start_track) { - memcpy(&(b[len]), &(t[i]), 11); - len += 11; - } - - return len; -} - int -cdrom_read_toc(cdrom_t *dev, unsigned char *b, int type, unsigned char start_track, int msf, int max_len) +cdrom_read_toc(const cdrom_t *dev, uint8_t *b, const int type, + const uint8_t start_track, const int msf, const int max_len) { int len; @@ -1353,7 +1894,7 @@ cdrom_read_toc(cdrom_t *dev, unsigned char *b, int type, unsigned char start_tra len = read_toc_raw(dev, b, start_track); break; default: - cdrom_log("CD-ROM %i: Unknown TOC read type: %i\n", dev->id, type); + cdrom_log(dev->log, "Unknown TOC read type: %i\n", type); return 0; } @@ -1366,11 +1907,10 @@ cdrom_read_toc(cdrom_t *dev, unsigned char *b, int type, unsigned char start_tra } int -cdrom_read_toc_sony(cdrom_t *dev, unsigned char *b, unsigned char start_track, int msf, int max_len) +cdrom_read_toc_sony(const cdrom_t *dev, uint8_t *b, const uint8_t start_track, + const int msf, const int max_len) { - int len; - - len = read_toc_normal(dev, b, start_track, msf, 1); + int len = read_toc_normal(dev, b, start_track, msf, 1); len = MIN(len, max_len); @@ -1392,7 +1932,7 @@ cdrom_get_track_buffer(cdrom_t *dev, uint8_t *buf) int last = -1; if (dev != NULL) - dev->ops->get_raw_track_info(dev, &num, (raw_track_info_t *) rti); + dev->ops->get_raw_track_info(dev->local, &num, rti); if (num > 0) { first = find_track(trti, num, 1); @@ -1428,7 +1968,7 @@ cdrom_get_track_buffer(cdrom_t *dev, uint8_t *buf) /* TODO: Actually implement this properly. */ void -cdrom_get_q(cdrom_t *dev, uint8_t *buf, int *curtoctrk, uint8_t mode) +cdrom_get_q(UNUSED(cdrom_t *dev), uint8_t *buf, UNUSED(int *curtoctrk), UNUSED(uint8_t mode)) { memset(buf, 0x00, 10); } @@ -1437,68 +1977,86 @@ uint8_t cdrom_mitsumi_audio_play(cdrom_t *dev, uint32_t pos, uint32_t len) { track_info_t ti; + int ret = 0; - if (dev->cd_status == CD_STATUS_DATA_ONLY) - return 0; + if (dev->cd_status & CD_STATUS_HAS_AUDIO) { + cdrom_log(dev->log, "Play Mitsumi audio - %08X %08X\n", pos, len); - cdrom_log("CD-ROM 0: Play Mitsumi audio - %08X %08X\n", pos, len); - dev->ops->get_track_info(dev, pos, 0, &ti); - pos = MSFtoLBA(ti.m, ti.s, ti.f) - 150; - dev->ops->get_track_info(dev, len, 1, &ti); - len = MSFtoLBA(ti.m, ti.s, ti.f) - 150; + ret = dev->ops->get_track_info(dev->local, pos, 0, &ti); - /* Do this at this point, since it's at this point that we know the - actual LBA position to start playing from. */ - if (!(dev->ops->track_type(dev, pos) & CD_TRACK_AUDIO)) { - cdrom_log("CD-ROM %i: LBA %08X not on an audio track\n", dev->id, pos); - cdrom_stop(dev); - return 0; + if (ret) { + pos = MSFtoLBA(ti.m, ti.s, ti.f) - 150; + ret = dev->ops->get_track_info(dev->local, len, 1, &ti); + + if (ret) { + len = MSFtoLBA(ti.m, ti.s, ti.f) - 150; + + /* + Do this at this point, since it's at this point that we know the + actual LBA position to start playing from. + */ + ret = (dev->ops->get_track_type(dev->local, pos) == CD_TRACK_AUDIO); + + if (ret) { + dev->seek_pos = pos; + dev->cd_end = len; + dev->cd_status = CD_STATUS_PLAYING; + dev->cd_buflen = 0; + } else { + cdrom_log(dev->log, "LBA %08X not on an audio track\n", pos); + cdrom_stop(dev); + } + } else { + cdrom_log(dev->log, "Unable to get the ending position for track %08X\n", + len); + cdrom_stop(dev); + } + } else { + cdrom_log(dev->log, "Unable to get the starting position for track %08X\n", pos); + cdrom_stop(dev); + } } - dev->seek_pos = pos; - dev->cd_end = len; - dev->cd_status = CD_STATUS_PLAYING; - dev->cd_buflen = 0; - - return 1; + return ret; } #endif uint8_t -cdrom_read_disc_info_toc(cdrom_t *dev, unsigned char *b, unsigned char track, int type) +cdrom_read_disc_info_toc(cdrom_t *dev, uint8_t *b, + const uint8_t track, const int type) { - uint8_t rti[65536] = { 0 }; - raw_track_info_t *trti = (raw_track_info_t *) rti; - int num = 0; - int first = -1; - int last = -1; - int t = -1; - uint32_t temp; - uint8_t ret = 1; + uint8_t rti[65536] = { 0 }; + const raw_track_info_t *trti = (raw_track_info_t *) rti; + int num = 0; + int first = -1; + int t = -1; + uint8_t ret = 1; + uint32_t temp; - if (dev != NULL) - dev->ops->get_raw_track_info(dev, &num, (raw_track_info_t *) rti); + cdrom_log(dev->log, "Read DISC Info TOC Type = %d, track = %d\n", type, track); - cdrom_log("Read DISC Info TOC Type = %d, track = %d\n", type, track); + dev->inv_field = track; + dev->ops->get_raw_track_info(dev->local, &num, rti); switch (type) { case 0: if (num > 0) { first = find_track(trti, num, 1); - last = find_track(trti, num, 0); - } + const int last = find_track(trti, num, 0); - if ((first == -1) || (last == -1)) + if ((first == -1) || (last == -1)) + ret = 0; + else { + b[0] = bin2bcd(first); + b[1] = bin2bcd(last); + b[2] = 0x00; + b[3] = 0x00; + + cdrom_log(dev->log, "Returned Toshiba/NEC disc information (type 0) " + "at %02i:%02i\n", b[0], b[1]); + } + } else ret = 0; - else { - b[0] = bin2bcd(first); - b[1] = bin2bcd(last); - b[2] = 0x00; - b[3] = 0x00; - - cdrom_log("CD-ROM %i: Returned Toshiba/NEC disc information (type 0) at %02i:%02i\n", - dev->id, b[0], b[1]); - } break; case 1: if (num > 0) @@ -1512,8 +2070,8 @@ cdrom_read_disc_info_toc(cdrom_t *dev, unsigned char *b, unsigned char track, in b[2] = bin2bcd(trti[t].pf); b[3] = 0x00; - cdrom_log("CD-ROM %i: Returned Toshiba/NEC disc information (type 1) at %02i:%02i.%02i\n", - dev->id, b[0], b[1], b[2]); + cdrom_log(dev->log, "Returned Toshiba/NEC disc information (type 1) at " + "%02i:%02i.%02i\n", b[0], b[1], b[2]); } break; case 2: @@ -1528,49 +2086,41 @@ cdrom_read_disc_info_toc(cdrom_t *dev, unsigned char *b, unsigned char track, in b[2] = bin2bcd(trti[t].pf); b[3] = trti[t].adr_ctl; - cdrom_log("CD-ROM %i: Returned Toshiba/NEC disc information (type 2) at " - "%02i:%02i.%02i, track=%d, attr=%02x.\n", dev->id, b[0], b[1], b[2], bcd2bin(track), b[3]); + cdrom_log(dev->log, "Returned Toshiba/NEC disc information (type 2) at " + "%02i:%02i.%02i, track=%d, attr=%02x.\n", b[0], b[1], + b[2], bcd2bin(track), b[3]); } break; case 3: /* Undocumented on NEC CD-ROM's, from information based on sr_vendor.c from the Linux kernel */ - switch (dev->type) { - case CDROM_TYPE_NEC_25_10a: - case CDROM_TYPE_NEC_38_103: - case CDROM_TYPE_NEC_75_103: - case CDROM_TYPE_NEC_77_106: - case CDROM_TYPE_NEC_211_100: - case CDROM_TYPE_NEC_464_105: - b[0x0e] = 0x00; + if (dev->is_nec) { + b[0x0e] = 0x00; - if (num > 0) - first = find_track(trti, num, 1); + if (num > 0) + first = find_track(trti, num, 1); - if (first == -1) - ret = 0; - else { - temp = MSFtoLBA(trti[first].pm, trti[first].ps, trti[first].pf) - 150; - b[0x0f] = temp >> 24; - b[0x10] = temp >> 16; - b[0x11] = temp >> 8; - b[0x12] = temp; - } - break; + if (first == -1) + ret = 0; + else { + temp = MSFtoLBA(trti[first].pm, trti[first].ps, trti[first].pf) - 150; + b[0x0f] = temp >> 24; + b[0x10] = temp >> 16; + b[0x11] = temp >> 8; + b[0x12] = temp; + } + } else { + b[0] = 0x00; /* Audio or CDROM disc. */ - default: - b[0] = 0x00; /* Audio or CDROM disc. */ + if (num > 0) + first = find_track(trti, num, 1); - if (num > 0) - first = find_track(trti, num, 1); - - if (first == -1) - ret = 0; - else { - temp = MSFtoLBA(trti[first].pm, trti[first].ps, trti[first].pf) - 150; - b[0x1] = temp >> 24; - b[0x2] = temp >> 16; - b[0x3] = temp >> 8; - } - break; + if (first == -1) + ret = 0; + else { + temp = MSFtoLBA(trti[first].pm, trti[first].ps, trti[first].pf) - 150; + b[0x1] = temp >> 24; + b[0x2] = temp >> 16; + b[0x3] = temp >> 8; + } } break; default: @@ -1580,462 +2130,531 @@ cdrom_read_disc_info_toc(cdrom_t *dev, unsigned char *b, unsigned char track, in return ret; } -static int -track_type_is_valid(UNUSED(uint8_t id), int type, int flags, int audio, int mode2) +int +cdrom_readsector_raw(cdrom_t *dev, uint8_t *buffer, const int sector, const int ismsf, + int cdrom_sector_type, const int cdrom_sector_flags, + int *len, const uint8_t vendor_type) { - if (!(flags & 0x70) && (flags & 0xf8)) { /* 0x08/0x80/0x88 are illegal modes */ - cdrom_log("CD-ROM %i: [Any Mode] 0x08/0x80/0x88 are illegal modes\n", id); - return 0; + int pos = sector; + int ret = 0; + + if ((cdrom_sector_type & 0x0f) >= 0x08) { + mult = cdrom_sector_type >> 4; + cdrom_sector_type &= 0x0f; + part = pos % mult; + pos /= mult; + ecc_diff = (cdrom_sector_type & 0x01) ? 4 : 0; + } else { + mult = 1; + part = 0; + ecc_diff = 0; } - if ((type != 1) && !audio) { - if ((flags & 0x06) == 0x06) { - cdrom_log("CD-ROM %i: [Any Data Mode] Invalid error flags\n", id); - return 0; - } + if (dev->cd_status != CD_STATUS_EMPTY) { + uint8_t *temp_b; + uint8_t *b = temp_b = buffer; + int audio = 0; + uint32_t lba; + int mode2 = 0; - if (((flags & 0x700) == 0x300) || ((flags & 0x700) > 0x400)) { - cdrom_log("CD-ROM %i: [Any Data Mode] Invalid subchannel data flags (%02X)\n", id, flags & 0x700); - return 0; - } + *len = 0; - if ((flags & 0x18) == 0x08) { /* EDC/ECC without user data is an illegal mode */ - cdrom_log("CD-ROM %i: [Any Data Mode] EDC/ECC without user data is an illegal mode\n", id); - return 0; - } + if (ismsf) { + const int m = (pos >> 16) & 0xff; + const int s = (pos >> 8) & 0xff; + const int f = pos & 0xff; - if (((flags & 0xf0) == 0x90) || ((flags & 0xf0) == 0xc0)) { /* 0x90/0x98/0xC0/0xC8 are illegal modes */ - cdrom_log("CD-ROM %i: [Any Data Mode] 0x90/0x98/0xC0/0xC8 are illegal modes\n", id); - return 0; - } + lba = MSFtoLBA(m, s, f) - 150; + } else { + switch (vendor_type) { + case 0x00: + lba = pos; + break; + case 0x40: { + const int m = bcd2bin((pos >> 24) & 0xff); + const int s = bcd2bin((pos >> 16) & 0xff); + const int f = bcd2bin((pos >> 8) & 0xff); - if (((type > 3) && (type != 8)) || (mode2 && (mode2 & 0x03))) { - if ((flags & 0xf0) == 0x30) { /* 0x30/0x38 are illegal modes */ - cdrom_log("CD-ROM %i: [Any XA Mode 2] 0x30/0x38 are illegal modes\n", id); - return 0; + lba = MSFtoLBA(m, s, f) - 150; + break; + } case 0x80: + lba = bcd2bin((pos >> 24) & 0xff); + break; + /* Never used values but the compiler complains. */ + default: + lba = 0; } - if (((flags & 0xf0) == 0xb0) || ((flags & 0xf0) == 0xd0)) { /* 0xBx and 0xDx are illegal modes */ - cdrom_log("CD-ROM %i: [Any XA Mode 2] 0xBx and 0xDx are illegal modes\n", id); - return 0; + } + + if (dev->ops->get_track_type) + audio = dev->ops->get_track_type(dev->local, lba); + + const int dm = audio & CD_TRACK_MODE_MASK; + audio &= CD_TRACK_AUDIO; + + if (dm != CD_TRACK_NORMAL) + mode2 = 1; + + memset(dev->raw_buffer, 0, 2448); + memset(dev->extra_buffer, 0, 296); + + if ((cdrom_sector_flags & 0xf8) == 0x08) { + /* 0x08 is an illegal mode */ + cdrom_log(dev->log, "[Mode 1] 0x08 is an illegal mode\n"); + } else if ((cdrom_sector_type > 5) && (cdrom_sector_type < 8)) { + cdrom_log(dev->log, "Attempting to read an unrecognized sector " + "type from an image\n"); + return 0; + } else { + if ((cdrom_sector_type > 1) && audio && + (dev->cd_status & CD_STATUS_HAS_AUDIO)) { + cdrom_log(dev->log, "[%s] Attempting to read a data sector " + "from an audio track\n", + cdrom_req_modes[cdrom_sector_type]); + } else if ((cdrom_sector_type == 1) && + (!audio || !(dev->cd_status & CD_STATUS_HAS_AUDIO))) { + cdrom_log(dev->log, "[Audio] Attempting to read an audio " + "sector from a data track\n"); + } else if (audio) { + if (!track_type_is_valid(dev, cdrom_sector_type, + cdrom_sector_flags, 1, 0x00)) + ret = 0; + else + ret = read_audio(dev, lba, temp_b); + } else { + ret = read_data(dev, lba); + + /* Return with error if we had one. */ + if (ret > 0) { + int form = 0; + + if ((dev->raw_buffer[0x000f] == 0x00) || + (dev->raw_buffer[0x000f] > 0x02)) { + cdrom_log(dev->log, "[%s] Unknown mode: %02X\n", + cdrom_req_modes[cdrom_sector_type], + dev->raw_buffer[0x000f]); + ret = 0; + } else if (mode2) { + if (dev->raw_buffer[0x000f] == 0x01) + /* + Use Mode 1, since evidently specification-violating + discs exist. + */ + mode2 = 0; + else if (dev->raw_buffer[0x0012] != + dev->raw_buffer[0x0016]) { + cdrom_log(dev->log, "[%s] XA Mode 2 sector with " + "malformed sub-header\n", + cdrom_req_modes[cdrom_sector_type]); + ret = 0; + } else + form = ((dev->raw_buffer[0x0012] & 0x20) >> 5) + 1; + } else if (dev->raw_buffer[0x000f] == 0x02) + mode2 = 1; + + if (ret > 0) { + const int mode_id = mode2 + form; + + cdrom_log(dev->log, "[%s] %s detected\n", + cdrom_req_modes[cdrom_sector_type], + cdrom_modes[mode_id]); + + if (!track_type_is_valid(dev, cdrom_sector_type, + cdrom_sector_flags, 0, + (mode2 << 2) + form)) { + cdrom_log(dev->log, "[%s] Invalid track type\n", + cdrom_req_modes[cdrom_sector_type]); + ret = 0; + } else if (cdrom_mode_masks[cdrom_sector_type] & + (1 << mode_id)) + cdrom_process_data[mode_id](dev, cdrom_sector_flags, + temp_b); + else { + cdrom_log(dev->log, "[%s] Attempting to read a " + "%s sector\n", + cdrom_req_modes[cdrom_sector_type], + cdrom_modes[mode_id]); + ret = 0; + } + } + } + } + + if (ret > 0) { + process_ecc_and_subch(dev, cdrom_sector_flags, b); + *len = dev->cdrom_sector_size; } } } - return 1; + return ret; } -static int -read_audio(cdrom_t *dev, uint32_t lba, uint8_t *b) +/* + Read DVD Structure + + Yes, +2 instead of +4 is correct, I have verified this via Windows IOCTL, and it also matches + the MMC specification. + */ +int +cdrom_read_dvd_structure(const cdrom_t *dev, const uint8_t layer, const uint8_t format, + uint8_t *buffer, uint32_t *info) { - int ret = dev->ops->read_sector(dev, raw_buffer, lba); + int max_layer = 0; + int ret = 0; + uint64_t total_sectors; - memcpy(b, raw_buffer, 2352); + if (format < 0xc0) { + if (dev->cd_status != CD_STATUS_DVD) { + *info = format; + ret = -(SENSE_ILLEGAL_REQUEST << 16) | (ASC_INCOMPATIBLE_FORMAT << 8); + } else if ((dev->ops != NULL) && (dev->ops->read_dvd_structure != NULL)) + ret = dev->ops->read_dvd_structure(dev->local, layer, format, buffer, info); + } - cdrom_sector_size = 2352; + if (ret == 0) switch (format) { + case 0x00: /* Physical format information */ + total_sectors = (uint64_t) dev->cdrom_capacity; + + if (total_sectors > DVD_LAYER_0_SECTORS) + max_layer++; + + if (layer > max_layer) { + *info = layer; + ret = -(SENSE_ILLEGAL_REQUEST << 16) | (ASC_INV_FIELD_IN_CMD_PACKET << 8); + } else { + if (total_sectors == 0) { + *info = 0x00000000; + ret = -(SENSE_NOT_READY << 16) | (ASC_MEDIUM_NOT_PRESENT << 8); + } else { + buffer[4] = 0x01; /* DVD-ROM, part version 1. */ + buffer[5] = 0x0f; /* 120mm disc, minimum rate unspecified .*/ + if (max_layer == 1) + /* Two layers, OTP track path, read-only (per MMC-2 spec). */ + buffer[6] = 0x31; + else + /* One layer, read-only (per MMC-2 spec). */ + buffer[6] = 0x01; + buffer[7] = 0x10; /* Default densities. */ + + /* Start sector. */ + buffer[8] = 0x00; + buffer[9] = (0x030000 >> 16) & 0xff; + buffer[10] = (0x030000 >> 8) & 0xff; + buffer[11] = 0x030000 & 0xff; + + /* End sector. */ + buffer[12] = 0x00; + if (layer == 1) { + buffer[13] = ((total_sectors - DVD_LAYER_0_SECTORS) >> 16) & 0xff; + buffer[14] = ((total_sectors - DVD_LAYER_0_SECTORS) >> 8) & 0xff; + buffer[15] = (total_sectors - DVD_LAYER_0_SECTORS) & 0xff; + } else if (max_layer == 1) { + buffer[13] = (DVD_LAYER_0_SECTORS >> 16) & 0xff; + buffer[14] = (DVD_LAYER_0_SECTORS >> 8) & 0xff; + buffer[15] = DVD_LAYER_0_SECTORS & 0xff; + } else { + buffer[13] = (total_sectors >> 16) & 0xff; + buffer[14] = (total_sectors >> 8) & 0xff; + buffer[15] = total_sectors & 0xff; + } + + /* Layer 0 end sector. */ + buffer[16] = 0x00; + buffer[17] = (total_sectors >> 16) & 0xff; + buffer[18] = (total_sectors >> 8) & 0xff; + buffer[19] = total_sectors & 0xff; + + buffer[20] = 0x00; /* No BCA */ + + /* 2048 bytes of data + 2 byte header */ + ret = (2048 + 2); + } + } + break; + + case 0x01: /* DVD copyright information */ + buffer[4] = 0; /* No copyright data. */ + buffer[5] = 0; /* No region restrictions. */ + + /* 4 bytes of data + 2 byte header. */ + ret = (4 + 2); + break; + + case 0x04: /* DVD disc manufacturing information. */ + /* 2048 bytes of data + 2 byte header */ + ret = (2048 + 2); + break; + + case 0xff: + /* + * This lists all the command capabilities above. Add new ones + * in order and update the length and buffer return values. + */ + + buffer[4] = 0x00; /* Physical format */ + buffer[5] = 0x40; /* Not writable, is readable */ + buffer[6] = ((2048 + 4) >> 8) & 0xff; + buffer[7] = (2048 + 4) & 0xff; + + buffer[8] = 0x01; /* Copyright info */ + buffer[9] = 0x40; /* Not writable, is readable */ + buffer[10] = ((4 + 2) >> 8) & 0xff; + buffer[11] = (4 + 2) & 0xff; + + buffer[12] = 0x03; /* BCA info */ + buffer[13] = 0x40; /* Not writable, is readable */ + buffer[14] = ((188 + 2) >> 8) & 0xff; + buffer[15] = (188 + 2) & 0xff; + + buffer[16] = 0x04; /* Manufacturing info */ + buffer[17] = 0x40; /* Not writable, is readable */ + buffer[18] = ((2048 + 2) >> 8) & 0xff; + buffer[19] = (2048 + 2) & 0xff; + + /* data written + 4 byte header */ + ret = (16 + 2); + break; + + default: + *info = format; + ret = -(SENSE_ILLEGAL_REQUEST << 16) | (ASC_INV_FIELD_IN_CMD_PACKET << 8); + break; + } return ret; } -static void -process_mode1(cdrom_t *dev, int cdrom_sector_flags, uint8_t *b) +void +cdrom_read_disc_information(const cdrom_t *dev, uint8_t *buffer) { - cdrom_sector_size = 0; + uint8_t rti[65536] = { 0 }; + raw_track_info_t *t = (raw_track_info_t *) rti; + int num = 0; + int first = 0; + int sessions = 0; + int ls_first = 0; + int ls_last = 0; + int t_b0 = -1; - if (cdrom_sector_flags & 0x80) { - /* Sync */ - cdrom_log("CD-ROM %i: [Mode 1] Sync\n", dev->id); - memcpy(b, raw_buffer, 12); - cdrom_sector_size += 12; - b += 12; - } + dev->ops->get_raw_track_info(dev->local, &num, rti); - if (cdrom_sector_flags & 0x20) { - /* Header */ - cdrom_log("CD-ROM %i: [Mode 1] Header\n", dev->id); - memcpy(b, raw_buffer + 12, 4); - cdrom_sector_size += 4; - b += 4; - } + for (int i = 0; i < num; i++) + if (t[i].session > sessions) + sessions = t[i].session; + else if ((first == 0) && (t[i].point >= 1) && (t[i].point <= 99)) + first = t[i].point; - if (cdrom_sector_flags & 0x40) { - /* Sub-header */ - if (!(cdrom_sector_flags & 0x10)) { - /* No user data */ - cdrom_log("CD-ROM %i: [Mode 1] Sub-header\n", dev->id); - memcpy(b, raw_buffer + 16, 8); - cdrom_sector_size += 8; - b += 8; + for (int i = 0; i < num; i++) + if ((t[i].session == sessions) && (t[i].point >= 1) && (t[i].point <= 99)) { + ls_first = t[i].point; + break; } - } - if (cdrom_sector_flags & 0x10) { - /* User data */ - cdrom_log("CD-ROM %i: [Mode 1] User data\n", dev->id); - memcpy(b, raw_buffer + 16, 2048); - cdrom_sector_size += 2048; - b += 2048; - } + for (int i = (num - 1); i >= 0; i--) + if ((t[i].session == sessions) && (t[i].point >= 1) && (t[i].point <= 99)) { + ls_last = t[i].point; + break; + } - if (cdrom_sector_flags & 0x08) { - /* EDC/ECC */ - cdrom_log("CD-ROM %i: [Mode 1] EDC/ECC\n", dev->id); - memcpy(b, raw_buffer + 2064, 288); - cdrom_sector_size += 288; - b += 288; + for (int i = (num - 1); i >= 0; i--) + if (t[i].point == 0xb0) { + t_b0 = i; + break; + } + + memset(buffer, 0x00, 34); + + buffer[ 0] = 0x00; /* Disc Information Length (MSB) */ + buffer[ 1] = 0x20; /* Disc Information Lenght (LSB) */ + buffer[ 2] = 0x0e; /* Last session complete, disc finalized */ + buffer[ 3] = first; /* Number of First Track on Disc */ + buffer[ 4] = sessions; /* Number of Sessions (LSB) */ + buffer[ 5] = ls_first; /* First Track Number in Last Session (LSB) */ + buffer[ 5] = ls_last; /* Last Track Number in Last Session (LSB) */ + buffer[ 7] = 0x20; /* Unrestricted use */ + buffer[ 8] = t[0].ps; /* Disc Type */ + buffer[ 9] = 0x00; /* Number Of Sessions (MSB) */ + buffer[10] = 0x00; /* First Track Number in Last Session (MSB) */ + buffer[11] = 0x00; /* Last Track Number in Last Session (MSB) */ + + if (t_b0 == -1) { + /* Single-session disc. */ + + /* Last Session Lead-in Start Time MSF is 00:00:00 */ + + /* Last Possible Start Time for Start of Lead-out */ + buffer[20] = t[2].pm; + buffer[21] = t[2].ps; + buffer[22] = t[2].pf; + } else { + /* Multi-session disc. */ + + /* Last Session Lead-in Start Time MSF */ + buffer[17] = t[t_b0].m; + buffer[18] = t[t_b0].s; + buffer[19] = t[t_b0].f; + + /* Last Possible Start Time for Start of Lead-out */ + buffer[20] = t[t_b0].pm; + buffer[21] = t[t_b0].ps; + buffer[22] = t[t_b0].pf; } } -static int -read_data(cdrom_t *dev, uint32_t lba) +int +cdrom_read_track_information(cdrom_t *dev, const uint8_t *cdb, uint8_t *buffer) { - return dev->ops->read_sector(dev, raw_buffer, lba); -} + uint8_t rti[65536] = { 0 }; + const raw_track_info_t *t = (raw_track_info_t *) rti; + const raw_track_info_t *track = NULL; + const raw_track_info_t lead_in = { 0 }; + const uint32_t pos = (cdb[2] << 24) | (cdb[3] << 16) | + (cdb[4] << 8) | cdb[5]; + uint32_t real_pos = pos; + int num = 0; + int ret; -static int -read_mode1(cdrom_t *dev, int cdrom_sector_flags, uint32_t lba, uint8_t *b) -{ - int ret = read_data(dev, lba); + dev->ops->get_raw_track_info(dev->local, &num, rti); - process_mode1(dev, cdrom_sector_flags, b); + switch (cdb[1] & 0x03) { + default: + ret = -cdb[1]; + break; + case 0x00: + if (num < 4) + ret = -pos; + else { + for (int i = 0; i < num; i++) { + const raw_track_info_t *ct = &(t[i]); + const uint32_t start = ((ct->pm * 60 * 75) + (ct->ps * 75) + + ct->pf) - 150; + if (pos > start) { + track = ct; + break; + } + } - return ret; -} + if (track == NULL) + ret = -cdb[1]; + else + ret = 36; + } + break; + case 0x01: + switch (pos) { + default: + /* + TODO: Does READ TRACK INFORMATION use track AAh + or the raw A0h, A1h, and A2h? + */ + if (pos == 0xaa) + real_pos = 0xa2; -static int -read_mode2_non_xa(cdrom_t *dev, int cdrom_sector_flags, uint32_t lba, uint8_t *b) -{ - int ret = dev->ops->read_sector(dev, raw_buffer, lba); + for (int i = 0; i < num; i++) { + const raw_track_info_t *ct = &(t[i]); + if (ct->point == real_pos) { + track = ct; + break; + } + } - cdrom_sector_size = 0; + if (track == NULL) + ret = -pos; + else + ret = 36; + break; + case 0x00: + track = &lead_in; + ret = 36; + break; + case 0xff: + ret = -pos; + break; + } + break; + case 0x02: + for (int i = 0; i < num; i++) { + const raw_track_info_t *ct = &(t[i]); + if ((ct->session == pos) && (ct->point >= 1) && (ct->point <= 99)) { + track = ct; + break; + } + } - if (cdrom_sector_flags & 0x80) { - /* Sync */ - cdrom_log("CD-ROM %i: [Mode 2 Formless] Sync\n", dev->id); - memcpy(b, raw_buffer, 12); - cdrom_sector_size += 12; - b += 12; + if (track == NULL) + ret = -pos; + else + ret = 36; + break; } - if (cdrom_sector_flags & 0x20) { - /* Header */ - cdrom_log("CD-ROM %i: [Mode 2 Formless] Header\n", dev->id); - memcpy(b, raw_buffer + 12, 4); - cdrom_sector_size += 4; - b += 4; - } + if (ret == 36) { + uint32_t start = ((track->pm * 60 * 75) + (track->ps * 75) + + track->pf) - 150; + uint32_t len = 0x00000000; + uint8_t mode = 0xf; - /* Mode 1 sector, expected type is 1 type. */ - if (cdrom_sector_flags & 0x40) { - /* Sub-header */ - cdrom_log("CD-ROM %i: [Mode 2 Formless] Sub-header\n", dev->id); - memcpy(b, raw_buffer + 16, 8); - cdrom_sector_size += 8; - b += 8; - } + memset(buffer, 0, 36); + buffer[0] = 0x00; + buffer[1] = 0x22; + buffer[2] = track->point; /* Track number (LSB). */ + buffer[3] = track->session; /* Session number (LSB). */ + /* Not damaged, primary copy. */ + buffer[5] = track->adr_ctl & 0x04; - if (cdrom_sector_flags & 0x10) { - /* User data */ - cdrom_log("CD-ROM %i: [Mode 2 Formless] User data\n", dev->id); - memcpy(b, raw_buffer + 24, 2336); - cdrom_sector_size += 2336; - b += 2336; - } + if ((track->point >= 1) && (track->point >= 99)) { + for (int i = 0; i < num; i++) { + const raw_track_info_t *ct = &(t[i]); + const uint32_t ts = ((ct->pm * 60 * 75) + (ct->ps * 75) + + ct->pf) - 150; + if ((ts > start) && ((ct->point == 0xa2) || ((ct->point >= 1) && + (ct->point <= 99)))) { + len = ts - start; + break; + } + } - return ret; -} + if (track->adr_ctl & 0x04) { + ret = read_data(dev, start); + mode = dev->raw_buffer[3]; + } + } else if (track->point != 0xa2) + start = 0x00000000; -static void -process_mode2_xa_form1(cdrom_t *dev, int cdrom_sector_flags, uint8_t *b) -{ - cdrom_sector_size = 0; + /* Not reserved track, not blank, not packet writing, not fixed packet. */ + buffer[ 6] = mode << 0; + /* Last recorded address not valid, next recordable address not valid. */ + buffer[ 7] = 0x00; - if (cdrom_sector_flags & 0x80) { - /* Sync */ - cdrom_log("CD-ROM %i: [XA Mode 2 Form 1] Sync\n", dev->id); - memcpy(b, raw_buffer, 12); - cdrom_sector_size += 12; - b += 12; - } + buffer[ 8] = (start >> 24) & 0xff; + buffer[ 9] = (start >> 16) & 0xff; + buffer[10] = (start >> 8) & 0xff; + buffer[11] = start & 0xff; - if (cdrom_sector_flags & 0x20) { - /* Header */ - cdrom_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_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_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_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; - } -} - -static int -read_mode2_xa_form1(cdrom_t *dev, int cdrom_sector_flags, uint32_t lba, uint8_t *b) -{ - int ret = read_data(dev, lba); - - process_mode2_xa_form1(dev, cdrom_sector_flags, b); - - return ret; -} - -static int -read_mode2_xa_form2(cdrom_t *dev, int cdrom_sector_flags, uint32_t lba, uint8_t *b) -{ - int ret = dev->ops->read_sector(dev, raw_buffer, lba); - - cdrom_sector_size = 0; - - if (cdrom_sector_flags & 0x80) { - /* Sync */ - cdrom_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_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_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_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; + buffer[24] = (len >> 24) & 0xff; + buffer[25] = (len >> 16) & 0xff; + buffer[26] = (len >> 8) & 0xff; + buffer[27] = len & 0xff; } return ret; } int -cdrom_readsector_raw(cdrom_t *dev, uint8_t *buffer, int sector, int ismsf, int cdrom_sector_type, - int cdrom_sector_flags, int *len, uint8_t vendor_type) +cdrom_is_empty(const uint8_t id) { - uint8_t *b; - uint8_t *temp_b; - uint32_t lba; - int audio = 0; - int mode2 = 0; - int unk = 0; - int ret = 0; + const cdrom_t *dev = &cdrom[id]; + int ret = 0; - if (dev->cd_status == CD_STATUS_EMPTY) - return 0; - - b = temp_b = buffer; - - *len = 0; - - if (ismsf) { - int m = (sector >> 16) & 0xff; - int s = (sector >> 8) & 0xff; - int f = sector & 0xff; - - lba = MSFtoLBA(m, s, f) - 150; - } else { - switch (vendor_type) { - case 0x00: - lba = sector; - break; - case 0x40: { - int m = bcd2bin((sector >> 24) & 0xff); - int s = bcd2bin((sector >> 16) & 0xff); - int f = bcd2bin((sector >> 8) & 0xff); - - lba = MSFtoLBA(m, s, f) - 150; - break; - } case 0x80: - lba = bcd2bin((sector >> 24) & 0xff); - break; - /* Never used values but the compiler complains. */ - default: - lba = 0; - } - } - - if (dev->ops->track_type) - audio = dev->ops->track_type(dev, lba); - - mode2 = audio & CD_TRACK_MODE2; - unk = audio & CD_TRACK_UNK_DATA; - audio &= CD_TRACK_AUDIO; - - memset(raw_buffer, 0, 2448); - memset(extra_buffer, 0, 296); - - if ((cdrom_sector_flags & 0xf8) == 0x08) { - /* 0x08 is an illegal mode */ - cdrom_log("CD-ROM %i: [Mode 1] 0x08 is an illegal mode\n", dev->id); - return 0; - } - - if (!track_type_is_valid(dev->id, cdrom_sector_type, cdrom_sector_flags, audio, mode2)) - return 0; - - if ((cdrom_sector_type > 5) && (cdrom_sector_type != 8)) { - cdrom_log("CD-ROM %i: Attempting to read an unrecognized sector type from an image\n", dev->id); - return 0; - } else if (cdrom_sector_type == 1) { - if (!audio || (dev->cd_status == CD_STATUS_DATA_ONLY)) { - cdrom_log("CD-ROM %i: [Audio] Attempting to read an audio sector from a data image\n", dev->id); - return 0; - } - - ret = read_audio(dev, lba, temp_b); - } else if (cdrom_sector_type == 2) { - if (audio || mode2) { - cdrom_log("CD-ROM %i: [Mode 1] Attempting to read a sector of another type\n", dev->id); - return 0; - } - - ret = read_mode1(dev, cdrom_sector_flags, lba, temp_b); - } else if (cdrom_sector_type == 3) { - if (audio || !mode2 || (mode2 & 0x03)) { - cdrom_log("CD-ROM %i: [Mode 2 Formless] Attempting to read a sector of another type\n", dev->id); - return 0; - } - - ret = read_mode2_non_xa(dev, cdrom_sector_flags, lba, temp_b); - } else if (cdrom_sector_type == 4) { - if (audio || !mode2 || ((mode2 & 0x03) != 1)) { - cdrom_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(dev, cdrom_sector_flags, lba, temp_b); - } else if (cdrom_sector_type == 5) { - if (audio || !mode2 || ((mode2 & 0x03) != 2)) { - cdrom_log("CD-ROM %i: [XA Mode 2 Form 2] Attempting to read a sector of another type\n", dev->id); - return 0; - } - - ret = read_mode2_xa_form2(dev, cdrom_sector_flags, lba, temp_b); - } else if (cdrom_sector_type == 8) { - if (audio) { - cdrom_log("CD-ROM %i: [Any Data] Attempting to read a data sector from an audio track\n", dev->id); - return 0; - } - - if (unk) { - /* This is needed to correctly read Mode 2 XA Form 1 sectors over IOCTL. */ - ret = read_data(dev, lba); - - if (raw_buffer[0x000f] == 0x02) { - cdrom_log("CD-ROM %i: [Any Data] Unknown data type determined to be XA Mode 2 Form 1\n", dev->id); - process_mode2_xa_form1(dev, cdrom_sector_flags, temp_b); - } else { - cdrom_log("CD-ROM %i: [Any Data] Unknown data type determined to be Mode 1\n", dev->id); - process_mode1(dev, cdrom_sector_flags, temp_b); - } - } else if (mode2 && ((mode2 & 0x03) == 1)) - ret = read_mode2_xa_form1(dev, cdrom_sector_flags, lba, temp_b); - else if (!mode2) - ret = read_mode1(dev, cdrom_sector_flags, lba, temp_b); - else { - cdrom_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) - ret = read_mode2_xa_form1(dev, cdrom_sector_flags, lba, temp_b); - else if ((mode2 & 0x03) == 0x02) - ret = read_mode2_xa_form2(dev, cdrom_sector_flags, lba, temp_b); - else - ret = read_mode2_non_xa(dev, cdrom_sector_flags, lba, temp_b); - } else { - if (audio) - ret = read_audio(dev, lba, temp_b); - else - ret = read_mode1(dev, cdrom_sector_flags, lba, temp_b); - } - } - - if ((cdrom_sector_flags & 0x06) == 0x02) { - /* Add error flags. */ - cdrom_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_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_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_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_log("CD-ROM %i: R/W subchannel data\n", dev->id); - memcpy(b + cdrom_sector_size, raw_buffer + 2352, 96); - cdrom_sector_size += 96; - } - - *len = cdrom_sector_size; + /* This entire block should be in cdrom.c/cdrom_eject(dev*) ... */ + if (strlen(dev->image_path) == 0) + /* Switch from empty to empty. Do nothing. */ + ret = 1; return ret; } -/* Peform a master init on the entire module. */ -void -cdrom_global_init(void) -{ - /* Clear the global data. */ - memset(cdrom, 0x00, sizeof(cdrom)); -} - -static void -cdrom_drive_reset(cdrom_t *dev) -{ - dev->priv = NULL; - dev->insert = NULL; - dev->close = NULL; - dev->get_volume = NULL; - dev->get_channel = NULL; -} - #ifdef ENABLE_CDROM_LOG static void cdrom_toc_dump(cdrom_t *dev) @@ -2047,7 +2666,7 @@ cdrom_toc_dump(cdrom_t *dev) fwrite(b, 1, len, f); fflush(f); fclose(f); - pclog("Written TOC of %i bytes to %s\n", len, fn2); + cdrom_log(dev->log, "Written TOC of %i bytes to %s\n", len, fn2); memset(b, 0x00, 65536); len = cdrom_read_toc(dev, b, CD_TOC_NORMAL, 0, 0, 65536); @@ -2056,7 +2675,7 @@ cdrom_toc_dump(cdrom_t *dev) fwrite(b, 1, len, f); fflush(f); fclose(f); - pclog("Written cooked TOC of %i bytes to %s\n", len, fn2); + cdrom_log(dev->log, "Written cooked TOC of %i bytes to %s\n", len, fn2); memset(b, 0x00, 65536); len = cdrom_read_toc(dev, b, CD_TOC_SESSION, 0, 0, 65536); @@ -2065,24 +2684,136 @@ cdrom_toc_dump(cdrom_t *dev) fwrite(b, 1, len, f); fflush(f); fclose(f); - pclog("Written session TOC of %i bytes to %s\n", len, fn2); + cdrom_log(dev->log, "Written session TOC of %i bytes to %s\n", len, fn2); } #endif +void +cdrom_set_empty(cdrom_t *dev) +{ + dev->cd_status = CD_STATUS_EMPTY; +} + +void +cdrom_update_status(cdrom_t *dev) +{ + const int was_empty = (dev->cd_status == CD_STATUS_EMPTY); + + if (dev->ops->load != NULL) + dev->ops->load(dev->local); + + /* All good, reset state. */ + dev->seek_pos = 0; + dev->cd_buflen = 0; + + if ((dev->ops->is_empty != NULL) && dev->ops->is_empty(dev->local)) + dev->cd_status = CD_STATUS_EMPTY; + else if (dev->ops->is_dvd(dev->local)) + dev->cd_status = CD_STATUS_DVD; + else + dev->cd_status = dev->ops->has_audio(dev->local) ? CD_STATUS_STOPPED : + CD_STATUS_DATA_ONLY; + + dev->cdrom_capacity = dev->ops->get_last_block(dev->local); + + if (dev->cd_status != CD_STATUS_EMPTY) { + /* Signal media change to the emulated machine. */ + cdrom_insert(dev->id); + + /* The drive was previously empty, transition directly to UNIT ATTENTION. */ + if (was_empty) + cdrom_insert(dev->id); + } +} + +int +cdrom_load(cdrom_t *dev, const char *fn, const int skip_insert) +{ + const int was_empty = cdrom_is_empty(dev->id); + int ret = 0; + + /* Make sure to not STRCPY if the two are pointing + at the same place. */ + if (fn != dev->image_path) + strcpy(dev->image_path, fn); + + /* Open the target. */ + if ((strlen(dev->image_path) != 0) && + (strstr(dev->image_path, "ioctl://") == dev->image_path)) + dev->local = ioctl_open(dev, dev->image_path); + else + dev->local = image_open(dev, dev->image_path); + + if (dev->local == NULL) { + dev->ops = NULL; + dev->image_path[0] = 0; + + ret = 1; + } else { + /* All good, reset state. */ + dev->seek_pos = 0; + dev->cd_buflen = 0; + + if ((dev->ops->is_empty != NULL) && dev->ops->is_empty(dev->local)) + dev->cd_status = CD_STATUS_EMPTY; + if (dev->ops->is_dvd(dev->local)) + dev->cd_status = CD_STATUS_DVD; + else + dev->cd_status = dev->ops->has_audio(dev->local) ? CD_STATUS_STOPPED : + CD_STATUS_DATA_ONLY; + + dev->cdrom_capacity = dev->ops->get_last_block(dev->local); + + cdrom_log(dev->log, "CD-ROM capacity: %i sectors (%" PRIi64 " bytes)\n", + dev->cdrom_capacity, ((uint64_t) dev->cdrom_capacity) << 11ULL); + } + +#ifdef ENABLE_CDROM_LOG + cdrom_toc_dump(dev); +#endif + + if (!skip_insert && (dev->cd_status != CD_STATUS_EMPTY)) { + /* Signal media change to the emulated machine. */ + cdrom_insert(dev->id); + + /* The drive was previously empty, transition directly to UNIT ATTENTION. */ + if (was_empty) + cdrom_insert(dev->id); + } + + return ret; +} + +/* Peform a master init on the entire module. */ +void +cdrom_global_init(void) +{ + /* Clear the global data. */ + memset(cdrom, 0x00, sizeof(cdrom)); +} + void cdrom_hard_reset(void) { - cdrom_t *dev; - for (uint8_t i = 0; i < CDROM_NUM; i++) { - dev = &cdrom[i]; - if (dev->bus_type) { - cdrom_log("CD-ROM %i: Hard reset\n", i); + cdrom_t *dev = &cdrom[i]; - dev->id = i; + if (dev->bus_type) { + dev->id = i; + + dev->is_early = cdrom_is_early(dev->type); + dev->is_nec = (dev->bus_type == CDROM_BUS_SCSI) && + !strcmp(cdrom_drive_types[dev->type].vendor, "NEC"); cdrom_drive_reset(dev); + char n[1024] = { 0 }; + + sprintf(n, "CD-ROM %i ", i + 1); + dev->log = log_open(n); + + cdrom_log(dev->log, "Hard reset\n"); + switch (dev->bus_type) { case CDROM_BUS_ATAPI: case CDROM_BUS_SCSI: @@ -2105,18 +2836,7 @@ cdrom_hard_reset(void) dev->image_path[strlen(dev->image_path) - 1] = '/'; #endif - if ((strlen(dev->image_path) != 0) && (strstr(dev->image_path, "ioctl://") == dev->image_path)) - cdrom_ioctl_open(dev, dev->image_path); - else - cdrom_image_open(dev, dev->image_path); - - cdrom_insert(i); - cdrom_insert(i); - -#ifdef ENABLE_CDROM_LOG - if (i == 0) - cdrom_toc_dump(dev); -#endif + cdrom_load(dev, dev->image_path, 0); } } } @@ -2127,10 +2847,8 @@ cdrom_hard_reset(void) void cdrom_close(void) { - cdrom_t *dev; - for (uint8_t i = 0; i < CDROM_NUM; i++) { - dev = &cdrom[i]; + cdrom_t *dev = &cdrom[i]; if (dev->bus_type == CDROM_BUS_SCSI) memset(&scsi_devices[dev->scsi_device_id], 0x00, sizeof(scsi_device_t)); @@ -2138,92 +2856,79 @@ cdrom_close(void) if (dev->close) dev->close(dev->priv); - if (dev->ops && dev->ops->exit) - dev->ops->exit(dev); + cdrom_unload(dev); dev->ops = NULL; dev->priv = NULL; cdrom_drive_reset(dev); + + if (dev->log != NULL) { + cdrom_log(dev->log, "Log closed\n"); + + log_close(dev->log); + dev->log = NULL; + } } } /* Signal disc change to the emulated machine. */ void -cdrom_insert(uint8_t id) +cdrom_insert(const uint8_t id) { - cdrom_t *dev = &cdrom[id]; + const cdrom_t *dev = &cdrom[id]; if (dev->bus_type && dev->insert) dev->insert(dev->priv); } void -cdrom_exit(uint8_t id) +cdrom_exit(const uint8_t id) { cdrom_t *dev = &cdrom[id]; strcpy(dev->prev_image_path, dev->image_path); if (dev->ops) { - if (dev->ops->exit) - dev->ops->exit(dev); + cdrom_unload(dev); dev->ops = NULL; } memset(dev->image_path, 0, sizeof(dev->image_path)); - cdrom_log("cdrom_exit(%i): cdrom_insert(%i)\n", id, id); + cdrom_log(dev->log, "cdrom_exit(): cdrom_insert()\n"); cdrom_insert(id); } -int -cdrom_is_empty(uint8_t id) -{ - cdrom_t *dev = &cdrom[id]; - int ret = 0; - - /* This entire block should be in cdrom.c/cdrom_eject(dev*) ... */ - if (strlen(dev->image_path) == 0) - /* Switch from empty to empty. Do nothing. */ - ret = 1; - - return ret; -} - /* The mechanics of ejecting a CD-ROM from a drive. */ void -cdrom_eject(uint8_t id) +cdrom_eject(const uint8_t id) { - cdrom_t *dev = &cdrom[id]; + const cdrom_t *dev = &cdrom[id]; - /* This entire block should be in cdrom.c/cdrom_eject(dev*) ... */ - if (strlen(dev->image_path) == 0) - /* Switch from empty to empty. Do nothing. */ - return; + if (strlen(dev->image_path) != 0) { + cdrom_exit(id); - cdrom_exit(id); + plat_cdrom_ui_update(id, 0); - plat_cdrom_ui_update(id, 0); - - config_save(); + config_save(); + } } /* The mechanics of re-loading a CD-ROM drive. */ void -cdrom_reload(uint8_t id) +cdrom_reload(const uint8_t id) { - cdrom_t *dev = &cdrom[id]; - int was_empty = cdrom_is_empty(id); + cdrom_t *dev = &cdrom[id]; if ((strcmp(dev->image_path, dev->prev_image_path) == 0) || (strlen(dev->prev_image_path) == 0) || (strlen(dev->image_path) > 0)) { /* Switch from empty to empty. Do nothing. */ return; } - if (dev->ops && dev->ops->exit) - dev->ops->exit(dev); + cdrom_unload(dev); + dev->ops = NULL; memset(dev->image_path, 0, sizeof(dev->image_path)); @@ -2242,22 +2947,7 @@ cdrom_reload(uint8_t id) dev->image_path[strlen(dev->image_path) - 1] = '/'; #endif - if ((strlen(dev->image_path) != 0) && (strstr(dev->image_path, "ioctl://") == dev->image_path)) - cdrom_ioctl_open(dev, dev->image_path); - else - cdrom_image_open(dev, dev->image_path); - -#ifdef ENABLE_CDROM_LOG - cdrom_toc_dump(dev); -#endif - - /* Signal media change to the emulated machine. */ - cdrom_log("cdrom_reload(%i): cdrom_insert(%i)\n", id, id); - cdrom_insert(id); - - /* The drive was previously empty, transition directly to UNIT ATTENTION. */ - if (was_empty) - cdrom_insert(id); + cdrom_load(dev, dev->image_path, 0); } plat_cdrom_ui_update(id, 1); diff --git a/src/cdrom/cdrom_image.c b/src/cdrom/cdrom_image.c index 0c7870902..271a290cb 100644 --- a/src/cdrom/cdrom_image.c +++ b/src/cdrom/cdrom_image.c @@ -6,63 +6,1705 @@ * * This file is part of the 86Box distribution. * - * CD-ROM image support. + * CD-ROM image file handling module. * + * Authors: Miran Grca, + * RichardG, + * Cacodemon345 * - * - * Authors: RichardG867, - * Miran Grca, - * bit, - * - * Copyright 2015-2019 Richardg867. - * Copyright 2015-2019 Miran Grca. - * Copyright 2017-2019 bit. + * Copyright 2016-2025 Miran Grca. + * Copyright 2016-2025 RichardG. + * Copyright 2024-2025 Cacodemon345. */ +#define __STDC_FORMAT_MACROS +#include #include +#ifdef ENABLE_IMAGE_LOG #include -#include +#endif #include -#include +#include #include -#include -#define HAVE_STDARG_H +#include +#include +#ifndef _WIN32 +# include +#endif #include <86box/86box.h> -#include <86box/config.h> +#include <86box/log.h> #include <86box/path.h> #include <86box/plat.h> -#include <86box/scsi_device.h> -#include <86box/cdrom_image_backend.h> #include <86box/cdrom.h> #include <86box/cdrom_image.h> +#include <86box/cdrom_image_viso.h> -#ifdef ENABLE_CDROM_IMAGE_LOG -int cdrom_image_do_log = ENABLE_CDROM_IMAGE_LOG; +#include + +#define MAX_LINE_LENGTH 512 +#define MAX_FILENAME_LENGTH 256 +#define CROSS_LEN 512 + +static char temp_keyword[1024]; + +#define INDEX_SPECIAL -2 /* Track A0h onwards. */ +#define INDEX_NONE -1 /* Empty block. */ +#define INDEX_ZERO 0 /* Block not in the file, return all 0x00's. */ +#define INDEX_NORMAL 1 /* Block in the file. */ + +typedef struct track_index_t { + /* + Is the current block in the file? If not, return all 0x00's. -1 means not + yet loaded. + */ + int32_t type; + /* The amount of bytes to skip at the beginning of each sector. */ + int32_t skip; + /* + Starting and ending sector LBA - negative in order to accomodate LBA -150 to -1 + to read the pregap of track 1. + */ + uint64_t start; + uint64_t length; + uint64_t file_start; + uint64_t file_length; + track_file_t *file; +} track_index_t; + +typedef struct track_t { + uint8_t session; + uint8_t attr; + uint8_t tno; + uint8_t point; + uint8_t extra[4]; + uint8_t mode; + uint8_t form; + uint8_t subch_type; + uint8_t skip; + uint32_t sector_size; + track_index_t idx[3]; +} track_t; + +typedef struct cd_image_t { + cdrom_t *dev; + void *log; + int is_dvd; + int has_audio; + int32_t tracks_num; + uint32_t bad_sectors_num; + track_t *tracks; + uint32_t *bad_sectors; +} cd_image_t; + +#ifdef ENABLE_IMAGE_LOG +int image_do_log = ENABLE_IMAGE_LOG; void -cdrom_image_log(const char *fmt, ...) +image_log(void *priv, const char *fmt, ...) { va_list ap; - if (cdrom_image_do_log) { + if (image_do_log) { va_start(ap, fmt); - pclog_ex(fmt, ap); + log_out(priv, fmt, ap); va_end(ap); } } + +static char *cit[4] = { "SPECIAL", "NONE", "ZERO", "NORMAL" }; #else -# define cdrom_image_log(fmt, ...) +# define image_log(priv, fmt, ...) #endif -/* 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) +typedef struct audio_file_t { + SNDFILE *file; + SF_INFO info; +} audio_file_t; + +/* Audio file functions */ +static int +audio_read(void *priv, uint8_t *buffer, const uint64_t seek, const size_t count) +{ + const track_file_t *tf = (track_file_t *) priv; + const audio_file_t *audio = (audio_file_t *) tf->priv; + const uint64_t samples_seek = seek / 4; + const uint64_t samples_count = count / 4; + + if ((seek & 3) || (count & 3)) { + image_log(tf->log, "CD Audio file: Reading on non-4-aligned boundaries.\n"); + } + + const sf_count_t res = sf_seek(audio->file, samples_seek, SEEK_SET); + + if (res == -1) + return 0; + + return !!sf_readf_short(audio->file, (short *) buffer, samples_count); +} + +static uint64_t +audio_get_length(void *priv) +{ + const track_file_t *tf = (track_file_t *) priv; + const audio_file_t *audio = (audio_file_t *) tf->priv; + + /* Assume 16-bit audio, 2 channel. */ + return audio->info.frames * 4ull; +} static void -image_get_track_info(cdrom_t *dev, uint32_t track, int end, track_info_t *ti) +audio_close(void *priv) { - cd_img_t *img = (cd_img_t *) dev->local; - track_t *ct = NULL; + track_file_t *tf = (track_file_t *) priv; + audio_file_t *audio = (audio_file_t *) tf->priv; + + memset(tf->fn, 0x00, sizeof(tf->fn)); + if (audio && audio->file) + sf_close(audio->file); + free(audio); + free(tf); +} + +static track_file_t * +audio_init(const uint8_t id, const char *filename, int *error) +{ + track_file_t *tf = (track_file_t *) calloc(sizeof(track_file_t), 1); + audio_file_t *audio = (audio_file_t *) calloc(sizeof(audio_file_t), 1); +#ifdef _WIN32 + wchar_t filename_w[4096]; +#endif + + if (tf == NULL || audio == NULL) { + goto cleanup_error; + } + + memset(tf->fn, 0x00, sizeof(tf->fn)); + strncpy(tf->fn, filename, sizeof(tf->fn) - 1); +#ifdef _WIN32 + mbstowcs(filename_w, filename, 4096); + audio->file = sf_wchar_open(filename_w, SFM_READ, &audio->info); +#else + audio->file = sf_open(filename, SFM_READ, &audio->info); +#endif + + if (audio->file == NULL) { + image_log(tf->log, "Audio file open error!"); + goto cleanup_error; + } + + if (audio->info.channels != 2 || audio->info.samplerate != 44100 || !audio->info.seekable) { + image_log(tf->log, "Audio file not seekable or in non-CD format!"); + sf_close(audio->file); + goto cleanup_error; + } + + *error = 0; + + tf->priv = audio; + tf->fp = NULL; + tf->close = audio_close; + tf->get_length = audio_get_length; + tf->read = audio_read; + + char n[1024] = { 0 }; + + sprintf(n, "CD-ROM %i Audio", id + 1); + tf->log = log_open(n); + + return tf; +cleanup_error: + free(tf); + free(audio); + *error = 1; + return NULL; +} + +/* Binary file functions. */ +static int +bin_read(void *priv, uint8_t *buffer, const uint64_t seek, const size_t count) +{ + const track_file_t *tf = (track_file_t *) priv; + + if (tf->fp == NULL) + return 0; + + image_log(tf->log, "binary_read(%08lx, pos=%" PRIu64 " count=%lu)\n", + tf->fp, seek, count); + + if (fseeko64(tf->fp, seek, SEEK_SET) == -1) { + image_log(tf->log, "binary_read failed during seek!\n"); + + return -1; + } + + if (fread(buffer, count, 1, tf->fp) != 1) { + image_log(tf->log, "binary_read failed during read!\n"); + + return -1; + } + + if (UNLIKELY(tf->motorola)) { + for (uint64_t i = 0; i < count; i += 2) { + const uint8_t buffer0 = buffer[i]; + const uint8_t buffer1 = buffer[i + 1]; + buffer[i] = buffer1; + buffer[i + 1] = buffer0; + } + } + + return 1; +} + +static uint64_t +bin_get_length(void *priv) +{ + const track_file_t *tf = (track_file_t *) priv; + + if (tf->fp == NULL) + return 0; + + fseeko64(tf->fp, 0, SEEK_END); + const off64_t len = ftello64(tf->fp); + image_log(tf->log, "binary_length(%08lx) = %" PRIu64 "\n", tf->fp, len); + + return len; +} + +static void +bin_close(void *priv) +{ + track_file_t *tf = (track_file_t *) priv; + + if (tf == NULL) + return; + + if (tf->fp != NULL) { + fclose(tf->fp); + tf->fp = NULL; + } + + memset(tf->fn, 0x00, sizeof(tf->fn)); + + free(priv); +} + +static track_file_t * +bin_init(const uint8_t id, const char *filename, int *error) +{ + track_file_t *tf = (track_file_t *) calloc(1, sizeof(track_file_t)); + struct stat stats; + + if (tf == NULL) { + *error = 1; + return NULL; + } + + memset(tf->fn, 0x00, sizeof(tf->fn)); + strncpy(tf->fn, filename, sizeof(tf->fn) - 1); + tf->fp = plat_fopen64(tf->fn, "rb"); + image_log(tf->log, "binary_open(%s) = %08lx\n", tf->fn, tf->fp); + + if (stat(tf->fn, &stats) != 0) { + /* Use a blank structure if stat failed. */ + memset(&stats, 0, sizeof(struct stat)); + } + *error = ((tf->fp == NULL) || ((stats.st_mode & S_IFMT) == S_IFDIR)); + + /* Set the function pointers. */ + if (!*error) { + tf->read = bin_read; + tf->get_length = bin_get_length; + tf->close = bin_close; + + char n[1024] = { 0 }; + + sprintf(n, "CD-ROM %i Bin ", id + 1); + tf->log = log_open(n); + } else { + /* From the check above, error may still be non-zero if opening a directory. + * The error is set for viso to try and open the directory following this function. + * However, we need to make sure the descriptor is closed. */ + if ((tf->fp != NULL) && ((stats.st_mode & S_IFMT) == S_IFDIR)) { + /* tf is freed by bin_close */ + bin_close(tf); + } else + free(tf); + tf = NULL; + } + + return tf; +} + +static track_file_t * +index_file_init(const uint8_t id, const char *filename, int *error, int *is_viso) +{ + track_file_t *tf = NULL; + + *is_viso = 0; + + /* Current we only support .BIN files, either combined or one per + track. In the future, more is planned. */ + tf = bin_init(id, filename, error); + + if (*error) { + if ((tf != NULL) && (tf->close != NULL)) { + tf->close(tf); + tf = NULL; + } + + tf = viso_init(id, filename, error); + + if (!*error) + *is_viso = 1; + } + + return tf; +} + +static void +index_file_close(track_index_t *idx) +{ + if ((idx == NULL) || (idx->file == NULL)) + return; + + image_log(idx->file->log, "Log closed\n"); + + if (idx->file->log != NULL) { + log_close(idx->file->log); + idx->file->log = NULL; + } + + if (idx->file->close != NULL) + idx->file->close(idx->file); + + idx->file = NULL; +} + +/* Internal functions. */ +static int +image_get_track(const cd_image_t *img, const uint32_t sector) +{ + int ret = -1; + + for (int i = 0; i < img->tracks_num; i++) { + track_t *ct = &(img->tracks[i]); + for (int j = 0; j < 3; j++) { + const track_index_t *ci = &(ct->idx[j]); + if ((ci->type >= INDEX_ZERO) && (ci->length != 0ULL) && + ((sector + 150) >= ci->start) && ((sector + 150) <= (ci->start + ci->length - 1))) { + ret = i; + break; + } + } + } + + return ret; +} + +static void +image_get_track_and_index(const cd_image_t *img, const uint32_t sector, + int *track, int *index) +{ + *track = -1; + *index = -1; + + for (int i = 0; i < img->tracks_num; i++) { + track_t *ct = &(img->tracks[i]); + for (int j = 0; j < 3; j++) { + track_index_t *ci = &(ct->idx[j]); + if ((ci->type >= INDEX_ZERO) && (ci->length != 0ULL) && + ((sector + 150) >= ci->start) && ((sector + 150) <= (ci->start + ci->length - 1))) { + *track = i; + *index = j; + break; + } + } + } +} + +static int +image_is_sector_bad(const cd_image_t *img, const uint32_t sector) +{ + int ret = 0; + + if (img->bad_sectors_num > 0) for (int i = 0; i < img->bad_sectors_num; i++) + if (img->bad_sectors[i] == sector) { + ret = 1; + break; + } + + return ret; +} + +static int +image_is_track_audio(const cd_image_t *img, const uint32_t pos) +{ + int ret = 0; + + if (img->has_audio) { + const int track = image_get_track(img, pos); + + if (track >= 0) { + const track_t *trk = &(img->tracks[track]); + + ret = (trk->mode == 0); + } + } + + return ret; +} + +static int +image_can_read_pvd(track_file_t *file, const uint64_t start, + const uint64_t sector_size, const int xa) +{ + uint8_t buf[2448] = { 0 }; + /* First VD is located at sector 16. */ + uint64_t seek = start + (16ULL * sector_size); + uint8_t *pvd = (uint8_t *) buf; + + if (sector_size >= RAW_SECTOR_SIZE) { + if (xa) + pvd = &(buf[24]); + else + pvd = &(buf[16]); + } else if (sector_size >= 2332) { + if (xa) + pvd = &(buf[8]); + } + + file->read(file, buf, seek, sector_size); + + int ret = (((pvd[0] == 1) && + !strncmp((char *) &(pvd[1]), "CD001", 5) && + (pvd[6] == 1)) || + ((pvd[8] == 1) && + !strncmp((char *) &(pvd[9]), "CDROM", 5) && + (pvd[14] == 1))); + + if (ret) { + if (sector_size >= RAW_SECTOR_SIZE) { + if (xa) + /* Mode 2 XA, Form from the sub-header. */ + ret = 0x20 | (((buf[18] & 0x20) >> 5) + 1); + else + /* Mode from header. */ + ret = buf[15] << 4; + } else if (sector_size >= 2332) { + if (xa) + /* Mode 2 XA, Form from the sub-header. */ + ret = 0x20 | (((buf[2] & 0x20) >> 5) + 1); + else + /* Mode 2 non-XA. */ + ret = 0x20; + } else if (sector_size >= 2324) + /* Mode 2 XA Form 2. */ + ret = 0x22; + else if (!strncmp((char *) &(pvd[0x400]), "CD-XA001", 8)) + /* Mode 2 XA Form 1. */ + ret = 0x21; + else + /* Mode 1. */ + ret = 0x10; + } + + return ret; +} + +static int +image_cue_get_buffer(char *str, char **line, const int up) +{ + char *s = *line; + char *p = str; + int quote = 0; + int done = 0; + int space = 1; + + /* Copy to local buffer until we have end of string or whitespace. */ + while (!done) { + switch (*s) { + case '\0': + if (quote) { + /* Ouch, unterminated string.. */ + return 0; + } + done = 1; + break; + + case '\"': + quote ^= 1; + break; + + case ' ': + case '\t': + if (space) + break; + + if (!quote) { + done = 1; + break; + } + fallthrough; + + default: + if (up && islower((int) *s)) + *p++ = toupper((int) *s); + else + *p++ = *s; + space = 0; + break; + } + + if (!done) + s++; + } + *p = '\0'; + + *line = s; + + return 1; +} + +static int +image_cue_get_keyword(char **dest, char **line) +{ + const int success = image_cue_get_buffer(temp_keyword, line, 1); + + if (success) + *dest = temp_keyword; + + return success; +} + +/* Get a string from the input line, handling quotes properly. */ +static uint64_t +image_cue_get_number(char **line) +{ + char temp[128]; + uint64_t num; + + if (!image_cue_get_buffer(temp, line, 0)) + return 0; + + if (sscanf(temp, "%" PRIu64, &num) != 1) + return 0; + + return num; +} + +static int +image_cue_get_frame(uint64_t *frames, char **line) +{ + char temp[128]; + int min = 0; + int sec = 0; + int fr = 0; + + int success = image_cue_get_buffer(temp, line, 0); + if (!success) + return 0; + + success = sscanf(temp, "%d:%d:%d", &min, &sec, &fr) == 3; + if (!success) + return 0; + + *frames = MSF_TO_FRAMES(min, sec, fr); + + return 1; +} + +static int +image_cue_get_flags(track_t *cur, char **line) +{ + char temp[128]; + char temp2[128]; + + int success = image_cue_get_buffer(temp, line, 0); + if (!success) + return 0; + + memset(temp2, 0x00, sizeof(temp2)); + success = sscanf(temp, "%s", temp2) == 1; + if (!success) + return 0; + + if (strstr(temp2, "PRE") != NULL) + cur->attr |= 0x01; + if (strstr(temp2, "DCP") != NULL) + cur->attr |= 0x02; + if (strstr(temp2, "4CH") != NULL) + cur->attr |= 0x08; + + return 1; +} + +static track_t * +image_insert_track(cd_image_t *img, const uint8_t session, const uint8_t point) +{ + track_t *ct = NULL; + + img->tracks_num++; + if (img->tracks == NULL) { + img->tracks = calloc(1, sizeof(track_t)); + ct = &(img->tracks[0]); + } else { + img->tracks = realloc(img->tracks, img->tracks_num * sizeof(track_t)); + ct = &(img->tracks[img->tracks_num - 1]); + } + + image_log(img->log, " [TRACK ] Insert %02X: img->tracks[%2i]\n", + point, img->tracks_num - 1); + + memset(ct, 0x00, sizeof(track_t)); + + ct->session = session; + ct->point = point; + + for (int i = 0; i < 3; i++) + ct->idx[i].type = (point > 99) ? INDEX_SPECIAL : INDEX_NONE; + + if (point >= 0xb0) + ct->attr = 0x50; + + return ct; +} + +static void +image_process(cd_image_t *img) +{ + track_t *ct = NULL; + track_t *lt = NULL; + track_index_t *ci = NULL; + track_file_t *tf = NULL; + uint64_t tf_len = 0ULL; + uint64_t cur_pos = 0ULL; + int pos = 0; + int ls = 0; + int map[256] = { 0 }; + int lead[3] = { 0 }; + uint64_t spg[256] = { 0ULL }; + track_t *lo[256] = { 0 }; + + /* + Pass 2 - adjusting pre-gaps of the first track of every session and creating the + map so we can map from <01-99> to <01-99> + so that their times and length can be adjusted correctly in the third and fourth + passes - especially important for multi-session Cue files. + + We have to do that because Cue sheets do not explicitly indicate those pre-gaps + but they are required so we have the correct frames - the first track of each + session always has a pre-gap of at least 0:02:00. We do not adjust it if it is + already present. + */ + image_log(img->log, "Pass 2 (adjusting pre-gaps and preparing map)...\n"); + + /* Pre-gap of the first track of the first session. */ + ct = &(img->tracks[3]); + ci = &(ct->idx[0]); + + if (ci->type == INDEX_NONE) { + ci->type = INDEX_ZERO; + ci->start = 0ULL; + ci->length = 150ULL; + } + + image_log(img->log, " [PREGAP ] Adjusted pre-gap of track %02X (first in " + "session %i)\n", ct->point, ct->session); + + /* The other pre-gaps and the preparation of the map. */ + for (int i = 0; i < img->tracks_num; i++) { + ct = &(img->tracks[i]); + if (((ct->point >= 1) && (ct->point <= 99)) || (ct->point >= 0xb0)) { + if (ct->point == 0xb0) { + /* The first track of a session always has a pre-gap of at least 0:02:00. */ + track_t *ft = &(img->tracks[i + (ct->session == 1) + 4]); + ci = &(ft->idx[0]); + + if (ci->type == INDEX_NONE) { + if (ft->idx[1].type == INDEX_NORMAL) { + ci->type = INDEX_NORMAL; + ci->file_start = ft->idx[1].file_start - 150ULL; + } else { + ci->type = INDEX_ZERO; + ci->start = 0ULL; + ci->length = 150ULL; + } + } + + image_log(img->log, " [PREGAP ] Adjusted pre-gap of track %02X " + "(first in session %i)\n", ft->point, ct->session); + + /* Point B0h found, add the previous three lead tracks. */ + for (int j = 0; j < 3; j++) { + map[pos] = lead[j]; + image_log(img->log, " [REMAP ] Remap %3i to %3i (%02X)\n", pos, + map[pos], 0xa0 + j); + pos++; + } + } + + /* Add the current track. */ + map[pos] = i; + image_log(img->log, " [NORMAL ] Remap %3i to %3i\n", pos, map[pos]); + pos++; + } else if ((ct->point >= 0xa0) && (ct->point <= 0xa2)) { + /* + Collect lead track (A0 = first track in session, A1 = last track in session, + A2 = lead out). + */ + lead[ct->point & 0x03] = i; + + image_log(img->log, " [LEAD ] Lead %i = %3i (%02X)\n", ct->point & 0x03, i, + ct->point); + } + } + + /* Add the last three lead tracks. */ + for (int i = 0; i < 3; i++) { + map[pos] = lead[i]; + image_log(img->log, " [REMAP ] Remap %3i to %3i (%02X)\n", pos, map[pos], + 0xa0 + i); + pos++; + } + + /* + If these two mismatch, it is a fatal condition since it means something + has gone wrong enough that the Cue sheet processing has been messed up. + */ + if (pos != img->tracks_num) + log_fatal(img->log, "Something has gone wrong and we have remappped %3i tracks " + "instead of the expected %3i\n", pos, img->tracks_num); + + /* + Pass 3 - adjusting the time lengths of each index of track according to the + files. + + We have to do that because Cue sheets do not explicitly indicate the lengths + of track, so we have to deduce them from what the combination of the Cue sheet + and the various files give us. + */ + image_log(img->log, "Pass 3 (adjusting track file lengths according to the files)...\n"); + for (int i = (img->tracks_num - 1); i >= 0; i--) { + ct = &(img->tracks[map[i]]); + if (ct->idx[1].type != INDEX_SPECIAL) { + for (int j = 2; j >= 0; j--) { + ci = &(ct->idx[j]); + + /* + If the file is not NULL and is different from the previous file, + open it and read its length. + */ + if ((ci->file != NULL) && (ci->file != tf)) { + tf = ci->file; + if (tf != NULL) { + tf_len = tf->get_length(tf) / ct->sector_size; + image_log(img->log, " [FILE ] File length: %016" + PRIX64 " sectors\n", tf_len); + } + } + + if ((ci->type < INDEX_SPECIAL) || (ci->type > INDEX_NORMAL)) { + image_log(img->log, " [TRACK ] %02X, INDEX %02X, ATTR %02X,\n", + ci->type, j, + ct->attr); + log_fatal(img->log, " Unrecognized index type during " + "Pass 3: %2i\n", + ci->type); + } else if (ci->type == INDEX_NORMAL) { + /* Index was in the cue sheet and is present in the file. */ + ci->file_length = tf_len - ci->file_start; + tf_len -= ci->file_length; + } else { + /* Index was not in the cue sheet or is not present in the file, + keep its length at zero. */ + ci->file_start = tf_len; + } + + image_log(img->log, " [TRACK ] %02X/%02X, INDEX %02X, ATTR %02X, " + "MODE %02X/%02X, %8s,\n", + ct->session, + ct->point, j, + ct->attr, + ct->mode, ct->form, + cit[ci->type + 2]); + image_log(img->log, " file_start = %016" + PRIX64 " (%2i:%02i:%02i),\n", + ci->file_start, + (int) ((ci->file_start / 75) / 60), + (int) ((ci->file_start / 75) % 60), + (int) (ci->file_start % 75)); + image_log(img->log, " file_length = %016" + PRIX64 " (%2i:%02i:%02i),\n", + ci->file_length, + (int) ((ci->file_length / 75) / 60), + (int) ((ci->file_length / 75) % 60), + (int) (ci->file_length % 75)); + image_log(img->log, " remaining = %016" + PRIX64 " (%2i:%02i:%02i)\n", + tf_len, + (int) ((tf_len / 75) / 60), + (int) ((tf_len / 75) % 60), + (int) (tf_len % 75)); + } + } + } + + /* + Pass 4 - calculating the actual track starts and lengths for the TOC. + */ + image_log(img->log, "Pass 4 (calculating the actual track starts " + "and lengths for the TOC)...\n"); + for (int i = 0; i < img->tracks_num; i++) { + ct = &(img->tracks[map[i]]); + if (ct->idx[1].type != INDEX_SPECIAL) { + int session_changed = 0; + + /* + If the session has changed, store the last session + and mark that it has changed. + */ + if (ct->session != ls) { + ls = ct->session; + session_changed = 1; + } + + for (int j = 0; j < 3; j++) { + ci = &(ct->idx[j]); + + if ((ci->type < INDEX_SPECIAL) || (ci->type > INDEX_NORMAL)) { + image_log(img->log, " [TRACK ] %02X, INDEX %02X, ATTR %02X,\n", + ci->type, j, + ct->attr); + log_fatal(img->log, " Unrecognized index type during " + "Pass 4: %2i\n", + ci->type); + } else if (ci->type <= INDEX_NONE) + /* Index was not in the cue sheet, keep its length at zero. */ + ci->start = cur_pos; + else if (ci->type == INDEX_ZERO) { + /* Index was in the cue sheet and is not present in the file. */ + ci->start = cur_pos; + cur_pos += ci->length; + } else if (ci->type == INDEX_NORMAL) { + /* Index was in the cue sheet and is present in the file. */ + ci->start = cur_pos; + ci->length = ci->file_length; + cur_pos += ci->file_length; + } + + image_log(img->log, " [TRACK ] %02X/%02X, INDEX %02X, ATTR %02X, " + "MODE %02X/%02X, %8s,\n", + ct->session, + ct->point, j, + ct->attr, + ct->mode, ct->form, + cit[ci->type + 2]); + image_log(img->log, " start = %016" + PRIX64 " (%2i:%02i:%02i),\n", + ci->start, + (int) ((ci->start / 75) / 60), + (int) ((ci->start / 75) % 60), + (int) (ci->start % 75)); + image_log(img->log, " length = %016" + PRIX64 " (%2i:%02i:%02i),\n", + ci->length, + (int) ((ci->length / 75) / 60), + (int) ((ci->length / 75) % 60), + (int) (ci->length % 75)); + image_log(img->log, " cur_pos = %016" + PRIX64 " (%2i:%02i:%02i)\n", + cur_pos, + (int) ((cur_pos / 75) / 60), + (int) ((cur_pos / 75) % 60), + (int) (cur_pos % 75)); + + /* Set the pre-gap of the first track of this session. */ + if (session_changed) + spg[ct->session] = ct->idx[0].start; + } + } + } + + /* + Pass 5 - setting the lead out starts for all sessions. + */ + image_log(img->log, "Pass 5 (setting the lead out starts for all sessions)...\n"); + for (int i = 0; i <= ls; i++) { + lo[i] = NULL; + for (int j = (img->tracks_num - 1); j >= 0; j--) { + const track_t *jt = &(img->tracks[j]); + if ((jt->session == i) && (jt->point >= 1) && (jt->point <= 99)) { + lo[i] = &(img->tracks[j]); + image_log(img->log, " [TRACK ] %02X/%02X, INDEX %02X, ATTR %02X, " + "MODE %02X/%02X, %8s,\n", + ct->session, + ct->point, j, + ct->attr, + ct->mode, ct->form, + cit[ci->type + 2]); + image_log(img->log, " using to calculate the start of session " + "%02X lead out\n", + ct->session); + break; + } + } + } + + /* + Pass 6 - refinining modes and forms, and finalizing all the special tracks. + */ + image_log(img->log, "Pass 6 (refinining modes and forms, and finalizing " + "all the special tracks)...\n"); + for (int i = 0; i < img->tracks_num; i++) { + ct = &(img->tracks[i]); + lt = NULL; + switch (ct->point) { + default: + break; + case 1 ... 99: + ci = &(ct->idx[1]); + + if ((ci->type == INDEX_NORMAL) && (ct->mode >= 1)) { + image_log(img->log, " [TRACK ] %02X/01, INDEX %02X, ATTR %02X, " + "MODE %02X/%02X, %8s,\n", + ct->session, + ct->point, + ct->attr, + ct->mode, ct->form, + cit[ct->idx[1].type + 2]); + + /* Override the loaded modes with that we determine here. */ + int can_read_pvd = image_can_read_pvd(ci->file, + ci->file_start * ct->sector_size, + ct->sector_size, 0); + ct->skip = 0; + if (can_read_pvd) { + ct->mode = can_read_pvd >> 4; + ct->form = can_read_pvd & 0xf; + if (((ct->sector_size == 2332) || (ct->sector_size == 2336)) && + (ct->form >= 1)) + ct->skip = 8; + } else if (ct->sector_size >= 2332) { + can_read_pvd = image_can_read_pvd(ci->file, + ci->file_start * ct->sector_size, + ct->sector_size, 1); + if (can_read_pvd) { + ct->mode = can_read_pvd >> 4; + ct->form = can_read_pvd & 0xf; + if (((ct->sector_size == 2332) || (ct->sector_size == 2336)) && + (ct->form >= 1)) + ct->skip = 8; + } + } + + image_log(img->log, " NEW MODE: %02X/%02X\n", + ct->mode, ct->form); + } + break; + case 0xa0: + for (int j = 0; j < img->tracks_num; j++) { + track_t *jt = &(img->tracks[j]); + if ((jt->session == ct->session) && + (jt->point >= 1) && (jt->point <= 99)) { + lt = jt; + break; + } + } + + if (lt != NULL) { + int disc_type = 0x00; + + ct->attr = lt->attr; + + ct->mode = lt->mode; + ct->form = lt->form; + + if (lt->mode == 2) + disc_type = 0x20; + + for (int j = 0; j < 3; j++) { + ci = &(ct->idx[j]); + ci->type = INDEX_ZERO; + ci->start = (lt->point * 60 * 75) + (disc_type * 75); + ci->length = 0; + + image_log(img->log, " [TRACK ] %02X/%02X, INDEX %02X, " + "ATTR %02X, MODE %02X/%02X, %8s,\n", + ct->session, + ct->point, j, + ct->attr, + ct->mode, ct->form, + cit[ci->type + 2]); + image_log(img->log, " first track = %02X, " + "disc type = %02X\n", + lt->point, disc_type); + } + } + break; + case 0xa1: + for (int j = (img->tracks_num - 1); j >= 0; j--) { + track_t *jt = &(img->tracks[j]); + if ((jt->session == ct->session) && (jt->point >= 1) && (jt->point <= 99)) { + lt = jt; + break; + } + } + + if (lt != NULL) { + ct->attr = lt->attr; + + ct->mode = lt->mode; + ct->form = lt->form; + + for (int j = 0; j < 3; j++) { + ci = &(ct->idx[j]); + ci->type = INDEX_ZERO; + ci->start = (lt->point * 60 * 75); + ci->length = 0; + + image_log(img->log, " [TRACK ] %02X/%02X, INDEX %02X, " + "ATTR %02X, MODE %02X/%02X, %8s,\n", + ct->session, + ct->point, j, + ct->attr, + ct->mode, ct->form, + cit[ci->type + 2]); + image_log(img->log, " last track = %02X\n", + lt->point); + } + } + break; + case 0xa2: + if (lo[ct->session] != NULL) { + /* + We have a track to use for the calculation, first adjust the track's + attribute (ADR/Ctrl), mode, and form to match the last non-special track. + */ + lt = lo[ct->session]; + + ct->attr = lt->attr; + + ct->mode = lt->mode; + ct->form = lt->form; + + if (ct->idx[1].type != INDEX_NORMAL) { + /* + Index not normal, therefore, this is not a lead out track from a + second or afterwards session of a multi-session Cue sheet, calculate + the starting time and update all the indexes accordingly. + */ + const track_index_t *li = &(lt->idx[2]); + + for (int j = 0; j < 3; j++) { + image_log(img->log, " [TRACK ] %02X/%02X, INDEX %02X, " + "ATTR %02X, MODE %02X/%02X, %8s,\n", + ct->session, + ct->point, j, + ct->attr, + ct->mode, ct->form, + cit[ci->type + 2]); + + ci = &(ct->idx[j]); + ci->type = INDEX_ZERO; + ci->start = li->start + li->length; + ci->length = 0; + + image_log(img->log, " start = %016" PRIX64 + " (%2i:%02i:%02i)\n", + ci->start, + (int) ((ci->start / 75) / 60), + (int) ((ci->start / 75) % 60), + (int) (ci->start % 75)); + } + } +#ifdef ENABLE_IMAGE_LOG + else + image_log(img->log, " no start calculation done, " + "already specified\n"); +#endif + } +#ifdef ENABLE_IMAGE_LOG + else + image_log(img->log, " nothing done, no suitable last track " + "found\n"); +#endif + break; + case 0xb0: + /* + B0: MSF points to the beginning of the pre-gap + of the following session's first track. + */ + ct->extra[0] = (spg[ct->session + 1] / 75) / 60; + ct->extra[1] = (spg[ct->session + 1] / 75) % 60; + ct->extra[2] = spg[ct->session + 1] % 75; + + image_log(img->log, " [TRACK ] %02X/%02X, INDEX 01, " + "ATTR %02X, MODE %02X/%02X, %8s,\n", + ct->session, + ct->point, + ct->attr, + ct->mode, ct->form, + cit[ct->idx[1].type + 2]); + image_log(img->log, " %02X:%02X:%02X, %02X,\n", + ct->extra[0], ct->extra[1], ct->extra[2], ct->extra[3]); + + /* + B0 PMSF points to the start of the lead out track + of the last session. + */ + if (lo[ls] != NULL) { + lt = lo[ls]; + const track_index_t *li = &(lt->idx[2]); + + ct->idx[1].start = li->start + li->length; + + image_log(img->log, " start = %016" PRIX64 + " (%2i:%02i:%02i)\n", + ct->idx[1].start, + (int) ((ct->idx[1].start / 75) / 60), + (int) ((ct->idx[1].start / 75) % 60), + (int) (ct->idx[1].start % 75)); + } +#ifdef ENABLE_IMAGE_LOG + else + image_log(img->log, " no start calculation done, " + "no suitable last track found\n"); +#endif + break; + } + } + +#ifdef ENABLE_IMAGE_LOG + image_log(img->log, "Final tracks list:\n"); + for (int i = 0; i < img->tracks_num; i++) { + ct = &(img->tracks[i]); + for (int j = 0; j < 3; j++) { + ci = &(ct->idx[j]); + image_log(img->log, " [TRACK ] %02X INDEX %02X: [%8s, %016" PRIX64 "]\n", + ct->point, j, + cit[ci->type + 2], ci->file_start * ct->sector_size); + image_log(img->log, " TOC data: %02X %02X %02X " + "%%02X %02X %02X %02X 02X %02X %02X %02X\n", + ct->session, ct->attr, ct->tno, ct->point, + ct->extra[0], ct->extra[1], ct->extra[2], ct->extra[3], + (uint32_t) ((ci->start / 75) / 60), + (uint32_t) ((ci->start / 75) % 60), + (uint32_t) (ci->start % 75)); + } + } +#endif +} + +static void +image_set_track_subch_type(track_t *ct) +{ + if (ct->sector_size == 2448) + ct->subch_type = 0x08; + else if (ct->sector_size == 2368) + ct->subch_type = 0x10; + else + ct->subch_type = 0x00; +} + +static int +image_load_iso(cd_image_t *img, const char *filename) +{ + track_t *ct = NULL; + track_index_t *ci = NULL; + track_file_t *tf = NULL; + int success = 1; + int error = 1; + int is_viso = 0; + int sector_sizes[8] = { 2448, 2368, RAW_SECTOR_SIZE, 2336, + 2332, 2328, 2324, COOKED_SECTOR_SIZE }; + + img->tracks = NULL; + /* + Pass 1 - loading the ISO image. + */ + image_log(img->log, "Pass 1 (loading the ISO image)...\n"); + img->tracks_num = 0; + + image_insert_track(img, 1, 0xa0); + image_insert_track(img, 1, 0xa1); + image_insert_track(img, 1, 0xa2); + + /* Data track (shouldn't there be a lead in track?). */ + tf = index_file_init(img->dev->id, filename, &error, &is_viso); + + if (error) { + if (tf != NULL) { + tf->close(tf); + tf = NULL; + } + + success = 0; + } else if (is_viso) + success = 3; + + if (success) { + ct = image_insert_track(img, 1, 1); + ci = &(ct->idx[1]); + + ct->form = 0; + ct->mode = 0; + + for (int i = 0; i < 3; i++) + ct->idx[i].type = INDEX_NONE; + + ct->attr = DATA_TRACK; + + /* Try to detect ISO type. */ + ct->mode = 1; + ct->form = 0; + + ci->type = INDEX_NORMAL; + ci->file_start = 0ULL; + + ci->file = tf; + + for (int i = 0; i < 8; i++) { + ct->sector_size = sector_sizes[i]; + int can_read_pvd = image_can_read_pvd(ci->file, 0, ct->sector_size, 0); + if (can_read_pvd) { + ct->mode = can_read_pvd >> 4; + ct->form = can_read_pvd & 0xf; + if (((ct->sector_size == 2332) || (ct->sector_size == 2336)) && + (ct->form >= 1)) + ct->skip = 8; + break; + } else if (ct->sector_size >= 2332) { + can_read_pvd = image_can_read_pvd(ci->file, 0, ct->sector_size, 1); + if (can_read_pvd) { + ct->mode = can_read_pvd >> 4; + ct->form = can_read_pvd & 0xf; + if (((ct->sector_size == 2332) || (ct->sector_size == 2336)) && + (ct->form >= 1)) + ct->skip = 8; + break; + } + } + } + + image_set_track_subch_type(ct); + + image_log(img->log, " [TRACK ] %02X/%02X, ATTR %02X, MODE %02X/%02X,\n", + ct->session, + ct->point, + ct->attr, + ct->mode, ct->form); + image_log(img->log, " %02X:%02X:%02X, %02X, %i\n", + ct->sector_size); + } + + if (success) for (int i = 2; i >= 0; i--) { + if (ct->idx[i].file == NULL) + ct->idx[i].file = tf; + else + break; + } + + tf = NULL; + + if (success) + image_process(img); + else { + image_log(img->log, " [ISO ] Unable to open image or folder \"%s\"\n", + filename); + return 0; + } + + return success; +} + +static int +image_load_cue(cd_image_t *img, const char *cuefile) +{ + track_t *ct = NULL; + track_index_t *ci = NULL; + track_file_t *tf = NULL; + uint64_t frame = 0ULL; + uint64_t last = 0ULL; + uint8_t session = 1; + int last_t = -1; + int is_viso = 0; + int lead[3] = { 0 }; + int error; + char pathname[MAX_FILENAME_LENGTH]; + char buf[MAX_LINE_LENGTH]; + char *line; + char *command; + char *type; + char temp; + + img->tracks = NULL; + img->tracks_num = 0; + + /* Get a copy of the filename into pathname, we need it later. */ + memset(pathname, 0, MAX_FILENAME_LENGTH * sizeof(char)); + path_get_dirname(pathname, cuefile); + + /* Open the file. */ + FILE *fp = plat_fopen(cuefile, "r"); + if (fp == NULL) + return 0; + + int success = 0; + + /* + Pass 1 - loading the Cue sheet. + */ + image_log(img->log, "Pass 1 (loading the Cue sheet)...\n"); + img->tracks_num = 0; + + for (int i = 0; i < 3; i++) { + lead[i] = img->tracks_num; + (void) image_insert_track(img, session, 0xa0 + i); + } + + while (1) { + line = buf; + + /* Read a line from the cuesheet file. */ + if (feof(fp) || (fgets(buf, sizeof(buf), fp) == NULL) || ferror(fp)) + break; + + /* Do two iterations to make sure to nuke even if it's \r\n or \n\r, + but do checks to make sure we're not nuking other bytes. */ + for (uint8_t i = 0; i < 2; i++) { + if (strlen(buf) > 0) { + if (buf[strlen(buf) - 1] == '\n') + buf[strlen(buf) - 1] = '\0'; + /* nuke trailing newline */ + else if (buf[strlen(buf) - 1] == '\r') + buf[strlen(buf) - 1] = '\0'; + /* nuke trailing newline */ + } + } + image_log(img->log, " [LINE ] \"%s\"\n", line); + + (void) image_cue_get_keyword(&command, &line); + + if (!strcmp(command, "FILE")) { + /* The file for the track. */ + char filename[MAX_FILENAME_LENGTH]; + char ansi[MAX_FILENAME_LENGTH]; + + tf = NULL; + + memset(ansi, 0, MAX_FILENAME_LENGTH * sizeof(char)); + memset(filename, 0, MAX_FILENAME_LENGTH * sizeof(char)); + + success = image_cue_get_buffer(ansi, &line, 0); + if (!success) + break; + success = image_cue_get_keyword(&type, &line); + if (!success) + break; + + error = 1; + is_viso = 0; + + if (!strcmp(type, "BINARY") || !strcmp(type, "MOTOROLA")) { + if (!path_abs(ansi)) + path_append_filename(filename, pathname, ansi); + else + strcpy(filename, ansi); + + tf = index_file_init(img->dev->id, filename, &error, &is_viso); + + if (tf) + tf->motorola = !strcmp(type, "MOTOROLA"); + } else if (!strcmp(type, "WAVE") || !strcmp(type, "AIFF") || + !strcmp(type, "MP3")) { + if (!path_abs(ansi)) + path_append_filename(filename, pathname, ansi); + else + strcpy(filename, ansi); + tf = audio_init(img->dev->id, filename, &error); + } + if (error) { + if (tf != NULL) { + tf->close(tf); + tf = NULL; + } + success = 0; + } else if (is_viso) + success = 3; + +#ifdef ENABLE_IMAGE_LOG + if (!success) + image_log(img->log, " [FILE ] Unable to open file \"%s\" " + "specified in cue sheet\n", filename); +#endif + } else if (!strcmp(command, "TRACK")) { + int t = image_cue_get_number(&line); + success = image_cue_get_keyword(&type, &line); + + if (!success) + break; + + if (last_t != -1) { + /* + Important: This has to be done like this because pointers + change due to realloc. + */ + ct = &(img->tracks[t]); + + for (int i = 2; i >= 0; i--) { + if (ct->idx[i].file == NULL) + ct->idx[i].file = tf; + else + break; + } + } + + last_t = t; + ct = image_insert_track(img, session, t); + + ct->form = 0; + ct->mode = 0; + + if (!strcmp(type, "AUDIO")) { + ct->sector_size = RAW_SECTOR_SIZE; + ct->attr = AUDIO_TRACK; + } else if (!memcmp(type, "MODE", 4)) { + uint32_t mode; + ct->attr = DATA_TRACK; + sscanf(type, "MODE%" PRIu32 "/%" PRIu32, + &mode, &(ct->sector_size)); + ct->mode = mode; + if (ct->mode == 2) switch(ct->sector_size) { + default: + break; + case 2324: case 2328: + ct->form = 2; + break; + case 2048: case 2332: case 2336: case 2352: case 2368: case 2448: + ct->form = 1; + break; + } + if (((ct->sector_size == 2336) || (ct->sector_size == 2332)) && (ct->mode == 2) && (ct->form == 1)) + ct->skip = 8; + } else if (!memcmp(type, "CD", 2)) { + ct->attr = DATA_TRACK; + ct->mode = 2; + sscanf(type, "CD%c/%i", &temp, &(ct->sector_size)); + } else + success = 0; + + if (success) { + image_set_track_subch_type(ct); + + last = ct->sector_size; + + image_log(img->log, " [TRACK ] %02X/%02X, ATTR %02X, MODE %02X/%02X,\n", + ct->session, + ct->point, + ct->attr, + ct->mode, ct->form); + image_log(img->log, " %i\n", + ct->sector_size); + } +#ifdef ENABLE_IMAGE_LOG + else + image_log(img->log, " [TRACK ] Unable to initialize track %02X " + "specified in Cue sheet\n", t); +#endif + } else if (!strcmp(command, "INDEX")) { + int t = image_cue_get_number(&line); + ci = &(ct->idx[t]); + + ci->type = INDEX_NORMAL; + ci->file = tf; + success = image_cue_get_frame(&frame, &line); + ci->file_start = frame; + + image_log(img->log, " [INDEX ] %02X (%8s): Initialization %s\n", + t, cit[ci->type + 2], success ? "successful" : "failed"); + } else if (!strcmp(command, "PREGAP")) { + ci = &(ct->idx[0]); + + ci->type = INDEX_ZERO; + ci->file = tf; + success = image_cue_get_frame(&frame, &line); + ci->length = frame; + + image_log(img->log, " [INDEX ] 00 (%8s): Initialization %s\n", + cit[ci->type + 2], success ? "successful" : "failed"); + } else if (!strcmp(command, "PAUSE") || !strcmp(command, "ZERO")) { + ci = &(ct->idx[1]); + + ci->type = INDEX_ZERO; + ci->file = tf; + success = image_cue_get_frame(&frame, &line); + ci->length = frame; + + image_log(img->log, " [INDEX ] 01 (%8s): Initialization %s\n", + cit[ci->type + 2], success ? "successful" : "failed"); + } else if (!strcmp(command, "POSTGAP")) { + ci = &(ct->idx[2]); + + ci->type = INDEX_ZERO; + ci->file = tf; + success = image_cue_get_frame(&frame, &line); + ci->length = frame; + + image_log(img->log, " [INDEX ] 02 (%8s): Initialization %s\n", + cit[ci->type + 2], success ? "successful" : "failed"); + } else if (!strcmp(command, "FLAGS")) { + success = image_cue_get_flags(ct, &line); + + image_log(img->log, " [FLAGS ] Initialization %s\n", + success ? "successful" : "failed"); + } else if (!strcmp(command, "REM")) { + success = 1; + char *space = strstr(line, " "); + if (space != NULL) { + space++; + if (space < (line + strlen(line))) { + (void) image_cue_get_keyword(&command, &space); + if (!strcmp(command, "LEAD-OUT")) { + ct = &(img->tracks[lead[2]]); + /* + Mark it this way so file pointers on it are not + going to be adjusted. + */ + last_t = -1; + ct->sector_size = last; + ci = &(ct->idx[1]); + ci->type = INDEX_NORMAL; + ci->file = tf; + success = image_cue_get_frame(&frame, &space); + ci->file_start = frame; + + image_log(img->log, " [LEAD-OUT] Initialization %s\n", + success ? "successful" : "failed"); + } else if (!strcmp(command, "SESSION")) { + session = image_cue_get_number(&space); + + if (session > 1) { + ct = image_insert_track(img, session - 1, 0xb0); + /* + Mark it this way so file pointers on it are not + going to be adjusted. + */ + last_t = -1; + ci = &(ct->idx[1]); + ci->start = (0x40 * 60 * 75) + (0x02 * 75); + + if (session == 2) { + ct->extra[3] = 0x02; + + /* + 00:00:00 on Wembley, C0:00:00 in the spec. + And what's in PMSF? + */ + ct = image_insert_track(img, session - 1, 0xc0); + /* + Mark it this way so file pointers on it are not + going to be adjusted. + */ + last_t = -1; + ci = &(ct->idx[1]); + /* Queen - Live at Wembley '86 CD 1. */ + ci->start = (0x5f * 75 * 60); + /* Optimum recording power. */ + ct->extra[0] = 0x00; + } else + ct->extra[3] = 0x01; + + for (int i = 0; i < 3; i++) { + lead[i] = img->tracks_num; + (void) image_insert_track(img, session, 0xa0 + i); + } + } + + image_log(img->log, " [SESSION ] Initialization successful\n"); + } + } + } + } else if (!strcmp(command, "CATALOG") || !strcmp(command, "CDTEXTFILE") || + !strcmp(command, "ISRC") || !strcmp(command, "PERFORMER") || + !strcmp(command, "SONGWRITER") || !strcmp(command, "TITLE") || + !strcmp(command, "")) { + /* Ignored commands. */ + image_log(img->log, " [CUE ] Ignored command \"%s\" in Cue sheet\n", + command); + success = 1; + } else { + image_log(img->log, " [CUE ] Unsupported command \"%s\" in Cue sheet\n", + command); + success = 0; + } + + if (!success) + break; + } + + if (success && (ct != NULL)) for (int i = 2; i >= 0; i--) { + if (ct->idx[i].file == NULL) + ct->idx[i].file = tf; + else + break; + } + + tf = NULL; + + fclose(fp); + + if (success) + image_process(img); + else { + image_log(img->log, " [CUE ] Unable to open Cue sheet \"%s\"\n", cuefile); + return 0; + } + + return success; +} + +/* Root functions. */ +static void +image_clear_tracks(cd_image_t *img) +{ + const track_file_t *last = NULL; + track_t *cur = NULL; + track_index_t *idx = NULL; + + if ((img->tracks != NULL) && (img->tracks_num > 0)) { + for (int i = 0; i < img->tracks_num; i++) { + cur = &img->tracks[i]; + + if (((cur->point >= 1) && (cur->point <= 99)) || + (cur->point == 0xa2)) for (int j = 0; j < 3; j++) { + idx = &(cur->idx[j]); + /* Make sure we do not attempt to close a NULL file. */ + if ((idx->file != NULL) && (idx->type == INDEX_NORMAL)) { + if (idx->file != last) { + last = idx->file; + index_file_close(idx); + } else + idx->file = NULL; + } + } + } + + /* Now free the array. */ + free(img->tracks); + img->tracks = NULL; + + /* Mark that there's no tracks. */ + img->tracks_num = 0; + } +} + +/* Shared functions. */ +static int +image_get_track_info(const void *local, const uint32_t track, + const int end, track_info_t *ti) +{ + const cd_image_t *img = (const cd_image_t *) local; + const track_t *ct = NULL; + int ret = 0; for (int i = 0; i < img->tracks_num; i++) { ct = &(img->tracks[i]); @@ -70,238 +1712,329 @@ image_get_track_info(cdrom_t *dev, uint32_t track, int end, track_info_t *ti) break; } - ti->number = ct->point; + if (ct != NULL) { + const uint32_t pos = end ? ct->idx[1].start : + (ct->idx[1].start + ct->idx[1].length); - if (ct == NULL) { - ti->attr = 0x14; - ti->m = 0; - ti->s = 2; - ti->f = 0; - } else { - uint32_t pos = end ? ct->idx[1].start : (ct->idx[1].start + ct->idx[1].length); - ti->attr = ct->attr; - ti->m = (pos / 75) / 60; - ti->s = (pos / 75) % 60; - ti->f = pos % 75; + ti->number = ct->point; + ti->attr = ct->attr; + ti->m = (pos / 75) / 60; + ti->s = (pos / 75) % 60; + ti->f = pos % 75; + + ret = 1; } + + return ret; } static void -image_get_raw_track_info(cdrom_t *dev, int *num, raw_track_info_t *rti) +image_get_raw_track_info(const void *local, int *num, uint8_t *buffer) { - cdi_get_raw_track_info((cd_img_t *) dev->local, num, (uint8_t *) rti); -} + const cd_image_t *img = (const cd_image_t *) local; + int len = 0; -static void -image_get_subchannel(cdrom_t *dev, uint32_t lba, subchannel_t *subc) -{ - cd_img_t *img = (cd_img_t *) dev->local; - TMSF rel_pos; - TMSF abs_pos; + image_log(img->log, "img->tracks_num = %i\n", img->tracks_num); - cdi_get_audio_sub(img, lba, &subc->attr, &subc->track, &subc->index, - &rel_pos, &abs_pos); + for (int i = 0; i < img->tracks_num; i++) { + const track_t *ct = &(img->tracks[i]); +#ifdef ENABLE_IMAGE_LOG + int old_len = len; +#endif + buffer[len++] = ct->session; /* Session number. */ + buffer[len++] = ct->attr; /* Track ADR and Control. */ + buffer[len++] = ct->tno; /* TNO (always 0). */ + buffer[len++] = ct->point; /* Point (track number). */ + for (int j = 0; j < 4; j++) + buffer[len++] = ct->extra[j]; + buffer[len++] = (ct->idx[1].start / 75) / 60; + buffer[len++] = (ct->idx[1].start / 75) % 60; + buffer[len++] = ct->idx[1].start % 75; + image_log(img->log, "%i: %02X %02X %02X %02X %02X %02X %02X\n", i, + buffer[old_len], buffer[old_len + 1], + buffer[old_len + 2], buffer[old_len + 3], + buffer[old_len + 8], buffer[old_len + 9], + buffer[old_len + 10]); + } - subc->abs_m = abs_pos.min; - subc->abs_s = abs_pos.sec; - subc->abs_f = abs_pos.fr; - - subc->rel_m = rel_pos.min; - subc->rel_s = rel_pos.sec; - subc->rel_f = rel_pos.fr; - - cdrom_image_log("image_get_subchannel(): %02X, %02X, %02i, %02i:%02i:%02i, %02i:%02i:%02i\n", - subc->attr, subc->track, subc->index, subc->abs_m, subc->abs_s, subc->abs_f, - subc->rel_m, subc->rel_s, subc->rel_f); + *num = img->tracks_num; } static int -image_get_capacity(cdrom_t *dev) +image_is_track_pre(const void *local, const uint32_t sector) { - cd_img_t *img = (cd_img_t *) dev->local; - uint32_t lb = 0; - track_t *lo = NULL; + const cd_image_t *img = (const cd_image_t *) local; + int ret = 0; - if (!img) - return 0; + if (img->has_audio) { + const int track = image_get_track(img, sector); - for (int i = (img->tracks_num - 1); i >= 0; i--) { - if (img->tracks[i].point == 0xa2) { - lo = &(img->tracks[i]); - break; + if (track >= 0) { + const track_t *trk = &(img->tracks[track]); + + ret = !!(trk->attr & 0x01); } } - if (lo != NULL) - lb = lo->idx[1].start - 1; + return ret; +} + +static int +image_read_sector(const void *local, uint8_t *buffer, + const uint32_t sector) +{ + const cd_image_t *img = (const cd_image_t *) local; + int m = 0; + int s = 0; + int f = 0; + int ret = 0; + uint32_t lba = sector; + int track; + int index; + uint8_t q[16] = { 0x00 }; + + if (sector == 0xffffffff) + lba = img->dev->seek_pos; + + const uint64_t sect = (uint64_t) lba; + + image_get_track_and_index(img, lba, &track, &index); + + const track_t *trk = &(img->tracks[track]); + const track_index_t *idx = &(trk->idx[index]); + const int track_is_raw = ((trk->sector_size == RAW_SECTOR_SIZE) || + (trk->sector_size == 2448)); + const uint64_t seek = ((sect + 150 - idx->start + idx->file_start) * + trk->sector_size) + trk->skip; + + if (track >= 0) { + /* Signal CIRC error to the guest if sector is bad. */ + ret = image_is_sector_bad(img, lba) ? -1 : 1; + + if (ret > 0) { + uint64_t offset = 0ULL; + + image_log(img->log, "cdrom_read_sector(%08X): track %02X, index %02X, %016" + PRIX64 ", %i, %i, %i, %i\n", + lba, track, index, idx->start, trk->sector_size, track_is_raw, + trk->mode, trk->form); + + memset(buffer, 0x00, 2448); + + if ((trk->attr & 0x04) && ((idx->type < INDEX_NORMAL) || !track_is_raw)) { + offset += 16ULL; + + /* Construct the header. */ + memset(buffer + 1, 0xff, 10); + buffer += 12; + FRAMES_TO_MSF(sector + 150, &m, &s, &f); + /* These have to be BCD. */ + buffer[0] = bin2bcd(m & 0xff); + buffer[1] = bin2bcd(s & 0xff); + buffer[2] = bin2bcd(f & 0xff); + /* Data, should reflect the actual sector type. */ + buffer[3] = trk->mode; + buffer += 4; + if (trk->form >= 1) { + offset += 8ULL; + + /* Construct the CD-I/XA sub-header. */ + buffer[2] = buffer[6] = (trk->form - 1) << 5; + buffer += 8; + } + } + + if (idx->type >= INDEX_NORMAL) { + /* Read the data from the file. */ + ret = idx->file->read(idx->file, buffer, seek, trk->sector_size); + } else + /* Index is not in the file, no read to fail here. */ + ret = 1; + + if ((ret > 0) && ((idx->type < INDEX_NORMAL) || (trk->subch_type != 0x08))) { + buffer -= offset; + + if (trk->subch_type == 0x10) + memcpy(q, &(buffer[2352]), 12); + else { + /* Construct Q. */ + q[0] = (trk->attr >> 4) | ((trk->attr & 0xf) << 4); + q[1] = bin2bcd(trk->point); + q[2] = index; + if (index == 0) { + /* + Pre-gap sector relative frame addresses count from + 00:01:74 downwards. + */ + FRAMES_TO_MSF((int32_t) (149 - (lba + 150 - idx->start)), &m, &s, &f); + } else { + FRAMES_TO_MSF((int32_t) (lba + 150 - idx->start), &m, &s, &f); + } + q[3] = bin2bcd(m & 0xff); + q[4] = bin2bcd(s & 0xff); + q[5] = bin2bcd(f & 0xff); + FRAMES_TO_MSF(lba + 150, &m, &s, &f); + q[7] = bin2bcd(m & 0xff); + q[8] = bin2bcd(s & 0xff); + q[9] = bin2bcd(f & 0xff); + } + + /* Construct raw subchannel data from Q only. */ + for (int i = 0; i < 12; i++) + for (int j = 0; j < 8; j++) + buffer[2352 + (i << 3) + j] = ((q[i] >> (7 - j)) & 0x01) << 6; + } + } + } + + return ret; +} + +static uint8_t +image_get_track_type(const void *local, const uint32_t sector) +{ + const cd_image_t *img = (cd_image_t *) local; + const int track = image_get_track(img, sector); + const track_t * trk = &(img->tracks[track]); + int ret = 0x00; + + if (image_is_track_audio(img, sector)) + ret = CD_TRACK_AUDIO; + else if (track >= 0) for (int i = 0; i < img->tracks_num; i++) { + const track_t *ct = &(img->tracks[i]); + const track_t *nt = &(img->tracks[i + 1]); + + if (ct->point == 0xa0) { + const uint8_t first = (ct->idx[1].start / 75 / 60); + const uint8_t last = (nt->idx[1].start / 75 / 60); + + if ((trk->point >= first) && (trk->point <= last)) { + ret = (ct->idx[1].start / 75) % 60; + break; + } + } + } + + return ret; +} + +static uint32_t +image_get_last_block(const void *local) +{ + const cd_image_t *img = (const cd_image_t *) local; + uint32_t lb = 0x00000000; + + if (img != NULL) { + const track_t *lo = NULL; + + for (int i = (img->tracks_num - 1); i >= 0; i--) { + if (img->tracks[i].point == 0xa2) { + lo = &(img->tracks[i]); + break; + } + } + + if (lo != NULL) + lb = lo->idx[1].start - 1; + } return lb; } static int -image_is_track_audio(cdrom_t *dev, uint32_t pos, int ismsf) -{ - cd_img_t *img = (cd_img_t *) dev->local; - int m; - int s; - int f; - - if (!img || (dev->cd_status == CD_STATUS_DATA_ONLY)) - return 0; - - if (ismsf) { - m = (pos >> 16) & 0xff; - s = (pos >> 8) & 0xff; - f = pos & 0xff; - pos = MSFtoLBA(m, s, f) - 150; - } - - return cdi_is_audio(img, pos); -} - -static int -image_is_track_pre(cdrom_t *dev, uint32_t lba) -{ - cd_img_t *img = (cd_img_t *) dev->local; - - if (!img || (dev->cd_status == CD_STATUS_DATA_ONLY)) - return 0; - - return cdi_is_pre(img, lba); -} - -static int -image_sector_size(struct cdrom *dev, uint32_t lba) -{ - cd_img_t *img = (cd_img_t *) dev->local; - - return cdi_get_sector_size(img, lba); -} - -static int -image_read_sector(struct cdrom *dev, uint8_t *b, uint32_t lba) -{ - cd_img_t *img = (cd_img_t *) dev->local; - - if (cdi_get_sector_size(img, lba) <= 2352) - return cdi_read_sector(img, b, 1, lba); - else - return cdi_read_sector_sub(img, b, lba); -} - -static int -image_track_type(cdrom_t *dev, uint32_t lba) -{ - cd_img_t *img = (cd_img_t *) dev->local; - - if (img) { - if (image_is_track_audio(dev, lba, 0)) - return CD_TRACK_AUDIO; - else if (cdi_is_mode2(img, lba)) - return CD_TRACK_MODE2 | cdi_get_mode2_form(img, lba); - } - - return 0; -} - -static int -image_ext_medium_changed(cdrom_t *dev) +image_read_dvd_structure(const void *local, const uint8_t layer, const uint8_t format, + uint8_t *buffer, uint32_t *info) { return 0; } +static int +image_is_dvd(const void *local) +{ + const cd_image_t *img = (const cd_image_t *) local; + + return img->is_dvd; +} + +static int +image_has_audio(const void *local) +{ + const cd_image_t *img = (const cd_image_t *) local; + + return img->has_audio; +} + static void -image_exit(cdrom_t *dev) +image_close(void *local) { - cd_img_t *img = (cd_img_t *) dev->local; + cd_image_t *img = (cd_image_t *) local; - cdrom_image_log("CDROM: image_exit(%s)\n", dev->image_path); - dev->cd_status = CD_STATUS_EMPTY; + if (img != NULL) { + image_clear_tracks(img); - if (img) { - cdi_close(img); - dev->local = NULL; + image_log(img->log, "Log closed\n"); + + log_close(img->log); + img->log = NULL; + + free(img); } - - dev->ops = NULL; } -static const cdrom_ops_t cdrom_image_ops = { +static const cdrom_ops_t image_ops = { image_get_track_info, image_get_raw_track_info, - image_get_subchannel, image_is_track_pre, - image_sector_size, image_read_sector, - image_track_type, - image_ext_medium_changed, - image_exit + image_get_track_type, + image_get_last_block, + image_read_dvd_structure, + image_is_dvd, + image_has_audio, + NULL, + image_close, + NULL }; -static int -image_open_abort(cdrom_t *dev) +/* Public functions. */ +void * +image_open(cdrom_t *dev, const char *path) { - cdrom_image_close(dev); - dev->ops = NULL; - dev->image_path[0] = 0; - return 1; -} - -int -cdrom_image_open(cdrom_t *dev, const char *fn) -{ - cd_img_t *img; - - /* Make sure to not STRCPY if the two are pointing - at the same place. */ - if (fn != dev->image_path) - strcpy(dev->image_path, fn); - - /* Create new instance of the CDROM_Image class. */ - img = (cd_img_t *) calloc(1, sizeof(cd_img_t)); - - /* This guarantees that if ops is not NULL, then - neither is the image pointer. */ - if (img == NULL) - return image_open_abort(dev); - - dev->local = img; - - /* Open the image. */ - int i = cdi_set_device(img, fn); - if (!i) - return image_open_abort(dev); - - /* All good, reset state. */ - if (i >= 2) - dev->cd_status = CD_STATUS_DATA_ONLY; - else - dev->cd_status = CD_STATUS_STOPPED; - dev->seek_pos = 0; - dev->cd_buflen = 0; - dev->cdrom_capacity = image_get_capacity(dev); - cdrom_image_log("CD-ROM capacity: %i sectors (%" PRIi64 " bytes)\n", dev->cdrom_capacity, - ((uint64_t) dev->cdrom_capacity) << 11ULL); -#ifdef ENABLE_CDROM_IMAGE_LOG - int cm, cs, cf; - cf = dev->cdrom_capacity % 75; - cs = (dev->cdrom_capacity / 75) % 60; - cm = (dev->cdrom_capacity / 75) / 60; - cdrom_image_log("CD-ROM capacity: %i sectors (%" PRIi64 " bytes) (time: %02i:%02i:%02i)\n", - dev->cdrom_capacity, ((uint64_t) dev->cdrom_capacity - 150ULL) * 2352ULL, cm, cs, cf); -#endif - - /* 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(%s)\n", dev->image_path); - - if (dev && dev->ops && dev->ops->exit) - dev->ops->exit(dev); + const uintptr_t ext = path + strlen(path) - strrchr(path, '.'); + cd_image_t *img = (cd_image_t *) calloc(1, sizeof(cd_image_t)); + + if (img != NULL) { + int ret; + const int is_cue = ((ext == 4) && !stricmp(path + strlen(path) - ext + 1, "CUE")); + + img->dev = dev; + + if (is_cue) { + ret = image_load_cue(img, path); + + if (ret >= 2) + img->has_audio = 0; + else if (ret) + img->has_audio = 1; + } else { + ret = image_load_iso(img, path); + + if (!ret) { + image_close(img); + img = NULL; + } else + img->has_audio = 0; + } + + if (ret) { + char n[1024] = { 0 }; + + sprintf(n, "CD-ROM %i Image", dev->id + 1); + img->log = log_open(n); + + dev->ops = &image_ops; + } + } + + return img; } diff --git a/src/cdrom/cdrom_image_backend.c b/src/cdrom/cdrom_image_backend.c deleted file mode 100644 index 9d065a0cb..000000000 --- a/src/cdrom/cdrom_image_backend.c +++ /dev/null @@ -1,1499 +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. - * - * CD-ROM image file handling module. - * - * Authors: Miran Grca, - * RichardG, - * Cacodemon345 - * - * Copyright 2016-2025 Miran Grca. - * Copyright 2016-2025 Miran Grca. - * Copyright 2024-2025 Cacodemon345. - */ -#define __STDC_FORMAT_MACROS -#include -#include -#include -#include -#include -#include -#include -#include -#ifdef _WIN32 -# include -# include -#else -# include -#endif -#define HAVE_STDARG_H -#include <86box/86box.h> -#include <86box/path.h> -#include <86box/plat.h> -#include <86box/cdrom_image_backend.h> - -#include - -#define CDROM_BCD(x) (((x) % 10) | (((x) / 10) << 4)) - -#define MAX_LINE_LENGTH 512 -#define MAX_FILENAME_LENGTH 256 -#define CROSS_LEN 512 - -static char temp_keyword[1024]; - -#ifdef ENABLE_CDROM_IMAGE_BACKEND_LOG -int cdrom_image_backend_do_log = ENABLE_CDROM_IMAGE_BACKEND_LOG; - -void -cdrom_image_backend_log(const char *fmt, ...) -{ - va_list ap; - - if (cdrom_image_backend_do_log) { - va_start(ap, fmt); - pclog_ex(fmt, ap); - va_end(ap); - } -} -#else -# define cdrom_image_backend_log(fmt, ...) -#endif - -typedef struct audio_file_t { - SNDFILE *file; - SF_INFO info; -} audio_file_t; - -/* Audio file functions */ -static int -audio_read(void *priv, uint8_t *buffer, uint64_t seek, size_t count) -{ - track_file_t *tf = (track_file_t *) priv; - audio_file_t *audio = (audio_file_t *) tf->priv; - uint64_t samples_seek = seek / 4; - uint64_t samples_count = count / 4; - - if ((seek & 3) || (count & 3)) { - cdrom_image_backend_log("CD Audio file: Reading on non-4-aligned boundaries.\n"); - } - - sf_count_t res = sf_seek(audio->file, samples_seek, SEEK_SET); - - if (res == -1) - return 0; - - return !!sf_readf_short(audio->file, (short *) buffer, samples_count); -} - -static uint64_t -audio_get_length(void *priv) -{ - track_file_t *tf = (track_file_t *) priv; - audio_file_t *audio = (audio_file_t *) tf->priv; - - /* Assume 16-bit audio, 2 channel. */ - return audio->info.frames * 4ull; -} - -static void -audio_close(void *priv) -{ - track_file_t *tf = (track_file_t *) priv; - audio_file_t *audio = (audio_file_t *) tf->priv; - - memset(tf->fn, 0x00, sizeof(tf->fn)); - if (audio && audio->file) - sf_close(audio->file); - free(audio); - free(tf); -} - -static track_file_t * -audio_init(const char *filename, int *error) -{ - track_file_t *tf = (track_file_t *) calloc(sizeof(track_file_t), 1); - audio_file_t *audio = (audio_file_t *) calloc(sizeof(audio_file_t), 1); -#ifdef _WIN32 - wchar_t filename_w[4096]; -#endif - - if (tf == NULL || audio == NULL) { - goto cleanup_error; - } - - memset(tf->fn, 0x00, sizeof(tf->fn)); - strncpy(tf->fn, filename, sizeof(tf->fn) - 1); -#ifdef _WIN32 - mbstowcs(filename_w, filename, 4096); - audio->file = sf_wchar_open(filename_w, SFM_READ, &audio->info); -#else - audio->file = sf_open(filename, SFM_READ, &audio->info); -#endif - - if (!audio->file) { - cdrom_image_backend_log("Audio file open error!"); - goto cleanup_error; - } - - if (audio->info.channels != 2 || audio->info.samplerate != 44100 || !audio->info.seekable) { - cdrom_image_backend_log("Audio file not seekable or in non-CD format!"); - sf_close(audio->file); - goto cleanup_error; - } - - *error = 0; - tf->priv = audio; - tf->fp = NULL; - tf->close = audio_close; - tf->get_length = audio_get_length; - tf->read = audio_read; - return tf; -cleanup_error: - free(tf); - free(audio); - *error = 1; - return NULL; -} - -/* Binary file functions. */ -static int -bin_read(void *priv, uint8_t *buffer, uint64_t seek, size_t count) -{ - track_file_t *tf = NULL; - - if ((tf = (track_file_t *) priv)->fp == NULL) - return 0; - - cdrom_image_backend_log("CDROM: binary_read(%08lx, pos=%" PRIu64 " count=%lu)\n", - tf->fp, seek, count); - - if (fseeko64(tf->fp, seek, SEEK_SET) == -1) { - cdrom_image_backend_log("CDROM: binary_read failed during seek!\n"); - - return -1; - } - - if (fread(buffer, count, 1, tf->fp) != 1) { - cdrom_image_backend_log("CDROM: binary_read failed during read!\n"); - - return -1; - } - - if (UNLIKELY(tf->motorola)) { - for (uint64_t i = 0; i < count; i += 2) { - uint8_t buffer0 = buffer[i]; - uint8_t buffer1 = buffer[i + 1]; - buffer[i] = buffer1; - buffer[i + 1] = buffer0; - } - } - - return 1; -} - -static uint64_t -bin_get_length(void *priv) -{ - track_file_t *tf = NULL; - - if ((tf = (track_file_t *) priv)->fp == NULL) - return 0; - - fseeko64(tf->fp, 0, SEEK_END); - const off64_t len = ftello64(tf->fp); - cdrom_image_backend_log("CDROM: binary_length(%08lx) = %" PRIu64 "\n", tf->fp, len); - - return len; -} - -static void -bin_close(void *priv) -{ - track_file_t *tf = (track_file_t *) priv; - - if (tf == NULL) - return; - - if (tf->fp != NULL) { - fclose(tf->fp); - tf->fp = NULL; - } - - memset(tf->fn, 0x00, sizeof(tf->fn)); - - free(priv); -} - -static track_file_t * -bin_init(const char *filename, int *error) -{ - track_file_t *tf = (track_file_t *) calloc(1, sizeof(track_file_t)); - struct stat stats; - - if (tf == NULL) { - *error = 1; - return NULL; - } - - memset(tf->fn, 0x00, sizeof(tf->fn)); - strncpy(tf->fn, filename, sizeof(tf->fn) - 1); - tf->fp = plat_fopen64(tf->fn, "rb"); - cdrom_image_backend_log("CDROM: binary_open(%s) = %08lx\n", tf->fn, tf->fp); - - if (stat(tf->fn, &stats) != 0) { - /* Use a blank structure if stat failed. */ - memset(&stats, 0, sizeof(struct stat)); - } - *error = ((tf->fp == NULL) || ((stats.st_mode & S_IFMT) == S_IFDIR)); - - /* Set the function pointers. */ - if (!*error) { - tf->read = bin_read; - tf->get_length = bin_get_length; - tf->close = bin_close; - } else { - /* From the check above, error may still be non-zero if opening a directory. - * The error is set for viso to try and open the directory following this function. - * However, we need to make sure the descriptor is closed. */ - if ((tf->fp != NULL) && ((stats.st_mode & S_IFMT) == S_IFDIR)) { - /* tf is freed by bin_close */ - bin_close(tf); - } else - free(tf); - tf = NULL; - } - - return tf; -} - -static track_file_t * -track_file_init(const char *filename, int *error, int *is_viso) -{ - track_file_t *tf; - - *is_viso = 0; - - /* Current we only support .BIN files, either combined or one per - track. In the future, more is planned. */ - tf = bin_init(filename, error); - - if (*error) { - if ((tf != NULL) && (tf->close != NULL)) { - tf->close(tf); - tf = NULL; - } - - tf = viso_init(filename, error); - - if (!*error) - *is_viso = 1; - } - - return tf; -} - -static void -index_file_close(track_index_t *idx) -{ - if (idx == NULL) - return; - - if (idx->file == NULL) - return; - - if (idx->file->close == NULL) - return; - - idx->file->close(idx->file); - idx->file = NULL; -} - -void -cdi_get_raw_track_info(cd_img_t *cdi, int *num, uint8_t *buffer) -{ - int len = 0; - - cdrom_image_backend_log("cdi->tracks_num = %i\n", cdi->tracks_num); - - for (int i = 0; i < cdi->tracks_num; i++) { - track_t *ct = &(cdi->tracks[i]); -#ifdef ENABLE_CDROM_IMAGE_BACKEND_LOG - int old_len = len; -#endif - buffer[len++] = ct->session; /* Session number */ - buffer[len++] = ct->attr; /* Track ADR and Control */ - buffer[len++] = ct->tno; /* TNO (always 0) */ - buffer[len++] = ct->point; /* Point (for track points - track number) */ - for (int j = 0; j < 4; j++) - buffer[len++] = ct->extra[j]; - buffer[len++] = (ct->idx[1].start / 75) / 60; - buffer[len++] = (ct->idx[1].start / 75) % 60; - buffer[len++] = ct->idx[1].start % 75; - cdrom_image_backend_log("%i: %02X %02X %02X %02X %02X %02X %02X\n", i, - buffer[old_len], buffer[old_len + 1], buffer[old_len + 2], buffer[old_len + 3], - buffer[old_len + 8], buffer[old_len + 9], buffer[old_len + 10]); - } - - *num = cdi->tracks_num; -} - -static int -cdi_get_track(cd_img_t *cdi, uint32_t sector) -{ - int ret = -1; - - for (int i = 0; i < cdi->tracks_num; i++) { - track_t *ct = &(cdi->tracks[i]); - for (int j = 0; j < 3; j++) { - track_index_t *ci = &(ct->idx[j]); - if (((sector + 150) >= ci->start) && ((sector + 150) <= (ci->start + ci->length - 1))) { - ret = i; - break; - } - } - } - - return ret; -} - -static void -cdi_get_track_and_index(cd_img_t *cdi, uint32_t sector, int *track, int *index) -{ - *track = -1; - *index = -1; - - for (int i = 0; i < cdi->tracks_num; i++) { - track_t *ct = &(cdi->tracks[i]); - for (int j = 0; j < 3; j++) { - track_index_t *ci = &(ct->idx[j]); - if (((sector + 150) >= ci->start) && ((sector + 150) <= (ci->start + ci->length - 1))) { - *track = i; - *index = j; - break; - } - } - } -} - -/* TODO: See if track start is adjusted by 150 or not. */ -int -cdi_get_audio_sub(cd_img_t *cdi, uint32_t sector, uint8_t *attr, uint8_t *track, uint8_t *index, TMSF *rel_pos, TMSF *abs_pos) -{ - int cur_track = cdi_get_track(cdi, sector); - - if (cur_track < 1) - return 0; - - *track = (uint8_t) cur_track; - const track_t *trk = &cdi->tracks[*track]; - *attr = trk->attr; - *index = 1; - - /* Absolute position should be adjusted by 150, not the relative ones. */ - FRAMES_TO_MSF(sector + 150, &abs_pos->min, &abs_pos->sec, &abs_pos->fr); - - /* Relative position is relative Index 1 start - pre-gap values will be negative. */ - FRAMES_TO_MSF((int32_t) (sector + 150 - trk->idx[1].start), &rel_pos->min, &rel_pos->sec, &rel_pos->fr); - - return 1; -} - -static __inline int -bin2bcd(int x) -{ - return (x % 10) | ((x / 10) << 4); -} - -int -cdi_read_sector(cd_img_t *cdi, uint8_t *buffer, int raw, uint32_t sector) -{ - const uint64_t sect = (uint64_t) sector; - int m = 0; - int s = 0; - int f = 0; - int ret = 0; - uint64_t offset = 0ULL; - int track; - int index; - int raw_size; - int cooked_size; - uint8_t q[16] = { 0x00 }; - - cdi_get_track_and_index(cdi, sector, &track, &index); - - if (track < 0) - return 0; - - const track_t *trk = &(cdi->tracks[track]); - const track_index_t *idx = &(trk->idx[index]); - const int track_is_raw = ((trk->sector_size == RAW_SECTOR_SIZE) || (trk->sector_size == 2448)); - const uint64_t seek = (sect + 150 - idx->start + idx->file_start) * trk->sector_size; - - cdrom_image_backend_log("cdrom_read_sector(%08X): track %02X, index %02X, %016" PRIX64 ", %016" PRIX64 ", %i\n", - sector, track, index, idx->start, trk->sector_size); - - if (track_is_raw) - raw_size = trk->sector_size; - else - raw_size = 2448; - - if ((trk->mode == 2) && (trk->form != 1)) { - if (trk->form == 2) - cooked_size = (track_is_raw ? 2328 : trk->sector_size); /* Both 2324 + ECC and 2328 variants are valid. */ - else - cooked_size = 2336; - } else - cooked_size = COOKED_SECTOR_SIZE; - - if ((trk->mode == 2) && (trk->form >= 1)) - offset = 24ULL; - else - offset = 16ULL; - - if (idx->type < INDEX_NORMAL) { - memset(buffer, 0x00, 2448); - if (trk->attr & 0x04) { - /* Construct the rest of the raw sector. */ - memset(buffer + 1, 0xff, 10); - buffer += 12; - FRAMES_TO_MSF(sector + 150, &m, &s, &f); - /* These have to be BCD. */ - buffer[0] = CDROM_BCD(m & 0xff); - buffer[1] = CDROM_BCD(s & 0xff); - buffer[2] = CDROM_BCD(f & 0xff); - /* Data, should reflect the actual sector type. */ - buffer[3] = trk->mode; - ret = 1; - } - } else if (raw && !track_is_raw) { - memset(buffer, 0x00, 2448); - /* We are doing a raw read but the track is cooked, length should be cooked size. */ - const int temp = idx->file->read(idx->file, buffer + offset, seek, cooked_size); - if (temp <= 0) - return temp; - if (trk->attr & 0x04) { - /* Construct the rest of the raw sector. */ - memset(buffer + 1, 0xff, 10); - buffer += 12; - FRAMES_TO_MSF(sector + 150, &m, &s, &f); - /* These have to be BCD. */ - buffer[0] = CDROM_BCD(m & 0xff); - buffer[1] = CDROM_BCD(s & 0xff); - buffer[2] = CDROM_BCD(f & 0xff); - /* Data, should reflect the actual sector type. */ - buffer[3] = trk->mode; - ret = 1; - } - } else if (!raw && track_is_raw) - /* The track is raw but we are doing a cooked read, length should be cooked size. */ - return idx->file->read(idx->file, buffer, seek + offset, cooked_size); - else { - /* The track is raw and we are doing a raw read, length should be raw size. */ - ret = idx->file->read(idx->file, buffer, seek, raw_size); - if (raw && (raw_size == 2448)) - return ret; - } - - /* Construct Q. */ - q[0] = (trk->attr >> 4) | ((trk->attr & 0xf) << 4); - q[1] = bin2bcd(trk->point); - q[2] = index; - if (index == 0) { - /* Pre-gap sector relative frame addresses count from 00:01:74 downwards. */ - FRAMES_TO_MSF((int32_t) (149 - (sector + 150 - idx->start)), &m, &s, &f); - } else { - FRAMES_TO_MSF((int32_t) (sector + 150 - idx->start), &m, &s, &f); - } - q[3] = bin2bcd(m); - q[4] = bin2bcd(s); - q[5] = bin2bcd(f); - FRAMES_TO_MSF(sector + 150, &m, &s, &f); - q[7] = bin2bcd(m); - q[8] = bin2bcd(s); - q[9] = bin2bcd(f); - - /* Construct raw subchannel data from Q only. */ - for (int i = 0; i < 12; i++) - for (int j = 0; j < 8; j++) - buffer[2352 + (i << 3) + j] = ((q[i] >> (7 - j)) & 0x01) << 6; - - return ret; -} - -/* TODO: Do CUE+BIN images with a sector size of 2448 even exist? */ -int -cdi_read_sector_sub(cd_img_t *cdi, uint8_t *buffer, uint32_t sector) -{ - int track; - int index; - - cdi_get_track_and_index(cdi, sector, &track, &index); - - if (track < 0) - return 0; - - const track_t *trk = &(cdi->tracks[track]); - const track_index_t *idx = &(trk->idx[index]); - - const uint64_t seek = (((uint64_t) sector + 150 - idx->start + idx->file_start) * trk->sector_size); - - if ((idx->type < INDEX_NORMAL) && (trk->sector_size != 2448)) - return 0; - - return idx->file->read(idx->file, buffer, seek, 2448); -} - -int -cdi_get_sector_size(cd_img_t *cdi, uint32_t sector) -{ - int track = cdi_get_track(cdi, sector); - - if (track < 0) - return 0; - - const track_t *trk = &(cdi->tracks[track]); - - return trk->sector_size; -} - -int -cdi_is_audio(cd_img_t *cdi, uint32_t sector) -{ - int track = cdi_get_track(cdi, sector); - - if (track < 0) - return 0; - - const track_t *trk = &(cdi->tracks[track]); - - return !!(trk->mode == 0); -} - -int -cdi_is_pre(cd_img_t *cdi, uint32_t sector) -{ - int track = cdi_get_track(cdi, sector); - - if (track < 0) - return 0; - - const track_t *trk = &(cdi->tracks[track]); - - return !!(trk->attr & 0x01); -} - -int -cdi_is_mode2(cd_img_t *cdi, uint32_t sector) -{ - int track = cdi_get_track(cdi, sector); - - if (track < 0) - return 0; - - const track_t *trk = &(cdi->tracks[track]); - - return !!(trk->mode == 2); -} - -int -cdi_get_mode2_form(cd_img_t *cdi, uint32_t sector) -{ - int track = cdi_get_track(cdi, sector); - - if (track < 0) - return 0; - - const track_t *trk = &(cdi->tracks[track]); - - return trk->form; -} - -static int -cdi_can_read_pvd(track_file_t *file, uint64_t sector_size, int mode2, int form) -{ - uint8_t pvd[COOKED_SECTOR_SIZE]; - uint64_t seek = 16ULL * sector_size; /* First VD is located at sector 16. */ - - if (sector_size == RAW_SECTOR_SIZE) { - if (mode2 && (form > 0)) - seek += 24; - else - seek += 16; - } else if (form > 0) - seek += 8; - - file->read(file, pvd, seek, COOKED_SECTOR_SIZE); - - return ((pvd[0] == 1 && !strncmp((char *) (&pvd[1]), "CD001", 5) && pvd[6] == 1) || (pvd[8] == 1 && !strncmp((char *) (&pvd[9]), "CDROM", 5) && pvd[14] == 1)); -} - -static int -cdi_cue_get_buffer(char *str, char **line, int up) -{ - char *s = *line; - char *p = str; - int quote = 0; - int done = 0; - int space = 1; - - /* Copy to local buffer until we have end of string or whitespace. */ - while (!done) { - switch (*s) { - case '\0': - if (quote) { - /* Ouch, unterminated string.. */ - return 0; - } - done = 1; - break; - - case '\"': - quote ^= 1; - break; - - case ' ': - case '\t': - if (space) - break; - - if (!quote) { - done = 1; - break; - } - fallthrough; - - default: - if (up && islower((int) *s)) - *p++ = toupper((int) *s); - else - *p++ = *s; - space = 0; - break; - } - - if (!done) - s++; - } - *p = '\0'; - - *line = s; - - return 1; -} - -static int -cdi_cue_get_keyword(char **dest, char **line) -{ - int success; - - success = cdi_cue_get_buffer(temp_keyword, line, 1); - if (success) - *dest = temp_keyword; - - return success; -} - -/* Get a string from the input line, handling quotes properly. */ -static uint64_t -cdi_cue_get_number(char **line) -{ - char temp[128]; - uint64_t num; - - if (!cdi_cue_get_buffer(temp, line, 0)) - return 0; - - if (sscanf(temp, "%" PRIu64, &num) != 1) - return 0; - - return num; -} - -static int -cdi_cue_get_frame(uint64_t *frames, char **line) -{ - char temp[128]; - int min = 0; - int sec = 0; - int fr = 0; - int success; - - success = cdi_cue_get_buffer(temp, line, 0); - if (!success) - return 0; - - success = sscanf(temp, "%d:%d:%d", &min, &sec, &fr) == 3; - if (!success) - return 0; - - *frames = MSF_TO_FRAMES(min, sec, fr); - - return 1; -} - -static int -cdi_cue_get_flags(track_t *cur, char **line) -{ - char temp[128]; - char temp2[128]; - int success; - - success = cdi_cue_get_buffer(temp, line, 0); - if (!success) - return 0; - - memset(temp2, 0x00, sizeof(temp2)); - success = sscanf(temp, "%s", temp2) == 1; - if (!success) - return 0; - - if (strstr(temp2, "PRE") != NULL) - cur->attr |= 0x01; - if (strstr(temp2, "DCP") != NULL) - cur->attr |= 0x02; - if (strstr(temp2, "4CH") != NULL) - cur->attr |= 0x08; - - return 1; -} - -static track_t * -cdi_insert_track(cd_img_t *cdi, uint8_t session, uint8_t point) -{ - track_t *ct = NULL; - - cdi->tracks_num++; - if (cdi->tracks == NULL) { - cdi->tracks = calloc(1, sizeof(track_t)); - ct = &(cdi->tracks[0]); - } else { - cdi->tracks = realloc(cdi->tracks, cdi->tracks_num * sizeof(track_t)); - ct = &(cdi->tracks[cdi->tracks_num - 1]); - } - cdrom_image_backend_log("%02X: cdi->tracks[%2i] = %016" PRIX64 "\n", point, cdi->tracks_num - 1, (uint64_t) ct); - - memset(ct, 0x00, sizeof(track_t)); - - ct->session = session; - ct->point = point; - - for (int i = 0; i < 3; i++) - ct->idx[i].type = (point > 99) ? INDEX_SPECIAL : INDEX_NONE; - - return ct; -} - -static void -cdi_last_3_passes(cd_img_t *cdi) -{ - track_t *ct = NULL; - track_t *lt = NULL; - track_index_t *ci = NULL; - track_file_t *tf = NULL; - uint64_t tf_len = 0ULL; - uint64_t cur_pos = 0ULL; - int map[256] = { 0 }; - int lead[3] = { 0 }; - int pos = 0; - int ls = 0; - uint64_t spg[256] = { 0ULL }; - track_t *lo[256] = { 0 }; - - cdrom_image_backend_log("A2 = %016" PRIX64 "\n", (uint64_t) &(cdi->tracks[2])); - - for (int i = 0; i < cdi->tracks_num; i++) { - ct = &(cdi->tracks[i]); - if (((ct->point >= 1) && (ct->point <= 99)) || (ct->point >= 0xb0)) { - if (ct->point == 0xb0) { - /* Point B0h found, add the previous three lead tracks. */ - for (int j = 0; j < 3; j++) { - map[pos] = lead[j]; - pos++; - } - } - - map[pos] = i; - pos++; - } else if ((ct->point >= 0xa0) && (ct->point <= 0xa2)) - lead[ct->point & 0x03] = i; - } - - /* The last lead tracks. */ - for (int i = 0; i < 3; i++) { - map[pos] = lead[i]; - pos++; - } -#ifdef ENABLE_CDROM_IMAGE_BACKEND_LOG - cdrom_image_backend_log("pos = %i, cdi->tracks_num = %i\n", pos, cdi->tracks_num); - for (int i = 0; i < pos; i++) - cdrom_image_backend_log("map[%02i] = %02X\n", i, map[i]); -#endif - - cdrom_image_backend_log("Second pass:\n"); - for (int i = (cdi->tracks_num - 1); i >= 0; i--) { - ct = &(cdi->tracks[map[i]]); - if (ct->idx[1].type != INDEX_SPECIAL) { - for (int j = 2; j >= 0; j--) { - ci = &(ct->idx[j]); - - if ((ci->type >= INDEX_ZERO) && (ci->file != tf)) { - tf = ci->file; - if (tf != NULL) { - tf_len = tf->get_length(tf) / ct->sector_size; - cdrom_image_backend_log(" File length: %016" PRIX64 " sectors\n", tf_len); - } - } - - if (ci->type == INDEX_NONE) { - /* Index was not in the cue sheet, keep its length at zero. */ - ci->file_start = tf_len; - } else if (ci->type == INDEX_NORMAL) { - /* Index was in the cue sheet and is present in the file. */ - ci->file_length = tf_len - ci->file_start; - tf_len -= ci->file_length; - } - - cdrom_image_backend_log(" TRACK %2i (%2i), ATTR %02X, INDEX %i: %2i, file_start = %016" - PRIX64 " (%2i:%02i:%02i), file_length = %016" PRIX64 " (%2i:%02i:%02i)\n", - i, map[i], - ct->attr, - j, ci->type, - ci->file_start, - (int) ((ci->file_start / 75) / 60), - (int) ((ci->file_start / 75) % 60), - (int) (ci->file_start % 75), - ci->file_length, - (int) ((ci->file_length / 75) / 60), - (int) ((ci->file_length / 75) % 60), - (int) (ci->file_length % 75)); - } - } - } - - cdrom_image_backend_log("Third pass:\n"); - for (int i = 0; i < cdi->tracks_num; i++) { - int session_changed = 0; - - ct = &(cdi->tracks[map[i]]); - if (ct->idx[1].type != INDEX_SPECIAL) { - if (ct->session != ls) { - /* The first track of a session always has a pre-gap of at least 0:02:00. */ - ci = &(ct->idx[0]); - if (ci->type == INDEX_NONE) { - ci->type = INDEX_ZERO; - ci->start = 0ULL; - ci->length = 150ULL; - } - - session_changed = 1; - ls = ct->session; - } - - for (int j = 0; j < 3; j++) { - ci = &(ct->idx[j]); - - if (ci->type == INDEX_NONE) - /* Index was not in the cue sheet, keep its length at zero. */ - ci->start = cur_pos; - else if (ci->type == INDEX_ZERO) { - /* Index was in the cue sheet and is not present in the file. */ - ci->start = cur_pos; - cur_pos += ci->length; - } else if (ci->type == INDEX_NORMAL) { - /* Index was in the cue sheet and is present in the file. */ - ci->start = cur_pos; - ci->length = ci->file_length; - cur_pos += ci->file_length; - } - - cdrom_image_backend_log(" TRACK %2i (%2i) (%2i), ATTR %02X, MODE %i, INDEX %i: %2i, " - "start = %016" PRIX64 " (%2i:%02i:%02i), length = %016" PRIX64 - " (%2i:%02i:%02i)\n", - i, map[i], - ct->point, ct->attr, - ct->mode, - j, ci->type, - ci->start, - (int) ((ci->start / 75) / 60), - (int) ((ci->start / 75) % 60), - (int) (ci->start % 75), - ci->length, - (int) ((ci->length / 75) / 60), - (int) ((ci->length / 75) % 60), - (int) (ci->length % 75)); - - /* Set the pre-gap of the first track of this session. */ - if (session_changed) - spg[ct->session] = ct->idx[0].start; - } - } - } - - /* Set the lead out starts for all sessions. */ - for (int i = 0; i <= ls; i++) { - lo[i] = NULL; - for (int j = (cdi->tracks_num - 1); j >= 0; j--) { - track_t *jt = &(cdi->tracks[j]); - if ((jt->session == ct->session) && (jt->point >= 1) && (jt->point <= 99)) { - lo[i] = &(cdi->tracks[j]); - break; - } - } - } - - cdrom_image_backend_log("Fourth pass:\n"); - for (int i = 0; i < cdi->tracks_num; i++) { - ct = &(cdi->tracks[i]); - lt = NULL; - switch (ct->point) { - case 0xa0: - for (int j = 0; j < cdi->tracks_num; j++) { - track_t *jt = &(cdi->tracks[j]); - if ((jt->session == ct->session) && (jt->point >= 1) && (jt->point <= 99)) { - lt = &(cdi->tracks[j]); - break; - } - } - if (lt != NULL) { - int disc_type = 0x00; - - ct->attr = lt->attr; - - ct->mode = lt->mode; - ct->form = lt->form; - - if (lt->mode == 2) - disc_type = (lt->form > 0) ? 0x20 : 0x10; - for (int j = 0; j < 3; j++) { - ci = &(ct->idx[j]); - ci->type = INDEX_ZERO; - ci->start = (lt->point * 60 * 75) + (disc_type * 75); - ci->length = 0; - } - } - break; - case 0xa1: - for (int j = (cdi->tracks_num - 1); j >= 0; j--) { - track_t *jt = &(cdi->tracks[j]); - if ((jt->session == ct->session) && (jt->point >= 1) && (jt->point <= 99)) { - lt = &(cdi->tracks[j]); - break; - } - } - if (lt != NULL) { - ct->attr = lt->attr; - - ct->mode = lt->mode; - ct->form = lt->form; - - for (int j = 0; j < 3; j++) { - ci = &(ct->idx[j]); - ci->type = INDEX_ZERO; - ci->start = (lt->point * 60 * 75); - ci->length = 0; - } - } - break; - case 0xa2: - if (lo[ct->session] != NULL) { - lt = lo[ct->session]; - - ct->attr = lt->attr; - - ct->mode = lt->mode; - ct->form = lt->form; - - if (ct->idx[1].type != INDEX_NORMAL) { - track_index_t *li = &(lt->idx[2]); - - for (int j = 0; j < 3; j++) { - ci = &(ct->idx[j]); - ci->type = INDEX_ZERO; - ci->start = li->start + li->length; - ci->length = 0; - } - } - } - break; - case 0xb0: - /* - B0 MSF (*NOT* PMSF) points to the beginning of the pre-gap - of the corresponding session's first track. - */ - ct->extra[0] = (spg[ct->session] / 75) / 60; - ct->extra[1] = (spg[ct->session] / 75) % 60; - ct->extra[2] = spg[ct->session] % 75; - - /* - B0 PMSF points to the start of the lead out track - of the last session. - */ - if (lo[ls] != NULL) { - lt = lo[ls]; - track_index_t *li = &(lt->idx[2]); - - ct->idx[1].start = li->start + li->length; - } - break; - } - -#ifdef ENABLE_CDROM_IMAGE_BACKEND_LOG - if ((ct->point >= 0xa0) && (ct->point <= 0xa2)) - cdrom_image_backend_log(" TRACK %02X, SESSION %i: start = %016" PRIX64 " (%2i:%02i:%02i)\n", - ct->point, ct->session, - ct->idx[1].start, - (int) ((ct->idx[1].start / 75) / 60), - (int) ((ct->idx[1].start / 75) % 60), - (int) (ct->idx[1].start % 75)); -#endif - } -} - -int -cdi_load_iso(cd_img_t *cdi, const char *filename) -{ - track_t *ct = NULL; - track_index_t *ci = NULL; - track_file_t *tf = NULL; - int success; - int error = 1; - int is_viso = 0; - - cdi->tracks = NULL; - success = 1; - - cdrom_image_backend_log("First pass:\n"); - cdi->tracks_num = 0; - - cdi_insert_track(cdi, 1, 0xa0); - cdi_insert_track(cdi, 1, 0xa1); - cdi_insert_track(cdi, 1, 0xa2); - - /* Data track (shouldn't there be a lead in track?). */ - tf = track_file_init(filename, &error, &is_viso); - - if (error) { - cdrom_image_backend_log("ISO: cannot open file '%s'!\n", filename); - - if (tf != NULL) { - tf->close(tf); - tf = NULL; - } - success = 0; - } else if (is_viso) - success = 3; - - if (success) { - ct = cdi_insert_track(cdi, 1, 1); - ci = &(ct->idx[1]); - - ct->form = 0; - ct->mode = 0; - - for (int i = 0; i < 3; i++) - ct->idx[i].type = INDEX_NONE; - - ct->attr = DATA_TRACK; - - /* Try to detect ISO type. */ - ct->mode = 1; - ct->form = 0; - - ci->type = INDEX_NORMAL; - ci->file_start = 0ULL; - - ci->file = tf; - - /* For Mode 2 XA, skip the first 8 bytes in every sector when sector size = 2336. */ - if (cdi_can_read_pvd(ci->file, RAW_SECTOR_SIZE, 0, 0)) - ct->sector_size = RAW_SECTOR_SIZE; - else if (cdi_can_read_pvd(ci->file, 2336, 1, 0)) { - ct->sector_size = 2336; - ct->mode = 2; - } else if (cdi_can_read_pvd(ci->file, 2324, 1, 2)) { - ct->sector_size = 2324; - ct->mode = 2; - ct->form = 2; - } else if (cdi_can_read_pvd(ci->file, 2328, 1, 2)) { - ct->sector_size = 2328; - ct->mode = 2; - ct->form = 2; - } else if (cdi_can_read_pvd(ci->file, 2336, 1, 1)) { - ct->sector_size = 2336; - ct->mode = 2; - ct->form = 1; - ct->skip = 8; - } else if (cdi_can_read_pvd(ci->file, RAW_SECTOR_SIZE, 1, 0)) { - ct->sector_size = RAW_SECTOR_SIZE; - ct->mode = 2; - } else if (cdi_can_read_pvd(ci->file, RAW_SECTOR_SIZE, 1, 1)) { - ct->sector_size = RAW_SECTOR_SIZE; - ct->mode = 2; - ct->form = 1; - } else { - /* We use 2048 mode 1 as the default. */ - ct->sector_size = COOKED_SECTOR_SIZE; - } - - cdrom_image_backend_log("TRACK 1: Mode = %i, Form = %i, Sector size = %08X\n", - ct->mode, ct->form, ct->sector_size); - } - - tf = NULL; - - if (!success) - return 0; - - cdi_last_3_passes(cdi); - - return success; -} - -int -cdi_load_cue(cd_img_t *cdi, const char *cuefile) -{ - track_t *ct = NULL; - track_index_t *ci = NULL; - track_file_t *tf = NULL; - uint64_t frame = 0ULL; - uint64_t last = 0ULL; - uint8_t session = 1; - int success; - int error; - int is_viso = 0; - int lead[3] = { 0 }; - char pathname[MAX_FILENAME_LENGTH]; - char buf[MAX_LINE_LENGTH]; - FILE *fp; - char *line; - char *command; - char *type; - char temp; - - cdi->tracks = NULL; - cdi->tracks_num = 0; - - /* Get a copy of the filename into pathname, we need it later. */ - memset(pathname, 0, MAX_FILENAME_LENGTH * sizeof(char)); - path_get_dirname(pathname, cuefile); - - /* Open the file. */ - fp = plat_fopen(cuefile, "r"); - if (fp == NULL) - return 0; - - success = 0; - - cdrom_image_backend_log("First pass:\n"); - cdi->tracks_num = 0; - - for (int i = 0; i < 3; i++) { - lead[i] = cdi->tracks_num; - (void *) cdi_insert_track(cdi, session, 0xa0 + i); - } - cdrom_image_backend_log("lead[2] = %016" PRIX64 "\n", (uint64_t) &(cdi->tracks[lead[2]])); - - while (1) { - line = buf; - - /* Read a line from the cuesheet file. */ - if (feof(fp) || (fgets(buf, sizeof(buf), fp) == NULL) || ferror(fp)) - break; - - /* Do two iterations to make sure to nuke even if it's \r\n or \n\r, - but do checks to make sure we're not nuking other bytes. */ - for (uint8_t i = 0; i < 2; i++) { - if (strlen(buf) > 0) { - if (buf[strlen(buf) - 1] == '\n') - buf[strlen(buf) - 1] = '\0'; - /* nuke trailing newline */ - else if (buf[strlen(buf) - 1] == '\r') - buf[strlen(buf) - 1] = '\0'; - /* nuke trailing newline */ - } - } - cdrom_image_backend_log(" line = %s\n", line); - - (void) cdi_cue_get_keyword(&command, &line); - - if (!strcmp(command, "FILE")) { - /* The file for the track. */ - char filename[MAX_FILENAME_LENGTH]; - char ansi[MAX_FILENAME_LENGTH]; - - tf = NULL; - - memset(ansi, 0, MAX_FILENAME_LENGTH * sizeof(char)); - memset(filename, 0, MAX_FILENAME_LENGTH * sizeof(char)); - - success = cdi_cue_get_buffer(ansi, &line, 0); - if (!success) - break; - success = cdi_cue_get_keyword(&type, &line); - if (!success) - break; - - error = 1; - is_viso = 0; - - if (!strcmp(type, "BINARY") || !strcmp(type, "MOTOROLA")) { - if (!path_abs(ansi)) - path_append_filename(filename, pathname, ansi); - else - strcpy(filename, ansi); - - tf = track_file_init(filename, &error, &is_viso); - - if (tf) - tf->motorola = !strcmp(type, "MOTOROLA"); - } else if (!strcmp(type, "WAVE") || !strcmp(type, "AIFF") || !strcmp(type, "MP3")) { - if (!path_abs(ansi)) - path_append_filename(filename, pathname, ansi); - else - strcpy(filename, ansi); - tf = audio_init(filename, &error); - } - if (error) { - cdrom_image_backend_log("CUE: cannot open file '%s' in cue sheet!\n", - filename); - - if (tf != NULL) { - tf->close(tf); - tf = NULL; - } - success = 0; - } else if (is_viso) - success = 3; - } else if (!strcmp(command, "TRACK")) { - int t = cdi_cue_get_number(&line); - success = cdi_cue_get_keyword(&type, &line); - - if (!success) - break; - - ct = cdi_insert_track(cdi, session, t); - - cdrom_image_backend_log(" TRACK %i\n", t); - - ct->form = 0; - ct->mode = 0; - - if (!strcmp(type, "AUDIO")) { - ct->sector_size = RAW_SECTOR_SIZE; - ct->attr = AUDIO_TRACK; - } else if (!memcmp(type, "MODE", 4)) { - uint32_t mode; - ct->attr = DATA_TRACK; - sscanf(type, "MODE%" PRIu32 "/%" PRIu32, &mode, &(ct->sector_size)); - ct->mode = mode; - if (ct->mode == 2) switch(ct->sector_size) { - case 2324: case 2328: - ct->form = 2; - break; - case 2048: case 2336: case 2352: case 2448: - ct->form = 1; - break; - } - if ((ct->sector_size == 2336) && (ct->mode == 2) && (ct->form == 1)) - ct->skip = 8; - } else if (!memcmp(type, "CD", 2)) { - ct->attr = DATA_TRACK; - ct->mode = 2; - sscanf(type, "CD%c/%i", &temp, &(ct->sector_size)); - } else - success = 0; - - if (success) - last = ct->sector_size; - } else if (!strcmp(command, "INDEX")) { - int t = cdi_cue_get_number(&line); - ci = &(ct->idx[t]); - - cdrom_image_backend_log(" INDEX %i (1)\n", t); - - ci->type = INDEX_NORMAL; - ci->file = tf; - success = cdi_cue_get_frame(&frame, &line); - ci->file_start = frame; - } else if (!strcmp(command, "PREGAP")) { - ci = &(ct->idx[0]); - cdrom_image_backend_log(" INDEX 0 (0)\n"); - - ci->type = INDEX_ZERO; - ci->file = tf; - success = cdi_cue_get_frame(&frame, &line); - ci->length = frame; - } else if (!strcmp(command, "PAUSE")) { - ci = &(ct->idx[1]); - cdrom_image_backend_log(" INDEX 1 (0)\n"); - - ci->type = INDEX_ZERO; - ci->file = tf; - success = cdi_cue_get_frame(&frame, &line); - ci->length = frame; - } else if (!strcmp(command, "POSTGAP")) { - ci = &(ct->idx[2]); - cdrom_image_backend_log(" INDEX 2 (0)\n"); - - ci->type = INDEX_ZERO; - ci->file = tf; - success = cdi_cue_get_frame(&frame, &line); - ci->length = frame; - } else if (!strcmp(command, "ZERO")) { - ci = &(ct->idx[1]); - cdrom_image_backend_log(" INDEX 1 (0)\n"); - - ci->type = INDEX_ZERO; - ci->file = tf; - success = cdi_cue_get_frame(&frame, &line); - ci->length = frame; - } else if (!strcmp(command, "FLAGS")) - success = cdi_cue_get_flags(ct, &line); - else if (!strcmp(command, "REM")) { - success = 1; - char *space = strstr(line, " "); - if (space != NULL) { - space++; - if (space < (line + strlen(line))) { - (void) cdi_cue_get_keyword(&command, &space); - if (!strcmp(command, "LEAD-OUT")) { - ct = &(cdi->tracks[lead[2]]); - cdrom_image_backend_log("lead[2] = %016" PRIX64 "\n", (uint64_t) ct); - ct->sector_size = last; - ci = &(ct->idx[1]); - ci->type = INDEX_NORMAL; - ci->file = tf; - success = cdi_cue_get_frame(&frame, &space); - ci->file_start = frame; - - cdrom_image_backend_log(" LEAD-OUT\n"); - } else if (!strcmp(command, "SESSION")) { - session = cdi_cue_get_number(&space); - - if (session > 1) { - ct = cdi_insert_track(cdi, session - 1, 0xb0); - ci = &(ct->idx[1]); - ci->start = (0x40 * 60 * 75) + (0x02 * 75); - - if (session == 2) { - ct->extra[3] = 0x02; - - /* 5F:00:00 on Wembley, C0:00:00 in the spec. And what's in PMSF? */ - ct = cdi_insert_track(cdi, session - 1, 0xc0); - ci = &(ct->idx[1]); - ct->extra[0] = 0x5f; /* Optimum recording power. */ - } else - ct->extra[3] = 0x01; - - for (int i = 0; i < 3; i++) { - lead[i] = cdi->tracks_num; - (void *) cdi_insert_track(cdi, session, 0xa0 + i); - } - cdrom_image_backend_log("lead[2] = %016" PRIX64 "\n", - (uint64_t) &(cdi->tracks[lead[2]])); - } - - cdrom_image_backend_log(" SESSION %i\n", session); - } - } - } - } else if (!strcmp(command, "CATALOG") || !strcmp(command, "CDTEXTFILE") || - !strcmp(command, "ISRC") || !strcmp(command, "PERFORMER") || - !strcmp(command, "SONGWRITER") || !strcmp(command, "TITLE") || - !strcmp(command, "")) - /* Ignored commands. */ - success = 1; - else { - cdrom_image_backend_log("CUE: unsupported command '%s' in cue sheet!\n", command); - - success = 0; - } - - if (!success) - break; - } - - tf = NULL; - - fclose(fp); - - if (!success) - return 0; - - cdi_last_3_passes(cdi); - - return success; -} - -/* Root functions. */ -static void -cdi_clear_tracks(cd_img_t *cdi) -{ - track_file_t *last = NULL; - track_t *cur = NULL; - track_index_t *idx = NULL; - - if ((cdi->tracks == NULL) || (cdi->tracks_num == 0)) - return; - - for (int i = 0; i < cdi->tracks_num; i++) { - cur = &cdi->tracks[i]; - - if ((cur->point >= 1) && (cur->point <= 99)) for (int j = 0; j < 3; j++) { - idx = &(cur->idx[j]); - - /* Make sure we do not attempt to close a NULL file. */ - if (idx->file != NULL) { - if (idx->file != last) { - last = idx->file; - index_file_close(idx); - } else - idx->file = NULL; - } - } - } - - /* Now free the array. */ - free(cdi->tracks); - cdi->tracks = NULL; - - /* Mark that there's no tracks. */ - cdi->tracks_num = 0; -} - -void -cdi_close(cd_img_t *cdi) -{ - cdi_clear_tracks(cdi); - free(cdi); -} - -int -cdi_set_device(cd_img_t *cdi, const char *path) -{ - uintptr_t ext = path + strlen(path) - strrchr(path, '.'); - int ret; - - cdrom_image_backend_log("cdi_set_device(): %" PRIu64 ", %lli, %s\n", - ext, strlen(path), path + strlen(path) - ext + 1); - - if ((ext == 4) && !stricmp(path + strlen(path) - ext + 1, "CUE")) { - if ((ret = cdi_load_cue(cdi, path))) - return ret; - - cdi_clear_tracks(cdi); - } - - if ((ret = cdi_load_iso(cdi, path))) - return ret; - - cdi_close(cdi); - - return 0; -} diff --git a/src/cdrom/cdrom_image_viso.c b/src/cdrom/cdrom_image_viso.c index 24f60836d..4bf976794 100644 --- a/src/cdrom/cdrom_image_viso.c +++ b/src/cdrom/cdrom_image_viso.c @@ -21,7 +21,9 @@ #define __STDC_FORMAT_MACROS #include #include +#ifdef IMAGE_VISO_LOG #include +#endif #include #include #include @@ -29,15 +31,16 @@ #include #include #include -#define HAVE_STDARG_H #include <86box/86box.h> -#include <86box/bswap.h> -#include <86box/cdrom_image_backend.h> +#include <86box/cdrom.h> +#include <86box/cdrom_image.h> +#include <86box/cdrom_image_viso.h> +#include <86box/log.h> #include <86box/path.h> #include <86box/plat.h> +#include <86box/bswap.h> #include <86box/plat_dir.h> #include <86box/version.h> -#include <86box/timer.h> #include <86box/nvr.h> #ifndef S_ISDIR @@ -136,29 +139,30 @@ static const char rr_eid[] = "RRIP_1991A"; /* identifiers used in ER field for static const char rr_edesc[] = "THE ROCK RIDGE INTERCHANGE PROTOCOL PROVIDES SUPPORT FOR POSIX FILE SYSTEM SEMANTICS."; static int8_t tz_offset = 0; -#ifdef ENABLE_CDROM_IMAGE_VISO_LOG -int cdrom_image_viso_do_log = ENABLE_CDROM_IMAGE_VISO_LOG; +#ifdef IMAGE_VISO_LOG +int image_viso_do_log = IMAGE_VISO_LOG; void -cdrom_image_viso_log(const char *fmt, ...) +image_viso_log(void *priv, const char *fmt, ...) { va_list ap; - if (cdrom_image_viso_do_log) { + if (image_viso_do_log) { va_start(ap, fmt); - pclog_ex(fmt, ap); + log_out(priv, fmt, ap); va_end(ap); } } #else -# define cdrom_image_viso_log(fmt, ...) +# define image_viso_log(priv, fmt, ...) #endif static size_t -viso_pread(void *ptr, uint64_t offset, size_t size, size_t count, FILE *fp) +viso_pread(void *ptr, const uint64_t offset, const size_t size, + const size_t count, FILE *fp) { - uint64_t cur_pos = ftello64(fp); - size_t ret = 0; + const uint64_t cur_pos = ftello64(fp); + size_t ret = 0; if (fseeko64(fp, offset, SEEK_SET) != -1) ret = fread(ptr, size, count, fp); fseeko64(fp, cur_pos, SEEK_SET); @@ -166,10 +170,11 @@ viso_pread(void *ptr, uint64_t offset, size_t size, size_t count, FILE *fp) } static size_t -viso_pwrite(const void *ptr, uint64_t offset, size_t size, size_t count, FILE *fp) +viso_pwrite(const void *ptr, const uint64_t offset, const size_t size, + const size_t count, FILE *fp) { - uint64_t cur_pos = ftello64(fp); - size_t ret = 0; + const uint64_t cur_pos = ftello64(fp); + size_t ret = 0; if (fseeko64(fp, offset, SEEK_SET) != -1) ret = fwrite(ptr, size, count, fp); fseeko64(fp, cur_pos, SEEK_SET); @@ -691,22 +696,22 @@ viso_read(void *priv, uint8_t *buffer, uint64_t seek, size_t count) /* Close any existing FIFO entry's file. */ viso_entry_t *other_entry = viso->file_fifo[viso->file_fifo_pos]; if (other_entry && other_entry->file) { - cdrom_image_viso_log("VISO: Closing [%s]", other_entry->path); + image_viso_log(viso->tf.log, "Closing [%s]...\n", other_entry->path); fclose(other_entry->file); other_entry->file = NULL; - cdrom_image_viso_log("\n"); + image_viso_log(viso->tf.log, "Done\n"); } /* Open file. */ - cdrom_image_viso_log("VISO: Opening [%s]", entry->path); + image_viso_log(viso->tf.log, "Opening [%s]...\n", entry->path); if ((entry->file = fopen(entry->path, "rb"))) { - cdrom_image_viso_log("\n"); + image_viso_log(viso->tf.log, "Done\n"); /* Add this entry to the FIFO. */ viso->file_fifo[viso->file_fifo_pos++] = entry; viso->file_fifo_pos &= (sizeof(viso->file_fifo) / sizeof(viso->file_fifo[0])) - 1; } else { - cdrom_image_viso_log(" => failed\n"); + image_viso_log(viso->tf.log, "Failed\n"); /* Clear any existing FIFO entry. */ viso->file_fifo[viso->file_fifo_pos] = NULL; @@ -753,12 +758,12 @@ viso_close(void *priv) if (viso == NULL) return; - cdrom_image_viso_log("VISO: close()\n"); + image_viso_log(viso->tf.log, "close()\n"); /* De-allocate everything. */ if (tf->fp) fclose(tf->fp); -#ifndef ENABLE_CDROM_IMAGE_VISO_LOG +#ifndef ENABLE_IMAGE_VISO_LOG remove(nvr_path(viso->tf.fn)); #endif @@ -777,21 +782,32 @@ viso_close(void *priv) if (viso->entry_map) free(viso->entry_map); + if (tf->log != NULL) { + + } + free(viso); } track_file_t * -viso_init(const char *dirname, int *error) +viso_init(const uint8_t id, const char *dirname, int *error) { - cdrom_image_viso_log("VISO: init()\n"); - /* Initialize our data structure. */ viso_t *viso = (viso_t *) calloc(1, sizeof(viso_t)); uint8_t *data = NULL; uint8_t *p; *error = 1; + if (viso == NULL) goto end; + + char n[1024] = { 0 }; + + sprintf(n, "CD-ROM %i VISO ", id + 1); + viso->tf.log = log_open(n); + + image_viso_log(viso->tf.log, "init()\n"); + viso->sector_size = VISO_SECTOR_SIZE; viso->format = VISO_FORMAT_ISO | VISO_FORMAT_JOLIET | VISO_FORMAT_RR; viso->use_version_suffix = (viso->format & VISO_FORMAT_ISO); /* cleared later if required */ @@ -802,7 +818,7 @@ viso_init(const char *dirname, int *error) goto end; /* Open temporary file. */ -#ifdef ENABLE_CDROM_IMAGE_VISO_LOG +#ifdef ENABLE_IMAGE_VISO_LOG strcpy(viso->tf.fn, "viso-debug.iso"); #else plat_tempfile(viso->tf.fn, "viso", ".tmp"); @@ -812,7 +828,7 @@ viso_init(const char *dirname, int *error) goto end; /* Set up directory traversal. */ - cdrom_image_viso_log("VISO: Traversing directories:\n"); + image_viso_log(viso->tf.log, "Traversing directories:\n"); viso_entry_t *entry; viso_entry_t *last_entry; viso_entry_t *dir; @@ -839,7 +855,7 @@ viso_init(const char *dirname, int *error) if (!S_ISDIR(dir->stats.st_mode)) /* root is not a directory */ goto end; dir->parent = dir; /* for the root's path table and .. entries */ - cdrom_image_viso_log("[%08X] %s => [root]\n", dir, dir->path); + image_viso_log(viso->tf.log, "[%08X] %s => [root]\n", dir, dir->path); /* Traverse directories, starting with the root. */ viso_entry_t **dir_entries = NULL; @@ -889,7 +905,8 @@ viso_init(const char *dirname, int *error) /* Set basename. */ strcpy(entry->name_short, children_count ? ".." : "."); - cdrom_image_viso_log("[%08X] %s => %s\n", entry, dir->path, entry->name_short); + image_viso_log(viso->tf.log, "[%08X] %s => %s\n", entry, + dir->path, entry->name_short); } /* Iterate through this directory's children again, making the entries. */ @@ -897,12 +914,16 @@ viso_init(const char *dirname, int *error) rewinddir(dirp); while ((readdir_entry = readdir(dirp))) { /* Ignore . and .. pseudo-directories. */ - if ((readdir_entry->d_name[0] == '.') && ((readdir_entry->d_name[1] == '\0') || (*((uint16_t *) &readdir_entry->d_name[1]) == '.'))) + if ((readdir_entry->d_name[0] == '.') && + ((readdir_entry->d_name[1] == '\0') || + (*((uint16_t *) &readdir_entry->d_name[1]) == '.'))) continue; /* Add and fill entry. */ - entry = dir_entries[children_count++] = (viso_entry_t *) calloc(1, sizeof(viso_entry_t) + dir_path_len + strlen(readdir_entry->d_name) + 2); - if (!entry) + entry = dir_entries[children_count++] = + (viso_entry_t *) calloc(1, sizeof(viso_entry_t) + + dir_path_len + strlen(readdir_entry->d_name) + 2); + if (entry == NULL) break; entry->parent = dir; strcpy(entry->path, dir->path); @@ -972,10 +993,12 @@ have_eltorito_entry: continue; } - cdrom_image_viso_log("[%08X] %s => [%-12s] %s\n", entry, dir->path, entry->name_short, entry->basename); + image_viso_log(viso->tf.log, "[%08X] %s => [%-12s] %s\n", entry, + dir->path, entry->name_short, entry->basename); } } else { - cdrom_image_viso_log("VISO: Failed to enumerate [%s], will be empty\n", dir->path); + image_viso_log(viso->tf.log, "Failed to enumerate [%s], will be empty\n", + dir->path); } /* Add terminator. */ @@ -1129,13 +1152,17 @@ next_dir: /* Write El Torito boot descriptor. This is an awkward spot for that, but the spec requires it to be the second descriptor. */ if (!i && eltorito_entry) { - cdrom_image_viso_log("VISO: Writing El Torito boot descriptor for entry [%08X]\n", eltorito_entry); + image_viso_log(viso->tf.log, "Writing El Torito boot descriptor for " + "entry [%08X]\n", eltorito_entry); p = data; if (!(viso->format & VISO_FORMAT_ISO)) - VISO_LBE_32(p, ftello64(viso->tf.fp) / viso->sector_size); /* sector offset (HSF only) */ - *p++ = 0; /* type */ - memcpy(p, (viso->format & VISO_FORMAT_ISO) ? "CD001" : "CDROM", 5); /* standard ID */ + /* Sector offset (HSF only). */ + VISO_LBE_32(p, ftello64(viso->tf.fp) / viso->sector_size); + /* Type. */ + *p++ = 0; + /* Standard ID. */ + memcpy(p, (viso->format & VISO_FORMAT_ISO) ? "CD001" : "CDROM", 5); p += 5; *p++ = 1; /* version */ @@ -1236,7 +1263,7 @@ next_dir: /* Write each path table. */ for (int i = 0; i <= ((max_vd << 1) | 1); i++) { - cdrom_image_viso_log("VISO: Generating path table #%d:\n", i); + image_viso_log(viso->tf.log, "Generating path table #%d:\n", i); /* Save this path table's start offset. */ uint64_t pt_start = ftello64(viso->tf.fp); @@ -1257,7 +1284,9 @@ next_dir: continue; } - cdrom_image_viso_log("[%08X] %s => %s\n", dir, dir->path, ((i & 2) || (dir == viso->root_dir)) ? dir->basename : dir->name_short); + image_viso_log(viso->tf.log, "[%08X] %s => %s\n", dir, + dir->path, ((i & 2) || (dir == viso->root_dir)) ? dir->basename : + dir->name_short); /* Save this directory's path table index and offset. */ dir->pt_idx = pt_idx; @@ -1325,7 +1354,7 @@ next_dir: /* Write directory records for each type. */ int dir_type = VISO_DIR_CURRENT_ROOT; for (int i = 0; i <= max_vd; i++) { - cdrom_image_viso_log("VISO: Generating directory record set #%d:\n", i); + image_viso_log(viso->tf.log, "Generating directory record set #%d:\n", i); /* Go through directories. */ dir = viso->root_dir; @@ -1368,8 +1397,10 @@ next_dir: if ((entry == eltorito_entry) || (entry == eltorito_dir)) goto next_entry; - cdrom_image_viso_log("[%08X] %s => %s\n", entry, dir->path, - ((dir_type == VISO_DIR_PARENT) ? ".." : ((dir_type < VISO_DIR_PARENT) ? "." : (i ? entry->basename : entry->name_short)))); + image_viso_log(viso->tf.log, "[%08X] %s => %s\n", entry, dir->path, + ((dir_type == VISO_DIR_PARENT) ? ".." : + ((dir_type < VISO_DIR_PARENT) ? "." : + (i ? entry->basename : entry->name_short)))); /* Fill directory record. */ viso_fill_dir_record(data, entry, viso, dir_type); @@ -1436,7 +1467,8 @@ next_entry: /* Allocate entry map for sector->file lookups. */ size_t orig_sector_size = viso->sector_size; while (1) { - cdrom_image_viso_log("VISO: Allocating entry map for %zu %zu-byte sectors\n", viso->entry_map_size, viso->sector_size); + image_viso_log(viso->tf.log, "Allocating entry map for %zu %zu-byte sectors\n", + viso->entry_map_size, viso->sector_size); viso->entry_map = (viso_entry_t **) calloc(viso->entry_map_size, sizeof(viso_entry_t *)); if (viso->entry_map) { /* Successfully allocated. */ @@ -1477,7 +1509,7 @@ next_entry: viso->all_sectors = viso->metadata_sectors; /* Go through files, assigning sectors to them. */ - cdrom_image_viso_log("VISO: Assigning sectors to files:\n"); + image_viso_log(viso->tf.log, "Assigning sectors to files:\n"); size_t base_factor = viso->sector_size / orig_sector_size; viso_entry_t *prev_entry = viso->root_dir; viso_entry_t **entry_map_p = viso->entry_map; @@ -1522,7 +1554,8 @@ next_entry: size_t size = entry->stats.st_size / viso->sector_size; if (entry->stats.st_size % viso->sector_size) size++; /* round up to the next sector */ - cdrom_image_viso_log("[%08X] %s => %zu + %zu sectors\n", entry, entry->path, viso->all_sectors, size); + image_viso_log(viso->tf.log, "[%08X] %s => %zu + %zu sectors\n", entry, + entry->path, viso->all_sectors, size); /* Allocate sectors to this file. */ viso->all_sectors += size; @@ -1541,9 +1574,10 @@ next_entry: viso_pwrite(data, viso->vol_size_offsets[i], 8, 1, viso->tf.fp); /* Metadata processing is finished, read it back to memory. */ - cdrom_image_viso_log("VISO: Reading back %zu %zu-byte sectors of metadata\n", viso->metadata_sectors, viso->sector_size); + image_viso_log(viso->tf.log, "Reading back %zu %zu-byte sectors of metadata\n", + viso->metadata_sectors, viso->sector_size); viso->metadata = (uint8_t *) calloc(viso->metadata_sectors, viso->sector_size); - if (!viso->metadata) + if (viso->metadata == NULL) goto end; fseeko64(viso->tf.fp, 0, SEEK_SET); size_t metadata_size = viso->metadata_sectors * viso->sector_size; @@ -1554,7 +1588,7 @@ next_entry: /* We no longer need the temporary file; close and delete it. */ fclose(viso->tf.fp); viso->tf.fp = NULL; -#ifndef ENABLE_CDROM_IMAGE_VISO_LOG +#ifndef ENABLE_IMAGE_VISO_LOG remove(nvr_path(viso->tf.fn)); #endif @@ -1565,13 +1599,15 @@ end: /* Set the function pointers. */ viso->tf.priv = viso; if (!*error) { - cdrom_image_viso_log("VISO: Initialized\n"); + image_viso_log(viso->tf.log, "Initialized\n"); + viso->tf.read = viso_read; viso->tf.get_length = viso_get_length; viso->tf.close = viso_close; + return &viso->tf; } else { - cdrom_image_viso_log("VISO: Initialization failed\n"); + image_viso_log(viso->tf.log, "Initialization failed\n"); if (data) free(data); viso_close(&viso->tf); diff --git a/src/cdrom/cdrom_ioctl.c b/src/cdrom/cdrom_ioctl.c deleted file mode 100644 index 2bb691f30..000000000 --- a/src/cdrom/cdrom_ioctl.c +++ /dev/null @@ -1,267 +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. - * - * CD-ROM passthrough support. - * - * - * - * Authors: TheCollector1995, , - * Miran Grca, - * - * Copyright 2023 TheCollector1995. - * Copyright 2023 Miran Grca. - */ -#include -#include -#include -#include -#include -#include -#include -#define HAVE_STDARG_H -#include <86box/86box.h> -#include <86box/config.h> -#include <86box/path.h> -#include <86box/plat.h> -#include <86box/scsi_device.h> -#include <86box/cdrom.h> -#include <86box/plat_cdrom.h> - -#ifdef ENABLE_CDROM_IOCTL_LOG -int cdrom_ioctl_do_log = ENABLE_CDROM_IOCTL_LOG; - -void -cdrom_ioctl_log(const char *fmt, ...) -{ - va_list ap; - - if (cdrom_ioctl_do_log) { - va_start(ap, fmt); - pclog_ex(fmt, ap); - va_end(ap); - } -} -#else -# define cdrom_ioctl_log(fmt, ...) -#endif - -/* 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) - -static void -ioctl_get_track_info(cdrom_t *dev, uint32_t track, int end, track_info_t *ti) -{ - TMSF tmsf; - - plat_cdrom_get_audio_track_info(dev->local, end, track, &ti->number, &tmsf, &ti->attr); - - ti->m = tmsf.min; - ti->s = tmsf.sec; - ti->f = tmsf.fr; -} - -static void -ioctl_get_raw_track_info(cdrom_t *dev, int *num, raw_track_info_t *rti) -{ - plat_cdrom_get_raw_track_info(dev->local, num, rti); -} - -static void -ioctl_get_subchannel(cdrom_t *dev, uint32_t lba, subchannel_t *subc) -{ - TMSF rel_pos; - TMSF abs_pos; - - if ((dev->cd_status == CD_STATUS_PLAYING) || (dev->cd_status == CD_STATUS_PAUSED)) { - const uint32_t trk = plat_cdrom_get_track_start(dev->local, lba, &subc->attr, &subc->track); - - FRAMES_TO_MSF(lba + 150, &abs_pos.min, &abs_pos.sec, &abs_pos.fr); - - /* Absolute position should be adjusted by 150, not the relative ones. */ - FRAMES_TO_MSF(lba - trk, &rel_pos.min, &rel_pos.sec, &rel_pos.fr); - - subc->index = 1; - } else - plat_cdrom_get_audio_sub(dev->local, lba, &subc->attr, &subc->track, &subc->index, - &rel_pos, &abs_pos); - - subc->abs_m = abs_pos.min; - subc->abs_s = abs_pos.sec; - subc->abs_f = abs_pos.fr; - - subc->rel_m = rel_pos.min; - subc->rel_s = rel_pos.sec; - subc->rel_f = rel_pos.fr; - - cdrom_ioctl_log("ioctl_get_subchannel(): %02X, %02X, %02i, %02i:%02i:%02i, %02i:%02i:%02i\n", - subc->attr, subc->track, subc->index, subc->abs_m, subc->abs_s, subc->abs_f, - subc->rel_m, subc->rel_s, subc->rel_f); -} - -static int -ioctl_get_capacity(cdrom_t *dev) -{ - int ret; - - ret = plat_cdrom_get_last_block(dev->local); - cdrom_ioctl_log("GetCapacity=%x.\n", ret); - return ret; -} - -static int -ioctl_is_track_audio(cdrom_t *dev, uint32_t pos, int ismsf) -{ - int m; - int s; - int f; - - if (dev->cd_status == CD_STATUS_DATA_ONLY) - return 0; - - if (ismsf) { - m = (pos >> 16) & 0xff; - s = (pos >> 8) & 0xff; - f = pos & 0xff; - pos = MSFtoLBA(m, s, f) - 150; - } - - /* GetTrack requires LBA. */ - return plat_cdrom_is_track_audio(dev->local, pos); -} - -static int -ioctl_is_track_pre(cdrom_t *dev, uint32_t lba) -{ - return plat_cdrom_is_track_pre(dev->local, lba); -} - -static int -ioctl_sector_size(cdrom_t *dev, uint32_t lba) -{ - cdrom_ioctl_log("LBA=%x.\n", lba); - return plat_cdrom_get_sector_size(dev->local, lba); -} - -static int -ioctl_read_sector(cdrom_t *dev, uint8_t *b, uint32_t lba) -{ - cdrom_ioctl_log("cdrom_ioctl_read_sector(): Raw.\n"); - return plat_cdrom_read_sector(dev->local, b, lba); -} - -static int -ioctl_track_type(cdrom_t *dev, uint32_t lba) -{ - int ret = CD_TRACK_UNK_DATA; - - if (ioctl_is_track_audio(dev, lba, 0)) - ret = CD_TRACK_AUDIO; - - cdrom_ioctl_log("cdrom_ioctl_track_type(): %i\n", ret); - - return ret; -} - -static int -ioctl_ext_medium_changed(cdrom_t *dev) -{ - int ret; - - if ((dev->cd_status == CD_STATUS_PLAYING) || (dev->cd_status == CD_STATUS_PAUSED)) - ret = 0; - else - ret = plat_cdrom_ext_medium_changed(dev->local); - - if (ret == 1) { - dev->cd_status = CD_STATUS_STOPPED; - dev->cdrom_capacity = ioctl_get_capacity(dev); - } else if (ret == -1) - dev->cd_status = CD_STATUS_EMPTY; - - return ret; -} - -static void -ioctl_exit(cdrom_t *dev) -{ - cdrom_ioctl_log("CDROM: ioctl_exit(%s)\n", dev->image_path); - dev->cd_status = CD_STATUS_EMPTY; - - plat_cdrom_close(dev->local); - dev->local = NULL; - - dev->ops = NULL; -} - -static const cdrom_ops_t cdrom_ioctl_ops = { - ioctl_get_track_info, - ioctl_get_raw_track_info, - ioctl_get_subchannel, - ioctl_is_track_pre, - ioctl_sector_size, - ioctl_read_sector, - ioctl_track_type, - ioctl_ext_medium_changed, - ioctl_exit -}; - -static int -cdrom_ioctl_open_abort(cdrom_t *dev) -{ - cdrom_ioctl_close(dev); - dev->ops = NULL; - dev->image_path[0] = 0; - return 1; -} - -int -cdrom_ioctl_open(cdrom_t *dev, const char *drv) -{ - const char *actual_drv = &(drv[8]); - int local_size = plat_cdrom_get_local_size(); - - /* Make sure to not STRCPY if the two are pointing - at the same place. */ - if (drv != dev->image_path) - strcpy(dev->image_path, drv); - - /* Open the image. */ - if (strstr(drv, "ioctl://") != drv) - return cdrom_ioctl_open_abort(dev); - cdrom_ioctl_log("actual_drv = %s\n", actual_drv); - if (dev->local == NULL) - dev->local = calloc(1, local_size); - int i = plat_cdrom_set_drive(dev->local, actual_drv); - if (!i) - return cdrom_ioctl_open_abort(dev); - - /* All good, reset state. */ - dev->cd_status = CD_STATUS_STOPPED; - dev->seek_pos = 0; - dev->cd_buflen = 0; - dev->cdrom_capacity = ioctl_get_capacity(dev); - cdrom_ioctl_log("CD-ROM capacity: %i sectors (%" PRIi64 " bytes)\n", - dev->cdrom_capacity, ((uint64_t) dev->cdrom_capacity) << 11ULL); - - /* Attach this handler to the drive. */ - dev->ops = &cdrom_ioctl_ops; - - return 0; -} - -void -cdrom_ioctl_close(cdrom_t *dev) -{ - cdrom_ioctl_log("CDROM: ioctl_close(%s)\n", dev->image_path); - - if (dev && dev->ops && dev->ops->exit) - dev->ops->exit(dev); -} - diff --git a/src/cdrom/cdrom_mitsumi.c b/src/cdrom/cdrom_mitsumi.c index c3c362b1b..19fa06e23 100644 --- a/src/cdrom/cdrom_mitsumi.c +++ b/src/cdrom/cdrom_mitsumi.c @@ -118,14 +118,6 @@ typedef struct mcd_t { int newstat; } mcd_t; -/* 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. */ -#ifdef MSFtoLBA -#undef MSFtoLBA -#endif -#define MSFtoLBA(m, s, f) ((((m * 60) + s) * 75) + f) - #define CD_BCD(x) (((x) % 10) | (((x) / 10) << 4)) #define CD_DCB(x) ((((x) &0xf0) >> 4) * 10 + ((x) &0x0f)) diff --git a/src/chipset/82c100.c b/src/chipset/82c100.c index 689234ebb..a9d61b3b9 100644 --- a/src/chipset/82c100.c +++ b/src/chipset/82c100.c @@ -358,8 +358,7 @@ ct_82c100_init(UNUSED(const device_t *info)) { ct_82c100_t *dev; - dev = (ct_82c100_t *) malloc(sizeof(ct_82c100_t)); - memset(dev, 0x00, sizeof(ct_82c100_t)); + dev = (ct_82c100_t *) calloc(1, sizeof(ct_82c100_t)); ct_82c100_reset(dev); @@ -393,7 +392,7 @@ const device_t ct_82c100_device = { .init = ct_82c100_init, .close = ct_82c100_close, .reset = ct_82c100_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/acc2168.c b/src/chipset/acc2168.c index 9ce29bdff..dbbdc99f6 100644 --- a/src/chipset/acc2168.c +++ b/src/chipset/acc2168.c @@ -184,8 +184,7 @@ acc2168_close(void *priv) static void * acc2168_init(UNUSED(const device_t *info)) { - acc2168_t *dev = (acc2168_t *) malloc(sizeof(acc2168_t)); - memset(dev, 0, sizeof(acc2168_t)); + acc2168_t *dev = (acc2168_t *) calloc(1, sizeof(acc2168_t)); device_add(&port_92_device); io_sethandler(0x00f2, 0x0002, acc2168_read, NULL, NULL, acc2168_write, NULL, NULL, dev); @@ -201,7 +200,7 @@ const device_t acc2168_device = { .init = acc2168_init, .close = acc2168_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/ali1409.c b/src/chipset/ali1409.c index 3e4286f80..5009a6505 100644 --- a/src/chipset/ali1409.c +++ b/src/chipset/ali1409.c @@ -40,9 +40,8 @@ #include <86box/fdc.h> #include <86box/smram.h> #include <86box/chipset.h> - +#include <86box/plat_unused.h> - #ifdef ENABLE_ALI1409_LOG int ali1409_do_log = ENABLE_ALI1409_LOG; @@ -161,10 +160,9 @@ ali1409_close(void *priv) } static void * -ali1409_init(const device_t *info) +ali1409_init(UNUSED(const device_t *info)) { - ali1409_t *dev = (ali1409_t *) malloc(sizeof(ali1409_t)); - memset(dev, 0, sizeof(ali1409_t)); + ali1409_t *dev = (ali1409_t *) calloc(1, sizeof(ali1409_t)); dev->cfg_locked = 1; @@ -173,7 +171,7 @@ ali1409_init(const device_t *info) 23h Data Port */ - ali1409_log ("Bus speed: %i",cpu_busspeed); + ali1409_log ("Bus speed: %i", cpu_busspeed); io_sethandler(0x0022, 0x0002, ali1409_read, NULL, NULL, ali1409_write, NULL, NULL, dev); @@ -191,7 +189,7 @@ const device_t ali1409_device = { .init = ali1409_init, .close = ali1409_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/ali1429.c b/src/chipset/ali1429.c index 34c3e18c2..e2478078f 100644 --- a/src/chipset/ali1429.c +++ b/src/chipset/ali1429.c @@ -331,8 +331,7 @@ ali1429_defaults(ali1429_t *dev) static void * ali1429_init(const device_t *info) { - ali1429_t *dev = (ali1429_t *) malloc(sizeof(ali1429_t)); - memset(dev, 0, sizeof(ali1429_t)); + ali1429_t *dev = (ali1429_t *) calloc(1, sizeof(ali1429_t)); dev->cfg_locked = 1; GREEN = info->local; @@ -358,7 +357,7 @@ const device_t ali1429_device = { .init = ali1429_init, .close = ali1429_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -372,7 +371,7 @@ const device_t ali1429g_device = { .init = ali1429_init, .close = ali1429_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/ali1435.c b/src/chipset/ali1435.c index 9476d2b45..ff096ac55 100644 --- a/src/chipset/ali1435.c +++ b/src/chipset/ali1435.c @@ -282,8 +282,7 @@ ali1435_close(void *priv) static void * ali1435_init(UNUSED(const device_t *info)) { - ali1435_t *dev = (ali1435_t *) malloc(sizeof(ali1435_t)); - memset(dev, 0, sizeof(ali1435_t)); + ali1435_t *dev = (ali1435_t *) calloc(1, sizeof(ali1435_t)); dev->cfg_locked = 1; @@ -308,7 +307,7 @@ const device_t ali1435_device = { .init = ali1435_init, .close = ali1435_close, .reset = ali1435_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/ali1489.c b/src/chipset/ali1489.c index 3550f1da6..fc51bbed2 100644 --- a/src/chipset/ali1489.c +++ b/src/chipset/ali1489.c @@ -470,8 +470,7 @@ ali1489_close(void *priv) static void * ali1489_init(UNUSED(const device_t *info)) { - ali1489_t *dev = (ali1489_t *) malloc(sizeof(ali1489_t)); - memset(dev, 0, sizeof(ali1489_t)); + ali1489_t *dev = (ali1489_t *) calloc(1, sizeof(ali1489_t)); /* M1487/M1489 22h Index Port @@ -499,7 +498,7 @@ const device_t ali1489_device = { .init = ali1489_init, .close = ali1489_close, .reset = ali1489_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/ali1531.c b/src/chipset/ali1531.c index 06d0a0a60..e765e6d45 100644 --- a/src/chipset/ali1531.c +++ b/src/chipset/ali1531.c @@ -369,8 +369,7 @@ ali1531_close(void *priv) static void * ali1531_init(UNUSED(const device_t *info)) { - ali1531_t *dev = (ali1531_t *) malloc(sizeof(ali1531_t)); - memset(dev, 0, sizeof(ali1531_t)); + ali1531_t *dev = (ali1531_t *) calloc(1, sizeof(ali1531_t)); pci_add_card(PCI_ADD_NORTHBRIDGE, ali1531_read, ali1531_write, dev, &dev->pci_slot); @@ -389,7 +388,7 @@ const device_t ali1531_device = { .init = ali1531_init, .close = ali1531_close, .reset = ali1531_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/ali1541.c b/src/chipset/ali1541.c index d57ef51e7..eed6ddbc5 100644 --- a/src/chipset/ali1541.c +++ b/src/chipset/ali1541.c @@ -643,8 +643,7 @@ ali1541_close(void *priv) static void * ali1541_init(UNUSED(const device_t *info)) { - ali1541_t *dev = (ali1541_t *) malloc(sizeof(ali1541_t)); - memset(dev, 0, sizeof(ali1541_t)); + ali1541_t *dev = (ali1541_t *) calloc(1, sizeof(ali1541_t)); pci_add_card(PCI_ADD_NORTHBRIDGE, ali1541_read, ali1541_write, dev, &dev->pci_slot); @@ -665,7 +664,7 @@ const device_t ali1541_device = { .init = ali1541_init, .close = ali1541_close, .reset = ali1541_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/ali1543.c b/src/chipset/ali1543.c index f35ec7590..69a8990e9 100644 --- a/src/chipset/ali1543.c +++ b/src/chipset/ali1543.c @@ -1599,8 +1599,7 @@ ali1543_close(void *priv) static void * ali1543_init(const device_t *info) { - ali1543_t *dev = (ali1543_t *) malloc(sizeof(ali1543_t)); - memset(dev, 0, sizeof(ali1543_t)); + ali1543_t *dev = (ali1543_t *) calloc(1, sizeof(ali1543_t)); /* Device 02: M1533 Southbridge */ pci_add_card(PCI_ADD_SOUTHBRIDGE, ali1533_read, ali1533_write, dev, &dev->pci_slot); @@ -1673,7 +1672,7 @@ const device_t ali1543_device = { .init = ali1543_init, .close = ali1543_close, .reset = ali1543_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -1687,7 +1686,7 @@ const device_t ali1543c_device = { .init = ali1543_init, .close = ali1543_close, .reset = ali1543_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/ali1621.c b/src/chipset/ali1621.c index 6194dce19..d44c0f5a9 100644 --- a/src/chipset/ali1621.c +++ b/src/chipset/ali1621.c @@ -669,8 +669,7 @@ ali1621_close(void *priv) static void * ali1621_init(UNUSED(const device_t *info)) { - ali1621_t *dev = (ali1621_t *) malloc(sizeof(ali1621_t)); - memset(dev, 0, sizeof(ali1621_t)); + ali1621_t *dev = (ali1621_t *) calloc(1, sizeof(ali1621_t)); pci_add_card(PCI_ADD_NORTHBRIDGE, ali1621_read, ali1621_write, dev, &dev->pci_slot); @@ -692,7 +691,7 @@ const device_t ali1621_device = { .init = ali1621_init, .close = ali1621_close, .reset = ali1621_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/ali6117.c b/src/chipset/ali6117.c index cc2e465a2..c351a0cfa 100644 --- a/src/chipset/ali6117.c +++ b/src/chipset/ali6117.c @@ -466,8 +466,7 @@ ali6117_init(const device_t *info) ali6117_log("ALI6117: init()\n"); - ali6117_t *dev = (ali6117_t *) malloc(sizeof(ali6117_t)); - memset(dev, 0, sizeof(ali6117_t)); + ali6117_t *dev = (ali6117_t *) calloc(1, sizeof(ali6117_t)); dev->local = info->local; @@ -499,7 +498,7 @@ const device_t ali1217_device = { .init = ali6117_init, .close = ali6117_close, .reset = ali6117_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -513,7 +512,7 @@ const device_t ali6117d_device = { .init = ali6117_init, .close = ali6117_close, .reset = ali6117_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/compaq_386.c b/src/chipset/compaq_386.c index 8c241e087..bc81c5472 100644 --- a/src/chipset/compaq_386.c +++ b/src/chipset/compaq_386.c @@ -772,7 +772,7 @@ const device_t compaq_386_device = { .init = compaq_386_init, .close = compaq_386_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -786,7 +786,7 @@ const device_t compaq_genoa_device = { .init = compaq_genoa_init, .close = NULL, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/contaq_82c59x.c b/src/chipset/contaq_82c59x.c index 5c2910227..1981fd11c 100644 --- a/src/chipset/contaq_82c59x.c +++ b/src/chipset/contaq_82c59x.c @@ -322,8 +322,7 @@ contaq_82c59x_close(void *priv) static void * contaq_82c59x_init(const device_t *info) { - contaq_82c59x_t *dev = (contaq_82c59x_t *) malloc(sizeof(contaq_82c59x_t)); - memset(dev, 0x00, sizeof(contaq_82c59x_t)); + contaq_82c59x_t *dev = (contaq_82c59x_t *) calloc(1, sizeof(contaq_82c59x_t)); dev->green = info->local; @@ -359,7 +358,7 @@ const device_t contaq_82c596a_device = { .init = contaq_82c59x_init, .close = contaq_82c59x_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -373,7 +372,7 @@ const device_t contaq_82c597_device = { .init = contaq_82c59x_init, .close = contaq_82c59x_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/cs4031.c b/src/chipset/cs4031.c index fb439ec3a..cfec9ad30 100644 --- a/src/chipset/cs4031.c +++ b/src/chipset/cs4031.c @@ -164,8 +164,7 @@ cs4031_close(void *priv) static void * cs4031_init(UNUSED(const device_t *info)) { - cs4031_t *dev = (cs4031_t *) malloc(sizeof(cs4031_t)); - memset(dev, 0, sizeof(cs4031_t)); + cs4031_t *dev = (cs4031_t *) calloc(1, sizeof(cs4031_t)); dev->port_92 = device_add(&port_92_device); @@ -185,7 +184,7 @@ const device_t cs4031_device = { .init = cs4031_init, .close = cs4031_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/cs8230.c b/src/chipset/cs8230.c index 93a7f1bba..0374a44a6 100644 --- a/src/chipset/cs8230.c +++ b/src/chipset/cs8230.c @@ -157,8 +157,7 @@ cs8230_close(void *priv) static void * cs8230_init(UNUSED(const device_t *info)) { - cs8230_t *cs8230 = (cs8230_t *) malloc(sizeof(cs8230_t)); - memset(cs8230, 0, sizeof(cs8230_t)); + cs8230_t *cs8230 = (cs8230_t *) calloc(1, sizeof(cs8230_t)); io_sethandler(0x0022, 0x0002, cs8230_read, NULL, NULL, cs8230_write, NULL, NULL, cs8230); @@ -178,7 +177,7 @@ const device_t cs8230_device = { .init = cs8230_init, .close = cs8230_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/et6000.c b/src/chipset/et6000.c index f2cffd7f7..14ebf852e 100644 --- a/src/chipset/et6000.c +++ b/src/chipset/et6000.c @@ -137,8 +137,7 @@ et6000_close(void *priv) static void * et6000_init(UNUSED(const device_t *info)) { - et6000_t *dev = (et6000_t *) malloc(sizeof(et6000_t)); - memset(dev, 0, sizeof(et6000_t)); + et6000_t *dev = (et6000_t *) calloc(1, sizeof(et6000_t)); /* Port 92h */ device_add(&port_92_device); @@ -162,7 +161,7 @@ const device_t et6000_device = { .init = et6000_init, .close = et6000_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/gc100.c b/src/chipset/gc100.c index 0b4717903..23455b952 100644 --- a/src/chipset/gc100.c +++ b/src/chipset/gc100.c @@ -208,8 +208,7 @@ gc100_close(void *priv) static void * gc100_init(const device_t *info) { - gc100_t *dev = (gc100_t *) malloc(sizeof(gc100_t)); - memset(dev, 0, sizeof(gc100_t)); + gc100_t *dev = (gc100_t *) calloc(1, sizeof(gc100_t)); dev->reg[0x2] = 0xff; dev->reg[0x3] = 0x0; @@ -238,7 +237,7 @@ const device_t gc100_device = { .init = gc100_init, .close = gc100_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -252,7 +251,7 @@ const device_t gc100a_device = { .init = gc100_init, .close = gc100_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/headland.c b/src/chipset/headland.c index db5922470..1172d105d 100644 --- a/src/chipset/headland.c +++ b/src/chipset/headland.c @@ -594,8 +594,7 @@ headland_init(const device_t *info) headland_t *dev; int ht386 = 0; - dev = (headland_t *) malloc(sizeof(headland_t)); - memset(dev, 0x00, sizeof(headland_t)); + dev = (headland_t *) calloc(1, sizeof(headland_t)); dev->has_cri = (info->local & HEADLAND_HAS_CRI); dev->has_sleep = (info->local & HEADLAND_HAS_SLEEP); @@ -699,7 +698,7 @@ const device_t headland_gc10x_device = { .init = headland_init, .close = headland_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -713,7 +712,7 @@ const device_t headland_gc113_device = { .init = headland_init, .close = headland_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -727,7 +726,7 @@ const device_t headland_ht18a_device = { .init = headland_init, .close = headland_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -741,7 +740,7 @@ const device_t headland_ht18b_device = { .init = headland_init, .close = headland_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -755,7 +754,7 @@ const device_t headland_ht18c_device = { .init = headland_init, .close = headland_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -769,7 +768,7 @@ const device_t headland_ht21c_d_device = { .init = headland_init, .close = headland_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -783,7 +782,7 @@ const device_t headland_ht21e_device = { .init = headland_init, .close = headland_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/ims8848.c b/src/chipset/ims8848.c index 3e86a44e1..094ee31f8 100644 --- a/src/chipset/ims8848.c +++ b/src/chipset/ims8848.c @@ -381,8 +381,7 @@ ims8848_close(void *priv) static void * ims8848_init(UNUSED(const device_t *info)) { - ims8848_t *dev = (ims8848_t *) malloc(sizeof(ims8848_t)); - memset(dev, 0, sizeof(ims8848_t)); + ims8848_t *dev = (ims8848_t *) calloc(1, sizeof(ims8848_t)); device_add(&port_92_device); @@ -416,7 +415,7 @@ const device_t ims8848_device = { .init = ims8848_init, .close = ims8848_close, .reset = ims8848_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/intel_420ex.c b/src/chipset/intel_420ex.c index 34335d53c..662fd0509 100644 --- a/src/chipset/intel_420ex.c +++ b/src/chipset/intel_420ex.c @@ -533,8 +533,7 @@ i420ex_speed_changed(void *priv) static void * i420ex_init(const device_t *info) { - i420ex_t *dev = (i420ex_t *) malloc(sizeof(i420ex_t)); - memset(dev, 0, sizeof(i420ex_t)); + i420ex_t *dev = (i420ex_t *) calloc(1, sizeof(i420ex_t)); dev->smram = smram_add(); @@ -579,7 +578,7 @@ const device_t i420ex_device = { .init = i420ex_init, .close = i420ex_close, .reset = i420ex_reset, - { .available = NULL }, + .available = NULL, .speed_changed = i420ex_speed_changed, .force_redraw = NULL, .config = NULL @@ -593,7 +592,7 @@ const device_t i420ex_ide_device = { .init = i420ex_init, .close = i420ex_close, .reset = i420ex_reset, - { .available = NULL }, + .available = NULL, .speed_changed = i420ex_speed_changed, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/intel_4x0.c b/src/chipset/intel_4x0.c index 2f6afa940..f9d6af150 100644 --- a/src/chipset/intel_4x0.c +++ b/src/chipset/intel_4x0.c @@ -1608,11 +1608,9 @@ i4x0_close(void *priv) static void * i4x0_init(const device_t *info) { - i4x0_t *dev = (i4x0_t *) malloc(sizeof(i4x0_t)); + i4x0_t *dev = (i4x0_t *) calloc(1, sizeof(i4x0_t)); uint8_t *regs; - memset(dev, 0, sizeof(i4x0_t)); - dev->smram_low = smram_add(); dev->smram_high = smram_add(); @@ -1967,7 +1965,7 @@ const device_t i420tx_device = { .init = i4x0_init, .close = i4x0_close, .reset = i4x0_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -1981,7 +1979,7 @@ const device_t i420zx_device = { .init = i4x0_init, .close = i4x0_close, .reset = i4x0_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -1995,7 +1993,7 @@ const device_t i430lx_device = { .init = i4x0_init, .close = i4x0_close, .reset = i4x0_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2009,7 +2007,7 @@ const device_t i430nx_device = { .init = i4x0_init, .close = i4x0_close, .reset = i4x0_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2023,7 +2021,7 @@ const device_t i430fx_device = { .init = i4x0_init, .close = i4x0_close, .reset = i4x0_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2037,7 +2035,7 @@ const device_t i430fx_rev02_device = { .init = i4x0_init, .close = i4x0_close, .reset = i4x0_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2051,7 +2049,7 @@ const device_t i430hx_device = { .init = i4x0_init, .close = i4x0_close, .reset = i4x0_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2065,7 +2063,7 @@ const device_t i430vx_device = { .init = i4x0_init, .close = i4x0_close, .reset = i4x0_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2079,7 +2077,7 @@ const device_t i430tx_device = { .init = i4x0_init, .close = i4x0_close, .reset = i4x0_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2093,7 +2091,7 @@ const device_t i440fx_device = { .init = i4x0_init, .close = i4x0_close, .reset = i4x0_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2107,7 +2105,7 @@ const device_t i440lx_device = { .init = i4x0_init, .close = i4x0_close, .reset = i4x0_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2121,7 +2119,7 @@ const device_t i440ex_device = { .init = i4x0_init, .close = i4x0_close, .reset = i4x0_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2135,7 +2133,7 @@ const device_t i440bx_device = { .init = i4x0_init, .close = i4x0_close, .reset = i4x0_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2149,7 +2147,7 @@ const device_t i440bx_no_agp_device = { .init = i4x0_init, .close = i4x0_close, .reset = i4x0_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2163,7 +2161,7 @@ const device_t i440gx_device = { .init = i4x0_init, .close = i4x0_close, .reset = i4x0_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2177,7 +2175,7 @@ const device_t i440zx_device = { .init = i4x0_init, .close = i4x0_close, .reset = i4x0_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/intel_82335.c b/src/chipset/intel_82335.c index da0cc30f6..bd53e0d05 100644 --- a/src/chipset/intel_82335.c +++ b/src/chipset/intel_82335.c @@ -171,8 +171,7 @@ intel_82335_close(void *priv) static void * intel_82335_init(UNUSED(const device_t *info)) { - intel_82335_t *dev = (intel_82335_t *) malloc(sizeof(intel_82335_t)); - memset(dev, 0, sizeof(intel_82335_t)); + intel_82335_t *dev = (intel_82335_t *) calloc(1, sizeof(intel_82335_t)); memset(dev->regs, 0, sizeof(dev->regs)); @@ -209,7 +208,7 @@ const device_t intel_82335_device = { .init = intel_82335_init, .close = intel_82335_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/intel_i450kx.c b/src/chipset/intel_i450kx.c index 2f6547309..34cc6a62f 100644 --- a/src/chipset/intel_i450kx.c +++ b/src/chipset/intel_i450kx.c @@ -799,8 +799,8 @@ i450kx_close(void *priv) static void * i450kx_init(UNUSED(const device_t *info)) { - i450kx_t *dev = (i450kx_t *) malloc(sizeof(i450kx_t)); - memset(dev, 0, sizeof(i450kx_t)); + i450kx_t *dev = (i450kx_t *) calloc(1, sizeof(i450kx_t)); + pci_add_card(PCI_ADD_NORTHBRIDGE, pb_read, pb_write, dev, &dev->pb_slot); /* Device 19h: Intel 450KX PCI Bridge PB */ pci_add_card(PCI_ADD_NORTHBRIDGE_SEC, mc_read, mc_write, dev, &dev->mc_slot); /* Device 14h: Intel 450KX Memory Controller MC */ @@ -824,7 +824,7 @@ const device_t i450kx_device = { .init = i450kx_init, .close = i450kx_close, .reset = i450kx_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/intel_piix.c b/src/chipset/intel_piix.c index c6a6fc0ac..6969d3274 100644 --- a/src/chipset/intel_piix.c +++ b/src/chipset/intel_piix.c @@ -1538,8 +1538,7 @@ piix_speed_changed(void *priv) static void * piix_init(const device_t *info) { - piix_t *dev = (piix_t *) malloc(sizeof(piix_t)); - memset(dev, 0, sizeof(piix_t)); + piix_t *dev = (piix_t *) calloc(1, sizeof(piix_t)); dev->type = info->local & 0x0f; /* If (dev->type == 4) and (dev->rev & 0x08), then this is PIIX4E. */ @@ -1674,7 +1673,7 @@ const device_t piix_device = { .init = piix_init, .close = piix_close, .reset = piix_reset, - { .available = NULL }, + .available = NULL, .speed_changed = piix_speed_changed, .force_redraw = NULL, .config = NULL @@ -1688,7 +1687,7 @@ const device_t piix_no_mirq_device = { .init = piix_init, .close = piix_close, .reset = piix_reset, - { .available = NULL }, + .available = NULL, .speed_changed = piix_speed_changed, .force_redraw = NULL, .config = NULL @@ -1702,7 +1701,7 @@ const device_t piix_rev02_device = { .init = piix_init, .close = piix_close, .reset = piix_reset, - { .available = NULL }, + .available = NULL, .speed_changed = piix_speed_changed, .force_redraw = NULL, .config = NULL @@ -1716,7 +1715,7 @@ const device_t piix3_device = { .init = piix_init, .close = piix_close, .reset = piix_reset, - { .available = NULL }, + .available = NULL, .speed_changed = piix_speed_changed, .force_redraw = NULL, .config = NULL @@ -1730,7 +1729,7 @@ const device_t piix3_ioapic_device = { .init = piix_init, .close = piix_close, .reset = piix_reset, - { .available = NULL }, + .available = NULL, .speed_changed = piix_speed_changed, .force_redraw = NULL, .config = NULL @@ -1744,7 +1743,7 @@ const device_t piix4_device = { .init = piix_init, .close = piix_close, .reset = piix_reset, - { .available = NULL }, + .available = NULL, .speed_changed = piix_speed_changed, .force_redraw = NULL, .config = NULL @@ -1758,7 +1757,7 @@ const device_t piix4e_device = { .init = piix_init, .close = piix_close, .reset = piix_reset, - { .available = NULL }, + .available = NULL, .speed_changed = piix_speed_changed, .force_redraw = NULL, .config = NULL @@ -1772,7 +1771,7 @@ const device_t slc90e66_device = { .init = piix_init, .close = piix_close, .reset = piix_reset, - { .available = NULL }, + .available = NULL, .speed_changed = piix_speed_changed, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/intel_sio.c b/src/chipset/intel_sio.c index 03a292da8..9b6d28ab1 100644 --- a/src/chipset/intel_sio.c +++ b/src/chipset/intel_sio.c @@ -508,8 +508,7 @@ sio_speed_changed(void *priv) static void * sio_init(const device_t *info) { - sio_t *dev = (sio_t *) malloc(sizeof(sio_t)); - memset(dev, 0, sizeof(sio_t)); + sio_t *dev = (sio_t *) calloc(1, sizeof(sio_t)); pci_add_card(PCI_ADD_SOUTHBRIDGE, sio_read, sio_write, dev, &dev->pci_slot); @@ -568,7 +567,7 @@ const device_t sio_device = { .init = sio_init, .close = sio_close, .reset = sio_reset, - { .available = NULL }, + .available = NULL, .speed_changed = sio_speed_changed, .force_redraw = NULL, .config = NULL @@ -582,7 +581,7 @@ const device_t sio_zb_device = { .init = sio_init, .close = sio_close, .reset = sio_reset, - { .available = NULL }, + .available = NULL, .speed_changed = sio_speed_changed, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/neat.c b/src/chipset/neat.c index 000492d14..069fa87e4 100644 --- a/src/chipset/neat.c +++ b/src/chipset/neat.c @@ -906,8 +906,7 @@ neat_init(UNUSED(const device_t *info)) uint8_t j; /* Create an instance. */ - dev = (neat_t *) malloc(sizeof(neat_t)); - memset(dev, 0x00, sizeof(neat_t)); + dev = (neat_t *) calloc(1, sizeof(neat_t)); /* Get configured I/O address. */ j = (dev->regs[REG_RB9] & RB9_BASE) >> RB9_BASE_SH; @@ -1124,7 +1123,7 @@ const device_t neat_device = { .init = neat_init, .close = neat_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/olivetti_eva.c b/src/chipset/olivetti_eva.c index 1f5eacc6c..7defac6ae 100644 --- a/src/chipset/olivetti_eva.c +++ b/src/chipset/olivetti_eva.c @@ -134,8 +134,7 @@ olivetti_eva_close(void *priv) static void * olivetti_eva_init(UNUSED(const device_t *info)) { - olivetti_eva_t *dev = (olivetti_eva_t *) malloc(sizeof(olivetti_eva_t)); - memset(dev, 0, sizeof(olivetti_eva_t)); + olivetti_eva_t *dev = (olivetti_eva_t *) calloc(1, sizeof(olivetti_eva_t)); /* GA98 registers */ dev->reg_065 = 0x00; @@ -171,7 +170,7 @@ const device_t olivetti_eva_device = { .init = olivetti_eva_init, .close = olivetti_eva_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/opti283.c b/src/chipset/opti283.c index 63976985b..395ad4212 100644 --- a/src/chipset/opti283.c +++ b/src/chipset/opti283.c @@ -284,8 +284,7 @@ opti283_close(void *priv) static void * opti283_init(UNUSED(const device_t *info)) { - opti283_t *dev = (opti283_t *) malloc(sizeof(opti283_t)); - memset(dev, 0x00, sizeof(opti283_t)); + opti283_t *dev = (opti283_t *) calloc(1, sizeof(opti283_t)); io_sethandler(0x0022, 0x0001, opti283_read, NULL, NULL, opti283_write, NULL, NULL, dev); io_sethandler(0x0023, 0x0001, opti283_read, NULL, NULL, opti283_write, NULL, NULL, dev); @@ -324,7 +323,7 @@ const device_t opti283_device = { .init = opti283_init, .close = opti283_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/opti291.c b/src/chipset/opti291.c index 6d2256974..91b9010e2 100644 --- a/src/chipset/opti291.c +++ b/src/chipset/opti291.c @@ -138,8 +138,7 @@ opti291_close(void *priv) static void * opti291_init(UNUSED(const device_t *info)) { - opti291_t *dev = (opti291_t *) malloc(sizeof(opti291_t)); - memset(dev, 0, sizeof(opti291_t)); + opti291_t *dev = (opti291_t *) calloc(1, sizeof(opti291_t)); io_sethandler(0x022, 0x0001, opti291_read, NULL, NULL, opti291_write, NULL, NULL, dev); io_sethandler(0x024, 0x0001, opti291_read, NULL, NULL, opti291_write, NULL, NULL, dev); @@ -161,7 +160,7 @@ const device_t opti291_device = { .init = opti291_init, .close = opti291_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/opti391.c b/src/chipset/opti391.c index c22c2a04b..7d3c10c98 100644 --- a/src/chipset/opti391.c +++ b/src/chipset/opti391.c @@ -374,7 +374,7 @@ const device_t opti381_device = { .init = opti391_init, .close = opti391_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -388,7 +388,7 @@ const device_t opti481_device = { .init = opti391_init, .close = opti391_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -402,7 +402,7 @@ const device_t opti391_device = { .init = opti391_init, .close = opti391_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/opti495.c b/src/chipset/opti495.c index 84ef6a202..aa4e4b4c5 100644 --- a/src/chipset/opti495.c +++ b/src/chipset/opti495.c @@ -219,8 +219,7 @@ opti495_close(void *priv) static void * opti495_init(const device_t *info) { - opti495_t *dev = (opti495_t *) malloc(sizeof(opti495_t)); - memset(dev, 0, sizeof(opti495_t)); + opti495_t *dev = (opti495_t *) calloc(1, sizeof(opti495_t)); device_add(&port_92_device); @@ -271,7 +270,7 @@ const device_t opti493_device = { .init = opti495_init, .close = opti495_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -285,7 +284,7 @@ const device_t opti495_device = { .init = opti495_init, .close = opti495_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/opti499.c b/src/chipset/opti499.c index ecadd2224..d54e8184e 100644 --- a/src/chipset/opti499.c +++ b/src/chipset/opti499.c @@ -242,8 +242,7 @@ opti499_close(void *priv) static void * opti499_init(UNUSED(const device_t *info)) { - opti499_t *dev = (opti499_t *) malloc(sizeof(opti499_t)); - memset(dev, 0, sizeof(opti499_t)); + opti499_t *dev = (opti499_t *) calloc(1, sizeof(opti499_t)); device_add(&port_92_device); @@ -265,7 +264,7 @@ const device_t opti499_device = { .init = opti499_init, .close = opti499_close, .reset = opti499_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/opti5x7.c b/src/chipset/opti5x7.c index 494fdee64..03fde4173 100644 --- a/src/chipset/opti5x7.c +++ b/src/chipset/opti5x7.c @@ -172,8 +172,7 @@ opti5x7_close(void *priv) static void * opti5x7_init(const device_t *info) { - opti5x7_t *dev = (opti5x7_t *) malloc(sizeof(opti5x7_t)); - memset(dev, 0, sizeof(opti5x7_t)); + opti5x7_t *dev = (opti5x7_t *) calloc(1, sizeof(opti5x7_t)); dev->is_pci = info->local; @@ -193,7 +192,7 @@ const device_t opti5x7_device = { .init = opti5x7_init, .close = opti5x7_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -207,7 +206,7 @@ const device_t opti5x7_pci_device = { .init = opti5x7_init, .close = opti5x7_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/opti602.c b/src/chipset/opti602.c index 3b5614ff4..7082408c7 100644 --- a/src/chipset/opti602.c +++ b/src/chipset/opti602.c @@ -218,7 +218,7 @@ const device_t opti601_device = { .init = opti602_init, .close = opti602_close, .reset = opti602_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -232,7 +232,7 @@ const device_t opti602_device = { .init = opti602_init, .close = opti602_close, .reset = opti602_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/opti822.c b/src/chipset/opti822.c index 3e9316f2b..471fbe393 100644 --- a/src/chipset/opti822.c +++ b/src/chipset/opti822.c @@ -394,8 +394,7 @@ opti822_close(void *priv) static void * opti822_init(UNUSED(const device_t *info)) { - opti822_t *dev = (opti822_t *) malloc(sizeof(opti822_t)); - memset(dev, 0, sizeof(opti822_t)); + opti822_t *dev = (opti822_t *) calloc(1, sizeof(opti822_t)); pci_add_card(PCI_ADD_NORTHBRIDGE, opti822_pci_read, opti822_pci_write, dev, &dev->pci_slot); @@ -412,7 +411,7 @@ const device_t opti822_device = { .init = opti822_init, .close = opti822_close, .reset = opti822_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/opti895.c b/src/chipset/opti895.c index f1878a51b..cb55ef2a7 100644 --- a/src/chipset/opti895.c +++ b/src/chipset/opti895.c @@ -259,8 +259,7 @@ opti895_close(void *priv) static void * opti895_init(const device_t *info) { - opti895_t *dev = (opti895_t *) malloc(sizeof(opti895_t)); - memset(dev, 0, sizeof(opti895_t)); + opti895_t *dev = (opti895_t *) calloc(1, sizeof(opti895_t)); device_add(&port_92_device); @@ -306,7 +305,7 @@ const device_t opti802g_device = { .init = opti895_init, .close = opti895_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -320,7 +319,7 @@ const device_t opti802g_pci_device = { .init = opti895_init, .close = opti895_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -334,7 +333,7 @@ const device_t opti895_device = { .init = opti895_init, .close = opti895_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/scamp.c b/src/chipset/scamp.c index 31e24eeba..8e7892c2e 100644 --- a/src/chipset/scamp.c +++ b/src/chipset/scamp.c @@ -1046,8 +1046,7 @@ static void * scamp_init(UNUSED(const device_t *info)) { uint32_t addr; - scamp_t *dev = (scamp_t *) malloc(sizeof(scamp_t)); - memset(dev, 0x00, sizeof(scamp_t)); + scamp_t *dev = (scamp_t *) calloc(1, sizeof(scamp_t)); dev->cfg_regs[CFG_ID] = ID_VL82C311; dev->cfg_enable = 1; @@ -1204,7 +1203,7 @@ const device_t vlsi_scamp_device = { .init = scamp_init, .close = scamp_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/scat.c b/src/chipset/scat.c index d168b643f..43f93649e 100644 --- a/src/chipset/scat.c +++ b/src/chipset/scat.c @@ -1403,8 +1403,7 @@ scat_init(const device_t *info) uint32_t k; int sx; - dev = (scat_t *) malloc(sizeof(scat_t)); - memset(dev, 0x00, sizeof(scat_t)); + dev = (scat_t *) calloc(1, sizeof(scat_t)); dev->type = info->local; sx = (dev->type == 32) ? 1 : 0; @@ -1559,7 +1558,7 @@ const device_t scat_device = { .init = scat_init, .close = scat_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -1573,7 +1572,7 @@ const device_t scat_4_device = { .init = scat_init, .close = scat_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -1587,7 +1586,7 @@ const device_t scat_sx_device = { .init = scat_init, .close = scat_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/sis_5511.c b/src/chipset/sis_5511.c index aa841ed9c..38fcfe717 100644 --- a/src/chipset/sis_5511.c +++ b/src/chipset/sis_5511.c @@ -165,7 +165,7 @@ const device_t sis_5511_device = { .init = sis_5511_init, .close = sis_5511_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/sis_5511_h2p.c b/src/chipset/sis_5511_h2p.c index 7916d6ae2..543fcacc5 100644 --- a/src/chipset/sis_5511_h2p.c +++ b/src/chipset/sis_5511_h2p.c @@ -454,7 +454,7 @@ const device_t sis_5511_h2p_device = { .init = sis_5511_host_to_pci_init, .close = sis_5511_host_to_pci_close, .reset = sis_5511_host_to_pci_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/sis_5513_ide.c b/src/chipset/sis_5513_ide.c index 5cbfbdea8..9e3a0ad07 100644 --- a/src/chipset/sis_5513_ide.c +++ b/src/chipset/sis_5513_ide.c @@ -456,7 +456,7 @@ const device_t sis_5513_ide_device = { .init = sis_5513_ide_init, .close = sis_5513_ide_close, .reset = sis_5513_ide_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -470,7 +470,7 @@ const device_t sis_5572_ide_device = { .init = sis_5513_ide_init, .close = sis_5513_ide_close, .reset = sis_5513_ide_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -484,7 +484,7 @@ const device_t sis_5582_ide_device = { .init = sis_5513_ide_init, .close = sis_5513_ide_close, .reset = sis_5513_ide_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -498,7 +498,7 @@ const device_t sis_5591_5600_ide_device = { .init = sis_5513_ide_init, .close = sis_5513_ide_close, .reset = sis_5513_ide_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/sis_5513_p2i.c b/src/chipset/sis_5513_p2i.c index 4205db161..3655ccc3f 100644 --- a/src/chipset/sis_5513_p2i.c +++ b/src/chipset/sis_5513_p2i.c @@ -115,7 +115,7 @@ sis_5513_apc_reset(sis_5513_pci_to_isa_t *dev) } static void -sis_5513_apc_write(uint16_t addr, uint8_t val, void *priv) +sis_5513_apc_write(UNUSED(uint16_t addr), uint8_t val, void *priv) { sis_5513_pci_to_isa_t *dev = (sis_5513_pci_to_isa_t *) priv; uint8_t nvr_index = nvr_get_index(dev->nvr, 0); @@ -135,7 +135,7 @@ sis_5513_apc_write(uint16_t addr, uint8_t val, void *priv) } static uint8_t -sis_5513_apc_read(uint16_t addr, void *priv) +sis_5513_apc_read(UNUSED(uint16_t addr), void *priv) { sis_5513_pci_to_isa_t *dev = (sis_5513_pci_to_isa_t *) priv; uint8_t nvr_index = nvr_get_index(dev->nvr, 0); @@ -1318,7 +1318,7 @@ const device_t sis_5513_p2i_device = { .init = sis_5513_pci_to_isa_init, .close = sis_5513_pci_to_isa_close, .reset = sis_5513_pci_to_isa_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -1332,7 +1332,7 @@ const device_t sis_5572_p2i_device = { .init = sis_5513_pci_to_isa_init, .close = sis_5513_pci_to_isa_close, .reset = sis_5513_pci_to_isa_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -1347,7 +1347,7 @@ const device_t sis_5582_p2i_device = { .init = sis_5513_pci_to_isa_init, .close = sis_5513_pci_to_isa_close, .reset = sis_5513_pci_to_isa_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -1362,7 +1362,7 @@ const device_t sis_5595_1997_p2i_device = { .init = sis_5513_pci_to_isa_init, .close = sis_5513_pci_to_isa_close, .reset = sis_5513_pci_to_isa_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -1376,7 +1376,7 @@ const device_t sis_5595_p2i_device = { .init = sis_5513_pci_to_isa_init, .close = sis_5513_pci_to_isa_close, .reset = sis_5513_pci_to_isa_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/sis_5571.c b/src/chipset/sis_5571.c index 3fb111978..3980704fd 100644 --- a/src/chipset/sis_5571.c +++ b/src/chipset/sis_5571.c @@ -177,7 +177,7 @@ const device_t sis_5571_device = { .init = sis_5571_init, .close = sis_5571_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/sis_5571_h2p.c b/src/chipset/sis_5571_h2p.c index 4a4ee9b83..d04964581 100644 --- a/src/chipset/sis_5571_h2p.c +++ b/src/chipset/sis_5571_h2p.c @@ -451,7 +451,7 @@ const device_t sis_5571_h2p_device = { .init = sis_5571_host_to_pci_init, .close = sis_5571_host_to_pci_close, .reset = sis_5571_host_to_pci_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/sis_5571_old.c b/src/chipset/sis_5571_old.c index f130ecd8a..495137aed 100644 --- a/src/chipset/sis_5571_old.c +++ b/src/chipset/sis_5571_old.c @@ -732,8 +732,7 @@ sis_5571_close(void *priv) static void * sis_5571_init(UNUSED(const device_t *info)) { - sis_5571_t *dev = (sis_5571_t *) malloc(sizeof(sis_5571_t)); - memset(dev, 0x00, sizeof(sis_5571_t)); + sis_5571_t *dev = (sis_5571_t *) calloc(1, sizeof(sis_5571_t)); pci_add_card(PCI_ADD_NORTHBRIDGE, memory_pci_bridge_read, memory_pci_bridge_write, dev, &dev->nb_slot); pci_add_card(PCI_ADD_SOUTHBRIDGE, pci_isa_bridge_read, pci_isa_bridge_write, dev, &dev->sb_slot); @@ -765,7 +764,7 @@ const device_t sis_5571_device = { .init = sis_5571_init, .close = sis_5571_close, .reset = sis_5571_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/sis_5572_usb.c b/src/chipset/sis_5572_usb.c index 250c32587..bc7dc7d38 100644 --- a/src/chipset/sis_5572_usb.c +++ b/src/chipset/sis_5572_usb.c @@ -288,7 +288,7 @@ const device_t sis_5572_usb_device = { .init = sis_5572_usb_init, .close = sis_5572_usb_close, .reset = sis_5572_usb_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -302,7 +302,7 @@ const device_t sis_5582_usb_device = { .init = sis_5572_usb_init, .close = sis_5572_usb_close, .reset = sis_5572_usb_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -316,7 +316,7 @@ const device_t sis_5595_usb_device = { .init = sis_5572_usb_init, .close = sis_5572_usb_close, .reset = sis_5572_usb_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/sis_5581.c b/src/chipset/sis_5581.c index e2308c2d9..998ac5350 100644 --- a/src/chipset/sis_5581.c +++ b/src/chipset/sis_5581.c @@ -177,7 +177,7 @@ const device_t sis_5581_device = { .init = sis_5581_init, .close = sis_5581_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/sis_5581_h2p.c b/src/chipset/sis_5581_h2p.c index 30bd70bfe..d01e9dd28 100644 --- a/src/chipset/sis_5581_h2p.c +++ b/src/chipset/sis_5581_h2p.c @@ -545,7 +545,7 @@ const device_t sis_5581_h2p_device = { .init = sis_5581_host_to_pci_init, .close = sis_5581_host_to_pci_close, .reset = sis_5581_host_to_pci_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/sis_5591.c b/src/chipset/sis_5591.c index 969fcb8dd..3cb11cb5b 100644 --- a/src/chipset/sis_5591.c +++ b/src/chipset/sis_5591.c @@ -189,7 +189,7 @@ const device_t sis_5591_1997_device = { .init = sis_5591_init, .close = sis_5591_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -203,7 +203,7 @@ const device_t sis_5591_device = { .init = sis_5591_init, .close = sis_5591_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/sis_5591_h2p.c b/src/chipset/sis_5591_h2p.c index 8fcbeeb6f..048e7deea 100644 --- a/src/chipset/sis_5591_h2p.c +++ b/src/chipset/sis_5591_h2p.c @@ -486,7 +486,7 @@ const device_t sis_5591_h2p_device = { .init = sis_5591_host_to_pci_init, .close = sis_5591_host_to_pci_close, .reset = sis_5591_host_to_pci_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/sis_5595_pmu.c b/src/chipset/sis_5595_pmu.c index de351ad7c..7de9735f1 100644 --- a/src/chipset/sis_5595_pmu.c +++ b/src/chipset/sis_5595_pmu.c @@ -119,7 +119,7 @@ sis_5595_pmu_trap_io_mask(int size, uint16_t addr, uint8_t write, uint8_t val, v } static void -sis_5595_pmu_trap_io_ide_bm(int size, uint16_t addr, uint8_t write, uint8_t val, void *priv) +sis_5595_pmu_trap_io_ide_bm(UNUSED(int size), UNUSED(uint16_t addr), UNUSED(uint8_t write), UNUSED(uint8_t val), void *priv) { sis_5595_pmu_io_trap_t *trap = (sis_5595_pmu_io_trap_t *) priv; sis_5595_pmu_t *dev = (sis_5595_pmu_t *) trap->priv; @@ -433,7 +433,7 @@ const device_t sis_5595_1997_pmu_device = { .init = sis_5595_pmu_init, .close = sis_5595_pmu_close, .reset = sis_5595_pmu_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -447,7 +447,7 @@ const device_t sis_5595_pmu_device = { .init = sis_5595_pmu_init, .close = sis_5595_pmu_close, .reset = sis_5595_pmu_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/sis_55xx.c b/src/chipset/sis_55xx.c index 2cad21f22..1cb0744eb 100644 --- a/src/chipset/sis_55xx.c +++ b/src/chipset/sis_55xx.c @@ -89,7 +89,7 @@ const device_t sis_55xx_common_device = { .init = sis_55xx_common_init, .close = sis_55xx_common_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/sis_5600.c b/src/chipset/sis_5600.c index ed7384740..1ed7f9ad0 100644 --- a/src/chipset/sis_5600.c +++ b/src/chipset/sis_5600.c @@ -189,7 +189,7 @@ const device_t sis_5600_1997_device = { .init = sis_5600_init, .close = sis_5600_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -203,7 +203,7 @@ const device_t sis_5600_device = { .init = sis_5600_init, .close = sis_5600_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/sis_5600_h2p.c b/src/chipset/sis_5600_h2p.c index f6ee926da..a15c6fff5 100644 --- a/src/chipset/sis_5600_h2p.c +++ b/src/chipset/sis_5600_h2p.c @@ -427,7 +427,7 @@ const device_t sis_5600_h2p_device = { .init = sis_5600_host_to_pci_init, .close = sis_5600_host_to_pci_close, .reset = sis_5600_host_to_pci_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/sis_85c310.c b/src/chipset/sis_85c310.c index 296307fe1..dfbd4b465 100644 --- a/src/chipset/sis_85c310.c +++ b/src/chipset/sis_85c310.c @@ -130,8 +130,7 @@ rabbit_close(void *priv) static void * rabbit_init(UNUSED(const device_t *info)) { - rabbit_t *dev = (rabbit_t *) malloc(sizeof(rabbit_t)); - memset(dev, 0, sizeof(rabbit_t)); + rabbit_t *dev = (rabbit_t *) calloc(1, sizeof(rabbit_t)); io_sethandler(0x0022, 0x0002, rabbit_read, NULL, NULL, rabbit_write, NULL, NULL, dev); @@ -146,7 +145,7 @@ const device_t rabbit_device = { .init = rabbit_init, .close = rabbit_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/sis_85c496.c b/src/chipset/sis_85c496.c index 3c3d5bd8c..10bccc1c8 100644 --- a/src/chipset/sis_85c496.c +++ b/src/chipset/sis_85c496.c @@ -637,8 +637,7 @@ static void * sis_85c496_init(const device_t *info) { - sis_85c496_t *dev = malloc(sizeof(sis_85c496_t)); - memset(dev, 0x00, sizeof(sis_85c496_t)); + sis_85c496_t *dev = calloc(1, sizeof(sis_85c496_t)); dev->smram = smram_add(); @@ -702,7 +701,7 @@ const device_t sis_85c496_device = { .init = sis_85c496_init, .close = sis_85c496_close, .reset = sis_85c496_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -716,7 +715,7 @@ const device_t sis_85c496_ls486e_device = { .init = sis_85c496_init, .close = sis_85c496_close, .reset = sis_85c496_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/sis_85c4xx.c b/src/chipset/sis_85c4xx.c index f80ecf99e..6e26a4751 100644 --- a/src/chipset/sis_85c4xx.c +++ b/src/chipset/sis_85c4xx.c @@ -368,8 +368,7 @@ sis_85c4xx_close(void *priv) static void * sis_85c4xx_init(const device_t *info) { - sis_85c4xx_t *dev = (sis_85c4xx_t *) malloc(sizeof(sis_85c4xx_t)); - memset(dev, 0, sizeof(sis_85c4xx_t)); + sis_85c4xx_t *dev = (sis_85c4xx_t *) calloc(1, sizeof(sis_85c4xx_t)); dev->is_471 = (info->local >> 8) & 0xff; @@ -403,7 +402,7 @@ const device_t sis_85c401_device = { .init = sis_85c4xx_init, .close = sis_85c4xx_close, .reset = sis_85c4xx_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -417,7 +416,7 @@ const device_t sis_85c460_device = { .init = sis_85c4xx_init, .close = sis_85c4xx_close, .reset = sis_85c4xx_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -432,7 +431,7 @@ const device_t sis_85c461_device = { .init = sis_85c4xx_init, .close = sis_85c4xx_close, .reset = sis_85c4xx_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -446,7 +445,7 @@ const device_t sis_85c471_device = { .init = sis_85c4xx_init, .close = sis_85c4xx_close, .reset = sis_85c4xx_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/sis_85c50x.c b/src/chipset/sis_85c50x.c index 2286105ce..192ae3767 100644 --- a/src/chipset/sis_85c50x.c +++ b/src/chipset/sis_85c50x.c @@ -684,7 +684,7 @@ const device_t sis_85c50x_device = { .init = sis_85c50x_init, .close = sis_85c50x_close, .reset = sis_85c50x_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -698,7 +698,7 @@ const device_t sis_550x_85c503_device = { .init = sis_85c50x_init, .close = sis_85c50x_close, .reset = sis_85c50x_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -712,7 +712,7 @@ const device_t sis_85c50x_5503_device = { .init = sis_85c50x_init, .close = sis_85c50x_close, .reset = sis_85c50x_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -726,7 +726,7 @@ const device_t sis_550x_device = { .init = sis_85c50x_init, .close = sis_85c50x_close, .reset = sis_85c50x_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/stpc.c b/src/chipset/stpc.c index dbe39ec5c..23cc56bd3 100644 --- a/src/chipset/stpc.c +++ b/src/chipset/stpc.c @@ -912,8 +912,7 @@ stpc_init(const device_t *info) { stpc_log("STPC: init()\n"); - stpc_t *dev = (stpc_t *) malloc(sizeof(stpc_t)); - memset(dev, 0, sizeof(stpc_t)); + stpc_t *dev = (stpc_t *) calloc(1, sizeof(stpc_t)); dev->local = info->local; @@ -963,8 +962,7 @@ stpc_serial_init(UNUSED(const device_t *info)) { stpc_log("STPC: serial_init()\n"); - stpc_serial_t *dev = (stpc_serial_t *) malloc(sizeof(stpc_serial_t)); - memset(dev, 0, sizeof(stpc_serial_t)); + stpc_serial_t *dev = (stpc_serial_t *) calloc(1, sizeof(stpc_serial_t)); dev->uart[0] = device_add_inst(&ns16550_device, 1); dev->uart[1] = device_add_inst(&ns16550_device, 2); @@ -1076,8 +1074,7 @@ stpc_lpt_init(UNUSED(const device_t *info)) { stpc_log("STPC: lpt_init()\n"); - stpc_lpt_t *dev = (stpc_lpt_t *) malloc(sizeof(stpc_lpt_t)); - memset(dev, 0, sizeof(stpc_lpt_t)); + stpc_lpt_t *dev = (stpc_lpt_t *) calloc(1, sizeof(stpc_lpt_t)); stpc_lpt_reset(dev); @@ -1096,7 +1093,7 @@ const device_t stpc_client_device = { .init = stpc_init, .close = stpc_close, .reset = stpc_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -1110,7 +1107,7 @@ const device_t stpc_consumer2_device = { .init = stpc_init, .close = stpc_close, .reset = stpc_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -1124,7 +1121,7 @@ const device_t stpc_elite_device = { .init = stpc_init, .close = stpc_close, .reset = stpc_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -1138,7 +1135,7 @@ const device_t stpc_atlas_device = { .init = stpc_init, .close = stpc_close, .reset = stpc_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -1153,7 +1150,7 @@ const device_t stpc_serial_device = { .init = stpc_serial_init, .close = stpc_serial_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -1167,7 +1164,7 @@ const device_t stpc_lpt_device = { .init = stpc_lpt_init, .close = stpc_lpt_close, .reset = stpc_lpt_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/umc_8886.c b/src/chipset/umc_8886.c index 4242062c6..f96480c2c 100644 --- a/src/chipset/umc_8886.c +++ b/src/chipset/umc_8886.c @@ -392,8 +392,7 @@ umc_8886_close(void *priv) static void * umc_8886_init(const device_t *info) { - umc_8886_t *dev = (umc_8886_t *) malloc(sizeof(umc_8886_t)); - memset(dev, 0, sizeof(umc_8886_t)); + umc_8886_t *dev = (umc_8886_t *) calloc(1, sizeof(umc_8886_t)); /* Device 12: UMC 8886xx */ pci_add_card(PCI_ADD_SOUTHBRIDGE, umc_8886_read, umc_8886_write, dev, &dev->pci_slot); @@ -431,7 +430,7 @@ const device_t umc_8886f_device = { .init = umc_8886_init, .close = umc_8886_close, .reset = umc_8886_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -445,7 +444,7 @@ const device_t umc_8886af_device = { .init = umc_8886_init, .close = umc_8886_close, .reset = umc_8886_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -459,7 +458,7 @@ const device_t umc_8886bf_device = { .init = umc_8886_init, .close = umc_8886_close, .reset = umc_8886_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/umc_8890.c b/src/chipset/umc_8890.c index 7de2ca1d0..cb69ce6a8 100644 --- a/src/chipset/umc_8890.c +++ b/src/chipset/umc_8890.c @@ -38,6 +38,7 @@ #include <86box/smram.h> #include <86box/chipset.h> +#include <86box/plat_unused.h> #ifdef ENABLE_UMC_8890_LOG int umc_8890_do_log = ENABLE_UMC_8890_LOG; @@ -209,7 +210,7 @@ umc_8890_close(void *priv) static void * -umc_8890_init(const device_t *info) +umc_8890_init(UNUSED(const device_t *info)) { umc_8890_t *dev = (umc_8890_t *) calloc(1, sizeof(umc_8890_t)); @@ -234,7 +235,7 @@ const device_t umc_8890_device = { .init = umc_8890_init, .close = umc_8890_close, .reset = umc_8890_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/umc_hb4.c b/src/chipset/umc_hb4.c index c1f359f26..889691988 100644 --- a/src/chipset/umc_hb4.c +++ b/src/chipset/umc_hb4.c @@ -450,8 +450,7 @@ ims8848_read(uint16_t addr, void *priv) static void * hb4_init(UNUSED(const device_t *info)) { - hb4_t *dev = (hb4_t *) malloc(sizeof(hb4_t)); - memset(dev, 0, sizeof(hb4_t)); + hb4_t *dev = (hb4_t *) calloc(1, sizeof(hb4_t)); pci_add_card(PCI_ADD_NORTHBRIDGE, hb4_read, hb4_write, dev, &dev->pci_slot); /* Device 10: UMC 8881x */ @@ -477,7 +476,7 @@ const device_t umc_hb4_device = { .init = hb4_init, .close = hb4_close, .reset = hb4_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/via_apollo.c b/src/chipset/via_apollo.c index 20e2c7f74..110b1f8e1 100644 --- a/src/chipset/via_apollo.c +++ b/src/chipset/via_apollo.c @@ -725,8 +725,7 @@ via_apollo_reset(void *priv) static void * via_apollo_init(const device_t *info) { - via_apollo_t *dev = (via_apollo_t *) malloc(sizeof(via_apollo_t)); - memset(dev, 0, sizeof(via_apollo_t)); + via_apollo_t *dev = (via_apollo_t *) calloc(1, sizeof(via_apollo_t)); dev->smram = smram_add(); if (dev->id != VIA_8601) @@ -793,7 +792,7 @@ const device_t via_vpx_device = { .init = via_apollo_init, .close = via_apollo_close, .reset = via_apollo_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -807,7 +806,7 @@ const device_t amd640_device = { .init = via_apollo_init, .close = via_apollo_close, .reset = via_apollo_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -821,7 +820,7 @@ const device_t via_vp3_device = { .init = via_apollo_init, .close = via_apollo_close, .reset = via_apollo_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -835,7 +834,7 @@ const device_t via_mvp3_device = { .init = via_apollo_init, .close = via_apollo_close, .reset = via_apollo_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -849,7 +848,7 @@ const device_t via_apro_device = { .init = via_apollo_init, .close = via_apollo_close, .reset = via_apollo_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -863,7 +862,7 @@ const device_t via_apro133_device = { .init = via_apollo_init, .close = via_apollo_close, .reset = via_apollo_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -877,7 +876,7 @@ const device_t via_apro133a_device = { .init = via_apollo_init, .close = via_apollo_close, .reset = via_apollo_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -891,7 +890,7 @@ const device_t via_vt8601_device = { .init = via_apollo_init, .close = via_apollo_close, .reset = via_apollo_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/via_pipc.c b/src/chipset/via_pipc.c index 1f153092b..dcfe41811 100644 --- a/src/chipset/via_pipc.c +++ b/src/chipset/via_pipc.c @@ -1627,8 +1627,7 @@ pipc_reset(void *priv) static void * pipc_init(const device_t *info) { - pipc_t *dev = (pipc_t *) malloc(sizeof(pipc_t)); - memset(dev, 0, sizeof(pipc_t)); + pipc_t *dev = (pipc_t *) calloc(1, sizeof(pipc_t)); pipc_log("PIPC: init()\n"); @@ -1721,7 +1720,7 @@ const device_t via_vt82c586b_device = { .init = pipc_init, .close = pipc_close, .reset = pipc_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -1735,7 +1734,7 @@ const device_t via_vt82c596a_device = { .init = pipc_init, .close = pipc_close, .reset = pipc_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -1749,7 +1748,7 @@ const device_t via_vt82c596b_device = { .init = pipc_init, .close = pipc_close, .reset = pipc_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -1763,7 +1762,7 @@ const device_t via_vt82c686a_device = { .init = pipc_init, .close = pipc_close, .reset = pipc_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -1777,7 +1776,7 @@ const device_t via_vt82c686b_device = { .init = pipc_init, .close = pipc_close, .reset = pipc_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -1791,7 +1790,7 @@ const device_t via_vt8231_device = { .init = pipc_init, .close = pipc_close, .reset = pipc_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/via_vt82c49x.c b/src/chipset/via_vt82c49x.c index de55f7060..3aaef55a6 100644 --- a/src/chipset/via_vt82c49x.c +++ b/src/chipset/via_vt82c49x.c @@ -342,8 +342,7 @@ vt82c49x_close(void *priv) static void * vt82c49x_init(const device_t *info) { - vt82c49x_t *dev = (vt82c49x_t *) malloc(sizeof(vt82c49x_t)); - memset(dev, 0x00, sizeof(vt82c49x_t)); + vt82c49x_t *dev = (vt82c49x_t *) calloc(1, sizeof(vt82c49x_t)); dev->smram_smm = smram_add(); dev->smram_low = smram_add(); @@ -375,7 +374,7 @@ const device_t via_vt82c49x_device = { .init = vt82c49x_init, .close = vt82c49x_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -389,7 +388,7 @@ const device_t via_vt82c49x_pci_device = { .init = vt82c49x_init, .close = vt82c49x_close, .reset = vt82c49x_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -403,7 +402,7 @@ const device_t via_vt82c49x_ide_device = { .init = vt82c49x_init, .close = vt82c49x_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -417,7 +416,7 @@ const device_t via_vt82c49x_pci_ide_device = { .init = vt82c49x_init, .close = vt82c49x_close, .reset = vt82c49x_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/via_vt82c505.c b/src/chipset/via_vt82c505.c index 34efbead9..dbbb447c7 100644 --- a/src/chipset/via_vt82c505.c +++ b/src/chipset/via_vt82c505.c @@ -167,7 +167,7 @@ vt82c505_in(uint16_t addr, void *priv) static void vt82c505_reset(void *priv) { - vt82c505_t *dev = (vt82c505_t *) malloc(sizeof(vt82c505_t)); + vt82c505_t *dev = (vt82c505_t *) calloc(1, sizeof(vt82c505_t)); dev->pci_conf[0x04] = 0x07; dev->pci_conf[0x07] = 0x00; @@ -204,8 +204,7 @@ vt82c505_close(void *priv) static void * vt82c505_init(UNUSED(const device_t *info)) { - vt82c505_t *dev = (vt82c505_t *) malloc(sizeof(vt82c505_t)); - memset(dev, 0, sizeof(vt82c505_t)); + vt82c505_t *dev = (vt82c505_t *) calloc(1, sizeof(vt82c505_t)); pci_add_card(PCI_ADD_NORTHBRIDGE, vt82c505_read, vt82c505_write, dev, &dev->pci_slot); @@ -232,7 +231,7 @@ const device_t via_vt82c505_device = { .init = vt82c505_init, .close = vt82c505_close, .reset = vt82c505_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/vl82c480.c b/src/chipset/vl82c480.c index 00adcc2a4..496544c63 100644 --- a/src/chipset/vl82c480.c +++ b/src/chipset/vl82c480.c @@ -180,8 +180,7 @@ vl82c480_close(void *priv) static void * vl82c480_init(const device_t *info) { - vl82c480_t *dev = (vl82c480_t *) malloc(sizeof(vl82c480_t)); - memset(dev, 0, sizeof(vl82c480_t)); + vl82c480_t *dev = (vl82c480_t *) calloc(1, sizeof(vl82c480_t)); dev->regs[0x00] = info->local; dev->regs[0x01] = 0xff; @@ -207,7 +206,7 @@ const device_t vl82c480_device = { .init = vl82c480_init, .close = vl82c480_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -221,7 +220,7 @@ const device_t vl82c486_device = { .init = vl82c480_init, .close = vl82c480_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/wd76c10.c b/src/chipset/wd76c10.c index df8558b05..d7d8b0fe2 100644 --- a/src/chipset/wd76c10.c +++ b/src/chipset/wd76c10.c @@ -37,6 +37,7 @@ #include <86box/port_92.h> #include <86box/serial.h> #include <86box/plat_fallthrough.h> +#include <86box/plat_unused.h> #include <86box/chipset.h> /* Lock/Unlock Procedures */ @@ -879,12 +880,12 @@ wd76c10_reset(void *priv) static void * -wd76c10_init(const device_t *info) +wd76c10_init(UNUSED(const device_t *info)) { wd76c10_t *dev = (wd76c10_t *) calloc(1, sizeof(wd76c10_t)); uint32_t total_mem = mem_size << 10; uint32_t accum_mem = 0x00000000; - ram_bank_t *rb; + ram_bank_t *rb = NULL; /* Calculate the physical RAM banks. */ for (uint8_t i = 0; i < 4; i++) { @@ -1022,7 +1023,7 @@ const device_t wd76c10_device = { .init = wd76c10_init, .close = wd76c10_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/codegen/codegen_ops_arith.h b/src/codegen/codegen_ops_arith.h index 28ee6d06c..50ef4310f 100644 --- a/src/codegen/codegen_ops_arith.h +++ b/src/codegen/codegen_ops_arith.h @@ -1,5 +1,5 @@ static uint32_t -ropINC_rw(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropINC_rw(uint8_t opcode, UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { int host_reg; @@ -22,7 +22,7 @@ ropINC_rw(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, cod return op_pc; } static uint32_t -ropINC_rl(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropINC_rl(uint8_t opcode, UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { int host_reg; @@ -45,7 +45,7 @@ ropINC_rl(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, cod return op_pc; } static uint32_t -ropDEC_rw(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropDEC_rw(uint8_t opcode, UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { int host_reg; @@ -68,7 +68,7 @@ ropDEC_rw(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, cod return op_pc; } static uint32_t -ropDEC_rl(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropDEC_rl(uint8_t opcode, UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { int host_reg; @@ -93,7 +93,7 @@ ropDEC_rl(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, cod #define ROP_ARITH_RMW(name, op, writeback) \ static uint32_t \ - rop##name##_b_rmw(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \ + rop##name##_b_rmw(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) \ { \ int src_reg; \ int dst_reg; \ @@ -129,7 +129,7 @@ ropDEC_rl(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, cod return op_pc + 1; \ } \ static uint32_t \ - rop##name##_w_rmw(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \ + rop##name##_w_rmw(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) \ { \ int src_reg; \ int dst_reg; \ @@ -165,7 +165,7 @@ ropDEC_rl(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, cod return op_pc + 1; \ } \ static uint32_t \ - rop##name##_l_rmw(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \ + rop##name##_l_rmw(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) \ { \ int src_reg; \ int dst_reg; \ @@ -203,7 +203,7 @@ ropDEC_rl(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, cod #define ROP_ARITH_RM(name, op, writeback) \ static uint32_t \ - rop##name##_b_rm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \ + rop##name##_b_rm(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) \ { \ int src_reg; \ int dst_reg; \ @@ -233,7 +233,7 @@ ropDEC_rl(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, cod return op_pc + 1; \ } \ static uint32_t \ - rop##name##_w_rm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \ + rop##name##_w_rm(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) \ { \ int src_reg; \ int dst_reg; \ @@ -263,7 +263,7 @@ ropDEC_rl(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, cod return op_pc + 1; \ } \ static uint32_t \ - rop##name##_l_rm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \ + rop##name##_l_rm(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) \ { \ int src_reg; \ int dst_reg; \ @@ -299,7 +299,7 @@ ROP_ARITH_RM(ADD, ADD, 1) ROP_ARITH_RM(SUB, SUB, 1) static uint32_t -ropCMP_b_rm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropCMP_b_rm(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { int src_reg; int dst_reg; @@ -326,7 +326,7 @@ ropCMP_b_rm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, c return op_pc + 1; } static uint32_t -ropCMP_w_rm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropCMP_w_rm(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { int src_reg; int dst_reg; @@ -353,7 +353,7 @@ ropCMP_w_rm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, c return op_pc + 1; } static uint32_t -ropCMP_l_rm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropCMP_l_rm(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { int src_reg; int dst_reg; @@ -381,7 +381,7 @@ ropCMP_l_rm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, c } static uint32_t -ropCMP_b_rmw(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropCMP_b_rmw(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { int src_reg; int dst_reg; @@ -408,7 +408,7 @@ ropCMP_b_rmw(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, return op_pc + 1; } static uint32_t -ropCMP_w_rmw(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropCMP_w_rmw(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { int src_reg; int dst_reg; @@ -435,7 +435,7 @@ ropCMP_w_rmw(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, return op_pc + 1; } static uint32_t -ropCMP_l_rmw(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropCMP_l_rmw(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { int src_reg; int dst_reg; @@ -463,7 +463,7 @@ ropCMP_l_rmw(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, } static uint32_t -ropADD_AL_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropADD_AL_imm(UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { int host_reg = LOAD_REG_B(REG_AL); @@ -478,7 +478,7 @@ ropADD_AL_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, return op_pc + 1; } static uint32_t -ropADD_AX_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropADD_AX_imm(UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { int host_reg = LOAD_REG_W(REG_AX); @@ -493,7 +493,7 @@ ropADD_AX_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, return op_pc + 2; } static uint32_t -ropADD_EAX_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropADD_EAX_imm(UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { int host_reg = LOAD_REG_L(REG_EAX); @@ -510,7 +510,7 @@ ropADD_EAX_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc } static uint32_t -ropCMP_AL_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropCMP_AL_imm(UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { int host_reg = LOAD_REG_B(REG_AL); @@ -525,7 +525,7 @@ ropCMP_AL_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, return op_pc + 1; } static uint32_t -ropCMP_AX_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropCMP_AX_imm(UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { int host_reg = LOAD_REG_W(REG_AX); @@ -540,7 +540,7 @@ ropCMP_AX_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, return op_pc + 2; } static uint32_t -ropCMP_EAX_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropCMP_EAX_imm(UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { int host_reg = LOAD_REG_L(REG_EAX); @@ -557,7 +557,7 @@ ropCMP_EAX_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc } static uint32_t -ropSUB_AL_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropSUB_AL_imm(UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { int host_reg = LOAD_REG_B(REG_AL); @@ -572,7 +572,7 @@ ropSUB_AL_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, return op_pc + 1; } static uint32_t -ropSUB_AX_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropSUB_AX_imm(UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { int host_reg = LOAD_REG_W(REG_AX); @@ -587,7 +587,7 @@ ropSUB_AX_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, return op_pc + 2; } static uint32_t -ropSUB_EAX_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropSUB_EAX_imm(UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { int host_reg = LOAD_REG_L(REG_EAX); @@ -604,7 +604,7 @@ ropSUB_EAX_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc } static uint32_t -rop80(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +rop80(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { int host_reg; uint32_t imm; @@ -679,7 +679,7 @@ rop80(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblo } static uint32_t -rop81_w(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +rop81_w(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { int host_reg; uint32_t imm; @@ -753,7 +753,7 @@ rop81_w(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeb return op_pc + 3; } static uint32_t -rop81_l(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +rop81_l(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { int host_reg; uint32_t imm; @@ -827,7 +827,7 @@ rop81_l(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeb } static uint32_t -rop83_w(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +rop83_w(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { int host_reg; uint32_t imm; @@ -904,7 +904,7 @@ rop83_w(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeb return op_pc + 2; } static uint32_t -rop83_l(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +rop83_l(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { int host_reg; uint32_t imm; diff --git a/src/codegen/codegen_ops_fpu.h b/src/codegen/codegen_ops_fpu.h index 242743dee..a82b10d82 100644 --- a/src/codegen/codegen_ops_fpu.h +++ b/src/codegen/codegen_ops_fpu.h @@ -1,5 +1,5 @@ static uint32_t -ropFXCH(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropFXCH(uint8_t opcode, UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { FP_ENTER(); @@ -9,7 +9,7 @@ ropFXCH(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeb } static uint32_t -ropFLD(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropFLD(uint8_t opcode, UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { FP_ENTER(); @@ -19,7 +19,7 @@ ropFLD(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codebl } static uint32_t -ropFST(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropFST(uint8_t opcode, UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { FP_ENTER(); @@ -28,7 +28,7 @@ ropFST(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codebl return op_pc; } static uint32_t -ropFSTP(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropFSTP(uint8_t opcode, UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { FP_ENTER(); @@ -39,7 +39,7 @@ ropFSTP(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeb } static uint32_t -ropFLDs(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropFLDs(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { x86seg *target_seg; @@ -57,7 +57,7 @@ ropFLDs(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeb return op_pc + 1; } static uint32_t -ropFLDd(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropFLDd(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { x86seg *target_seg; @@ -76,7 +76,7 @@ ropFLDd(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeb } static uint32_t -ropFILDw(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropFILDw(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { x86seg *target_seg; @@ -94,7 +94,7 @@ ropFILDw(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, code return op_pc + 1; } static uint32_t -ropFILDl(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropFILDl(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { x86seg *target_seg; @@ -112,7 +112,7 @@ ropFILDl(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, code return op_pc + 1; } static uint32_t -ropFILDq(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropFILDq(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { x86seg *target_seg; @@ -133,7 +133,7 @@ ropFILDq(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, code } static uint32_t -ropFSTs(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropFSTs(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { x86seg *target_seg; int host_reg; @@ -153,7 +153,7 @@ ropFSTs(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeb return op_pc + 1; } static uint32_t -ropFSTd(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropFSTd(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { x86seg *target_seg; int host_reg1; @@ -194,24 +194,28 @@ ropFSTPd(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, code return new_pc; } -#define ropFarith(name, size, load, op) \ - static uint32_t \ - ropF##name##size(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \ - { \ - x86seg *target_seg; \ - \ - FP_ENTER(); \ - op_pc--; \ - target_seg = FETCH_EA(op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32); \ - \ - STORE_IMM_ADDR_L((uintptr_t) &cpu_state.oldpc, op_old_pc); \ - \ - CHECK_SEG_READ(target_seg); \ - load(target_seg); \ - \ - op(FPU_##name); \ - \ - return op_pc + 1; \ +#define ropFarith(name, size, load, op) \ + static uint32_t \ + ropF##name##size(UNUSED(uint8_t opcode), \ + uint32_t fetchdat, \ + uint32_t op_32, \ + uint32_t op_pc, \ + UNUSED(codeblock_t *block)) \ + { \ + x86seg *target_seg; \ + \ + FP_ENTER(); \ + op_pc--; \ + target_seg = FETCH_EA(op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32); \ + \ + STORE_IMM_ADDR_L((uintptr_t) &cpu_state.oldpc, op_old_pc); \ + \ + CHECK_SEG_READ(target_seg); \ + load(target_seg); \ + \ + op(FPU_##name); \ + \ + return op_pc + 1; \ } ropFarith(ADD, s, MEM_LOAD_ADDR_EA_L, FP_OP_S); @@ -239,32 +243,40 @@ ropFarith(MUL, il, MEM_LOAD_ADDR_EA_L, FP_OP_IL); ropFarith(SUB, il, MEM_LOAD_ADDR_EA_L, FP_OP_IL); ropFarith(SUBR, il, MEM_LOAD_ADDR_EA_L, FP_OP_IL); -#define ropFcompare(name, size, load, op) \ - static uint32_t \ - ropF##name##size(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \ - { \ - x86seg *target_seg; \ - \ - FP_ENTER(); \ - op_pc--; \ - target_seg = FETCH_EA(op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32); \ - \ - STORE_IMM_ADDR_L((uintptr_t) &cpu_state.oldpc, op_old_pc); \ - \ - CHECK_SEG_READ(target_seg); \ - load(target_seg); \ - \ - op(); \ - \ - return op_pc + 1; \ - } \ - static uint32_t ropF##name##P##size(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \ - { \ - uint32_t new_pc = ropF##name##size(opcode, fetchdat, op_32, op_pc, block); \ - \ - FP_POP(); \ - \ - return new_pc; \ +#define ropFcompare(name, size, load, op) \ + static uint32_t \ + ropF##name##size(UNUSED(uint8_t opcode), \ + uint32_t fetchdat, \ + uint32_t op_32, \ + uint32_t op_pc, \ + UNUSED(codeblock_t *block)) \ + { \ + x86seg *target_seg; \ + \ + FP_ENTER(); \ + op_pc--; \ + target_seg = FETCH_EA(op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32); \ + \ + STORE_IMM_ADDR_L((uintptr_t) &cpu_state.oldpc, op_old_pc); \ + \ + CHECK_SEG_READ(target_seg); \ + load(target_seg); \ + \ + op(); \ + \ + return op_pc + 1; \ + } \ + static uint32_t ropF##name##P##size(uint8_t opcode, \ + uint32_t fetchdat, \ + uint32_t op_32, \ + uint32_t op_pc, \ + codeblock_t *block) \ + { \ + uint32_t new_pc = ropF##name##size(opcode, fetchdat, op_32, op_pc, block); \ + \ + FP_POP(); \ + \ + return new_pc; \ } ropFcompare(COM, s, MEM_LOAD_ADDR_EA_L, FP_COMPARE_S); @@ -348,7 +360,7 @@ ropFSUBs(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, code #endif static uint32_t -ropFADD(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropFADD(uint8_t opcode, UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { FP_ENTER(); FP_OP_REG(FPU_ADD, 0, opcode & 7); @@ -356,7 +368,7 @@ ropFADD(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeb return op_pc; } static uint32_t -ropFCOM(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropFCOM(uint8_t opcode, UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { FP_ENTER(); FP_COMPARE_REG(0, opcode & 7); @@ -364,7 +376,7 @@ ropFCOM(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeb return op_pc; } static uint32_t -ropFDIV(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropFDIV(uint8_t opcode, UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { FP_ENTER(); FP_OP_REG(FPU_DIV, 0, opcode & 7); @@ -372,7 +384,7 @@ ropFDIV(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeb return op_pc; } static uint32_t -ropFDIVR(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropFDIVR(uint8_t opcode, UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { FP_ENTER(); FP_OP_REG(FPU_DIVR, 0, opcode & 7); @@ -380,7 +392,7 @@ ropFDIVR(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, code return op_pc; } static uint32_t -ropFMUL(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropFMUL(uint8_t opcode, UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { FP_ENTER(); FP_OP_REG(FPU_MUL, 0, opcode & 7); @@ -388,7 +400,7 @@ ropFMUL(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeb return op_pc; } static uint32_t -ropFSUB(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropFSUB(uint8_t opcode, UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { FP_ENTER(); FP_OP_REG(FPU_SUB, 0, opcode & 7); @@ -396,7 +408,7 @@ ropFSUB(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeb return op_pc; } static uint32_t -ropFSUBR(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropFSUBR(uint8_t opcode, UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { FP_ENTER(); FP_OP_REG(FPU_SUBR, 0, opcode & 7); @@ -405,7 +417,7 @@ ropFSUBR(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, code } static uint32_t -ropFADDr(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropFADDr(uint8_t opcode, UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { FP_ENTER(); FP_OP_REG(FPU_ADD, opcode & 7, 0); @@ -413,7 +425,7 @@ ropFADDr(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, code return op_pc; } static uint32_t -ropFDIVr(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropFDIVr(uint8_t opcode, UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { FP_ENTER(); FP_OP_REG(FPU_DIV, opcode & 7, 0); @@ -421,7 +433,7 @@ ropFDIVr(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, code return op_pc; } static uint32_t -ropFDIVRr(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropFDIVRr(uint8_t opcode, UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { FP_ENTER(); FP_OP_REG(FPU_DIVR, opcode & 7, 0); @@ -429,7 +441,7 @@ ropFDIVRr(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, cod return op_pc; } static uint32_t -ropFMULr(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropFMULr(uint8_t opcode, UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { FP_ENTER(); FP_OP_REG(FPU_MUL, opcode & 7, 0); @@ -437,7 +449,7 @@ ropFMULr(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, code return op_pc; } static uint32_t -ropFSUBr(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropFSUBr(uint8_t opcode, UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { FP_ENTER(); FP_OP_REG(FPU_SUB, opcode & 7, 0); @@ -445,7 +457,7 @@ ropFSUBr(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, code return op_pc; } static uint32_t -ropFSUBRr(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropFSUBRr(uint8_t opcode, UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { FP_ENTER(); FP_OP_REG(FPU_SUBR, opcode & 7, 0); @@ -454,7 +466,7 @@ ropFSUBRr(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, cod } static uint32_t -ropFADDP(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropFADDP(uint8_t opcode, UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { FP_ENTER(); FP_OP_REG(FPU_ADD, opcode & 7, 0); @@ -463,7 +475,7 @@ ropFADDP(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, code return op_pc; } static uint32_t -ropFCOMP(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropFCOMP(uint8_t opcode, UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { FP_ENTER(); FP_COMPARE_REG(0, opcode & 7); @@ -472,7 +484,7 @@ ropFCOMP(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, code return op_pc; } static uint32_t -ropFDIVP(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropFDIVP(uint8_t opcode, UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { FP_ENTER(); FP_OP_REG(FPU_DIV, opcode & 7, 0); @@ -481,7 +493,7 @@ ropFDIVP(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, code return op_pc; } static uint32_t -ropFDIVRP(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropFDIVRP(uint8_t opcode, UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { FP_ENTER(); FP_OP_REG(FPU_DIVR, opcode & 7, 0); @@ -490,7 +502,7 @@ ropFDIVRP(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, cod return op_pc; } static uint32_t -ropFMULP(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropFMULP(uint8_t opcode, UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { FP_ENTER(); FP_OP_REG(FPU_MUL, opcode & 7, 0); @@ -499,7 +511,7 @@ ropFMULP(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, code return op_pc; } static uint32_t -ropFSUBP(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropFSUBP(uint8_t opcode, UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { FP_ENTER(); FP_OP_REG(FPU_SUB, opcode & 7, 0); @@ -508,7 +520,7 @@ ropFSUBP(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, code return op_pc; } static uint32_t -ropFSUBRP(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropFSUBRP(uint8_t opcode, UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { FP_ENTER(); FP_OP_REG(FPU_SUBR, opcode & 7, 0); @@ -518,7 +530,7 @@ ropFSUBRP(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, cod } static uint32_t -ropFCOMPP(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropFCOMPP(UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { FP_ENTER(); FP_COMPARE_REG(0, 1); @@ -528,7 +540,7 @@ ropFCOMPP(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, cod } static uint32_t -ropFSTSW_AX(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropFSTSW_AX(UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { int host_reg; @@ -540,7 +552,7 @@ ropFSTSW_AX(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, c } static uint32_t -ropFISTw(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropFISTw(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { x86seg *target_seg; int host_reg; @@ -560,7 +572,7 @@ ropFISTw(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, code return op_pc + 1; } static uint32_t -ropFISTl(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropFISTl(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { x86seg *target_seg; int host_reg; @@ -599,7 +611,7 @@ ropFISTPl(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, cod return new_pc; } static uint32_t -ropFISTPq(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropFISTPq(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { x86seg *target_seg; int host_reg1; @@ -623,7 +635,7 @@ ropFISTPq(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, cod } static uint32_t -ropFLDCW(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropFLDCW(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { x86seg *target_seg; @@ -640,7 +652,7 @@ ropFLDCW(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, code return op_pc + 1; } static uint32_t -ropFSTCW(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropFSTCW(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { int host_reg; x86seg *target_seg; @@ -658,7 +670,7 @@ ropFSTCW(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, code } static uint32_t -ropFCHS(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropFCHS(UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { FP_ENTER(); FP_FCHS(); @@ -666,17 +678,21 @@ ropFCHS(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeb return op_pc; } -#define opFLDimm(name, v) \ - static uint32_t \ - ropFLD##name(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \ - { \ - static double fp_imm = v; \ - static uint64_t *fptr = (uint64_t *) &fp_imm; \ - \ - FP_ENTER(); \ - FP_LOAD_IMM_Q(*fptr); \ - \ - return op_pc; \ +#define opFLDimm(name, v) \ + static uint32_t \ + ropFLD##name(UNUSED(uint8_t opcode), \ + UNUSED(uint32_t fetchdat), \ + UNUSED(uint32_t op_32), \ + uint32_t op_pc, \ + UNUSED(codeblock_t *block)) \ + { \ + static double fp_imm = v; \ + static uint64_t *fptr = (uint64_t *) &fp_imm; \ + \ + FP_ENTER(); \ + FP_LOAD_IMM_Q(*fptr); \ + \ + return op_pc; \ } // clang-format off @@ -689,7 +705,7 @@ opFLDimm(Z, 0.0) // clang-format on static uint32_t -ropFLDLN2(UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) +ropFLDLN2(UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { FP_ENTER(); FP_LOAD_IMM_Q(0x3fe62e42fefa39f0ULL); diff --git a/src/codegen/codegen_ops_jump.h b/src/codegen/codegen_ops_jump.h index da16ce03e..4572b623b 100644 --- a/src/codegen/codegen_ops_jump.h +++ b/src/codegen/codegen_ops_jump.h @@ -1,5 +1,5 @@ static uint32_t -ropJMP_r8(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropJMP_r8(UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { uint32_t offset = fetchdat & 0xff; @@ -12,7 +12,7 @@ ropJMP_r8(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, cod } static uint32_t -ropJMP_r16(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropJMP_r16(UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { uint16_t offset = fetchdat & 0xffff; @@ -22,7 +22,7 @@ ropJMP_r16(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, co } static uint32_t -ropJMP_r32(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropJMP_r32(UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { uint32_t offset = fastreadl(cs + op_pc); @@ -32,7 +32,7 @@ ropJMP_r32(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, co } static uint32_t -ropJCXZ(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropJCXZ(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { uint32_t offset = fetchdat & 0xff; @@ -51,7 +51,7 @@ ropJCXZ(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeb } static uint32_t -ropLOOP(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropLOOP(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { uint32_t offset = fetchdat & 0xff; @@ -214,45 +214,51 @@ BRANCH_COND_S(int pc_offset, uint32_t op_pc, uint32_t offset, int not ) } } -#define ropBRANCH(name, func, not ) \ - static uint32_t \ - rop##name(uint8_t opcode, uint32_t fetchdat, \ - uint32_t op_32, uint32_t op_pc, \ - codeblock_t *block) \ - { \ - uint32_t offset = fetchdat & 0xff; \ - \ - if (offset & 0x80) \ - offset |= 0xffffff00; \ - \ - func(1, op_pc, offset, not ); \ - \ - return op_pc + 1; \ - } \ - static uint32_t \ - rop##name##_w(uint8_t opcode, \ - uint32_t fetchdat, uint32_t op_32, \ - uint32_t op_pc, codeblock_t *block) \ - { \ - uint32_t offset = fetchdat & 0xffff; \ - \ - if (offset & 0x8000) \ - offset |= 0xffff0000; \ - \ - func(2, op_pc, offset, not ); \ - \ - return op_pc + 2; \ - } \ - static uint32_t \ - rop##name##_l(uint8_t opcode, \ - uint32_t fetchdat, uint32_t op_32, \ - uint32_t op_pc, codeblock_t *block) \ - { \ - uint32_t offset = fastreadl(cs + op_pc); \ - \ - func(4, op_pc, offset, not ); \ - \ - return op_pc + 4; \ +#define ropBRANCH(name, func, not ) \ + static uint32_t \ + rop##name(UNUSED(uint8_t opcode), \ + uint32_t fetchdat, \ + UNUSED(uint32_t op_32), \ + uint32_t op_pc, \ + UNUSED(codeblock_t *block)) \ + { \ + uint32_t offset = fetchdat & 0xff; \ + \ + if (offset & 0x80) \ + offset |= 0xffffff00; \ + \ + func(1, op_pc, offset, not ); \ + \ + return op_pc + 1; \ + } \ + static uint32_t \ + rop##name##_w(UNUSED(uint8_t opcode), \ + uint32_t fetchdat, \ + UNUSED(uint32_t op_32), \ + uint32_t op_pc, \ + UNUSED(codeblock_t *block)) \ + { \ + uint32_t offset = fetchdat & 0xffff; \ + \ + if (offset & 0x8000) \ + offset |= 0xffff0000; \ + \ + func(2, op_pc, offset, not ); \ + \ + return op_pc + 2; \ + } \ + static uint32_t \ + rop##name##_l(UNUSED(uint8_t opcode), \ + UNUSED(uint32_t fetchdat), \ + UNUSED(uint32_t op_32), \ + uint32_t op_pc, \ + UNUSED(codeblock_t *block)) \ + { \ + uint32_t offset = fastreadl(cs + op_pc); \ + \ + func(4, op_pc, offset, not ); \ + \ + return op_pc + 4; \ } // clang-format off diff --git a/src/codegen/codegen_ops_logic.h b/src/codegen/codegen_ops_logic.h index 9f23723e2..2c79c4a2d 100644 --- a/src/codegen/codegen_ops_logic.h +++ b/src/codegen/codegen_ops_logic.h @@ -1,6 +1,6 @@ #define ROP_LOGIC(name, op, writeback) \ static uint32_t \ - rop##name##_b_rmw(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \ + rop##name##_b_rmw(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) \ { \ int src_reg; \ int dst_reg; \ @@ -33,7 +33,7 @@ return op_pc + 1; \ } \ static uint32_t \ - rop##name##_w_rmw(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \ + rop##name##_w_rmw(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) \ { \ int src_reg; \ int dst_reg; \ @@ -66,7 +66,7 @@ return op_pc + 1; \ } \ static uint32_t \ - rop##name##_l_rmw(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \ + rop##name##_l_rmw(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) \ { \ int src_reg; \ int dst_reg; \ @@ -99,7 +99,7 @@ return op_pc + 1; \ } \ static uint32_t \ - rop##name##_b_rm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \ + rop##name##_b_rm(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) \ { \ int src_reg; \ int dst_reg; \ @@ -126,7 +126,7 @@ return op_pc + 1; \ } \ static uint32_t \ - rop##name##_w_rm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \ + rop##name##_w_rm(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) \ { \ int src_reg; \ int dst_reg; \ @@ -153,7 +153,7 @@ return op_pc + 1; \ } \ static uint32_t \ - rop##name##_l_rm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \ + rop##name##_l_rm(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) \ { \ int src_reg; \ int dst_reg; \ @@ -185,7 +185,7 @@ ROP_LOGIC(OR, OR, 1) ROP_LOGIC(XOR, XOR, 1) static uint32_t -ropTEST_b_rm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropTEST_b_rm(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { int src_reg; int dst_reg; @@ -209,7 +209,7 @@ ropTEST_b_rm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, return op_pc + 1; } static uint32_t -ropTEST_w_rm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropTEST_w_rm(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { int src_reg; int dst_reg; @@ -233,7 +233,7 @@ ropTEST_w_rm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, return op_pc + 1; } static uint32_t -ropTEST_l_rm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropTEST_l_rm(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { int src_reg; int dst_reg; @@ -258,7 +258,7 @@ ropTEST_l_rm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, } static uint32_t -ropAND_AL_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropAND_AL_imm(UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { int host_reg = LOAD_REG_B(REG_AL); @@ -270,7 +270,7 @@ ropAND_AL_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, return op_pc + 1; } static uint32_t -ropAND_AX_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropAND_AX_imm(UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { int host_reg = LOAD_REG_W(REG_AX); @@ -282,7 +282,7 @@ ropAND_AX_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, return op_pc + 2; } static uint32_t -ropAND_EAX_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropAND_EAX_imm(UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { int host_reg = LOAD_REG_L(REG_EAX); @@ -296,7 +296,7 @@ ropAND_EAX_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc } static uint32_t -ropOR_AL_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropOR_AL_imm(UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { int host_reg = LOAD_REG_B(REG_AL); @@ -308,7 +308,7 @@ ropOR_AL_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, return op_pc + 1; } static uint32_t -ropOR_AX_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropOR_AX_imm(UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { int host_reg = LOAD_REG_W(REG_AX); @@ -320,7 +320,7 @@ ropOR_AX_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, return op_pc + 2; } static uint32_t -ropOR_EAX_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropOR_EAX_imm(UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { int host_reg = LOAD_REG_L(REG_EAX); @@ -334,7 +334,7 @@ ropOR_EAX_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, } static uint32_t -ropTEST_AL_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropTEST_AL_imm(UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { int host_reg = LOAD_REG_B(REG_AL); @@ -346,7 +346,7 @@ ropTEST_AL_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc return op_pc + 1; } static uint32_t -ropTEST_AX_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropTEST_AX_imm(UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { int host_reg = LOAD_REG_W(REG_AX); @@ -358,7 +358,7 @@ ropTEST_AX_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc return op_pc + 2; } static uint32_t -ropTEST_EAX_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropTEST_EAX_imm(UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { int host_reg = LOAD_REG_L(REG_EAX); @@ -372,7 +372,7 @@ ropTEST_EAX_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_p } static uint32_t -ropXOR_AL_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropXOR_AL_imm(UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { int host_reg = LOAD_REG_B(REG_AL); @@ -384,7 +384,7 @@ ropXOR_AL_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, return op_pc + 1; } static uint32_t -ropXOR_AX_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropXOR_AX_imm(UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { int host_reg = LOAD_REG_W(REG_AX); @@ -396,7 +396,7 @@ ropXOR_AX_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, return op_pc + 2; } static uint32_t -ropXOR_EAX_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropXOR_EAX_imm(UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { int host_reg = LOAD_REG_L(REG_EAX); @@ -410,7 +410,7 @@ ropXOR_EAX_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc } static uint32_t -ropF6(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropF6(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { x86seg *target_seg; int host_reg; @@ -458,7 +458,7 @@ ropF6(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblo return 0; } static uint32_t -ropF7_w(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropF7_w(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { x86seg *target_seg; int host_reg; @@ -506,7 +506,7 @@ ropF7_w(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeb return 0; } static uint32_t -ropF7_l(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropF7_l(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { x86seg *target_seg; int host_reg; diff --git a/src/codegen/codegen_ops_misc.h b/src/codegen/codegen_ops_misc.h index 61854ab37..db16dc09e 100644 --- a/src/codegen/codegen_ops_misc.h +++ b/src/codegen/codegen_ops_misc.h @@ -1,24 +1,24 @@ static uint32_t -ropNOP(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropNOP(UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { return op_pc; } static uint32_t -ropCLD(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropCLD(UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { CLEAR_BITS((uintptr_t) &cpu_state.flags, D_FLAG); return op_pc; } static uint32_t -ropSTD(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropSTD(UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { SET_BITS((uintptr_t) &cpu_state.flags, D_FLAG); return op_pc; } static uint32_t -ropCLI(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropCLI(UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { if (!IOPLp && (cr4 & (CR4_VME | CR4_PVI))) return 0; @@ -29,7 +29,7 @@ ropCLI(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codebl return op_pc; } static uint32_t -ropSTI(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropSTI(UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { if (!IOPLp && (cr4 & (CR4_VME | CR4_PVI))) return 0; @@ -38,7 +38,7 @@ ropSTI(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codebl } static uint32_t -ropFE(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropFE(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { x86seg *target_seg = NULL; int host_reg; @@ -88,7 +88,7 @@ ropFE(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblo } static uint32_t codegen_temp; static uint32_t -ropFF_16(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropFF_16(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { x86seg *target_seg = NULL; int host_reg; @@ -175,7 +175,7 @@ ropFF_16(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, code return 0; } static uint32_t -ropFF_32(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropFF_32(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { x86seg *target_seg = NULL; int host_reg; diff --git a/src/codegen/codegen_ops_mmx.h b/src/codegen/codegen_ops_mmx.h index 4c5a92c8f..2e07bde77 100644 --- a/src/codegen/codegen_ops_mmx.h +++ b/src/codegen/codegen_ops_mmx.h @@ -1,5 +1,5 @@ static uint32_t -ropMOVQ_q_mm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropMOVQ_q_mm(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { int host_reg1; int host_reg2 = 0; @@ -25,7 +25,7 @@ ropMOVQ_q_mm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, } static uint32_t -ropMOVQ_mm_q(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropMOVQ_mm_q(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { MMX_ENTER(); @@ -50,7 +50,7 @@ ropMOVQ_mm_q(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, } static uint32_t -ropMOVD_l_mm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropMOVD_l_mm(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { int host_reg; @@ -74,7 +74,7 @@ ropMOVD_l_mm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, return op_pc + 1; } static uint32_t -ropMOVD_mm_l(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropMOVD_mm_l(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { MMX_ENTER(); @@ -95,36 +95,40 @@ ropMOVD_mm_l(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, return op_pc + 1; } -#define MMX_OP(name, func) \ - static uint32_t \ - name(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \ - { \ - int src_reg1; \ - int src_reg2; \ - int xmm_src; \ - int xmm_dst; \ - \ - MMX_ENTER(); \ - \ - if ((fetchdat & 0xc0) == 0xc0) { \ - xmm_src = LOAD_MMX_Q_MMX(fetchdat & 7); \ - } else { \ - x86seg *target_seg = FETCH_EA(op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32); \ - \ - STORE_IMM_ADDR_L((uintptr_t) &cpu_state.oldpc, op_old_pc); \ - \ - CHECK_SEG_READ(target_seg); \ - \ - MEM_LOAD_ADDR_EA_Q(target_seg); \ - src_reg1 = LOAD_Q_REG_1; \ - src_reg2 = LOAD_Q_REG_2; \ - xmm_src = LOAD_INT_TO_MMX(src_reg1, src_reg2); \ - } \ - xmm_dst = LOAD_MMX_Q_MMX((fetchdat >> 3) & 7); \ - func(xmm_dst, xmm_src); \ - STORE_MMX_Q_MMX((fetchdat >> 3) & 7, xmm_dst); \ - \ - return op_pc + 1; \ +#define MMX_OP(name, func) \ + static uint32_t \ + name(UNUSED(uint8_t opcode), \ + uint32_t fetchdat, \ + uint32_t op_32, \ + uint32_t op_pc, \ + UNUSED(codeblock_t *block)) \ + { \ + int src_reg1; \ + int src_reg2; \ + int xmm_src; \ + int xmm_dst; \ + \ + MMX_ENTER(); \ + \ + if ((fetchdat & 0xc0) == 0xc0) { \ + xmm_src = LOAD_MMX_Q_MMX(fetchdat & 7); \ + } else { \ + x86seg *target_seg = FETCH_EA(op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32); \ + \ + STORE_IMM_ADDR_L((uintptr_t) &cpu_state.oldpc, op_old_pc); \ + \ + CHECK_SEG_READ(target_seg); \ + \ + MEM_LOAD_ADDR_EA_Q(target_seg); \ + src_reg1 = LOAD_Q_REG_1; \ + src_reg2 = LOAD_Q_REG_2; \ + xmm_src = LOAD_INT_TO_MMX(src_reg1, src_reg2); \ + } \ + xmm_dst = LOAD_MMX_Q_MMX((fetchdat >> 3) & 7); \ + func(xmm_dst, xmm_src); \ + STORE_MMX_Q_MMX((fetchdat >> 3) & 7, xmm_dst); \ + \ + return op_pc + 1; \ } MMX_OP(ropPAND, MMX_AND) @@ -179,7 +183,7 @@ MMX_OP(ropPMULHW, MMX_PMULHW); MMX_OP(ropPMADDWD, MMX_PMADDWD); static uint32_t -ropPSxxW_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropPSxxW_imm(UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { int xmm_dst; @@ -207,7 +211,7 @@ ropPSxxW_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, return op_pc + 2; } static uint32_t -ropPSxxD_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropPSxxD_imm(UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { int xmm_dst; @@ -235,7 +239,7 @@ ropPSxxD_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, return op_pc + 2; } static uint32_t -ropPSxxQ_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropPSxxQ_imm(UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { int xmm_dst; @@ -264,7 +268,7 @@ ropPSxxQ_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, } static uint32_t -ropEMMS(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropEMMS(UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), UNUSED(uint32_t op_pc), UNUSED(codeblock_t *block)) { codegen_mmx_entered = 0; diff --git a/src/codegen/codegen_ops_mov.h b/src/codegen/codegen_ops_mov.h index 04c4bf2bc..039489035 100644 --- a/src/codegen/codegen_ops_mov.h +++ b/src/codegen/codegen_ops_mov.h @@ -1,19 +1,19 @@ static uint32_t -ropMOV_rb_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropMOV_rb_imm(uint8_t opcode, uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { STORE_IMM_REG_B(opcode & 7, fetchdat & 0xff); return op_pc + 1; } static uint32_t -ropMOV_rw_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropMOV_rw_imm(uint8_t opcode, uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { STORE_IMM_REG_W(opcode & 7, fetchdat & 0xffff); return op_pc + 2; } static uint32_t -ropMOV_rl_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropMOV_rl_imm(uint8_t opcode, uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { fetchdat = fastreadl(cs + op_pc); @@ -23,7 +23,7 @@ ropMOV_rl_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, } static uint32_t -ropMOV_b_r(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropMOV_b_r(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { int host_reg = LOAD_REG_B((fetchdat >> 3) & 7); @@ -44,7 +44,7 @@ ropMOV_b_r(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, co return op_pc + 1; } static uint32_t -ropMOV_w_r(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropMOV_w_r(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { int host_reg = LOAD_REG_W((fetchdat >> 3) & 7); @@ -66,7 +66,7 @@ ropMOV_w_r(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, co } static uint32_t -ropMOV_l_r(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropMOV_l_r(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { int host_reg; @@ -90,7 +90,7 @@ ropMOV_l_r(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, co } static uint32_t -ropMOV_r_b(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropMOV_r_b(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { if ((fetchdat & 0xc0) == 0xc0) { int host_reg = LOAD_REG_B(fetchdat & 7); @@ -109,7 +109,7 @@ ropMOV_r_b(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, co return op_pc + 1; } static uint32_t -ropMOV_r_w(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropMOV_r_w(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { if ((fetchdat & 0xc0) == 0xc0) { int host_reg = LOAD_REG_W(fetchdat & 7); @@ -128,7 +128,7 @@ ropMOV_r_w(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, co return op_pc + 1; } static uint32_t -ropMOV_r_l(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropMOV_r_l(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { if ((fetchdat & 0xc0) == 0xc0) { int host_reg = LOAD_REG_L(fetchdat & 7); @@ -148,7 +148,7 @@ ropMOV_r_l(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, co } static uint32_t -ropMOV_b_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropMOV_b_imm(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { if ((fetchdat & 0xc0) == 0xc0) { STORE_IMM_REG_B(fetchdat & 7, (fetchdat >> 8) & 0xff); @@ -167,7 +167,7 @@ ropMOV_b_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, return op_pc + 2; } static uint32_t -ropMOV_w_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropMOV_w_imm(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { if ((fetchdat & 0xc0) == 0xc0) { STORE_IMM_REG_W(fetchdat & 7, (fetchdat >> 8) & 0xffff); @@ -186,7 +186,7 @@ ropMOV_w_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, return op_pc + 3; } static uint32_t -ropMOV_l_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropMOV_l_imm(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { if ((fetchdat & 0xc0) == 0xc0) { uint32_t imm = fastreadl(cs + op_pc + 1); @@ -208,7 +208,7 @@ ropMOV_l_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, } static uint32_t -ropMOV_AL_a(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropMOV_AL_a(UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { uint32_t addr; @@ -226,7 +226,7 @@ ropMOV_AL_a(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, c return op_pc + ((op_32 & 0x200) ? 4 : 2); } static uint32_t -ropMOV_AX_a(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropMOV_AX_a(UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { uint32_t addr; @@ -244,7 +244,7 @@ ropMOV_AX_a(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, c return op_pc + ((op_32 & 0x200) ? 4 : 2); } static uint32_t -ropMOV_EAX_a(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropMOV_EAX_a(UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { uint32_t addr; @@ -263,7 +263,7 @@ ropMOV_EAX_a(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, } static uint32_t -ropMOV_a_AL(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropMOV_a_AL(UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { uint32_t addr; int host_reg; @@ -284,7 +284,7 @@ ropMOV_a_AL(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, c return op_pc + ((op_32 & 0x200) ? 4 : 2); } static uint32_t -ropMOV_a_AX(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropMOV_a_AX(UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { uint32_t addr; int host_reg; @@ -305,7 +305,7 @@ ropMOV_a_AX(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, c return op_pc + ((op_32 & 0x200) ? 4 : 2); } static uint32_t -ropMOV_a_EAX(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropMOV_a_EAX(UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { uint32_t addr; int host_reg; @@ -327,7 +327,7 @@ ropMOV_a_EAX(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, } static uint32_t -ropLEA_w(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropLEA_w(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { int dest_reg = (fetchdat >> 3) & 7; @@ -341,7 +341,7 @@ ropLEA_w(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, code return op_pc + 1; } static uint32_t -ropLEA_l(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropLEA_l(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { int dest_reg = (fetchdat >> 3) & 7; @@ -356,7 +356,7 @@ ropLEA_l(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, code } static uint32_t -ropMOVZX_w_b(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropMOVZX_w_b(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { if ((fetchdat & 0xc0) == 0xc0) { int host_reg = LOAD_REG_B(fetchdat & 7); @@ -377,7 +377,7 @@ ropMOVZX_w_b(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, return op_pc + 1; } static uint32_t -ropMOVZX_l_b(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropMOVZX_l_b(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { if ((fetchdat & 0xc0) == 0xc0) { int host_reg = LOAD_REG_B(fetchdat & 7); @@ -398,7 +398,7 @@ ropMOVZX_l_b(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, return op_pc + 1; } static uint32_t -ropMOVZX_l_w(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropMOVZX_l_w(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { if ((fetchdat & 0xc0) == 0xc0) { int host_reg = LOAD_REG_W(fetchdat & 7); @@ -420,7 +420,7 @@ ropMOVZX_l_w(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, } static uint32_t -ropMOVSX_w_b(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropMOVSX_w_b(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { if ((fetchdat & 0xc0) == 0xc0) { int host_reg = LOAD_REG_B(fetchdat & 7); @@ -441,7 +441,7 @@ ropMOVSX_w_b(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, return op_pc + 1; } static uint32_t -ropMOVSX_l_b(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropMOVSX_l_b(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { if ((fetchdat & 0xc0) == 0xc0) { int host_reg = LOAD_REG_B(fetchdat & 7); @@ -462,7 +462,7 @@ ropMOVSX_l_b(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, return op_pc + 1; } static uint32_t -ropMOVSX_l_w(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropMOVSX_l_w(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { if ((fetchdat & 0xc0) == 0xc0) { int host_reg = LOAD_REG_W(fetchdat & 7); @@ -484,7 +484,7 @@ ropMOVSX_l_w(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, } static uint32_t -ropMOV_w_seg(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropMOV_w_seg(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { int host_reg; @@ -531,7 +531,7 @@ ropMOV_w_seg(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, return op_pc + 1; } static uint32_t -ropMOV_seg_w(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropMOV_seg_w(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { int host_reg; @@ -578,7 +578,7 @@ ropMOV_seg_w(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, } #define ropLseg(seg, rseg) \ - static uint32_t ropL##seg(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \ + static uint32_t ropL##seg(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) \ { \ int dest_reg = (fetchdat >> 3) & 7; \ x86seg *target_seg; \ diff --git a/src/codegen/codegen_ops_shift.h b/src/codegen/codegen_ops_shift.h index d750bfcad..a36fb3fdc 100644 --- a/src/codegen/codegen_ops_shift.h +++ b/src/codegen/codegen_ops_shift.h @@ -43,7 +43,7 @@ } static uint32_t -ropC0(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropC0(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { x86seg *target_seg = NULL; int count; @@ -57,7 +57,7 @@ ropC0(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblo return op_pc + 2; } static uint32_t -ropC1_w(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropC1_w(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { x86seg *target_seg = NULL; int count; @@ -71,7 +71,7 @@ ropC1_w(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeb return op_pc + 2; } static uint32_t -ropC1_l(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropC1_l(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { x86seg *target_seg = NULL; int count; @@ -86,7 +86,7 @@ ropC1_l(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeb } static uint32_t -ropD0(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropD0(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { x86seg *target_seg = NULL; int count = 1; @@ -100,7 +100,7 @@ ropD0(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblo return op_pc + 1; } static uint32_t -ropD1_w(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropD1_w(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { x86seg *target_seg = NULL; int count = 1; @@ -114,7 +114,7 @@ ropD1_w(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeb return op_pc + 1; } static uint32_t -ropD1_l(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropD1_l(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { x86seg *target_seg = NULL; int count = 1; diff --git a/src/codegen/codegen_ops_stack.h b/src/codegen/codegen_ops_stack.h index 342ddedd4..b7e3d66fe 100644 --- a/src/codegen/codegen_ops_stack.h +++ b/src/codegen/codegen_ops_stack.h @@ -1,5 +1,5 @@ static uint32_t -ropPUSH_16(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropPUSH_16(uint8_t opcode, UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { int host_reg; @@ -12,7 +12,7 @@ ropPUSH_16(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, co return op_pc; } static uint32_t -ropPUSH_32(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropPUSH_32(uint8_t opcode, UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { int host_reg; @@ -26,7 +26,7 @@ ropPUSH_32(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, co } static uint32_t -ropPUSH_imm_16(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropPUSH_imm_16(UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { uint16_t imm = fetchdat & 0xffff; int host_reg; @@ -40,7 +40,7 @@ ropPUSH_imm_16(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc return op_pc + 2; } static uint32_t -ropPUSH_imm_32(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropPUSH_imm_32(UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { uint32_t imm = fastreadl(cs + op_pc); int host_reg; @@ -55,7 +55,7 @@ ropPUSH_imm_32(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc } static uint32_t -ropPUSH_imm_b16(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropPUSH_imm_b16(UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { uint16_t imm = fetchdat & 0xff; int host_reg; @@ -72,7 +72,7 @@ ropPUSH_imm_b16(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_p return op_pc + 1; } static uint32_t -ropPUSH_imm_b32(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropPUSH_imm_b32(UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { uint32_t imm = fetchdat & 0xff; int host_reg; @@ -90,7 +90,7 @@ ropPUSH_imm_b32(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_p } static uint32_t -ropPOP_16(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropPOP_16(uint8_t opcode, UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { STORE_IMM_ADDR_L((uintptr_t) &cpu_state.oldpc, op_old_pc); LOAD_STACK_TO_EA(0); @@ -101,7 +101,7 @@ ropPOP_16(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, cod return op_pc; } static uint32_t -ropPOP_32(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropPOP_32(uint8_t opcode, UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { STORE_IMM_ADDR_L((uintptr_t) &cpu_state.oldpc, op_old_pc); LOAD_STACK_TO_EA(0); @@ -113,7 +113,7 @@ ropPOP_32(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, cod } static uint32_t -ropRET_16(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropRET_16(UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), UNUSED(uint32_t op_pc), UNUSED(codeblock_t *block)) { STORE_IMM_ADDR_L((uintptr_t) &cpu_state.oldpc, op_old_pc); LOAD_STACK_TO_EA(0); @@ -124,7 +124,7 @@ ropRET_16(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, cod return -1; } static uint32_t -ropRET_32(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropRET_32(UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), UNUSED(uint32_t op_pc), UNUSED(codeblock_t *block)) { STORE_IMM_ADDR_L((uintptr_t) &cpu_state.oldpc, op_old_pc); LOAD_STACK_TO_EA(0); @@ -136,7 +136,7 @@ ropRET_32(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, cod } static uint32_t -ropRET_imm_16(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropRET_imm_16(UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), UNUSED(uint32_t op_pc), UNUSED(codeblock_t *block)) { uint16_t offset = fetchdat & 0xffff; @@ -149,7 +149,7 @@ ropRET_imm_16(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, return -1; } static uint32_t -ropRET_imm_32(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropRET_imm_32(UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), UNUSED(uint32_t op_pc), UNUSED(codeblock_t *block)) { uint16_t offset = fetchdat & 0xffff; @@ -163,7 +163,7 @@ ropRET_imm_32(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, } static uint32_t -ropCALL_r16(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropCALL_r16(UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { uint16_t offset = fetchdat & 0xffff; int host_reg; @@ -178,7 +178,7 @@ ropCALL_r16(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, c return -1; } static uint32_t -ropCALL_r32(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropCALL_r32(UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { uint32_t offset = fastreadl(cs + op_pc); int host_reg; @@ -194,7 +194,7 @@ ropCALL_r32(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, c } static uint32_t -ropLEAVE_16(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropLEAVE_16(UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { int host_reg; @@ -209,7 +209,7 @@ ropLEAVE_16(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, c return op_pc; } static uint32_t -ropLEAVE_32(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropLEAVE_32(UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { int host_reg; @@ -224,32 +224,40 @@ ropLEAVE_32(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, c return op_pc; } -#define ROP_PUSH_SEG(seg) \ - static uint32_t \ - ropPUSH_##seg##_16(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \ - { \ - int host_reg; \ - \ - STORE_IMM_ADDR_L((uintptr_t) &cpu_state.oldpc, op_old_pc); \ - LOAD_STACK_TO_EA(-2); \ - host_reg = LOAD_VAR_W((uintptr_t) &seg); \ - MEM_STORE_ADDR_EA_W(&cpu_state.seg_ss, host_reg); \ - SP_MODIFY(-2); \ - \ - return op_pc; \ - } \ - static uint32_t \ - ropPUSH_##seg##_32(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \ - { \ - int host_reg; \ - \ - STORE_IMM_ADDR_L((uintptr_t) &cpu_state.oldpc, op_old_pc); \ - LOAD_STACK_TO_EA(-4); \ - host_reg = LOAD_VAR_W((uintptr_t) &seg); \ - MEM_STORE_ADDR_EA_L(&cpu_state.seg_ss, host_reg); \ - SP_MODIFY(-4); \ - \ - return op_pc; \ +#define ROP_PUSH_SEG(seg) \ + static uint32_t \ + ropPUSH_##seg##_16(UNUSED(uint8_t opcode), \ + UNUSED(uint32_t fetchdat), \ + UNUSED(uint32_t op_32), \ + uint32_t op_pc, \ + UNUSED(codeblock_t *block)) \ + { \ + int host_reg; \ + \ + STORE_IMM_ADDR_L((uintptr_t) &cpu_state.oldpc, op_old_pc); \ + LOAD_STACK_TO_EA(-2); \ + host_reg = LOAD_VAR_W((uintptr_t) &seg); \ + MEM_STORE_ADDR_EA_W(&cpu_state.seg_ss, host_reg); \ + SP_MODIFY(-2); \ + \ + return op_pc; \ + } \ + static uint32_t \ + ropPUSH_##seg##_32(UNUSED(uint8_t opcode), \ + UNUSED(uint32_t fetchdat), \ + UNUSED(uint32_t op_32), \ + uint32_t op_pc, \ + UNUSED(codeblock_t *block)) \ + { \ + int host_reg; \ + \ + STORE_IMM_ADDR_L((uintptr_t) &cpu_state.oldpc, op_old_pc); \ + LOAD_STACK_TO_EA(-4); \ + host_reg = LOAD_VAR_W((uintptr_t) &seg); \ + MEM_STORE_ADDR_EA_L(&cpu_state.seg_ss, host_reg); \ + SP_MODIFY(-4); \ + \ + return op_pc; \ } ROP_PUSH_SEG(CS) @@ -259,28 +267,36 @@ ROP_PUSH_SEG(FS) ROP_PUSH_SEG(GS) ROP_PUSH_SEG(SS) -#define ROP_POP_SEG(seg, rseg) \ - static uint32_t \ - ropPOP_##seg##_16(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \ - { \ - STORE_IMM_ADDR_L((uintptr_t) &cpu_state.oldpc, op_old_pc); \ - LOAD_STACK_TO_EA(0); \ - MEM_LOAD_ADDR_EA_W(&cpu_state.seg_ss); \ - LOAD_SEG(0, &rseg); \ - SP_MODIFY(2); \ - \ - return op_pc; \ - } \ - static uint32_t \ - ropPOP_##seg##_32(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \ - { \ - STORE_IMM_ADDR_L((uintptr_t) &cpu_state.oldpc, op_old_pc); \ - LOAD_STACK_TO_EA(0); \ - MEM_LOAD_ADDR_EA_W(&cpu_state.seg_ss); \ - LOAD_SEG(0, &rseg); \ - SP_MODIFY(4); \ - \ - return op_pc; \ +#define ROP_POP_SEG(seg, rseg) \ + static uint32_t \ + ropPOP_##seg##_16(UNUSED(uint8_t opcode), \ + UNUSED(uint32_t fetchdat), \ + UNUSED(uint32_t op_32), \ + uint32_t op_pc, \ + UNUSED(codeblock_t *block)) \ + { \ + STORE_IMM_ADDR_L((uintptr_t) &cpu_state.oldpc, op_old_pc); \ + LOAD_STACK_TO_EA(0); \ + MEM_LOAD_ADDR_EA_W(&cpu_state.seg_ss); \ + LOAD_SEG(0, &rseg); \ + SP_MODIFY(2); \ + \ + return op_pc; \ + } \ + static uint32_t \ + ropPOP_##seg##_32(UNUSED(uint8_t opcode), \ + UNUSED(uint32_t fetchdat), \ + UNUSED(uint32_t op_32), \ + uint32_t op_pc, \ + UNUSED(codeblock_t *block)) \ + { \ + STORE_IMM_ADDR_L((uintptr_t) &cpu_state.oldpc, op_old_pc); \ + LOAD_STACK_TO_EA(0); \ + MEM_LOAD_ADDR_EA_W(&cpu_state.seg_ss); \ + LOAD_SEG(0, &rseg); \ + SP_MODIFY(4); \ + \ + return op_pc; \ } ROP_POP_SEG(DS, cpu_state.seg_ds) diff --git a/src/codegen/codegen_ops_x86-64.h b/src/codegen/codegen_ops_x86-64.h index 08b9ee5f2..e46f55a05 100644 --- a/src/codegen/codegen_ops_x86-64.h +++ b/src/codegen/codegen_ops_x86-64.h @@ -55,7 +55,7 @@ call_long(uintptr_t func) } static __inline void -load_param_1_32(codeblock_t *block, uint32_t param) +load_param_1_32(UNUSED(codeblock_t *block), uint32_t param) { #if _WIN64 addbyte(0xb9); /*MOVL $fetchdat,%ecx*/ @@ -93,7 +93,7 @@ static __inline void load_param_1_64(codeblock_t *block, uint64_t param) #endif static __inline void -load_param_2_32(codeblock_t *block, uint32_t param) +load_param_2_32(UNUSED(codeblock_t *block), uint32_t param) { #if _WIN64 addbyte(0xba); /*MOVL $fetchdat,%edx*/ @@ -118,7 +118,7 @@ load_param_2_reg_32(int reg) #endif } static __inline void -load_param_2_64(codeblock_t *block, uint64_t param) +load_param_2_64(UNUSED(codeblock_t *block), uint64_t param) { addbyte(0x48); #if _WIN64 @@ -1492,7 +1492,7 @@ MEM_STORE_ADDR_EA_L(x86seg *seg, int host_reg) /*done:*/ } static __inline void -MEM_STORE_ADDR_EA_Q(x86seg *seg, int host_reg, int host_reg2) +MEM_STORE_ADDR_EA_Q(x86seg *seg, int host_reg, UNUSED(int host_reg2)) { if ((seg == &cpu_state.seg_ds && codegen_flat_ds && !(cpu_cur_status & CPU_STATUS_NOTFLATDS)) || (seg == &cpu_state.seg_ss && codegen_flat_ss && !(cpu_cur_status & CPU_STATUS_NOTFLATSS))) { addbyte(0x31); /*XOR ECX, ECX*/ @@ -3926,7 +3926,7 @@ FP_LOAD_REG(int reg) return REG_EBX; } static __inline void -FP_LOAD_REG_D(int reg, int *host_reg1, int *host_reg2) +FP_LOAD_REG_D(int reg, int *host_reg1, UNUSED(int *host_reg2)) { addbyte(0x8b); /*MOV EBX, TOP*/ addbyte(0x5d); @@ -4086,7 +4086,7 @@ FP_LOAD_REG_INT(int reg) return REG_EBX; } static __inline void -FP_LOAD_REG_INT_Q(int reg, int *host_reg1, int *host_reg2) +FP_LOAD_REG_INT_Q(int reg, int *host_reg1, UNUSED(int *host_reg2)) { addbyte(0x89); /*MOV EBX, EAX*/ addbyte(0xc3); @@ -4693,7 +4693,7 @@ LOAD_MMX_D(int guest_reg) return host_reg; } static __inline void -LOAD_MMX_Q(int guest_reg, int *host_reg1, int *host_reg2) +LOAD_MMX_Q(int guest_reg, int *host_reg1, UNUSED(int *host_reg2)) { int host_reg = REG_EBX; @@ -4725,7 +4725,7 @@ LOAD_MMX_Q_MMX(int guest_reg) } static __inline int -LOAD_INT_TO_MMX(int src_reg1, int src_reg2) +LOAD_INT_TO_MMX(int src_reg1, UNUSED(int src_reg2)) { int dst_reg = find_host_xmm_reg(); host_reg_xmm_mapping[dst_reg] = 100; @@ -4758,7 +4758,7 @@ STORE_MMX_LQ(int guest_reg, int host_reg1) addbyte((uint8_t) cpu_state_offset(MM[guest_reg].l[0])); } static __inline void -STORE_MMX_Q(int guest_reg, int host_reg1, int host_reg2) +STORE_MMX_Q(int guest_reg, int host_reg1, UNUSED(int host_reg2)) { if (host_reg1 & 8) addbyte(0x4c); diff --git a/src/codegen/codegen_ops_xchg.h b/src/codegen/codegen_ops_xchg.h index 28a558078..467f711e4 100644 --- a/src/codegen/codegen_ops_xchg.h +++ b/src/codegen/codegen_ops_xchg.h @@ -1,16 +1,20 @@ -#define OP_XCHG_AX_(reg) \ - static uint32_t \ - ropXCHG_AX_##reg(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \ - { \ - int ax_reg, host_reg, temp_reg; \ - \ - ax_reg = LOAD_REG_W(REG_AX); \ - host_reg = LOAD_REG_W(REG_##reg); \ - temp_reg = COPY_REG(host_reg); \ - STORE_REG_TARGET_W_RELEASE(ax_reg, REG_##reg); \ - STORE_REG_TARGET_W_RELEASE(temp_reg, REG_AX); \ - \ - return op_pc; \ +#define OP_XCHG_AX_(reg) \ + static uint32_t \ + ropXCHG_AX_##reg(UNUSED(uint8_t opcode), \ + UNUSED(uint32_t fetchdat), \ + UNUSED(uint32_t op_32), \ + uint32_t op_pc, \ + UNUSED(codeblock_t *block)) \ + { \ + int ax_reg, host_reg, temp_reg; \ + \ + ax_reg = LOAD_REG_W(REG_AX); \ + host_reg = LOAD_REG_W(REG_##reg); \ + temp_reg = COPY_REG(host_reg); \ + STORE_REG_TARGET_W_RELEASE(ax_reg, REG_##reg); \ + STORE_REG_TARGET_W_RELEASE(temp_reg, REG_AX); \ + \ + return op_pc; \ } OP_XCHG_AX_(BX) @@ -21,19 +25,23 @@ OP_XCHG_AX_(DI) OP_XCHG_AX_(SP) OP_XCHG_AX_(BP) -#define OP_XCHG_EAX_(reg) \ - static uint32_t \ - ropXCHG_EAX_##reg(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \ - { \ - int eax_reg, host_reg, temp_reg; \ - \ - eax_reg = LOAD_REG_L(REG_EAX); \ - host_reg = LOAD_REG_L(REG_##reg); \ - temp_reg = COPY_REG(host_reg); \ - STORE_REG_TARGET_L_RELEASE(eax_reg, REG_##reg); \ - STORE_REG_TARGET_L_RELEASE(temp_reg, REG_EAX); \ - \ - return op_pc; \ +#define OP_XCHG_EAX_(reg) \ + static uint32_t \ + ropXCHG_EAX_##reg(UNUSED(uint8_t opcode), \ + UNUSED(uint32_t fetchdat), \ + UNUSED(uint32_t op_32), \ + uint32_t op_pc, \ + UNUSED(codeblock_t *block)) \ + { \ + int eax_reg, host_reg, temp_reg; \ + \ + eax_reg = LOAD_REG_L(REG_EAX); \ + host_reg = LOAD_REG_L(REG_##reg); \ + temp_reg = COPY_REG(host_reg); \ + STORE_REG_TARGET_L_RELEASE(eax_reg, REG_##reg); \ + STORE_REG_TARGET_L_RELEASE(temp_reg, REG_EAX); \ + \ + return op_pc; \ } OP_XCHG_EAX_(EBX) @@ -45,7 +53,7 @@ OP_XCHG_EAX_(ESP) OP_XCHG_EAX_(EBP) static uint32_t -ropXCHG_b(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropXCHG_b(UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { int src_reg; int dst_reg; @@ -63,7 +71,7 @@ ropXCHG_b(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, cod return op_pc + 1; } static uint32_t -ropXCHG_w(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropXCHG_w(UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { int src_reg; int dst_reg; @@ -81,7 +89,7 @@ ropXCHG_w(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, cod return op_pc + 1; } static uint32_t -ropXCHG_l(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropXCHG_l(UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { int src_reg; int dst_reg; diff --git a/src/codegen/codegen_x86-64.c b/src/codegen/codegen_x86-64.c index 59f411612..04c2136ff 100644 --- a/src/codegen/codegen_x86-64.c +++ b/src/codegen/codegen_x86-64.c @@ -125,7 +125,7 @@ add_to_block_list(codeblock_t *block) } static void -remove_from_block_list(codeblock_t *block, uint32_t pc) +remove_from_block_list(codeblock_t *block, UNUSED(uint32_t pc)) { if (!block->page_mask) return; diff --git a/src/codegen_new/codegen_ir.c b/src/codegen_new/codegen_ir.c index 6345bbe86..ed8ae051f 100644 --- a/src/codegen_new/codegen_ir.c +++ b/src/codegen_new/codegen_ir.c @@ -2,6 +2,7 @@ #include <86box/86box.h> #include "cpu.h" #include <86box/mem.h> +#include <86box/plat_unused.h> #include "codegen.h" #include "codegen_allocator.h" diff --git a/src/codegen_new/codegen_ir_defs.h b/src/codegen_new/codegen_ir_defs.h index 26a1c3cb4..9bd2f9afe 100644 --- a/src/codegen_new/codegen_ir_defs.h +++ b/src/codegen_new/codegen_ir_defs.h @@ -410,7 +410,7 @@ uop_gen_reg_src1(uint32_t uop_type, ir_data_t *ir, int src_reg_a) } static inline void -uop_gen_reg_src1_arg(uint32_t uop_type, ir_data_t *ir, int arg, int src_reg_a) +uop_gen_reg_src1_arg(uint32_t uop_type, ir_data_t *ir, UNUSED(int arg), int src_reg_a) { uop_t *uop = uop_alloc(ir, uop_type); diff --git a/src/codegen_new/codegen_ops.c b/src/codegen_new/codegen_ops.c index 59e148659..bb7d1f3ee 100644 --- a/src/codegen_new/codegen_ops.c +++ b/src/codegen_new/codegen_ops.c @@ -2,6 +2,7 @@ #include <86box/86box.h> #include "cpu.h" #include <86box/mem.h> +#include <86box/plat_unused.h> #include "codegen.h" #include "codegen_ir.h" diff --git a/src/codegen_new/codegen_ops_3dnow.c b/src/codegen_new/codegen_ops_3dnow.c index 8b4d471ba..03af718d1 100644 --- a/src/codegen_new/codegen_ops_3dnow.c +++ b/src/codegen_new/codegen_ops_3dnow.c @@ -17,7 +17,7 @@ #include "codegen_ops_helpers.h" #define ropParith(func) \ - uint32_t rop##func(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ + uint32_t rop##func(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ { \ int dest_reg = (fetchdat >> 3) & 7; \ \ @@ -192,7 +192,7 @@ ropPFRSQRT(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t f } uint32_t -ropPFRSQIT1(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropPFRSQIT1(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uop_MMX_ENTER(ir); diff --git a/src/codegen_new/codegen_ops_arith.c b/src/codegen_new/codegen_ops_arith.c index 9e136ace5..c899c13d8 100644 --- a/src/codegen_new/codegen_ops_arith.c +++ b/src/codegen_new/codegen_ops_arith.c @@ -22,7 +22,7 @@ get_cf(ir_data_t *ir, int dest_reg) } uint32_t -ropADC_AL_imm(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropADC_AL_imm(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uint8_t imm_data = fastreadb(cs + op_pc); @@ -39,7 +39,7 @@ ropADC_AL_imm(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_ return op_pc + 1; } uint32_t -ropADC_AX_imm(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropADC_AX_imm(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uint16_t imm_data = fastreadw(cs + op_pc); @@ -274,7 +274,7 @@ ropADC_l_rmw(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t } uint32_t -ropADD_AL_imm(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropADD_AL_imm(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uint8_t imm_data = fastreadb(cs + op_pc); @@ -289,7 +289,7 @@ ropADD_AL_imm(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_ return op_pc + 1; } uint32_t -ropADD_AX_imm(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropADD_AX_imm(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uint16_t imm_data = fastreadw(cs + op_pc); @@ -511,7 +511,7 @@ ropADD_l_rmw(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t } uint32_t -ropCMP_AL_imm(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropCMP_AL_imm(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uint8_t imm_data = fastreadb(cs + op_pc); @@ -526,7 +526,7 @@ ropCMP_AL_imm(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_ return op_pc + 1; } uint32_t -ropCMP_AX_imm(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropCMP_AX_imm(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uint16_t imm_data = fastreadw(cs + op_pc); @@ -734,7 +734,7 @@ ropCMP_l_rmw(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t } uint32_t -ropSBB_AL_imm(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropSBB_AL_imm(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uint8_t imm_data = fastreadb(cs + op_pc); @@ -751,7 +751,7 @@ ropSBB_AL_imm(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_ return op_pc + 1; } uint32_t -ropSBB_AX_imm(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropSBB_AX_imm(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uint16_t imm_data = fastreadw(cs + op_pc); @@ -988,7 +988,7 @@ ropSBB_l_rmw(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t } uint32_t -ropSUB_AL_imm(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropSUB_AL_imm(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uint8_t imm_data = fastreadb(cs + op_pc); @@ -1003,7 +1003,7 @@ ropSUB_AL_imm(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_ return op_pc + 1; } uint32_t -ropSUB_AX_imm(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropSUB_AX_imm(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uint16_t imm_data = fastreadw(cs + op_pc); @@ -2293,7 +2293,7 @@ rebuild_c(ir_data_t *ir) } uint32_t -ropINC_r16(UNUSED(UNUSED(codeblock_t *block)), ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropINC_r16(UNUSED(UNUSED(codeblock_t *block)), ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { rebuild_c(ir); @@ -2307,7 +2307,7 @@ ropINC_r16(UNUSED(UNUSED(codeblock_t *block)), ir_data_t *ir, UNUSED(uint8_t opc return op_pc; } uint32_t -ropINC_r32(UNUSED(UNUSED(codeblock_t *block)), ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropINC_r32(UNUSED(UNUSED(codeblock_t *block)), ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { rebuild_c(ir); @@ -2322,7 +2322,7 @@ ropINC_r32(UNUSED(UNUSED(codeblock_t *block)), ir_data_t *ir, UNUSED(uint8_t opc } uint32_t -ropDEC_r16(UNUSED(codeblock_t *block), ir_data_t *ir, uint8_t opcode, uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropDEC_r16(UNUSED(codeblock_t *block), ir_data_t *ir, uint8_t opcode, UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { rebuild_c(ir); @@ -2336,7 +2336,7 @@ ropDEC_r16(UNUSED(codeblock_t *block), ir_data_t *ir, uint8_t opcode, uint32_t f return op_pc; } uint32_t -ropDEC_r32(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropDEC_r32(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { rebuild_c(ir); diff --git a/src/codegen_new/codegen_ops_branch.c b/src/codegen_new/codegen_ops_branch.c index cedb54177..1e2589f8b 100644 --- a/src/codegen_new/codegen_ops_branch.c +++ b/src/codegen_new/codegen_ops_branch.c @@ -816,7 +816,7 @@ ropJNLE_common(codeblock_t *block, ir_data_t *ir, uint32_t dest_addr, uint32_t n } #define ropJ(cond) \ - uint32_t ropJ##cond##_8(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ + uint32_t ropJ##cond##_8(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), uint32_t op_32, uint32_t op_pc) \ { \ uint32_t offset = (int32_t) (int8_t) fastreadb(cs + op_pc); \ uint32_t dest_addr = op_pc + 1 + offset; \ @@ -829,7 +829,7 @@ ropJNLE_common(codeblock_t *block, ir_data_t *ir, uint32_t dest_addr, uint32_t n codegen_mark_code_present(block, cs + op_pc, 1); \ return ret ? dest_addr : (op_pc + 1); \ } \ - uint32_t ropJ##cond##_16(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ + uint32_t ropJ##cond##_16(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) \ { \ uint32_t offset = (int32_t) (int16_t) fastreadw(cs + op_pc); \ uint32_t dest_addr = (op_pc + 2 + offset) & 0xffff; \ @@ -840,7 +840,7 @@ ropJNLE_common(codeblock_t *block, ir_data_t *ir, uint32_t dest_addr, uint32_t n codegen_mark_code_present(block, cs + op_pc, 2); \ return ret ? dest_addr : (op_pc + 2); \ } \ - uint32_t ropJ##cond##_32(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ + uint32_t ropJ##cond##_32(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) \ { \ uint32_t offset = fastreadl(cs + op_pc); \ uint32_t dest_addr = op_pc + 4 + offset; \ @@ -852,6 +852,7 @@ ropJNLE_common(codeblock_t *block, ir_data_t *ir, uint32_t dest_addr, uint32_t n return ret ? dest_addr : (op_pc + 4); \ } +// clang-format off ropJ(O) ropJ(NO) ropJ(B) @@ -868,9 +869,10 @@ ropJ(L) ropJ(NL) ropJ(LE) ropJ(NLE) +// clang-format on uint32_t -ropJCXZ(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) +ropJCXZ(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), uint32_t op_32, uint32_t op_pc) { uint32_t offset = (int32_t) (int8_t) fastreadb(cs + op_pc); uint32_t dest_addr = op_pc + 1 + offset; @@ -892,7 +894,7 @@ ropJCXZ(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetc } uint32_t -ropLOOP(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) +ropLOOP(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), uint32_t op_32, uint32_t op_pc) { uint32_t offset = (int32_t) (int8_t) fastreadb(cs + op_pc); uint32_t dest_addr = op_pc + 1 + offset; @@ -932,7 +934,7 @@ ropLOOP(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetc } uint32_t -ropLOOPE(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) +ropLOOPE(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), uint32_t op_32, uint32_t op_pc) { uint32_t offset = (int32_t) (int8_t) fastreadb(cs + op_pc); uint32_t dest_addr = op_pc + 1 + offset; @@ -965,7 +967,7 @@ ropLOOPE(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fet return op_pc + 1; } uint32_t -ropLOOPNE(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) +ropLOOPNE(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), uint32_t op_32, uint32_t op_pc) { uint32_t offset = (int32_t) (int8_t) fastreadb(cs + op_pc); uint32_t dest_addr = op_pc + 1 + offset; diff --git a/src/codegen_new/codegen_ops_fpu_arith.c b/src/codegen_new/codegen_ops_fpu_arith.c index a7b5290f4..43d243c0f 100644 --- a/src/codegen_new/codegen_ops_fpu_arith.c +++ b/src/codegen_new/codegen_ops_fpu_arith.c @@ -79,7 +79,7 @@ ropFCOMP(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fet return op_pc; } uint32_t -ropFCOMPP(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropFCOMPP(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uop_FP_ENTER(ir); uop_FCOM(ir, IREG_temp0_W, IREG_ST(0), IREG_ST(1)); @@ -289,7 +289,7 @@ ropFUCOMP(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fe return op_pc; } uint32_t -ropFUCOMPP(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropFUCOMPP(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uop_FP_ENTER(ir); uop_FCOM(ir, IREG_temp0_W, IREG_ST(0), IREG_ST(1)); @@ -301,7 +301,7 @@ ropFUCOMPP(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t f } #define ropF_arith_mem(name, load_uop) \ - uint32_t ropFADD##name(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ + uint32_t ropFADD##name(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ { \ x86seg *target_seg; \ \ @@ -318,7 +318,7 @@ ropFUCOMPP(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t f \ return op_pc + 1; \ } \ - uint32_t ropFCOM##name(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ + uint32_t ropFCOM##name(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ { \ x86seg *target_seg; \ \ @@ -329,12 +329,12 @@ ropFUCOMPP(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t f codegen_check_seg_read(block, ir, target_seg); \ load_uop(ir, IREG_temp0_D, ireg_seg_base(target_seg), IREG_eaaddr); \ uop_FCOM(ir, IREG_temp1_W, IREG_ST(0), IREG_temp0_D); \ - uop_AND_IMM(ir, IREG_NPXS, IREG_NPXS, ~(FPU_SW_C0 | FPU_SW_C2 | FPU_SW_C3)); \ + uop_AND_IMM(ir, IREG_NPXS, IREG_NPXS, ~(FPU_SW_C0 | FPU_SW_C2 | FPU_SW_C3)); \ uop_OR(ir, IREG_NPXS, IREG_NPXS, IREG_temp1_W); \ \ return op_pc + 1; \ } \ - uint32_t ropFCOMP##name(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ + uint32_t ropFCOMP##name(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ { \ x86seg *target_seg; \ \ @@ -351,7 +351,7 @@ ropFUCOMPP(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t f \ return op_pc + 1; \ } \ - uint32_t ropFDIV##name(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ + uint32_t ropFDIV##name(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ { \ x86seg *target_seg; \ \ @@ -366,7 +366,7 @@ ropFUCOMPP(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t f \ return op_pc + 1; \ } \ - uint32_t ropFDIVR##name(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ + uint32_t ropFDIVR##name(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ { \ x86seg *target_seg; \ \ @@ -381,7 +381,7 @@ ropFUCOMPP(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t f \ return op_pc + 1; \ } \ - uint32_t ropFMUL##name(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ + uint32_t ropFMUL##name(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ { \ x86seg *target_seg; \ \ @@ -396,7 +396,7 @@ ropFUCOMPP(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t f \ return op_pc + 1; \ } \ - uint32_t ropFSUB##name(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ + uint32_t ropFSUB##name(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ { \ x86seg *target_seg; \ \ @@ -411,7 +411,7 @@ ropFUCOMPP(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t f \ return op_pc + 1; \ } \ - uint32_t ropFSUBR##name(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ + uint32_t ropFSUBR##name(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ { \ x86seg *target_seg; \ \ @@ -433,7 +433,7 @@ ropF_arith_mem(d, uop_MEM_LOAD_DOUBLE) // clang-format on #define ropFI_arith_mem(name, temp_reg) \ - uint32_t ropFIADD##name(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ + uint32_t ropFIADD##name(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ { \ x86seg *target_seg; \ \ @@ -449,7 +449,7 @@ ropF_arith_mem(d, uop_MEM_LOAD_DOUBLE) \ return op_pc + 1; \ } \ - uint32_t ropFICOM##name(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ + uint32_t ropFICOM##name(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ { \ x86seg *target_seg; \ \ @@ -461,12 +461,12 @@ ropF_arith_mem(d, uop_MEM_LOAD_DOUBLE) uop_MEM_LOAD_REG(ir, temp_reg, ireg_seg_base(target_seg), IREG_eaaddr); \ uop_MOV_DOUBLE_INT(ir, IREG_temp0_D, temp_reg); \ uop_FCOM(ir, IREG_temp1_W, IREG_ST(0), IREG_temp0_D); \ - uop_AND_IMM(ir, IREG_NPXS, IREG_NPXS, ~(FPU_SW_C0 | FPU_SW_C2 | FPU_SW_C3)); \ + uop_AND_IMM(ir, IREG_NPXS, IREG_NPXS, ~(FPU_SW_C0 | FPU_SW_C2 | FPU_SW_C3)); \ uop_OR(ir, IREG_NPXS, IREG_NPXS, IREG_temp1_W); \ \ return op_pc + 1; \ } \ - uint32_t ropFICOMP##name(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ + uint32_t ropFICOMP##name(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ { \ x86seg *target_seg; \ \ @@ -478,13 +478,13 @@ ropF_arith_mem(d, uop_MEM_LOAD_DOUBLE) uop_MEM_LOAD_REG(ir, temp_reg, ireg_seg_base(target_seg), IREG_eaaddr); \ uop_MOV_DOUBLE_INT(ir, IREG_temp0_D, temp_reg); \ uop_FCOM(ir, IREG_temp1_W, IREG_ST(0), IREG_temp0_D); \ - uop_AND_IMM(ir, IREG_NPXS, IREG_NPXS, ~(FPU_SW_C0 | FPU_SW_C2 | FPU_SW_C3)); \ + uop_AND_IMM(ir, IREG_NPXS, IREG_NPXS, ~(FPU_SW_C0 | FPU_SW_C2 | FPU_SW_C3)); \ uop_OR(ir, IREG_NPXS, IREG_NPXS, IREG_temp1_W); \ fpu_POP(block, ir); \ \ return op_pc + 1; \ } \ - uint32_t ropFIDIV##name(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ + uint32_t ropFIDIV##name(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ { \ x86seg *target_seg; \ \ @@ -500,7 +500,7 @@ ropF_arith_mem(d, uop_MEM_LOAD_DOUBLE) \ return op_pc + 1; \ } \ - uint32_t ropFIDIVR##name(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ + uint32_t ropFIDIVR##name(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ { \ x86seg *target_seg; \ \ @@ -516,7 +516,7 @@ ropF_arith_mem(d, uop_MEM_LOAD_DOUBLE) \ return op_pc + 1; \ } \ - uint32_t ropFIMUL##name(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ + uint32_t ropFIMUL##name(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ { \ x86seg *target_seg; \ \ @@ -532,7 +532,7 @@ ropF_arith_mem(d, uop_MEM_LOAD_DOUBLE) \ return op_pc + 1; \ } \ - uint32_t ropFISUB##name(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ + uint32_t ropFISUB##name(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ { \ x86seg *target_seg; \ \ @@ -548,7 +548,7 @@ ropF_arith_mem(d, uop_MEM_LOAD_DOUBLE) \ return op_pc + 1; \ } \ - uint32_t ropFISUBR##name(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ + uint32_t ropFISUBR##name(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ { \ x86seg *target_seg; \ \ @@ -565,11 +565,13 @@ ropF_arith_mem(d, uop_MEM_LOAD_DOUBLE) return op_pc + 1; \ } +// clang-format off ropFI_arith_mem(l, IREG_temp0) ropFI_arith_mem(w, IREG_temp0_W) +// clang-format on uint32_t -ropFABS(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropFABS(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uop_FP_ENTER(ir); uop_FABS(ir, IREG_ST(0), IREG_ST(0)); @@ -579,7 +581,7 @@ ropFABS(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), uint3 } uint32_t -ropFCHS(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropFCHS(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uop_FP_ENTER(ir); uop_FCHS(ir, IREG_ST(0), IREG_ST(0)); @@ -588,7 +590,7 @@ ropFCHS(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), uint3 return op_pc; } uint32_t -ropFSQRT(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropFSQRT(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uop_FP_ENTER(ir); uop_FSQRT(ir, IREG_ST(0), IREG_ST(0)); @@ -597,7 +599,7 @@ ropFSQRT(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), uint return op_pc; } uint32_t -ropFTST(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropFTST(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uop_FP_ENTER(ir); uop_FTST(ir, IREG_temp0_W, IREG_ST(0)); diff --git a/src/codegen_new/codegen_ops_fpu_constant.c b/src/codegen_new/codegen_ops_fpu_constant.c index a91d675c5..6ec2f6888 100644 --- a/src/codegen_new/codegen_ops_fpu_constant.c +++ b/src/codegen_new/codegen_ops_fpu_constant.c @@ -19,7 +19,7 @@ #include "codegen_ops_helpers.h" uint32_t -ropFLD1(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropFLD1(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uop_FP_ENTER(ir); uop_MOV_IMM(ir, IREG_temp0, 1); @@ -30,7 +30,7 @@ ropFLD1(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetc return op_pc; } uint32_t -ropFLDZ(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropFLDZ(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uop_FP_ENTER(ir); uop_MOV_IMM(ir, IREG_temp0, 0); diff --git a/src/codegen_new/codegen_ops_fpu_misc.c b/src/codegen_new/codegen_ops_fpu_misc.c index 31b668488..938204a70 100644 --- a/src/codegen_new/codegen_ops_fpu_misc.c +++ b/src/codegen_new/codegen_ops_fpu_misc.c @@ -98,7 +98,7 @@ ropFSTSW(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fet return op_pc + 1; } uint32_t -ropFSTSW_AX(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropFSTSW_AX(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uop_FP_ENTER(ir); uop_MOV(ir, IREG_AX, IREG_NPXS); diff --git a/src/codegen_new/codegen_ops_helpers.c b/src/codegen_new/codegen_ops_helpers.c index f2a4ce41a..037d91469 100644 --- a/src/codegen_new/codegen_ops_helpers.c +++ b/src/codegen_new/codegen_ops_helpers.c @@ -18,8 +18,8 @@ void LOAD_IMMEDIATE_FROM_RAM_16_unaligned(UNUSED(codeblock_t *block), ir_data_t *ir, int dest_reg, uint32_t addr) { /*Word access that crosses two pages. Perform reads from both pages, shift and combine*/ - uop_MOVZX_REG_PTR_8(ir, IREG_temp3_W, get_ram_ptr(addr)); - uop_MOVZX_REG_PTR_8(ir, dest_reg, get_ram_ptr(addr + 1)); + uop_MOVZX_REG_PTR_8(ir, IREG_temp3_W, get_ram_ptr(addr + 1)); + uop_MOVZX_REG_PTR_8(ir, dest_reg, get_ram_ptr(addr)); uop_SHL_IMM(ir, IREG_temp3_W, IREG_temp3_W, 8); uop_OR(ir, dest_reg, dest_reg, IREG_temp3_W); } diff --git a/src/codegen_new/codegen_ops_helpers.h b/src/codegen_new/codegen_ops_helpers.h index 5a8f1e1c7..92b721099 100644 --- a/src/codegen_new/codegen_ops_helpers.h +++ b/src/codegen_new/codegen_ops_helpers.h @@ -71,7 +71,7 @@ fpu_PUSH(codeblock_t *block, ir_data_t *ir) } static inline void -CHECK_SEG_LIMITS(codeblock_t *block, ir_data_t *ir, x86seg *seg, int addr_reg, int end_offset) +CHECK_SEG_LIMITS(UNUSED(codeblock_t *block), ir_data_t *ir, x86seg *seg, int addr_reg, int end_offset) { if ((seg == &cpu_state.seg_ds && codegen_flat_ds && !(cpu_cur_status & CPU_STATUS_NOTFLATDS)) || (seg == &cpu_state.seg_ss && codegen_flat_ss && !(cpu_cur_status & CPU_STATUS_NOTFLATSS))) return; @@ -85,7 +85,7 @@ CHECK_SEG_LIMITS(codeblock_t *block, ir_data_t *ir, x86seg *seg, int addr_reg, i } static inline void -LOAD_IMMEDIATE_FROM_RAM_8(codeblock_t *block, ir_data_t *ir, int dest_reg, uint32_t addr) +LOAD_IMMEDIATE_FROM_RAM_8(UNUSED(codeblock_t *block), ir_data_t *ir, int dest_reg, uint32_t addr) { uop_MOVZX_REG_PTR_8(ir, dest_reg, get_ram_ptr(addr)); } diff --git a/src/codegen_new/codegen_ops_jump.c b/src/codegen_new/codegen_ops_jump.c index fb2f1e5ba..430b16b2b 100644 --- a/src/codegen_new/codegen_ops_jump.c +++ b/src/codegen_new/codegen_ops_jump.c @@ -15,7 +15,7 @@ #include "codegen_ops_mov.h" uint32_t -ropJMP_r8(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) +ropJMP_r8(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), uint32_t op_32, uint32_t op_pc) { uint32_t offset = (int32_t) (int8_t) fastreadb(cs + op_pc); uint32_t dest_addr = op_pc + 1 + offset; @@ -29,7 +29,7 @@ ropJMP_r8(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fe return dest_addr; } uint32_t -ropJMP_r16(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropJMP_r16(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uint32_t offset = (int32_t) (int16_t) fastreadw(cs + op_pc); uint32_t dest_addr = op_pc + 2 + offset; @@ -42,7 +42,7 @@ ropJMP_r16(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t f return dest_addr; } uint32_t -ropJMP_r32(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropJMP_r32(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uint32_t offset = fastreadl(cs + op_pc); uint32_t dest_addr = op_pc + 4 + offset; @@ -54,7 +54,7 @@ ropJMP_r32(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t f } uint32_t -ropJMP_far_16(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropJMP_far_16(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uint16_t new_pc = fastreadw(cs + op_pc); uint16_t new_cs = fastreadw(cs + op_pc + 2); @@ -69,7 +69,7 @@ ropJMP_far_16(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_ return -1; } uint32_t -ropJMP_far_32(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropJMP_far_32(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uint32_t new_pc = fastreadl(cs + op_pc); uint16_t new_cs = fastreadw(cs + op_pc + 4); @@ -85,7 +85,7 @@ ropJMP_far_32(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_ } uint32_t -ropCALL_r16(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropCALL_r16(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uint32_t offset = (int32_t) (int16_t) fastreadw(cs + op_pc); uint16_t ret_addr = op_pc + 2; @@ -104,7 +104,7 @@ ropCALL_r16(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t return -1; } uint32_t -ropCALL_r32(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropCALL_r32(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uint32_t offset = fastreadl(cs + op_pc); uint32_t ret_addr = op_pc + 4; @@ -122,7 +122,7 @@ ropCALL_r32(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t } uint32_t -ropRET_16(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), UNUSED(uint32_t op_pc)) +ropRET_16(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), UNUSED(uint32_t op_pc)) { uop_MOV_IMM(ir, IREG_oldpc, cpu_state.oldpc); @@ -138,7 +138,7 @@ ropRET_16(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), uin return -1; } uint32_t -ropRET_32(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), UNUSED(uint32_t op_pc)) +ropRET_32(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), UNUSED(uint32_t op_pc)) { uop_MOV_IMM(ir, IREG_oldpc, cpu_state.oldpc); @@ -154,7 +154,7 @@ ropRET_32(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), uin } uint32_t -ropRET_imm_16(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropRET_imm_16(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uint16_t offset = fastreadw(cs + op_pc); @@ -173,7 +173,7 @@ ropRET_imm_16(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_ return -1; } uint32_t -ropRET_imm_32(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropRET_imm_32(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uint16_t offset = fastreadw(cs + op_pc); @@ -192,7 +192,7 @@ ropRET_imm_32(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_ } uint32_t -ropRETF_16(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), UNUSED(uint32_t op_pc)) +ropRETF_16(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), UNUSED(uint32_t op_pc)) { if ((msw & 1) && !(cpu_state.eflags & VM_FLAG)) return 0; @@ -215,7 +215,7 @@ ropRETF_16(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), ui return -1; } uint32_t -ropRETF_32(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), UNUSED(uint32_t op_pc)) +ropRETF_32(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), UNUSED(uint32_t op_pc)) { if ((msw & 1) && !(cpu_state.eflags & VM_FLAG)) return 0; @@ -239,7 +239,7 @@ ropRETF_32(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), ui } uint32_t -ropRETF_imm_16(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropRETF_imm_16(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uint16_t offset; @@ -266,7 +266,7 @@ ropRETF_imm_16(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32 return -1; } uint32_t -ropRETF_imm_32(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropRETF_imm_32(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uint16_t offset; diff --git a/src/codegen_new/codegen_ops_logic.c b/src/codegen_new/codegen_ops_logic.c index 684052fea..f289f1cba 100644 --- a/src/codegen_new/codegen_ops_logic.c +++ b/src/codegen_new/codegen_ops_logic.c @@ -16,7 +16,7 @@ #include "codegen_ops_logic.h" uint32_t -ropAND_AL_imm(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropAND_AL_imm(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uint8_t imm_data = fastreadb(cs + op_pc); @@ -29,7 +29,7 @@ ropAND_AL_imm(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_ return op_pc + 1; } uint32_t -ropAND_AX_imm(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropAND_AX_imm(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uint16_t imm_data = fastreadw(cs + op_pc); @@ -226,7 +226,7 @@ ropAND_l_rmw(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t } uint32_t -ropOR_AL_imm(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropOR_AL_imm(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uint8_t imm_data = fastreadb(cs + op_pc); @@ -239,7 +239,7 @@ ropOR_AL_imm(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t return op_pc + 1; } uint32_t -ropOR_AX_imm(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropOR_AX_imm(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uint16_t imm_data = fastreadw(cs + op_pc); @@ -437,7 +437,7 @@ ropOR_l_rmw(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t } uint32_t -ropTEST_AL_imm(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropTEST_AL_imm(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uint8_t imm_data = fastreadb(cs + op_pc); @@ -449,7 +449,7 @@ ropTEST_AL_imm(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32 return op_pc + 1; } uint32_t -ropTEST_AX_imm(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropTEST_AX_imm(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uint16_t imm_data = fastreadw(cs + op_pc); @@ -557,7 +557,7 @@ ropTEST_l_rm(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t } uint32_t -ropXOR_AL_imm(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropXOR_AL_imm(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uint8_t imm_data = fastreadb(cs + op_pc); @@ -570,7 +570,7 @@ ropXOR_AL_imm(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_ return op_pc + 1; } uint32_t -ropXOR_AX_imm(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropXOR_AX_imm(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uint16_t imm_data = fastreadw(cs + op_pc); diff --git a/src/codegen_new/codegen_ops_misc.c b/src/codegen_new/codegen_ops_misc.c index 545634672..c709dffc9 100644 --- a/src/codegen_new/codegen_ops_misc.c +++ b/src/codegen_new/codegen_ops_misc.c @@ -485,34 +485,34 @@ ropFF_32(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fet } uint32_t -ropNOP(UNUSED(codeblock_t *block), UNUSED(ir_data_t *ir), UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropNOP(UNUSED(codeblock_t *block), UNUSED(ir_data_t *ir), UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { return op_pc; } uint32_t -ropCBW(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropCBW(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uop_MOVSX(ir, IREG_AX, IREG_AL); return op_pc; } uint32_t -ropCDQ(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropCDQ(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uop_SAR_IMM(ir, IREG_EDX, IREG_EAX, 31); return op_pc; } uint32_t -ropCWD(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropCWD(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uop_SAR_IMM(ir, IREG_DX, IREG_AX, 15); return op_pc; } uint32_t -ropCWDE(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropCWDE(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uop_MOVSX(ir, IREG_EAX, IREG_AX); @@ -520,7 +520,7 @@ ropCWDE(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), uint3 } #define ropLxS(name, seg) \ - uint32_t rop##name##_16(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ + uint32_t rop##name##_16(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ { \ x86seg *target_seg = NULL; \ int dest_reg = (fetchdat >> 3) & 7; \ @@ -542,7 +542,7 @@ ropCWDE(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), uint3 \ return op_pc + 1; \ } \ - uint32_t rop##name##_32(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ + uint32_t rop##name##_32(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ { \ x86seg *target_seg = NULL; \ int dest_reg = (fetchdat >> 3) & 7; \ @@ -572,21 +572,21 @@ ropLxS(LGS, &cpu_state.seg_gs) ropLxS(LSS, &cpu_state.seg_ss) uint32_t -ropCLC(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropCLC(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uop_CALL_FUNC(ir, flags_rebuild); uop_AND_IMM(ir, IREG_flags, IREG_flags, ~C_FLAG); return op_pc; } uint32_t -ropCMC(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropCMC(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uop_CALL_FUNC(ir, flags_rebuild); uop_XOR_IMM(ir, IREG_flags, IREG_flags, C_FLAG); return op_pc; } uint32_t -ropSTC(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropSTC(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uop_CALL_FUNC(ir, flags_rebuild); uop_OR_IMM(ir, IREG_flags, IREG_flags, C_FLAG); @@ -594,20 +594,20 @@ ropSTC(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), uint32 } uint32_t -ropCLD(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropCLD(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uop_AND_IMM(ir, IREG_flags, IREG_flags, ~D_FLAG); return op_pc; } uint32_t -ropSTD(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropSTD(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uop_OR_IMM(ir, IREG_flags, IREG_flags, D_FLAG); return op_pc; } uint32_t -ropCLI(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropCLI(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { if (!IOPLp && (cr4 & (CR4_VME | CR4_PVI))) return 0; @@ -616,7 +616,7 @@ ropCLI(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), uint32 return op_pc; } uint32_t -ropSTI(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropSTI(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { if (!IOPLp && (cr4 & (CR4_VME | CR4_PVI))) return 0; diff --git a/src/codegen_new/codegen_ops_mmx_arith.c b/src/codegen_new/codegen_ops_mmx_arith.c index e99b4c56d..8fd1d1651 100644 --- a/src/codegen_new/codegen_ops_mmx_arith.c +++ b/src/codegen_new/codegen_ops_mmx_arith.c @@ -2,6 +2,7 @@ #include <86box/86box.h> #include "cpu.h" #include <86box/mem.h> +#include <86box/plat_unused.h> #include "x86.h" #include "x86_flags.h" @@ -16,7 +17,7 @@ #include "codegen_ops_helpers.h" #define ropParith(func) \ - uint32_t rop##func(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ + uint32_t rop##func(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ { \ int dest_reg = (fetchdat >> 3) & 7; \ \ @@ -58,4 +59,4 @@ ropParith(PSUBUSW) ropParith(PMADDWD) ropParith(PMULHW) ropParith(PMULLW) - // clang-format on +// clang-format on diff --git a/src/codegen_new/codegen_ops_mmx_cmp.c b/src/codegen_new/codegen_ops_mmx_cmp.c index 6f38cba67..e00e56472 100644 --- a/src/codegen_new/codegen_ops_mmx_cmp.c +++ b/src/codegen_new/codegen_ops_mmx_cmp.c @@ -2,6 +2,7 @@ #include <86box/86box.h> #include "cpu.h" #include <86box/mem.h> +#include <86box/plat_unused.h> #include "x86.h" #include "x86_flags.h" @@ -16,7 +17,7 @@ #include "codegen_ops_helpers.h" #define ropPcmp(func) \ - uint32_t rop##func(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ + uint32_t rop##func(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ { \ int dest_reg = (fetchdat >> 3) & 7; \ \ @@ -45,4 +46,4 @@ ropPcmp(PCMPEQD) ropPcmp(PCMPGTB) ropPcmp(PCMPGTW) ropPcmp(PCMPGTD) - // clang-format on +// clang-format on diff --git a/src/codegen_new/codegen_ops_mmx_pack.c b/src/codegen_new/codegen_ops_mmx_pack.c index d25edd52e..18377e142 100644 --- a/src/codegen_new/codegen_ops_mmx_pack.c +++ b/src/codegen_new/codegen_ops_mmx_pack.c @@ -2,6 +2,7 @@ #include <86box/86box.h> #include "cpu.h" #include <86box/mem.h> +#include <86box/plat_unused.h> #include "x86.h" #include "x86_flags.h" @@ -16,7 +17,7 @@ #include "codegen_ops_helpers.h" #define ropPpack(func) \ - uint32_t rop##func(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ + uint32_t rop##func(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ { \ int dest_reg = (fetchdat >> 3) & 7; \ \ @@ -48,4 +49,4 @@ ropPpack(PUNPCKLDQ) ropPpack(PUNPCKHBW) ropPpack(PUNPCKHWD) ropPpack(PUNPCKHDQ) - // clang-format on +// clang-format on diff --git a/src/codegen_new/codegen_ops_mov.c b/src/codegen_new/codegen_ops_mov.c index eae7045a8..031d2ea05 100644 --- a/src/codegen_new/codegen_ops_mov.c +++ b/src/codegen_new/codegen_ops_mov.c @@ -15,7 +15,7 @@ #include "codegen_ops_mov.h" uint32_t -ropMOV_rb_imm(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropMOV_rb_imm(codeblock_t *block, ir_data_t *ir, uint8_t opcode, UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uint8_t imm = fastreadb(cs + op_pc); @@ -25,7 +25,7 @@ ropMOV_rb_imm(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_t fetchd return op_pc + 1; } uint32_t -ropMOV_rw_imm(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropMOV_rw_imm(codeblock_t *block, ir_data_t *ir, uint8_t opcode, UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uint16_t imm = fastreadw(cs + op_pc); @@ -172,7 +172,7 @@ ropMOV_r_l(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t f } uint32_t -ropMOV_AL_abs(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) +ropMOV_AL_abs(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), uint32_t op_32, uint32_t op_pc) { uint32_t addr; @@ -189,7 +189,7 @@ ropMOV_AL_abs(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_ return op_pc + ((op_32 & 0x200) ? 4 : 2); } uint32_t -ropMOV_AX_abs(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) +ropMOV_AX_abs(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), uint32_t op_32, uint32_t op_pc) { uint32_t addr; @@ -206,7 +206,7 @@ ropMOV_AX_abs(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_ return op_pc + ((op_32 & 0x200) ? 4 : 2); } uint32_t -ropMOV_EAX_abs(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) +ropMOV_EAX_abs(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), uint32_t op_32, uint32_t op_pc) { uint32_t addr = 0; @@ -233,7 +233,7 @@ ropMOV_EAX_abs(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32 } uint32_t -ropMOV_abs_AL(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) +ropMOV_abs_AL(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), uint32_t op_32, uint32_t op_pc) { uint32_t addr; @@ -250,7 +250,7 @@ ropMOV_abs_AL(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_ return op_pc + ((op_32 & 0x200) ? 4 : 2); } uint32_t -ropMOV_abs_AX(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) +ropMOV_abs_AX(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), uint32_t op_32, uint32_t op_pc) { uint32_t addr; @@ -267,7 +267,7 @@ ropMOV_abs_AX(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_ return op_pc + ((op_32 & 0x200) ? 4 : 2); } uint32_t -ropMOV_abs_EAX(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) +ropMOV_abs_EAX(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), uint32_t op_32, uint32_t op_pc) { uint32_t addr; @@ -614,7 +614,7 @@ ropMOVZX_32_16(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32 } uint32_t -ropXCHG_AX(UNUSED(codeblock_t *block), ir_data_t *ir, uint8_t opcode, uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropXCHG_AX(UNUSED(codeblock_t *block), ir_data_t *ir, uint8_t opcode, UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { int reg2 = IREG_16(opcode & 7); @@ -625,7 +625,7 @@ ropXCHG_AX(UNUSED(codeblock_t *block), ir_data_t *ir, uint8_t opcode, uint32_t f return op_pc; } uint32_t -ropXCHG_EAX(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropXCHG_EAX(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { int reg2 = IREG_32(opcode & 7); @@ -716,7 +716,7 @@ ropXCHG_32(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t f } uint32_t -ropXLAT(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) +ropXLAT(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), uint32_t op_32, uint32_t op_pc) { uop_MOV_IMM(ir, IREG_oldpc, cpu_state.oldpc); diff --git a/src/codegen_new/codegen_ops_stack.c b/src/codegen_new/codegen_ops_stack.c index 92ad9509d..057cccb0f 100644 --- a/src/codegen_new/codegen_ops_stack.c +++ b/src/codegen_new/codegen_ops_stack.c @@ -16,7 +16,7 @@ #include "codegen_ops_misc.h" uint32_t -ropPUSH_r16(UNUSED(codeblock_t *block), ir_data_t *ir, uint8_t opcode, uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropPUSH_r16(UNUSED(codeblock_t *block), ir_data_t *ir, uint8_t opcode, UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { int sp_reg; @@ -28,7 +28,7 @@ ropPUSH_r16(UNUSED(codeblock_t *block), ir_data_t *ir, uint8_t opcode, uint32_t return op_pc; } uint32_t -ropPUSH_r32(UNUSED(codeblock_t *block), ir_data_t *ir, uint8_t opcode, uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropPUSH_r32(UNUSED(codeblock_t *block), ir_data_t *ir, uint8_t opcode, UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { int sp_reg; @@ -41,7 +41,7 @@ ropPUSH_r32(UNUSED(codeblock_t *block), ir_data_t *ir, uint8_t opcode, uint32_t } uint32_t -ropPOP_r16(UNUSED(codeblock_t *block), ir_data_t *ir, uint8_t opcode, uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropPOP_r16(UNUSED(codeblock_t *block), ir_data_t *ir, uint8_t opcode, UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uop_MOV_IMM(ir, IREG_oldpc, cpu_state.oldpc); @@ -57,7 +57,7 @@ ropPOP_r16(UNUSED(codeblock_t *block), ir_data_t *ir, uint8_t opcode, uint32_t f return op_pc; } uint32_t -ropPOP_r32(UNUSED(codeblock_t *block), ir_data_t *ir, uint8_t opcode, uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropPOP_r32(UNUSED(codeblock_t *block), ir_data_t *ir, uint8_t opcode, UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uop_MOV_IMM(ir, IREG_oldpc, cpu_state.oldpc); @@ -74,7 +74,7 @@ ropPOP_r32(UNUSED(codeblock_t *block), ir_data_t *ir, uint8_t opcode, uint32_t f } uint32_t -ropPUSH_imm_16(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropPUSH_imm_16(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uint16_t imm = fastreadw(cs + op_pc); int sp_reg; @@ -88,7 +88,7 @@ ropPUSH_imm_16(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32 return op_pc + 2; } uint32_t -ropPUSH_imm_32(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropPUSH_imm_32(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uint32_t imm = fastreadl(cs + op_pc); int sp_reg; @@ -103,7 +103,7 @@ ropPUSH_imm_32(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32 } uint32_t -ropPUSH_imm_16_8(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropPUSH_imm_16_8(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uint16_t imm = (int16_t) (int8_t) fastreadb(cs + op_pc); int sp_reg; @@ -117,7 +117,7 @@ ropPUSH_imm_16_8(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint return op_pc + 1; } uint32_t -ropPUSH_imm_32_8(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropPUSH_imm_32_8(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uint32_t imm = (int32_t) (int8_t) fastreadb(cs + op_pc); int sp_reg; @@ -197,7 +197,7 @@ ropPOP_L(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fet } #define ROP_PUSH_SEG(seg) \ - uint32_t ropPUSH_##seg##_16(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ + uint32_t ropPUSH_##seg##_16(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) \ { \ int sp_reg; \ \ @@ -208,7 +208,7 @@ ropPOP_L(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fet \ return op_pc; \ } \ - uint32_t ropPUSH_##seg##_32(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ + uint32_t ropPUSH_##seg##_32(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) \ { \ int sp_reg; \ \ @@ -222,7 +222,7 @@ ropPOP_L(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fet } #define ROP_POP_SEG(seg, rseg) \ - uint32_t ropPOP_##seg##_16(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ + uint32_t ropPOP_##seg##_16(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) \ { \ uop_MOV_IMM(ir, IREG_oldpc, cpu_state.oldpc); \ \ @@ -237,7 +237,7 @@ ropPOP_L(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fet \ return op_pc; \ } \ - uint32_t ropPOP_##seg##_32(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ + uint32_t ropPOP_##seg##_32(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) \ { \ uop_MOV_IMM(ir, IREG_oldpc, cpu_state.oldpc); \ \ @@ -253,6 +253,7 @@ ropPOP_L(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fet return op_pc; \ } +// clang-format off ROP_PUSH_SEG(CS) ROP_PUSH_SEG(DS) ROP_PUSH_SEG(ES) @@ -263,9 +264,10 @@ ROP_POP_SEG(DS, cpu_state.seg_ds) ROP_POP_SEG(ES, cpu_state.seg_es) ROP_POP_SEG(FS, cpu_state.seg_fs) ROP_POP_SEG(GS, cpu_state.seg_gs) +// clang-format on uint32_t -ropLEAVE_16(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropLEAVE_16(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uop_MOV_IMM(ir, IREG_oldpc, cpu_state.oldpc); @@ -281,7 +283,7 @@ ropLEAVE_16(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), u return op_pc; } uint32_t -ropLEAVE_32(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropLEAVE_32(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uop_MOV_IMM(ir, IREG_oldpc, cpu_state.oldpc); @@ -298,7 +300,7 @@ ropLEAVE_32(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), u } uint32_t -ropPUSHA_16(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropPUSHA_16(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { int sp_reg; @@ -317,7 +319,7 @@ ropPUSHA_16(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), u return op_pc; } uint32_t -ropPUSHA_32(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropPUSHA_32(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { int sp_reg; @@ -337,7 +339,7 @@ ropPUSHA_32(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), u } uint32_t -ropPOPA_16(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropPOPA_16(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { int sp_reg; @@ -355,7 +357,7 @@ ropPOPA_16(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), ui return op_pc; } uint32_t -ropPOPA_32(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropPOPA_32(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { int sp_reg; @@ -374,7 +376,7 @@ ropPOPA_32(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), ui } uint32_t -ropPUSHF(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropPUSHF(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { int sp_reg; @@ -390,7 +392,7 @@ ropPUSHF(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), uint return op_pc; } uint32_t -ropPUSHFD(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropPUSHFD(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { int sp_reg; diff --git a/src/config.c b/src/config.c index 24efcf264..c52ec48ad 100644 --- a/src/config.c +++ b/src/config.c @@ -8,20 +8,19 @@ * * Configuration file handler. * - * - * * Authors: Sarah Walker, * Miran Grca, * Fred N. van Kempen, * Overdoze, * David Hrdlička, + * Jasmine Iwanek, * * Copyright 2008-2019 Sarah Walker. * Copyright 2016-2019 Miran Grca. * Copyright 2017-2019 Fred N. van Kempen. * Copyright 2018-2019 David Hrdlička. * Copyright 2021 Andreas J. Reichel. - * Copyright 2021-2022 Jasmine Iwanek. + * Copyright 2021-2025 Jasmine Iwanek. * * NOTE: Forcing config files to be in Unicode encoding breaks * it on Windows XP, and possibly also Vista. Use the @@ -29,12 +28,13 @@ */ #include +#ifdef ENABLE_CONFIG_LOG #include +#endif #include #include #include #include -#include #define HAVE_STDARG_H #include <86box/86box.h> #include "cpu.h" @@ -53,10 +53,8 @@ #include <86box/hdc.h> #include <86box/hdc_ide.h> #include <86box/fdd.h> -#include <86box/fdc.h> #include <86box/fdc_ext.h> #include <86box/gameport.h> -#include <86box/serial.h> #include <86box/serial_passthrough.h> #include <86box/machine.h> #include <86box/mouse.h> @@ -300,7 +298,7 @@ load_machine(void) /* Only copy if a file with the new name doesn't already exist. */ FILE *g = nvr_fopen(new_fn, "rb"); - if (!g) { + if (g == NULL) { FILE *f = nvr_fopen(entry->d_name, "rb"); g = nvr_fopen(new_fn, "wb"); @@ -361,7 +359,7 @@ load_machine(void) while (!cpu_family_is_eligible(&cpu_families[c], machine)) { if (cpu_families[c++].package == 0) { /* End of list. */ - fatal("No eligible CPU families for the selected machine\n"); + fatal("Configuration: No eligible CPU families for the selected machine\n"); return; } } @@ -441,7 +439,6 @@ load_video(void) if (free_p) { free(p); p = NULL; - free_p = 0; } } @@ -527,23 +524,23 @@ load_input_devices(void) for (int js = 0; js < joystick_get_max_joysticks(joystick_type); js++) { sprintf(temp, "joystick_%i_nr", js); - joystick_state[js].plat_joystick_nr = ini_section_get_int(cat, temp, 0); + joystick_state[0][js].plat_joystick_nr = ini_section_get_int(cat, temp, 0); - if (joystick_state[js].plat_joystick_nr) { + if (joystick_state[0][js].plat_joystick_nr) { for (int axis_nr = 0; axis_nr < joystick_get_axis_count(joystick_type); axis_nr++) { sprintf(temp, "joystick_%i_axis_%i", js, axis_nr); - joystick_state[js].axis_mapping[axis_nr] = ini_section_get_int(cat, temp, axis_nr); + joystick_state[0][js].axis_mapping[axis_nr] = ini_section_get_int(cat, temp, axis_nr); } for (int button_nr = 0; button_nr < joystick_get_button_count(joystick_type); button_nr++) { sprintf(temp, "joystick_%i_button_%i", js, button_nr); - joystick_state[js].button_mapping[button_nr] = ini_section_get_int(cat, temp, button_nr); + joystick_state[0][js].button_mapping[button_nr] = ini_section_get_int(cat, temp, button_nr); } for (int pov_nr = 0; pov_nr < joystick_get_pov_count(joystick_type); pov_nr++) { sprintf(temp, "joystick_%i_pov_%i", js, pov_nr); p = ini_section_get_string(cat, temp, "0, 0"); - joystick_state[js].pov_mapping[pov_nr][0] = joystick_state[js].pov_mapping[pov_nr][1] = 0; - sscanf(p, "%i, %i", &joystick_state[js].pov_mapping[pov_nr][0], - &joystick_state[js].pov_mapping[pov_nr][1]); + joystick_state[0][js].pov_mapping[pov_nr][0] = joystick_state[0][js].pov_mapping[pov_nr][1] = 0; + sscanf(p, "%i, %i", &joystick_state[0][js].pov_mapping[pov_nr][0], + &joystick_state[0][js].pov_mapping[pov_nr][1]); } } } @@ -618,7 +615,7 @@ load_sound(void) memset(temp, '\0', sizeof(temp)); p = ini_section_get_string(cat, "sound_type", "float"); if (strlen(p) > 511) - fatal("load_sound(): strlen(p) > 511\n"); + fatal("Configuration: Length of sound_type is more than 511\n"); else strncpy(temp, p, 511); if (!strcmp(temp, "float") || !strcmp(temp, "1")) @@ -762,6 +759,28 @@ load_ports(void) p = ini_section_get_string(cat, temp, "none"); lpt_ports[c].device = lpt_device_get_from_internal_name(p); } + +#if 0 +// TODO: Load + for (c = 0; c < GAMEPORT_MAX; c++) { + sprintf(temp, "gameport%d_enabled", c + 1); + game_ports[c].enabled = !!ini_section_get_int(cat, temp, (c == 0) ? 1 : 0); + + sprintf(temp, "gameport%d_device", c + 1); + p = ini_section_get_string(cat, temp, "none"); + game_ports[c].device = gameport_get_from_internal_name(p); + } + + for (uint8_t c = 0; c < GAMEPORT_MAX; c++) { + sprintf(temp, "gameport%d_type", c); + + p = ini_section_get_string(cat, temp, "none"); + gameport_type[c] = gameport_get_from_internal_name(p); + + if (!strcmp(p, "none")) + ini_section_delete_var(cat, temp); + } +#endif } /* Load "Storage Controllers" section. */ @@ -847,7 +866,6 @@ load_storage_controllers(void) if (free_p) { free(p); p = NULL; - free_p = 0; } ide_ter_enabled = !!ini_section_get_int(cat, "ide_ter", 0); @@ -866,7 +884,7 @@ load_storage_controllers(void) if (p[0] != 0x00) { if (path_abs(p)) { if (strlen(p) > 511) - fatal("load_storage_controllers(): strlen(p) > 511 (cassette_fname)\n"); + fatal("Configuration: Length of cassette_file is more than 511\n"); else strncpy(cassette_fname, p, 511); } else @@ -876,7 +894,7 @@ load_storage_controllers(void) p = ini_section_get_string(cat, "cassette_mode", "load"); if (strlen(p) > 511) - fatal("load_storage_controllers(): strlen(p) > 511\n"); + fatal("Configuration: Length of cassette_mode is more than 511\n"); else strncpy(cassette_mode, p, 511); @@ -887,8 +905,8 @@ load_storage_controllers(void) if (p) { if (path_abs(p)) { if (strlen(p) > (MAX_IMAGE_PATH_LEN - 1)) - fatal("load_storage_controllers(): strlen(p) > 2047 " - "(cassette_image_history[%i])\n", i); + fatal("Configuration: Length of cassette_image_history_%02i is more " + "than %i\n", i + 1, MAX_IMAGE_PATH_LEN - 1); else snprintf(cassette_image_history[i], MAX_IMAGE_PATH_LEN, "%s", p); } else @@ -937,7 +955,8 @@ load_storage_controllers(void) if (p[0] != 0x00) { if (path_abs(p)) { if (strlen(p) > 511) - fatal("load_storage_controllers(): strlen(p) > 511 (cart_fns[%i])\n", c); + fatal("Configuration: Length of cartridge_%02i_fn is more than 511\n", + c + 1); else strncpy(cart_fns[c], p, 511); } else @@ -952,8 +971,8 @@ load_storage_controllers(void) if (p) { if (path_abs(p)) { if (strlen(p) > (MAX_IMAGE_PATH_LEN - 1)) - fatal("load_storage_controllers(): strlen(p) > 2047 " - "(cart_image_history[%i][%i])\n", c, i); + fatal("Configuration: Length of cartridge_%02i_image_history_%02i " + "is more than %i\n", c + 1, i + 1, MAX_IMAGE_PATH_LEN - 1); else snprintf(cart_image_history[c][i], MAX_IMAGE_PATH_LEN, "%s", p); } else @@ -992,8 +1011,8 @@ load_hard_disks(void) sscanf(p, "%u, %u, %u, %i, %s", &hdd[c].spt, &hdd[c].hpc, &hdd[c].tracks, (int *) &hdd[c].wp, s); - hdd[c].bus = hdd_string_to_bus(s, 0); - switch (hdd[c].bus) { + hdd[c].bus_type = hdd_string_to_bus(s, 0); + switch (hdd[c].bus_type) { default: case HDD_BUS_DISABLED: max_spt = max_hpc = max_tracks = 0; @@ -1039,7 +1058,7 @@ load_hard_disks(void) hdd[c].tracks = max_tracks; sprintf(temp, "hdd_%02i_speed", c + 1); - switch (hdd[c].bus) { + switch (hdd[c].bus_type) { case HDD_BUS_IDE: case HDD_BUS_ESDI: case HDD_BUS_ATAPI: @@ -1055,28 +1074,28 @@ load_hard_disks(void) /* MFM/RLL */ sprintf(temp, "hdd_%02i_mfm_channel", c + 1); - if (hdd[c].bus == HDD_BUS_MFM) + if (hdd[c].bus_type == HDD_BUS_MFM) hdd[c].mfm_channel = !!ini_section_get_int(cat, temp, c & 1); else ini_section_delete_var(cat, temp); /* XTA */ sprintf(temp, "hdd_%02i_xta_channel", c + 1); - if (hdd[c].bus == HDD_BUS_XTA) + if (hdd[c].bus_type == HDD_BUS_XTA) hdd[c].xta_channel = !!ini_section_get_int(cat, temp, c & 1); else ini_section_delete_var(cat, temp); /* ESDI */ sprintf(temp, "hdd_%02i_esdi_channel", c + 1); - if (hdd[c].bus == HDD_BUS_ESDI) + if (hdd[c].bus_type == HDD_BUS_ESDI) hdd[c].esdi_channel = !!ini_section_get_int(cat, temp, c & 1); else ini_section_delete_var(cat, temp); /* IDE */ sprintf(temp, "hdd_%02i_ide_channel", c + 1); - if ((hdd[c].bus == HDD_BUS_IDE) || (hdd[c].bus == HDD_BUS_ATAPI)) { + if ((hdd[c].bus_type == HDD_BUS_IDE) || (hdd[c].bus_type == HDD_BUS_ATAPI)) { sprintf(tmp2, "%01u:%01u", c >> 1, c & 1); p = ini_section_get_string(cat, temp, tmp2); sscanf(p, "%01u:%01u", &board, &dev); @@ -1090,7 +1109,7 @@ load_hard_disks(void) ini_section_delete_var(cat, temp); /* SCSI */ - if (hdd[c].bus == HDD_BUS_SCSI) { + if (hdd[c].bus_type == HDD_BUS_SCSI) { sprintf(temp, "hdd_%02i_scsi_location", c + 1); sprintf(tmp2, "%01u:%02u", SCSI_BUS_MAX, c + 2); p = ini_section_get_string(cat, temp, tmp2); @@ -1130,7 +1149,8 @@ load_hard_disks(void) if (p[0] != 0x00) { if (path_abs(p)) { if (strlen(p) > 511) - fatal("load_hard_disks(): strlen(p) > 511 (hdd[%i].fn)\n", c); + fatal("Configuration: Length of hdd_%02i_fn is more " + "than 511\n", c + 1); else strncpy(hdd[c].fn, p, 511); } else @@ -1179,12 +1199,12 @@ load_floppy_and_cdrom_drives(void) char temp[512]; char tmp2[512]; char *p; - char *def_type; char s[512]; unsigned int board = 0; unsigned int dev = 0; int c; int d = 0; + int count = cdrom_get_type_count(); memset(temp, 0x00, sizeof(temp)); for (c = 0; c < FDD_NUM; c++) { @@ -1203,7 +1223,7 @@ load_floppy_and_cdrom_drives(void) if (p[0] != 0x00) { if (path_abs(p)) { if (strlen(p) > 511) - fatal("load_floppy_and_cdrom_drives(): strlen(p) > 511 (floppyfns[%i])\n", c); + fatal("Configuration: Length of fdd_%02i_fn is more than 511\n", c + 1); else strncpy(floppyfns[c], p, 511); } else @@ -1251,8 +1271,8 @@ load_floppy_and_cdrom_drives(void) if (p) { if (path_abs(p)) { if (strlen(p) > (MAX_IMAGE_PATH_LEN - 1)) - fatal("load_floppy_and_cdrom_drives(): strlen(p) > 2047 " - "(fdd_image_history[%i][%i])\n", c, i); + fatal("Configuration: Length of fdd_%02i_image_history_%02i is more " + "than %i\n", c + 1, i + 1, MAX_IMAGE_PATH_LEN - 1); else snprintf(fdd_image_history[c][i], MAX_IMAGE_PATH_LEN, "%s", p); } else @@ -1284,12 +1304,20 @@ load_floppy_and_cdrom_drives(void) cdrom[c].speed = ini_section_get_int(cat, temp, 8); sprintf(temp, "cdrom_%02i_type", c + 1); - def_type = (c == 1) ? "86BOX_CD-ROM_1.00" : "none"; - p = ini_section_get_string(cat, temp, def_type); - cdrom_set_type(c, cdrom_get_from_internal_name(p)); - if (cdrom_get_type(c) > KNOWN_CDROM_DRIVE_TYPES) - cdrom_set_type(c, KNOWN_CDROM_DRIVE_TYPES); - if (!strcmp(p, def_type)) + p = ini_section_get_string(cat, temp, "86cd"); + /* TODO: Configuration migration, remove when no longer needed. */ + int cdrom_type = cdrom_get_from_internal_name(p); + if (cdrom_type == -1) { + cdrom_type = cdrom_get_from_name(p); + if (cdrom_type == -1) + cdrom_set_type(c, cdrom_get_from_internal_name("86cd")); + else + cdrom_set_type(c, cdrom_type); + } else + cdrom_set_type(c, cdrom_type); + if (cdrom_get_type(c) >= count) + cdrom_set_type(c, count - 1); + if (!strcmp(p, "86cd")) ini_section_delete_var(cat, temp); /* Default values, needed for proper operation of the Settings dialog. */ @@ -1347,7 +1375,7 @@ load_floppy_and_cdrom_drives(void) if (p[0] != 0x00) { if (path_abs(p)) { if (strlen(p) > 511) - fatal("load_floppy_and_cdrom_drives(): strlen(p) > 511 (cdrom[%i].image_path)\n", c); + fatal("Configuration: Length of cdrom_%02i_image_path is more than 511\n", c + 1); else strncpy(cdrom[c].image_path, p, 511); } else @@ -1362,8 +1390,8 @@ load_floppy_and_cdrom_drives(void) if (p) { if (path_abs(p)) { if (strlen(p) > (MAX_IMAGE_PATH_LEN - 1)) - fatal("load_floppy_and_cdrom_drives(): strlen(p) > 2047 " - "(cdrom[%i].image_history[%i])\n", c, i); + fatal("Configuration: Length of cdrom_%02i_image_history_%02i is more " + "than %i\n", c + 1, i + 1, MAX_IMAGE_PATH_LEN - 1); else snprintf(cdrom[c].image_history[i], MAX_IMAGE_PATH_LEN, "%s", p); } else @@ -1378,6 +1406,12 @@ load_floppy_and_cdrom_drives(void) sprintf(temp, "cdrom_%02i_parameters", c + 1); ini_section_delete_var(cat, temp); + sprintf(temp, "cdrom_%02i_speed", c + 1); + ini_section_delete_var(cat, temp); + + sprintf(temp, "cdrom_%02i_type", c + 1); + ini_section_delete_var(cat, temp); + sprintf(temp, "cdrom_%02i_ide_channel", c + 1); ini_section_delete_var(cat, temp); @@ -1476,8 +1510,7 @@ load_other_removable_devices(void) if (p[0] != 0x00) { if (path_abs(p)) { if (strlen(p) > 511) - fatal("load_other_removable_devices(): strlen(p) > 511 (zip_drives[%i].image_path)\n", - c); + fatal("Configuration: Length of zip_%02i_image_path is more than 511\n", c + 1); else strncpy(zip_drives[c].image_path, p, 511); } else @@ -1492,8 +1525,8 @@ load_other_removable_devices(void) if (p) { if (path_abs(p)) { if (strlen(p) > (MAX_IMAGE_PATH_LEN - 1)) - fatal("load_other_removable_devices(): strlen(p) > 2047 " - "(zip_drives[%i].image_history[%i])\n", c, i); + fatal("Configuration: Length of zip_%02i_image_history_%02i is more than %i\n", + c + 1, i + 1, MAX_IMAGE_PATH_LEN - 1); else snprintf(zip_drives[c].image_history[i], MAX_IMAGE_PATH_LEN, "%s", p); } else @@ -1589,8 +1622,7 @@ load_other_removable_devices(void) if (p[0] != 0x00) { if (path_abs(p)) { if (strlen(p) > 511) - fatal("load_other_removable_devices(): strlen(p) > 511 (mo_drives[%i].image_path)\n", - c); + fatal("Configuration: Length of mo_%02i_image_path is more than 511\n", c + 1); else strncpy(mo_drives[c].image_path, p, 511); } else @@ -1605,8 +1637,8 @@ load_other_removable_devices(void) if (p) { if (path_abs(p)) { if (strlen(p) > (MAX_IMAGE_PATH_LEN - 1)) - fatal("load_other_removable_devices(): strlen(p) > 2047 " - "(mo_drives[%i].image_history[%i])\n", c, i); + fatal("Configuration: Length of mo_%02i_image_history_%02i is more than %i\n", + c + 1, i + 1, MAX_IMAGE_PATH_LEN - 1); else snprintf(mo_drives[c].image_history[i], MAX_IMAGE_PATH_LEN, "%s", p); } else @@ -1698,7 +1730,7 @@ config_load(void) config = ini_read(cfg_path); - if (!config) { + if (config == NULL) { config = ini_new(); config_changed = 1; @@ -2163,21 +2195,21 @@ save_input_devices(void) for (int js = 0; js < joystick_get_max_joysticks(joystick_type); js++) { sprintf(tmp2, "joystick_%i_nr", js); - ini_section_set_int(cat, tmp2, joystick_state[js].plat_joystick_nr); + ini_section_set_int(cat, tmp2, joystick_state[0][js].plat_joystick_nr); - if (joystick_state[js].plat_joystick_nr) { + if (joystick_state[0][js].plat_joystick_nr) { for (int axis_nr = 0; axis_nr < joystick_get_axis_count(joystick_type); axis_nr++) { sprintf(tmp2, "joystick_%i_axis_%i", js, axis_nr); - ini_section_set_int(cat, tmp2, joystick_state[js].axis_mapping[axis_nr]); + ini_section_set_int(cat, tmp2, joystick_state[0][js].axis_mapping[axis_nr]); } for (int button_nr = 0; button_nr < joystick_get_button_count(joystick_type); button_nr++) { sprintf(tmp2, "joystick_%i_button_%i", js, button_nr); - ini_section_set_int(cat, tmp2, joystick_state[js].button_mapping[button_nr]); + ini_section_set_int(cat, tmp2, joystick_state[0][js].button_mapping[button_nr]); } for (int pov_nr = 0; pov_nr < joystick_get_pov_count(joystick_type); pov_nr++) { sprintf(tmp2, "joystick_%i_pov_%i", js, pov_nr); - sprintf(temp, "%i, %i", joystick_state[js].pov_mapping[pov_nr][0], - joystick_state[js].pov_mapping[pov_nr][1]); + sprintf(temp, "%i, %i", joystick_state[0][js].pov_mapping[pov_nr][0], + joystick_state[0][js].pov_mapping[pov_nr][1]); ini_section_set_string(cat, tmp2, temp); } } @@ -2366,6 +2398,34 @@ save_ports(void) lpt_device_get_internal_name(lpt_ports[c].device)); } +#if 0 +// TODO: Save + for (c = 0; c < GAMEPORT_MAX; c++) { + sprintf(temp, "gameport%d_enabled", c + 1); + d = (c == 0) ? 1 : 0; + if (game_ports[c].enabled == d) + ini_section_delete_var(cat, temp); + else + ini_section_set_int(cat, temp, game_ports[c].enabled); + + sprintf(temp, "gameport%d_device", c + 1); + if (game_ports[c].device == 0) + ini_section_delete_var(cat, temp); + else + ini_section_set_string(cat, temp, + gameport_get_internal_name(game_ports[c].device)); + } + + for (uint8_t c = 0; c < GAMEPORT_MAX; c++) { + sprintf(temp, "gameport%d_enabled", c); + if (gameport_type[c] == 0) + ini_section_delete_var(cat, temp); + else + ini_section_set_string(cat, temp, + gameport_get_internal_name(gameport_type[c])); + } +#endif + ini_delete_section_if_empty(config, cat); } @@ -2574,7 +2634,7 @@ save_hard_disks(void) for (uint8_t c = 0; c < HDD_NUM; c++) { sprintf(temp, "hdd_%02i_parameters", c + 1); if (hdd_is_valid(c)) { - p = hdd_bus_to_string(hdd[c].bus, 0); + p = hdd_bus_to_string(hdd[c].bus_type, 0); sprintf(tmp2, "%u, %u, %u, %i, %s", hdd[c].spt, hdd[c].hpc, hdd[c].tracks, hdd[c].wp, p); ini_section_set_string(cat, temp, tmp2); @@ -2582,25 +2642,26 @@ save_hard_disks(void) ini_section_delete_var(cat, temp); sprintf(temp, "hdd_%02i_mfm_channel", c + 1); - if (hdd_is_valid(c) && (hdd[c].bus == HDD_BUS_MFM)) + if (hdd_is_valid(c) && (hdd[c].bus_type == HDD_BUS_MFM)) ini_section_set_int(cat, temp, hdd[c].mfm_channel); else ini_section_delete_var(cat, temp); sprintf(temp, "hdd_%02i_xta_channel", c + 1); - if (hdd_is_valid(c) && (hdd[c].bus == HDD_BUS_XTA)) + if (hdd_is_valid(c) && (hdd[c].bus_type == HDD_BUS_XTA)) ini_section_set_int(cat, temp, hdd[c].xta_channel); else ini_section_delete_var(cat, temp); sprintf(temp, "hdd_%02i_esdi_channel", c + 1); - if (hdd_is_valid(c) && (hdd[c].bus == HDD_BUS_ESDI)) + if (hdd_is_valid(c) && (hdd[c].bus_type == HDD_BUS_ESDI)) ini_section_set_int(cat, temp, hdd[c].esdi_channel); else ini_section_delete_var(cat, temp); sprintf(temp, "hdd_%02i_ide_channel", c + 1); - if (!hdd_is_valid(c) || ((hdd[c].bus != HDD_BUS_IDE) && (hdd[c].bus != HDD_BUS_ATAPI))) + if (!hdd_is_valid(c) || ((hdd[c].bus_type != HDD_BUS_IDE) && + (hdd[c].bus_type != HDD_BUS_ATAPI))) ini_section_delete_var(cat, temp); else { sprintf(tmp2, "%01u:%01u", hdd[c].ide_channel >> 1, hdd[c].ide_channel & 1); @@ -2611,7 +2672,7 @@ save_hard_disks(void) ini_section_delete_var(cat, temp); sprintf(temp, "hdd_%02i_scsi_location", c + 1); - if (hdd[c].bus != HDD_BUS_SCSI) + if (hdd[c].bus_type != HDD_BUS_SCSI) ini_section_delete_var(cat, temp); else { sprintf(tmp2, "%01u:%02u", hdd[c].scsi_id >> 4, @@ -2643,8 +2704,9 @@ save_hard_disks(void) ini_section_delete_var(cat, temp); sprintf(temp, "hdd_%02i_speed", c + 1); - if (!hdd_is_valid(c) || ((hdd[c].bus != HDD_BUS_ESDI) && (hdd[c].bus != HDD_BUS_IDE) && - (hdd[c].bus != HDD_BUS_SCSI) && (hdd[c].bus != HDD_BUS_ATAPI))) + if (!hdd_is_valid(c) || + ((hdd[c].bus_type != HDD_BUS_ESDI) && (hdd[c].bus_type != HDD_BUS_IDE) && + (hdd[c].bus_type != HDD_BUS_SCSI) && (hdd[c].bus_type != HDD_BUS_ATAPI))) ini_section_delete_var(cat, temp); else ini_section_set_string(cat, temp, hdd_preset_get_internal_name(hdd[c].speed_preset)); @@ -2729,11 +2791,12 @@ save_floppy_and_cdrom_drives(void) ini_section_set_int(cat, temp, cdrom[c].speed); sprintf(temp, "cdrom_%02i_type", c + 1); - if ((cdrom[c].bus_type == 0) || (cdrom[c].bus_type == CDROM_BUS_MITSUMI)) + char *tn = cdrom_get_internal_name(cdrom_get_type(c)); + if ((cdrom[c].bus_type == 0) || (cdrom[c].bus_type == CDROM_BUS_MITSUMI) || + !strcmp(tn, "86cd")) ini_section_delete_var(cat, temp); else - ini_section_set_string(cat, temp, - cdrom_get_internal_name(cdrom_get_type(c))); + ini_section_set_string(cat, temp, tn); sprintf(temp, "cdrom_%02i_parameters", c + 1); if (cdrom[c].bus_type == 0) diff --git a/src/cpu/386.c b/src/cpu/386.c index 21db155e9..caa5f84a2 100644 --- a/src/cpu/386.c +++ b/src/cpu/386.c @@ -27,6 +27,7 @@ #include <86box/fdc.h> #include <86box/machine.h> #include <86box/plat_fallthrough.h> +#include <86box/plat_unused.h> #include <86box/gdbstub.h> #ifndef OPS_286_386 # define OPS_286_386 diff --git a/src/cpu/386_common.c b/src/cpu/386_common.c index a68d866bf..8a2bb4ab8 100644 --- a/src/cpu/386_common.c +++ b/src/cpu/386_common.c @@ -1825,7 +1825,7 @@ cpu_386_check_instruction_fault(void) } int -sysenter(uint32_t fetchdat) +sysenter(UNUSED(uint32_t fetchdat)) { #ifdef ENABLE_386_COMMON_LOG x386_common_log("SYSENTER called\n"); @@ -1907,7 +1907,7 @@ sysenter(uint32_t fetchdat) } int -sysexit(uint32_t fetchdat) +sysexit(UNUSED(uint32_t fetchdat)) { #ifdef ENABLE_386_COMMON_LOG x386_common_log("SYSEXIT called\n"); @@ -1994,7 +1994,7 @@ sysexit(uint32_t fetchdat) } int -syscall_op(uint32_t fetchdat) +syscall_op(UNUSED(uint32_t fetchdat)) { #ifdef ENABLE_386_COMMON_LOG x386_common_log("SYSCALL called\n"); @@ -2046,7 +2046,7 @@ syscall_op(uint32_t fetchdat) } int -sysret(uint32_t fetchdat) +sysret(UNUSED(uint32_t fetchdat)) { #ifdef ENABLE_386_COMMON_LOG x386_common_log("SYSRET called\n"); diff --git a/src/cpu/386_dynarec.c b/src/cpu/386_dynarec.c index c4c095735..5f41c416a 100644 --- a/src/cpu/386_dynarec.c +++ b/src/cpu/386_dynarec.c @@ -30,6 +30,7 @@ #include <86box/fdc.h> #include <86box/machine.h> #include <86box/plat_fallthrough.h> +#include <86box/plat_unused.h> #include <86box/gdbstub.h> #ifdef USE_DYNAREC # include "codegen.h" diff --git a/src/cpu/808x.c b/src/cpu/808x.c index f37672a5c..a74cf84ab 100644 --- a/src/cpu/808x.c +++ b/src/cpu/808x.c @@ -35,6 +35,7 @@ #include <86box/ppi.h> #include <86box/timer.h> #include <86box/gdbstub.h> +#include <86box/plat_unused.h> /* Is the CPU 8088 or 8086. */ int is8086 = 0; @@ -815,7 +816,7 @@ pop(void) } static void -access(int num, int bits) +access(int num, UNUSED(int bits)) { switch (num) { case 0: @@ -1419,7 +1420,7 @@ set_pzs(int bits) } static void -set_co_mul(int bits, int carry) +set_co_mul(UNUSED(int bits), int carry) { set_cf(carry); set_of(carry); diff --git a/src/cpu/codegen_timing_486.c b/src/cpu/codegen_timing_486.c index 90d682211..d8f05cfd3 100644 --- a/src/cpu/codegen_timing_486.c +++ b/src/cpu/codegen_timing_486.c @@ -328,7 +328,7 @@ codegen_timing_486_start(void) } void -codegen_timing_486_prefix(uint8_t prefix, uint32_t fetchdat) +codegen_timing_486_prefix(uint8_t prefix, UNUSED(uint32_t fetchdat)) { timing_count += COUNT(opcode_timings_486[prefix], 0); last_prefix = prefix; diff --git a/src/cpu/codegen_timing_k5.c b/src/cpu/codegen_timing_k5.c index 42b1129fe..8ce2f4cea 100644 --- a/src/cpu/codegen_timing_k5.c +++ b/src/cpu/codegen_timing_k5.c @@ -8,6 +8,7 @@ #include <86box/mem.h> #include "cpu.h" #include <86box/machine.h> +#include <86box/plat_unused.h> #include "x86.h" #include "x86_ops.h" @@ -2037,7 +2038,7 @@ codegen_timing_k5_start(void) } void -codegen_timing_k5_prefix(uint8_t prefix, uint32_t fetchdat) +codegen_timing_k5_prefix(uint8_t prefix, UNUSED(uint32_t fetchdat)) { if (prefix != 0x0f) decode_timestamp++; @@ -2047,7 +2048,7 @@ codegen_timing_k5_prefix(uint8_t prefix, uint32_t fetchdat) } void -codegen_timing_k5_opcode(uint8_t opcode, uint32_t fetchdat, int op_32, uint32_t op_pc) +codegen_timing_k5_opcode(uint8_t opcode, UNUSED(uint32_t fetchdat), int op_32, uint32_t op_pc) { const risc86_instruction_t **ins_table; const uint64_t *deps; diff --git a/src/cpu/codegen_timing_k6.c b/src/cpu/codegen_timing_k6.c index 5566fbbcd..34297211b 100644 --- a/src/cpu/codegen_timing_k6.c +++ b/src/cpu/codegen_timing_k6.c @@ -8,6 +8,7 @@ #include <86box/mem.h> #include "cpu.h" #include <86box/machine.h> +#include <86box/plat_unused.h> #include "x86.h" #include "x86_ops.h" @@ -2037,7 +2038,7 @@ codegen_timing_k6_start(void) } void -codegen_timing_k6_prefix(uint8_t prefix, uint32_t fetchdat) +codegen_timing_k6_prefix(uint8_t prefix, UNUSED(uint32_t fetchdat)) { if (prefix != 0x0f) decode_timestamp++; @@ -2047,7 +2048,7 @@ codegen_timing_k6_prefix(uint8_t prefix, uint32_t fetchdat) } void -codegen_timing_k6_opcode(uint8_t opcode, uint32_t fetchdat, int op_32, uint32_t op_pc) +codegen_timing_k6_opcode(uint8_t opcode, UNUSED(uint32_t fetchdat), int op_32, uint32_t op_pc) { const risc86_instruction_t **ins_table; const uint64_t *deps; diff --git a/src/cpu/codegen_timing_p6.c b/src/cpu/codegen_timing_p6.c index a22813068..42db319c3 100644 --- a/src/cpu/codegen_timing_p6.c +++ b/src/cpu/codegen_timing_p6.c @@ -1845,7 +1845,7 @@ codegen_timing_p6_start(void) } void -codegen_timing_p6_prefix(uint8_t prefix, uint32_t fetchdat) +codegen_timing_p6_prefix(uint8_t prefix, UNUSED(uint32_t fetchdat)) { if (prefix != 0x0f) decode_timestamp++; @@ -1855,7 +1855,7 @@ codegen_timing_p6_prefix(uint8_t prefix, uint32_t fetchdat) } void -codegen_timing_p6_opcode(uint8_t opcode, uint32_t fetchdat, int op_32, UNUSED(uint32_t op_pc)) +codegen_timing_p6_opcode(uint8_t opcode, UNUSED(uint32_t fetchdat), int op_32, UNUSED(uint32_t op_pc)) { const macro_op_t **ins_table; const uint64_t *deps; diff --git a/src/cpu/codegen_timing_winchip.c b/src/cpu/codegen_timing_winchip.c index 3597517ce..0d39f4151 100644 --- a/src/cpu/codegen_timing_winchip.c +++ b/src/cpu/codegen_timing_winchip.c @@ -328,7 +328,7 @@ codegen_timing_winchip_start(void) } void -codegen_timing_winchip_prefix(uint8_t prefix, uint32_t fetchdat) +codegen_timing_winchip_prefix(uint8_t prefix, UNUSED(uint32_t fetchdat)) { timing_count += COUNT(opcode_timings_winchip[prefix], 0); last_prefix = prefix; diff --git a/src/cpu/codegen_timing_winchip2.c b/src/cpu/codegen_timing_winchip2.c index f37fe3366..696a059cf 100644 --- a/src/cpu/codegen_timing_winchip2.c +++ b/src/cpu/codegen_timing_winchip2.c @@ -589,7 +589,7 @@ codegen_timing_winchip2_start(void) } static void -codegen_timing_winchip2_prefix(uint8_t prefix, uint32_t fetchdat) +codegen_timing_winchip2_prefix(uint8_t prefix, UNUSED(uint32_t fetchdat)) { if (prefix == 0x0f) { /*0fh prefix is 'free'*/ diff --git a/src/cpu/x86_ops_3dnow.h b/src/cpu/x86_ops_3dnow.h index b72cbc06c..2b4ed1a6d 100644 --- a/src/cpu/x86_ops_3dnow.h +++ b/src/cpu/x86_ops_3dnow.h @@ -20,7 +20,7 @@ opPREFETCH_a32(uint32_t fetchdat) } static int -opFEMMS(uint32_t fetchdat) +opFEMMS(UNUSED(uint32_t fetchdat)) { ILLEGAL_ON(!cpu_has_feature(CPU_FEATURE_MMX)); if (cr0 & 0xc) { @@ -33,7 +33,7 @@ opFEMMS(uint32_t fetchdat) } static int -opPAVGUSB(uint32_t fetchdat) +opPAVGUSB(UNUSED(uint32_t fetchdat)) { MMX_REG src; MMX_REG *dst = MMX_GETREGP(cpu_reg); @@ -54,7 +54,7 @@ opPAVGUSB(uint32_t fetchdat) return 0; } static int -opPF2ID(uint32_t fetchdat) +opPF2ID(UNUSED(uint32_t fetchdat)) { MMX_REG src; MMX_REG *dst = MMX_GETREGP(cpu_reg); @@ -69,7 +69,7 @@ opPF2ID(uint32_t fetchdat) return 0; } static int -opPF2IW(uint32_t fetchdat) +opPF2IW(UNUSED(uint32_t fetchdat)) { MMX_REG src; MMX_REG *dst = MMX_GETREGP(cpu_reg); @@ -84,7 +84,7 @@ opPF2IW(uint32_t fetchdat) return 0; } static int -opPFACC(uint32_t fetchdat) +opPFACC(UNUSED(uint32_t fetchdat)) { MMX_REG src; MMX_REG *dst = MMX_GETREGP(cpu_reg); @@ -101,7 +101,7 @@ opPFACC(uint32_t fetchdat) return 0; } static int -opPFNACC(uint32_t fetchdat) +opPFNACC(UNUSED(uint32_t fetchdat)) { MMX_REG src; MMX_REG *dst = MMX_GETREGP(cpu_reg); @@ -118,7 +118,7 @@ opPFNACC(uint32_t fetchdat) return 0; } static int -opPFPNACC(uint32_t fetchdat) +opPFPNACC(UNUSED(uint32_t fetchdat)) { MMX_REG src; MMX_REG *dst = MMX_GETREGP(cpu_reg); @@ -135,7 +135,7 @@ opPFPNACC(uint32_t fetchdat) return 0; } static int -opPSWAPD(uint32_t fetchdat) +opPSWAPD(UNUSED(uint32_t fetchdat)) { MMX_REG src; MMX_REG *dst = MMX_GETREGP(cpu_reg); @@ -155,7 +155,7 @@ opPSWAPD(uint32_t fetchdat) return 0; } static int -opPFADD(uint32_t fetchdat) +opPFADD(UNUSED(uint32_t fetchdat)) { MMX_REG src; MMX_REG *dst = MMX_GETREGP(cpu_reg); @@ -170,7 +170,7 @@ opPFADD(uint32_t fetchdat) return 0; } static int -opPFCMPEQ(uint32_t fetchdat) +opPFCMPEQ(UNUSED(uint32_t fetchdat)) { MMX_REG src; MMX_REG *dst = MMX_GETREGP(cpu_reg); @@ -185,7 +185,7 @@ opPFCMPEQ(uint32_t fetchdat) return 0; } static int -opPFCMPGE(uint32_t fetchdat) +opPFCMPGE(UNUSED(uint32_t fetchdat)) { MMX_REG src; MMX_REG *dst = MMX_GETREGP(cpu_reg); @@ -200,7 +200,7 @@ opPFCMPGE(uint32_t fetchdat) return 0; } static int -opPFCMPGT(uint32_t fetchdat) +opPFCMPGT(UNUSED(uint32_t fetchdat)) { MMX_REG src; MMX_REG *dst = MMX_GETREGP(cpu_reg); @@ -215,7 +215,7 @@ opPFCMPGT(uint32_t fetchdat) return 0; } static int -opPFMAX(uint32_t fetchdat) +opPFMAX(UNUSED(uint32_t fetchdat)) { MMX_REG src; MMX_REG *dst = MMX_GETREGP(cpu_reg); @@ -232,7 +232,7 @@ opPFMAX(uint32_t fetchdat) return 0; } static int -opPFMIN(uint32_t fetchdat) +opPFMIN(UNUSED(uint32_t fetchdat)) { MMX_REG src; MMX_REG *dst = MMX_GETREGP(cpu_reg); @@ -249,7 +249,7 @@ opPFMIN(uint32_t fetchdat) return 0; } static int -opPFMUL(uint32_t fetchdat) +opPFMUL(UNUSED(uint32_t fetchdat)) { MMX_REG src; MMX_REG *dst = MMX_GETREGP(cpu_reg); @@ -264,7 +264,7 @@ opPFMUL(uint32_t fetchdat) return 0; } static int -opPFRCP(uint32_t fetchdat) +opPFRCP(UNUSED(uint32_t fetchdat)) { MMX_REG *dst = MMX_GETREGP(cpu_reg); @@ -293,7 +293,7 @@ opPFRCP(uint32_t fetchdat) } /*Since opPFRCP() calculates a full precision reciprocal, treat the followup iterations as MOVs*/ static int -opPFRCPIT1(uint32_t fetchdat) +opPFRCPIT1(UNUSED(uint32_t fetchdat)) { MMX_REG src; MMX_REG *dst = MMX_GETREGP(cpu_reg); @@ -308,7 +308,7 @@ opPFRCPIT1(uint32_t fetchdat) return 0; } static int -opPFRCPIT2(uint32_t fetchdat) +opPFRCPIT2(UNUSED(uint32_t fetchdat)) { MMX_REG src; MMX_REG *dst = MMX_GETREGP(cpu_reg); @@ -323,7 +323,7 @@ opPFRCPIT2(uint32_t fetchdat) return 0; } static int -opPFRSQRT(uint32_t fetchdat) +opPFRSQRT(UNUSED(uint32_t fetchdat)) { MMX_REG *dst = MMX_GETREGP(cpu_reg); @@ -352,7 +352,7 @@ opPFRSQRT(uint32_t fetchdat) } /*Since opPFRSQRT() calculates a full precision inverse square root, treat the followup iteration as a NOP*/ static int -opPFRSQIT1(uint32_t fetchdat) +opPFRSQIT1(UNUSED(uint32_t fetchdat)) { MMX_REG src; @@ -362,7 +362,7 @@ opPFRSQIT1(uint32_t fetchdat) return 0; } static int -opPFSUB(uint32_t fetchdat) +opPFSUB(UNUSED(uint32_t fetchdat)) { MMX_REG src; MMX_REG *dst = MMX_GETREGP(cpu_reg); @@ -377,7 +377,7 @@ opPFSUB(uint32_t fetchdat) return 0; } static int -opPFSUBR(uint32_t fetchdat) +opPFSUBR(UNUSED(uint32_t fetchdat)) { MMX_REG src; MMX_REG *dst = MMX_GETREGP(cpu_reg); @@ -392,7 +392,7 @@ opPFSUBR(uint32_t fetchdat) return 0; } static int -opPI2FD(uint32_t fetchdat) +opPI2FD(UNUSED(uint32_t fetchdat)) { MMX_REG src; MMX_REG *dst = MMX_GETREGP(cpu_reg); @@ -407,7 +407,7 @@ opPI2FD(uint32_t fetchdat) return 0; } static int -opPI2FW(uint32_t fetchdat) +opPI2FW(UNUSED(uint32_t fetchdat)) { MMX_REG src; MMX_REG *dst = MMX_GETREGP(cpu_reg); @@ -422,7 +422,7 @@ opPI2FW(uint32_t fetchdat) return 0; } static int -opPMULHRW(uint32_t fetchdat) +opPMULHRW(UNUSED(uint32_t fetchdat)) { MMX_REG src; MMX_REG *dst = MMX_GETREGP(cpu_reg); diff --git a/src/cpu/x86_ops_arith.h b/src/cpu/x86_ops_arith.h index 4e3f74e36..0764877a4 100644 --- a/src/cpu/x86_ops_arith.h +++ b/src/cpu/x86_ops_arith.h @@ -313,7 +313,7 @@ return 0; \ } \ \ - static int op##name##_EAX_imm(uint32_t fetchdat) \ + static int op##name##_EAX_imm(UNUSED(uint32_t fetchdat)) \ { \ uint32_t dst = EAX; \ uint32_t src = getlong(); \ @@ -581,7 +581,7 @@ opCMP_AX_imm(uint32_t fetchdat) } static int -opCMP_EAX_imm(uint32_t fetchdat) +opCMP_EAX_imm(UNUSED(uint32_t fetchdat)) { uint32_t src = getlong(); @@ -747,7 +747,7 @@ opTEST_AX(uint32_t fetchdat) return 0; } static int -opTEST_EAX(uint32_t fetchdat) +opTEST_EAX(UNUSED(uint32_t fetchdat)) { uint32_t temp = getlong(); if (cpu_state.abrt) diff --git a/src/cpu/x86_ops_bcd.h b/src/cpu/x86_ops_bcd.h index a04dea65a..a0d18875d 100644 --- a/src/cpu/x86_ops_bcd.h +++ b/src/cpu/x86_ops_bcd.h @@ -1,5 +1,5 @@ static int -opAAA(uint32_t fetchdat) +opAAA(UNUSED(uint32_t fetchdat)) { flags_rebuild(); if ((cpu_state.flags & A_FLAG) || ((AL & 0xF) > 9)) { @@ -46,7 +46,7 @@ opAAM(uint32_t fetchdat) } static int -opAAS(uint32_t fetchdat) +opAAS(UNUSED(uint32_t fetchdat)) { flags_rebuild(); if ((cpu_state.flags & A_FLAG) || ((AL & 0xF) > 9)) { @@ -63,7 +63,7 @@ opAAS(uint32_t fetchdat) } static int -opDAA(uint32_t fetchdat) +opDAA(UNUSED(uint32_t fetchdat)) { uint16_t tempw; uint16_t old_AL; @@ -100,7 +100,7 @@ opDAA(uint32_t fetchdat) } static int -opDAS(uint32_t fetchdat) +opDAS(UNUSED(uint32_t fetchdat)) { uint16_t tempw; uint16_t old_AL; diff --git a/src/cpu/x86_ops_call.h b/src/cpu/x86_ops_call.h index 9d52a2764..ee54dceff 100644 --- a/src/cpu/x86_ops_call.h +++ b/src/cpu/x86_ops_call.h @@ -209,7 +209,7 @@ opCALL_far_w(uint32_t fetchdat) return 0; } static int -opCALL_far_l(uint32_t fetchdat) +opCALL_far_l(UNUSED(uint32_t fetchdat)) { uint32_t old_cs; uint32_t old_pc; diff --git a/src/cpu/x86_ops_cyrix.h b/src/cpu/x86_ops_cyrix.h index 672ebd08e..8c3d6e155 100644 --- a/src/cpu/x86_ops_cyrix.h +++ b/src/cpu/x86_ops_cyrix.h @@ -212,7 +212,7 @@ opRSTS_a32(uint32_t fetchdat) } static int -opSMINT(uint32_t fetchdat) +opSMINT(UNUSED(uint32_t fetchdat)) { if (in_smm) fatal("opSMINT\n"); @@ -223,7 +223,7 @@ opSMINT(uint32_t fetchdat) } static int -opRDSHR_a16(uint32_t fetchdat) +opRDSHR_a16(UNUSED(uint32_t fetchdat)) { if (in_smm) fatal("opRDSHR_a16\n"); @@ -233,7 +233,7 @@ opRDSHR_a16(uint32_t fetchdat) return 1; } static int -opRDSHR_a32(uint32_t fetchdat) +opRDSHR_a32(UNUSED(uint32_t fetchdat)) { if (in_smm) fatal("opRDSHR_a32\n"); @@ -244,7 +244,7 @@ opRDSHR_a32(uint32_t fetchdat) } static int -opWRSHR_a16(uint32_t fetchdat) +opWRSHR_a16(UNUSED(uint32_t fetchdat)) { if (in_smm) fatal("opWRSHR_a16\n"); @@ -254,7 +254,7 @@ opWRSHR_a16(uint32_t fetchdat) return 1; } static int -opWRSHR_a32(uint32_t fetchdat) +opWRSHR_a32(UNUSED(uint32_t fetchdat)) { if (in_smm) fatal("opWRSHR_a32\n"); diff --git a/src/cpu/x86_ops_flag.h b/src/cpu/x86_ops_flag.h index 019472aa0..a0fa612a8 100644 --- a/src/cpu/x86_ops_flag.h +++ b/src/cpu/x86_ops_flag.h @@ -1,5 +1,5 @@ static int -opCMC(uint32_t fetchdat) +opCMC(UNUSED(uint32_t fetchdat)) { flags_rebuild(); cpu_state.flags ^= C_FLAG; @@ -9,7 +9,7 @@ opCMC(uint32_t fetchdat) } static int -opCLC(uint32_t fetchdat) +opCLC(UNUSED(uint32_t fetchdat)) { flags_rebuild(); cpu_state.flags &= ~C_FLAG; @@ -18,7 +18,7 @@ opCLC(uint32_t fetchdat) return 0; } static int -opCLD(uint32_t fetchdat) +opCLD(UNUSED(uint32_t fetchdat)) { cpu_state.flags &= ~D_FLAG; CLOCK_CYCLES(2); @@ -26,7 +26,7 @@ opCLD(uint32_t fetchdat) return 0; } static int -opCLI(uint32_t fetchdat) +opCLI(UNUSED(uint32_t fetchdat)) { if (!IOPLp) { if ((!(cpu_state.eflags & VM_FLAG) && (cr4 & CR4_PVI)) || ((cpu_state.eflags & VM_FLAG) && (cr4 & CR4_VME))) { @@ -44,7 +44,7 @@ opCLI(uint32_t fetchdat) } static int -opSTC(uint32_t fetchdat) +opSTC(UNUSED(uint32_t fetchdat)) { flags_rebuild(); cpu_state.flags |= C_FLAG; @@ -53,7 +53,7 @@ opSTC(uint32_t fetchdat) return 0; } static int -opSTD(uint32_t fetchdat) +opSTD(UNUSED(uint32_t fetchdat)) { cpu_state.flags |= D_FLAG; CLOCK_CYCLES(2); @@ -61,7 +61,7 @@ opSTD(uint32_t fetchdat) return 0; } static int -opSTI(uint32_t fetchdat) +opSTI(UNUSED(uint32_t fetchdat)) { if (!IOPLp) { if ((!(cpu_state.eflags & VM_FLAG) && (cr4 & CR4_PVI)) || ((cpu_state.eflags & VM_FLAG) && (cr4 & CR4_VME))) { @@ -87,7 +87,7 @@ opSTI(uint32_t fetchdat) } static int -opSAHF(uint32_t fetchdat) +opSAHF(UNUSED(uint32_t fetchdat)) { flags_rebuild(); cpu_state.flags = (cpu_state.flags & 0xff00) | (AH & 0xd5) | 2; @@ -101,7 +101,7 @@ opSAHF(uint32_t fetchdat) return 0; } static int -opLAHF(uint32_t fetchdat) +opLAHF(UNUSED(uint32_t fetchdat)) { flags_rebuild(); AH = cpu_state.flags & 0xff; @@ -111,7 +111,7 @@ opLAHF(uint32_t fetchdat) } static int -opPUSHF(uint32_t fetchdat) +opPUSHF(UNUSED(uint32_t fetchdat)) { if ((cpu_state.eflags & VM_FLAG) && (IOPL < 3)) { if (cr4 & CR4_VME) { @@ -135,7 +135,7 @@ opPUSHF(uint32_t fetchdat) return cpu_state.abrt; } static int -opPUSHFD(uint32_t fetchdat) +opPUSHFD(UNUSED(uint32_t fetchdat)) { uint16_t tempw; if ((cpu_state.eflags & VM_FLAG) && (IOPL < 3)) { @@ -156,7 +156,7 @@ opPUSHFD(uint32_t fetchdat) } static int -opPOPF_186(uint32_t fetchdat) +opPOPF_186(UNUSED(uint32_t fetchdat)) { uint16_t tempw; @@ -192,7 +192,7 @@ opPOPF_186(uint32_t fetchdat) return 0; } static int -opPOPF_286(uint32_t fetchdat) +opPOPF_286(UNUSED(uint32_t fetchdat)) { uint16_t tempw; @@ -228,7 +228,7 @@ opPOPF_286(uint32_t fetchdat) return 0; } static int -opPOPF(uint32_t fetchdat) +opPOPF(UNUSED(uint32_t fetchdat)) { uint16_t tempw; @@ -284,7 +284,7 @@ opPOPF(uint32_t fetchdat) return 0; } static int -opPOPFD(uint32_t fetchdat) +opPOPFD(UNUSED(uint32_t fetchdat)) { uint32_t templ; diff --git a/src/cpu/x86_ops_flag_2386.h b/src/cpu/x86_ops_flag_2386.h index ba34ae5e7..c9a2d5ab2 100644 --- a/src/cpu/x86_ops_flag_2386.h +++ b/src/cpu/x86_ops_flag_2386.h @@ -1,5 +1,5 @@ static int -opCMC(uint32_t fetchdat) +opCMC(UNUSED(uint32_t fetchdat)) { flags_rebuild(); cpu_state.flags ^= C_FLAG; @@ -9,7 +9,7 @@ opCMC(uint32_t fetchdat) } static int -opCLC(uint32_t fetchdat) +opCLC(UNUSED(uint32_t fetchdat)) { flags_rebuild(); cpu_state.flags &= ~C_FLAG; @@ -18,7 +18,7 @@ opCLC(uint32_t fetchdat) return 0; } static int -opCLD(uint32_t fetchdat) +opCLD(UNUSED(uint32_t fetchdat)) { cpu_state.flags &= ~D_FLAG; CLOCK_CYCLES(2); @@ -26,7 +26,7 @@ opCLD(uint32_t fetchdat) return 0; } static int -opCLI(uint32_t fetchdat) +opCLI(UNUSED(uint32_t fetchdat)) { if (!IOPLp) { if ((!(cpu_state.eflags & VM_FLAG) && (cr4 & CR4_PVI)) || ((cpu_state.eflags & VM_FLAG) && (cr4 & CR4_VME))) { @@ -44,7 +44,7 @@ opCLI(uint32_t fetchdat) } static int -opSTC(uint32_t fetchdat) +opSTC(UNUSED(uint32_t fetchdat)) { flags_rebuild(); cpu_state.flags |= C_FLAG; @@ -53,7 +53,7 @@ opSTC(uint32_t fetchdat) return 0; } static int -opSTD(uint32_t fetchdat) +opSTD(UNUSED(uint32_t fetchdat)) { cpu_state.flags |= D_FLAG; CLOCK_CYCLES(2); @@ -61,7 +61,7 @@ opSTD(uint32_t fetchdat) return 0; } static int -opSTI(uint32_t fetchdat) +opSTI(UNUSED(uint32_t fetchdat)) { if (!IOPLp) { if ((!(cpu_state.eflags & VM_FLAG) && (cr4 & CR4_PVI)) || ((cpu_state.eflags & VM_FLAG) && (cr4 & CR4_VME))) { @@ -87,7 +87,7 @@ opSTI(uint32_t fetchdat) } static int -opSAHF(uint32_t fetchdat) +opSAHF(UNUSED(uint32_t fetchdat)) { flags_rebuild(); cpu_state.flags = (cpu_state.flags & 0xff00) | (AH & 0xd5) | 2; @@ -101,7 +101,7 @@ opSAHF(uint32_t fetchdat) return 0; } static int -opLAHF(uint32_t fetchdat) +opLAHF(UNUSED(uint32_t fetchdat)) { flags_rebuild(); AH = cpu_state.flags & 0xff; @@ -111,7 +111,7 @@ opLAHF(uint32_t fetchdat) } static int -opPUSHF(uint32_t fetchdat) +opPUSHF(UNUSED(uint32_t fetchdat)) { if ((cpu_state.eflags & VM_FLAG) && (IOPL < 3)) { if (cr4 & CR4_VME) { @@ -135,7 +135,7 @@ opPUSHF(uint32_t fetchdat) return cpu_state.abrt; } static int -opPUSHFD(uint32_t fetchdat) +opPUSHFD(UNUSED(uint32_t fetchdat)) { uint16_t tempw; if ((cpu_state.eflags & VM_FLAG) && (IOPL < 3)) { @@ -156,7 +156,7 @@ opPUSHFD(uint32_t fetchdat) } static int -opPOPF_186(uint32_t fetchdat) +opPOPF_186(UNUSED(uint32_t fetchdat)) { uint16_t tempw; @@ -190,7 +190,7 @@ opPOPF_186(uint32_t fetchdat) return 0; } static int -opPOPF_286(uint32_t fetchdat) +opPOPF_286(UNUSED(uint32_t fetchdat)) { uint16_t tempw; @@ -224,7 +224,7 @@ opPOPF_286(uint32_t fetchdat) return 0; } static int -opPOPF(uint32_t fetchdat) +opPOPF(UNUSED(uint32_t fetchdat)) { uint16_t tempw; @@ -278,7 +278,7 @@ opPOPF(uint32_t fetchdat) return 0; } static int -opPOPFD(uint32_t fetchdat) +opPOPFD(UNUSED(uint32_t fetchdat)) { uint32_t templ; diff --git a/src/cpu/x86_ops_fpu.h b/src/cpu/x86_ops_fpu.h index 74c67c2ee..3434c4a73 100644 --- a/src/cpu/x86_ops_fpu.h +++ b/src/cpu/x86_ops_fpu.h @@ -90,7 +90,7 @@ opESCAPE_df_a32(uint32_t fetchdat) } static int -opWAIT(uint32_t fetchdat) +opWAIT(UNUSED(uint32_t fetchdat)) { if ((cr0 & 0xa) == 0xa) { x86_int(7); diff --git a/src/cpu/x86_ops_fpu_2386.h b/src/cpu/x86_ops_fpu_2386.h index cc9c6dcc2..c2252af12 100644 --- a/src/cpu/x86_ops_fpu_2386.h +++ b/src/cpu/x86_ops_fpu_2386.h @@ -90,7 +90,7 @@ opESCAPE_df_a32(uint32_t fetchdat) } static int -opWAIT(uint32_t fetchdat) +opWAIT(UNUSED(uint32_t fetchdat)) { if ((cr0 & 0xa) == 0xa) { x86_int(7); diff --git a/src/cpu/x86_ops_inc_dec.h b/src/cpu/x86_ops_inc_dec.h index 3eb908c57..b33d02f45 100644 --- a/src/cpu/x86_ops_inc_dec.h +++ b/src/cpu/x86_ops_inc_dec.h @@ -1,5 +1,5 @@ #define INC_DEC_OP(name, reg, inc, setflags) \ - static int op##name(uint32_t fetchdat) \ + static int op##name(UNUSED(uint32_t fetchdat)) \ { \ setflags(reg, 1); \ reg += inc; \ diff --git a/src/cpu/x86_ops_int.h b/src/cpu/x86_ops_int.h index a73ed62e0..1ed5e6c2f 100644 --- a/src/cpu/x86_ops_int.h +++ b/src/cpu/x86_ops_int.h @@ -1,5 +1,5 @@ static int -opINT3(uint32_t fetchdat) +opINT3(UNUSED(uint32_t fetchdat)) { int cycles_old = cycles; UN_USED(cycles_old); @@ -18,7 +18,7 @@ opINT3(uint32_t fetchdat) } static int -opINT1(uint32_t fetchdat) +opINT1(UNUSED(uint32_t fetchdat)) { int cycles_old = cycles; UN_USED(cycles_old); @@ -75,7 +75,7 @@ opINT(uint32_t fetchdat) } static int -opINTO(uint32_t fetchdat) +opINTO(UNUSED(uint32_t fetchdat)) { int cycles_old = cycles; UN_USED(cycles_old); diff --git a/src/cpu/x86_ops_io.h b/src/cpu/x86_ops_io.h index 8a99b8668..36bf05cd3 100644 --- a/src/cpu/x86_ops_io.h +++ b/src/cpu/x86_ops_io.h @@ -75,7 +75,7 @@ opOUT_EAX_imm(uint32_t fetchdat) } static int -opIN_AL_DX(uint32_t fetchdat) +opIN_AL_DX(UNUSED(uint32_t fetchdat)) { check_io_perm(DX, 1); AL = inb(DX); @@ -86,7 +86,7 @@ opIN_AL_DX(uint32_t fetchdat) return 0; } static int -opIN_AX_DX(uint32_t fetchdat) +opIN_AX_DX(UNUSED(uint32_t fetchdat)) { check_io_perm(DX, 2); AX = inw(DX); @@ -97,7 +97,7 @@ opIN_AX_DX(uint32_t fetchdat) return 0; } static int -opIN_EAX_DX(uint32_t fetchdat) +opIN_EAX_DX(UNUSED(uint32_t fetchdat)) { check_io_perm(DX, 4); EAX = inl(DX); @@ -109,7 +109,7 @@ opIN_EAX_DX(uint32_t fetchdat) } static int -opOUT_AL_DX(uint32_t fetchdat) +opOUT_AL_DX(UNUSED(uint32_t fetchdat)) { check_io_perm(DX, 1); outb(DX, AL); @@ -120,7 +120,7 @@ opOUT_AL_DX(uint32_t fetchdat) return x86_was_reset; } static int -opOUT_AX_DX(uint32_t fetchdat) +opOUT_AX_DX(UNUSED(uint32_t fetchdat)) { check_io_perm(DX, 2); outw(DX, AX); @@ -131,7 +131,7 @@ opOUT_AX_DX(uint32_t fetchdat) return 0; } static int -opOUT_EAX_DX(uint32_t fetchdat) +opOUT_EAX_DX(UNUSED(uint32_t fetchdat)) { check_io_perm(DX, 4); outl(DX, EAX); diff --git a/src/cpu/x86_ops_jump.h b/src/cpu/x86_ops_jump.h index 97ca673d7..fc99fc5fd 100644 --- a/src/cpu/x86_ops_jump.h +++ b/src/cpu/x86_ops_jump.h @@ -51,7 +51,7 @@ return 0; \ } \ \ - static int opJ##condition##_l(uint32_t fetchdat) \ + static int opJ##condition##_l(UNUSED(uint32_t fetchdat)) \ { \ uint32_t offset = getlong(); \ if (cpu_state.abrt) \ @@ -256,7 +256,7 @@ opJMP_r16(uint32_t fetchdat) return 0; } static int -opJMP_r32(uint32_t fetchdat) +opJMP_r32(UNUSED(uint32_t fetchdat)) { int32_t offset = (int32_t) getlong(); if (cpu_state.abrt) @@ -289,7 +289,7 @@ opJMP_far_a16(uint32_t fetchdat) return 0; } static int -opJMP_far_a32(uint32_t fetchdat) +opJMP_far_a32(UNUSED(uint32_t fetchdat)) { uint16_t seg; uint32_t addr; @@ -323,7 +323,7 @@ opCALL_r16(uint32_t fetchdat) return 0; } static int -opCALL_r32(uint32_t fetchdat) +opCALL_r32(UNUSED(uint32_t fetchdat)) { int32_t addr = getlong(); @@ -339,7 +339,7 @@ opCALL_r32(uint32_t fetchdat) } static int -opRET_w(uint32_t fetchdat) +opRET_w(UNUSED(uint32_t fetchdat)) { uint16_t ret; @@ -355,7 +355,7 @@ opRET_w(uint32_t fetchdat) return 0; } static int -opRET_l(uint32_t fetchdat) +opRET_l(UNUSED(uint32_t fetchdat)) { uint32_t ret; diff --git a/src/cpu/x86_ops_misc.h b/src/cpu/x86_ops_misc.h index c0b9de437..ffc79f0e8 100644 --- a/src/cpu/x86_ops_misc.h +++ b/src/cpu/x86_ops_misc.h @@ -1,5 +1,5 @@ static int -opCBW(uint32_t fetchdat) +opCBW(UNUSED(uint32_t fetchdat)) { AH = (AL & 0x80) ? 0xff : 0; CLOCK_CYCLES(3); @@ -7,7 +7,7 @@ opCBW(uint32_t fetchdat) return 0; } static int -opCWDE(uint32_t fetchdat) +opCWDE(UNUSED(uint32_t fetchdat)) { EAX = (AX & 0x8000) ? (0xffff0000 | AX) : AX; CLOCK_CYCLES(3); @@ -15,7 +15,7 @@ opCWDE(uint32_t fetchdat) return 0; } static int -opCWD(uint32_t fetchdat) +opCWD(UNUSED(uint32_t fetchdat)) { DX = (AX & 0x8000) ? 0xFFFF : 0; CLOCK_CYCLES(2); @@ -23,7 +23,7 @@ opCWD(uint32_t fetchdat) return 0; } static int -opCDQ(uint32_t fetchdat) +opCDQ(UNUSED(uint32_t fetchdat)) { EDX = (EAX & 0x80000000) ? 0xffffffff : 0; CLOCK_CYCLES(2); @@ -32,7 +32,7 @@ opCDQ(uint32_t fetchdat) } static int -opNOP(uint32_t fetchdat) +opNOP(UNUSED(uint32_t fetchdat)) { CLOCK_CYCLES((is486) ? 1 : 3); PREFETCH_RUN(3, 1, -1, 0, 0, 0, 0, 0); @@ -40,7 +40,7 @@ opNOP(uint32_t fetchdat) } static int -opSETALC(uint32_t fetchdat) +opSETALC(UNUSED(uint32_t fetchdat)) { AL = (CF_SET()) ? 0xff : 0; CLOCK_CYCLES(timing_rr); @@ -701,7 +701,7 @@ opF7_l_a32(uint32_t fetchdat) } static int -opHLT(uint32_t fetchdat) +opHLT(UNUSED(uint32_t fetchdat)) { if ((CPL || (cpu_state.eflags & VM_FLAG)) && (cr0 & 1)) { x86gpf(NULL, 0); @@ -856,7 +856,7 @@ opBOUND_l_a32(uint32_t fetchdat) } static int -opCLTS(uint32_t fetchdat) +opCLTS(UNUSED(uint32_t fetchdat)) { if ((CPL || (cpu_state.eflags & VM_FLAG)) && (cr0 & 1)) { x86gpf(NULL, 0); @@ -869,14 +869,14 @@ opCLTS(uint32_t fetchdat) } static int -opINVD(uint32_t fetchdat) +opINVD(UNUSED(uint32_t fetchdat)) { CLOCK_CYCLES(1000); CPU_BLOCK_END(); return 0; } static int -opWBINVD(uint32_t fetchdat) +opWBINVD(UNUSED(uint32_t fetchdat)) { if ((CPL || (cpu_state.eflags & VM_FLAG)) && (cr0 & 1)) { x86gpf(NULL, 0); @@ -888,7 +888,7 @@ opWBINVD(uint32_t fetchdat) } static int -opLOADALL(uint32_t fetchdat) +opLOADALL(UNUSED(uint32_t fetchdat)) { if (CPL && (cr0 & 1)) { x86gpf(NULL, 0); @@ -998,7 +998,7 @@ loadall_load_segment(uint32_t addr, x86seg *s) } static int -opLOADALL386(uint32_t fetchdat) +opLOADALL386(UNUSED(uint32_t fetchdat)) { uint32_t la_addr = es + EDI; @@ -1046,7 +1046,7 @@ opLOADALL386(uint32_t fetchdat) } static int -opCPUID(uint32_t fetchdat) +opCPUID(UNUSED(uint32_t fetchdat)) { if (CPUID) { cpu_CPUID(); @@ -1059,7 +1059,7 @@ opCPUID(uint32_t fetchdat) } static int -opRDMSR(uint32_t fetchdat) +opRDMSR(UNUSED(uint32_t fetchdat)) { if (cpu_has_feature(CPU_FEATURE_MSR)) { cpu_RDMSR(); @@ -1072,7 +1072,7 @@ opRDMSR(uint32_t fetchdat) } static int -opWRMSR(uint32_t fetchdat) +opWRMSR(UNUSED(uint32_t fetchdat)) { if (cpu_has_feature(CPU_FEATURE_MSR)) { cpu_WRMSR(); @@ -1085,7 +1085,7 @@ opWRMSR(uint32_t fetchdat) } static int -opRSM(uint32_t fetchdat) +opRSM(UNUSED(uint32_t fetchdat)) { if (in_smm) { leave_smm(); diff --git a/src/cpu/x86_ops_mmx.h b/src/cpu/x86_ops_mmx.h index ab5e19762..338948af5 100644 --- a/src/cpu/x86_ops_mmx.h +++ b/src/cpu/x86_ops_mmx.h @@ -34,7 +34,7 @@ x87_set_mmx() static int -opEMMS(uint32_t fetchdat) +opEMMS(UNUSED(uint32_t fetchdat)) { if (!cpu_has_feature(CPU_FEATURE_MMX)) { cpu_state.pc = cpu_state.oldpc; diff --git a/src/cpu/x86_ops_mov.h b/src/cpu/x86_ops_mov.h index e77876d5c..787a727d3 100644 --- a/src/cpu/x86_ops_mov.h +++ b/src/cpu/x86_ops_mov.h @@ -129,7 +129,7 @@ opMOV_SP_imm(uint32_t fetchdat) } static int -opMOV_EAX_imm(uint32_t fetchdat) +opMOV_EAX_imm(UNUSED(uint32_t fetchdat)) { uint32_t templ = getlong(); if (cpu_state.abrt) @@ -140,7 +140,7 @@ opMOV_EAX_imm(uint32_t fetchdat) return 0; } static int -opMOV_EBX_imm(uint32_t fetchdat) +opMOV_EBX_imm(UNUSED(uint32_t fetchdat)) { uint32_t templ = getlong(); if (cpu_state.abrt) @@ -151,7 +151,7 @@ opMOV_EBX_imm(uint32_t fetchdat) return 0; } static int -opMOV_ECX_imm(uint32_t fetchdat) +opMOV_ECX_imm(UNUSED(uint32_t fetchdat)) { uint32_t templ = getlong(); if (cpu_state.abrt) @@ -162,7 +162,7 @@ opMOV_ECX_imm(uint32_t fetchdat) return 0; } static int -opMOV_EDX_imm(uint32_t fetchdat) +opMOV_EDX_imm(UNUSED(uint32_t fetchdat)) { uint32_t templ = getlong(); if (cpu_state.abrt) @@ -173,7 +173,7 @@ opMOV_EDX_imm(uint32_t fetchdat) return 0; } static int -opMOV_ESI_imm(uint32_t fetchdat) +opMOV_ESI_imm(UNUSED(uint32_t fetchdat)) { uint32_t templ = getlong(); if (cpu_state.abrt) @@ -184,7 +184,7 @@ opMOV_ESI_imm(uint32_t fetchdat) return 0; } static int -opMOV_EDI_imm(uint32_t fetchdat) +opMOV_EDI_imm(UNUSED(uint32_t fetchdat)) { uint32_t templ = getlong(); if (cpu_state.abrt) @@ -195,7 +195,7 @@ opMOV_EDI_imm(uint32_t fetchdat) return 0; } static int -opMOV_EBP_imm(uint32_t fetchdat) +opMOV_EBP_imm(UNUSED(uint32_t fetchdat)) { uint32_t templ = getlong(); if (cpu_state.abrt) @@ -206,7 +206,7 @@ opMOV_EBP_imm(uint32_t fetchdat) return 0; } static int -opMOV_ESP_imm(uint32_t fetchdat) +opMOV_ESP_imm(UNUSED(uint32_t fetchdat)) { uint32_t templ = getlong(); if (cpu_state.abrt) @@ -326,7 +326,7 @@ opMOV_AL_a16(uint32_t fetchdat) return 0; } static int -opMOV_AL_a32(uint32_t fetchdat) +opMOV_AL_a32(UNUSED(uint32_t fetchdat)) { uint8_t temp; uint32_t addr = getlong(); @@ -356,7 +356,7 @@ opMOV_AX_a16(uint32_t fetchdat) return 0; } static int -opMOV_AX_a32(uint32_t fetchdat) +opMOV_AX_a32(UNUSED(uint32_t fetchdat)) { uint16_t temp; uint32_t addr = getlong(); @@ -386,7 +386,7 @@ opMOV_EAX_a16(uint32_t fetchdat) return 0; } static int -opMOV_EAX_a32(uint32_t fetchdat) +opMOV_EAX_a32(UNUSED(uint32_t fetchdat)) { uint32_t temp; uint32_t addr = getlong(); @@ -413,7 +413,7 @@ opMOV_a16_AL(uint32_t fetchdat) return cpu_state.abrt; } static int -opMOV_a32_AL(uint32_t fetchdat) +opMOV_a32_AL(UNUSED(uint32_t fetchdat)) { uint32_t addr = getlong(); SEG_CHECK_WRITE(cpu_state.ea_seg); @@ -435,7 +435,7 @@ opMOV_a16_AX(uint32_t fetchdat) return cpu_state.abrt; } static int -opMOV_a32_AX(uint32_t fetchdat) +opMOV_a32_AX(UNUSED(uint32_t fetchdat)) { uint32_t addr = getlong(); if (cpu_state.abrt) @@ -459,7 +459,7 @@ opMOV_a16_EAX(uint32_t fetchdat) return cpu_state.abrt; } static int -opMOV_a32_EAX(uint32_t fetchdat) +opMOV_a32_EAX(UNUSED(uint32_t fetchdat)) { uint32_t addr = getlong(); if (cpu_state.abrt) @@ -515,7 +515,7 @@ opLEA_l_a32(uint32_t fetchdat) } static int -opXLAT_a16(uint32_t fetchdat) +opXLAT_a16(UNUSED(uint32_t fetchdat)) { uint32_t addr = (BX + AL) & 0xFFFF; uint8_t temp; @@ -530,7 +530,7 @@ opXLAT_a16(uint32_t fetchdat) return 0; } static int -opXLAT_a32(uint32_t fetchdat) +opXLAT_a32(UNUSED(uint32_t fetchdat)) { uint32_t addr = EBX + AL; uint8_t temp; diff --git a/src/cpu/x86_ops_msr.h b/src/cpu/x86_ops_msr.h index daae01d84..a59cecdd4 100644 --- a/src/cpu/x86_ops_msr.h +++ b/src/cpu/x86_ops_msr.h @@ -1,5 +1,5 @@ static int -opRDTSC(uint32_t fetchdat) +opRDTSC(UNUSED(uint32_t fetchdat)) { if (!cpu_has_feature(CPU_FEATURE_RDTSC)) { cpu_state.pc = cpu_state.oldpc; @@ -21,7 +21,7 @@ opRDTSC(uint32_t fetchdat) } static int -opRDPMC(uint32_t fetchdat) +opRDPMC(UNUSED(uint32_t fetchdat)) { if (ECX > 1 || (!(cr4 & CR4_PCE) && (cr0 & 1) && CPL)) { x86gpf("RDPMC not allowed", 0); diff --git a/src/cpu/x86_ops_pmode.h b/src/cpu/x86_ops_pmode.h index 4f32b0e37..81f194f14 100644 --- a/src/cpu/x86_ops_pmode.h +++ b/src/cpu/x86_ops_pmode.h @@ -172,12 +172,12 @@ opLAR(w_a16, fetch_ea_16, 0, 0) return cpu_state.abrt; \ } - opLSL(w_a16, fetch_ea_16, 0, 0) - opLSL(w_a32, fetch_ea_32, 0, 1) - opLSL(l_a16, fetch_ea_16, 1, 0) - opLSL(l_a32, fetch_ea_32, 1, 1) +opLSL(w_a16, fetch_ea_16, 0, 0) +opLSL(w_a32, fetch_ea_32, 0, 1) +opLSL(l_a16, fetch_ea_16, 1, 0) +opLSL(l_a32, fetch_ea_32, 1, 1) - static int op0F00_common(uint32_t fetchdat, int ea32) +static int op0F00_common(uint32_t fetchdat, UNUSED(int ea32)) { int dpl; int valid; @@ -359,7 +359,7 @@ op0F00_a32(uint32_t fetchdat) } static int -op0F01_common(uint32_t fetchdat, int is32, int is286, int ea32) +op0F01_common(UNUSED(uint32_t fetchdat), int is32, int is286, UNUSED(int ea32)) { uint32_t base; uint16_t limit; diff --git a/src/cpu/x86_ops_rep.h b/src/cpu/x86_ops_rep.h index a49db7e81..c75684d31 100644 --- a/src/cpu/x86_ops_rep.h +++ b/src/cpu/x86_ops_rep.h @@ -1,5 +1,5 @@ #define REP_OPS(size, CNT_REG, SRC_REG, DEST_REG) \ - static int opREP_INSB_##size(uint32_t fetchdat) \ + static int opREP_INSB_##size(UNUSED(uint32_t fetchdat)) \ { \ int reads = 0, writes = 0, total_cycles = 0; \ \ @@ -38,7 +38,7 @@ } \ return cpu_state.abrt; \ } \ - static int opREP_INSW_##size(uint32_t fetchdat) \ + static int opREP_INSW_##size(UNUSED(uint32_t fetchdat)) \ { \ int reads = 0, writes = 0, total_cycles = 0; \ \ @@ -77,7 +77,7 @@ } \ return cpu_state.abrt; \ } \ - static int opREP_INSL_##size(uint32_t fetchdat) \ + static int opREP_INSL_##size(UNUSED(uint32_t fetchdat)) \ { \ int reads = 0, writes = 0, total_cycles = 0; \ \ @@ -117,7 +117,7 @@ return cpu_state.abrt; \ } \ \ - static int opREP_OUTSB_##size(uint32_t fetchdat) \ + static int opREP_OUTSB_##size(UNUSED(uint32_t fetchdat)) \ { \ int reads = 0, writes = 0, total_cycles = 0; \ \ @@ -148,7 +148,7 @@ } \ return cpu_state.abrt; \ } \ - static int opREP_OUTSW_##size(uint32_t fetchdat) \ + static int opREP_OUTSW_##size(UNUSED(uint32_t fetchdat)) \ { \ int reads = 0, writes = 0, total_cycles = 0; \ \ @@ -179,7 +179,7 @@ } \ return cpu_state.abrt; \ } \ - static int opREP_OUTSL_##size(uint32_t fetchdat) \ + static int opREP_OUTSL_##size(UNUSED(uint32_t fetchdat)) \ { \ int reads = 0, writes = 0, total_cycles = 0; \ \ @@ -211,7 +211,7 @@ return cpu_state.abrt; \ } \ \ - static int opREP_MOVSB_##size(uint32_t fetchdat) \ + static int opREP_MOVSB_##size(UNUSED(uint32_t fetchdat)) \ { \ int reads = 0, writes = 0, total_cycles = 0; \ int cycles_end = cycles - ((is386 && cpu_use_dynarec) ? 1000 : 100); \ @@ -264,7 +264,7 @@ } \ return cpu_state.abrt; \ } \ - static int opREP_MOVSW_##size(uint32_t fetchdat) \ + static int opREP_MOVSW_##size(UNUSED(uint32_t fetchdat)) \ { \ int reads = 0, writes = 0, total_cycles = 0; \ int cycles_end = cycles - ((is386 && cpu_use_dynarec) ? 1000 : 100); \ @@ -318,7 +318,7 @@ } \ return cpu_state.abrt; \ } \ - static int opREP_MOVSL_##size(uint32_t fetchdat) \ + static int opREP_MOVSL_##size(UNUSED(uint32_t fetchdat)) \ { \ int reads = 0, writes = 0, total_cycles = 0; \ int cycles_end = cycles - ((is386 && cpu_use_dynarec) ? 1000 : 100); \ @@ -373,7 +373,7 @@ return cpu_state.abrt; \ } \ \ - static int opREP_STOSB_##size(uint32_t fetchdat) \ + static int opREP_STOSB_##size(UNUSED(uint32_t fetchdat)) \ { \ int writes = 0, total_cycles = 0; \ int cycles_end = cycles - ((is386 && cpu_use_dynarec) ? 1000 : 100); \ @@ -405,7 +405,7 @@ } \ return cpu_state.abrt; \ } \ - static int opREP_STOSW_##size(uint32_t fetchdat) \ + static int opREP_STOSW_##size(UNUSED(uint32_t fetchdat)) \ { \ int writes = 0, total_cycles = 0; \ int cycles_end = cycles - ((is386 && cpu_use_dynarec) ? 1000 : 100); \ @@ -437,7 +437,7 @@ } \ return cpu_state.abrt; \ } \ - static int opREP_STOSL_##size(uint32_t fetchdat) \ + static int opREP_STOSL_##size(UNUSED(uint32_t fetchdat)) \ { \ int writes = 0, total_cycles = 0; \ int cycles_end = cycles - ((is386 && cpu_use_dynarec) ? 1000 : 100); \ @@ -470,7 +470,7 @@ return cpu_state.abrt; \ } \ \ - static int opREP_LODSB_##size(uint32_t fetchdat) \ + static int opREP_LODSB_##size(UNUSED(uint32_t fetchdat)) \ { \ int reads = 0, total_cycles = 0; \ int cycles_end = cycles - ((is386 && cpu_use_dynarec) ? 1000 : 100); \ @@ -502,7 +502,7 @@ } \ return cpu_state.abrt; \ } \ - static int opREP_LODSW_##size(uint32_t fetchdat) \ + static int opREP_LODSW_##size(UNUSED(uint32_t fetchdat)) \ { \ int reads = 0, total_cycles = 0; \ int cycles_end = cycles - ((is386 && cpu_use_dynarec) ? 1000 : 100); \ @@ -534,7 +534,7 @@ } \ return cpu_state.abrt; \ } \ - static int opREP_LODSL_##size(uint32_t fetchdat) \ + static int opREP_LODSL_##size(UNUSED(uint32_t fetchdat)) \ { \ int reads = 0, total_cycles = 0; \ int cycles_end = cycles - ((is386 && cpu_use_dynarec) ? 1000 : 100); \ @@ -570,7 +570,7 @@ #define CHEK_READ(a, b, c) #define REP_OPS_CMPS_SCAS(size, CNT_REG, SRC_REG, DEST_REG, FV) \ - static int opREP_CMPSB_##size(uint32_t fetchdat) \ + static int opREP_CMPSB_##size(UNUSED(uint32_t fetchdat)) \ { \ int reads = 0, total_cycles = 0, tempz; \ \ @@ -623,7 +623,7 @@ } \ return cpu_state.abrt; \ } \ - static int opREP_CMPSW_##size(uint32_t fetchdat) \ + static int opREP_CMPSW_##size(UNUSED(uint32_t fetchdat)) \ { \ int reads = 0, total_cycles = 0, tempz; \ \ @@ -677,7 +677,7 @@ } \ return cpu_state.abrt; \ } \ - static int opREP_CMPSL_##size(uint32_t fetchdat) \ + static int opREP_CMPSL_##size(UNUSED(uint32_t fetchdat)) \ { \ int reads = 0, total_cycles = 0, tempz; \ \ @@ -732,7 +732,7 @@ return cpu_state.abrt; \ } \ \ - static int opREP_SCASB_##size(uint32_t fetchdat) \ + static int opREP_SCASB_##size(UNUSED(uint32_t fetchdat)) \ { \ int reads = 0, total_cycles = 0, tempz; \ int cycles_end = cycles - ((is386 && cpu_use_dynarec) ? 1000 : 100); \ @@ -767,7 +767,7 @@ } \ return cpu_state.abrt; \ } \ - static int opREP_SCASW_##size(uint32_t fetchdat) \ + static int opREP_SCASW_##size(UNUSED(uint32_t fetchdat)) \ { \ int reads = 0, total_cycles = 0, tempz; \ int cycles_end = cycles - ((is386 && cpu_use_dynarec) ? 1000 : 100); \ @@ -802,7 +802,7 @@ } \ return cpu_state.abrt; \ } \ - static int opREP_SCASL_##size(uint32_t fetchdat) \ + static int opREP_SCASL_##size(UNUSED(uint32_t fetchdat)) \ { \ int reads = 0, total_cycles = 0, tempz; \ int cycles_end = cycles - ((is386 && cpu_use_dynarec) ? 1000 : 100); \ diff --git a/src/cpu/x86_ops_rep_2386.h b/src/cpu/x86_ops_rep_2386.h index fe5048340..aa1984f81 100644 --- a/src/cpu/x86_ops_rep_2386.h +++ b/src/cpu/x86_ops_rep_2386.h @@ -1,5 +1,5 @@ #define REP_OPS(size, CNT_REG, SRC_REG, DEST_REG) \ - static int opREP_INSB_##size(uint32_t fetchdat) \ + static int opREP_INSB_##size(UNUSED(uint32_t fetchdat)) \ { \ int reads = 0, writes = 0, total_cycles = 0; \ \ @@ -38,7 +38,7 @@ } \ return cpu_state.abrt; \ } \ - static int opREP_INSW_##size(uint32_t fetchdat) \ + static int opREP_INSW_##size(UNUSED(uint32_t fetchdat)) \ { \ int reads = 0, writes = 0, total_cycles = 0; \ \ @@ -77,7 +77,7 @@ } \ return cpu_state.abrt; \ } \ - static int opREP_INSL_##size(uint32_t fetchdat) \ + static int opREP_INSL_##size(UNUSED(uint32_t fetchdat)) \ { \ int reads = 0, writes = 0, total_cycles = 0; \ \ @@ -117,7 +117,7 @@ return cpu_state.abrt; \ } \ \ - static int opREP_OUTSB_##size(uint32_t fetchdat) \ + static int opREP_OUTSB_##size(UNUSED(uint32_t fetchdat)) \ { \ int reads = 0, writes = 0, total_cycles = 0; \ \ @@ -148,7 +148,7 @@ } \ return cpu_state.abrt; \ } \ - static int opREP_OUTSW_##size(uint32_t fetchdat) \ + static int opREP_OUTSW_##size(UNUSED(uint32_t fetchdat)) \ { \ int reads = 0, writes = 0, total_cycles = 0; \ \ @@ -179,7 +179,7 @@ } \ return cpu_state.abrt; \ } \ - static int opREP_OUTSL_##size(uint32_t fetchdat) \ + static int opREP_OUTSL_##size(UNUSED(uint32_t fetchdat)) \ { \ int reads = 0, writes = 0, total_cycles = 0; \ \ @@ -211,7 +211,7 @@ return cpu_state.abrt; \ } \ \ - static int opREP_MOVSB_##size(uint32_t fetchdat) \ + static int opREP_MOVSB_##size(UNUSED(uint32_t fetchdat)) \ { \ int reads = 0, writes = 0, total_cycles = 0; \ int cycles_end = cycles - ((is386 && cpu_use_dynarec) ? 1000 : 100); \ @@ -264,7 +264,7 @@ } \ return cpu_state.abrt; \ } \ - static int opREP_MOVSW_##size(uint32_t fetchdat) \ + static int opREP_MOVSW_##size(UNUSED(uint32_t fetchdat)) \ { \ int reads = 0, writes = 0, total_cycles = 0; \ int cycles_end = cycles - ((is386 && cpu_use_dynarec) ? 1000 : 100); \ @@ -318,7 +318,7 @@ } \ return cpu_state.abrt; \ } \ - static int opREP_MOVSL_##size(uint32_t fetchdat) \ + static int opREP_MOVSL_##size(UNUSED(uint32_t fetchdat)) \ { \ int reads = 0, writes = 0, total_cycles = 0; \ int cycles_end = cycles - ((is386 && cpu_use_dynarec) ? 1000 : 100); \ @@ -373,7 +373,7 @@ return cpu_state.abrt; \ } \ \ - static int opREP_STOSB_##size(uint32_t fetchdat) \ + static int opREP_STOSB_##size(UNUSED(uint32_t fetchdat)) \ { \ int writes = 0, total_cycles = 0; \ int cycles_end = cycles - ((is386 && cpu_use_dynarec) ? 1000 : 100); \ @@ -405,7 +405,7 @@ } \ return cpu_state.abrt; \ } \ - static int opREP_STOSW_##size(uint32_t fetchdat) \ + static int opREP_STOSW_##size(UNUSED(uint32_t fetchdat)) \ { \ int writes = 0, total_cycles = 0; \ int cycles_end = cycles - ((is386 && cpu_use_dynarec) ? 1000 : 100); \ @@ -437,7 +437,7 @@ } \ return cpu_state.abrt; \ } \ - static int opREP_STOSL_##size(uint32_t fetchdat) \ + static int opREP_STOSL_##size(UNUSED(uint32_t fetchdat)) \ { \ int writes = 0, total_cycles = 0; \ int cycles_end = cycles - ((is386 && cpu_use_dynarec) ? 1000 : 100); \ @@ -470,7 +470,7 @@ return cpu_state.abrt; \ } \ \ - static int opREP_LODSB_##size(uint32_t fetchdat) \ + static int opREP_LODSB_##size(UNUSED(uint32_t fetchdat)) \ { \ int reads = 0, total_cycles = 0; \ int cycles_end = cycles - ((is386 && cpu_use_dynarec) ? 1000 : 100); \ @@ -502,7 +502,7 @@ } \ return cpu_state.abrt; \ } \ - static int opREP_LODSW_##size(uint32_t fetchdat) \ + static int opREP_LODSW_##size(UNUSED(uint32_t fetchdat)) \ { \ int reads = 0, total_cycles = 0; \ int cycles_end = cycles - ((is386 && cpu_use_dynarec) ? 1000 : 100); \ @@ -534,7 +534,7 @@ } \ return cpu_state.abrt; \ } \ - static int opREP_LODSL_##size(uint32_t fetchdat) \ + static int opREP_LODSL_##size(UNUSED(uint32_t fetchdat)) \ { \ int reads = 0, total_cycles = 0; \ int cycles_end = cycles - ((is386 && cpu_use_dynarec) ? 1000 : 100); \ @@ -570,7 +570,7 @@ #define CHEK_READ(a, b, c) #define REP_OPS_CMPS_SCAS(size, CNT_REG, SRC_REG, DEST_REG, FV) \ - static int opREP_CMPSB_##size(uint32_t fetchdat) \ + static int opREP_CMPSB_##size(UNUSED(uint32_t fetchdat)) \ { \ int reads = 0, total_cycles = 0, tempz; \ \ @@ -619,7 +619,7 @@ } \ return cpu_state.abrt; \ } \ - static int opREP_CMPSW_##size(uint32_t fetchdat) \ + static int opREP_CMPSW_##size(UNUSED(uint32_t fetchdat)) \ { \ int reads = 0, total_cycles = 0, tempz; \ \ @@ -669,7 +669,7 @@ } \ return cpu_state.abrt; \ } \ - static int opREP_CMPSL_##size(uint32_t fetchdat) \ + static int opREP_CMPSL_##size(UNUSED(uint32_t fetchdat)) \ { \ int reads = 0, total_cycles = 0, tempz; \ \ @@ -720,7 +720,7 @@ return cpu_state.abrt; \ } \ \ - static int opREP_SCASB_##size(uint32_t fetchdat) \ + static int opREP_SCASB_##size(UNUSED(uint32_t fetchdat)) \ { \ int reads = 0, total_cycles = 0, tempz; \ int cycles_end = cycles - ((is386 && cpu_use_dynarec) ? 1000 : 100); \ @@ -755,7 +755,7 @@ } \ return cpu_state.abrt; \ } \ - static int opREP_SCASW_##size(uint32_t fetchdat) \ + static int opREP_SCASW_##size(UNUSED(uint32_t fetchdat)) \ { \ int reads = 0, total_cycles = 0, tempz; \ int cycles_end = cycles - ((is386 && cpu_use_dynarec) ? 1000 : 100); \ @@ -790,7 +790,7 @@ } \ return cpu_state.abrt; \ } \ - static int opREP_SCASL_##size(uint32_t fetchdat) \ + static int opREP_SCASL_##size(UNUSED(uint32_t fetchdat)) \ { \ int reads = 0, total_cycles = 0, tempz; \ int cycles_end = cycles - ((is386 && cpu_use_dynarec) ? 1000 : 100); \ diff --git a/src/cpu/x86_ops_rep_dyn.h b/src/cpu/x86_ops_rep_dyn.h index cf32209cc..bdb721ab0 100644 --- a/src/cpu/x86_ops_rep_dyn.h +++ b/src/cpu/x86_ops_rep_dyn.h @@ -1,5 +1,5 @@ #define REP_OPS(size, CNT_REG, SRC_REG, DEST_REG) \ - static int opREP_INSB_##size(uint32_t fetchdat) \ + static int opREP_INSB_##size(UNUSED(uint32_t fetchdat)) \ { \ addr64 = 0x00000000; \ \ @@ -32,7 +32,7 @@ } \ return cpu_state.abrt; \ } \ - static int opREP_INSW_##size(uint32_t fetchdat) \ + static int opREP_INSW_##size(UNUSED(uint32_t fetchdat)) \ { \ addr64a[0] = addr64a[1] = 0x00000000; \ \ @@ -65,7 +65,7 @@ } \ return cpu_state.abrt; \ } \ - static int opREP_INSL_##size(uint32_t fetchdat) \ + static int opREP_INSL_##size(UNUSED(uint32_t fetchdat)) \ { \ addr64a[0] = addr64a[1] = addr64a[2] = addr64a[3] = 0x00000000; \ \ @@ -99,7 +99,7 @@ return cpu_state.abrt; \ } \ \ - static int opREP_OUTSB_##size(uint32_t fetchdat) \ + static int opREP_OUTSB_##size(UNUSED(uint32_t fetchdat)) \ { \ if (CNT_REG > 0) { \ uint8_t temp; \ @@ -124,7 +124,7 @@ } \ return cpu_state.abrt; \ } \ - static int opREP_OUTSW_##size(uint32_t fetchdat) \ + static int opREP_OUTSW_##size(UNUSED(uint32_t fetchdat)) \ { \ if (CNT_REG > 0) { \ uint16_t temp; \ @@ -149,7 +149,7 @@ } \ return cpu_state.abrt; \ } \ - static int opREP_OUTSL_##size(uint32_t fetchdat) \ + static int opREP_OUTSL_##size(UNUSED(uint32_t fetchdat)) \ { \ if (CNT_REG > 0) { \ uint32_t temp; \ @@ -175,7 +175,7 @@ return cpu_state.abrt; \ } \ \ - static int opREP_MOVSB_##size(uint32_t fetchdat) \ + static int opREP_MOVSB_##size(UNUSED(uint32_t fetchdat)) \ { \ int cycles_end = cycles - ((is386 && cpu_use_dynarec) ? 1000 : 100); \ addr64 = addr64_2 = 0x00000000; \ @@ -223,7 +223,7 @@ } \ return cpu_state.abrt; \ } \ - static int opREP_MOVSW_##size(uint32_t fetchdat) \ + static int opREP_MOVSW_##size(UNUSED(uint32_t fetchdat)) \ { \ int cycles_end = cycles - ((is386 && cpu_use_dynarec) ? 1000 : 100); \ addr64a[0] = addr64a[1] = 0x00000000; \ @@ -272,7 +272,7 @@ } \ return cpu_state.abrt; \ } \ - static int opREP_MOVSL_##size(uint32_t fetchdat) \ + static int opREP_MOVSL_##size(UNUSED(uint32_t fetchdat)) \ { \ int cycles_end = cycles - ((is386 && cpu_use_dynarec) ? 1000 : 100); \ addr64a[0] = addr64a[1] = addr64a[2] = addr64a[3] = 0x00000000; \ @@ -322,7 +322,7 @@ return cpu_state.abrt; \ } \ \ - static int opREP_STOSB_##size(uint32_t fetchdat) \ + static int opREP_STOSB_##size(UNUSED(uint32_t fetchdat)) \ { \ int cycles_end = cycles - ((is386 && cpu_use_dynarec) ? 1000 : 100); \ if (trap) \ @@ -350,7 +350,7 @@ } \ return cpu_state.abrt; \ } \ - static int opREP_STOSW_##size(uint32_t fetchdat) \ + static int opREP_STOSW_##size(UNUSED(uint32_t fetchdat)) \ { \ int cycles_end = cycles - ((is386 && cpu_use_dynarec) ? 1000 : 100); \ if (trap) \ @@ -378,7 +378,7 @@ } \ return cpu_state.abrt; \ } \ - static int opREP_STOSL_##size(uint32_t fetchdat) \ + static int opREP_STOSL_##size(UNUSED(uint32_t fetchdat)) \ { \ int cycles_end = cycles - ((is386 && cpu_use_dynarec) ? 1000 : 100); \ if (trap) \ @@ -407,7 +407,7 @@ return cpu_state.abrt; \ } \ \ - static int opREP_LODSB_##size(uint32_t fetchdat) \ + static int opREP_LODSB_##size(UNUSED(uint32_t fetchdat)) \ { \ int cycles_end = cycles - ((is386 && cpu_use_dynarec) ? 1000 : 100); \ if (trap) \ @@ -435,7 +435,7 @@ } \ return cpu_state.abrt; \ } \ - static int opREP_LODSW_##size(uint32_t fetchdat) \ + static int opREP_LODSW_##size(UNUSED(uint32_t fetchdat)) \ { \ int cycles_end = cycles - ((is386 && cpu_use_dynarec) ? 1000 : 100); \ if (trap) \ @@ -463,7 +463,7 @@ } \ return cpu_state.abrt; \ } \ - static int opREP_LODSL_##size(uint32_t fetchdat) \ + static int opREP_LODSL_##size(UNUSED(uint32_t fetchdat)) \ { \ int cycles_end = cycles - ((is386 && cpu_use_dynarec) ? 1000 : 100); \ if (trap) \ @@ -495,7 +495,7 @@ #define CHEK_READ(a, b, c) #define REP_OPS_CMPS_SCAS(size, CNT_REG, SRC_REG, DEST_REG, FV) \ - static int opREP_CMPSB_##size(uint32_t fetchdat) \ + static int opREP_CMPSB_##size(UNUSED(uint32_t fetchdat)) \ { \ int tempz; \ \ @@ -545,7 +545,7 @@ } \ return cpu_state.abrt; \ } \ - static int opREP_CMPSW_##size(uint32_t fetchdat) \ + static int opREP_CMPSW_##size(UNUSED(uint32_t fetchdat)) \ { \ int tempz; \ \ @@ -596,7 +596,7 @@ } \ return cpu_state.abrt; \ } \ - static int opREP_CMPSL_##size(uint32_t fetchdat) \ + static int opREP_CMPSL_##size(UNUSED(uint32_t fetchdat)) \ { \ int tempz; \ \ @@ -648,7 +648,7 @@ return cpu_state.abrt; \ } \ \ - static int opREP_SCASB_##size(uint32_t fetchdat) \ + static int opREP_SCASB_##size(UNUSED(uint32_t fetchdat)) \ { \ int tempz; \ int cycles_end = cycles - 1000; \ @@ -680,7 +680,7 @@ } \ return cpu_state.abrt; \ } \ - static int opREP_SCASW_##size(uint32_t fetchdat) \ + static int opREP_SCASW_##size(UNUSED(uint32_t fetchdat)) \ { \ int tempz; \ int cycles_end = cycles - 1000; \ @@ -712,7 +712,7 @@ } \ return cpu_state.abrt; \ } \ - static int opREP_SCASL_##size(uint32_t fetchdat) \ + static int opREP_SCASL_##size(UNUSED(uint32_t fetchdat)) \ { \ int tempz; \ int cycles_end = cycles - 1000; \ diff --git a/src/cpu/x86_ops_ret.h b/src/cpu/x86_ops_ret.h index d30d4eb8f..935fb5aa0 100644 --- a/src/cpu/x86_ops_ret.h +++ b/src/cpu/x86_ops_ret.h @@ -47,7 +47,7 @@ cycles -= timing_retf_rm; static int -opRETF_a16(uint32_t fetchdat) +opRETF_a16(UNUSED(uint32_t fetchdat)) { int cycles_old = cycles; UN_USED(cycles_old); @@ -60,7 +60,7 @@ opRETF_a16(uint32_t fetchdat) return 0; } static int -opRETF_a32(uint32_t fetchdat) +opRETF_a32(UNUSED(uint32_t fetchdat)) { int cycles_old = cycles; UN_USED(cycles_old); @@ -103,7 +103,7 @@ opRETF_a32_imm(uint32_t fetchdat) } static int -opIRET_186(uint32_t fetchdat) +opIRET_186(UNUSED(uint32_t fetchdat)) { int cycles_old = cycles; UN_USED(cycles_old); @@ -146,7 +146,7 @@ opIRET_186(uint32_t fetchdat) } static int -opIRET_286(uint32_t fetchdat) +opIRET_286(UNUSED(uint32_t fetchdat)) { int cycles_old = cycles; UN_USED(cycles_old); @@ -189,7 +189,7 @@ opIRET_286(uint32_t fetchdat) } static int -opIRET(uint32_t fetchdat) +opIRET(UNUSED(uint32_t fetchdat)) { int cycles_old = cycles; UN_USED(cycles_old); @@ -260,7 +260,7 @@ opIRET(uint32_t fetchdat) } static int -opIRETD(uint32_t fetchdat) +opIRETD(UNUSED(uint32_t fetchdat)) { int cycles_old = cycles; UN_USED(cycles_old); diff --git a/src/cpu/x86_ops_ret_2386.h b/src/cpu/x86_ops_ret_2386.h index ca85bf2b0..155925dfe 100644 --- a/src/cpu/x86_ops_ret_2386.h +++ b/src/cpu/x86_ops_ret_2386.h @@ -47,7 +47,7 @@ cycles -= timing_retf_rm; static int -opRETF_a16(uint32_t fetchdat) +opRETF_a16(UNUSED(uint32_t fetchdat)) { int cycles_old = cycles; UN_USED(cycles_old); @@ -60,7 +60,7 @@ opRETF_a16(uint32_t fetchdat) return 0; } static int -opRETF_a32(uint32_t fetchdat) +opRETF_a32(UNUSED(uint32_t fetchdat)) { int cycles_old = cycles; UN_USED(cycles_old); @@ -103,7 +103,7 @@ opRETF_a32_imm(uint32_t fetchdat) } static int -opIRET_186(uint32_t fetchdat) +opIRET_186(UNUSED(uint32_t fetchdat)) { int cycles_old = cycles; UN_USED(cycles_old); @@ -144,7 +144,7 @@ opIRET_186(uint32_t fetchdat) } static int -opIRET_286(uint32_t fetchdat) +opIRET_286(UNUSED(uint32_t fetchdat)) { int cycles_old = cycles; UN_USED(cycles_old); @@ -185,7 +185,7 @@ opIRET_286(uint32_t fetchdat) } static int -opIRET(uint32_t fetchdat) +opIRET(UNUSED(uint32_t fetchdat)) { int cycles_old = cycles; UN_USED(cycles_old); @@ -254,7 +254,7 @@ opIRET(uint32_t fetchdat) } static int -opIRETD(uint32_t fetchdat) +opIRETD(UNUSED(uint32_t fetchdat)) { int cycles_old = cycles; UN_USED(cycles_old); diff --git a/src/cpu/x86_ops_stack.h b/src/cpu/x86_ops_stack.h index fbf603ddb..f5d608fbb 100644 --- a/src/cpu/x86_ops_stack.h +++ b/src/cpu/x86_ops_stack.h @@ -1,5 +1,5 @@ #define PUSH_W_OP(reg) \ - static int opPUSH_##reg(uint32_t fetchdat) \ + static int opPUSH_##reg(UNUSED(uint32_t fetchdat)) \ { \ PUSH_W(reg); \ CLOCK_CYCLES((is486) ? 1 : 2); \ @@ -8,7 +8,7 @@ } #define PUSH_L_OP(reg) \ - static int opPUSH_##reg(uint32_t fetchdat) \ + static int opPUSH_##reg(UNUSED(uint32_t fetchdat)) \ { \ PUSH_L(reg); \ CLOCK_CYCLES((is486) ? 1 : 2); \ @@ -17,7 +17,7 @@ } #define POP_W_OP(reg) \ - static int opPOP_##reg(uint32_t fetchdat) \ + static int opPOP_##reg(UNUSED(uint32_t fetchdat)) \ { \ reg = POP_W(); \ CLOCK_CYCLES((is486) ? 1 : 4); \ @@ -26,7 +26,7 @@ } #define POP_L_OP(reg) \ - static int opPOP_##reg(uint32_t fetchdat) \ + static int opPOP_##reg(UNUSED(uint32_t fetchdat)) \ { \ reg = POP_L(); \ CLOCK_CYCLES((is486) ? 1 : 4); \ @@ -71,7 +71,7 @@ POP_L_OP(EBP) POP_L_OP(ESP) static int -opPUSHA_w(uint32_t fetchdat) +opPUSHA_w(UNUSED(uint32_t fetchdat)) { if (stack32) { writememw(ss, ESP - 2, AX); @@ -101,7 +101,7 @@ opPUSHA_w(uint32_t fetchdat) return cpu_state.abrt; } static int -opPUSHA_l(uint32_t fetchdat) +opPUSHA_l(UNUSED(uint32_t fetchdat)) { if (stack32) { writememl(ss, ESP - 4, EAX); @@ -132,7 +132,7 @@ opPUSHA_l(uint32_t fetchdat) } static int -opPOPA_w(uint32_t fetchdat) +opPOPA_w(UNUSED(uint32_t fetchdat)) { if (stack32) { DI = readmemw(ss, ESP); @@ -186,7 +186,7 @@ opPOPA_w(uint32_t fetchdat) return 0; } static int -opPOPA_l(uint32_t fetchdat) +opPOPA_l(UNUSED(uint32_t fetchdat)) { if (stack32) { EDI = readmeml(ss, ESP); @@ -250,7 +250,7 @@ opPUSH_imm_w(uint32_t fetchdat) return cpu_state.abrt; } static int -opPUSH_imm_l(uint32_t fetchdat) +opPUSH_imm_l(UNUSED(uint32_t fetchdat)) { uint32_t val = getlong(); if (cpu_state.abrt) @@ -550,7 +550,7 @@ opENTER_l(uint32_t fetchdat) } static int -opLEAVE_w(uint32_t fetchdat) +opLEAVE_w(UNUSED(uint32_t fetchdat)) { uint32_t tempESP = ESP; uint16_t temp; @@ -568,7 +568,7 @@ opLEAVE_w(uint32_t fetchdat) return 0; } static int -opLEAVE_l(uint32_t fetchdat) +opLEAVE_l(UNUSED(uint32_t fetchdat)) { uint32_t tempESP = ESP; uint32_t temp; @@ -587,14 +587,14 @@ opLEAVE_l(uint32_t fetchdat) } #define PUSH_SEG_OPS(seg) \ - static int opPUSH_##seg##_w(uint32_t fetchdat) \ + static int opPUSH_##seg##_w(UNUSED(uint32_t fetchdat)) \ { \ PUSH_W(seg); \ CLOCK_CYCLES(2); \ PREFETCH_RUN(2, 1, -1, 0, 0, 1, 0, 0); \ return cpu_state.abrt; \ } \ - static int opPUSH_##seg##_l(uint32_t fetchdat) \ + static int opPUSH_##seg##_l(UNUSED(uint32_t fetchdat)) \ { \ PUSH_L(seg); \ CLOCK_CYCLES(2); \ @@ -603,7 +603,7 @@ opLEAVE_l(uint32_t fetchdat) } #define POP_SEG_OPS(seg, realseg) \ - static int opPOP_##seg##_w(uint32_t fetchdat) \ + static int opPOP_##seg##_w(UNUSED(uint32_t fetchdat)) \ { \ uint16_t temp_seg; \ uint32_t temp_esp = ESP; \ @@ -617,7 +617,7 @@ opLEAVE_l(uint32_t fetchdat) PREFETCH_RUN(is486 ? 3 : 7, 1, -1, 0, 0, 1, 0, 0); \ return cpu_state.abrt; \ } \ - static int opPOP_##seg##_l(uint32_t fetchdat) \ + static int opPOP_##seg##_l(UNUSED(uint32_t fetchdat)) \ { \ uint32_t temp_seg; \ uint32_t temp_esp = ESP; \ diff --git a/src/cpu/x86_ops_string.h b/src/cpu/x86_ops_string.h index 619386fcb..d3a7d89a9 100644 --- a/src/cpu/x86_ops_string.h +++ b/src/cpu/x86_ops_string.h @@ -1,5 +1,5 @@ static int -opMOVSB_a16(uint32_t fetchdat) +opMOVSB_a16(UNUSED(uint32_t fetchdat)) { uint8_t temp; @@ -35,7 +35,7 @@ opMOVSB_a16(uint32_t fetchdat) return 0; } static int -opMOVSB_a32(uint32_t fetchdat) +opMOVSB_a32(UNUSED(uint32_t fetchdat)) { uint8_t temp; @@ -71,7 +71,7 @@ opMOVSB_a32(uint32_t fetchdat) } static int -opMOVSW_a16(uint32_t fetchdat) +opMOVSW_a16(UNUSED(uint32_t fetchdat)) { uint16_t temp; @@ -107,7 +107,7 @@ opMOVSW_a16(uint32_t fetchdat) return 0; } static int -opMOVSW_a32(uint32_t fetchdat) +opMOVSW_a32(UNUSED(uint32_t fetchdat)) { uint16_t temp; @@ -144,7 +144,7 @@ opMOVSW_a32(uint32_t fetchdat) } static int -opMOVSL_a16(uint32_t fetchdat) +opMOVSL_a16(UNUSED(uint32_t fetchdat)) { uint32_t temp; @@ -180,7 +180,7 @@ opMOVSL_a16(uint32_t fetchdat) return 0; } static int -opMOVSL_a32(uint32_t fetchdat) +opMOVSL_a32(UNUSED(uint32_t fetchdat)) { uint32_t temp; @@ -217,7 +217,7 @@ opMOVSL_a32(uint32_t fetchdat) } static int -opCMPSB_a16(uint32_t fetchdat) +opCMPSB_a16(UNUSED(uint32_t fetchdat)) { uint8_t src; uint8_t dst; @@ -258,7 +258,7 @@ opCMPSB_a16(uint32_t fetchdat) return 0; } static int -opCMPSB_a32(uint32_t fetchdat) +opCMPSB_a32(UNUSED(uint32_t fetchdat)) { uint8_t src; uint8_t dst; @@ -300,7 +300,7 @@ opCMPSB_a32(uint32_t fetchdat) } static int -opCMPSW_a16(uint32_t fetchdat) +opCMPSW_a16(UNUSED(uint32_t fetchdat)) { uint16_t src; uint16_t dst; @@ -342,7 +342,7 @@ opCMPSW_a16(uint32_t fetchdat) return 0; } static int -opCMPSW_a32(uint32_t fetchdat) +opCMPSW_a32(UNUSED(uint32_t fetchdat)) { uint16_t src; uint16_t dst; @@ -385,7 +385,7 @@ opCMPSW_a32(uint32_t fetchdat) } static int -opCMPSL_a16(uint32_t fetchdat) +opCMPSL_a16(UNUSED(uint32_t fetchdat)) { uint32_t src; uint32_t dst; @@ -427,7 +427,7 @@ opCMPSL_a16(uint32_t fetchdat) return 0; } static int -opCMPSL_a32(uint32_t fetchdat) +opCMPSL_a32(UNUSED(uint32_t fetchdat)) { uint32_t src; uint32_t dst; @@ -470,7 +470,7 @@ opCMPSL_a32(uint32_t fetchdat) } static int -opSTOSB_a16(uint32_t fetchdat) +opSTOSB_a16(UNUSED(uint32_t fetchdat)) { SEG_CHECK_WRITE(&cpu_state.seg_es); CHECK_WRITE(&cpu_state.seg_es, DI, DI); @@ -486,7 +486,7 @@ opSTOSB_a16(uint32_t fetchdat) return 0; } static int -opSTOSB_a32(uint32_t fetchdat) +opSTOSB_a32(UNUSED(uint32_t fetchdat)) { SEG_CHECK_WRITE(&cpu_state.seg_es); CHECK_WRITE(&cpu_state.seg_es, EDI, EDI); @@ -503,7 +503,7 @@ opSTOSB_a32(uint32_t fetchdat) } static int -opSTOSW_a16(uint32_t fetchdat) +opSTOSW_a16(UNUSED(uint32_t fetchdat)) { SEG_CHECK_WRITE(&cpu_state.seg_es); CHECK_WRITE(&cpu_state.seg_es, DI, DI + 1UL); @@ -519,7 +519,7 @@ opSTOSW_a16(uint32_t fetchdat) return 0; } static int -opSTOSW_a32(uint32_t fetchdat) +opSTOSW_a32(UNUSED(uint32_t fetchdat)) { SEG_CHECK_WRITE(&cpu_state.seg_es); CHECK_WRITE(&cpu_state.seg_es, EDI, EDI + 1UL); @@ -536,7 +536,7 @@ opSTOSW_a32(uint32_t fetchdat) } static int -opSTOSL_a16(uint32_t fetchdat) +opSTOSL_a16(UNUSED(uint32_t fetchdat)) { SEG_CHECK_WRITE(&cpu_state.seg_es); CHECK_WRITE(&cpu_state.seg_es, DI, DI + 3UL); @@ -552,7 +552,7 @@ opSTOSL_a16(uint32_t fetchdat) return 0; } static int -opSTOSL_a32(uint32_t fetchdat) +opSTOSL_a32(UNUSED(uint32_t fetchdat)) { SEG_CHECK_WRITE(&cpu_state.seg_es); CHECK_WRITE(&cpu_state.seg_es, EDI, EDI + 3UL); @@ -569,7 +569,7 @@ opSTOSL_a32(uint32_t fetchdat) } static int -opLODSB_a16(uint32_t fetchdat) +opLODSB_a16(UNUSED(uint32_t fetchdat)) { uint8_t temp; @@ -588,7 +588,7 @@ opLODSB_a16(uint32_t fetchdat) return 0; } static int -opLODSB_a32(uint32_t fetchdat) +opLODSB_a32(UNUSED(uint32_t fetchdat)) { uint8_t temp; @@ -608,7 +608,7 @@ opLODSB_a32(uint32_t fetchdat) } static int -opLODSW_a16(uint32_t fetchdat) +opLODSW_a16(UNUSED(uint32_t fetchdat)) { uint16_t temp; @@ -627,7 +627,7 @@ opLODSW_a16(uint32_t fetchdat) return 0; } static int -opLODSW_a32(uint32_t fetchdat) +opLODSW_a32(UNUSED(uint32_t fetchdat)) { uint16_t temp; @@ -647,7 +647,7 @@ opLODSW_a32(uint32_t fetchdat) } static int -opLODSL_a16(uint32_t fetchdat) +opLODSL_a16(UNUSED(uint32_t fetchdat)) { uint32_t temp; @@ -666,7 +666,7 @@ opLODSL_a16(uint32_t fetchdat) return 0; } static int -opLODSL_a32(uint32_t fetchdat) +opLODSL_a32(UNUSED(uint32_t fetchdat)) { uint32_t temp; @@ -686,7 +686,7 @@ opLODSL_a32(uint32_t fetchdat) } static int -opSCASB_a16(uint32_t fetchdat) +opSCASB_a16(UNUSED(uint32_t fetchdat)) { uint8_t temp; @@ -705,7 +705,7 @@ opSCASB_a16(uint32_t fetchdat) return 0; } static int -opSCASB_a32(uint32_t fetchdat) +opSCASB_a32(UNUSED(uint32_t fetchdat)) { uint8_t temp; @@ -725,7 +725,7 @@ opSCASB_a32(uint32_t fetchdat) } static int -opSCASW_a16(uint32_t fetchdat) +opSCASW_a16(UNUSED(uint32_t fetchdat)) { uint16_t temp; @@ -744,7 +744,7 @@ opSCASW_a16(uint32_t fetchdat) return 0; } static int -opSCASW_a32(uint32_t fetchdat) +opSCASW_a32(UNUSED(uint32_t fetchdat)) { uint16_t temp; @@ -764,7 +764,7 @@ opSCASW_a32(uint32_t fetchdat) } static int -opSCASL_a16(uint32_t fetchdat) +opSCASL_a16(UNUSED(uint32_t fetchdat)) { uint32_t temp; @@ -783,7 +783,7 @@ opSCASL_a16(uint32_t fetchdat) return 0; } static int -opSCASL_a32(uint32_t fetchdat) +opSCASL_a32(UNUSED(uint32_t fetchdat)) { uint32_t temp; @@ -803,7 +803,7 @@ opSCASL_a32(uint32_t fetchdat) } static int -opINSB_a16(uint32_t fetchdat) +opINSB_a16(UNUSED(uint32_t fetchdat)) { uint8_t temp; @@ -829,7 +829,7 @@ opINSB_a16(uint32_t fetchdat) return 0; } static int -opINSB_a32(uint32_t fetchdat) +opINSB_a32(UNUSED(uint32_t fetchdat)) { uint8_t temp; @@ -856,7 +856,7 @@ opINSB_a32(uint32_t fetchdat) } static int -opINSW_a16(uint32_t fetchdat) +opINSW_a16(UNUSED(uint32_t fetchdat)) { uint16_t temp; @@ -882,7 +882,7 @@ opINSW_a16(uint32_t fetchdat) return 0; } static int -opINSW_a32(uint32_t fetchdat) +opINSW_a32(UNUSED(uint32_t fetchdat)) { uint16_t temp; @@ -909,7 +909,7 @@ opINSW_a32(uint32_t fetchdat) } static int -opINSL_a16(uint32_t fetchdat) +opINSL_a16(UNUSED(uint32_t fetchdat)) { uint32_t temp; @@ -935,7 +935,7 @@ opINSL_a16(uint32_t fetchdat) return 0; } static int -opINSL_a32(uint32_t fetchdat) +opINSL_a32(UNUSED(uint32_t fetchdat)) { uint32_t temp; @@ -962,7 +962,7 @@ opINSL_a32(uint32_t fetchdat) } static int -opOUTSB_a16(uint32_t fetchdat) +opOUTSB_a16(UNUSED(uint32_t fetchdat)) { uint8_t temp; @@ -982,7 +982,7 @@ opOUTSB_a16(uint32_t fetchdat) return 0; } static int -opOUTSB_a32(uint32_t fetchdat) +opOUTSB_a32(UNUSED(uint32_t fetchdat)) { uint8_t temp; @@ -1003,7 +1003,7 @@ opOUTSB_a32(uint32_t fetchdat) } static int -opOUTSW_a16(uint32_t fetchdat) +opOUTSW_a16(UNUSED(uint32_t fetchdat)) { uint16_t temp; @@ -1023,7 +1023,7 @@ opOUTSW_a16(uint32_t fetchdat) return 0; } static int -opOUTSW_a32(uint32_t fetchdat) +opOUTSW_a32(UNUSED(uint32_t fetchdat)) { uint16_t temp; @@ -1044,7 +1044,7 @@ opOUTSW_a32(uint32_t fetchdat) } static int -opOUTSL_a16(uint32_t fetchdat) +opOUTSL_a16(UNUSED(uint32_t fetchdat)) { uint32_t temp; @@ -1064,7 +1064,7 @@ opOUTSL_a16(uint32_t fetchdat) return 0; } static int -opOUTSL_a32(uint32_t fetchdat) +opOUTSL_a32(UNUSED(uint32_t fetchdat)) { uint32_t temp; diff --git a/src/cpu/x86_ops_string_2386.h b/src/cpu/x86_ops_string_2386.h index 98875e54f..32d69d4b2 100644 --- a/src/cpu/x86_ops_string_2386.h +++ b/src/cpu/x86_ops_string_2386.h @@ -1,5 +1,5 @@ static int -opMOVSB_a16(uint32_t fetchdat) +opMOVSB_a16(UNUSED(uint32_t fetchdat)) { uint8_t temp; @@ -35,7 +35,7 @@ opMOVSB_a16(uint32_t fetchdat) return 0; } static int -opMOVSB_a32(uint32_t fetchdat) +opMOVSB_a32(UNUSED(uint32_t fetchdat)) { uint8_t temp; @@ -71,7 +71,7 @@ opMOVSB_a32(uint32_t fetchdat) } static int -opMOVSW_a16(uint32_t fetchdat) +opMOVSW_a16(UNUSED(uint32_t fetchdat)) { uint16_t temp; @@ -107,7 +107,7 @@ opMOVSW_a16(uint32_t fetchdat) return 0; } static int -opMOVSW_a32(uint32_t fetchdat) +opMOVSW_a32(UNUSED(uint32_t fetchdat)) { uint16_t temp; @@ -144,7 +144,7 @@ opMOVSW_a32(uint32_t fetchdat) } static int -opMOVSL_a16(uint32_t fetchdat) +opMOVSL_a16(UNUSED(uint32_t fetchdat)) { uint32_t temp; @@ -180,7 +180,7 @@ opMOVSL_a16(uint32_t fetchdat) return 0; } static int -opMOVSL_a32(uint32_t fetchdat) +opMOVSL_a32(UNUSED(uint32_t fetchdat)) { uint32_t temp; @@ -217,7 +217,7 @@ opMOVSL_a32(uint32_t fetchdat) } static int -opCMPSB_a16(uint32_t fetchdat) +opCMPSB_a16(UNUSED(uint32_t fetchdat)) { uint8_t src; uint8_t dst; @@ -254,7 +254,7 @@ opCMPSB_a16(uint32_t fetchdat) return 0; } static int -opCMPSB_a32(uint32_t fetchdat) +opCMPSB_a32(UNUSED(uint32_t fetchdat)) { uint8_t src; uint8_t dst; @@ -292,7 +292,7 @@ opCMPSB_a32(uint32_t fetchdat) } static int -opCMPSW_a16(uint32_t fetchdat) +opCMPSW_a16(UNUSED(uint32_t fetchdat)) { uint16_t src; uint16_t dst; @@ -330,7 +330,7 @@ opCMPSW_a16(uint32_t fetchdat) return 0; } static int -opCMPSW_a32(uint32_t fetchdat) +opCMPSW_a32(UNUSED(uint32_t fetchdat)) { uint16_t src; uint16_t dst; @@ -369,7 +369,7 @@ opCMPSW_a32(uint32_t fetchdat) } static int -opCMPSL_a16(uint32_t fetchdat) +opCMPSL_a16(UNUSED(uint32_t fetchdat)) { uint32_t src; uint32_t dst; @@ -407,7 +407,7 @@ opCMPSL_a16(uint32_t fetchdat) return 0; } static int -opCMPSL_a32(uint32_t fetchdat) +opCMPSL_a32(UNUSED(uint32_t fetchdat)) { uint32_t src; uint32_t dst; @@ -446,7 +446,7 @@ opCMPSL_a32(uint32_t fetchdat) } static int -opSTOSB_a16(uint32_t fetchdat) +opSTOSB_a16(UNUSED(uint32_t fetchdat)) { SEG_CHECK_WRITE(&cpu_state.seg_es); CHECK_WRITE(&cpu_state.seg_es, DI, DI); @@ -462,7 +462,7 @@ opSTOSB_a16(uint32_t fetchdat) return 0; } static int -opSTOSB_a32(uint32_t fetchdat) +opSTOSB_a32(UNUSED(uint32_t fetchdat)) { SEG_CHECK_WRITE(&cpu_state.seg_es); CHECK_WRITE(&cpu_state.seg_es, EDI, EDI); @@ -479,7 +479,7 @@ opSTOSB_a32(uint32_t fetchdat) } static int -opSTOSW_a16(uint32_t fetchdat) +opSTOSW_a16(UNUSED(uint32_t fetchdat)) { SEG_CHECK_WRITE(&cpu_state.seg_es); CHECK_WRITE(&cpu_state.seg_es, DI, DI + 1UL); @@ -495,7 +495,7 @@ opSTOSW_a16(uint32_t fetchdat) return 0; } static int -opSTOSW_a32(uint32_t fetchdat) +opSTOSW_a32(UNUSED(uint32_t fetchdat)) { SEG_CHECK_WRITE(&cpu_state.seg_es); CHECK_WRITE(&cpu_state.seg_es, EDI, EDI + 1UL); @@ -512,7 +512,7 @@ opSTOSW_a32(uint32_t fetchdat) } static int -opSTOSL_a16(uint32_t fetchdat) +opSTOSL_a16(UNUSED(uint32_t fetchdat)) { SEG_CHECK_WRITE(&cpu_state.seg_es); CHECK_WRITE(&cpu_state.seg_es, DI, DI + 3UL); @@ -528,7 +528,7 @@ opSTOSL_a16(uint32_t fetchdat) return 0; } static int -opSTOSL_a32(uint32_t fetchdat) +opSTOSL_a32(UNUSED(uint32_t fetchdat)) { SEG_CHECK_WRITE(&cpu_state.seg_es); CHECK_WRITE(&cpu_state.seg_es, EDI, EDI + 3UL); @@ -545,7 +545,7 @@ opSTOSL_a32(uint32_t fetchdat) } static int -opLODSB_a16(uint32_t fetchdat) +opLODSB_a16(UNUSED(uint32_t fetchdat)) { uint8_t temp; @@ -564,7 +564,7 @@ opLODSB_a16(uint32_t fetchdat) return 0; } static int -opLODSB_a32(uint32_t fetchdat) +opLODSB_a32(UNUSED(uint32_t fetchdat)) { uint8_t temp; @@ -584,7 +584,7 @@ opLODSB_a32(uint32_t fetchdat) } static int -opLODSW_a16(uint32_t fetchdat) +opLODSW_a16(UNUSED(uint32_t fetchdat)) { uint16_t temp; @@ -603,7 +603,7 @@ opLODSW_a16(uint32_t fetchdat) return 0; } static int -opLODSW_a32(uint32_t fetchdat) +opLODSW_a32(UNUSED(uint32_t fetchdat)) { uint16_t temp; @@ -623,7 +623,7 @@ opLODSW_a32(uint32_t fetchdat) } static int -opLODSL_a16(uint32_t fetchdat) +opLODSL_a16(UNUSED(uint32_t fetchdat)) { uint32_t temp; @@ -642,7 +642,7 @@ opLODSL_a16(uint32_t fetchdat) return 0; } static int -opLODSL_a32(uint32_t fetchdat) +opLODSL_a32(UNUSED(uint32_t fetchdat)) { uint32_t temp; @@ -662,7 +662,7 @@ opLODSL_a32(uint32_t fetchdat) } static int -opSCASB_a16(uint32_t fetchdat) +opSCASB_a16(UNUSED(uint32_t fetchdat)) { uint8_t temp; @@ -681,7 +681,7 @@ opSCASB_a16(uint32_t fetchdat) return 0; } static int -opSCASB_a32(uint32_t fetchdat) +opSCASB_a32(UNUSED(uint32_t fetchdat)) { uint8_t temp; @@ -701,7 +701,7 @@ opSCASB_a32(uint32_t fetchdat) } static int -opSCASW_a16(uint32_t fetchdat) +opSCASW_a16(UNUSED(uint32_t fetchdat)) { uint16_t temp; @@ -720,7 +720,7 @@ opSCASW_a16(uint32_t fetchdat) return 0; } static int -opSCASW_a32(uint32_t fetchdat) +opSCASW_a32(UNUSED(uint32_t fetchdat)) { uint16_t temp; @@ -740,7 +740,7 @@ opSCASW_a32(uint32_t fetchdat) } static int -opSCASL_a16(uint32_t fetchdat) +opSCASL_a16(UNUSED(uint32_t fetchdat)) { uint32_t temp; @@ -759,7 +759,7 @@ opSCASL_a16(uint32_t fetchdat) return 0; } static int -opSCASL_a32(uint32_t fetchdat) +opSCASL_a32(UNUSED(uint32_t fetchdat)) { uint32_t temp; @@ -779,7 +779,7 @@ opSCASL_a32(uint32_t fetchdat) } static int -opINSB_a16(uint32_t fetchdat) +opINSB_a16(UNUSED(uint32_t fetchdat)) { uint8_t temp; @@ -805,7 +805,7 @@ opINSB_a16(uint32_t fetchdat) return 0; } static int -opINSB_a32(uint32_t fetchdat) +opINSB_a32(UNUSED(uint32_t fetchdat)) { uint8_t temp; @@ -832,7 +832,7 @@ opINSB_a32(uint32_t fetchdat) } static int -opINSW_a16(uint32_t fetchdat) +opINSW_a16(UNUSED(uint32_t fetchdat)) { uint16_t temp; @@ -858,7 +858,7 @@ opINSW_a16(uint32_t fetchdat) return 0; } static int -opINSW_a32(uint32_t fetchdat) +opINSW_a32(UNUSED(uint32_t fetchdat)) { uint16_t temp; @@ -885,7 +885,7 @@ opINSW_a32(uint32_t fetchdat) } static int -opINSL_a16(uint32_t fetchdat) +opINSL_a16(UNUSED(uint32_t fetchdat)) { uint32_t temp; @@ -911,7 +911,7 @@ opINSL_a16(uint32_t fetchdat) return 0; } static int -opINSL_a32(uint32_t fetchdat) +opINSL_a32(UNUSED(uint32_t fetchdat)) { uint32_t temp; @@ -938,7 +938,7 @@ opINSL_a32(uint32_t fetchdat) } static int -opOUTSB_a16(uint32_t fetchdat) +opOUTSB_a16(UNUSED(uint32_t fetchdat)) { uint8_t temp; @@ -958,7 +958,7 @@ opOUTSB_a16(uint32_t fetchdat) return 0; } static int -opOUTSB_a32(uint32_t fetchdat) +opOUTSB_a32(UNUSED(uint32_t fetchdat)) { uint8_t temp; @@ -979,7 +979,7 @@ opOUTSB_a32(uint32_t fetchdat) } static int -opOUTSW_a16(uint32_t fetchdat) +opOUTSW_a16(UNUSED(uint32_t fetchdat)) { uint16_t temp; @@ -999,7 +999,7 @@ opOUTSW_a16(uint32_t fetchdat) return 0; } static int -opOUTSW_a32(uint32_t fetchdat) +opOUTSW_a32(UNUSED(uint32_t fetchdat)) { uint16_t temp; @@ -1020,7 +1020,7 @@ opOUTSW_a32(uint32_t fetchdat) } static int -opOUTSL_a16(uint32_t fetchdat) +opOUTSL_a16(UNUSED(uint32_t fetchdat)) { uint32_t temp; @@ -1040,7 +1040,7 @@ opOUTSL_a16(uint32_t fetchdat) return 0; } static int -opOUTSL_a32(uint32_t fetchdat) +opOUTSL_a32(UNUSED(uint32_t fetchdat)) { uint32_t temp; diff --git a/src/cpu/x86_ops_xchg.h b/src/cpu/x86_ops_xchg.h index 70e7be58c..826181a8e 100644 --- a/src/cpu/x86_ops_xchg.h +++ b/src/cpu/x86_ops_xchg.h @@ -116,7 +116,7 @@ opXCHG_l_a32(uint32_t fetchdat) } static int -opXCHG_AX_BX(uint32_t fetchdat) +opXCHG_AX_BX(UNUSED(uint32_t fetchdat)) { uint16_t temp = AX; AX = BX; @@ -126,7 +126,7 @@ opXCHG_AX_BX(uint32_t fetchdat) return 0; } static int -opXCHG_AX_CX(uint32_t fetchdat) +opXCHG_AX_CX(UNUSED(uint32_t fetchdat)) { uint16_t temp = AX; AX = CX; @@ -136,7 +136,7 @@ opXCHG_AX_CX(uint32_t fetchdat) return 0; } static int -opXCHG_AX_DX(uint32_t fetchdat) +opXCHG_AX_DX(UNUSED(uint32_t fetchdat)) { uint16_t temp = AX; AX = DX; @@ -146,7 +146,7 @@ opXCHG_AX_DX(uint32_t fetchdat) return 0; } static int -opXCHG_AX_SI(uint32_t fetchdat) +opXCHG_AX_SI(UNUSED(uint32_t fetchdat)) { uint16_t temp = AX; AX = SI; @@ -156,7 +156,7 @@ opXCHG_AX_SI(uint32_t fetchdat) return 0; } static int -opXCHG_AX_DI(uint32_t fetchdat) +opXCHG_AX_DI(UNUSED(uint32_t fetchdat)) { uint16_t temp = AX; AX = DI; @@ -166,7 +166,7 @@ opXCHG_AX_DI(uint32_t fetchdat) return 0; } static int -opXCHG_AX_BP(uint32_t fetchdat) +opXCHG_AX_BP(UNUSED(uint32_t fetchdat)) { uint16_t temp = AX; AX = BP; @@ -176,7 +176,7 @@ opXCHG_AX_BP(uint32_t fetchdat) return 0; } static int -opXCHG_AX_SP(uint32_t fetchdat) +opXCHG_AX_SP(UNUSED(uint32_t fetchdat)) { uint16_t temp = AX; AX = SP; @@ -187,7 +187,7 @@ opXCHG_AX_SP(uint32_t fetchdat) } static int -opXCHG_EAX_EBX(uint32_t fetchdat) +opXCHG_EAX_EBX(UNUSED(uint32_t fetchdat)) { uint32_t temp = EAX; EAX = EBX; @@ -197,7 +197,7 @@ opXCHG_EAX_EBX(uint32_t fetchdat) return 0; } static int -opXCHG_EAX_ECX(uint32_t fetchdat) +opXCHG_EAX_ECX(UNUSED(uint32_t fetchdat)) { uint32_t temp = EAX; EAX = ECX; @@ -207,7 +207,7 @@ opXCHG_EAX_ECX(uint32_t fetchdat) return 0; } static int -opXCHG_EAX_EDX(uint32_t fetchdat) +opXCHG_EAX_EDX(UNUSED(uint32_t fetchdat)) { uint32_t temp = EAX; EAX = EDX; @@ -217,7 +217,7 @@ opXCHG_EAX_EDX(uint32_t fetchdat) return 0; } static int -opXCHG_EAX_ESI(uint32_t fetchdat) +opXCHG_EAX_ESI(UNUSED(uint32_t fetchdat)) { uint32_t temp = EAX; EAX = ESI; @@ -227,7 +227,7 @@ opXCHG_EAX_ESI(uint32_t fetchdat) return 0; } static int -opXCHG_EAX_EDI(uint32_t fetchdat) +opXCHG_EAX_EDI(UNUSED(uint32_t fetchdat)) { uint32_t temp = EAX; EAX = EDI; @@ -237,7 +237,7 @@ opXCHG_EAX_EDI(uint32_t fetchdat) return 0; } static int -opXCHG_EAX_EBP(uint32_t fetchdat) +opXCHG_EAX_EBP(UNUSED(uint32_t fetchdat)) { uint32_t temp = EAX; EAX = EBP; @@ -247,7 +247,7 @@ opXCHG_EAX_EBP(uint32_t fetchdat) return 0; } static int -opXCHG_EAX_ESP(uint32_t fetchdat) +opXCHG_EAX_ESP(UNUSED(uint32_t fetchdat)) { uint32_t temp = EAX; EAX = ESP; @@ -258,7 +258,7 @@ opXCHG_EAX_ESP(uint32_t fetchdat) } #define opBSWAP(reg) \ - static int opBSWAP_##reg(uint32_t fetchdat) \ + static int opBSWAP_##reg(UNUSED(uint32_t fetchdat)) \ { \ reg = (reg >> 24) | ((reg >> 8) & 0xff00) | ((reg << 8) & 0xff0000) | ((reg << 24) & 0xff000000); \ CLOCK_CYCLES(1); \ @@ -275,4 +275,4 @@ opBSWAP(ESI) opBSWAP(EDI) opBSWAP(EBP) opBSWAP(ESP) - // clang-format on +// clang-format on diff --git a/src/cpu/x87.c b/src/cpu/x87.c index 3b06cab3c..fecca0772 100644 --- a/src/cpu/x87.c +++ b/src/cpu/x87.c @@ -20,6 +20,7 @@ #include "softfloat3e/config.h" #include "softfloat3e/fpu_trans.h" #include "softfloat3e/specialize.h" +#include <86box/plat_unused.h> uint32_t x87_pc_off; uint32_t x87_op_off; @@ -312,7 +313,7 @@ FPU_write_eflags_fpu_compare(int float_relation) } uint16_t -FPU_exception(uint32_t fetchdat, uint16_t exceptions, int store) +FPU_exception(UNUSED(uint32_t fetchdat), uint16_t exceptions, int store) { uint16_t status; uint16_t unmasked; diff --git a/src/cpu/x87_ops.h b/src/cpu/x87_ops.h index d33122b5c..f1362bf76 100644 --- a/src/cpu/x87_ops.h +++ b/src/cpu/x87_ops.h @@ -542,7 +542,7 @@ op_nofpu_a32(uint32_t fetchdat) #ifdef FPU_8087 static int -FPU_ILLEGAL_a16(uint32_t fetchdat) +FPU_ILLEGAL_a16(UNUSED(uint32_t fetchdat)) { geteaw(); wait(timing_rr, 0); diff --git a/src/cpu/x87_ops_arith.h b/src/cpu/x87_ops_arith.h index 31c26231b..8d0c02167 100644 --- a/src/cpu/x87_ops_arith.h +++ b/src/cpu/x87_ops_arith.h @@ -1,5 +1,5 @@ #define opFPU(name, optype, a_size, load_var, get, use_var, cycle_postfix) \ - static int opFADD##name##_a##a_size(uint32_t fetchdat) \ + static int opFADD##name##_a##a_size(UNUSED(uint32_t fetchdat)) \ { \ optype t; \ FP_ENTER(); \ @@ -18,7 +18,7 @@ CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fadd##cycle_postfix) : ((x87_concurrency.fadd##cycle_postfix) * cpu_multi)); \ return 0; \ } \ - static int opFCOM##name##_a##a_size(uint32_t fetchdat) \ + static int opFCOM##name##_a##a_size(UNUSED(uint32_t fetchdat)) \ { \ optype t; \ FP_ENTER(); \ @@ -27,13 +27,13 @@ load_var = get(); \ if (cpu_state.abrt) \ return 1; \ - cpu_state.npxs &= ~(FPU_SW_C0 | FPU_SW_C2 | FPU_SW_C3); \ + cpu_state.npxs &= ~(FPU_SW_C0 | FPU_SW_C2 | FPU_SW_C3); \ cpu_state.npxs |= x87_compare(ST(0), (double) use_var); \ CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fcom##cycle_postfix) : ((x87_timings.fcom##cycle_postfix) * cpu_multi)); \ CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fcom##cycle_postfix) : ((x87_concurrency.fcom##cycle_postfix) * cpu_multi)); \ return 0; \ } \ - static int opFCOMP##name##_a##a_size(uint32_t fetchdat) \ + static int opFCOMP##name##_a##a_size(UNUSED(uint32_t fetchdat)) \ { \ optype t; \ FP_ENTER(); \ @@ -42,14 +42,14 @@ load_var = get(); \ if (cpu_state.abrt) \ return 1; \ - cpu_state.npxs &= ~(FPU_SW_C0 | FPU_SW_C2 | FPU_SW_C3); \ + cpu_state.npxs &= ~(FPU_SW_C0 | FPU_SW_C2 | FPU_SW_C3); \ cpu_state.npxs |= x87_compare(ST(0), (double) use_var); \ x87_pop(); \ CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fcom##cycle_postfix) : ((x87_timings.fcom##cycle_postfix) * cpu_multi)); \ CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fcom##cycle_postfix) : ((x87_concurrency.fcom##cycle_postfix) * cpu_multi)); \ return 0; \ } \ - static int opFDIV##name##_a##a_size(uint32_t fetchdat) \ + static int opFDIV##name##_a##a_size(UNUSED(uint32_t fetchdat)) \ { \ optype t; \ FP_ENTER(); \ @@ -64,7 +64,7 @@ CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fadd##cycle_postfix) : ((x87_concurrency.fadd##cycle_postfix) * cpu_multi)); \ return 0; \ } \ - static int opFDIVR##name##_a##a_size(uint32_t fetchdat) \ + static int opFDIVR##name##_a##a_size(UNUSED(uint32_t fetchdat)) \ { \ optype t; \ FP_ENTER(); \ @@ -79,7 +79,7 @@ CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fdiv##cycle_postfix) : ((x87_concurrency.fdiv##cycle_postfix) * cpu_multi)); \ return 0; \ } \ - static int opFMUL##name##_a##a_size(uint32_t fetchdat) \ + static int opFMUL##name##_a##a_size(UNUSED(uint32_t fetchdat)) \ { \ optype t; \ FP_ENTER(); \ @@ -94,7 +94,7 @@ CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fmul##cycle_postfix) : ((x87_concurrency.fmul##cycle_postfix) * cpu_multi)); \ return 0; \ } \ - static int opFSUB##name##_a##a_size(uint32_t fetchdat) \ + static int opFSUB##name##_a##a_size(UNUSED(uint32_t fetchdat)) \ { \ optype t; \ FP_ENTER(); \ @@ -109,7 +109,7 @@ CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fadd##cycle_postfix) : ((x87_concurrency.fadd##cycle_postfix) * cpu_multi)); \ return 0; \ } \ - static int opFSUBR##name##_a##a_size(uint32_t fetchdat) \ + static int opFSUBR##name##_a##a_size(UNUSED(uint32_t fetchdat)) \ { \ optype t; \ FP_ENTER(); \ @@ -208,7 +208,7 @@ opFCOMP(uint32_t fetchdat) } static int -opFCOMPP(uint32_t fetchdat) +opFCOMPP(UNUSED(uint32_t fetchdat)) { uint64_t *p, *q; FP_ENTER(); @@ -229,7 +229,7 @@ opFCOMPP(uint32_t fetchdat) } #ifndef FPU_8087 static int -opFUCOMPP(uint32_t fetchdat) +opFUCOMPP(UNUSED(uint32_t fetchdat)) { FP_ENTER(); cpu_state.pc++; diff --git a/src/cpu/x87_ops_loadstore.h b/src/cpu/x87_ops_loadstore.h index 0936f325b..d0b31ac85 100644 --- a/src/cpu/x87_ops_loadstore.h +++ b/src/cpu/x87_ops_loadstore.h @@ -17,7 +17,7 @@ * Copyright 2016-2019 Miran Grca. */ static int -opFILDiw_a16(uint32_t fetchdat) +opFILDiw_a16(UNUSED(uint32_t fetchdat)) { int16_t temp; FP_ENTER(); @@ -50,7 +50,7 @@ opFILDiw_a32(uint32_t fetchdat) #endif static int -opFISTiw_a16(uint32_t fetchdat) +opFISTiw_a16(UNUSED(uint32_t fetchdat)) { FP_ENTER(); fetch_ea_16(fetchdat); @@ -75,7 +75,7 @@ opFISTiw_a32(uint32_t fetchdat) #endif static int -opFISTPiw_a16(uint32_t fetchdat) +opFISTPiw_a16(UNUSED(uint32_t fetchdat)) { FP_ENTER(); fetch_ea_16(fetchdat); @@ -106,7 +106,7 @@ opFISTPiw_a32(uint32_t fetchdat) #endif static int -opFILDiq_a16(uint32_t fetchdat) +opFILDiq_a16(UNUSED(uint32_t fetchdat)) { int64_t temp64; FP_ENTER(); @@ -145,7 +145,7 @@ opFILDiq_a32(uint32_t fetchdat) #endif static int -FBLD_a16(uint32_t fetchdat) +FBLD_a16(UNUSED(uint32_t fetchdat)) { uint16_t load_reg_hi = 0xffff; uint64_t load_reg_lo = BX_CONST64(0xC000000000000000); @@ -228,7 +228,7 @@ FBLD_a32(uint32_t fetchdat) #endif static int -FBSTP_a16(uint32_t fetchdat) +FBSTP_a16(UNUSED(uint32_t fetchdat)) { double dt; double tempd; @@ -296,7 +296,7 @@ FBSTP_a32(uint32_t fetchdat) #endif static int -FISTPiq_a16(uint32_t fetchdat) +FISTPiq_a16(UNUSED(uint32_t fetchdat)) { int64_t temp64; FP_ENTER(); @@ -337,7 +337,7 @@ FISTPiq_a32(uint32_t fetchdat) #endif static int -opFILDil_a16(uint32_t fetchdat) +opFILDil_a16(UNUSED(uint32_t fetchdat)) { int32_t templ; FP_ENTER(); @@ -370,7 +370,7 @@ opFILDil_a32(uint32_t fetchdat) #endif static int -opFISTil_a16(uint32_t fetchdat) +opFISTil_a16(UNUSED(uint32_t fetchdat)) { FP_ENTER(); fetch_ea_16(fetchdat); @@ -395,7 +395,7 @@ opFISTil_a32(uint32_t fetchdat) #endif static int -opFISTPil_a16(uint32_t fetchdat) +opFISTPil_a16(UNUSED(uint32_t fetchdat)) { FP_ENTER(); fetch_ea_16(fetchdat); @@ -426,7 +426,7 @@ opFISTPil_a32(uint32_t fetchdat) #endif static int -opFLDe_a16(uint32_t fetchdat) +opFLDe_a16(UNUSED(uint32_t fetchdat)) { double t; FP_ENTER(); @@ -459,7 +459,7 @@ opFLDe_a32(uint32_t fetchdat) #endif static int -opFSTPe_a16(uint32_t fetchdat) +opFSTPe_a16(UNUSED(uint32_t fetchdat)) { FP_ENTER(); fetch_ea_16(fetchdat); @@ -490,7 +490,7 @@ opFSTPe_a32(uint32_t fetchdat) #endif static int -opFLDd_a16(uint32_t fetchdat) +opFLDd_a16(UNUSED(uint32_t fetchdat)) { x87_td t; FP_ENTER(); @@ -523,7 +523,7 @@ opFLDd_a32(uint32_t fetchdat) #endif static int -opFSTd_a16(uint32_t fetchdat) +opFSTd_a16(UNUSED(uint32_t fetchdat)) { x87_td t; FP_ENTER(); @@ -552,7 +552,7 @@ opFSTd_a32(uint32_t fetchdat) #endif static int -opFSTPd_a16(uint32_t fetchdat) +opFSTPd_a16(UNUSED(uint32_t fetchdat)) { x87_td t; FP_ENTER(); @@ -587,7 +587,7 @@ opFSTPd_a32(uint32_t fetchdat) #endif static int -opFLDs_a16(uint32_t fetchdat) +opFLDs_a16(UNUSED(uint32_t fetchdat)) { x87_ts ts; FP_ENTER(); @@ -620,7 +620,7 @@ opFLDs_a32(uint32_t fetchdat) #endif static int -opFSTs_a16(uint32_t fetchdat) +opFSTs_a16(UNUSED(uint32_t fetchdat)) { x87_ts ts; FP_ENTER(); @@ -649,7 +649,7 @@ opFSTs_a32(uint32_t fetchdat) #endif static int -opFSTPs_a16(uint32_t fetchdat) +opFSTPs_a16(UNUSED(uint32_t fetchdat)) { x87_ts ts; FP_ENTER(); diff --git a/src/cpu/x87_ops_misc.h b/src/cpu/x87_ops_misc.h index 96750468a..c1f09fda9 100644 --- a/src/cpu/x87_ops_misc.h +++ b/src/cpu/x87_ops_misc.h @@ -12,7 +12,7 @@ opFI(uint32_t fetchdat) } #else static int -opFSTSW_AX(uint32_t fetchdat) +opFSTSW_AX(UNUSED(uint32_t fetchdat)) { FP_ENTER(); cpu_state.pc++; @@ -24,7 +24,7 @@ opFSTSW_AX(uint32_t fetchdat) #endif static int -opFNOP(uint32_t fetchdat) +opFNOP(UNUSED(uint32_t fetchdat)) { FP_ENTER(); cpu_state.pc++; @@ -34,7 +34,7 @@ opFNOP(uint32_t fetchdat) } static int -opFXTRACT(uint32_t fetchdat) +opFXTRACT(UNUSED(uint32_t fetchdat)) { x87_conv_t test; int64_t exp80; @@ -56,7 +56,7 @@ opFXTRACT(uint32_t fetchdat) } static int -opFCLEX(uint32_t fetchdat) +opFCLEX(UNUSED(uint32_t fetchdat)) { FP_ENTER(); cpu_state.pc++; @@ -67,7 +67,7 @@ opFCLEX(uint32_t fetchdat) } static int -opFINIT(uint32_t fetchdat) +opFINIT(UNUSED(uint32_t fetchdat)) { uint64_t *p; FP_ENTER(); @@ -208,7 +208,7 @@ FSTOR(void) return cpu_state.abrt; } static int -opFSTOR_a16(uint32_t fetchdat) +opFSTOR_a16(UNUSED(uint32_t fetchdat)) { FP_ENTER(); fetch_ea_16(fetchdat); @@ -429,7 +429,7 @@ FSAVE(void) return cpu_state.abrt; } static int -opFSAVE_a16(uint32_t fetchdat) +opFSAVE_a16(UNUSED(uint32_t fetchdat)) { FP_ENTER(); fetch_ea_16(fetchdat); @@ -450,7 +450,7 @@ opFSAVE_a32(uint32_t fetchdat) #endif static int -opFSTSW_a16(uint32_t fetchdat) +opFSTSW_a16(UNUSED(uint32_t fetchdat)) { FP_ENTER(); fetch_ea_16(fetchdat); @@ -516,7 +516,7 @@ opFXCH(uint32_t fetchdat) } static int -opFCHS(uint32_t fetchdat) +opFCHS(UNUSED(uint32_t fetchdat)) { FP_ENTER(); cpu_state.pc++; @@ -528,7 +528,7 @@ opFCHS(uint32_t fetchdat) } static int -opFABS(uint32_t fetchdat) +opFABS(UNUSED(uint32_t fetchdat)) { FP_ENTER(); cpu_state.pc++; @@ -540,7 +540,7 @@ opFABS(uint32_t fetchdat) } static int -opFTST(uint32_t fetchdat) +opFTST(UNUSED(uint32_t fetchdat)) { FP_ENTER(); cpu_state.pc++; @@ -555,7 +555,7 @@ opFTST(uint32_t fetchdat) } static int -opFXAM(uint32_t fetchdat) +opFXAM(UNUSED(uint32_t fetchdat)) { FP_ENTER(); cpu_state.pc++; @@ -579,7 +579,7 @@ opFXAM(uint32_t fetchdat) } static int -opFLD1(uint32_t fetchdat) +opFLD1(UNUSED(uint32_t fetchdat)) { FP_ENTER(); cpu_state.pc++; @@ -590,7 +590,7 @@ opFLD1(uint32_t fetchdat) } static int -opFLDL2T(uint32_t fetchdat) +opFLDL2T(UNUSED(uint32_t fetchdat)) { FP_ENTER(); cpu_state.pc++; @@ -601,7 +601,7 @@ opFLDL2T(uint32_t fetchdat) } static int -opFLDL2E(uint32_t fetchdat) +opFLDL2E(UNUSED(uint32_t fetchdat)) { FP_ENTER(); cpu_state.pc++; @@ -612,7 +612,7 @@ opFLDL2E(uint32_t fetchdat) } static int -opFLDPI(uint32_t fetchdat) +opFLDPI(UNUSED(uint32_t fetchdat)) { FP_ENTER(); cpu_state.pc++; @@ -623,7 +623,7 @@ opFLDPI(uint32_t fetchdat) } static int -opFLDEG2(uint32_t fetchdat) +opFLDEG2(UNUSED(uint32_t fetchdat)) { FP_ENTER(); cpu_state.pc++; @@ -634,7 +634,7 @@ opFLDEG2(uint32_t fetchdat) } static int -opFLDLN2(uint32_t fetchdat) +opFLDLN2(UNUSED(uint32_t fetchdat)) { FP_ENTER(); cpu_state.pc++; @@ -645,7 +645,7 @@ opFLDLN2(uint32_t fetchdat) } static int -opFLDZ(uint32_t fetchdat) +opFLDZ(UNUSED(uint32_t fetchdat)) { FP_ENTER(); cpu_state.pc++; @@ -657,7 +657,7 @@ opFLDZ(uint32_t fetchdat) } static int -opF2XM1(uint32_t fetchdat) +opF2XM1(UNUSED(uint32_t fetchdat)) { FP_ENTER(); cpu_state.pc++; @@ -669,7 +669,7 @@ opF2XM1(uint32_t fetchdat) } static int -opFYL2X(uint32_t fetchdat) +opFYL2X(UNUSED(uint32_t fetchdat)) { FP_ENTER(); cpu_state.pc++; @@ -682,7 +682,7 @@ opFYL2X(uint32_t fetchdat) } static int -opFYL2XP1(uint32_t fetchdat) +opFYL2XP1(UNUSED(uint32_t fetchdat)) { FP_ENTER(); cpu_state.pc++; @@ -695,7 +695,7 @@ opFYL2XP1(uint32_t fetchdat) } static int -opFPTAN(uint32_t fetchdat) +opFPTAN(UNUSED(uint32_t fetchdat)) { FP_ENTER(); cpu_state.pc++; @@ -709,7 +709,7 @@ opFPTAN(uint32_t fetchdat) } static int -opFPATAN(uint32_t fetchdat) +opFPATAN(UNUSED(uint32_t fetchdat)) { FP_ENTER(); cpu_state.pc++; @@ -722,7 +722,7 @@ opFPATAN(uint32_t fetchdat) } static int -opFDECSTP(uint32_t fetchdat) +opFDECSTP(UNUSED(uint32_t fetchdat)) { FP_ENTER(); cpu_state.pc++; @@ -737,7 +737,7 @@ opFDECSTP(uint32_t fetchdat) } static int -opFINCSTP(uint32_t fetchdat) +opFINCSTP(UNUSED(uint32_t fetchdat)) { FP_ENTER(); cpu_state.pc++; @@ -752,7 +752,7 @@ opFINCSTP(uint32_t fetchdat) } static int -opFPREM(uint32_t fetchdat) +opFPREM(UNUSED(uint32_t fetchdat)) { int64_t temp64; FP_ENTER(); @@ -773,7 +773,7 @@ opFPREM(uint32_t fetchdat) } static int -opFPREM1(uint32_t fetchdat) +opFPREM1(UNUSED(uint32_t fetchdat)) { int64_t temp64; FP_ENTER(); @@ -794,7 +794,7 @@ opFPREM1(uint32_t fetchdat) } static int -opFSQRT(uint32_t fetchdat) +opFSQRT(UNUSED(uint32_t fetchdat)) { FP_ENTER(); cpu_state.pc++; @@ -807,7 +807,7 @@ opFSQRT(uint32_t fetchdat) #ifndef FPU_8087 static int -opFSINCOS(uint32_t fetchdat) +opFSINCOS(UNUSED(uint32_t fetchdat)) { double td; FP_ENTER(); @@ -824,7 +824,7 @@ opFSINCOS(uint32_t fetchdat) #endif static int -opFRNDINT(uint32_t fetchdat) +opFRNDINT(UNUSED(uint32_t fetchdat)) { double dst0; @@ -839,7 +839,7 @@ opFRNDINT(uint32_t fetchdat) } static int -opFSCALE(uint32_t fetchdat) +opFSCALE(UNUSED(uint32_t fetchdat)) { int64_t temp64; FP_ENTER(); @@ -855,7 +855,7 @@ opFSCALE(uint32_t fetchdat) #ifndef FPU_8087 static int -opFSIN(uint32_t fetchdat) +opFSIN(UNUSED(uint32_t fetchdat)) { FP_ENTER(); cpu_state.pc++; @@ -868,7 +868,7 @@ opFSIN(uint32_t fetchdat) } static int -opFCOS(uint32_t fetchdat) +opFCOS(UNUSED(uint32_t fetchdat)) { FP_ENTER(); cpu_state.pc++; @@ -909,7 +909,7 @@ FLDENV(void) } static int -opFLDENV_a16(uint32_t fetchdat) +opFLDENV_a16(UNUSED(uint32_t fetchdat)) { FP_ENTER(); fetch_ea_16(fetchdat); @@ -930,7 +930,7 @@ opFLDENV_a32(uint32_t fetchdat) #endif static int -opFLDCW_a16(uint32_t fetchdat) +opFLDCW_a16(UNUSED(uint32_t fetchdat)) { uint16_t tempw; FP_ENTER(); @@ -1011,7 +1011,7 @@ FSTENV(void) } static int -opFSTENV_a16(uint32_t fetchdat) +opFSTENV_a16(UNUSED(uint32_t fetchdat)) { FP_ENTER(); fetch_ea_16(fetchdat); @@ -1032,7 +1032,7 @@ opFSTENV_a32(uint32_t fetchdat) #endif static int -opFSTCW_a16(uint32_t fetchdat) +opFSTCW_a16(UNUSED(uint32_t fetchdat)) { FP_ENTER(); fetch_ea_16(fetchdat); diff --git a/src/cpu/x87_ops_sf.h b/src/cpu/x87_ops_sf.h index 31416447e..0d4fee81a 100644 --- a/src/cpu/x87_ops_sf.h +++ b/src/cpu/x87_ops_sf.h @@ -235,7 +235,7 @@ fpu_load_environment(void) } static int -sf_FLDCW_a16(uint32_t fetchdat) +sf_FLDCW_a16(UNUSED(uint32_t fetchdat)) { uint16_t tempw; @@ -288,7 +288,7 @@ sf_FLDCW_a32(uint32_t fetchdat) #endif static int -sf_FNSTCW_a16(uint32_t fetchdat) +sf_FNSTCW_a16(UNUSED(uint32_t fetchdat)) { uint16_t cwd = i387_get_control_word(); @@ -317,7 +317,7 @@ sf_FNSTCW_a32(uint32_t fetchdat) #endif static int -sf_FNSTSW_a16(uint32_t fetchdat) +sf_FNSTSW_a16(UNUSED(uint32_t fetchdat)) { uint16_t swd = i387_get_status_word(); @@ -359,7 +359,7 @@ sf_FI(uint32_t fetchdat) } #else static int -sf_FNSTSW_AX(uint32_t fetchdat) +sf_FNSTSW_AX(UNUSED(uint32_t fetchdat)) { FP_ENTER(); cpu_state.pc++; @@ -371,7 +371,7 @@ sf_FNSTSW_AX(uint32_t fetchdat) #endif static int -sf_FRSTOR_a16(uint32_t fetchdat) +sf_FRSTOR_a16(UNUSED(uint32_t fetchdat)) { floatx80 tmp; int offset; @@ -414,7 +414,7 @@ sf_FRSTOR_a32(uint32_t fetchdat) #endif static int -sf_FNSAVE_a16(uint32_t fetchdat) +sf_FNSAVE_a16(UNUSED(uint32_t fetchdat)) { floatx80 stn; int offset; @@ -488,7 +488,7 @@ sf_FNSAVE_a32(uint32_t fetchdat) #endif static int -sf_FNCLEX(uint32_t fetchdat) +sf_FNCLEX(UNUSED(uint32_t fetchdat)) { FP_ENTER(); cpu_state.pc++; @@ -499,7 +499,7 @@ sf_FNCLEX(uint32_t fetchdat) } static int -sf_FNINIT(uint32_t fetchdat) +sf_FNINIT(UNUSED(uint32_t fetchdat)) { FP_ENTER(); cpu_state.pc++; @@ -525,7 +525,7 @@ sf_FNINIT(uint32_t fetchdat) } static int -sf_FLDENV_a16(uint32_t fetchdat) +sf_FLDENV_a16(UNUSED(uint32_t fetchdat)) { int tag; @@ -572,7 +572,7 @@ sf_FLDENV_a32(uint32_t fetchdat) #endif static int -sf_FNSTENV_a16(uint32_t fetchdat) +sf_FNSTENV_a16(UNUSED(uint32_t fetchdat)) { FP_ENTER(); fetch_ea_16(fetchdat); @@ -605,7 +605,7 @@ sf_FNSTENV_a32(uint32_t fetchdat) #endif static int -sf_FNOP(uint32_t fetchdat) +sf_FNOP(UNUSED(uint32_t fetchdat)) { FP_ENTER(); FPU_check_pending_exceptions(); diff --git a/src/cpu/x87_ops_sf_arith.h b/src/cpu/x87_ops_sf_arith.h index edbd64dcf..c9e25e97c 100644 --- a/src/cpu/x87_ops_sf_arith.h +++ b/src/cpu/x87_ops_sf_arith.h @@ -1,7 +1,7 @@ #define sf_FPU(name, optype, a_size, load_var, rw, use_var, is_nan, cycle_postfix) \ static int sf_FADD##name##_a##a_size(uint32_t fetchdat) \ { \ - floatx80 a, result; \ + floatx80 a, result; \ struct softfloat_status_t status; \ optype temp; \ FP_ENTER(); \ @@ -31,7 +31,7 @@ next_ins: } \ static int sf_FDIV##name##_a##a_size(uint32_t fetchdat) \ { \ - floatx80 a, result; \ + floatx80 a, result; \ struct softfloat_status_t status; \ optype temp; \ FP_ENTER(); \ @@ -61,7 +61,7 @@ next_ins: } \ static int sf_FDIVR##name##_a##a_size(uint32_t fetchdat) \ { \ - floatx80 a, result; \ + floatx80 a, result; \ struct softfloat_status_t status; \ optype temp; \ FP_ENTER(); \ @@ -91,7 +91,7 @@ next_ins: } \ static int sf_FMUL##name##_a##a_size(uint32_t fetchdat) \ { \ - floatx80 a, result; \ + floatx80 a, result; \ struct softfloat_status_t status; \ optype temp; \ FP_ENTER(); \ @@ -121,7 +121,7 @@ next_ins: } \ static int sf_FSUB##name##_a##a_size(uint32_t fetchdat) \ { \ - floatx80 a, result; \ + floatx80 a, result; \ struct softfloat_status_t status; \ optype temp; \ FP_ENTER(); \ @@ -151,7 +151,7 @@ next_ins: } \ static int sf_FSUBR##name##_a##a_size(uint32_t fetchdat) \ { \ - floatx80 a, result; \ + floatx80 a, result; \ struct softfloat_status_t status; \ optype temp; \ FP_ENTER(); \ diff --git a/src/cpu/x87_ops_sf_compare.h b/src/cpu/x87_ops_sf_compare.h index c4a38b375..945ed99d3 100644 --- a/src/cpu/x87_ops_sf_compare.h +++ b/src/cpu/x87_ops_sf_compare.h @@ -460,7 +460,7 @@ sf_FTST(uint32_t fetchdat) } static int -sf_FXAM(uint32_t fetchdat) +sf_FXAM(UNUSED(uint32_t fetchdat)) { floatx80 reg; int sign; diff --git a/src/cpu/x87_ops_sf_misc.h b/src/cpu/x87_ops_sf_misc.h index 0aab2ec08..746e85c6f 100644 --- a/src/cpu/x87_ops_sf_misc.h +++ b/src/cpu/x87_ops_sf_misc.h @@ -81,7 +81,7 @@ sf_FABS(uint32_t fetchdat) } static int -sf_FDECSTP(uint32_t fetchdat) +sf_FDECSTP(UNUSED(uint32_t fetchdat)) { FP_ENTER(); FPU_check_pending_exceptions(); @@ -94,7 +94,7 @@ sf_FDECSTP(uint32_t fetchdat) } static int -sf_FINCSTP(uint32_t fetchdat) +sf_FINCSTP(UNUSED(uint32_t fetchdat)) { FP_ENTER(); FPU_check_pending_exceptions(); diff --git a/src/ddma.c b/src/ddma.c index 7cbe2831e..0ca1bb879 100644 --- a/src/ddma.c +++ b/src/ddma.c @@ -193,7 +193,7 @@ const device_t ddma_device = { .init = ddma_init, .close = ddma_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/device.c b/src/device.c index 5b733df46..55552ead4 100644 --- a/src/device.c +++ b/src/device.c @@ -45,6 +45,7 @@ #include #include #include +#include #define HAVE_STDARG_H #include <86box/86box.h> #include <86box/ini.h> @@ -52,8 +53,10 @@ #include <86box/device.h> #include <86box/machine.h> #include <86box/mem.h> +#include <86box/plat.h> #include <86box/rom.h> #include <86box/sound.h> +#include <86box/ui.h> #define DEVICE_MAX 256 /* max # of devices */ @@ -155,6 +158,17 @@ device_add_common(const device_t *dev, void *p, void *params, int inst) void *priv = NULL; int16_t c; + if (!device_available(dev)) { + wchar_t temp[512] = { 0 }; + swprintf(temp, sizeof_w(temp), + plat_get_string(STRING_HW_NOT_AVAILABLE_DEVICE), + dev->name); + ui_msgbox_header(MBX_INFO, + plat_get_string(STRING_HW_NOT_AVAILABLE_TITLE), + temp); + return ((void *) dev->name); + } + if (params != NULL) { init_dev = calloc(1, sizeof(device_t)); memcpy(init_dev, dev, sizeof(device_t)); @@ -171,7 +185,8 @@ device_add_common(const device_t *dev, void *p, void *params, int inst) break; } if (c >= DEVICE_MAX) { - fatal("DEVICE: too many devices\n"); + fatal("Attempting to initialize more than the maximum " + "limit of %i devices\n", DEVICE_MAX); return NULL; } diff --git a/src/device/bugger.c b/src/device/bugger.c index c2678d66a..56cac91bc 100644 --- a/src/device/bugger.c +++ b/src/device/bugger.c @@ -351,7 +351,7 @@ const device_t bugger_device = { .init = bug_init, .close = bug_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/device/cartridge.c b/src/device/cartridge.c index 52f36a4ca..d2e91ecb3 100644 --- a/src/device/cartridge.c +++ b/src/device/cartridge.c @@ -104,6 +104,7 @@ cart_image_load(int drive, char *fn) if (size < 0x1200) { cartridge_log("cart_image_load(): File size %i is too small\n", size); cart_load_error(drive, fn); + fclose(fp); return; } if (size & 0x00000fff) { @@ -112,8 +113,7 @@ cart_image_load(int drive, char *fn) (void) !fread(&base, 1, 2, fp); base <<= 4; fseek(fp, 0x00000200, SEEK_SET); - carts[drive].buf = (uint8_t *) malloc(size); - memset(carts[drive].buf, 0x00, size); + carts[drive].buf = (uint8_t *) calloc(1, size); (void) !fread(carts[drive].buf, 1, size, fp); fclose(fp); } else { @@ -121,8 +121,7 @@ cart_image_load(int drive, char *fn) if (size == 32768) base += 0x8000; fseek(fp, 0x00000000, SEEK_SET); - carts[drive].buf = (uint8_t *) malloc(size); - memset(carts[drive].buf, 0x00, size); + carts[drive].buf = (uint8_t *) calloc(1, size); (void) !fread(carts[drive].buf, 1, size, fp); fclose(fp); } diff --git a/src/device/cassette.c b/src/device/cassette.c index a239c6393..ac79edff2 100644 --- a/src/device/cassette.c +++ b/src/device/cassette.c @@ -131,9 +131,7 @@ pc_cas_free(pc_cassette_t *cas) pc_cassette_t * pc_cas_new(void) { - pc_cassette_t *cas; - - cas = malloc(sizeof(pc_cassette_t)); + pc_cassette_t *cas = calloc(1, sizeof( pc_cassette_t)); if (cas == NULL) { return (NULL); @@ -722,7 +720,7 @@ const device_t cassette_device = { .init = cassette_init, .close = cassette_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/device/clock_ics9xxx.c b/src/device/clock_ics9xxx.c index 263170741..02f033e9b 100644 --- a/src/device/clock_ics9xxx.c +++ b/src/device/clock_ics9xxx.c @@ -1181,8 +1181,7 @@ ics9xxx_find_bus_match(ics9xxx_t *dev, uint32_t bus, uint8_t preset_mask, uint8_ static void * ics9xxx_init(const device_t *info) { - ics9xxx_t *dev = (ics9xxx_t *) malloc(sizeof(ics9xxx_t)); - memset(dev, 0, sizeof(ics9xxx_t)); + ics9xxx_t *dev = (ics9xxx_t *) calloc(1, sizeof(ics9xxx_t)); dev->model_idx = info->local; dev->model = (ics9xxx_model_t *) &ics9xxx_models[dev->model_idx]; @@ -1267,8 +1266,7 @@ ics9xxx_close(void *priv) device_t * ics9xxx_get(uint8_t model) { - device_t *dev = (device_t *) malloc(sizeof(device_t)); - memset(dev, 0, sizeof(device_t)); + device_t *dev = (device_t *) calloc(1, sizeof(device_t)); dev->name = "ICS9xxx-xx Clock Generator"; dev->local = model; diff --git a/src/device/hasp.c b/src/device/hasp.c index 9873c3460..3834af4cd 100644 --- a/src/device/hasp.c +++ b/src/device/hasp.c @@ -305,8 +305,7 @@ hasp_read_status(void *priv) static void * hasp_init(void *lpt, int type) { - hasp_t *dev = malloc(sizeof(hasp_t)); - memset(dev, 0, sizeof(hasp_t)); + hasp_t *dev = calloc(1, sizeof(hasp_t)); hasp_log("HASP: init(%d)\n", type); diff --git a/src/device/hwm_gl518sm.c b/src/device/hwm_gl518sm.c index 6ba1083d9..cfc16664a 100644 --- a/src/device/hwm_gl518sm.c +++ b/src/device/hwm_gl518sm.c @@ -282,8 +282,7 @@ gl518sm_close(void *priv) static void * gl518sm_init(const device_t *info) { - gl518sm_t *dev = (gl518sm_t *) malloc(sizeof(gl518sm_t)); - memset(dev, 0, sizeof(gl518sm_t)); + gl518sm_t *dev = (gl518sm_t *) calloc(1, sizeof(gl518sm_t)); dev->local = info->local; @@ -325,7 +324,7 @@ const device_t gl518sm_2c_device = { .init = gl518sm_init, .close = gl518sm_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -340,7 +339,7 @@ const device_t gl518sm_2d_device = { .init = gl518sm_init, .close = gl518sm_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -355,7 +354,7 @@ const device_t gl520sm_2c_device = { .init = gl518sm_init, .close = gl518sm_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -371,7 +370,7 @@ const device_t gl520sm_2d_device = { .init = gl518sm_init, .close = gl518sm_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/device/hwm_lm75.c b/src/device/hwm_lm75.c index 14b638365..29fe2024f 100644 --- a/src/device/hwm_lm75.c +++ b/src/device/hwm_lm75.c @@ -216,8 +216,7 @@ lm75_close(void *priv) static void * lm75_init(const device_t *info) { - lm75_t *dev = (lm75_t *) malloc(sizeof(lm75_t)); - memset(dev, 0, sizeof(lm75_t)); + lm75_t *dev = (lm75_t *) calloc(1, sizeof(lm75_t)); dev->local = info->local; @@ -243,7 +242,7 @@ const device_t lm75_1_4a_device = { .init = lm75_init, .close = lm75_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -259,7 +258,7 @@ const device_t lm75_w83781d_device = { .init = lm75_init, .close = lm75_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/device/hwm_lm78.c b/src/device/hwm_lm78.c index f3003db26..1e61168ac 100644 --- a/src/device/hwm_lm78.c +++ b/src/device/hwm_lm78.c @@ -771,8 +771,7 @@ lm78_close(void *priv) static void * lm78_init(const device_t *info) { - lm78_t *dev = (lm78_t *) malloc(sizeof(lm78_t)); - memset(dev, 0, sizeof(lm78_t)); + lm78_t *dev = (lm78_t *) calloc(1, sizeof(lm78_t)); dev->local = info->local; @@ -857,7 +856,7 @@ const device_t lm78_device = { .init = lm78_init, .close = lm78_close, .reset = lm78_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -872,7 +871,7 @@ const device_t w83781d_device = { .init = lm78_init, .close = lm78_close, .reset = lm78_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -887,7 +886,7 @@ const device_t w83781d_p5a_device = { .init = lm78_init, .close = lm78_close, .reset = lm78_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -903,7 +902,7 @@ const device_t as99127f_device = { .init = lm78_init, .close = lm78_close, .reset = lm78_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -918,7 +917,7 @@ const device_t as99127f_rev2_device = { .init = lm78_init, .close = lm78_close, .reset = lm78_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -933,7 +932,7 @@ const device_t w83782d_device = { .init = lm78_init, .close = lm78_close, .reset = lm78_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/device/hwm_vt82c686.c b/src/device/hwm_vt82c686.c index b6a0dddda..8623a9f6b 100644 --- a/src/device/hwm_vt82c686.c +++ b/src/device/hwm_vt82c686.c @@ -183,8 +183,7 @@ vt82c686_close(void *priv) static void * vt82c686_init(UNUSED(const device_t *info)) { - vt82c686_t *dev = (vt82c686_t *) malloc(sizeof(vt82c686_t)); - memset(dev, 0, sizeof(vt82c686_t)); + vt82c686_t *dev = (vt82c686_t *) calloc(1, sizeof(vt82c686_t)); /* Set default values. Since this hardware monitor has a complex voltage factor system, the values struct contains voltage values *before* applying their respective factors. */ @@ -222,7 +221,7 @@ const device_t via_vt82c686_hwm_device = { .init = vt82c686_init, .close = vt82c686_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/device/i2c.c b/src/device/i2c.c index 56e6f8f4c..eb80f413b 100644 --- a/src/device/i2c.c +++ b/src/device/i2c.c @@ -67,8 +67,7 @@ i2c_log(const char *fmt, ...) void * i2c_addbus(char *name) { - i2c_bus_t *bus = (i2c_bus_t *) malloc(sizeof(i2c_bus_t)); - memset(bus, 0, sizeof(i2c_bus_t)); + i2c_bus_t *bus = (i2c_bus_t *) calloc(1, sizeof(i2c_bus_t)); bus->name = name; @@ -127,8 +126,7 @@ i2c_sethandler(void *bus_handle, uint8_t base, int size, for (int c = 0; c < size; c++) { p = bus->last[base + c]; - q = (i2c_t *) malloc(sizeof(i2c_t)); - memset(q, 0, sizeof(i2c_t)); + q = (i2c_t *) calloc(1, sizeof(i2c_t)); if (p) { p->next = q; q->prev = p; diff --git a/src/device/i2c_gpio.c b/src/device/i2c_gpio.c index 22bdaffd3..61a3dbe05 100644 --- a/src/device/i2c_gpio.c +++ b/src/device/i2c_gpio.c @@ -59,8 +59,7 @@ i2c_gpio_log(int level, const char *fmt, ...) void * i2c_gpio_init(char *bus_name) { - i2c_gpio_t *dev = (i2c_gpio_t *) malloc(sizeof(i2c_gpio_t)); - memset(dev, 0, sizeof(i2c_gpio_t)); + i2c_gpio_t *dev = (i2c_gpio_t *) calloc(1, sizeof(i2c_gpio_t)); i2c_gpio_log(1, "I2C GPIO %s: init()\n", bus_name); diff --git a/src/device/ibm_5161.c b/src/device/ibm_5161.c index 762a379a1..456227676 100644 --- a/src/device/ibm_5161.c +++ b/src/device/ibm_5161.c @@ -116,7 +116,7 @@ const device_t ibm_5161_device = { .init = ibm_5161_init, .close = ibm_5161_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/device/isamem.c b/src/device/isamem.c index f63a5a5a1..5cac31c7f 100644 --- a/src/device/isamem.c +++ b/src/device/isamem.c @@ -27,16 +27,20 @@ * modern boards even have multiple 'copies' of those registers, * which can be switched very fast, to allow for multitasking. * - * TODO: The EV159 is supposed to support 16b EMS transfers, but the + * TODO: The EV-159 is supposed to support 16b EMS transfers, but the * EMM.sys driver for it doesn't seem to want to do that.. * + * EV-125 (It supports backfill) + * https://theretroweb.com/expansioncard/documentation/50250.pdf * + * EV-158 (RAM 10000) + * http://web.archive.org/web/19961104093221/http://www.everex.com/supp/techlib/memmem.html * * Authors: Fred N. van Kempen, * Jasmine Iwanek * * Copyright 2018 Fred N. van Kempen. - * Copyright 2022-2024 Jasmine Iwanek. + * Copyright 2022-2025 Jasmine Iwanek. * * Redistribution and use in source and binary forms, with * or without modification, are permitted provided that the @@ -102,7 +106,7 @@ #define ISAMEM_BRXT_CARD 13 #define ISAMEM_BRAT_CARD 14 #define ISAMEM_EV165A_CARD 15 -#define ISAMEM_LOTECH_CARD 16 +#define ISAMEM_LOTECH_EMS_CARD 16 #define ISAMEM_DEBUG 0 @@ -304,16 +308,13 @@ ems_writew(uint32_t addr, uint16_t val, void *priv) static uint8_t ems_in(uint16_t port, void *priv) { - const emsreg_t *dev = (emsreg_t *) priv; - uint8_t ret = 0xff; -#ifdef ENABLE_ISAMEM_LOG - int vpage; -#endif - + const emsreg_t *dev = (emsreg_t *) priv; + uint8_t ret = 0xff; /* Get the viewport page number. */ #ifdef ENABLE_ISAMEM_LOG - vpage = (port / EMS_PGSIZE); + int vpage = (port / EMS_PGSIZE); #endif + port &= (EMS_PGSIZE - 1); switch (port & 0x0001) { @@ -339,13 +340,11 @@ ems_in(uint16_t port, void *priv) static uint8_t consecutive_ems_in(uint16_t port, void *priv) { - const memdev_t *dev = (memdev_t *) priv; - uint8_t ret = 0xff; - int vpage; - + const memdev_t *dev = (memdev_t *) priv; + uint8_t ret = 0xff; /* Get the viewport page number. */ - vpage = (port - dev->base_addr[0]); - + int vpage = (port - dev->base_addr[0]); + ret = dev->ems[vpage].page; if (dev->ems[vpage].enabled) ret |= 0x80; @@ -359,11 +358,10 @@ consecutive_ems_in(uint16_t port, void *priv) static void ems_out(uint16_t port, uint8_t val, void *priv) { - emsreg_t *dev = (emsreg_t *) priv; - int vpage; - + emsreg_t *dev = (emsreg_t *) priv; /* Get the viewport page number. */ - vpage = (port / EMS_PGSIZE); + int vpage = (port / EMS_PGSIZE); + port &= (EMS_PGSIZE - 1); switch (port & 0x0001) { @@ -433,11 +431,9 @@ ems_out(uint16_t port, uint8_t val, void *priv) static void consecutive_ems_out(uint16_t port, uint8_t val, void *priv) { - memdev_t *dev = (memdev_t *) priv; - int vpage; - + memdev_t *dev = (memdev_t *) priv; /* Get the viewport page number. */ - vpage = (port - dev->base_addr[0]); + int vpage = (port - dev->base_addr[0]); isamem_log("ISAMEM: write(%04x, %02x) to page mapping registers! (page=%d)\n", port, val, vpage); @@ -483,8 +479,7 @@ isamem_init(const device_t *info) uint8_t *ptr; /* Find our device and create an instance. */ - dev = (memdev_t *) malloc(sizeof(memdev_t)); - memset(dev, 0x00, sizeof(memdev_t)); + dev = (memdev_t *) calloc(1, sizeof(memdev_t)); dev->name = info->name; dev->board = info->local; @@ -579,7 +574,7 @@ isamem_init(const device_t *info) dev->flags |= FLAG_FAST; break; - case ISAMEM_LOTECH_CARD: /* Lotech EMS */ + case ISAMEM_LOTECH_EMS_CARD: /* Lotech EMS */ /* The Lotech EMS cannot have more than 4096KB per board. */ ems_max = EMS_LOTECH_MAXSIZE; fallthrough; @@ -801,7 +796,7 @@ isamem_init(const device_t *info) mem_mapping_disable(&dev->ems[i].mapping); /* Set up an I/O port handler. */ - if (dev->board != ISAMEM_LOTECH_CARD) + if (dev->board != ISAMEM_LOTECH_EMS_CARD) io_sethandler(dev->base_addr[0] + (EMS_PGSIZE * i), 2, ems_in, NULL, NULL, ems_out, NULL, NULL, &(dev->ems[i])); @@ -832,7 +827,7 @@ isamem_init(const device_t *info) } } - if (dev->board == ISAMEM_LOTECH_CARD) + if (dev->board == ISAMEM_LOTECH_EMS_CARD) io_sethandler(dev->base_addr[0], 4, consecutive_ems_in, NULL, NULL, consecutive_ems_out, NULL, NULL, dev); } @@ -895,7 +890,7 @@ static const device_t ibmxt_32k_device = { .init = isamem_init, .close = isamem_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = ibmxt_32k_config @@ -943,7 +938,7 @@ static const device_t ibmxt_64k_device = { .init = isamem_init, .close = isamem_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = ibmxt_64k_config @@ -991,7 +986,7 @@ static const device_t ibmxt_device = { .init = isamem_init, .close = isamem_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = ibmxt_config @@ -1031,6 +1026,7 @@ static const device_config_t genericxt_config[] = { // clang-format on }; +// This also nicely accounts for the Everex EV-138 static const device_t genericxt_device = { .name = "Generic PC/XT Memory Expansion", .internal_name = "genericxt", @@ -1039,7 +1035,7 @@ static const device_t genericxt_device = { .init = isamem_init, .close = isamem_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = genericxt_config @@ -1087,7 +1083,7 @@ static const device_t msramcard_device = { .init = isamem_init, .close = isamem_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = msramcard_config @@ -1135,7 +1131,7 @@ static const device_t mssystemcard_device = { .init = isamem_init, .close = isamem_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = mssystemcard_config @@ -1149,7 +1145,7 @@ static const device_t ibmat_128k_device = { .init = isamem_init, .close = isamem_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -1197,7 +1193,7 @@ static const device_t ibmat_device = { .init = isamem_init, .close = isamem_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = ibmat_config @@ -1237,6 +1233,7 @@ static const device_config_t genericat_config[] = { // clang-format on }; +// This also nicely accounts for the Everex EV-135 static const device_t genericat_device = { .name = "Generic PC/AT Memory Expansion", .internal_name = "genericat", @@ -1245,7 +1242,7 @@ static const device_t genericat_device = { .init = isamem_init, .close = isamem_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = genericat_config @@ -1293,7 +1290,7 @@ static const device_t p5pak_device = { .init = isamem_init, .close = isamem_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = p5pak_config @@ -1341,7 +1338,7 @@ static const device_t a6pak_device = { .init = isamem_init, .close = isamem_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = a6pak_config @@ -1392,7 +1389,7 @@ static const device_t ems5150_device = { .init = isamem_init, .close = isamem_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = ems5150_config @@ -1534,7 +1531,7 @@ static const device_t ev159_device = { .init = isamem_init, .close = isamem_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = ev159_config @@ -1629,7 +1626,7 @@ static const device_t ev165a_device = { .init = isamem_init, .close = isamem_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = ev165a_config @@ -1693,7 +1690,7 @@ static const device_t brxt_device = { .init = isamem_init, .close = isamem_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = brxt_config @@ -1799,7 +1796,7 @@ static const device_t brat_device = { .init = isamem_init, .close = isamem_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = brat_config @@ -1857,15 +1854,15 @@ static const device_config_t lotech_config[] = { // clang-format on }; -static const device_t lotech_device = { +static const device_t lotech_ems_device = { .name = "Lo-tech EMS Board", .internal_name = "lotechems", .flags = DEVICE_ISA, - .local = ISAMEM_LOTECH_CARD, + .local = ISAMEM_LOTECH_EMS_CARD, .init = isamem_init, .close = isamem_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = lotech_config @@ -1934,7 +1931,7 @@ static const device_t rampage_device = { .init = isamem_init, .close = isamem_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = rampage_config @@ -2033,7 +2030,7 @@ static const device_t iab_device = { .init = isamem_init, .close = isamem_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = iab_config @@ -2072,7 +2069,7 @@ static const struct { #ifdef USE_ISAMEM_IAB { &iab_device }, #endif /* USE_ISAMEM_IAB */ - { &lotech_device }, + { &lotech_ems_device }, { NULL } // clang-format on }; diff --git a/src/device/isapnp.c b/src/device/isapnp.c index f69c69612..1ee8be040 100644 --- a/src/device/isapnp.c +++ b/src/device/isapnp.c @@ -679,7 +679,7 @@ isapnp_write_data(UNUSED(uint16_t addr), uint8_t val, void *priv) static void * isapnp_init(UNUSED(const device_t *info)) { - isapnp_t *dev = (isapnp_t *) malloc(sizeof(isapnp_t)); + isapnp_t *dev = (isapnp_t *) calloc(1, sizeof(isapnp_t)); memset(dev, 0, sizeof(isapnp_t)); io_sethandler(0x279, 1, NULL, NULL, NULL, isapnp_write_addr, NULL, NULL, dev); @@ -728,8 +728,7 @@ isapnp_add_card(uint8_t *rom, uint16_t rom_size, if (!dev) dev = (isapnp_t *) device_add(&isapnp_device); - isapnp_card_t *card = (isapnp_card_t *) malloc(sizeof(isapnp_card_t)); - memset(card, 0, sizeof(isapnp_card_t)); + isapnp_card_t *card = (isapnp_card_t *) calloc(1, sizeof(isapnp_card_t)); card->enable = 1; card->priv = priv; @@ -1231,7 +1230,7 @@ static const device_t isapnp_device = { .init = isapnp_init, .close = isapnp_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/device/isartc.c b/src/device/isartc.c index 77f35ffc7..f24ffb72b 100644 --- a/src/device/isartc.c +++ b/src/device/isartc.c @@ -520,8 +520,7 @@ isartc_init(const device_t *info) is_at = is_at || !strcmp(machine_get_internal_name(), "xi8088"); /* Create a device instance. */ - dev = (rtcdev_t *) malloc(sizeof(rtcdev_t)); - memset(dev, 0x00, sizeof(rtcdev_t)); + dev = (rtcdev_t *) calloc(1, sizeof(rtcdev_t)); dev->name = info->name; dev->board = info->local; dev->irq = -1; diff --git a/src/device/kbc_at.c b/src/device/kbc_at.c index 74be59017..ad1625873 100644 --- a/src/device/kbc_at.c +++ b/src/device/kbc_at.c @@ -2282,8 +2282,7 @@ kbc_at_init(const device_t *info) atkbc_t *dev; int max_ports; - dev = (atkbc_t *) malloc(sizeof(atkbc_t)); - memset(dev, 0x00, sizeof(atkbc_t)); + dev = (atkbc_t *) calloc(1, sizeof(atkbc_t)); dev->flags = info->local; @@ -2393,8 +2392,7 @@ kbc_at_init(const device_t *info) #endif for (int i = 0; i < max_ports; i++) { - kbc_at_ports[i] = (kbc_at_port_t *) malloc(sizeof(kbc_at_port_t)); - memset(kbc_at_ports[i], 0x00, sizeof(kbc_at_port_t)); + kbc_at_ports[i] = (kbc_at_port_t *) calloc(1, sizeof(kbc_at_port_t)); kbc_at_ports[i]->out_new = -1; } @@ -2417,7 +2415,7 @@ const device_t keyboard_at_device = { .init = kbc_at_init, .close = kbc_at_close, .reset = kbc_at_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2431,7 +2429,7 @@ const device_t keyboard_at_siemens_device = { .init = kbc_at_init, .close = kbc_at_close, .reset = kbc_at_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2445,7 +2443,7 @@ const device_t keyboard_at_ami_device = { .init = kbc_at_init, .close = kbc_at_close, .reset = kbc_at_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2459,7 +2457,7 @@ const device_t keyboard_at_tg_ami_device = { .init = kbc_at_init, .close = kbc_at_close, .reset = kbc_at_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2473,7 +2471,7 @@ const device_t keyboard_at_toshiba_device = { .init = kbc_at_init, .close = kbc_at_close, .reset = kbc_at_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2487,7 +2485,7 @@ const device_t keyboard_at_olivetti_device = { .init = kbc_at_init, .close = kbc_at_close, .reset = kbc_at_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2501,7 +2499,7 @@ const device_t keyboard_at_ncr_device = { .init = kbc_at_init, .close = kbc_at_close, .reset = kbc_at_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2515,7 +2513,7 @@ const device_t keyboard_at_compaq_device = { .init = kbc_at_init, .close = kbc_at_close, .reset = kbc_at_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2529,7 +2527,7 @@ const device_t keyboard_ps2_device = { .init = kbc_at_init, .close = kbc_at_close, .reset = kbc_at_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2543,7 +2541,7 @@ const device_t keyboard_ps2_ps1_device = { .init = kbc_at_init, .close = kbc_at_close, .reset = kbc_at_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2557,7 +2555,7 @@ const device_t keyboard_ps2_ps1_pci_device = { .init = kbc_at_init, .close = kbc_at_close, .reset = kbc_at_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2571,7 +2569,7 @@ const device_t keyboard_ps2_xi8088_device = { .init = kbc_at_init, .close = kbc_at_close, .reset = kbc_at_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2585,7 +2583,7 @@ const device_t keyboard_ps2_ami_device = { .init = kbc_at_init, .close = kbc_at_close, .reset = kbc_at_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2599,7 +2597,7 @@ const device_t keyboard_ps2_holtek_device = { .init = kbc_at_init, .close = kbc_at_close, .reset = kbc_at_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2613,7 +2611,7 @@ const device_t keyboard_ps2_phoenix_device = { .init = kbc_at_init, .close = kbc_at_close, .reset = kbc_at_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2627,7 +2625,7 @@ const device_t keyboard_ps2_tg_ami_device = { .init = kbc_at_init, .close = kbc_at_close, .reset = kbc_at_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2641,7 +2639,7 @@ const device_t keyboard_ps2_mca_1_device = { .init = kbc_at_init, .close = kbc_at_close, .reset = kbc_at_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2655,7 +2653,7 @@ const device_t keyboard_ps2_mca_2_device = { .init = kbc_at_init, .close = kbc_at_close, .reset = kbc_at_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2669,7 +2667,7 @@ const device_t keyboard_ps2_quadtel_device = { .init = kbc_at_init, .close = kbc_at_close, .reset = kbc_at_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2683,7 +2681,7 @@ const device_t keyboard_ps2_pci_device = { .init = kbc_at_init, .close = kbc_at_close, .reset = kbc_at_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2697,7 +2695,7 @@ const device_t keyboard_ps2_ami_pci_device = { .init = kbc_at_init, .close = kbc_at_close, .reset = kbc_at_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2711,7 +2709,7 @@ const device_t keyboard_ps2_ali_pci_device = { .init = kbc_at_init, .close = kbc_at_close, .reset = kbc_at_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2725,7 +2723,7 @@ const device_t keyboard_ps2_intel_ami_pci_device = { .init = kbc_at_init, .close = kbc_at_close, .reset = kbc_at_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2739,7 +2737,7 @@ const device_t keyboard_ps2_tg_ami_pci_device = { .init = kbc_at_init, .close = kbc_at_close, .reset = kbc_at_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2753,7 +2751,7 @@ const device_t keyboard_ps2_acer_pci_device = { .init = kbc_at_init, .close = kbc_at_close, .reset = kbc_at_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/device/keyboard.c b/src/device/keyboard.c index 2eff2159b..a352d8df9 100644 --- a/src/device/keyboard.c +++ b/src/device/keyboard.c @@ -33,23 +33,13 @@ uint16_t scancode_map[768] = { 0 }; int keyboard_scan; -#ifdef _WIN32 -/* Windows: F8+F12 */ +/* F8+F12 */ uint16_t key_prefix_1_1 = 0x042; /* F8 */ uint16_t key_prefix_1_2 = 0x000; /* Invalid */ uint16_t key_prefix_2_1 = 0x000; /* Invalid */ uint16_t key_prefix_2_2 = 0x000; /* Invalid */ uint16_t key_uncapture_1 = 0x058; /* F12 */ uint16_t key_uncapture_2 = 0x000; /* Invalid */ -#else -/* WxWidgets cannot do two regular keys.. CTRL+END */ -uint16_t key_prefix_1_1 = 0x01d; /* Left Ctrl */ -uint16_t key_prefix_1_2 = 0x11d; /* Right Ctrl */ -uint16_t key_prefix_2_1 = 0x000; /* Invalid */ -uint16_t key_prefix_2_2 = 0x000; /* Invalid */ -uint16_t key_uncapture_1 = 0x04f; /* Numpad End */ -uint16_t key_uncapture_2 = 0x14f; /* End */ -#endif void (*keyboard_send)(uint16_t val); diff --git a/src/device/keyboard_xt.c b/src/device/keyboard_xt.c index b90f4a77a..644168004 100644 --- a/src/device/keyboard_xt.c +++ b/src/device/keyboard_xt.c @@ -1000,8 +1000,7 @@ kbd_init(const device_t *info) { xtkbd_t *kbd; - kbd = (xtkbd_t *) malloc(sizeof(xtkbd_t)); - memset(kbd, 0x00, sizeof(xtkbd_t)); + kbd = (xtkbd_t *) calloc(1, sizeof(xtkbd_t)); io_sethandler(0x0060, 4, kbd_read, NULL, NULL, kbd_write, NULL, NULL, kbd); @@ -1188,7 +1187,7 @@ const device_t keyboard_pc_device = { .init = kbd_init, .close = kbd_close, .reset = kbd_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -1202,7 +1201,7 @@ const device_t keyboard_pc82_device = { .init = kbd_init, .close = kbd_close, .reset = kbd_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -1216,7 +1215,7 @@ const device_t keyboard_pravetz_device = { .init = kbd_init, .close = kbd_close, .reset = kbd_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -1230,7 +1229,7 @@ const device_t keyboard_xt_device = { .init = kbd_init, .close = kbd_close, .reset = kbd_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -1244,7 +1243,7 @@ const device_t keyboard_xt86_device = { .init = kbd_init, .close = kbd_close, .reset = kbd_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -1258,7 +1257,7 @@ const device_t keyboard_xt_compaq_device = { .init = kbd_init, .close = kbd_close, .reset = kbd_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -1272,7 +1271,7 @@ const device_t keyboard_tandy_device = { .init = kbd_init, .close = kbd_close, .reset = kbd_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -1286,7 +1285,7 @@ const device_t keyboard_xt_t1x00_device = { .init = kbd_init, .close = kbd_close, .reset = kbd_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -1301,7 +1300,7 @@ const device_t keyboard_xt_lxt3_device = { .init = kbd_init, .close = kbd_close, .reset = kbd_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -1316,7 +1315,7 @@ const device_t keyboard_xt_olivetti_device = { .init = kbd_init, .close = kbd_close, .reset = kbd_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -1330,7 +1329,7 @@ const device_t keyboard_xt_zenith_device = { .init = kbd_init, .close = kbd_close, .reset = kbd_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -1344,7 +1343,7 @@ const device_t keyboard_xt_hyundai_device = { .init = kbd_init, .close = kbd_close, .reset = kbd_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -1358,7 +1357,7 @@ const device_t keyboard_xtclone_device = { .init = kbd_init, .close = kbd_close, .reset = kbd_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/device/mouse_bus.c b/src/device/mouse_bus.c index fdd58b404..b56a3cc18 100644 --- a/src/device/mouse_bus.c +++ b/src/device/mouse_bus.c @@ -614,8 +614,7 @@ bm_init(const device_t *info) mouse_t *dev; int hz; - dev = (mouse_t *) malloc(sizeof(mouse_t)); - memset(dev, 0x00, sizeof(mouse_t)); + dev = (mouse_t *) calloc(1, sizeof(mouse_t)); if ((info->local & ~MOUSE_TYPE_ONBOARD) == MOUSE_TYPE_INPORT) dev->flags = FLAG_INPORT; @@ -812,7 +811,7 @@ const device_t mouse_logibus_device = { .init = bm_init, .close = bm_close, .reset = NULL, - { .poll = bm_poll }, + .poll = bm_poll, .speed_changed = NULL, .force_redraw = NULL, .config = lt_config @@ -826,7 +825,7 @@ const device_t mouse_logibus_onboard_device = { .init = bm_init, .close = bm_close, .reset = NULL, - { .poll = bm_poll }, + .poll = bm_poll, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -840,7 +839,7 @@ const device_t mouse_msinport_device = { .init = bm_init, .close = bm_close, .reset = NULL, - { .poll = bm_poll }, + .poll = bm_poll, .speed_changed = NULL, .force_redraw = NULL, .config = ms_config diff --git a/src/device/mouse_microtouch_touchscreen.c b/src/device/mouse_microtouch_touchscreen.c index 442b25b91..24d5de1fb 100644 --- a/src/device/mouse_microtouch_touchscreen.c +++ b/src/device/mouse_microtouch_touchscreen.c @@ -128,8 +128,7 @@ mtouch_initnvr(void *priv) FILE *fp; /* Allocate and initialize the EEPROM. */ - dev->nvr = (uint8_t *) malloc(NVR_SIZE); - memset(dev->nvr, 0x00, NVR_SIZE); + dev->nvr = (uint8_t *) calloc(1, NVR_SIZE); fp = nvr_fopen(dev->nvr_path, "rb"); if (fp) { @@ -314,7 +313,7 @@ mtouch_process_commands(mouse_microtouch_t *dev) } static void -mtouch_write(serial_t *serial, void *priv, uint8_t data) +mtouch_write(UNUSED(serial_t *serial), void *priv, uint8_t data) { mouse_microtouch_t *dev = (mouse_microtouch_t *) priv; @@ -496,7 +495,7 @@ mtouch_poll_global(void) } void * -mtouch_init(const device_t *info) +mtouch_init(UNUSED(const device_t *info)) { mouse_microtouch_t *dev = calloc(1, sizeof(mouse_microtouch_t)); @@ -599,7 +598,7 @@ const device_t mouse_mtouch_device = { .init = mtouch_init, .close = mtouch_close, .reset = NULL, - { .poll = mtouch_poll }, + .poll = mtouch_poll, .speed_changed = NULL, .force_redraw = NULL, .config = mtouch_config diff --git a/src/device/mouse_ps2.c b/src/device/mouse_ps2.c index e5f9dd410..53af97b78 100644 --- a/src/device/mouse_ps2.c +++ b/src/device/mouse_ps2.c @@ -396,7 +396,7 @@ const device_t mouse_ps2_device = { .init = mouse_ps2_init, .close = ps2_close, .reset = NULL, - { .poll = ps2_poll }, + .poll = ps2_poll, .speed_changed = NULL, .force_redraw = NULL, .config = ps2_config diff --git a/src/device/mouse_serial.c b/src/device/mouse_serial.c index fa3190536..c64be5a6d 100644 --- a/src/device/mouse_serial.c +++ b/src/device/mouse_serial.c @@ -845,8 +845,7 @@ sermouse_init(const device_t *info) void (*dev_write)(struct serial_s *serial, void *priv, uint8_t data); void (*transmit_period_callback)(struct serial_s *serial, void *priv, double transmit_period); - dev = (mouse_t *) malloc(sizeof(mouse_t)); - memset(dev, 0x00, sizeof(mouse_t)); + dev = (mouse_t *) calloc(1, sizeof(mouse_t)); dev->name = info->name; dev->but = device_get_config_int("buttons"); dev->rev = device_get_config_int("revision"); @@ -1061,7 +1060,7 @@ const device_t mouse_mssystems_device = { .init = sermouse_init, .close = sermouse_close, .reset = NULL, - { .poll = sermouse_poll }, + .poll = sermouse_poll, .speed_changed = sermouse_speed_changed, .force_redraw = NULL, .config = msssermouse_config @@ -1075,7 +1074,7 @@ const device_t mouse_msserial_device = { .init = sermouse_init, .close = sermouse_close, .reset = NULL, - { .poll = sermouse_poll }, + .poll = sermouse_poll, .speed_changed = sermouse_speed_changed, .force_redraw = NULL, .config = mssermouse_config @@ -1089,7 +1088,7 @@ const device_t mouse_ltserial_device = { .init = sermouse_init, .close = sermouse_close, .reset = NULL, - { .poll = sermouse_poll }, + .poll = sermouse_poll, .speed_changed = sermouse_speed_changed, .force_redraw = NULL, .config = ltsermouse_config diff --git a/src/device/mouse_wacom_tablet.c b/src/device/mouse_wacom_tablet.c index d299d8bab..d74e58411 100644 --- a/src/device/mouse_wacom_tablet.c +++ b/src/device/mouse_wacom_tablet.c @@ -720,7 +720,7 @@ const device_t mouse_wacom_device = { .init = wacom_init, .close = wacom_close, .reset = NULL, - { .poll = wacom_poll }, + .poll = wacom_poll, .speed_changed = wacom_speed_changed, .force_redraw = NULL, .config = wacom_config @@ -730,11 +730,11 @@ const device_t mouse_wacom_artpad_device = { .name = "Wacom ArtPad", .internal_name = "wacom_serial_artpad", .flags = DEVICE_COM, - .local = (uintptr_t)&artpad_id, + .local = (uintptr_t) &artpad_id, .init = wacom_init, .close = wacom_close, .reset = NULL, - { .poll = wacom_poll }, + .poll = wacom_poll, .speed_changed = wacom_speed_changed, .force_redraw = NULL, .config = wacom_config diff --git a/src/device/nec_mate_unk.c b/src/device/nec_mate_unk.c index 165962f30..c0393eaa2 100644 --- a/src/device/nec_mate_unk.c +++ b/src/device/nec_mate_unk.c @@ -30,7 +30,7 @@ #include <86box/plat_unused.h> static uint8_t -nec_mate_unk_read(UNUSED(uint16_t addr), void *priv) +nec_mate_unk_read(UNUSED(uint16_t addr), UNUSED(void *priv)) { /* Expected by this NEC machine. @@ -49,7 +49,7 @@ nec_mate_unk_close(void *priv) } static void * -nec_mate_unk_init(const device_t *info) +nec_mate_unk_init(UNUSED(const device_t *info)) { /* We have to return something non-NULL. */ uint8_t *dev = (uint8_t *) calloc(1, sizeof(uint8_t)); @@ -68,7 +68,7 @@ const device_t nec_mate_unk_device = { .init = nec_mate_unk_init, .close = nec_mate_unk_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/device/novell_cardkey.c b/src/device/novell_cardkey.c index 4730b6bb4..34b6390d1 100644 --- a/src/device/novell_cardkey.c +++ b/src/device/novell_cardkey.c @@ -61,7 +61,7 @@ novell_cardkey_read(uint16_t port, void *priv) return val ^ 0xFF; } -void* novell_cardkey_init(const device_t* info) +void* novell_cardkey_init(UNUSED(const device_t* info)) { char sernumstr[13] = { '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', 0 }; int i = 0; @@ -116,7 +116,7 @@ const device_t novell_keycard_device = { .init = novell_cardkey_init, .close = novell_cardkey_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = keycard_config diff --git a/src/device/pci_bridge.c b/src/device/pci_bridge.c index c1f551162..7dda00aee 100644 --- a/src/device/pci_bridge.c +++ b/src/device/pci_bridge.c @@ -491,8 +491,7 @@ pci_bridge_init(const device_t *info) uint8_t interrupt_mask; uint8_t slot_count; - pci_bridge_t *dev = (pci_bridge_t *) malloc(sizeof(pci_bridge_t)); - memset(dev, 0, sizeof(pci_bridge_t)); + pci_bridge_t *dev = (pci_bridge_t *) calloc(1, sizeof(pci_bridge_t)); dev->local = info->local; dev->bus_index = pci_register_bus(); @@ -542,7 +541,7 @@ const device_t dec21150_device = { .init = pci_bridge_init, .close = NULL, .reset = pci_bridge_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -557,7 +556,7 @@ const device_t ali5243_agp_device = { .init = pci_bridge_init, .close = NULL, .reset = pci_bridge_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -572,7 +571,7 @@ const device_t ali5247_agp_device = { .init = pci_bridge_init, .close = NULL, .reset = pci_bridge_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -586,7 +585,7 @@ const device_t i440lx_agp_device = { .init = pci_bridge_init, .close = NULL, .reset = pci_bridge_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -600,7 +599,7 @@ const device_t i440bx_agp_device = { .init = pci_bridge_init, .close = NULL, .reset = pci_bridge_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -614,7 +613,7 @@ const device_t i440gx_agp_device = { .init = pci_bridge_init, .close = NULL, .reset = pci_bridge_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -628,7 +627,7 @@ const device_t via_vp3_agp_device = { .init = pci_bridge_init, .close = NULL, .reset = pci_bridge_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -642,7 +641,7 @@ const device_t via_mvp3_agp_device = { .init = pci_bridge_init, .close = NULL, .reset = pci_bridge_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -656,7 +655,7 @@ const device_t via_apro_agp_device = { .init = pci_bridge_init, .close = NULL, .reset = pci_bridge_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -670,7 +669,7 @@ const device_t via_vt8601_agp_device = { .init = pci_bridge_init, .close = NULL, .reset = pci_bridge_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -684,7 +683,7 @@ const device_t sis_5xxx_agp_device = { .init = pci_bridge_init, .close = NULL, .reset = pci_bridge_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/device/phoenix_486_jumper.c b/src/device/phoenix_486_jumper.c index a3c891c90..a3e2f0e7e 100644 --- a/src/device/phoenix_486_jumper.c +++ b/src/device/phoenix_486_jumper.c @@ -110,8 +110,7 @@ phoenix_486_jumper_close(void *priv) static void * phoenix_486_jumper_init(const device_t *info) { - phoenix_486_jumper_t *dev = (phoenix_486_jumper_t *) malloc(sizeof(phoenix_486_jumper_t)); - memset(dev, 0, sizeof(phoenix_486_jumper_t)); + phoenix_486_jumper_t *dev = (phoenix_486_jumper_t *) calloc(1, sizeof(phoenix_486_jumper_t)); dev->type = info->local; @@ -130,7 +129,7 @@ const device_t phoenix_486_jumper_device = { .init = phoenix_486_jumper_init, .close = phoenix_486_jumper_close, .reset = phoenix_486_jumper_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -144,7 +143,7 @@ const device_t phoenix_486_jumper_pci_device = { .init = phoenix_486_jumper_init, .close = phoenix_486_jumper_close, .reset = phoenix_486_jumper_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/device/postcard.c b/src/device/postcard.c index dbae3232a..9e2c629c1 100644 --- a/src/device/postcard.c +++ b/src/device/postcard.c @@ -187,7 +187,7 @@ const device_t postcard_device = { .init = postcard_init, .close = postcard_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/device/serial.c b/src/device/serial.c index dcaff0f7f..0ba60551c 100644 --- a/src/device/serial.c +++ b/src/device/serial.c @@ -914,8 +914,7 @@ serial_reset(void *priv) static void * serial_init(const device_t *info) { - serial_t *dev = (serial_t *) malloc(sizeof(serial_t)); - memset(dev, 0, sizeof(serial_t)); + serial_t *dev = (serial_t *) calloc(1, sizeof(serial_t)); dev->inst = next_inst; @@ -996,7 +995,7 @@ const device_t ns8250_device = { .init = serial_init, .close = serial_close, .reset = serial_reset, - { .available = NULL }, + .available = NULL, .speed_changed = serial_speed_changed, .force_redraw = NULL, .config = NULL @@ -1010,7 +1009,7 @@ const device_t ns8250_pcjr_device = { .init = serial_init, .close = serial_close, .reset = serial_reset, - { .available = NULL }, + .available = NULL, .speed_changed = serial_speed_changed, .force_redraw = NULL, .config = NULL @@ -1024,7 +1023,7 @@ const device_t ns16450_device = { .init = serial_init, .close = serial_close, .reset = serial_reset, - { .available = NULL }, + .available = NULL, .speed_changed = serial_speed_changed, .force_redraw = NULL, .config = NULL @@ -1038,7 +1037,7 @@ const device_t ns16550_device = { .init = serial_init, .close = serial_close, .reset = serial_reset, - { .available = NULL }, + .available = NULL, .speed_changed = serial_speed_changed, .force_redraw = NULL, .config = NULL @@ -1052,7 +1051,7 @@ const device_t ns16650_device = { .init = serial_init, .close = serial_close, .reset = serial_reset, - { .available = NULL }, + .available = NULL, .speed_changed = serial_speed_changed, .force_redraw = NULL, .config = NULL @@ -1066,7 +1065,7 @@ const device_t ns16750_device = { .init = serial_init, .close = serial_close, .reset = serial_reset, - { .available = NULL }, + .available = NULL, .speed_changed = serial_speed_changed, .force_redraw = NULL, .config = NULL @@ -1080,7 +1079,7 @@ const device_t ns16850_device = { .init = serial_init, .close = serial_close, .reset = serial_reset, - { .available = NULL }, + .available = NULL, .speed_changed = serial_speed_changed, .force_redraw = NULL, .config = NULL @@ -1094,7 +1093,7 @@ const device_t ns16950_device = { .init = serial_init, .close = serial_close, .reset = serial_reset, - { .available = NULL }, + .available = NULL, .speed_changed = serial_speed_changed, .force_redraw = NULL, .config = NULL diff --git a/src/device/serial_passthrough.c b/src/device/serial_passthrough.c index ed5abe618..bb2378a22 100644 --- a/src/device/serial_passthrough.c +++ b/src/device/serial_passthrough.c @@ -178,8 +178,7 @@ serial_passthrough_dev_init(const device_t *info) { serial_passthrough_t *dev; - dev = (serial_passthrough_t *) malloc(sizeof(serial_passthrough_t)); - memset(dev, 0, sizeof(serial_passthrough_t)); + dev = (serial_passthrough_t *) calloc(1, sizeof(serial_passthrough_t)); dev->mode = device_get_config_int("mode"); dev->port = device_get_instance() - 1; @@ -370,13 +369,13 @@ static const device_config_t serial_passthrough_config[] = { // clang-format on const device_t serial_passthrough_device = { - .name = "Serial Passthrough Device", - .flags = 0, - .local = 0, - .init = serial_passthrough_dev_init, - .close = serial_passthrough_dev_close, - .reset = NULL, - { .poll = NULL }, + .name = "Serial Passthrough Device", + .flags = 0, + .local = 0, + .init = serial_passthrough_dev_init, + .close = serial_passthrough_dev_close, + .reset = NULL, + .poll = NULL, .speed_changed = serial_passthrough_speed_changed, .force_redraw = NULL, .config = serial_passthrough_config diff --git a/src/device/smbus_ali7101.c b/src/device/smbus_ali7101.c index 349de470d..3907a065e 100644 --- a/src/device/smbus_ali7101.c +++ b/src/device/smbus_ali7101.c @@ -273,7 +273,7 @@ smbus_ali7101_reset(void *priv) static void * smbus_ali7101_init(const device_t *info) { - smbus_ali7101_t *dev = (smbus_ali7101_t *) malloc(sizeof(smbus_ali7101_t)); + smbus_ali7101_t *dev = (smbus_ali7101_t *) calloc(1, sizeof(smbus_ali7101_t)); memset(dev, 0, sizeof(smbus_ali7101_t)); dev->local = info->local; @@ -307,7 +307,7 @@ const device_t ali7101_smbus_device = { .init = smbus_ali7101_init, .close = smbus_ali7101_close, .reset = smbus_ali7101_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/device/smbus_piix4.c b/src/device/smbus_piix4.c index 6f2b1632e..a9ffcd847 100644 --- a/src/device/smbus_piix4.c +++ b/src/device/smbus_piix4.c @@ -357,8 +357,7 @@ smbus_piix4_setclock(smbus_piix4_t *dev, int clock) static void * smbus_piix4_init(const device_t *info) { - smbus_piix4_t *dev = (smbus_piix4_t *) malloc(sizeof(smbus_piix4_t)); - memset(dev, 0, sizeof(smbus_piix4_t)); + smbus_piix4_t *dev = (smbus_piix4_t *) calloc(1, sizeof(smbus_piix4_t)); dev->local = info->local; /* We save the I2C bus handle on dev but use i2c_smbus for all operations because @@ -392,7 +391,7 @@ const device_t piix4_smbus_device = { .init = smbus_piix4_init, .close = smbus_piix4_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -406,7 +405,7 @@ const device_t via_smbus_device = { .init = smbus_piix4_init, .close = smbus_piix4_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/device/smbus_sis5595.c b/src/device/smbus_sis5595.c index 191e7a6a5..0a24d2355 100644 --- a/src/device/smbus_sis5595.c +++ b/src/device/smbus_sis5595.c @@ -343,8 +343,7 @@ smbus_sis5595_reset(void *priv) static void * smbus_sis5595_init(const device_t *info) { - smbus_sis5595_t *dev = (smbus_sis5595_t *) malloc(sizeof(smbus_sis5595_t)); - memset(dev, 0, sizeof(smbus_sis5595_t)); + smbus_sis5595_t *dev = (smbus_sis5595_t *) calloc(1, sizeof(smbus_sis5595_t)); dev->local = info->local; @@ -379,7 +378,7 @@ const device_t sis5595_smbus_device = { .init = smbus_sis5595_init, .close = smbus_sis5595_close, .reset = smbus_sis5595_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/device/unittester.c b/src/device/unittester.c index 614438fcb..5f0fa5712 100644 --- a/src/device/unittester.c +++ b/src/device/unittester.c @@ -115,12 +115,16 @@ static struct unittester_state unittester_defaults = { }; static const device_config_t unittester_config[] = { - { .name = "exit_enabled", - .description = "Enable 0x04 \"Exit 86Box\" command", - .type = CONFIG_BINARY, - .default_int = 1, - .default_string = "" }, - { .type = CONFIG_END } +// clang-format off + { + .name = "exit_enabled", + .description = "Enable 0x04 \"Exit 86Box\" command", + .type = CONFIG_BINARY, + .default_int = 1, + .default_string = "" + }, + { .name = "", .description = "", .type = CONFIG_END } +// clang-format on }; /* Kept separate, as we will be reusing this object */ @@ -628,7 +632,7 @@ const device_t unittester_device = { .init = unittester_init, .close = unittester_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = unittester_config, diff --git a/src/disk/hdc_esdi_at.c b/src/disk/hdc_esdi_at.c index 7228cba62..adc39d509 100644 --- a/src/disk/hdc_esdi_at.c +++ b/src/disk/hdc_esdi_at.c @@ -920,12 +920,11 @@ wd1007vse1_init(UNUSED(const device_t *info)) { int c; - esdi_t *esdi = malloc(sizeof(esdi_t)); - memset(esdi, 0x00, sizeof(esdi_t)); + esdi_t *esdi = calloc(1, sizeof(esdi_t)); c = 0; for (uint8_t d = 0; d < HDD_NUM; d++) { - if ((hdd[d].bus == HDD_BUS_ESDI) && (hdd[d].esdi_channel < ESDI_NUM)) { + if ((hdd[d].bus_type == HDD_BUS_ESDI) && (hdd[d].esdi_channel < ESDI_NUM)) { loadhd(esdi, hdd[d].esdi_channel, d, hdd[d].fn); if (++c >= ESDI_NUM) @@ -990,7 +989,7 @@ const device_t esdi_at_wd1007vse1_device = { .init = wd1007vse1_init, .close = wd1007vse1_close, .reset = NULL, - { .available = wd1007vse1_available }, + .available = wd1007vse1_available, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/disk/hdc_esdi_mca.c b/src/disk/hdc_esdi_mca.c index c63c80721..b7ab5ff9f 100644 --- a/src/disk/hdc_esdi_mca.c +++ b/src/disk/hdc_esdi_mca.c @@ -1249,10 +1249,9 @@ esdi_init(UNUSED(const device_t *info)) uint8_t c; uint8_t i; - dev = malloc(sizeof(esdi_t)); + dev = calloc(1, sizeof(esdi_t)); if (dev == NULL) return (NULL); - memset(dev, 0x00, sizeof(esdi_t)); /* Mark as unconfigured. */ dev->irq_status = 0xff; @@ -1265,7 +1264,7 @@ esdi_init(UNUSED(const device_t *info)) dev->drives[0].present = dev->drives[1].present = 0; for (c = 0, i = 0; i < HDD_NUM; i++) { - if ((hdd[i].bus == HDD_BUS_ESDI) && (hdd[i].esdi_channel < ESDI_NUM)) { + if ((hdd[i].bus_type == HDD_BUS_ESDI) && (hdd[i].esdi_channel < ESDI_NUM)) { /* This is an ESDI drive. */ drive = &dev->drives[hdd[i].esdi_channel]; @@ -1342,7 +1341,7 @@ const device_t esdi_ps2_device = { .init = esdi_init, .close = esdi_close, .reset = NULL, - { .available = esdi_available }, + .available = esdi_available, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/disk/hdc_ide.c b/src/disk/hdc_ide.c index a212361dc..592649c0e 100644 --- a/src/disk/hdc_ide.c +++ b/src/disk/hdc_ide.c @@ -386,7 +386,7 @@ ide_atapi_get_period(uint8_t channel) } static void -ide_irq_update(ide_board_t *dev, int log) +ide_irq_update(ide_board_t *dev, UNUSED(int log)) { ide_t *ide; uint8_t set; @@ -486,7 +486,7 @@ ide_get_max(const ide_t *ide, const int type) int ret; if (ide->type == IDE_ATAPI) - ret = ide->get_max(!IDE_ATAPI_IS_EARLY && ata_4, type); + ret = ide->get_max(ide, !IDE_ATAPI_IS_EARLY && ata_4, type); else ret = max[ata_4][type]; @@ -501,7 +501,7 @@ ide_get_timings(const ide_t *ide, const int type) int ret; if (ide->type == IDE_ATAPI) - ret = ide->get_timings(!IDE_ATAPI_IS_EARLY && ata_4, type); + ret = ide->get_timings(ide, !IDE_ATAPI_IS_EARLY && ata_4, type); else ret = timings[ata_4][type]; @@ -643,7 +643,7 @@ ide_identify(ide_t *ide) memset(ide->buffer, 0, 512); if (ide->type == IDE_ATAPI) - ide->identify(ide, !IDE_ATAPI_IS_EARLY && !ide_boards[ide->board]->force_ata3 && (bm != NULL)); + ide->identify((const ide_t *) ide, !IDE_ATAPI_IS_EARLY && !ide_boards[ide->board]->force_ata3 && (bm != NULL)); else if (ide->type == IDE_HDD) ide_hd_identify(ide); else { @@ -973,7 +973,7 @@ ide_atapi_attach(ide_t *ide) ide->type = IDE_ATAPI; ide_allocate_buffer(ide); ide_set_signature(ide); - ide->mdma_mode = (1 << ide->get_max(!IDE_ATAPI_IS_EARLY && + ide->mdma_mode = (1 << ide->get_max((const ide_t *) ide, !IDE_ATAPI_IS_EARLY && !ide_boards[ide->board]->force_ata3 && (bm != NULL), TYPE_PIO)); ide->tf->error = 1; ide->cfg_spt = ide->cfg_hpc = 0; @@ -1655,7 +1655,7 @@ ide_writeb(uint16_t addr, uint8_t val, void *priv) ide->sc->callback = 200.0 * IDE_TIME; if (ide->type == IDE_HDD) { - ui_sb_update_icon(SB_HDD | hdd[ide->hdd_num].bus, 1); + ui_sb_update_icon(SB_HDD | hdd[ide->hdd_num].bus_type, 1); uint32_t sec_count; double wait_time; if ((val == WIN_READ_DMA) || (val == WIN_READ_DMA_ALT)) { @@ -1697,7 +1697,7 @@ ide_writeb(uint16_t addr, uint8_t val, void *priv) ide->blockcount = 0; /* Turn on the activity indicator *here* so that it gets turned on less times. */ - ui_sb_update_icon(SB_HDD | hdd[ide->hdd_num].bus, 1); + ui_sb_update_icon(SB_HDD | hdd[ide->hdd_num].bus_type, 1); fallthrough; case WIN_WRITE: @@ -1885,7 +1885,7 @@ ide_read_data(ide_t *ide) ide_set_callback(ide, seek_us + xfer_us); } } else - ui_sb_update_icon(SB_HDD | hdd[ide->hdd_num].bus, 0); + ui_sb_update_icon(SB_HDD | hdd[ide->hdd_num].bus_type, 0); } } } @@ -1894,7 +1894,7 @@ ide_read_data(ide_t *ide) } static uint8_t -ide_status(ide_t *ide, ide_t *ide_other, int ch) +ide_status(ide_t *ide, UNUSED(ide_t *ide_other), UNUSED(int ch)) { uint8_t ret; @@ -2238,7 +2238,7 @@ ide_callback(void *priv) ide_irq_raise(ide); - ui_sb_update_icon(SB_HDD | hdd[ide->hdd_num].bus, 1); + ui_sb_update_icon(SB_HDD | hdd[ide->hdd_num].bus_type, 1); } break; @@ -2277,7 +2277,7 @@ ide_callback(void *priv) ide->tf->atastat = DRDY_STAT | DSC_STAT; ide_irq_raise(ide); - ui_sb_update_icon(SB_HDD | hdd[ide->hdd_num].bus, 0); + ui_sb_update_icon(SB_HDD | hdd[ide->hdd_num].bus_type, 0); } else { /* Bus master DMAS error, abort the command. */ ide_log("IDE %i: DMA read aborted (failed)\n", ide->channel); @@ -2346,10 +2346,10 @@ ide_callback(void *priv) ide->tf->atastat = DRQ_STAT | DRDY_STAT | DSC_STAT; ide->tf->pos = 0; ide_next_sector(ide); - ui_sb_update_icon(SB_HDD | hdd[ide->hdd_num].bus, 1); + ui_sb_update_icon(SB_HDD | hdd[ide->hdd_num].bus_type, 1); } else { ide->tf->atastat = DRDY_STAT | DSC_STAT; - ui_sb_update_icon(SB_HDD | hdd[ide->hdd_num].bus, 0); + ui_sb_update_icon(SB_HDD | hdd[ide->hdd_num].bus_type, 0); } if (ret < 0) err = UNC_ERR; @@ -2391,7 +2391,7 @@ ide_callback(void *priv) err = UNC_ERR; ide_irq_raise(ide); - ui_sb_update_icon(SB_HDD | hdd[ide->hdd_num].bus, 0); + ui_sb_update_icon(SB_HDD | hdd[ide->hdd_num].bus_type, 0); } else { /* Bus master DMA error, abort the command. */ ide_log("IDE %i: DMA read aborted (failed)\n", ide->channel); @@ -2429,7 +2429,7 @@ ide_callback(void *priv) ide_next_sector(ide); } else { ide->tf->atastat = DRDY_STAT | DSC_STAT; - ui_sb_update_icon(SB_HDD | hdd[ide->hdd_num].bus, 0); + ui_sb_update_icon(SB_HDD | hdd[ide->hdd_num].bus_type, 0); } if (ret < 0) err = UNC_ERR; @@ -2446,7 +2446,7 @@ ide_callback(void *priv) ide->tf->pos = 0; ide->tf->atastat = DRDY_STAT | DSC_STAT; ide_irq_raise(ide); - ui_sb_update_icon(SB_HDD | hdd[ide->hdd_num].bus, 1); + ui_sb_update_icon(SB_HDD | hdd[ide->hdd_num].bus_type, 1); } break; @@ -2463,7 +2463,7 @@ ide_callback(void *priv) err = UNC_ERR; ide_irq_raise(ide); - ui_sb_update_icon(SB_HDD | hdd[ide->hdd_num].bus, 1); + ui_sb_update_icon(SB_HDD | hdd[ide->hdd_num].bus_type, 1); } break; @@ -2759,7 +2759,7 @@ ide_board_setup(const int board) c = 0; for (d = 0; d < HDD_NUM; d++) { - const int is_ide = (hdd[d].bus == HDD_BUS_IDE); + const int is_ide = (hdd[d].bus_type == HDD_BUS_IDE); const int ch = hdd[d].ide_channel; const int valid_ch = ((ch >= min_ch) && (ch <= max_ch)); @@ -3207,7 +3207,7 @@ mcide_mca_reset(void *priv) } static void -mcide_reset(void *priv) +mcide_reset(UNUSED(void *priv)) { for (uint8_t i = 0; i < 2; i++) { if (ide_boards[i] != NULL) @@ -3269,7 +3269,7 @@ const device_t ide_isa_device = { .init = ide_init, .close = ide_close, .reset = ide_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -3283,7 +3283,7 @@ const device_t ide_isa_2ch_device = { .init = ide_init, .close = ide_close, .reset = ide_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -3297,7 +3297,7 @@ const device_t ide_vlb_device = { .init = ide_init, .close = ide_close, .reset = ide_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -3311,7 +3311,7 @@ const device_t ide_vlb_2ch_device = { .init = ide_init, .close = ide_close, .reset = ide_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -3325,7 +3325,7 @@ const device_t ide_pci_device = { .init = ide_init, .close = ide_close, .reset = ide_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -3339,7 +3339,7 @@ const device_t ide_pci_2ch_device = { .init = ide_init, .close = ide_close, .reset = ide_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -3353,7 +3353,7 @@ const device_t mcide_device = { .init = mcide_init, .close = mcide_close, .reset = mcide_reset, - { .available = mcide_available }, + .available = mcide_available, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -3422,7 +3422,7 @@ const device_t ide_ter_device = { .init = ide_ter_init, .close = ide_ter_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = ide_ter_config @@ -3436,7 +3436,7 @@ const device_t ide_ter_pnp_device = { .init = ide_ter_init, .close = ide_ter_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -3450,7 +3450,7 @@ const device_t ide_qua_device = { .init = ide_qua_init, .close = ide_qua_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = ide_qua_config @@ -3464,7 +3464,7 @@ const device_t ide_qua_pnp_device = { .init = ide_qua_init, .close = ide_qua_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/disk/hdc_ide_ali5213.c b/src/disk/hdc_ide_ali5213.c index 8ff3d392c..67f959e1a 100644 --- a/src/disk/hdc_ide_ali5213.c +++ b/src/disk/hdc_ide_ali5213.c @@ -246,7 +246,7 @@ const device_t ide_ali1489_device = { .init = ali5213_init, .close = ali5213_close, .reset = ali5213_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -260,7 +260,7 @@ const device_t ide_ali5213_device = { .init = ali5213_init, .close = ali5213_close, .reset = ali5213_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/disk/hdc_ide_cmd640.c b/src/disk/hdc_ide_cmd640.c index 3e77730a2..84a40efa4 100644 --- a/src/disk/hdc_ide_cmd640.c +++ b/src/disk/hdc_ide_cmd640.c @@ -504,8 +504,7 @@ cmd640_close(void *priv) static void * cmd640_init(const device_t *info) { - cmd640_t *dev = (cmd640_t *) malloc(sizeof(cmd640_t)); - memset(dev, 0x00, sizeof(cmd640_t)); + cmd640_t *dev = (cmd640_t *) calloc(1, sizeof(cmd640_t)); dev->id = next_id | 0x60; @@ -563,7 +562,7 @@ const device_t ide_cmd640_vlb_device = { .init = cmd640_init, .close = cmd640_close, .reset = cmd640_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -577,7 +576,7 @@ const device_t ide_cmd640_vlb_178_device = { .init = cmd640_init, .close = cmd640_close, .reset = cmd640_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -591,7 +590,7 @@ const device_t ide_cmd640_vlb_pri_device = { .init = cmd640_init, .close = cmd640_close, .reset = cmd640_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -605,7 +604,7 @@ const device_t ide_cmd640_vlb_pri_178_device = { .init = cmd640_init, .close = cmd640_close, .reset = cmd640_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -619,7 +618,7 @@ const device_t ide_cmd640_vlb_sec_device = { .init = cmd640_init, .close = cmd640_close, .reset = cmd640_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -633,7 +632,7 @@ const device_t ide_cmd640_vlb_sec_178_device = { .init = cmd640_init, .close = cmd640_close, .reset = cmd640_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -647,7 +646,7 @@ const device_t ide_cmd640_pci_device = { .init = cmd640_init, .close = cmd640_close, .reset = cmd640_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -661,7 +660,7 @@ const device_t ide_cmd640_pci_legacy_only_device = { .init = cmd640_init, .close = cmd640_close, .reset = cmd640_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -675,7 +674,7 @@ const device_t ide_cmd640_pci_single_channel_device = { .init = cmd640_init, .close = cmd640_close, .reset = cmd640_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -689,7 +688,7 @@ const device_t ide_cmd640_pci_single_channel_sec_device = { .init = cmd640_init, .close = cmd640_close, .reset = cmd640_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/disk/hdc_ide_cmd646.c b/src/disk/hdc_ide_cmd646.c index 8367b9a41..b548390fd 100644 --- a/src/disk/hdc_ide_cmd646.c +++ b/src/disk/hdc_ide_cmd646.c @@ -391,8 +391,7 @@ cmd646_close(void *priv) static void * cmd646_init(const device_t *info) { - cmd646_t *dev = (cmd646_t *) malloc(sizeof(cmd646_t)); - memset(dev, 0x00, sizeof(cmd646_t)); + cmd646_t *dev = (cmd646_t *) calloc(1, sizeof(cmd646_t)); dev->local = info->local; @@ -431,7 +430,7 @@ const device_t ide_cmd646_device = { .init = cmd646_init, .close = cmd646_close, .reset = cmd646_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -445,7 +444,7 @@ const device_t ide_cmd646_legacy_only_device = { .init = cmd646_init, .close = cmd646_close, .reset = cmd646_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -459,7 +458,7 @@ const device_t ide_cmd646_single_channel_device = { .init = cmd646_init, .close = cmd646_close, .reset = cmd646_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/disk/hdc_ide_opti611.c b/src/disk/hdc_ide_opti611.c index 480331201..4927b5fe3 100644 --- a/src/disk/hdc_ide_opti611.c +++ b/src/disk/hdc_ide_opti611.c @@ -317,8 +317,7 @@ opti611_close(void *priv) static void * opti611_init(UNUSED(const device_t *info)) { - opti611_t *dev = (opti611_t *) malloc(sizeof(opti611_t)); - memset(dev, 0, sizeof(opti611_t)); + opti611_t *dev = (opti611_t *) calloc(1, sizeof(opti611_t)); dev->is_sec = info->local; @@ -341,7 +340,7 @@ const device_t ide_opti611_vlb_device = { .init = opti611_init, .close = opti611_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -355,7 +354,7 @@ const device_t ide_opti611_vlb_sec_device = { .init = opti611_init, .close = opti611_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/disk/hdc_ide_sff8038i.c b/src/disk/hdc_ide_sff8038i.c index 631afa931..73dc5f36b 100644 --- a/src/disk/hdc_ide_sff8038i.c +++ b/src/disk/hdc_ide_sff8038i.c @@ -475,19 +475,22 @@ sff_reset(void *priv) #endif for (uint8_t i = 0; i < HDD_NUM; i++) { - if ((hdd[i].bus == HDD_BUS_ATAPI) && (hdd[i].ide_channel < 4) && hdd[i].priv) + if ((hdd[i].bus_type == HDD_BUS_ATAPI) && (hdd[i].ide_channel < 4) && hdd[i].priv) scsi_disk_reset((scsi_common_t *) hdd[i].priv); } for (uint8_t i = 0; i < CDROM_NUM; i++) { - if ((cdrom[i].bus_type == CDROM_BUS_ATAPI) && (cdrom[i].ide_channel < 4) && cdrom[i].priv) + if ((cdrom[i].bus_type == CDROM_BUS_ATAPI) && (cdrom[i].ide_channel < 4) && + cdrom[i].priv) scsi_cdrom_reset((scsi_common_t *) cdrom[i].priv); } for (uint8_t i = 0; i < ZIP_NUM; i++) { - if ((zip_drives[i].bus_type == ZIP_BUS_ATAPI) && (zip_drives[i].ide_channel < 4) && zip_drives[i].priv) + if ((zip_drives[i].bus_type == ZIP_BUS_ATAPI) && (zip_drives[i].ide_channel < 4) && + zip_drives[i].priv) zip_reset((scsi_common_t *) zip_drives[i].priv); } for (uint8_t i = 0; i < MO_NUM; i++) { - if ((mo_drives[i].bus_type == MO_BUS_ATAPI) && (mo_drives[i].ide_channel < 4) && mo_drives[i].priv) + if ((mo_drives[i].bus_type == MO_BUS_ATAPI) && (mo_drives[i].ide_channel < 4) && + mo_drives[i].priv) mo_reset((scsi_common_t *) mo_drives[i].priv); } @@ -575,8 +578,7 @@ sff_close(void *priv) static void * sff_init(UNUSED(const device_t *info)) { - sff8038i_t *dev = (sff8038i_t *) malloc(sizeof(sff8038i_t)); - memset(dev, 0, sizeof(sff8038i_t)); + sff8038i_t *dev = (sff8038i_t *) calloc(1, sizeof(sff8038i_t)); /* Make sure to only add IDE once. */ if (next_id == 0) @@ -608,7 +610,7 @@ const device_t sff8038i_device = { .init = sff_init, .close = sff_close, .reset = sff_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/disk/hdc_ide_um8673f.c b/src/disk/hdc_ide_um8673f.c index bc046dd26..b40595750 100644 --- a/src/disk/hdc_ide_um8673f.c +++ b/src/disk/hdc_ide_um8673f.c @@ -191,7 +191,7 @@ const device_t ide_um8886af_device = { .init = um8673f_init, .close = um8673f_close, .reset = um8673f_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -205,7 +205,7 @@ const device_t ide_um8673f_device = { .init = um8673f_init, .close = um8673f_close, .reset = um8673f_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/disk/hdc_ide_w83769f.c b/src/disk/hdc_ide_w83769f.c index 608d7a8a7..9c0f744b2 100644 --- a/src/disk/hdc_ide_w83769f.c +++ b/src/disk/hdc_ide_w83769f.c @@ -353,8 +353,7 @@ w83769f_close(void *priv) static void * w83769f_init(const device_t *info) { - w83769f_t *dev = (w83769f_t *) malloc(sizeof(w83769f_t)); - memset(dev, 0x00, sizeof(w83769f_t)); + w83769f_t *dev = (w83769f_t *) calloc(1, sizeof(w83769f_t)); dev->id = next_id | 0x60; @@ -410,7 +409,7 @@ const device_t ide_w83769f_vlb_device = { .init = w83769f_init, .close = w83769f_close, .reset = w83769f_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -424,7 +423,7 @@ const device_t ide_w83769f_vlb_34_device = { .init = w83769f_init, .close = w83769f_close, .reset = w83769f_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -438,7 +437,7 @@ const device_t ide_w83769f_pci_device = { .init = w83769f_init, .close = w83769f_close, .reset = w83769f_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -452,7 +451,7 @@ const device_t ide_w83769f_pci_34_device = { .init = w83769f_init, .close = w83769f_close, .reset = w83769f_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -466,9 +465,8 @@ const device_t ide_w83769f_pci_single_channel_device = { .init = w83769f_init, .close = w83769f_close, .reset = w83769f_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL }; - diff --git a/src/disk/hdc_st506_at.c b/src/disk/hdc_st506_at.c index 9e5b82336..eeb242a94 100644 --- a/src/disk/hdc_st506_at.c +++ b/src/disk/hdc_st506_at.c @@ -744,12 +744,11 @@ mfm_init(UNUSED(const device_t *info)) int c; st506_at_log("WD1003: ISA MFM/RLL Fixed Disk Adapter initializing ...\n"); - mfm = malloc(sizeof(mfm_t)); - memset(mfm, 0x00, sizeof(mfm_t)); + mfm = calloc(1, sizeof(mfm_t)); c = 0; for (uint8_t d = 0; d < HDD_NUM; d++) { - if ((hdd[d].bus == HDD_BUS_MFM) && (hdd[d].mfm_channel < MFM_NUM)) { + if ((hdd[d].bus_type == HDD_BUS_MFM) && (hdd[d].mfm_channel < MFM_NUM)) { loadhd(mfm, hdd[d].mfm_channel, d, hdd[d].fn); st506_at_log("WD1003(%d): (%s) geometry %d/%d/%d\n", c, hdd[d].fn, @@ -801,7 +800,7 @@ const device_t st506_at_wd1003_device = { .init = mfm_init, .close = mfm_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/disk/hdc_st506_xt.c b/src/disk/hdc_st506_xt.c index 766b28086..789e7e6c4 100644 --- a/src/disk/hdc_st506_xt.c +++ b/src/disk/hdc_st506_xt.c @@ -1627,8 +1627,7 @@ st506_init(const device_t *info) int i; int c; - dev = (hdc_t *) malloc(sizeof(hdc_t)); - memset(dev, 0x00, sizeof(hdc_t)); + dev = (hdc_t *) calloc(1, sizeof(hdc_t)); dev->type = info->local & 255; /* Set defaults for the controller. */ @@ -1799,7 +1798,7 @@ st506_init(const device_t *info) st506_xt_log("ST506: looking for disks...\n"); #endif for (c = 0, i = 0; i < HDD_NUM; i++) { - if ((hdd[i].bus == HDD_BUS_MFM) && (hdd[i].mfm_channel < MFM_NUM)) { + if ((hdd[i].bus_type == HDD_BUS_MFM) && (hdd[i].mfm_channel < MFM_NUM)) { st506_xt_log("ST506: disk '%s' on channel %i\n", hdd[i].fn, hdd[i].mfm_channel); loadhd(dev, hdd[i].mfm_channel, i, hdd[i].fn); @@ -2258,7 +2257,7 @@ const device_t st506_xt_xebec_device = { .init = st506_init, .close = st506_close, .reset = NULL, - { .available = xebec_available }, + .available = xebec_available, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2272,7 +2271,7 @@ const device_t st506_xt_wdxt_gen_device = { .init = st506_init, .close = st506_close, .reset = NULL, - { .available = wdxt_available }, + .available = wdxt_available, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2286,7 +2285,7 @@ const device_t st506_xt_dtc5150x_device = { .init = st506_init, .close = st506_close, .reset = NULL, - { .available = dtc5150x_available }, + .available = dtc5150x_available, .speed_changed = NULL, .force_redraw = NULL, .config = dtc_config @@ -2300,7 +2299,7 @@ const device_t st506_xt_st11_m_device = { .init = st506_init, .close = st506_close, .reset = NULL, - { .available = st11_m_available }, + .available = st11_m_available, .speed_changed = NULL, .force_redraw = NULL, .config = st11_config @@ -2314,7 +2313,7 @@ const device_t st506_xt_st11_r_device = { .init = st506_init, .close = st506_close, .reset = NULL, - { .available = st11_r_available }, + .available = st11_r_available, .speed_changed = NULL, .force_redraw = NULL, .config = st11_config @@ -2328,7 +2327,7 @@ const device_t st506_xt_wd1002a_wx1_device = { .init = st506_init, .close = st506_close, .reset = NULL, - { .available = wd1002a_wx1_available }, + .available = wd1002a_wx1_available, .speed_changed = NULL, .force_redraw = NULL, .config = wd_config @@ -2342,7 +2341,7 @@ const device_t st506_xt_wd1002a_wx1_nobios_device = { .init = st506_init, .close = st506_close, .reset = NULL, - { .available = wd1002a_wx1_available }, + .available = wd1002a_wx1_available, .speed_changed = NULL, .force_redraw = NULL, .config = wd_nobios_config @@ -2356,7 +2355,7 @@ const device_t st506_xt_wd1002a_27x_device = { .init = st506_init, .close = st506_close, .reset = NULL, - { .available = wd1002a_27x_available }, + .available = wd1002a_27x_available, .speed_changed = NULL, .force_redraw = NULL, .config = wd_rll_config @@ -2370,7 +2369,7 @@ const device_t st506_xt_wd1004a_wx1_device = { .init = st506_init, .close = st506_close, .reset = NULL, - { .available = wd1004a_wx1_available }, + .available = wd1004a_wx1_available, .speed_changed = NULL, .force_redraw = NULL, .config = wd1004a_config @@ -2384,7 +2383,7 @@ const device_t st506_xt_wd1004_27x_device = { .init = st506_init, .close = st506_close, .reset = NULL, - { .available = wd1004_27x_available }, + .available = wd1004_27x_available, .speed_changed = NULL, .force_redraw = NULL, .config = wd1004_rll_config @@ -2398,7 +2397,7 @@ const device_t st506_xt_wd1004a_27x_device = { .init = st506_init, .close = st506_close, .reset = NULL, - { .available = wd1004a_27x_available }, + .available = wd1004a_27x_available, .speed_changed = NULL, .force_redraw = NULL, .config = wd_rll_config @@ -2412,7 +2411,7 @@ const device_t st506_xt_victor_v86p_device = { .init = st506_init, .close = st506_close, .reset = NULL, - { .available = victor_v86p_available }, + .available = victor_v86p_available, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2426,7 +2425,7 @@ const device_t st506_xt_toshiba_t1200_device = { .init = st506_init, .close = st506_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/disk/hdc_xta.c b/src/disk/hdc_xta.c index a65ab5c69..553e53b48 100644 --- a/src/disk/hdc_xta.c +++ b/src/disk/hdc_xta.c @@ -1000,8 +1000,7 @@ xta_init(const device_t *info) int max = XTA_NUM; /* Allocate and initialize device block. */ - dev = malloc(sizeof(hdc_t)); - memset(dev, 0x00, sizeof(hdc_t)); + dev = calloc(1, sizeof(hdc_t)); dev->type = info->local; /* Do per-controller-type setup. */ @@ -1038,7 +1037,7 @@ xta_init(const device_t *info) /* Load any disks for this device class. */ c = 0; for (uint8_t i = 0; i < HDD_NUM; i++) { - if ((hdd[i].bus == HDD_BUS_XTA) && (hdd[i].xta_channel < max)) { + if ((hdd[i].bus_type == HDD_BUS_XTA) && (hdd[i].xta_channel < max)) { drive = &dev->drives[hdd[i].xta_channel]; if (!hdd_image_load(i)) { @@ -1170,29 +1169,29 @@ static const device_config_t wdxt150_config[] = { }; const device_t xta_wdxt150_device = { - .name = "WDXT-150 XTA Fixed Disk Controller", + .name = "WDXT-150 XTA Fixed Disk Controller", .internal_name = "xta_wdxt150", - .flags = DEVICE_ISA, - .local = 0, - .init = xta_init, - .close = xta_close, - .reset = NULL, - { .available = NULL /*xta_available*/ }, + .flags = DEVICE_ISA, + .local = 0, + .init = xta_init, + .close = xta_close, + .reset = NULL, + .available = NULL /*xta_available*/, .speed_changed = NULL, - .force_redraw = NULL, - .config = wdxt150_config + .force_redraw = NULL, + .config = wdxt150_config }; const device_t xta_hd20_device = { - .name = "EuroPC HD20 Fixed Disk Controller", + .name = "EuroPC HD20 Fixed Disk Controller", .internal_name = "xta_hd20", - .flags = DEVICE_ISA, - .local = 1, - .init = xta_init, - .close = xta_close, - .reset = NULL, - { .available = NULL }, + .flags = DEVICE_ISA, + .local = 1, + .init = xta_init, + .close = xta_close, + .reset = NULL, + .available = NULL, .speed_changed = NULL, - .force_redraw = NULL, - .config = NULL + .force_redraw = NULL, + .config = NULL }; diff --git a/src/disk/hdc_xtide.c b/src/disk/hdc_xtide.c index b324b4d32..7ec7695b3 100644 --- a/src/disk/hdc_xtide.c +++ b/src/disk/hdc_xtide.c @@ -132,13 +132,11 @@ xtide_read(uint16_t port, void *priv) static void * xtide_init(const device_t *info) { - xtide_t *xtide = malloc(sizeof(xtide_t)); + xtide_t *xtide = calloc(1, sizeof(xtide_t)); - memset(xtide, 0x00, sizeof(xtide_t)); - - rom_init(&xtide->bios_rom, - device_get_bios_file(info, device_get_config_bios("bios"), 0), - 0xc8000, 0x2000, 0x1fff, 0, MEM_MAPPING_EXTERNAL); + rom_init(&xtide->bios_rom, + device_get_bios_file(info, device_get_config_bios("bios"), 0), + 0xc8000, 0x2000, 0x1fff, 0, MEM_MAPPING_EXTERNAL); xtide->ide_board = ide_xtide_init(); @@ -152,13 +150,11 @@ xtide_init(const device_t *info) static void * xtide_at_init(const device_t *info) { - xtide_t *xtide = malloc(sizeof(xtide_t)); + xtide_t *xtide = calloc(1, sizeof(xtide_t)); - memset(xtide, 0x00, sizeof(xtide_t)); - - rom_init(&xtide->bios_rom, - device_get_bios_file(info, device_get_config_bios("bios"), 0), - 0xc8000, 0x2000, 0x1fff, 0, MEM_MAPPING_EXTERNAL); + rom_init(&xtide->bios_rom, + device_get_bios_file(info, device_get_config_bios("bios"), 0), + 0xc8000, 0x2000, 0x1fff, 0, MEM_MAPPING_EXTERNAL); device_add(&ide_isa_2ch_device); @@ -168,9 +164,7 @@ xtide_at_init(const device_t *info) static void * xtide_acculogic_init(UNUSED(const device_t *info)) { - xtide_t *xtide = malloc(sizeof(xtide_t)); - - memset(xtide, 0x00, sizeof(xtide_t)); + xtide_t *xtide = calloc(1, sizeof(xtide_t)); rom_init(&xtide->bios_rom, ROM_PATH_PS2, 0xc8000, 0x2000, 0x1fff, 0, MEM_MAPPING_EXTERNAL); @@ -203,9 +197,7 @@ xtide_close(void *priv) static void * xtide_at_ps2_init(UNUSED(const device_t *info)) { - xtide_t *xtide = malloc(sizeof(xtide_t)); - - memset(xtide, 0x00, sizeof(xtide_t)); + xtide_t *xtide = calloc(1, sizeof(xtide_t)); rom_init(&xtide->bios_rom, ROM_PATH_PS2AT, 0xc8000, 0x2000, 0x1fff, 0, MEM_MAPPING_EXTERNAL); @@ -281,7 +273,7 @@ const device_t xtide_device = { .init = xtide_init, .close = xtide_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = xtide_config @@ -295,7 +287,7 @@ const device_t xtide_at_device = { .init = xtide_at_init, .close = xtide_at_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = xtide_at_config @@ -309,7 +301,7 @@ const device_t xtide_acculogic_device = { .init = xtide_acculogic_init, .close = xtide_close, .reset = NULL, - { .available = xtide_acculogic_available }, + .available = xtide_acculogic_available, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -323,7 +315,7 @@ const device_t xtide_at_ps2_device = { .init = xtide_at_ps2_init, .close = xtide_at_close, .reset = NULL, - { .available = xtide_at_ps2_available }, + .available = xtide_at_ps2_available, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/disk/hdd.c b/src/disk/hdd.c index c17f64863..8292dc472 100644 --- a/src/disk/hdd.c +++ b/src/disk/hdd.c @@ -123,7 +123,7 @@ hdd_bus_to_string(int bus, UNUSED(int cdrom)) int hdd_is_valid(int c) { - if (hdd[c].bus == HDD_BUS_DISABLED) + if (hdd[c].bus_type == HDD_BUS_DISABLED) return 0; if (strlen(hdd[c].fn) == 0) @@ -415,35 +415,35 @@ static hdd_preset_t hdd_speed_presets[] = { { .name = "[1997] 5400 RPM", .internal_name = "1997_5400rpm", .zones = 16, .avg_spt = 185, .heads = 6, .rpm = 5400, .full_stroke_ms = 20, .track_seek_ms = 2.5, .rcache_num_seg = 8, .rcache_seg_size = 64, .max_multiple = 32 }, { .name = "[1998] 5400 RPM", .internal_name = "1998_5400rpm", .zones = 16, .avg_spt = 300, .heads = 8, .rpm = 5400, .full_stroke_ms = 20, .track_seek_ms = 2, .rcache_num_seg = 8, .rcache_seg_size = 128, .max_multiple = 32 }, { .name = "[2000] 7200 RPM", .internal_name = "2000_7200rpm", .zones = 16, .avg_spt = 350, .heads = 6, .rpm = 7200, .full_stroke_ms = 15, .track_seek_ms = 2, .rcache_num_seg = 16, .rcache_seg_size = 128, .max_multiple = 32 }, - { .name = "[PIO IDE] IBM WDA-L42", .internal_name = "WDAL42", .model = "IBM-WDA-L42", .zones = 1, .avg_spt = 85, .heads = 2, .rpm = 3600, .full_stroke_ms = 33, .track_seek_ms = 2.5, .rcache_num_seg = 1, .rcache_seg_size = 32, .max_multiple = 1 }, + { .name = "[PIO IDE] IBM WDA-L42", .internal_name = "WDAL42", .model = "WDA-L42", .zones = 1, .avg_spt = 85, .heads = 2, .rpm = 3600, .full_stroke_ms = 33, .track_seek_ms = 2.5, .rcache_num_seg = 1, .rcache_seg_size = 32, .max_multiple = 1 }, { .name = "[ATA-1] Conner CP3024", .internal_name = "CP3024", .model = "Conner Peripherals 20MB - CP3024", .zones = 1, .avg_spt = 33, .heads = 2, .rpm = 3500, .full_stroke_ms = 50, .track_seek_ms = 8, .rcache_num_seg = 1, .rcache_seg_size = 8, .max_multiple = 8 }, // Needed for GRiDcase 1520 to work { .name = "[ATA-1] Conner CP3044", .internal_name = "CP3044", .model = "Conner Peripherals 40MB - CP3044", .zones = 1, .avg_spt = 40, .heads = 2, .rpm = 3500, .full_stroke_ms = 50, .track_seek_ms = 8, .rcache_num_seg = 1, .rcache_seg_size = 8, .max_multiple = 8 }, // Needed for GRiDcase 1520 to work { .name = "[ATA-1] Conner CP3104", .internal_name = "CP3104", .model = "Conner Peripherals 104MB - CP3104", .zones = 1, .avg_spt = 33, .heads = 8, .rpm = 3500, .full_stroke_ms = 45, .track_seek_ms = 8, .rcache_num_seg = 4, .rcache_seg_size = 8, .max_multiple = 8 }, // Needed for GRiDcase 1520 to work - { .name = "[ATA-1] Conner CFS420A", .internal_name = "CFS420A", .model = "Conner Peripherals 420MB - CFS420A", .zones = 1, .avg_spt = 140, .heads = 2, .rpm = 3600, .full_stroke_ms = 33, .track_seek_ms = 3, .rcache_num_seg = 4, .rcache_seg_size = 32, .max_multiple = 8 }, - { .name = "[ATA-1] HP Kittyhawk", .internal_name = "C3014A", .model = "HP C3014A", .zones = 6, .avg_spt = 180, .heads = 3, .rpm = 5400, .full_stroke_ms = 18, .track_seek_ms = 3, .rcache_num_seg = 4, .rcache_seg_size = 16, .max_multiple = 8 }, - { .name = "[ATA-1] IBM H3256-A3", .internal_name = "H3256A3", .model = "IBM-H3256-A3", .zones = 1, .avg_spt = 140, .heads = 2, .rpm = 3600, .full_stroke_ms = 32, .track_seek_ms = 4, .rcache_num_seg = 4, .rcache_seg_size = 96, .max_multiple = 8 }, - { .name = "[ATA-1] IBM H3342-A4", .internal_name = "H3342A4", .model = "IBM-H3342-A4", .zones = 1, .avg_spt = 140, .heads = 2, .rpm = 3600, .full_stroke_ms = 30, .track_seek_ms = 4, .rcache_num_seg = 4, .rcache_seg_size = 96, .max_multiple = 8 }, - { .name = "[ATA-1] Kalok KL343", .internal_name = "KL343", .model = "KALOK KL-343", .zones = 1, .avg_spt = 280, .heads = 6, .rpm = 3600, .full_stroke_ms = 50, .track_seek_ms = 2, .rcache_num_seg = 1, .rcache_seg_size = 8, .max_multiple = 8 }, - { .name = "[ATA-1] Kalok KL3100", .internal_name = "KL3100", .model = "KALOK KL-3100", .zones = 1, .avg_spt = 200, .heads = 6, .rpm = 3662, .full_stroke_ms = 50, .track_seek_ms = 2, .rcache_num_seg = 1, .rcache_seg_size = 32, .max_multiple = 8 }, - { .name = "[ATA-1] Maxtor 7060AT", .internal_name = "7060AT", .model = "Maxtor 7060AT", .zones = 1, .avg_spt = 162, .heads = 2, .rpm = 3524, .full_stroke_ms = 30, .track_seek_ms = 3.6, .rcache_num_seg = 1, .rcache_seg_size = 64, .max_multiple = 8 }, - { .name = "[ATA-1] Maxtor 7131AT", .internal_name = "7131AT", .model = "Maxtor 7131AT", .zones = 2, .avg_spt = 154, .heads = 2, .rpm = 3551, .full_stroke_ms = 27, .track_seek_ms = 4.5, .rcache_num_seg = 1, .rcache_seg_size = 64, .max_multiple = 8 }, - { .name = "[ATA-1] Maxtor 7213AT", .internal_name = "7213AT", .model = "Maxtor 7213AT", .zones = 4, .avg_spt = 155, .heads = 4, .rpm = 3551, .full_stroke_ms = 28, .track_seek_ms = 6.5, .rcache_num_seg = 1, .rcache_seg_size = 64, .max_multiple = 8 }, - { .name = "[ATA-1] Maxtor 7245AT", .internal_name = "7245AT", .model = "Maxtor 7245AT", .zones = 4, .avg_spt = 149, .heads = 4, .rpm = 3551, .full_stroke_ms = 27, .track_seek_ms = 4.4, .rcache_num_seg = 8, .rcache_seg_size = 64, .max_multiple = 8 }, - { .name = "[ATA-1] Quantum ProDrive LPS 105", .internal_name = "LPS105AT", .model = "QUANTUM PRODRIVE 105", .zones = 1, .avg_spt = 170, .heads = 2, .rpm = 3662, .full_stroke_ms = 45, .track_seek_ms = 5, .rcache_num_seg = 1, .rcache_seg_size = 64, .max_multiple = 8 }, - { .name = "[ATA-1] Quantum ProDrive LPS 120AT", .internal_name = "GM12A012", .model = "QUANTUM PRODRIVE 120AT", .zones = 1, .avg_spt = 150, .heads = 2, .rpm = 3605, .full_stroke_ms = 45, .track_seek_ms = 4, .rcache_num_seg = 1, .rcache_seg_size = 64, .max_multiple = 8 }, - { .name = "[ATA-1] Seagate ST3243A", .internal_name = "ST3243A", .model = "ST3243A", .zones = 1, .avg_spt = 140, .heads = 4, .rpm = 3811, .full_stroke_ms = 32, .track_seek_ms = 4, .rcache_num_seg = 4, .rcache_seg_size = 32, .max_multiple = 8 }, - { .name = "[ATA-1] Western Digital Caviar 140", .internal_name = "AC140", .model = "WDC AC140", .zones = 4, .avg_spt = 170, .heads = 2, .rpm = 3551, .full_stroke_ms = 28, .track_seek_ms = 6, .rcache_num_seg = 8, .rcache_seg_size = 8, .max_multiple = 8 }, - { .name = "[ATA-1] Western Digital Caviar 280", .internal_name = "AC280", .model = "WDC AC280", .zones = 4, .avg_spt = 170, .heads = 4, .rpm = 3595, .full_stroke_ms = 28, .track_seek_ms = 6, .rcache_num_seg = 8, .rcache_seg_size = 32, .max_multiple = 8 }, - { .name = "[ATA-1] Western Digital Caviar 1210", .internal_name = "AC1210", .model = "WDC AC1210F", .zones = 4, .avg_spt = 130, .heads = 2, .rpm = 3314, .full_stroke_ms = 33, .track_seek_ms = 4, .rcache_num_seg = 4, .rcache_seg_size = 128, .max_multiple = 8 }, - { .name = "[ATA-1] Western Digital Caviar 2120", .internal_name = "AC2120", .model = "WDC AC2120M", .zones = 4, .avg_spt = 140, .heads = 2, .rpm = 3605, .full_stroke_ms = 28, .track_seek_ms = 2.8, .rcache_num_seg = 8, .rcache_seg_size = 32, .max_multiple = 8 }, - { .name = "[ATA-2] IBM DBOA-2720", .internal_name = "DBOA2720", .model = "IBM-DBOA-2720", .zones = 2, .avg_spt = 135, .heads = 2, .rpm = 4000, .full_stroke_ms = 30, .track_seek_ms = 5, .rcache_num_seg = 4, .rcache_seg_size = 64, .max_multiple = 8 }, - { .name = "[ATA-2] IBM DeskStar 4 (DCAA-32880)", .internal_name = "DCAA32880", .model = "IBM-DCAA-32880", .zones = 8, .avg_spt = 85, .heads = 2, .rpm = 5400, .full_stroke_ms = 19, .track_seek_ms = 1.7, .rcache_num_seg = 4, .rcache_seg_size = 96, .max_multiple = 16 }, - { .name = "[ATA-2] IBM DeskStar 4 (DCAA-33610)", .internal_name = "DCAA33610", .model = "IBM-DCAA-33610", .zones = 8, .avg_spt = 85, .heads = 3, .rpm = 5400, .full_stroke_ms = 19, .track_seek_ms = 1.7, .rcache_num_seg = 4, .rcache_seg_size = 96, .max_multiple = 16 }, - { .name = "[ATA-2] IBM DeskStar 4 (DCAA-34330)", .internal_name = "DCAA34330", .model = "IBM-DCAA-34330", .zones = 8, .avg_spt = 85, .heads = 3, .rpm = 5400, .full_stroke_ms = 19, .track_seek_ms = 1.7, .rcache_num_seg = 4, .rcache_seg_size = 96, .max_multiple = 16 }, - { .name = "[ATA-2] Maxtor 7540AV", .internal_name = "7540AV", .model = "Maxtor 7540AV", .zones = 2, .avg_spt = 120, .heads = 4, .rpm = 3551, .full_stroke_ms = 31, .track_seek_ms = 4.3, .rcache_num_seg = 4, .rcache_seg_size = 32, .max_multiple = 8 }, - { .name = "[ATA-2] Maxtor 7546AT", .internal_name = "7546AT", .model = "Maxtor 7546AT", .zones = 2, .avg_spt = 100, .heads = 4, .rpm = 4500, .full_stroke_ms = 28, .track_seek_ms = 2.3, .rcache_num_seg = 4, .rcache_seg_size = 256, .max_multiple = 8 }, - { .name = "[ATA-2] Maxtor 7850AV", .internal_name = "7850AV", .model = "Maxtor 7850AV", .zones = 4, .avg_spt = 120, .heads = 4, .rpm = 3551, .full_stroke_ms = 31, .track_seek_ms = 3.7, .rcache_num_seg = 4, .rcache_seg_size = 64, .max_multiple = 8 }, - { .name = "[ATA-2] Maxtor 71336AP", .internal_name = "71336AP", .model = "Maxtor 71336AP", .zones = 4, .avg_spt = 105, .heads = 4, .rpm = 4480, .full_stroke_ms = 12, .track_seek_ms = 3.4, .rcache_num_seg = 8, .rcache_seg_size = 128, .max_multiple = 16 }, + { .name = "[ATA-1] Conner CFS420A", .internal_name = "CFS420A", .model = "Conner Peripherals 420MB - CFS420A", .zones = 1, .avg_spt = 40, .heads = 2, .rpm = 3600, .full_stroke_ms = 33, .track_seek_ms = 3, .rcache_num_seg = 4, .rcache_seg_size = 32, .max_multiple = 8 }, + { .name = "[ATA-1] HP Kittyhawk", .internal_name = "C3014A", .model = "HP C3014A", .zones = 6, .avg_spt = 80, .heads = 3, .rpm = 5400, .full_stroke_ms = 18, .track_seek_ms = 3, .rcache_num_seg = 4, .rcache_seg_size = 16, .max_multiple = 8 }, + { .name = "[ATA-1] IBM H3256-A3", .internal_name = "H3256A3", .model = "H3256-A3", .zones = 1, .avg_spt = 40, .heads = 2, .rpm = 3600, .full_stroke_ms = 32, .track_seek_ms = 4, .rcache_num_seg = 4, .rcache_seg_size = 96, .max_multiple = 8 }, + { .name = "[ATA-1] IBM H3342-A4", .internal_name = "H3342A4", .model = "H3342-A4", .zones = 1, .avg_spt = 40, .heads = 2, .rpm = 3600, .full_stroke_ms = 30, .track_seek_ms = 4, .rcache_num_seg = 4, .rcache_seg_size = 96, .max_multiple = 8 }, + { .name = "[ATA-1] Kalok KL343", .internal_name = "KL343", .model = "KALOK KL-343", .zones = 1, .avg_spt = 80, .heads = 6, .rpm = 3600, .full_stroke_ms = 50, .track_seek_ms = 2, .rcache_num_seg = 1, .rcache_seg_size = 8, .max_multiple = 8 }, + { .name = "[ATA-1] Kalok KL3100", .internal_name = "KL3100", .model = "KALOK KL-3100", .zones = 1, .avg_spt = 100, .heads = 6, .rpm = 3662, .full_stroke_ms = 50, .track_seek_ms = 2, .rcache_num_seg = 1, .rcache_seg_size = 32, .max_multiple = 8 }, + { .name = "[ATA-1] Maxtor 7060AT", .internal_name = "7060AT", .model = "Maxtor 7060 AT", .zones = 1, .avg_spt = 62, .heads = 2, .rpm = 3524, .full_stroke_ms = 30, .track_seek_ms = 3.6, .rcache_num_seg = 1, .rcache_seg_size = 64, .max_multiple = 8 }, + { .name = "[ATA-1] Maxtor 7131AT", .internal_name = "7131AT", .model = "Maxtor 7131 AT", .zones = 2, .avg_spt = 54, .heads = 2, .rpm = 3551, .full_stroke_ms = 27, .track_seek_ms = 4.5, .rcache_num_seg = 1, .rcache_seg_size = 64, .max_multiple = 8 }, + { .name = "[ATA-1] Maxtor 7213AT", .internal_name = "7213AT", .model = "Maxtor 7213 AT", .zones = 4, .avg_spt = 55, .heads = 4, .rpm = 3551, .full_stroke_ms = 28, .track_seek_ms = 6.5, .rcache_num_seg = 1, .rcache_seg_size = 64, .max_multiple = 8 }, + { .name = "[ATA-1] Maxtor 7245AT", .internal_name = "7245AT", .model = "Maxtor 7245 AT", .zones = 4, .avg_spt = 49, .heads = 4, .rpm = 3551, .full_stroke_ms = 27, .track_seek_ms = 4.4, .rcache_num_seg = 8, .rcache_seg_size = 64, .max_multiple = 8 }, + { .name = "[ATA-1] Quantum ProDrive LPS 105", .internal_name = "LPS105AT", .model = "QUANTUM PRODRIVE 105", .zones = 1, .avg_spt = 70, .heads = 2, .rpm = 3662, .full_stroke_ms = 45, .track_seek_ms = 5, .rcache_num_seg = 1, .rcache_seg_size = 64, .max_multiple = 8 }, + { .name = "[ATA-1] Quantum ProDrive LPS 120AT", .internal_name = "GM12A012", .model = "QUANTUM PRODRIVE 120AT", .zones = 1, .avg_spt = 50, .heads = 2, .rpm = 3605, .full_stroke_ms = 45, .track_seek_ms = 4, .rcache_num_seg = 1, .rcache_seg_size = 64, .max_multiple = 8 }, + { .name = "[ATA-1] Seagate ST3243A", .internal_name = "ST3243A", .model = "ST3243A", .zones = 1, .avg_spt = 40, .heads = 4, .rpm = 3811, .full_stroke_ms = 32, .track_seek_ms = 4, .rcache_num_seg = 4, .rcache_seg_size = 32, .max_multiple = 8 }, + { .name = "[ATA-1] Western Digital Caviar 140", .internal_name = "AC140", .model = "WDC AC140", .zones = 4, .avg_spt = 70, .heads = 2, .rpm = 3551, .full_stroke_ms = 28, .track_seek_ms = 6, .rcache_num_seg = 8, .rcache_seg_size = 8, .max_multiple = 8 }, + { .name = "[ATA-1] Western Digital Caviar 280", .internal_name = "AC280", .model = "WDC AC280", .zones = 4, .avg_spt = 70, .heads = 4, .rpm = 3595, .full_stroke_ms = 28, .track_seek_ms = 6, .rcache_num_seg = 8, .rcache_seg_size = 32, .max_multiple = 8 }, + { .name = "[ATA-1] Western Digital Caviar 1210", .internal_name = "AC1210", .model = "WDC AC1210F", .zones = 4, .avg_spt = 30, .heads = 2, .rpm = 3314, .full_stroke_ms = 33, .track_seek_ms = 4, .rcache_num_seg = 4, .rcache_seg_size = 128, .max_multiple = 8 }, + { .name = "[ATA-1] Western Digital Caviar 2120", .internal_name = "AC2120", .model = "WDC AC2120M", .zones = 4, .avg_spt = 40, .heads = 2, .rpm = 3605, .full_stroke_ms = 28, .track_seek_ms = 2.8, .rcache_num_seg = 8, .rcache_seg_size = 32, .max_multiple = 8 }, + { .name = "[ATA-2] IBM DBOA-2720", .internal_name = "DBOA2720", .model = "DBOA-2720", .zones = 2, .avg_spt = 135, .heads = 2, .rpm = 4000, .full_stroke_ms = 30, .track_seek_ms = 5, .rcache_num_seg = 4, .rcache_seg_size = 64, .max_multiple = 8 }, + { .name = "[ATA-2] IBM DeskStar 4 (DCAA-32880)", .internal_name = "DCAA32880", .model = "IBM-DCAA-32880", .zones = 8, .avg_spt = 185, .heads = 2, .rpm = 5400, .full_stroke_ms = 19, .track_seek_ms = 1.7, .rcache_num_seg = 4, .rcache_seg_size = 96, .max_multiple = 16 }, + { .name = "[ATA-2] IBM DeskStar 4 (DCAA-33610)", .internal_name = "DCAA33610", .model = "IBM-DCAA-33610", .zones = 8, .avg_spt = 185, .heads = 3, .rpm = 5400, .full_stroke_ms = 19, .track_seek_ms = 1.7, .rcache_num_seg = 4, .rcache_seg_size = 96, .max_multiple = 16 }, + { .name = "[ATA-2] IBM DeskStar 4 (DCAA-34330)", .internal_name = "DCAA34330", .model = "IBM-DCAA-34330", .zones = 8, .avg_spt = 185, .heads = 3, .rpm = 5400, .full_stroke_ms = 19, .track_seek_ms = 1.7, .rcache_num_seg = 4, .rcache_seg_size = 96, .max_multiple = 16 }, + { .name = "[ATA-2] Maxtor 7540AV", .internal_name = "7540AV", .model = "Maxtor 7540 AV", .zones = 2, .avg_spt = 120, .heads = 4, .rpm = 3551, .full_stroke_ms = 31, .track_seek_ms = 4.3, .rcache_num_seg = 4, .rcache_seg_size = 32, .max_multiple = 8 }, + { .name = "[ATA-2] Maxtor 7546AT", .internal_name = "7546AT", .model = "Maxtor 7546 AT", .zones = 2, .avg_spt = 100, .heads = 4, .rpm = 4500, .full_stroke_ms = 28, .track_seek_ms = 2.3, .rcache_num_seg = 4, .rcache_seg_size = 256, .max_multiple = 8 }, + { .name = "[ATA-2] Maxtor 7850AV", .internal_name = "7850AV", .model = "Maxtor 7850 AV", .zones = 4, .avg_spt = 120, .heads = 4, .rpm = 3551, .full_stroke_ms = 31, .track_seek_ms = 3.7, .rcache_num_seg = 4, .rcache_seg_size = 64, .max_multiple = 8 }, + { .name = "[ATA-2] Maxtor 71336AP", .internal_name = "71336AP", .model = "Maxtor 71336 AP", .zones = 4, .avg_spt = 105, .heads = 4, .rpm = 4480, .full_stroke_ms = 12, .track_seek_ms = 3.4, .rcache_num_seg = 8, .rcache_seg_size = 128, .max_multiple = 16 }, { .name = "[ATA-2] Quantum Bigfoot 1.2AT", .internal_name = "BF12A011", .model = "QUANTUM BIGFOOT BF1.2A", .zones = 2, .avg_spt = 155, .heads = 2, .rpm = 3600, .full_stroke_ms = 30, .track_seek_ms = 3.5, .rcache_num_seg = 4, .rcache_seg_size = 128, .max_multiple = 16 }, { .name = "[ATA-2] Quantum Bigfoot (CY4320A)", .internal_name = "CY4320A", .model = "QUANTUM BIGFOOT_CY4320A", .zones = 2, .avg_spt = 130, .heads = 2, .rpm = 4000, .full_stroke_ms = 29, .track_seek_ms = 2, .rcache_num_seg = 8, .rcache_seg_size = 128, .max_multiple = 16 }, // from Hardcore Windows NT Final Segment by Kugee { .name = "[ATA-2] Quantum Fireball 640AT", .internal_name = "FB64A341", .model = "QUANTUM FIREBALL 640AT", .zones = 2, .avg_spt = 120, .heads = 2, .rpm = 5400, .full_stroke_ms = 24, .track_seek_ms = 3.1, .rcache_num_seg = 4, .rcache_seg_size = 128, .max_multiple = 8 }, @@ -458,89 +458,89 @@ static hdd_preset_t hdd_speed_presets[] = { { .name = "[ATA-2] Seagate Medalist 545xe", .internal_name = "ST3660A", .model = "ST3660A", .zones = 4, .avg_spt = 130, .heads = 4, .rpm = 3811, .full_stroke_ms = 34, .track_seek_ms = 3.4, .rcache_num_seg = 8, .rcache_seg_size = 120, .max_multiple = 8 }, { .name = "[ATA-2] Seagate Medalist 640xe", .internal_name = "ST3630A", .model = "ST3630A", .zones = 4, .avg_spt = 130, .heads = 4, .rpm = 3811, .full_stroke_ms = 34, .track_seek_ms = 3.5, .rcache_num_seg = 8, .rcache_seg_size = 120, .max_multiple = 8 }, { .name = "[ATA-2] Seagate Medalist 850xe", .internal_name = "ST3850A", .model = "ST3850A", .zones = 8, .avg_spt = 150, .heads = 4, .rpm = 3811, .full_stroke_ms = 34, .track_seek_ms = 3.8, .rcache_num_seg = 8, .rcache_seg_size = 120, .max_multiple = 8 }, - { .name = "[ATA-2] Seagate Medalist 1270SL", .internal_name = "ST51270A", .model = "ST51270A", .zones = 8, .avg_spt = 105, .heads = 3, .rpm = 5736, .full_stroke_ms = 25, .track_seek_ms = 2, .rcache_num_seg = 8, .rcache_seg_size = 128, .max_multiple = 16 }, - { .name = "[ATA-2] Seagate Medalist 3240", .internal_name = "ST33240A", .model = "ST33240A", .zones = 16, .avg_spt = 125, .heads = 8, .rpm = 4500, .full_stroke_ms = 25, .track_seek_ms = 2.5, .rcache_num_seg = 8, .rcache_seg_size = 128, .max_multiple = 16 }, + { .name = "[ATA-2] Seagate Medalist 1270SL", .internal_name = "ST51270A", .model = "ST51270A", .zones = 8, .avg_spt = 205, .heads = 3, .rpm = 5736, .full_stroke_ms = 25, .track_seek_ms = 2, .rcache_num_seg = 8, .rcache_seg_size = 128, .max_multiple = 16 }, + { .name = "[ATA-2] Seagate Medalist 3240", .internal_name = "ST33240A", .model = "ST33240A", .zones = 16, .avg_spt = 225, .heads = 8, .rpm = 4500, .full_stroke_ms = 25, .track_seek_ms = 2.5, .rcache_num_seg = 8, .rcache_seg_size = 128, .max_multiple = 16 }, { .name = "[ATA-2] Toshiba MK2101MAN (HDD2616)", .internal_name = "HDD2616", .model = "TOSHIBA MK2101MAN", .zones = 8, .avg_spt = 130, .heads = 10, .rpm = 4200, .full_stroke_ms = 36, .track_seek_ms = 3, .rcache_num_seg = 4, .rcache_seg_size = 128, .max_multiple = 16 }, - { .name = "[ATA-2] Western Digital Caviar 2540", .internal_name = "AC2540", .model = "WDC AC2540H", .zones = 4, .avg_spt = 250, .heads = 2, .rpm = 4500, .full_stroke_ms = 12, .track_seek_ms = 4, .rcache_num_seg = 4, .rcache_seg_size = 128, .max_multiple = 8 }, - { .name = "[ATA-2] Western Digital Caviar 2850", .internal_name = "AC2850", .model = "WDC AC2850F", .zones = 4, .avg_spt = 230, .heads = 2, .rpm = 5200, .full_stroke_ms = 12, .track_seek_ms = 4, .rcache_num_seg = 8, .rcache_seg_size = 128, .max_multiple = 8 }, + { .name = "[ATA-2] Western Digital Caviar 2540", .internal_name = "AC2540", .model = "WDC AC2540H", .zones = 4, .avg_spt = 150, .heads = 2, .rpm = 4500, .full_stroke_ms = 12, .track_seek_ms = 4, .rcache_num_seg = 4, .rcache_seg_size = 128, .max_multiple = 8 }, + { .name = "[ATA-2] Western Digital Caviar 2850", .internal_name = "AC2850", .model = "WDC AC2850F", .zones = 4, .avg_spt = 130, .heads = 2, .rpm = 5200, .full_stroke_ms = 12, .track_seek_ms = 4, .rcache_num_seg = 8, .rcache_seg_size = 128, .max_multiple = 8 }, { .name = "[ATA-2] Western Digital Caviar 11000", .internal_name = "AC11000", .model = "WDC AC11000H", .zones = 4, .avg_spt = 120, .heads = 2, .rpm = 5200, .full_stroke_ms = 12, .track_seek_ms = 3, .rcache_num_seg = 8, .rcache_seg_size = 128, .max_multiple = 8 }, { .name = "[ATA-2] Western Digital Caviar 21200", .internal_name = "AC21200", .model = "WDC AC21200H", .zones = 4, .avg_spt = 110, .heads = 4, .rpm = 5200, .full_stroke_ms = 39, .track_seek_ms = 3, .rcache_num_seg = 4, .rcache_seg_size = 128, .max_multiple = 8 }, { .name = "[ATA-2] Western Digital Caviar 21600", .internal_name = "AC21600", .model = "WDC AC21600H", .zones = 8, .avg_spt = 140, .heads = 4, .rpm = 5200, .full_stroke_ms = 30, .track_seek_ms = 3, .rcache_num_seg = 4, .rcache_seg_size = 128, .max_multiple = 8 }, { .name = "[ATA-2] Western Digital Caviar 22000", .internal_name = "AC22000", .model = "WDC AC22000LA", .zones = 8, .avg_spt = 130, .heads = 3, .rpm = 5200, .full_stroke_ms = 33, .track_seek_ms = 3.5, .rcache_num_seg = 4, .rcache_seg_size = 128, .max_multiple = 8 }, { .name = "[ATA-2] Western Digital Caviar 22100", .internal_name = "AC22100", .model = "WDC AC22100H", .zones = 8, .avg_spt = 140, .heads = 4, .rpm = 5200, .full_stroke_ms = 30, .track_seek_ms = 3, .rcache_num_seg = 8, .rcache_seg_size = 128, .max_multiple = 16 }, - { .name = "[ATA-2] Western Digital Caviar 31200", .internal_name = "AC31200", .model = "WDC AC31200F", .zones = 8, .avg_spt = 110, .heads = 4, .rpm = 4500, .full_stroke_ms = 12, .track_seek_ms = 4, .rcache_num_seg = 8, .rcache_seg_size = 64, .max_multiple = 16 }, + { .name = "[ATA-2] Western Digital Caviar 31200", .internal_name = "AC31200", .model = "WDC AC31200F", .zones = 8, .avg_spt = 210, .heads = 4, .rpm = 4500, .full_stroke_ms = 12, .track_seek_ms = 4, .rcache_num_seg = 8, .rcache_seg_size = 64, .max_multiple = 16 }, { .name = "[ATA-3] Connor CFS1275A", .internal_name = "CFS1275A", .model = "Connor Peripherals 1275MB - CFS1275A", .zones = 4, .avg_spt = 130, .heads = 2, .rpm = 4500, .full_stroke_ms = 25, .track_seek_ms = 3.8, .rcache_num_seg = 4, .rcache_seg_size = 64, .max_multiple = 16 }, // Either ATA-2 or ATA-3 - { .name = "[ATA-3] Fujitsu MPA3017AT", .internal_name = "MPA3017AT", .model = "FUJITSU MPA3017AT", .zones = 5, .avg_spt = 95, .heads = 2, .rpm = 5400, .full_stroke_ms = 20, .track_seek_ms = 3.2, .rcache_num_seg = 8, .rcache_seg_size = 128, .max_multiple = 16 }, - { .name = "[ATA-3] Fujitsu MPA3026AT", .internal_name = "MPA3026AT", .model = "FUJITSU MPA3026AT", .zones = 8, .avg_spt = 95, .heads = 3, .rpm = 5400, .full_stroke_ms = 20, .track_seek_ms = 3.2, .rcache_num_seg = 8, .rcache_seg_size = 128, .max_multiple = 16 }, - { .name = "[ATA-3] Fujitsu MPA3035AT", .internal_name = "MPA3035AT", .model = "FUJITSU MPA3035AT", .zones = 11, .avg_spt = 95, .heads = 4, .rpm = 5400, .full_stroke_ms = 20, .track_seek_ms = 3.2, .rcache_num_seg = 8, .rcache_seg_size = 128, .max_multiple = 16 }, - { .name = "[ATA-3] Fujitsu MPA3043AT", .internal_name = "MPA3043AT", .model = "FUJITSU MPA3043AT", .zones = 15, .avg_spt = 95, .heads = 5, .rpm = 5400, .full_stroke_ms = 20, .track_seek_ms = 3.2, .rcache_num_seg = 8, .rcache_seg_size = 128, .max_multiple = 16 }, - { .name = "[ATA-3] Fujitsu MPA3052AT", .internal_name = "MPA3052AT", .model = "FUJITSU MPA3052AT", .zones = 16, .avg_spt = 95, .heads = 6, .rpm = 5400, .full_stroke_ms = 20, .track_seek_ms = 3.2, .rcache_num_seg = 8, .rcache_seg_size = 128, .max_multiple = 16 }, - { .name = "[ATA-3] Samsung Voyager 6", .internal_name = "SV0844A", .model = "SAMSUNG SV0844A", .zones = 8, .avg_spt = 105, .heads = 4, .rpm = 5400, .full_stroke_ms = 22, .track_seek_ms = 2, .rcache_num_seg = 16, .rcache_seg_size = 512, .max_multiple = 32 }, - { .name = "[ATA-3] Samsung Winner 5X", .internal_name = "WU33205A", .model = "SAMSUNG WU33205A", .zones = 16, .avg_spt = 100, .heads = 4, .rpm = 5400, .full_stroke_ms = 20, .track_seek_ms = 3, .rcache_num_seg = 8, .rcache_seg_size = 128, .max_multiple = 16 }, + { .name = "[ATA-3] Fujitsu MPA3017AT", .internal_name = "MPA3017AT", .model = "FUJITSU MPA3017AT", .zones = 5, .avg_spt = 195, .heads = 2, .rpm = 5400, .full_stroke_ms = 20, .track_seek_ms = 3.2, .rcache_num_seg = 8, .rcache_seg_size = 128, .max_multiple = 16 }, + { .name = "[ATA-3] Fujitsu MPA3026AT", .internal_name = "MPA3026AT", .model = "FUJITSU MPA3026AT", .zones = 8, .avg_spt = 195, .heads = 3, .rpm = 5400, .full_stroke_ms = 20, .track_seek_ms = 3.2, .rcache_num_seg = 8, .rcache_seg_size = 128, .max_multiple = 16 }, + { .name = "[ATA-3] Fujitsu MPA3035AT", .internal_name = "MPA3035AT", .model = "FUJITSU MPA3035AT", .zones = 11, .avg_spt = 195, .heads = 4, .rpm = 5400, .full_stroke_ms = 20, .track_seek_ms = 3.2, .rcache_num_seg = 8, .rcache_seg_size = 128, .max_multiple = 16 }, + { .name = "[ATA-3] Fujitsu MPA3043AT", .internal_name = "MPA3043AT", .model = "FUJITSU MPA3043AT", .zones = 15, .avg_spt = 195, .heads = 5, .rpm = 5400, .full_stroke_ms = 20, .track_seek_ms = 3.2, .rcache_num_seg = 8, .rcache_seg_size = 128, .max_multiple = 16 }, + { .name = "[ATA-3] Fujitsu MPA3052AT", .internal_name = "MPA3052AT", .model = "FUJITSU MPA3052AT", .zones = 16, .avg_spt = 195, .heads = 6, .rpm = 5400, .full_stroke_ms = 20, .track_seek_ms = 3.2, .rcache_num_seg = 8, .rcache_seg_size = 128, .max_multiple = 16 }, + { .name = "[ATA-3] Samsung Voyager 6", .internal_name = "SV0844A", .model = "SAMSUNG SV0844A", .zones = 8, .avg_spt = 205, .heads = 4, .rpm = 5400, .full_stroke_ms = 22, .track_seek_ms = 2, .rcache_num_seg = 16, .rcache_seg_size = 512, .max_multiple = 32 }, + { .name = "[ATA-3] Samsung Winner 5X", .internal_name = "WU33205A", .model = "SAMSUNG WU33205A", .zones = 16, .avg_spt = 200, .heads = 4, .rpm = 5400, .full_stroke_ms = 20, .track_seek_ms = 3, .rcache_num_seg = 8, .rcache_seg_size = 128, .max_multiple = 16 }, { .name = "[ATA-3] Seagate Medalist 636", .internal_name = "ST3636A", .model = "Seagate Technology 636MB - ST3636A", .zones = 2, .avg_spt = 130, .heads = 2, .rpm = 4500, .full_stroke_ms = 25, .track_seek_ms = 3.8, .rcache_num_seg = 4, .rcache_seg_size = 64, .max_multiple = 8 }, { .name = "[ATA-3] Seagate Medalist 1082", .internal_name = "ST31082A", .model = "Seagate Technology 1082MB - ST31082A", .zones = 4, .avg_spt = 130, .heads = 3, .rpm = 4500, .full_stroke_ms = 25, .track_seek_ms = 3.8, .rcache_num_seg = 4, .rcache_seg_size = 64, .max_multiple = 8 }, { .name = "[ATA-3] Seagate Medalist 1276", .internal_name = "ST31276A", .model = "Seagate Technology 1275MB - ST31276A", .zones = 4, .avg_spt = 130, .heads = 3, .rpm = 4500, .full_stroke_ms = 25, .track_seek_ms = 3.8, .rcache_num_seg = 4, .rcache_seg_size = 64, .max_multiple = 16 }, { .name = "[ATA-3] Seagate Medalist 1720", .internal_name = "ST31720A", .model = "ST31720A", .zones = 4, .avg_spt = 120, .heads = 4, .rpm = 4500, .full_stroke_ms = 25, .track_seek_ms = 2, .rcache_num_seg = 4, .rcache_seg_size = 128, .max_multiple = 16 }, { .name = "[ATA-3] Seagate Medalist 2132", .internal_name = "ST32132A", .model = "ST32132A", .zones = 8, .avg_spt = 125, .heads = 6, .rpm = 4500, .full_stroke_ms = 30, .track_seek_ms = 2.3, .rcache_num_seg = 8, .rcache_seg_size = 120, .max_multiple = 16 }, - { .name = "[ATA-3] Western Digital Caviar 21700", .internal_name = "AC21700", .model = "WDC AC21700H", .zones = 8, .avg_spt = 85, .heads = 3, .rpm = 5200, .full_stroke_ms = 21, .track_seek_ms = 3, .rcache_num_seg = 8, .rcache_seg_size = 128, .max_multiple = 16 }, // Apple Computer OEM only, not retail version - { .name = "[ATA-4] Fujitsu MPB3021AT", .internal_name = "MPB3021AT", .model = "FUJITSU MPB3021AT", .zones = 7, .avg_spt = 100, .heads = 3, .rpm = 5400, .full_stroke_ms = 20, .track_seek_ms = 2.5, .rcache_num_seg = 8, .rcache_seg_size = 256, .max_multiple = 16 }, - { .name = "[ATA-4] Fujitsu MPD3043AT", .internal_name = "MPD3043AT", .model = "FUJITSU MPD3043AT", .zones = 5, .avg_spt = 95, .heads = 2, .rpm = 5400, .full_stroke_ms = 29, .track_seek_ms = 1.5, .rcache_num_seg = 8, .rcache_seg_size = 512, .max_multiple = 16 }, - { .name = "[ATA-4] Fujitsu MPD3064AT", .internal_name = "MPD3064AT", .model = "FUJITSU MPD3064AT", .zones = 7, .avg_spt = 95, .heads = 3, .rpm = 5400, .full_stroke_ms = 30, .track_seek_ms = 1.5, .rcache_num_seg = 8, .rcache_seg_size = 512, .max_multiple = 16 }, - { .name = "[ATA-4] Fujitsu MPD3084AT", .internal_name = "MPD3084AT", .model = "FUJITSU MPD3084AT", .zones = 7, .avg_spt = 95, .heads = 4, .rpm = 5400, .full_stroke_ms = 19, .track_seek_ms = 1.5, .rcache_num_seg = 16, .rcache_seg_size = 512, .max_multiple = 16 }, - { .name = "[ATA-4] Fujitsu MPE3064AT", .internal_name = "MPE3064AT", .model = "FUJITSU MPE3064AT", .zones = 7, .avg_spt = 95, .heads = 2, .rpm = 5400, .full_stroke_ms = 30, .track_seek_ms = 1.5, .rcache_num_seg = 16, .rcache_seg_size = 512, .max_multiple = 32 }, - { .name = "[ATA-4] Maxtor DiamondMax 2160", .internal_name = "86480D6", .model = "Maxtor 86480D6", .zones = 8, .avg_spt = 97, .heads = 4, .rpm = 5200, .full_stroke_ms = 18, .track_seek_ms = 1, .rcache_num_seg = 8, .rcache_seg_size = 512, .max_multiple = 32 }, - { .name = "[ATA-4] Maxtor DiamondMax 2880", .internal_name = "90432D3", .model = "Maxtor 90432D3", .zones = 16, .avg_spt = 90, .heads = 3, .rpm = 5400, .full_stroke_ms = 18, .track_seek_ms = 1, .rcache_num_seg = 8, .rcache_seg_size = 256, .max_multiple = 32 }, - { .name = "[ATA-4] Maxtor DiamondMax 3400", .internal_name = "90644D3", .model = "Maxtor 90644D3", .zones = 16, .avg_spt = 90, .heads = 3, .rpm = 5400, .full_stroke_ms = 20, .track_seek_ms = 0.9, .rcache_num_seg = 8, .rcache_seg_size = 256, .max_multiple = 32 }, - { .name = "[ATA-4] Maxtor DiamondMax 4320 (90432D2)", .internal_name = "90432D2", .model = "Maxtor 90432D2", .zones = 16, .avg_spt = 90, .heads = 2, .rpm = 5400, .full_stroke_ms = 20, .track_seek_ms = 0.9, .rcache_num_seg = 16, .rcache_seg_size = 256, .max_multiple = 32 }, - { .name = "[ATA-4] Maxtor DiamondMax 4320 (90845D4)", .internal_name = "90845D4", .model = "Maxtor 90845D4", .zones = 16, .avg_spt = 90, .heads = 3, .rpm = 5400, .full_stroke_ms = 18, .track_seek_ms = 0.9, .rcache_num_seg = 16, .rcache_seg_size = 256, .max_multiple = 32 }, - { .name = "[ATA-4] Maxtor DiamondMax Plus 6800 (90683U2)", .internal_name = "90683U2", .model = "Maxtor 90683U2", .zones = 16, .avg_spt = 90, .heads = 2, .rpm = 7200, .full_stroke_ms = 20, .track_seek_ms = 1, .rcache_num_seg = 16, .rcache_seg_size = 256, .max_multiple = 32 }, - { .name = "[ATA-4] Maxtor DiamondMax Plus 6800 (91024U3)", .internal_name = "91024U3", .model = "Maxtor 91024U3", .zones = 16, .avg_spt = 90, .heads = 3, .rpm = 7200, .full_stroke_ms = 20, .track_seek_ms = 1, .rcache_num_seg = 16, .rcache_seg_size = 256, .max_multiple = 32 }, - { .name = "[ATA-4] Maxtor DiamondMax Plus 6800 (91366U4)", .internal_name = "91366U4", .model = "Maxtor 91366U4", .zones = 16, .avg_spt = 90, .heads = 4, .rpm = 7200, .full_stroke_ms = 20, .track_seek_ms = 1, .rcache_num_seg = 16, .rcache_seg_size = 256, .max_multiple = 32 }, - { .name = "[ATA-4] Maxtor DiamondMax Plus 6800 (92049U6)", .internal_name = "92049U6", .model = "Maxtor 92049U6", .zones = 16, .avg_spt = 90, .heads = 6, .rpm = 7200, .full_stroke_ms = 20, .track_seek_ms = 1, .rcache_num_seg = 16, .rcache_seg_size = 256, .max_multiple = 32 }, - { .name = "[ATA-4] Maxtor DiamondMax Plus 6800 (92732U8)", .internal_name = "92732U8", .model = "Maxtor 92732U8", .zones = 16, .avg_spt = 90, .heads = 8, .rpm = 7200, .full_stroke_ms = 20, .track_seek_ms = 1, .rcache_num_seg = 16, .rcache_seg_size = 256, .max_multiple = 32 }, - { .name = "[ATA-4] Quantum Bigfoot TX4.3AT", .internal_name = "TX043A011", .model = "QUANTUM BIGFOOT TX4.3A", .zones = 2, .avg_spt = 120, .heads = 2, .rpm = 4000, .full_stroke_ms = 30, .track_seek_ms = 2.5, .rcache_num_seg = 8, .rcache_seg_size = 128, .max_multiple = 32 }, - { .name = "[ATA-4] Quantum Fireball ST3.2AT", .internal_name = "ST32A461", .model = "QUANTUM FIREBALL ST3.2A", .zones = 4, .avg_spt = 100, .heads = 4, .rpm = 5400, .full_stroke_ms = 21, .track_seek_ms = 2, .rcache_num_seg = 8, .rcache_seg_size = 128, .max_multiple = 16 }, - { .name = "[ATA-4] Quantum Fireball SE4.3A", .internal_name = "SE43A011", .model = "QUANTUM FIREBALL SE4.3A", .zones = 2, .avg_spt = 100, .heads = 4, .rpm = 5400, .full_stroke_ms = 20, .track_seek_ms = 2, .rcache_num_seg = 8, .rcache_seg_size = 128, .max_multiple = 16 }, - { .name = "[ATA-4] Quantum Fireball SE6.4A", .internal_name = "SE64A011", .model = "QUANTUM FIREBALL SE6.4A", .zones = 3, .avg_spt = 100, .heads = 6, .rpm = 5400, .full_stroke_ms = 20, .track_seek_ms = 2, .rcache_num_seg = 8, .rcache_seg_size = 128, .max_multiple = 16 }, - { .name = "[ATA-4] Quantum Fireball SE8.4A", .internal_name = "SE84A011", .model = "QUANTUM FIREBALL SE8.4A", .zones = 4, .avg_spt = 100, .heads = 8, .rpm = 5400, .full_stroke_ms = 20, .track_seek_ms = 2, .rcache_num_seg = 8, .rcache_seg_size = 128, .max_multiple = 16 }, - { .name = "[ATA-4] Seagate Medalist 2122", .internal_name = "ST32122A", .model = "ST32122A", .zones = 16, .avg_spt = 115, .heads = 2, .rpm = 4500, .full_stroke_ms = 23, .track_seek_ms = 3.8, .rcache_num_seg = 16, .rcache_seg_size = 128, .max_multiple = 16 }, - { .name = "[ATA-4] Seagate Medalist 3321", .internal_name = "ST33221A", .model = "ST33221A", .zones = 16, .avg_spt = 110, .heads = 4, .rpm = 5400, .full_stroke_ms = 20, .track_seek_ms = 1.7, .rcache_num_seg = 16, .rcache_seg_size = 128, .max_multiple = 16 }, - { .name = "[ATA-4] Seagate Medalist 4321", .internal_name = "ST34321A", .model = "ST34321A", .zones = 16, .avg_spt = 110, .heads = 4, .rpm = 5400, .full_stroke_ms = 20, .track_seek_ms = 2.2, .rcache_num_seg = 16, .rcache_seg_size = 128, .max_multiple = 16 }, - { .name = "[ATA-4] Seagate Medalist 6531", .internal_name = "ST36531A", .model = "ST36531A", .zones = 16, .avg_spt = 115, .heads = 6, .rpm = 5400, .full_stroke_ms = 20, .track_seek_ms = 1.7, .rcache_num_seg = 16, .rcache_seg_size = 128, .max_multiple = 16 }, - { .name = "[ATA-4] Seagate Medalist 8420", .internal_name = "ST38420A", .model = "ST38420A", .zones = 16, .avg_spt = 90, .heads = 4, .rpm = 5400, .full_stroke_ms = 16, .track_seek_ms = 1.5, .rcache_num_seg = 16, .rcache_seg_size = 512, .max_multiple = 32 }, - { .name = "[ATA-4] Seagate Medalist 13030", .internal_name = "ST313030A", .model = "ST313030A", .zones = 16, .avg_spt = 90, .heads = 6, .rpm = 5400, .full_stroke_ms = 16, .track_seek_ms = 1.5, .rcache_num_seg = 16, .rcache_seg_size = 512, .max_multiple = 32 }, - { .name = "[ATA-4] Seagate Medalist 17240", .internal_name = "ST317240A", .model = "ST317240A", .zones = 16, .avg_spt = 90, .heads = 8, .rpm = 5400, .full_stroke_ms = 16, .track_seek_ms = 1.5, .rcache_num_seg = 16, .rcache_seg_size = 512, .max_multiple = 32 }, - { .name = "[ATA-4] Toshiba MK4006MAV", .internal_name = "MK4006MAV", .model = "TOSHIBA MK4006MAV", .zones = 8, .avg_spt = 130, .heads = 6, .rpm = 4200, .full_stroke_ms = 25, .track_seek_ms = 3, .rcache_num_seg = 8, .rcache_seg_size = 512, .max_multiple = 32 }, - { .name = "[ATA-4] Western Digital Caviar 14300", .internal_name = "AC14300", .model = "WDC AC14300RT", .zones = 16, .avg_spt = 95, .heads = 2, .rpm = 5400, .full_stroke_ms = 21, .track_seek_ms = 5.5, .rcache_num_seg = 8, .rcache_seg_size = 512, .max_multiple = 16 }, - { .name = "[ATA-4] Western Digital Caviar 23200", .internal_name = "AC23200", .model = "WDC AC23200LB", .zones = 16, .avg_spt = 110, .heads = 4, .rpm = 5400, .full_stroke_ms = 21, .track_seek_ms = 3, .rcache_num_seg = 8, .rcache_seg_size = 256, .max_multiple = 32 }, - { .name = "[ATA-4] Western Digital Caviar 26400", .internal_name = "AC26400", .model = "WDC AC26400RN", .zones = 16, .avg_spt = 95, .heads = 5, .rpm = 5400, .full_stroke_ms = 21, .track_seek_ms = 3, .rcache_num_seg = 8, .rcache_seg_size = 512, .max_multiple = 32 }, - { .name = "[ATA-4] Western Digital Caviar 33200", .internal_name = "AC33200", .model = "WDC AC33200LA", .zones = 16, .avg_spt = 110, .heads = 5, .rpm = 5200, .full_stroke_ms = 40, .track_seek_ms = 3, .rcache_num_seg = 16, .rcache_seg_size = 256, .max_multiple = 32 }, - { .name = "[ATA-5] IBM Travelstar 6GN", .internal_name = "DARA206000", .model = "IBM-DARA-206000", .zones = 12, .avg_spt = 92, .heads = 2, .rpm = 4200, .full_stroke_ms = 31, .track_seek_ms = 4, .rcache_num_seg = 16, .rcache_seg_size = 512, .max_multiple = 32 }, - { .name = "[ATA-5] IBM Travelstar 9GN", .internal_name = "DARA209000", .model = "IBM-DARA-209000", .zones = 12, .avg_spt = 92, .heads = 3, .rpm = 4200, .full_stroke_ms = 31, .track_seek_ms = 4, .rcache_num_seg = 16, .rcache_seg_size = 512, .max_multiple = 32 }, - { .name = "[ATA-5] IBM/Hitachi Travelstar 12GN", .internal_name = "DARA212000", .model = "IBM-DARA-212000", .zones = 12, .avg_spt = 92, .heads = 4, .rpm = 4200, .full_stroke_ms = 31, .track_seek_ms = 4, .rcache_num_seg = 16, .rcache_seg_size = 512, .max_multiple = 32 }, // Either Hitachi or IBM OEM - { .name = "[ATA-5] Maxtor DiamondMax VL 17", .internal_name = "90871U2", .model = "Maxtor 90871U2", .zones = 16, .avg_spt = 90, .heads = 3, .rpm = 5400, .full_stroke_ms = 20, .track_seek_ms = 0.9, .rcache_num_seg = 16, .rcache_seg_size = 256, .max_multiple = 32 }, - { .name = "[ATA-5] Maxtor DiamondMax VL 20 (91021U2)", .internal_name = "91021U2", .model = "Maxtor 91021U2", .zones = 16, .avg_spt = 95, .heads = 2, .rpm = 5400, .full_stroke_ms = 20, .track_seek_ms = 1, .rcache_num_seg = 16, .rcache_seg_size = 512, .max_multiple = 32 }, - { .name = "[ATA-5] Maxtor DiamondMax VL 20 (91531U3)", .internal_name = "91531U3", .model = "Maxtor 91531U3", .zones = 16, .avg_spt = 95, .heads = 3, .rpm = 5400, .full_stroke_ms = 20, .track_seek_ms = 1, .rcache_num_seg = 16, .rcache_seg_size = 512, .max_multiple = 32 }, - { .name = "[ATA-5] Maxtor DiamondMax VL 20 (92041U4)", .internal_name = "92041U4", .model = "Maxtor 92041U4", .zones = 16, .avg_spt = 95, .heads = 4, .rpm = 5400, .full_stroke_ms = 20, .track_seek_ms = 1, .rcache_num_seg = 16, .rcache_seg_size = 512, .max_multiple = 32 }, - { .name = "[ATA-5] Quantum Fireball EX3.2A", .internal_name = "EX32A012", .model = "QUANTUM FIREBALL EX3.2A", .zones = 1, .avg_spt = 110, .heads = 2, .rpm = 5400, .full_stroke_ms = 18, .track_seek_ms = 2, .rcache_num_seg = 8, .rcache_seg_size = 512, .max_multiple = 16 }, - { .name = "[ATA-5] Quantum Fireball EX5.1A", .internal_name = "EX51A012", .model = "QUANTUM FIREBALL EX5.1A", .zones = 2, .avg_spt = 110, .heads = 3, .rpm = 5400, .full_stroke_ms = 18, .track_seek_ms = 2, .rcache_num_seg = 8, .rcache_seg_size = 512, .max_multiple = 16 }, - { .name = "[ATA-5] Quantum Fireball EX6.4A", .internal_name = "EX64A012", .model = "QUANTUM FIREBALL EX6.4A", .zones = 2, .avg_spt = 110, .heads = 4, .rpm = 5400, .full_stroke_ms = 18, .track_seek_ms = 2, .rcache_num_seg = 8, .rcache_seg_size = 512, .max_multiple = 16 }, - { .name = "[ATA-5] Quantum Fireball EX10.2A", .internal_name = "EX10A011", .model = "QUANTUM FIREBALL EX10.2A", .zones = 3, .avg_spt = 110, .heads = 6, .rpm = 5400, .full_stroke_ms = 18, .track_seek_ms = 2, .rcache_num_seg = 8, .rcache_seg_size = 512, .max_multiple = 16 }, - { .name = "[ATA-5] Quantum Fireball EX12.7A", .internal_name = "EX12A011", .model = "QUANTUM FIREBALL EX12.7A", .zones = 4, .avg_spt = 110, .heads = 8, .rpm = 5400, .full_stroke_ms = 18, .track_seek_ms = 2, .rcache_num_seg = 8, .rcache_seg_size = 512, .max_multiple = 16 }, - { .name = "[ATA-5] Quantum Fireball CR4.3A", .internal_name = "CR43A013", .model = "QUANTUM FIREBALL CR4.3A", .zones = 2, .avg_spt = 110, .heads = 3, .rpm = 5400, .full_stroke_ms = 18, .track_seek_ms = 2, .rcache_num_seg = 8, .rcache_seg_size = 512, .max_multiple = 16 }, - { .name = "[ATA-5] Quantum Fireball CR6.4A", .internal_name = "CR64A011", .model = "QUANTUM FIREBALL CR6.4A", .zones = 2, .avg_spt = 110, .heads = 4, .rpm = 5400, .full_stroke_ms = 18, .track_seek_ms = 2, .rcache_num_seg = 8, .rcache_seg_size = 512, .max_multiple = 16 }, - { .name = "[ATA-5] Quantum Fireball CR8.4A", .internal_name = "CR84A011", .model = "QUANTUM FIREBALL CR8.4A", .zones = 3, .avg_spt = 110, .heads = 6, .rpm = 5400, .full_stroke_ms = 18, .track_seek_ms = 2, .rcache_num_seg = 8, .rcache_seg_size = 512, .max_multiple = 16 }, - { .name = "[ATA-5] Quantum Fireball CR13.0A", .internal_name = "CR13A011", .model = "QUANTUM FIREBALL CR13.0A", .zones = 4, .avg_spt = 110, .heads = 8, .rpm = 5400, .full_stroke_ms = 18, .track_seek_ms = 2, .rcache_num_seg = 8, .rcache_seg_size = 512, .max_multiple = 16 }, - { .name = "[ATA-5] Samsung SpinPoint V6800 (SV0682D)", .internal_name = "SV0682D", .model = "SAMSUNG SV0682D", .zones = 8, .avg_spt = 95, .heads = 2, .rpm = 5400, .full_stroke_ms = 18, .track_seek_ms = 1.3, .rcache_num_seg = 16, .rcache_seg_size = 512, .max_multiple = 32 }, - { .name = "[ATA-5] Samsung SpinPoint V6800 (SV1023D)", .internal_name = "SV1023D", .model = "SAMSUNG SV1023D", .zones = 8, .avg_spt = 95, .heads = 3, .rpm = 5400, .full_stroke_ms = 18, .track_seek_ms = 1.3, .rcache_num_seg = 16, .rcache_seg_size = 512, .max_multiple = 32 }, - { .name = "[ATA-5] Samsung SpinPoint V6800 (SV1364D)", .internal_name = "SV1364D", .model = "SAMSUNG SV1364D", .zones = 8, .avg_spt = 95, .heads = 4, .rpm = 5400, .full_stroke_ms = 18, .track_seek_ms = 1.3, .rcache_num_seg = 16, .rcache_seg_size = 512, .max_multiple = 32 }, - { .name = "[ATA-5] Samsung SpinPoint V6800 (SV1705D)", .internal_name = "SV1705D", .model = "SAMSUNG SV1705D", .zones = 8, .avg_spt = 95, .heads = 5, .rpm = 5400, .full_stroke_ms = 18, .track_seek_ms = 1.3, .rcache_num_seg = 16, .rcache_seg_size = 512, .max_multiple = 32 }, - { .name = "[ATA-5] Samsung SpinPoint V6800 (SV2046D)", .internal_name = "SV2046D", .model = "SAMSUNG SV2046D", .zones = 8, .avg_spt = 95, .heads = 6, .rpm = 5400, .full_stroke_ms = 18, .track_seek_ms = 1.3, .rcache_num_seg = 16, .rcache_seg_size = 512, .max_multiple = 32 }, - { .name = "[ATA-5] Seagate U8 - 4.3gb", .internal_name = "ST34313A", .model = "ST34313A", .zones = 16, .avg_spt = 89, .heads = 1, .rpm = 5400, .full_stroke_ms = 25, .track_seek_ms = 1.5, .rcache_num_seg = 16, .rcache_seg_size = 512, .max_multiple = 32 }, - { .name = "[ATA-5] Seagate U8 - 8.4gb", .internal_name = "ST38410A", .model = "ST38410A", .zones = 16, .avg_spt = 89, .heads = 2, .rpm = 5400, .full_stroke_ms = 25, .track_seek_ms = 1.5, .rcache_num_seg = 16, .rcache_seg_size = 512, .max_multiple = 32 }, - { .name = "[ATA-5] Seagate U8 - 13gb", .internal_name = "ST313021A", .model = "ST313021A", .zones = 16, .avg_spt = 89, .heads = 4, .rpm = 5400, .full_stroke_ms = 25, .track_seek_ms = 1.5, .rcache_num_seg = 16, .rcache_seg_size = 512, .max_multiple = 32 }, - { .name = "[ATA-5] Seagate U8 - 17.2gb", .internal_name = "ST317221A", .model = "ST317221A", .zones = 16, .avg_spt = 89, .heads = 3, .rpm = 5400, .full_stroke_ms = 25, .track_seek_ms = 1.5, .rcache_num_seg = 16, .rcache_seg_size = 512, .max_multiple = 32 }, - { .name = "[ATA-5] Western Digital Caviar 102AA", .internal_name = "WD102AA", .model = "WDC WD102AA-00ANA0", .zones = 16, .avg_spt = 95, .heads = 8, .rpm = 5400, .full_stroke_ms = 12, .track_seek_ms = 1.5, .rcache_num_seg = 16, .rcache_seg_size = 512, .max_multiple = 32 }, + { .name = "[ATA-3] Western Digital Caviar 21700", .internal_name = "AC21700", .model = "WDC AC21700H", .zones = 8, .avg_spt = 185, .heads = 3, .rpm = 5200, .full_stroke_ms = 21, .track_seek_ms = 3, .rcache_num_seg = 8, .rcache_seg_size = 128, .max_multiple = 16 }, // Apple Computer OEM only, not retail version + { .name = "[ATA-4] Fujitsu MPB3021AT", .internal_name = "MPB3021AT", .model = "FUJITSU MPB3021AT", .zones = 7, .avg_spt = 200, .heads = 3, .rpm = 5400, .full_stroke_ms = 20, .track_seek_ms = 2.5, .rcache_num_seg = 8, .rcache_seg_size = 256, .max_multiple = 16 }, + { .name = "[ATA-4] Fujitsu MPD3043AT", .internal_name = "MPD3043AT", .model = "FUJITSU MPD3043AT", .zones = 5, .avg_spt = 195, .heads = 2, .rpm = 5400, .full_stroke_ms = 29, .track_seek_ms = 1.5, .rcache_num_seg = 8, .rcache_seg_size = 512, .max_multiple = 16 }, + { .name = "[ATA-4] Fujitsu MPD3064AT", .internal_name = "MPD3064AT", .model = "FUJITSU MPD3064AT", .zones = 7, .avg_spt = 195, .heads = 3, .rpm = 5400, .full_stroke_ms = 30, .track_seek_ms = 1.5, .rcache_num_seg = 8, .rcache_seg_size = 512, .max_multiple = 16 }, + { .name = "[ATA-4] Fujitsu MPD3084AT", .internal_name = "MPD3084AT", .model = "FUJITSU MPD3084AT", .zones = 7, .avg_spt = 195, .heads = 4, .rpm = 5400, .full_stroke_ms = 19, .track_seek_ms = 1.5, .rcache_num_seg = 16, .rcache_seg_size = 512, .max_multiple = 16 }, + { .name = "[ATA-4] Fujitsu MPE3064AT", .internal_name = "MPE3064AT", .model = "FUJITSU MPE3064AT", .zones = 7, .avg_spt = 295, .heads = 2, .rpm = 5400, .full_stroke_ms = 30, .track_seek_ms = 1.5, .rcache_num_seg = 16, .rcache_seg_size = 512, .max_multiple = 32 }, + { .name = "[ATA-4] Maxtor DiamondMax 2160", .internal_name = "86480D6", .model = "Maxtor 86480D6", .zones = 8, .avg_spt = 197, .heads = 4, .rpm = 5200, .full_stroke_ms = 18, .track_seek_ms = 1, .rcache_num_seg = 8, .rcache_seg_size = 512, .max_multiple = 32 }, + { .name = "[ATA-4] Maxtor DiamondMax 2880", .internal_name = "90432D3", .model = "Maxtor 90432D3", .zones = 16, .avg_spt = 190, .heads = 3, .rpm = 5400, .full_stroke_ms = 18, .track_seek_ms = 1, .rcache_num_seg = 8, .rcache_seg_size = 256, .max_multiple = 32 }, + { .name = "[ATA-4] Maxtor DiamondMax 3400", .internal_name = "90644D3", .model = "Maxtor 90644D3", .zones = 16, .avg_spt = 290, .heads = 3, .rpm = 5400, .full_stroke_ms = 20, .track_seek_ms = 0.9, .rcache_num_seg = 8, .rcache_seg_size = 256, .max_multiple = 32 }, + { .name = "[ATA-4] Maxtor DiamondMax 4320 (90432D2)", .internal_name = "90432D2", .model = "Maxtor 90432D2", .zones = 16, .avg_spt = 290, .heads = 2, .rpm = 5400, .full_stroke_ms = 20, .track_seek_ms = 0.9, .rcache_num_seg = 16, .rcache_seg_size = 256, .max_multiple = 32 }, + { .name = "[ATA-4] Maxtor DiamondMax 4320 (90845D4)", .internal_name = "90845D4", .model = "Maxtor 90845D4", .zones = 16, .avg_spt = 290, .heads = 3, .rpm = 5400, .full_stroke_ms = 18, .track_seek_ms = 0.9, .rcache_num_seg = 16, .rcache_seg_size = 256, .max_multiple = 32 }, + { .name = "[ATA-4] Maxtor DiamondMax Plus 6800 (90683U2)", .internal_name = "90683U2", .model = "Maxtor 90683U2", .zones = 16, .avg_spt = 290, .heads = 2, .rpm = 7200, .full_stroke_ms = 20, .track_seek_ms = 1, .rcache_num_seg = 16, .rcache_seg_size = 256, .max_multiple = 32 }, + { .name = "[ATA-4] Maxtor DiamondMax Plus 6800 (91024U3)", .internal_name = "91024U3", .model = "Maxtor 91024U3", .zones = 16, .avg_spt = 290, .heads = 3, .rpm = 7200, .full_stroke_ms = 20, .track_seek_ms = 1, .rcache_num_seg = 16, .rcache_seg_size = 256, .max_multiple = 32 }, + { .name = "[ATA-4] Maxtor DiamondMax Plus 6800 (91366U4)", .internal_name = "91366U4", .model = "Maxtor 91366U4", .zones = 16, .avg_spt = 290, .heads = 4, .rpm = 7200, .full_stroke_ms = 20, .track_seek_ms = 1, .rcache_num_seg = 16, .rcache_seg_size = 256, .max_multiple = 32 }, + { .name = "[ATA-4] Maxtor DiamondMax Plus 6800 (92049U6)", .internal_name = "92049U6", .model = "Maxtor 92049U6", .zones = 16, .avg_spt = 290, .heads = 6, .rpm = 7200, .full_stroke_ms = 20, .track_seek_ms = 1, .rcache_num_seg = 16, .rcache_seg_size = 256, .max_multiple = 32 }, + { .name = "[ATA-4] Maxtor DiamondMax Plus 6800 (92732U8)", .internal_name = "92732U8", .model = "Maxtor 92732U8", .zones = 16, .avg_spt = 290, .heads = 8, .rpm = 7200, .full_stroke_ms = 20, .track_seek_ms = 1, .rcache_num_seg = 16, .rcache_seg_size = 256, .max_multiple = 32 }, + { .name = "[ATA-4] Quantum Bigfoot TX4.3AT", .internal_name = "TX043A011", .model = "QUANTUM BIGFOOT TX4.3A", .zones = 2, .avg_spt = 220, .heads = 2, .rpm = 4000, .full_stroke_ms = 30, .track_seek_ms = 2.5, .rcache_num_seg = 8, .rcache_seg_size = 128, .max_multiple = 32 }, + { .name = "[ATA-4] Quantum Fireball ST3.2AT", .internal_name = "ST32A461", .model = "QUANTUM FIREBALL ST3.2A", .zones = 4, .avg_spt = 200, .heads = 4, .rpm = 5400, .full_stroke_ms = 21, .track_seek_ms = 2, .rcache_num_seg = 8, .rcache_seg_size = 128, .max_multiple = 16 }, + { .name = "[ATA-4] Quantum Fireball SE4.3A", .internal_name = "SE43A011", .model = "QUANTUM FIREBALL SE4.3A", .zones = 2, .avg_spt = 200, .heads = 4, .rpm = 5400, .full_stroke_ms = 20, .track_seek_ms = 2, .rcache_num_seg = 8, .rcache_seg_size = 128, .max_multiple = 16 }, + { .name = "[ATA-4] Quantum Fireball SE6.4A", .internal_name = "SE64A011", .model = "QUANTUM FIREBALL SE6.4A", .zones = 3, .avg_spt = 200, .heads = 6, .rpm = 5400, .full_stroke_ms = 20, .track_seek_ms = 2, .rcache_num_seg = 8, .rcache_seg_size = 128, .max_multiple = 16 }, + { .name = "[ATA-4] Quantum Fireball SE8.4A", .internal_name = "SE84A011", .model = "QUANTUM FIREBALL SE8.4A", .zones = 4, .avg_spt = 200, .heads = 8, .rpm = 5400, .full_stroke_ms = 20, .track_seek_ms = 2, .rcache_num_seg = 8, .rcache_seg_size = 128, .max_multiple = 16 }, + { .name = "[ATA-4] Seagate Medalist 2122", .internal_name = "ST32122A", .model = "ST32122A", .zones = 16, .avg_spt = 215, .heads = 2, .rpm = 4500, .full_stroke_ms = 23, .track_seek_ms = 3.8, .rcache_num_seg = 16, .rcache_seg_size = 128, .max_multiple = 16 }, + { .name = "[ATA-4] Seagate Medalist 3321", .internal_name = "ST33221A", .model = "ST33221A", .zones = 16, .avg_spt = 210, .heads = 4, .rpm = 5400, .full_stroke_ms = 20, .track_seek_ms = 1.7, .rcache_num_seg = 16, .rcache_seg_size = 128, .max_multiple = 16 }, + { .name = "[ATA-4] Seagate Medalist 4321", .internal_name = "ST34321A", .model = "ST34321A", .zones = 16, .avg_spt = 210, .heads = 4, .rpm = 5400, .full_stroke_ms = 20, .track_seek_ms = 2.2, .rcache_num_seg = 16, .rcache_seg_size = 128, .max_multiple = 16 }, + { .name = "[ATA-4] Seagate Medalist 6531", .internal_name = "ST36531A", .model = "ST36531A", .zones = 16, .avg_spt = 215, .heads = 6, .rpm = 5400, .full_stroke_ms = 20, .track_seek_ms = 1.7, .rcache_num_seg = 16, .rcache_seg_size = 128, .max_multiple = 16 }, + { .name = "[ATA-4] Seagate Medalist 8420", .internal_name = "ST38420A", .model = "ST38420A", .zones = 16, .avg_spt = 290, .heads = 4, .rpm = 5400, .full_stroke_ms = 16, .track_seek_ms = 1.5, .rcache_num_seg = 16, .rcache_seg_size = 512, .max_multiple = 32 }, + { .name = "[ATA-4] Seagate Medalist 13030", .internal_name = "ST313030A", .model = "ST313030A", .zones = 16, .avg_spt = 290, .heads = 6, .rpm = 5400, .full_stroke_ms = 16, .track_seek_ms = 1.5, .rcache_num_seg = 16, .rcache_seg_size = 512, .max_multiple = 32 }, + { .name = "[ATA-4] Seagate Medalist 17240", .internal_name = "ST317240A", .model = "ST317240A", .zones = 16, .avg_spt = 290, .heads = 8, .rpm = 5400, .full_stroke_ms = 16, .track_seek_ms = 1.5, .rcache_num_seg = 16, .rcache_seg_size = 512, .max_multiple = 32 }, + { .name = "[ATA-4] Toshiba MK4006MAV", .internal_name = "MK4006MAV", .model = "TOSHIBA MK4006MAV", .zones = 8, .avg_spt = 230, .heads = 6, .rpm = 4200, .full_stroke_ms = 25, .track_seek_ms = 3, .rcache_num_seg = 8, .rcache_seg_size = 512, .max_multiple = 32 }, + { .name = "[ATA-4] Western Digital Caviar 14300", .internal_name = "AC14300", .model = "WDC AC14300RT", .zones = 16, .avg_spt = 195, .heads = 2, .rpm = 5400, .full_stroke_ms = 21, .track_seek_ms = 5.5, .rcache_num_seg = 8, .rcache_seg_size = 512, .max_multiple = 16 }, + { .name = "[ATA-4] Western Digital Caviar 23200", .internal_name = "AC23200", .model = "WDC AC23200LB", .zones = 16, .avg_spt = 210, .heads = 4, .rpm = 5400, .full_stroke_ms = 21, .track_seek_ms = 3, .rcache_num_seg = 8, .rcache_seg_size = 256, .max_multiple = 32 }, + { .name = "[ATA-4] Western Digital Caviar 26400", .internal_name = "AC26400", .model = "WDC AC26400RN", .zones = 16, .avg_spt = 295, .heads = 5, .rpm = 5400, .full_stroke_ms = 21, .track_seek_ms = 3, .rcache_num_seg = 8, .rcache_seg_size = 512, .max_multiple = 32 }, + { .name = "[ATA-4] Western Digital Caviar 33200", .internal_name = "AC33200", .model = "WDC AC33200LA", .zones = 16, .avg_spt = 310, .heads = 5, .rpm = 5200, .full_stroke_ms = 40, .track_seek_ms = 3, .rcache_num_seg = 16, .rcache_seg_size = 256, .max_multiple = 32 }, + { .name = "[ATA-5] IBM Travelstar 6GN", .internal_name = "DARA206000", .model = "IBM-DARA-206000", .zones = 12, .avg_spt = 292, .heads = 2, .rpm = 4200, .full_stroke_ms = 31, .track_seek_ms = 4, .rcache_num_seg = 16, .rcache_seg_size = 512, .max_multiple = 32 }, + { .name = "[ATA-5] IBM Travelstar 9GN", .internal_name = "DARA209000", .model = "IBM-DARA-209000", .zones = 12, .avg_spt = 292, .heads = 3, .rpm = 4200, .full_stroke_ms = 31, .track_seek_ms = 4, .rcache_num_seg = 16, .rcache_seg_size = 512, .max_multiple = 32 }, + { .name = "[ATA-5] IBM/Hitachi Travelstar 12GN", .internal_name = "DARA212000", .model = "IBM-DARA-212000", .zones = 12, .avg_spt = 292, .heads = 4, .rpm = 4200, .full_stroke_ms = 31, .track_seek_ms = 4, .rcache_num_seg = 16, .rcache_seg_size = 512, .max_multiple = 32 }, // Either Hitachi or IBM OEM + { .name = "[ATA-5] Maxtor DiamondMax VL 17", .internal_name = "90871U2", .model = "Maxtor 90871U2", .zones = 16, .avg_spt = 290, .heads = 3, .rpm = 5400, .full_stroke_ms = 20, .track_seek_ms = 0.9, .rcache_num_seg = 16, .rcache_seg_size = 256, .max_multiple = 32 }, + { .name = "[ATA-5] Maxtor DiamondMax VL 20 (91021U2)", .internal_name = "91021U2", .model = "Maxtor 91021U2", .zones = 16, .avg_spt = 295, .heads = 2, .rpm = 5400, .full_stroke_ms = 20, .track_seek_ms = 1, .rcache_num_seg = 16, .rcache_seg_size = 512, .max_multiple = 32 }, + { .name = "[ATA-5] Maxtor DiamondMax VL 20 (91531U3)", .internal_name = "91531U3", .model = "Maxtor 91531U3", .zones = 16, .avg_spt = 295, .heads = 3, .rpm = 5400, .full_stroke_ms = 20, .track_seek_ms = 1, .rcache_num_seg = 16, .rcache_seg_size = 512, .max_multiple = 32 }, + { .name = "[ATA-5] Maxtor DiamondMax VL 20 (92041U4)", .internal_name = "92041U4", .model = "Maxtor 92041U4", .zones = 16, .avg_spt = 295, .heads = 4, .rpm = 5400, .full_stroke_ms = 20, .track_seek_ms = 1, .rcache_num_seg = 16, .rcache_seg_size = 512, .max_multiple = 32 }, + { .name = "[ATA-5] Quantum Fireball EX3.2A", .internal_name = "EX32A012", .model = "QUANTUM FIREBALL EX3.2A", .zones = 1, .avg_spt = 210, .heads = 2, .rpm = 5400, .full_stroke_ms = 18, .track_seek_ms = 2, .rcache_num_seg = 8, .rcache_seg_size = 512, .max_multiple = 16 }, + { .name = "[ATA-5] Quantum Fireball EX5.1A", .internal_name = "EX51A012", .model = "QUANTUM FIREBALL EX5.1A", .zones = 2, .avg_spt = 210, .heads = 3, .rpm = 5400, .full_stroke_ms = 18, .track_seek_ms = 2, .rcache_num_seg = 8, .rcache_seg_size = 512, .max_multiple = 16 }, + { .name = "[ATA-5] Quantum Fireball EX6.4A", .internal_name = "EX64A012", .model = "QUANTUM FIREBALL EX6.4A", .zones = 2, .avg_spt = 210, .heads = 4, .rpm = 5400, .full_stroke_ms = 18, .track_seek_ms = 2, .rcache_num_seg = 8, .rcache_seg_size = 512, .max_multiple = 16 }, + { .name = "[ATA-5] Quantum Fireball EX10.2A", .internal_name = "EX10A011", .model = "QUANTUM FIREBALL EX10.2A", .zones = 3, .avg_spt = 210, .heads = 6, .rpm = 5400, .full_stroke_ms = 18, .track_seek_ms = 2, .rcache_num_seg = 8, .rcache_seg_size = 512, .max_multiple = 16 }, + { .name = "[ATA-5] Quantum Fireball EX12.7A", .internal_name = "EX12A011", .model = "QUANTUM FIREBALL EX12.7A", .zones = 4, .avg_spt = 210, .heads = 8, .rpm = 5400, .full_stroke_ms = 18, .track_seek_ms = 2, .rcache_num_seg = 8, .rcache_seg_size = 512, .max_multiple = 16 }, + { .name = "[ATA-5] Quantum Fireball CR4.3A", .internal_name = "CR43A013", .model = "QUANTUM FIREBALL CR4.3A", .zones = 2, .avg_spt = 310, .heads = 3, .rpm = 5400, .full_stroke_ms = 18, .track_seek_ms = 2, .rcache_num_seg = 8, .rcache_seg_size = 512, .max_multiple = 16 }, + { .name = "[ATA-5] Quantum Fireball CR6.4A", .internal_name = "CR64A011", .model = "QUANTUM FIREBALL CR6.4A", .zones = 2, .avg_spt = 310, .heads = 4, .rpm = 5400, .full_stroke_ms = 18, .track_seek_ms = 2, .rcache_num_seg = 8, .rcache_seg_size = 512, .max_multiple = 16 }, + { .name = "[ATA-5] Quantum Fireball CR8.4A", .internal_name = "CR84A011", .model = "QUANTUM FIREBALL CR8.4A", .zones = 3, .avg_spt = 310, .heads = 6, .rpm = 5400, .full_stroke_ms = 18, .track_seek_ms = 2, .rcache_num_seg = 8, .rcache_seg_size = 512, .max_multiple = 16 }, + { .name = "[ATA-5] Quantum Fireball CR13.0A", .internal_name = "CR13A011", .model = "QUANTUM FIREBALL CR13.0A", .zones = 4, .avg_spt = 310, .heads = 8, .rpm = 5400, .full_stroke_ms = 18, .track_seek_ms = 2, .rcache_num_seg = 8, .rcache_seg_size = 512, .max_multiple = 16 }, + { .name = "[ATA-5] Samsung SpinPoint V6800 (SV0682D)", .internal_name = "SV0682D", .model = "SAMSUNG SV0682D", .zones = 8, .avg_spt = 295, .heads = 2, .rpm = 5400, .full_stroke_ms = 18, .track_seek_ms = 1.3, .rcache_num_seg = 16, .rcache_seg_size = 512, .max_multiple = 32 }, + { .name = "[ATA-5] Samsung SpinPoint V6800 (SV1023D)", .internal_name = "SV1023D", .model = "SAMSUNG SV1023D", .zones = 8, .avg_spt = 295, .heads = 3, .rpm = 5400, .full_stroke_ms = 18, .track_seek_ms = 1.3, .rcache_num_seg = 16, .rcache_seg_size = 512, .max_multiple = 32 }, + { .name = "[ATA-5] Samsung SpinPoint V6800 (SV1364D)", .internal_name = "SV1364D", .model = "SAMSUNG SV1364D", .zones = 8, .avg_spt = 295, .heads = 4, .rpm = 5400, .full_stroke_ms = 18, .track_seek_ms = 1.3, .rcache_num_seg = 16, .rcache_seg_size = 512, .max_multiple = 32 }, + { .name = "[ATA-5] Samsung SpinPoint V6800 (SV1705D)", .internal_name = "SV1705D", .model = "SAMSUNG SV1705D", .zones = 8, .avg_spt = 295, .heads = 5, .rpm = 5400, .full_stroke_ms = 18, .track_seek_ms = 1.3, .rcache_num_seg = 16, .rcache_seg_size = 512, .max_multiple = 32 }, + { .name = "[ATA-5] Samsung SpinPoint V6800 (SV2046D)", .internal_name = "SV2046D", .model = "SAMSUNG SV2046D", .zones = 8, .avg_spt = 295, .heads = 6, .rpm = 5400, .full_stroke_ms = 18, .track_seek_ms = 1.3, .rcache_num_seg = 16, .rcache_seg_size = 512, .max_multiple = 32 }, + { .name = "[ATA-5] Seagate U8 - 4.3gb", .internal_name = "ST34313A", .model = "ST34313A", .zones = 16, .avg_spt = 289, .heads = 1, .rpm = 5400, .full_stroke_ms = 25, .track_seek_ms = 1.5, .rcache_num_seg = 16, .rcache_seg_size = 512, .max_multiple = 32 }, + { .name = "[ATA-5] Seagate U8 - 8.4gb", .internal_name = "ST38410A", .model = "ST38410A", .zones = 16, .avg_spt = 289, .heads = 2, .rpm = 5400, .full_stroke_ms = 25, .track_seek_ms = 1.5, .rcache_num_seg = 16, .rcache_seg_size = 512, .max_multiple = 32 }, + { .name = "[ATA-5] Seagate U8 - 13gb", .internal_name = "ST313021A", .model = "ST313021A", .zones = 16, .avg_spt = 289, .heads = 4, .rpm = 5400, .full_stroke_ms = 25, .track_seek_ms = 1.5, .rcache_num_seg = 16, .rcache_seg_size = 512, .max_multiple = 32 }, + { .name = "[ATA-5] Seagate U8 - 17.2gb", .internal_name = "ST317221A", .model = "ST317221A", .zones = 16, .avg_spt = 289, .heads = 3, .rpm = 5400, .full_stroke_ms = 25, .track_seek_ms = 1.5, .rcache_num_seg = 16, .rcache_seg_size = 512, .max_multiple = 32 }, + { .name = "[ATA-5] Western Digital Caviar 102AA", .internal_name = "WD102AA", .model = "WDC WD102AA-00ANA0", .zones = 16, .avg_spt = 295, .heads = 8, .rpm = 5400, .full_stroke_ms = 12, .track_seek_ms = 1.5, .rcache_num_seg = 16, .rcache_seg_size = 512, .max_multiple = 32 }, { .name = "[ATA-5] Western Digital Expert", .internal_name = "WD135BA", .model = "WDC WD135BA-60AK", .zones = 16, .avg_spt = 350, .heads = 6, .rpm = 7200, .full_stroke_ms = 15, .track_seek_ms = 2, .rcache_num_seg = 16, .rcache_seg_size = 1920, .max_multiple = 32 }, // clang-format on }; diff --git a/src/disk/lba_enhancer.c b/src/disk/lba_enhancer.c index 35c845c16..8e8bc480d 100644 --- a/src/disk/lba_enhancer.c +++ b/src/disk/lba_enhancer.c @@ -44,7 +44,7 @@ lba_enhancer_close(void* priv) } void * -lba_enhancer_init(const device_t *info) +lba_enhancer_init(UNUSED(const device_t *info)) { lba_enhancer_t *dev = (lba_enhancer_t *) calloc(1, sizeof(lba_enhancer_t)); @@ -92,7 +92,7 @@ const device_t lba_enhancer_device = { .init = lba_enhancer_init, .close = lba_enhancer_close, .reset = NULL, - { .available = lba_enhancer_available }, + .available = lba_enhancer_available, .speed_changed = NULL, .force_redraw = NULL, .config = lba_enhancer_config diff --git a/src/disk/mo.c b/src/disk/mo.c index 5f757c8af..5494fc9a8 100644 --- a/src/disk/mo.c +++ b/src/disk/mo.c @@ -9,35 +9,31 @@ * Implementation of a generic Magneto-Optical Disk drive * commands, for both ATAPI and SCSI usage. * - * - * * Authors: Natalia Portillo * Miran Grca, * Fred N. van Kempen, * - * Copyright 2020-2021 Natalia Portillo. - * Copyright 2020-2021 Miran Grca. - * Copyright 2020-2021 Fred N. van Kempen + * Copyright 2020-2025 Natalia Portillo. + * Copyright 2020-2025 Miran Grca. + * Copyright 2020-2025 Fred N. van Kempen */ -#include -#include -#include -#include +#ifdef ENABLE_MO_LOG #include -#include -#define HAVE_STDARG_H +#endif +#include +#include +#include +#include #include <86box/86box.h> #include <86box/timer.h> -#include <86box/config.h> -#include <86box/timer.h> #include <86box/device.h> +#include <86box/log.h> #include <86box/scsi.h> #include <86box/scsi_device.h> #include <86box/nvr.h> #include <86box/path.h> #include <86box/plat.h> #include <86box/ui.h> -#include <86box/hdc.h> #include <86box/hdc_ide.h> #include <86box/mo.h> #include <86box/version.h> @@ -53,235 +49,50 @@ mo_drive_t mo_drives[MO_NUM]; -/* Table of all SCSI commands and their flags, needed for the new disc change / not ready handler. */ +// clang-format off +/* + Table of all SCSI commands and their flags, needed for the new disc change / + not ready handler. + */ const uint8_t mo_command_flags[0x100] = { - IMPLEMENTED | CHECK_READY | NONDATA, /* 0x00 */ - IMPLEMENTED | ALLOW_UA | NONDATA | SCSI_ONLY, /* 0x01 */ - 0, - IMPLEMENTED | ALLOW_UA, /* 0x03 */ - IMPLEMENTED | CHECK_READY | ALLOW_UA | NONDATA | SCSI_ONLY, /* 0x04 */ - 0, 0, 0, - IMPLEMENTED | CHECK_READY, /* 0x08 */ - 0, - IMPLEMENTED | CHECK_READY, /* 0x0A */ - IMPLEMENTED | CHECK_READY | NONDATA, /* 0x0B */ - 0, 0, 0, 0, 0, 0, - IMPLEMENTED | ALLOW_UA, /* 0x12 */ - IMPLEMENTED | CHECK_READY | NONDATA | SCSI_ONLY, /* 0x13 */ - 0, - IMPLEMENTED, /* 0x15 */ - IMPLEMENTED | SCSI_ONLY, /* 0x16 */ - IMPLEMENTED | SCSI_ONLY, /* 0x17 */ - 0, 0, - IMPLEMENTED, /* 0x1A */ - IMPLEMENTED | CHECK_READY, /* 0x1B */ - 0, - IMPLEMENTED, /* 0x1D */ - IMPLEMENTED | CHECK_READY, /* 0x1E */ - 0, 0, 0, 0, 0, 0, - IMPLEMENTED | CHECK_READY, /* 0x25 */ - 0, 0, - IMPLEMENTED | CHECK_READY, /* 0x28 */ - 0, - IMPLEMENTED | CHECK_READY, /* 0x2A */ - IMPLEMENTED | CHECK_READY | NONDATA, /* 0x2B */ - IMPLEMENTED | CHECK_READY | NONDATA, /* 0x2C */ - 0, - IMPLEMENTED | CHECK_READY, /* 0x2E */ - IMPLEMENTED | CHECK_READY | NONDATA | SCSI_ONLY, /* 0x2F */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, - 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, - IMPLEMENTED, /* 0x55 */ - 0, 0, 0, 0, - IMPLEMENTED, /* 0x5A */ - 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - IMPLEMENTED | CHECK_READY, /* 0xA8 */ - 0, - IMPLEMENTED | CHECK_READY, /* 0xAA */ - 0, - IMPLEMENTED | CHECK_READY | NONDATA, /* 0xAC */ - 0, - IMPLEMENTED | CHECK_READY, /* 0xAE */ - IMPLEMENTED | CHECK_READY | NONDATA | SCSI_ONLY, /* 0xAF */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, - 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 + [0x00] = IMPLEMENTED | CHECK_READY, + [0x01] = IMPLEMENTED | ALLOW_UA | SCSI_ONLY, + [0x03] = IMPLEMENTED | ALLOW_UA, + [0x04] = IMPLEMENTED | CHECK_READY | ALLOW_UA | SCSI_ONLY, + [0x08] = IMPLEMENTED | CHECK_READY, + [0x0a] = IMPLEMENTED | CHECK_READY, + [0x0b] = IMPLEMENTED | CHECK_READY, + [0x12] = IMPLEMENTED | ALLOW_UA, + [0x13] = IMPLEMENTED | CHECK_READY | SCSI_ONLY, + [0x15] = IMPLEMENTED, + [0x16] = IMPLEMENTED | SCSI_ONLY, + [0x17] = IMPLEMENTED | SCSI_ONLY, + [0x1a] = IMPLEMENTED, + [0x1b] = IMPLEMENTED | CHECK_READY, + [0x1d] = IMPLEMENTED, + [0x1e] = IMPLEMENTED | CHECK_READY, + [0x25] = IMPLEMENTED | CHECK_READY, + [0x28] = IMPLEMENTED | CHECK_READY, + [0x2a ... 0x2c] = IMPLEMENTED | CHECK_READY, + [0x2e] = IMPLEMENTED | CHECK_READY, + [0x2f] = IMPLEMENTED | CHECK_READY | SCSI_ONLY, + [0x41] = IMPLEMENTED | CHECK_READY, + [0x55] = IMPLEMENTED, + [0x5a] = IMPLEMENTED, + [0xa8] = IMPLEMENTED | CHECK_READY, + [0xaa] = IMPLEMENTED | CHECK_READY, + [0xac] = IMPLEMENTED | CHECK_READY, + [0xae] = IMPLEMENTED | CHECK_READY, + [0xaf] = IMPLEMENTED | CHECK_READY | SCSI_ONLY }; static uint64_t mo_mode_sense_page_flags = GPMODEP_ALL_PAGES; -static const mode_sense_pages_t mo_mode_sense_pages_default = - // clang-format off -{ { - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 } -} }; -// clang-format on +static const mode_sense_pages_t mo_mode_sense_pages_default = { 0 }; -static const mode_sense_pages_t mo_mode_sense_pages_default_scsi = - // clang-format off -{ { - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 } -} }; -// clang-format on +static const mode_sense_pages_t mo_mode_sense_pages_default_scsi = { 0 }; -static const mode_sense_pages_t mo_mode_sense_pages_changeable = - // clang-format off -{ { - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 } -} }; +static const mode_sense_pages_t mo_mode_sense_pages_changeable = { 0 }; // clang-format on static void mo_command_complete(mo_t *dev); @@ -291,32 +102,22 @@ static void mo_init(mo_t *dev); int mo_do_log = ENABLE_MO_LOG; static void -mo_log(const char *fmt, ...) +mo_log(void *priv, const char *fmt, ...) { va_list ap; if (mo_do_log) { va_start(ap, fmt); - pclog_ex(fmt, ap); + log_out(priv, fmt, ap); va_end(ap); } } #else -# define mo_log(fmt, ...) +# define mo_log(priv, fmt, ...) #endif -int -find_mo_for_channel(uint8_t channel) -{ - for (uint8_t i = 0; i < MO_NUM; i++) { - if ((mo_drives[i].bus_type == MO_BUS_ATAPI) && (mo_drives[i].ide_channel == channel)) - return i; - } - return 0xff; -} - static int -mo_load_abort(mo_t *dev) +mo_load_abort(const mo_t *dev) { if (dev->drv->fp) fclose(dev->drv->fp); @@ -330,105 +131,125 @@ mo_load_abort(mo_t *dev) int image_is_mdi(const char *s) { - if (!strcasecmp(path_get_extension((char *) s), "MDI")) - return 1; - else - return 0; + return !strcasecmp(path_get_extension((char *) s), "MDI"); } int -mo_load(mo_t *dev, char *fn) +mo_is_empty(const uint8_t id) { - int is_mdi; - uint32_t size = 0; - unsigned int found = 0; + const mo_t *dev = (const mo_t *) mo_drives[id].priv; + int ret = 0; - if (!dev->drv) { + if ((dev->drv == NULL) || (dev->drv->fp == NULL)) + ret = 1; + + return ret; +} + +void +mo_load(const mo_t *dev, const char *fn, const int skip_insert) +{ + const int was_empty = mo_is_empty(dev->id); + int ret = 0; + + if (dev->drv == NULL) mo_eject(dev->id); - return 0; - } + else { + const int is_mdi = image_is_mdi(fn); - is_mdi = image_is_mdi(fn); + dev->drv->fp = plat_fopen(fn, dev->drv->read_only ? "rb" : "rb+"); + ret = 1; - dev->drv->fp = plat_fopen(fn, dev->drv->read_only ? "rb" : "rb+"); - if (!dev->drv->fp) { - if (!dev->drv->read_only) { - dev->drv->fp = plat_fopen(fn, "rb"); - if (dev->drv->fp) - dev->drv->read_only = 1; - else - return mo_load_abort(dev); - } else - return mo_load_abort(dev); - } + if (dev->drv->fp == NULL) { + if (!dev->drv->read_only) { + dev->drv->fp = plat_fopen(fn, "rb"); + if (dev->drv->fp == NULL) + ret = mo_load_abort(dev); + else + dev->drv->read_only = 1; + } else + ret = mo_load_abort(dev); + } - fseek(dev->drv->fp, 0, SEEK_END); - size = (uint32_t) ftell(dev->drv->fp); + if (ret) { + fseek(dev->drv->fp, 0, SEEK_END); - if (is_mdi) { - /* This is a MDI image. */ - size -= 0x1000LL; - dev->drv->base = 0x1000; - } + uint32_t size = (uint32_t) ftell(dev->drv->fp); + unsigned int found = 0; - for (uint8_t i = 0; i < KNOWN_MO_TYPES; i++) { - if (size == (mo_types[i].sectors * mo_types[i].bytes_per_sector)) { - found = 1; - dev->drv->medium_size = mo_types[i].sectors; - dev->drv->sector_size = mo_types[i].bytes_per_sector; - break; + if (is_mdi) { + /* This is a MDI image. */ + size -= 0x1000LL; + dev->drv->base = 0x1000; + } else + dev->drv->base = 0; + + for (uint8_t i = 0; i < KNOWN_MO_TYPES; i++) { + if (size == (mo_types[i].sectors * mo_types[i].bytes_per_sector)) { + found = 1; + dev->drv->medium_size = mo_types[i].sectors; + dev->drv->sector_size = mo_types[i].bytes_per_sector; + break; + } + } + + if (found) { + if (fseek(dev->drv->fp, dev->drv->base, SEEK_SET) == -1) + log_fatal(dev->log, "mo_load(): Error seeking to the beginning of " + "the file\n"); + + strncpy(dev->drv->image_path, fn, sizeof(dev->drv->image_path) - 1); + + ret = 1; + } else + ret = mo_load_abort(dev); } } - if (!found) - return mo_load_abort(dev); + if (ret && !skip_insert) { + /* Signal media change to the emulated machine. */ + mo_insert((mo_t *) dev); - if (fseek(dev->drv->fp, dev->drv->base, SEEK_SET) == -1) - fatal("mo_load(): Error seeking to the beginning of the file\n"); - - strncpy(dev->drv->image_path, fn, sizeof(dev->drv->image_path) - 1); - - return 1; + /* The drive was previously empty, transition directly to UNIT ATTENTION. */ + if (was_empty) + mo_insert((mo_t *) dev); + } } void -mo_disk_reload(mo_t *dev) +mo_disk_reload(const mo_t *dev) { - int ret = 0; - - if (strlen(dev->drv->prev_image_path) == 0) - return; - else - ret = mo_load(dev, dev->drv->prev_image_path); - - if (ret) - dev->unit_attention = 1; + if (strlen(dev->drv->prev_image_path) != 0) + (void) mo_load(dev, dev->drv->prev_image_path, 0); } -void -mo_disk_unload(mo_t *dev) +static void +mo_disk_unload(const mo_t *dev) { - if (dev->drv && dev->drv->fp) { + if ((dev->drv != NULL) && (dev->drv->fp != NULL)) { fclose(dev->drv->fp); dev->drv->fp = NULL; } } void -mo_disk_close(mo_t *dev) +mo_disk_close(const mo_t *dev) { - if (dev->drv && dev->drv->fp) { + if ((dev->drv != NULL) && (dev->drv->fp != NULL)) { mo_disk_unload(dev); - memcpy(dev->drv->prev_image_path, dev->drv->image_path, sizeof(dev->drv->prev_image_path)); + memcpy(dev->drv->prev_image_path, dev->drv->image_path, + sizeof(dev->drv->prev_image_path)); memset(dev->drv->image_path, 0, sizeof(dev->drv->image_path)); dev->drv->medium_size = 0; + + mo_insert((mo_t *) dev); } } static void -mo_set_callback(mo_t *dev) +mo_set_callback(const mo_t *dev) { if (dev->drv->bus_type != MO_BUS_SCSI) ide_set_callback(ide_drives[dev->drv->ide_channel], dev->callback); @@ -437,55 +258,55 @@ mo_set_callback(mo_t *dev) static void mo_init(mo_t *dev) { - if (dev->id >= MO_NUM) - return; - - dev->requested_blocks = 1; - dev->sense[0] = 0xf0; - dev->sense[7] = 10; - dev->drv->bus_mode = 0; - if (dev->drv->bus_type >= MO_BUS_ATAPI) - dev->drv->bus_mode |= 2; - if (dev->drv->bus_type < MO_BUS_SCSI) - dev->drv->bus_mode |= 1; - mo_log("MO %i: Bus type %i, bus mode %i\n", dev->id, dev->drv->bus_type, dev->drv->bus_mode); - if (dev->drv->bus_type < MO_BUS_SCSI) { - dev->tf->phase = 1; - dev->tf->request_length = 0xEB14; + if (dev->id < MO_NUM) { + dev->requested_blocks = 1; + dev->sense[0] = 0xf0; + dev->sense[7] = 10; + dev->drv->bus_mode = 0; + if (dev->drv->bus_type >= MO_BUS_ATAPI) + dev->drv->bus_mode |= 2; + if (dev->drv->bus_type < MO_BUS_SCSI) + dev->drv->bus_mode |= 1; + mo_log(dev->log, "Bus type %i, bus mode %i\n", dev->drv->bus_type, dev->drv->bus_mode); + if (dev->drv->bus_type < MO_BUS_SCSI) { + dev->tf->phase = 1; + dev->tf->request_length = 0xEB14; + } + dev->tf->status = READY_STAT | DSC_STAT; + dev->tf->pos = 0; + dev->packet_status = PHASE_NONE; + mo_sense_key = mo_asc = mo_ascq = dev->unit_attention = dev->transition = 0; + mo_info = 0x00000000; } - dev->tf->status = READY_STAT | DSC_STAT; - dev->tf->pos = 0; - dev->packet_status = PHASE_NONE; - mo_sense_key = mo_asc = mo_ascq = dev->unit_attention = 0; } static int -mo_supports_pio(mo_t *dev) +mo_supports_pio(const mo_t *dev) { return (dev->drv->bus_mode & 1); } static int -mo_supports_dma(mo_t *dev) +mo_supports_dma(const mo_t *dev) { return (dev->drv->bus_mode & 2); } /* Returns: 0 for none, 1 for PIO, 2 for DMA. */ static int -mo_current_mode(mo_t *dev) +mo_current_mode(const mo_t *dev) { if (!mo_supports_pio(dev) && !mo_supports_dma(dev)) return 0; if (mo_supports_pio(dev) && !mo_supports_dma(dev)) { - mo_log("MO %i: Drive does not support DMA, setting to PIO\n", dev->id); + mo_log(dev->log, "Drive does not support DMA, setting to PIO\n"); return 1; } if (!mo_supports_pio(dev) && mo_supports_dma(dev)) return 2; if (mo_supports_pio(dev) && mo_supports_dma(dev)) { - mo_log("MO %i: Drive supports both, setting to %s\n", dev->id, - (dev->tf->features & 1) ? "DMA" : "PIO"); + mo_log(dev->log, "Drive supports both, setting to %s\n", (dev->tf->features & 1) ? + "DMA" : "PIO"); return (dev->tf->features & 1) ? 2 : 1; } @@ -495,21 +316,21 @@ mo_current_mode(mo_t *dev) static void mo_mode_sense_load(mo_t *dev) { - FILE *fp; - char fn[512]; + char fn[512] = { 0 }; memset(&dev->ms_pages_saved, 0, sizeof(mode_sense_pages_t)); if (mo_drives[dev->id].bus_type == MO_BUS_SCSI) - memcpy(&dev->ms_pages_saved, &mo_mode_sense_pages_default_scsi, sizeof(mode_sense_pages_t)); + memcpy(&dev->ms_pages_saved, &mo_mode_sense_pages_default_scsi, + sizeof(mode_sense_pages_t)); else - memcpy(&dev->ms_pages_saved, &mo_mode_sense_pages_default, sizeof(mode_sense_pages_t)); + memcpy(&dev->ms_pages_saved, &mo_mode_sense_pages_default, + sizeof(mode_sense_pages_t)); - memset(fn, 0, 512); if (dev->drv->bus_type == MO_BUS_SCSI) sprintf(fn, "scsi_mo_%02i_mode_sense_bin", dev->id); else sprintf(fn, "mo_%02i_mode_sense_bin", dev->id); - fp = plat_fopen(nvr_path(fn), "rb"); + FILE *fp = plat_fopen(nvr_path(fn), "rb"); if (fp) { /* Nothing to read, not used by MO. */ fclose(fp); @@ -517,28 +338,27 @@ mo_mode_sense_load(mo_t *dev) } static void -mo_mode_sense_save(mo_t *dev) +mo_mode_sense_save(const mo_t *dev) { - FILE *fp; - char fn[512]; + char fn[512] = { 0 }; - memset(fn, 0, 512); if (dev->drv->bus_type == MO_BUS_SCSI) sprintf(fn, "scsi_mo_%02i_mode_sense_bin", dev->id); else sprintf(fn, "mo_%02i_mode_sense_bin", dev->id); - fp = plat_fopen(nvr_path(fn), "wb"); + FILE *fp = plat_fopen(nvr_path(fn), "wb"); if (fp) { /* Nothing to write, not used by MO. */ fclose(fp); } } -/*SCSI Mode Sense 6/10*/ +/* SCSI Mode Sense 6/10. */ static uint8_t -mo_mode_sense_read(mo_t *dev, uint8_t page_control, uint8_t page, uint8_t pos) +mo_mode_sense_read(const mo_t *dev, const uint8_t pgctl, + const uint8_t page, const uint8_t pos) { - switch (page_control) { + switch (pgctl) { case 0: case 3: return dev->ms_pages_saved.pages[page][pos]; @@ -558,14 +378,11 @@ mo_mode_sense_read(mo_t *dev, uint8_t page_control, uint8_t page, uint8_t pos) } static uint32_t -mo_mode_sense(mo_t *dev, uint8_t *buf, uint32_t pos, uint8_t page, uint8_t block_descriptor_len) +mo_mode_sense(const mo_t *dev, uint8_t *buf, uint32_t pos, + uint8_t page, const uint8_t block_descriptor_len) { - uint64_t pf; - uint8_t page_control = (page >> 6) & 3; - - pf = mo_mode_sense_page_flags; - - uint8_t msplen; + const uint64_t pf = mo_mode_sense_page_flags; + const uint8_t pgctl = (page >> 6) & 3; page &= 0x3f; @@ -583,12 +400,12 @@ mo_mode_sense(mo_t *dev, uint8_t *buf, uint32_t pos, uint8_t page, uint8_t block for (uint8_t i = 0; i < 0x40; i++) { if ((page == GPMODE_ALL_PAGES) || (page == i)) { if (pf & (1LL << ((uint64_t) page))) { - buf[pos++] = mo_mode_sense_read(dev, page_control, i, 0); - msplen = mo_mode_sense_read(dev, page_control, i, 1); - buf[pos++] = msplen; - mo_log("MO %i: MODE SENSE: Page [%02X] length %i\n", dev->id, i, msplen); + const uint8_t msplen = mo_mode_sense_read(dev, pgctl, i, 1); + buf[pos++] = mo_mode_sense_read(dev, pgctl, i, 0); + buf[pos++] = msplen; + mo_log(dev->log, "MODE SENSE: Page [%02X] length %i\n", i, msplen); for (uint8_t j = 0; j < msplen; j++) - buf[pos++] = mo_mode_sense_read(dev, page_control, i, 2 + j); + buf[pos++] = mo_mode_sense_read(dev, pgctl, i, 2 + j); } } } @@ -604,7 +421,10 @@ mo_update_request_length(mo_t *dev, int len, int block_len) dev->max_transfer_len = dev->tf->request_length; - /* For media access commands, make sure the requested DRQ length matches the block length. */ + /* + For media access commands, make sure the requested DRQ length + matches the block length. + */ switch (dev->current_cdb[0]) { case 0x08: case 0x0a: @@ -615,8 +435,10 @@ mo_update_request_length(mo_t *dev, int len, int block_len) /* Round it to the nearest 2048 bytes. */ dev->max_transfer_len = (dev->max_transfer_len >> 9) << 9; - /* Make sure total length is not bigger than sum of the lengths of - all the requested blocks. */ + /* + Make sure total length is not bigger than sum of the lengths of + all the requested blocks. + */ bt = (dev->requested_blocks * block_len); if (len > bt) len = bt; @@ -641,7 +463,10 @@ mo_update_request_length(mo_t *dev, int len, int block_len) /* If the DRQ length is odd, and the total remaining length is bigger, make sure it's even. */ if ((dev->max_transfer_len & 1) && (dev->max_transfer_len < len)) dev->max_transfer_len &= 0xfffe; - /* If the DRQ length is smaller or equal in size to the total remaining length, set it to that. */ + /* + If the DRQ length is smaller or equal in size to the total remaining length, + set it to that. + */ if (!dev->max_transfer_len) dev->max_transfer_len = 65534; @@ -649,8 +474,6 @@ mo_update_request_length(mo_t *dev, int len, int block_len) dev->tf->request_length = dev->max_transfer_len = len; else if (len > dev->max_transfer_len) dev->tf->request_length = dev->max_transfer_len; - - return; } static double @@ -676,23 +499,22 @@ mo_bus_speed(mo_t *dev) static void mo_command_common(mo_t *dev) { - double bytes_per_second; - double period; - dev->tf->status = BUSY_STAT; dev->tf->phase = 1; dev->tf->pos = 0; if (dev->packet_status == PHASE_COMPLETE) dev->callback = 0.0; else { + double bytes_per_second; + if (dev->drv->bus_type == MO_BUS_SCSI) { dev->callback = -1.0; /* Speed depends on SCSI controller */ return; } else bytes_per_second = mo_bus_speed(dev); - period = 1000000.0 / bytes_per_second; - dev->callback = period * (double) (dev->packet_len); + const double period = 1000000.0 / bytes_per_second; + dev->callback = period * (double) (dev->packet_len); } mo_set_callback(dev); @@ -733,16 +555,20 @@ mo_command_write_dma(mo_t *dev) mo_command_common(dev); } -/* id = Current MO device ID; +/* + dev = Pointer to current MO device; len = Total transfer length; block_len = Length of a single block (why does it matter?!); alloc_len = Allocated transfer length; - direction = Transfer direction (0 = read from host, 1 = write to host). */ + direction = Transfer direction (0 = read from host, 1 = write to host). + */ static void -mo_data_command_finish(mo_t *dev, int len, int block_len, int alloc_len, int direction) +mo_data_command_finish(mo_t *dev, int len, const int block_len, + const int alloc_len, const int direction) { - mo_log("MO %i: Finishing command (%02X): %i, %i, %i, %i, %i\n", - dev->id, dev->current_cdb[0], len, block_len, alloc_len, direction, dev->tf->request_length); + mo_log(dev->log, "Finishing command (%02X): %i, %i, %i, %i, %i\n", + dev->current_cdb[0], len, block_len, alloc_len, + direction, dev->tf->request_length); dev->tf->pos = 0; if (alloc_len >= 0) { if (alloc_len < len) @@ -771,27 +597,26 @@ mo_data_command_finish(mo_t *dev, int len, int block_len, int alloc_len, int dir } } - mo_log("MO %i: Status: %i, cylinder %i, packet length: %i, position: %i, phase: %i\n", - dev->id, dev->packet_status, dev->tf->request_length, dev->packet_len, dev->tf->pos, - dev->tf->phase); + mo_log(dev->log, "Status: %i, cylinder %i, packet length: %i, position: %i, phase: %i\n", + dev->packet_status, dev->tf->request_length, dev->packet_len, + dev->tf->pos, dev->tf->phase); } static void mo_sense_clear(mo_t *dev, UNUSED(int command)) { mo_sense_key = mo_asc = mo_ascq = 0; + mo_info = 0x00000000; } static void -mo_set_phase(mo_t *dev, uint8_t phase) +mo_set_phase(const mo_t *dev, const uint8_t phase) { - uint8_t scsi_bus = (dev->drv->scsi_device_id >> 4) & 0x0f; - uint8_t scsi_id = dev->drv->scsi_device_id & 0x0f; + const uint8_t scsi_bus = (dev->drv->scsi_device_id >> 4) & 0x0f; + const uint8_t scsi_id = dev->drv->scsi_device_id & 0x0f; - if (dev->drv->bus_type != MO_BUS_SCSI) - return; - - scsi_devices[scsi_bus][scsi_id].phase = phase; + if (dev->drv->bus_type == MO_BUS_SCSI) + scsi_devices[scsi_bus][scsi_id].phase = phase; } static void @@ -799,8 +624,6 @@ mo_cmd_error(mo_t *dev) { mo_set_phase(dev, SCSI_PHASE_STATUS); dev->tf->error = ((mo_sense_key & 0xf) << 4) | ABRT_ERR; - if (dev->unit_attention) - dev->tf->error |= MCR_ERR; dev->tf->status = READY_STAT | ERR_STAT; dev->tf->phase = 3; dev->tf->pos = 0; @@ -808,31 +631,30 @@ mo_cmd_error(mo_t *dev) dev->callback = 50.0 * MO_TIME; mo_set_callback(dev); ui_sb_update_icon(SB_MO | dev->id, 0); - mo_log("MO %i: [%02X] ERROR: %02X/%02X/%02X\n", dev->id, dev->current_cdb[0], mo_sense_key, mo_asc, mo_ascq); + mo_log(dev->log, "[%02X] ERROR: %02X/%02X/%02X\n", dev->current_cdb[0], mo_sense_key, + mo_asc, mo_ascq); } static void mo_unit_attention(mo_t *dev) { mo_set_phase(dev, SCSI_PHASE_STATUS); - dev->tf->error = (SENSE_UNIT_ATTENTION << 4) | ABRT_ERR; - if (dev->unit_attention) - dev->tf->error |= MCR_ERR; - dev->tf->status = READY_STAT | ERR_STAT; - dev->tf->phase = 3; - dev->tf->pos = 0; - dev->packet_status = PHASE_ERROR; - dev->callback = 50.0 * MO_TIME; + dev->tf->error = (SENSE_UNIT_ATTENTION << 4) | ABRT_ERR; + dev->tf->status = READY_STAT | ERR_STAT; + dev->tf->phase = 3; + dev->tf->pos = 0; + dev->packet_status = PHASE_ERROR; + dev->callback = 50.0 * MO_TIME; mo_set_callback(dev); ui_sb_update_icon(SB_MO | dev->id, 0); - mo_log("MO %i: UNIT ATTENTION\n", dev->id); + mo_log(dev->log, "UNIT ATTENTION\n"); } static void mo_buf_alloc(mo_t *dev, uint32_t len) { - mo_log("MO %i: Allocated buffer length: %i\n", dev->id, len); - if (!dev->buffer) + mo_log(dev->log, "Allocated buffer length: %i\n", len); + if (dev->buffer == NULL) dev->buffer = (uint8_t *) malloc(len); } @@ -840,7 +662,7 @@ static void mo_buf_free(mo_t *dev) { if (dev->buffer) { - mo_log("MO %i: Freeing buffer...\n", dev->id); + mo_log(dev->log, "Freeing buffer...\n"); free(dev->buffer); dev->buffer = NULL; } @@ -853,6 +675,10 @@ mo_bus_master_error(scsi_common_t *sc) mo_buf_free(dev); mo_sense_key = mo_asc = mo_ascq = 0; + mo_info = (dev->sector_pos >> 24) | + ((dev->sector_pos >> 16) << 8) | + ((dev->sector_pos >> 8) << 16) | + ( dev->sector_pos << 24); mo_cmd_error(dev); } @@ -862,6 +688,7 @@ mo_not_ready(mo_t *dev) mo_sense_key = SENSE_NOT_READY; mo_asc = ASC_MEDIUM_NOT_PRESENT; mo_ascq = 0; + mo_info = 0x00000000; mo_cmd_error(dev); } @@ -871,6 +698,10 @@ mo_write_protected(mo_t *dev) mo_sense_key = SENSE_UNIT_ATTENTION; mo_asc = ASC_WRITE_PROTECTED; mo_ascq = 0; + mo_info = (dev->sector_pos >> 24) | + ((dev->sector_pos >> 16) << 8) | + ((dev->sector_pos >> 8) << 16) | + ( dev->sector_pos << 24); mo_cmd_error(dev); } @@ -880,6 +711,10 @@ mo_write_error(mo_t *dev) mo_sense_key = SENSE_MEDIUM_ERROR; mo_asc = ASC_WRITE_ERROR; mo_ascq = 0; + mo_info = (dev->sector_pos >> 24) | + ((dev->sector_pos >> 16) << 8) | + ((dev->sector_pos >> 8) << 16) | + ( dev->sector_pos << 24); mo_cmd_error(dev); } @@ -889,24 +724,30 @@ mo_read_error(mo_t *dev) mo_sense_key = SENSE_MEDIUM_ERROR; mo_asc = ASC_UNRECOVERED_READ_ERROR; mo_ascq = 0; + mo_info = (dev->sector_pos >> 24) | + ((dev->sector_pos >> 16) << 8) | + ((dev->sector_pos >> 8) << 16) | + ( dev->sector_pos << 24); mo_cmd_error(dev); } static void -mo_invalid_lun(mo_t *dev) +mo_invalid_lun(mo_t *dev, const uint8_t lun) { mo_sense_key = SENSE_ILLEGAL_REQUEST; mo_asc = ASC_INV_LUN; mo_ascq = 0; + mo_info = lun << 24; mo_cmd_error(dev); } static void -mo_illegal_opcode(mo_t *dev) +mo_illegal_opcode(mo_t *dev, const uint8_t opcode) { mo_sense_key = SENSE_ILLEGAL_REQUEST; mo_asc = ASC_ILLEGAL_OPCODE; mo_ascq = 0; + mo_info = opcode << 24; mo_cmd_error(dev); } @@ -916,140 +757,171 @@ mo_lba_out_of_range(mo_t *dev) mo_sense_key = SENSE_ILLEGAL_REQUEST; mo_asc = ASC_LBA_OUT_OF_RANGE; mo_ascq = 0; + mo_info = (dev->sector_pos >> 24) | + ((dev->sector_pos >> 16) << 8) | + ((dev->sector_pos >> 8) << 16) | + ( dev->sector_pos << 24); mo_cmd_error(dev); } static void -mo_invalid_field(mo_t *dev) +mo_invalid_field(mo_t *dev, const uint32_t field) { mo_sense_key = SENSE_ILLEGAL_REQUEST; mo_asc = ASC_INV_FIELD_IN_CMD_PACKET; mo_ascq = 0; + mo_info = (field >> 24) | + ((field >> 16) << 8) | + ((field >> 8) << 16) | + ( field << 24); mo_cmd_error(dev); dev->tf->status = 0x53; } static void -mo_invalid_field_pl(mo_t *dev) +mo_invalid_field_pl(mo_t *dev, const uint32_t field) { mo_sense_key = SENSE_ILLEGAL_REQUEST; mo_asc = ASC_INV_FIELD_IN_PARAMETER_LIST; mo_ascq = 0; + mo_info = (field >> 24) | + ((field >> 16) << 8) | + ((field >> 8) << 16) | + ( field << 24); mo_cmd_error(dev); dev->tf->status = 0x53; } static int -mo_blocks(mo_t *dev, int32_t *len, UNUSED(int first_batch), int out) +mo_blocks(mo_t *dev, int32_t *len, int out) { - *len = 0; + int ret = 0; - if (!dev->sector_len) { + *len = 0; + + if (!dev->sector_len) mo_command_complete(dev); - return 0; - } + else { + mo_log(dev->log, "%sing %i blocks starting from %i...\n", out ? "Writ" : "Read", + dev->requested_blocks, dev->sector_pos); - mo_log("%sing %i blocks starting from %i...\n", out ? "Writ" : "Read", dev->requested_blocks, dev->sector_pos); - - if (dev->sector_pos >= dev->drv->medium_size) { - mo_log("MO %i: Trying to %s beyond the end of disk\n", dev->id, out ? "write" : "read"); - mo_lba_out_of_range(dev); - return 0; - } - - *len = dev->requested_blocks * dev->drv->sector_size; - - for (int i = 0; i < dev->requested_blocks; i++) { - if (fseek(dev->drv->fp, dev->drv->base + (dev->sector_pos * dev->drv->sector_size) + (i * dev->drv->sector_size), SEEK_SET) == -1) { - if (out) - mo_write_error(dev); - else - mo_read_error(dev); - return -1; - } - - if (feof(dev->drv->fp)) - break; - - if (out) { - if (fwrite(dev->buffer + (i * dev->drv->sector_size), 1, dev->drv->sector_size, dev->drv->fp) != dev->drv->sector_size) { - mo_log("mo_blocks(): Error writing data\n"); - mo_write_error(dev); - return -1; - } - - fflush(dev->drv->fp); + if (dev->sector_pos >= dev->drv->medium_size) { + mo_log(dev->log, "Trying to %s beyond the end of disk\n", out ? "write" : "read"); + mo_lba_out_of_range(dev); } else { - if (fread(dev->buffer + (i * dev->drv->sector_size), 1, dev->drv->sector_size, dev->drv->fp) != dev->drv->sector_size) { - mo_log("mo_blocks(): Error reading data\n"); - mo_read_error(dev); - return -1; + *len = dev->requested_blocks * dev->drv->sector_size; + ret = 1; + + for (int i = 0; i < dev->requested_blocks; i++) { + if (fseek(dev->drv->fp, dev->drv->base + (dev->sector_pos * dev->drv->sector_size) + (i * dev->drv->sector_size), SEEK_SET) == -1) { + if (out) + mo_write_error(dev); + else + mo_read_error(dev); + + ret = -1; + } else { + if (!feof(dev->drv->fp)) + break; + + if (out) { + if (fwrite(dev->buffer + (i * dev->drv->sector_size), 1, + dev->drv->sector_size, dev->drv->fp) != dev->drv->sector_size) { + mo_log(dev->log, "mo_blocks(): Error writing data\n"); + mo_write_error(dev); + ret = -1; + } else + fflush(dev->drv->fp); + } else { + if (fread(dev->buffer + (i * dev->drv->sector_size), 1, + dev->drv->sector_size, dev->drv->fp) != dev->drv->sector_size) { + mo_log(dev->log, "mo_blocks(): Error reading data\n"); + mo_read_error(dev); + ret = -1; + } + } + } + + if (ret == -1) + break; + + dev->sector_pos++; + } + + if (ret == 1) { + mo_log(dev->log, "%s %i bytes of blocks...\n", out ? "Written" : "Read", *len); + + dev->sector_len -= dev->requested_blocks; } } } - mo_log("%s %i bytes of blocks...\n", out ? "Written" : "Read", *len); - - dev->sector_pos += dev->requested_blocks; - dev->sector_len -= dev->requested_blocks; - - return 1; + return ret; } void mo_insert(mo_t *dev) { - dev->unit_attention = 1; + if ((dev != NULL) && (dev->drv != NULL)) { + if (dev->drv->fp == NULL) { + dev->unit_attention = 0; + dev->transition = 0; + mo_log(dev->log, "Media removal\n"); + } else if (dev->transition) { + dev->unit_attention = 1; + /* Turn off the medium changed status. */ + dev->transition = 0; + mo_log(dev->log, "Media insert\n"); + } else { + dev->unit_attention = 0; + dev->transition = 1; + mo_log(dev->log, "Media transition\n"); + } + } } void mo_format(mo_t *dev) { - long size; int ret; int fd; - mo_log("MO %i: Formatting media...\n", dev->id); + mo_log(dev->log, "Formatting media...\n"); fseek(dev->drv->fp, 0, SEEK_END); - size = ftell(dev->drv->fp); + long size = ftell(dev->drv->fp); #ifdef _WIN32 - HANDLE fh; LARGE_INTEGER liSize; - fd = _fileno(dev->drv->fp); - fh = (HANDLE) _get_osfhandle(fd); + fd = _fileno(dev->drv->fp); + const HANDLE fh = (HANDLE) _get_osfhandle(fd); liSize.QuadPart = 0; ret = (int) SetFilePointerEx(fh, liSize, NULL, FILE_BEGIN); - if (!ret) { - mo_log("MO %i: Failed seek to start of image file\n", dev->id); - return; - } + if (ret) { + ret = (int) SetEndOfFile(fh); - ret = (int) SetEndOfFile(fh); + if (ret) { + liSize.QuadPart = size; + ret = (int) SetFilePointerEx(fh, liSize, NULL, FILE_BEGIN); - if (!ret) { - mo_log("MO %i: Failed to truncate image file to 0\n", dev->id); - return; - } + if (ret) { + ret = (int) SetEndOfFile(fh); - liSize.QuadPart = size; - ret = (int) SetFilePointerEx(fh, liSize, NULL, FILE_BEGIN); - - if (!ret) { - mo_log("MO %i: Failed seek to end of image file\n", dev->id); - return; - } - - ret = (int) SetEndOfFile(fh); - - if (!ret) { - mo_log("MO %i: Failed to truncate image file to %llu\n", dev->id, size); - return; + if (!ret) { + mo_log(dev->log, "Failed to truncate image file to %llu\n", size); + } + } else { + mo_log(dev->log, "Failed seek to end of image file\n"); + } + } else { + mo_log(dev->log, "Failed to truncate image file to 0\n"); + } + } else { + mo_log(dev->log, "Failed seek to start of image file\n"); } #else fd = fileno(dev->drv->fp); @@ -1057,15 +929,13 @@ mo_format(mo_t *dev) ret = ftruncate(fd, 0); if (ret) { - mo_log("MO %i: Failed to truncate image file to 0\n", dev->id); - return; - } + mo_log(dev->log, "Failed to truncate image file to 0\n"); + } else { + ret = ftruncate(fd, size); - ret = ftruncate(fd, size); - - if (ret) { - mo_log("MO %i: Failed to truncate image file to %llu", dev->id, size); - return; + if (ret) { + mo_log(dev->log, "Failed to truncate image file to %llu", size); + } } #endif } @@ -1080,10 +950,11 @@ mo_erase(mo_t *dev) return -1; } - mo_log("MO %i: Erasing %i blocks starting from %i...\n", dev->id, dev->sector_len, dev->sector_pos); + mo_log(dev->log, "Erasing %i blocks starting from %i...\n", + dev->sector_len, dev->sector_pos); if (dev->sector_pos >= dev->drv->medium_size) { - mo_log("MO %i: Trying to erase beyond the end of disk\n", dev->id); + mo_log(dev->log, "Trying to erase beyond the end of disk\n"); mo_lba_out_of_range(dev); return 0; } @@ -1091,7 +962,8 @@ mo_erase(mo_t *dev) mo_buf_alloc(dev, dev->drv->sector_size); memset(dev->buffer, 0, dev->drv->sector_size); - fseek(dev->drv->fp, dev->drv->base + (dev->sector_pos * dev->drv->sector_size), SEEK_SET); + fseek(dev->drv->fp, dev->drv->base + (dev->sector_pos * dev->drv->sector_size), + SEEK_SET); for (i = 0; i < dev->requested_blocks; i++) { if (feof(dev->drv->fp)) @@ -1102,7 +974,7 @@ mo_erase(mo_t *dev) fflush(dev->drv->fp); - mo_log("MO %i: Erased %i bytes of blocks...\n", dev->id, i * dev->drv->sector_size); + mo_log(dev->log, "Erased %i bytes of blocks...\n", i * dev->drv->sector_size); dev->sector_pos += i; dev->sector_len -= i; @@ -1110,96 +982,110 @@ mo_erase(mo_t *dev) return 1; } -/*SCSI Sense Initialization*/ -void -mo_sense_code_ok(mo_t *dev) -{ - mo_sense_key = SENSE_NONE; - mo_asc = 0; - mo_ascq = 0; -} - static int -mo_pre_execution_check(mo_t *dev, uint8_t *cdb) +mo_pre_execution_check(mo_t *dev, const uint8_t *cdb) { - int ready = 0; + int ready; - if ((cdb[0] != GPCMD_REQUEST_SENSE) && (dev->cur_lun == SCSI_LUN_USE_CDB) && (cdb[1] & 0xe0)) { - mo_log("MO %i: Attempting to execute a unknown command targeted at SCSI LUN %i\n", dev->id, + if ((cdb[0] != GPCMD_REQUEST_SENSE) && (dev->cur_lun == SCSI_LUN_USE_CDB) && + (cdb[1] & 0xe0)) { + mo_log(dev->log, "Attempting to execute a unknown command targeted at SCSI LUN %i\n", ((dev->tf->request_length >> 5) & 7)); - mo_invalid_lun(dev); + mo_invalid_lun(dev, cdb[1] >> 5); return 0; } if (!(mo_command_flags[cdb[0]] & IMPLEMENTED)) { - mo_log("MO %i: Attempting to execute unknown command %02X over %s\n", dev->id, cdb[0], - (dev->drv->bus_type == MO_BUS_SCSI) ? "SCSI" : "ATAPI"); + mo_log(dev->log, "Attempting to execute unknown command %02X over %s\n", + cdb[0], (dev->drv->bus_type == MO_BUS_SCSI) ? + "SCSI" : "ATAPI"); - mo_illegal_opcode(dev); + mo_illegal_opcode(dev, cdb[0]); return 0; } - if ((dev->drv->bus_type < MO_BUS_SCSI) && (mo_command_flags[cdb[0]] & SCSI_ONLY)) { - mo_log("MO %i: Attempting to execute SCSI-only command %02X over ATAPI\n", dev->id, cdb[0]); - mo_illegal_opcode(dev); + if ((dev->drv->bus_type < MO_BUS_SCSI) && + (mo_command_flags[cdb[0]] & SCSI_ONLY)) { + mo_log(dev->log, "Attempting to execute SCSI-only command %02X " + "over ATAPI\n", cdb[0]); + mo_illegal_opcode(dev, cdb[0]); return 0; } - if ((dev->drv->bus_type == MO_BUS_SCSI) && (mo_command_flags[cdb[0]] & ATAPI_ONLY)) { - mo_log("MO %i: Attempting to execute ATAPI-only command %02X over SCSI\n", dev->id, cdb[0]); - mo_illegal_opcode(dev); + if ((dev->drv->bus_type == MO_BUS_SCSI) && + (mo_command_flags[cdb[0]] & ATAPI_ONLY)) { + mo_log(dev->log, "Attempting to execute ATAPI-only command %02X " + "over SCSI\n", cdb[0]); + mo_illegal_opcode(dev, cdb[0]); return 0; } - ready = (dev->drv->fp != NULL); + if (dev->transition) { + if ((cdb[0] == GPCMD_TEST_UNIT_READY) || (cdb[0] == GPCMD_REQUEST_SENSE)) + ready = 0; + else { + if (!(mo_command_flags[cdb[0]] & ALLOW_UA)) { + mo_log(dev->log, "(ext_medium_changed != 0): mo_insert()\n"); + mo_insert((void *) dev); + } - /* If the drive is not ready, there is no reason to keep the + ready = (dev->drv->fp != NULL); + } + } else + ready = (dev->drv->fp != NULL); + + /* + If the drive is not ready, there is no reason to keep the UNIT ATTENTION condition present, as we only use it to mark - disc changes. */ - if (!ready && dev->unit_attention) + disc changes. + */ + if (!ready && (dev->unit_attention > 0)) dev->unit_attention = 0; - /* If the UNIT ATTENTION condition is set and the command does not allow - execution under it, error out and report the condition. */ + /* + If the UNIT ATTENTION condition is set and the command does not allow + execution under it, error out and report the condition. + */ if (dev->unit_attention == 1) { - /* Only increment the unit attention phase if the command can not pass through it. */ + /* + Only increment the unit attention phase if the command can + not pass through it. + */ if (!(mo_command_flags[cdb[0]] & ALLOW_UA)) { - /* mo_log("MO %i: Unit attention now 2\n", dev->id); */ - dev->unit_attention = 2; - mo_log("MO %i: UNIT ATTENTION: Command %02X not allowed to pass through\n", dev->id, cdb[0]); + mo_log(dev->log, "Unit attention now 2\n"); + dev->unit_attention++; + mo_log(dev->log, "UNIT ATTENTION: Command %02X not allowed to " + "pass through\n", cdb[0]); mo_unit_attention(dev); return 0; } } else if (dev->unit_attention == 2) { if (cdb[0] != GPCMD_REQUEST_SENSE) { - /* mo_log("MO %i: Unit attention now 0\n", dev->id); */ + mo_log(dev->log, "MO %i: Unit attention now 0\n"); dev->unit_attention = 0; } } - /* Unless the command is REQUEST SENSE, clear the sense. This will *NOT* - the UNIT ATTENTION condition if it's set. */ + /* + Unless the command is REQUEST SENSE, clear the sense. This will *NOT* clear + the UNIT ATTENTION condition if it's set. + */ if (cdb[0] != GPCMD_REQUEST_SENSE) mo_sense_clear(dev, cdb[0]); - /* Next it's time for NOT READY. */ - if ((mo_command_flags[cdb[0]] & CHECK_READY) && !ready) { - mo_log("MO %i: Not ready (%02X)\n", dev->id, cdb[0]); + if (!ready && (mo_command_flags[cdb[0]] & CHECK_READY)) { + mo_log(dev->log, "Not ready (%02X)\n", cdb[0]); mo_not_ready(dev); return 0; } - mo_log("MO %i: Continuing with command %02X\n", dev->id, cdb[0]); - + mo_log(dev->log, "Continuing with command %02X\n", cdb[0]); return 1; } static void mo_seek(mo_t *dev, uint32_t pos) { -#if 0 - mo_log("MO %i: Seek %08X\n", dev->id, pos); -#endif dev->sector_pos = pos; } @@ -1220,28 +1106,30 @@ mo_reset(scsi_common_t *sc) dev->callback = 0.0; mo_set_callback(dev); dev->tf->phase = 1; - dev->tf->request_length = 0xEB14; + dev->tf->request_length = 0xeb14; dev->packet_status = PHASE_NONE; - dev->unit_attention = 0; dev->cur_lun = SCSI_LUN_USE_CDB; + mo_sense_key = mo_asc = mo_ascq = dev->unit_attention = dev->transition = 0; + mo_info = 0x00000000; } static void -mo_request_sense(mo_t *dev, uint8_t *buffer, uint8_t alloc_length, int desc) +mo_request_sense(mo_t *dev, uint8_t *buffer, const uint8_t alloc_length, const int desc) { - /*Will return 18 bytes of 0*/ + /* Will return 18 bytes of 0. */ if (alloc_length != 0) { - memset(buffer, 0, alloc_length); - if (!desc) - memcpy(buffer, dev->sense, alloc_length); - else { + memset(buffer, 0x00, alloc_length); + if (desc) { buffer[1] = mo_sense_key; buffer[2] = mo_asc; buffer[3] = mo_ascq; - } + } else + memcpy(buffer, dev->sense, alloc_length); } - buffer[0] = desc ? 0x72 : 0x70; + buffer[0] = desc ? 0x72 : 0xf0; + if (!desc) + buffer[7] = 10; if (dev->unit_attention && (mo_sense_key == 0)) { buffer[desc ? 1 : 2] = SENSE_UNIT_ATTENTION; @@ -1249,25 +1137,27 @@ mo_request_sense(mo_t *dev, uint8_t *buffer, uint8_t alloc_length, int desc) buffer[desc ? 3 : 13] = 0; } - mo_log("MO %i: Reporting sense: %02X %02X %02X\n", dev->id, buffer[2], buffer[12], buffer[13]); + mo_log(dev->log, "Reporting sense: %02X %02X %02X\n", buffer[2], buffer[12], buffer[13]); if (buffer[desc ? 1 : 2] == SENSE_UNIT_ATTENTION) { - /* If the last remaining sense is unit attention, clear - that condition. */ + /* If the last remaining sense is unit attention, clear that condition. */ dev->unit_attention = 0; } /* Clear the sense stuff as per the spec. */ mo_sense_clear(dev, GPCMD_REQUEST_SENSE); + + if (dev->transition) { + mo_log(dev->log, "MO_TRANSITION: mo_insert()\n"); + mo_insert((void *) dev); + } } static void mo_request_sense_for_scsi(scsi_common_t *sc, uint8_t *buffer, uint8_t alloc_length) { - mo_t *dev = (mo_t *) sc; - int ready = 0; - - ready = (dev->drv->fp != NULL); + mo_t *dev = (mo_t *) sc; + const int ready = (dev->drv->fp != NULL); if (!ready && dev->unit_attention) { /* If the drive is not ready, there is no reason to keep the @@ -1277,12 +1167,11 @@ mo_request_sense_for_scsi(scsi_common_t *sc, uint8_t *buffer, uint8_t alloc_leng } /* Do *NOT* advance the unit attention phase. */ - mo_request_sense(dev, buffer, alloc_length, 0); } static void -mo_set_buf_len(mo_t *dev, int32_t *BufLen, int32_t *src_len) +mo_set_buf_len(const mo_t *dev, int32_t *BufLen, int32_t *src_len) { if (dev->drv->bus_type == MO_BUS_SCSI) { if (*BufLen == -1) @@ -1291,29 +1180,28 @@ mo_set_buf_len(mo_t *dev, int32_t *BufLen, int32_t *src_len) *BufLen = MIN(*src_len, *BufLen); *src_len = *BufLen; } - mo_log("MO %i: Actual transfer length: %i\n", dev->id, *BufLen); + mo_log(dev->log, "Actual transfer length: %i\n", *BufLen); } } static void -mo_command(scsi_common_t *sc, uint8_t *cdb) +mo_command(scsi_common_t *sc, const uint8_t *cdb) { - mo_t *dev = (mo_t *) sc; - int pos = 0; - int block_desc = 0; - int ret; - int32_t len; - int32_t max_len; - int32_t alloc_length; - int size_idx; - int idx = 0; - unsigned preamble_len; - char device_identify[9] = { '8', '6', 'B', '_', 'M', 'O', '0', '0', 0 }; - int32_t blen = 0; - int32_t *BufLen; - uint32_t previous_pos = 0; - uint8_t scsi_bus = (dev->drv->scsi_device_id >> 4) & 0x0f; - uint8_t scsi_id = dev->drv->scsi_device_id & 0x0f; + mo_t * dev = (mo_t *) sc; + char device_identify[9] = { '8', '6', 'B', '_', 'M', 'O', '0', '0', 0 }; + uint32_t previous_pos = 0; + int32_t blen = 0; + const uint8_t scsi_bus = (dev->drv->scsi_device_id >> 4) & 0x0f; + const uint8_t scsi_id = dev->drv->scsi_device_id & 0x0f; + int pos = 0; + int idx = 0; + int32_t len; + int32_t max_len; + int32_t alloc_length; + unsigned preamble_len; + int block_desc; + int size_idx; + int32_t * BufLen; if (dev->drv->bus_type == MO_BUS_SCSI) { BufLen = &scsi_devices[scsi_bus][scsi_id].buffer_length; @@ -1331,11 +1219,13 @@ mo_command(scsi_common_t *sc, uint8_t *cdb) memcpy(dev->current_cdb, cdb, 12); if (cdb[0] != 0) { - mo_log("MO %i: Command 0x%02X, Sense Key %02X, Asc %02X, Ascq %02X, Unit attention: %i\n", - dev->id, cdb[0], mo_sense_key, mo_asc, mo_ascq, dev->unit_attention); - mo_log("MO %i: Request length: %04X\n", dev->id, dev->tf->request_length); + mo_log(dev->log, "Command 0x%02X, Sense Key %02X, Asc %02X, Ascq %02X, " + "Unit attention: %i\n", + cdb[0], mo_sense_key, mo_asc, mo_ascq, dev->unit_attention); + mo_log(dev->log, "Request length: %04X\n", dev->tf->request_length); - mo_log("MO %i: CDB: %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X\n", dev->id, + mo_log(dev->log, "CDB: %02X %02X %02X %02X %02X %02X %02X %02X " + "%02X %02X %02X %02X\n", cdb[0], cdb[1], cdb[2], cdb[3], cdb[4], cdb[5], cdb[6], cdb[7], cdb[8], cdb[9], cdb[10], cdb[11]); } @@ -1344,14 +1234,17 @@ mo_command(scsi_common_t *sc, uint8_t *cdb) mo_set_phase(dev, SCSI_PHASE_STATUS); - /* This handles the Not Ready/Unit Attention check if it has to be handled at this point. */ + /* + This handles the Not Ready/Unit Attention check if it has to be + handled at this point. + */ if (mo_pre_execution_check(dev, cdb) == 0) return; switch (cdb[0]) { case GPCMD_SEND_DIAGNOSTIC: if (!(cdb[1] & (1 << 2))) { - mo_invalid_field(dev); + mo_invalid_field(dev, cdb[1]); return; } fallthrough; @@ -1380,8 +1273,6 @@ mo_command(scsi_common_t *sc, uint8_t *cdb) break; case GPCMD_REQUEST_SENSE: - /* If there's a unit attention condition and there's a buffered not ready, a standalone REQUEST SENSE - should forget about the not ready, and report unit attention straight away. */ mo_set_phase(dev, SCSI_PHASE_DATA_IN); max_len = cdb[4]; @@ -1422,158 +1313,187 @@ mo_command(scsi_common_t *sc, uint8_t *cdb) switch (cdb[0]) { case GPCMD_READ_6: dev->sector_len = cdb[4]; - dev->sector_pos = ((((uint32_t) cdb[1]) & 0x1f) << 16) | (((uint32_t) cdb[2]) << 8) | ((uint32_t) cdb[3]); + dev->sector_pos = ((((uint32_t) cdb[1]) & 0x1f) << 16) | + (((uint32_t) cdb[2]) << 8) | ((uint32_t) cdb[3]); if (dev->sector_len == 0) dev->sector_len = 256; - mo_log("MO %i: Length: %i, LBA: %i\n", dev->id, dev->sector_len, dev->sector_pos); + mo_log(dev->log, "Length: %i, LBA: %i\n", dev->sector_len, dev->sector_pos); break; case GPCMD_READ_10: dev->sector_len = (cdb[7] << 8) | cdb[8]; - dev->sector_pos = (cdb[2] << 24) | (cdb[3] << 16) | (cdb[4] << 8) | cdb[5]; - mo_log("MO %i: Length: %i, LBA: %i\n", dev->id, dev->sector_len, dev->sector_pos); + dev->sector_pos = (cdb[2] << 24) | (cdb[3] << 16) | + (cdb[4] << 8) | cdb[5]; + mo_log(dev->log, "Length: %i, LBA: %i\n", dev->sector_len, dev->sector_pos); break; case GPCMD_READ_12: - dev->sector_len = (((uint32_t) cdb[6]) << 24) | (((uint32_t) cdb[7]) << 16) | (((uint32_t) cdb[8]) << 8) | ((uint32_t) cdb[9]); - dev->sector_pos = (((uint32_t) cdb[2]) << 24) | (((uint32_t) cdb[3]) << 16) | (((uint32_t) cdb[4]) << 8) | ((uint32_t) cdb[5]); - mo_log("MO %i: Length: %i, LBA: %i\n", dev->id, dev->sector_len, dev->sector_pos); + dev->sector_len = (((uint32_t) cdb[6]) << 24) | + (((uint32_t) cdb[7]) << 16) | + (((uint32_t) cdb[8]) << 8) | ((uint32_t) cdb[9]); + dev->sector_pos = (((uint32_t) cdb[2]) << 24) | + (((uint32_t) cdb[3]) << 16) | + (((uint32_t) cdb[4]) << 8) | ((uint32_t) cdb[5]); + mo_log(dev->log, "Length: %i, LBA: %i\n", dev->sector_len, dev->sector_pos); break; default: break; } - if (!dev->sector_len) { + if (dev->sector_len) { + max_len = dev->sector_len; + dev->requested_blocks = max_len; + + dev->packet_len = max_len * alloc_length; + mo_buf_alloc(dev, dev->packet_len); + + const int ret = mo_blocks(dev, &alloc_length, 0); + + if (ret > 0) { + dev->requested_blocks = max_len; + dev->packet_len = alloc_length; + + mo_set_buf_len(dev, BufLen, (int32_t *) &dev->packet_len); + + mo_data_command_finish(dev, alloc_length, dev->drv->sector_size, alloc_length, 0); + + if (dev->packet_status != PHASE_COMPLETE) + ui_sb_update_icon(SB_MO | dev->id, 1); + else + ui_sb_update_icon(SB_MO | dev->id, 0); + } else { + mo_set_phase(dev, SCSI_PHASE_STATUS); + dev->packet_status = (ret < 0) ? PHASE_ERROR : PHASE_COMPLETE; + dev->callback = 20.0 * MO_TIME; + mo_set_callback(dev); + mo_buf_free(dev); + } + } else { mo_set_phase(dev, SCSI_PHASE_STATUS); - /* mo_log("MO %i: All done - callback set\n", dev->id); */ + /* mo_log(dev->log, "All done - callback set\n"); */ dev->packet_status = PHASE_COMPLETE; dev->callback = 20.0 * MO_TIME; mo_set_callback(dev); - break; } - - max_len = dev->sector_len; - dev->requested_blocks = max_len; /* If we're reading all blocks in one go for DMA, why not also for PIO, it should NOT - matter anyway, this step should be identical and only the way the read dat is - transferred to the host should be different. */ - - dev->packet_len = max_len * alloc_length; - mo_buf_alloc(dev, dev->packet_len); - - ret = mo_blocks(dev, &alloc_length, 1, 0); - if (ret <= 0) { - mo_set_phase(dev, SCSI_PHASE_STATUS); - dev->packet_status = (ret < 0) ? PHASE_ERROR : PHASE_COMPLETE; - dev->callback = 20.0 * MO_TIME; - mo_set_callback(dev); - mo_buf_free(dev); - return; - } - - dev->requested_blocks = max_len; - dev->packet_len = alloc_length; - - mo_set_buf_len(dev, BufLen, (int32_t *) &dev->packet_len); - - mo_data_command_finish(dev, alloc_length, dev->drv->sector_size, alloc_length, 0); - - if (dev->packet_status != PHASE_COMPLETE) - ui_sb_update_icon(SB_MO | dev->id, 1); - else - ui_sb_update_icon(SB_MO | dev->id, 0); - return; + break; case GPCMD_VERIFY_6: case GPCMD_VERIFY_10: case GPCMD_VERIFY_12: - /* Data and blank verification cannot be set at the same time */ - if ((cdb[1] & 2) && (cdb[1] & 4)) { - mo_invalid_field(dev); - return; - } - if (!(cdb[1] & 2) || (cdb[1] & 4)) { + if (!(cdb[1] & 2)) { mo_set_phase(dev, SCSI_PHASE_STATUS); mo_command_complete(dev); break; } - /*TODO: Implement*/ - mo_invalid_field(dev); - return; - + fallthrough; case GPCMD_WRITE_6: case GPCMD_WRITE_10: case GPCMD_WRITE_AND_VERIFY_10: case GPCMD_WRITE_12: case GPCMD_WRITE_AND_VERIFY_12: mo_set_phase(dev, SCSI_PHASE_DATA_OUT); - alloc_length = dev->drv->sector_size; - - if (dev->drv->read_only) { - mo_write_protected(dev); - return; - } + alloc_length = 512; switch (cdb[0]) { case GPCMD_VERIFY_6: case GPCMD_WRITE_6: dev->sector_len = cdb[4]; + /* + For READ (6) and WRITE (6), a length of 0 indicates a + transfer of 256 sectors. + */ if (dev->sector_len == 0) - dev->sector_len = 256; /* For READ (6) and WRITE (6), a length of 0 indicates a transfer of 256 sector. */ - dev->sector_pos = ((((uint32_t) cdb[1]) & 0x1f) << 16) | (((uint32_t) cdb[2]) << 8) | ((uint32_t) cdb[3]); + dev->sector_len = 256; + dev->sector_pos = ((((uint32_t) cdb[1]) & 0x1f) << 16) | + (((uint32_t) cdb[2]) << 8) | ((uint32_t) cdb[3]); + mo_log(dev->log, "Length: %i, LBA: %i\n", dev->sector_len, dev->sector_pos); break; case GPCMD_VERIFY_10: case GPCMD_WRITE_10: case GPCMD_WRITE_AND_VERIFY_10: dev->sector_len = (cdb[7] << 8) | cdb[8]; - dev->sector_pos = (cdb[2] << 24) | (cdb[3] << 16) | (cdb[4] << 8) | cdb[5]; - mo_log("MO %i: Length: %i, LBA: %i\n", dev->id, dev->sector_len, dev->sector_pos); + dev->sector_pos = (cdb[2] << 24) | (cdb[3] << 16) | + (cdb[4] << 8) | cdb[5]; + mo_log(dev->log, "Length: %i, LBA: %i\n", dev->sector_len, dev->sector_pos); break; case GPCMD_VERIFY_12: case GPCMD_WRITE_12: case GPCMD_WRITE_AND_VERIFY_12: - dev->sector_len = (((uint32_t) cdb[6]) << 24) | (((uint32_t) cdb[7]) << 16) | (((uint32_t) cdb[8]) << 8) | ((uint32_t) cdb[9]); - dev->sector_pos = (((uint32_t) cdb[2]) << 24) | (((uint32_t) cdb[3]) << 16) | (((uint32_t) cdb[4]) << 8) | ((uint32_t) cdb[5]); + dev->sector_len = (((uint32_t) cdb[6]) << 24) | + (((uint32_t) cdb[7]) << 16) | + (((uint32_t) cdb[8]) << 8) | ((uint32_t) cdb[9]); + dev->sector_pos = (((uint32_t) cdb[2]) << 24) | + (((uint32_t) cdb[3]) << 16) | + (((uint32_t) cdb[4]) << 8) | ((uint32_t) cdb[5]); break; default: break; } - if ((dev->sector_pos >= dev->drv->medium_size) /* || - ((dev->sector_pos + dev->sector_len - 1) >= dev->drv->medium_size)*/ - ) { + if (dev->sector_pos > (mo_types[dev->drv->type].sectors - 1)) mo_lba_out_of_range(dev); - return; + else { + if (dev->sector_len) { + max_len = dev->sector_len; + dev->requested_blocks = max_len; + + dev->packet_len = max_len * alloc_length; + mo_buf_alloc(dev, dev->packet_len); + + dev->requested_blocks = max_len; + dev->packet_len = max_len << 9; + + mo_set_buf_len(dev, BufLen, (int32_t *) &dev->packet_len); + + mo_data_command_finish(dev, dev->packet_len, 512, + dev->packet_len, 1); + + ui_sb_update_icon(SB_MO | dev->id, + dev->packet_status != PHASE_COMPLETE); + } else { + mo_set_phase(dev, SCSI_PHASE_STATUS); + mo_log(dev->log, "All done - callback set\n"); + dev->packet_status = PHASE_COMPLETE; + dev->callback = 20.0 * SCSI_TIME; + mo_set_callback(dev); + } } + break; - if (!dev->sector_len) { - mo_set_phase(dev, SCSI_PHASE_STATUS); - /* mo_log("MO %i: All done - callback set\n", dev->id); */ - dev->packet_status = PHASE_COMPLETE; - dev->callback = 20.0 * MO_TIME; - mo_set_callback(dev); - break; + case GPCMD_WRITE_SAME_10: + alloc_length = 512; + + if ((cdb[1] & 6) == 6) + mo_invalid_field(dev, cdb[1]); + else { + dev->sector_len = (cdb[7] << 8) | cdb[8]; + dev->sector_pos = (cdb[2] << 24) | (cdb[3] << 16) | (cdb[4] << 8) | cdb[5]; + + if (dev->sector_pos > (mo_types[dev->drv->type].sectors - 1)) + mo_lba_out_of_range(dev); + else if (dev->sector_len) { + mo_buf_alloc(dev, alloc_length); + mo_set_buf_len(dev, BufLen, (int32_t *) &dev->packet_len); + + dev->requested_blocks = 1; + dev->packet_len = alloc_length; + + mo_set_phase(dev, SCSI_PHASE_DATA_OUT); + + mo_data_command_finish(dev, 512, 512, + alloc_length, 1); + + ui_sb_update_icon(SB_MO | dev->id, + dev->packet_status != PHASE_COMPLETE); + } else { + mo_set_phase(dev, SCSI_PHASE_STATUS); + mo_log(dev->log, "All done - callback set\n"); + dev->packet_status = PHASE_COMPLETE; + dev->callback = 20.0 * SCSI_TIME; + mo_set_callback(dev); + } } - - max_len = dev->sector_len; - dev->requested_blocks = max_len; /* If we're writing all blocks in one go for DMA, why not also for PIO, it should NOT - matter anyway, this step should be identical and only the way the read dat is - transferred to the host should be different. */ - - dev->packet_len = max_len * alloc_length; - mo_buf_alloc(dev, dev->packet_len); - - dev->requested_blocks = max_len; - dev->packet_len = max_len << 9; - - mo_set_buf_len(dev, BufLen, (int32_t *) &dev->packet_len); - - mo_data_command_finish(dev, dev->packet_len, dev->drv->sector_size, dev->packet_len, 1); - - if (dev->packet_status != PHASE_COMPLETE) - ui_sb_update_icon(SB_MO | dev->id, 1); - else - ui_sb_update_icon(SB_MO | dev->id, 0); - return; + break; case GPCMD_MODE_SENSE_6: case GPCMD_MODE_SENSE_10: @@ -1593,7 +1513,7 @@ mo_command(scsi_common_t *sc, uint8_t *cdb) } if (!(mo_mode_sense_page_flags & (1LL << (uint64_t) (cdb[2] & 0x3f)))) { - mo_invalid_field(dev); + mo_invalid_field(dev, cdb[2]); mo_buf_free(dev); return; } @@ -1602,14 +1522,16 @@ mo_command(scsi_common_t *sc, uint8_t *cdb) alloc_length = len; if (cdb[0] == GPCMD_MODE_SENSE_6) { - len = mo_mode_sense(dev, dev->buffer, 4, cdb[2], block_desc); + len = mo_mode_sense(dev, dev->buffer, 4, + cdb[2], block_desc); len = MIN(len, alloc_length); dev->buffer[0] = len - 1; dev->buffer[1] = 0; if (block_desc) dev->buffer[3] = 8; } else { - len = mo_mode_sense(dev, dev->buffer, 8, cdb[2], block_desc); + len = mo_mode_sense(dev, dev->buffer, 8, + cdb[2], block_desc); len = MIN(len, alloc_length); dev->buffer[0] = (len - 2) >> 8; dev->buffer[1] = (len - 2) & 255; @@ -1622,7 +1544,7 @@ mo_command(scsi_common_t *sc, uint8_t *cdb) mo_set_buf_len(dev, BufLen, &len); - mo_log("MO %i: Reading mode page: %02X...\n", dev->id, cdb[2]); + mo_log(dev->log, "Reading mode page: %02X...\n", cdb[2]); mo_data_command_finish(dev, len, len, alloc_length, 0); return; @@ -1682,7 +1604,7 @@ mo_command(scsi_common_t *sc, uint8_t *cdb) preamble_len = 4; size_idx = 3; - dev->buffer[idx++] = 7; /*Optical disk*/ + dev->buffer[idx++] = 7; /* Optical disk */ dev->buffer[idx++] = cdb[2]; dev->buffer[idx++] = 0; @@ -1693,14 +1615,15 @@ mo_command(scsi_common_t *sc, uint8_t *cdb) dev->buffer[idx++] = 0x00; dev->buffer[idx++] = 0x80; break; - case 0x80: /*Unit serial number page*/ + case 0x80: /*Unit serial number page*/ dev->buffer[idx++] = strlen("VCM!10") + 1; - ide_padstr8(dev->buffer + idx, 20, "VCM!10"); /* Serial */ + /* Serial */ + ide_padstr8(dev->buffer + idx, 20, "VCM!10"); idx += strlen("VCM!10"); break; default: - mo_log("INQUIRY: Invalid page: %02X\n", cdb[2]); - mo_invalid_field(dev); + mo_log(dev->log, "INQUIRY: Invalid page: %02X\n", cdb[2]); + mo_invalid_field(dev, cdb[2]); mo_buf_free(dev); return; } @@ -1710,30 +1633,34 @@ mo_command(scsi_common_t *sc, uint8_t *cdb) memset(dev->buffer, 0, 8); if ((cdb[1] & 0xe0) || ((dev->cur_lun > 0x00) && (dev->cur_lun < 0xff))) - dev->buffer[0] = 0x7f; /*No physical device on this LUN*/ + dev->buffer[0] = 0x7f; /* No physical device on this LUN */ else - dev->buffer[0] = 0x07; /*Optical disk*/ - dev->buffer[1] = 0x80; /*Removable*/ - dev->buffer[2] = (dev->drv->bus_type == MO_BUS_SCSI) ? 0x02 : 0x00; /*SCSI-2 compliant*/ + dev->buffer[0] = 0x07; /* Optical disk */ + dev->buffer[1] = 0x80; /* Removable */ + /* SCSI-2 compliant */ + dev->buffer[2] = (dev->drv->bus_type == MO_BUS_SCSI) ? 0x02 : 0x00; dev->buffer[3] = (dev->drv->bus_type == MO_BUS_SCSI) ? 0x02 : 0x21; -#if 0 - dev->buffer[4] = 31; -#endif dev->buffer[4] = 0; if (dev->drv->bus_type == MO_BUS_SCSI) { - dev->buffer[6] = 1; /* 16-bit transfers supported */ - dev->buffer[7] = 0x20; /* Wide bus supported */ + dev->buffer[6] = 1; /* 16-bit transfers supported */ + dev->buffer[7] = 0x20; /* Wide bus supported */ } dev->buffer[7] |= 0x02; if (dev->drv->type > 0) { - ide_padstr8(dev->buffer + 8, 8, mo_drive_types[dev->drv->type].vendor); /* Vendor */ - ide_padstr8(dev->buffer + 16, 16, mo_drive_types[dev->drv->type].model); /* Product */ - ide_padstr8(dev->buffer + 32, 4, mo_drive_types[dev->drv->type].revision); /* Revision */ + ide_padstr8(dev->buffer + 8, 8, + mo_drive_types[dev->drv->type].vendor); /* Vendor */ + ide_padstr8(dev->buffer + 16, 16, + mo_drive_types[dev->drv->type].model); /* Product */ + ide_padstr8(dev->buffer + 32, 4, + mo_drive_types[dev->drv->type].revision); /* Revision */ } else { - ide_padstr8(dev->buffer + 8, 8, EMU_NAME); /* Vendor */ - ide_padstr8(dev->buffer + 16, 16, device_identify); /* Product */ - ide_padstr8(dev->buffer + 32, 4, EMU_VERSION_EX); /* Revision */ + ide_padstr8(dev->buffer + 8, 8, + EMU_NAME); /* Vendor */ + ide_padstr8(dev->buffer + 16, 16, + device_identify); /* Product */ + ide_padstr8(dev->buffer + 32, 4, + EMU_VERSION_EX); /* Revision */ } idx = 36; @@ -1784,7 +1711,8 @@ mo_command(scsi_common_t *sc, uint8_t *cdb) mo_buf_alloc(dev, 8); - max_len = dev->drv->medium_size - 1; /* IMPORTANT: What's returned is the last LBA block. */ + /* IMPORTANT: What's returned is the last LBA block. */ + max_len = dev->drv->medium_size - 1; memset(dev->buffer, 0, 8); dev->buffer[0] = (max_len >> 24) & 0xff; dev->buffer[1] = (max_len >> 16) & 0xff; @@ -1801,7 +1729,7 @@ mo_command(scsi_common_t *sc, uint8_t *cdb) case GPCMD_ERASE_10: case GPCMD_ERASE_12: - /*Relative address*/ + /* Relative address. */ if (cdb[1] & 1) previous_pos = dev->sector_pos; @@ -1810,18 +1738,20 @@ mo_command(scsi_common_t *sc, uint8_t *cdb) dev->sector_len = (cdb[7] << 8) | cdb[8]; break; case GPCMD_ERASE_12: - dev->sector_len = (((uint32_t) cdb[6]) << 24) | (((uint32_t) cdb[7]) << 16) | (((uint32_t) cdb[8]) << 8) | ((uint32_t) cdb[9]); + dev->sector_len = (((uint32_t) cdb[6]) << 24) | + (((uint32_t) cdb[7]) << 16) | + (((uint32_t) cdb[8]) << 8) | ((uint32_t) cdb[9]); break; default: break; } - /*Erase all remaining sectors*/ + /* Erase all remaining sectors. */ if (cdb[1] & 4) { - /* Cannot have a sector number when erase all*/ + /* Cannot have a sector number when erase all. */ if (dev->sector_len) { - mo_invalid_field(dev); + mo_invalid_field(dev, dev->sector_len); return; } mo_format(dev); @@ -1832,10 +1762,13 @@ mo_command(scsi_common_t *sc, uint8_t *cdb) switch (cdb[0]) { case GPCMD_ERASE_10: - dev->sector_pos = (cdb[2] << 24) | (cdb[3] << 16) | (cdb[4] << 8) | cdb[5]; + dev->sector_pos = (cdb[2] << 24) | (cdb[3] << 16) | + (cdb[4] << 8) | cdb[5]; break; case GPCMD_ERASE_12: - dev->sector_pos = (((uint32_t) cdb[2]) << 24) | (((uint32_t) cdb[3]) << 16) | (((uint32_t) cdb[4]) << 8) | ((uint32_t) cdb[5]); + dev->sector_pos = (((uint32_t) cdb[2]) << 24) | + (((uint32_t) cdb[3]) << 16) | + (((uint32_t) cdb[4]) << 8) | ((uint32_t) cdb[5]); break; default: @@ -1849,7 +1782,10 @@ mo_command(scsi_common_t *sc, uint8_t *cdb) mo_command_complete(dev); break; - /*Never seen media that supports generations but it's interesting to know if any implementation calls this commmand*/ + /* + Never seen media that supports generations but it's interesting to know if any + implementation calls this commmand. + */ case GPCMD_READ_GENERATION: mo_set_phase(dev, SCSI_PHASE_DATA_IN); @@ -1866,12 +1802,13 @@ mo_command(scsi_common_t *sc, uint8_t *cdb) break; default: - mo_illegal_opcode(dev); + mo_illegal_opcode(dev, cdb[0]); break; } #if 0 - mo_log("MO %i: Phase: %02X, request length: %i\n", dev->id, dev->tf->phase, dev->tf->request_length); + mo_log(dev->log, "Phase: %02X, request length: %i\n", + dev->tf->phase, dev->tf->request_length); #endif if ((dev->packet_status == PHASE_COMPLETE) || (dev->packet_status == PHASE_ERROR)) @@ -1891,22 +1828,16 @@ mo_command_stop(scsi_common_t *sc) static uint8_t mo_phase_data_out(scsi_common_t *sc) { - mo_t *dev = (mo_t *) sc; - - uint16_t block_desc_len; - uint16_t pos; - uint16_t param_list_len; - - uint8_t error = 0; - uint8_t page; - uint8_t page_len; - - uint8_t hdr_len; - uint8_t val; - uint8_t old_val; - uint8_t ch; - - int len = 0; + mo_t * dev = (mo_t *) sc; + const uint32_t last_sector = mo_types[dev->drv->type].sectors - 1; + int len = 0; + uint8_t error = 0; + uint32_t last_to_write; + uint16_t block_desc_len; + uint16_t pos; + uint16_t param_list_len; + uint8_t hdr_len; + uint8_t val; switch (dev->current_cdb[0]) { case GPCMD_VERIFY_6: @@ -1919,7 +1850,40 @@ mo_phase_data_out(scsi_common_t *sc) case GPCMD_WRITE_12: case GPCMD_WRITE_AND_VERIFY_12: if (dev->requested_blocks > 0) - mo_blocks(dev, &len, 1, 1); + mo_blocks(dev, &len, 1); + break; + case GPCMD_WRITE_SAME_10: + if (!dev->current_cdb[7] && !dev->current_cdb[8]) + last_to_write = last_sector; + else + last_to_write = dev->sector_pos + dev->sector_len - 1; + + for (int i = dev->sector_pos; i <= (int) last_to_write; i++) { + if (dev->current_cdb[1] & 2) { + dev->buffer[0] = (i >> 24) & 0xff; + dev->buffer[1] = (i >> 16) & 0xff; + dev->buffer[2] = (i >> 8) & 0xff; + dev->buffer[3] = i & 0xff; + } else if (dev->current_cdb[1] & 4) { + uint32_t s = (i % 63); + uint32_t h = ((i - s) / 63) % 16; + uint32_t c = ((i - s) / 63) / 16; + dev->buffer[0] = (c >> 16) & 0xff; + dev->buffer[1] = (c >> 8) & 0xff; + dev->buffer[2] = c & 0xff; + dev->buffer[3] = h & 0xff; + dev->buffer[4] = (s >> 24) & 0xff; + dev->buffer[5] = (s >> 16) & 0xff; + dev->buffer[6] = (s >> 8) & 0xff; + dev->buffer[7] = s & 0xff; + } + if (fseek(dev->drv->fp, (i * dev->drv->sector_size), SEEK_SET) == -1) + mo_write_error(dev); + if (feof(dev->drv->fp)) + break; + if (fwrite(dev->buffer, 1, dev->drv->sector_size, dev->drv->fp) != dev->drv->sector_size) + mo_write_error(dev); + } break; case GPCMD_MODE_SELECT_6: case GPCMD_MODE_SELECT_10: @@ -1950,27 +1914,27 @@ mo_phase_data_out(scsi_common_t *sc) while (1) { if (pos >= param_list_len) { - mo_log("MO %i: Buffer has only block descriptor\n", dev->id); + mo_log(dev->log, "Buffer has only block descriptor\n"); break; } - page = dev->buffer[pos] & 0x3F; - page_len = dev->buffer[pos + 1]; + const uint8_t page = dev->buffer[pos] & 0x3F; + const uint8_t page_len = dev->buffer[pos + 1]; pos += 2; if (!(mo_mode_sense_page_flags & (1LL << ((uint64_t) page)))) error |= 1; - else { - for (uint8_t i = 0; i < page_len; i++) { - ch = mo_mode_sense_pages_changeable.pages[page][i + 2]; - val = dev->buffer[pos + i]; - old_val = dev->ms_pages_saved.pages[page][i + 2]; - if (val != old_val) { - if (ch) - dev->ms_pages_saved.pages[page][i + 2] = val; - else - error |= 1; + else for (uint8_t i = 0; i < page_len; i++) { + const uint8_t ch = mo_mode_sense_pages_changeable.pages[page][i + 2]; + const uint8_t old_val = dev->ms_pages_saved.pages[page][i + 2]; + val = dev->buffer[pos + i]; + if (val != old_val) { + if (ch) + dev->ms_pages_saved.pages[page][i + 2] = val; + else { + error |= 1; + mo_invalid_field_pl(dev, val); } } } @@ -1990,7 +1954,6 @@ mo_phase_data_out(scsi_common_t *sc) if (error) { mo_buf_free(dev); - mo_invalid_field_pl(dev); return 0; } break; @@ -2012,7 +1975,7 @@ mo_global_init(void) } static int -mo_get_max(int ide_has_dma, int type) +mo_get_max(UNUSED(const ide_t *ide), const int ide_has_dma, const int type) { int ret; @@ -2036,7 +1999,7 @@ mo_get_max(int ide_has_dma, int type) } static int -mo_get_timings(int ide_has_dma, int type) +mo_get_timings(UNUSED(const ide_t *ide), const int ide_has_dma, const int type) { int ret; @@ -2059,7 +2022,7 @@ mo_get_timings(int ide_has_dma, int type) } static void -mo_do_identify(ide_t *ide, int ide_has_dma) +mo_do_identify(const ide_t *ide, const int ide_has_dma) { char model[40]; @@ -2068,56 +2031,65 @@ mo_do_identify(ide_t *ide, int ide_has_dma) memset(model, 0, 40); if (mo_drives[mo->id].type > 0) { - snprintf(model, 40, "%s %s", mo_drive_types[mo_drives[mo->id].type].vendor, mo_drive_types[mo_drives[mo->id].type].model); - ide_padstr((char *) (ide->buffer + 23), mo_drive_types[mo_drives[mo->id].type].revision, 8); /* Firmware */ + snprintf(model, 40, "%s %s", mo_drive_types[mo_drives[mo->id].type].vendor, + mo_drive_types[mo_drives[mo->id].type].model); + /* Firmware */ + ide_padstr((char *) (ide->buffer + 23), + mo_drive_types[mo_drives[mo->id].type].revision, 8); ide_padstr((char *) (ide->buffer + 27), model, 40); /* Model */ } else { snprintf(model, 40, "%s %s%02i", EMU_NAME, "86B_MO", mo->id); - ide_padstr((char *) (ide->buffer + 23), EMU_VERSION_EX, 8); /* Firmware */ - ide_padstr((char *) (ide->buffer + 27), model, 40); /* Model */ + ide_padstr((char *) (ide->buffer + 23), EMU_VERSION_EX, 8); /* Firmware */ + ide_padstr((char *) (ide->buffer + 27), model, 40); /* Model */ } if (ide_has_dma) { - ide->buffer[80] = 0x70; /*Supported ATA versions : ATA/ATAPI-4 ATA/ATAPI-6*/ - ide->buffer[81] = 0x19; /*Maximum ATA revision supported : ATA/ATAPI-6 T13 1410D revision 3a*/ + /* Supported ATA versions : ATA/ATAPI-4 ATA/ATAPI-6 */ + ide->buffer[80] = 0x70; + /* Maximum ATA revision supported : ATA/ATAPI-6 T13 1410D revision 3a */ + ide->buffer[81] = 0x19; } } static void -mo_identify(ide_t *ide, int ide_has_dma) +mo_identify(const ide_t *ide, const int ide_has_dma) { - ide->buffer[0] = 0x8000 | (0 << 8) | 0x80 | (1 << 5); /* ATAPI device, direct-access device, removable media, interrupt DRQ */ - ide_padstr((char *) (ide->buffer + 10), "", 20); /* Serial Number */ - ide->buffer[49] = 0x200; /* LBA supported */ - ide->buffer[126] = 0xfffe; /* Interpret zero byte count limit as maximum length */ + /* ATAPI device, direct-access device, removable media, interrupt DRQ */ + ide->buffer[0] = 0x8000 | (0 << 8) | 0x80 | (1 << 5); + ide_padstr((char *) (ide->buffer + 10), "", 20); /* Serial Number */ + ide->buffer[49] = 0x200; /* LBA supported */ + /* Interpret zero byte count limit as maximum length */ + ide->buffer[126] = 0xfffe; mo_do_identify(ide, ide_has_dma); } static void -mo_drive_reset(int c) +mo_drive_reset(const int c) { - mo_t *dev; - scsi_device_t *sd; - ide_t *id; - uint8_t scsi_bus = (mo_drives[c].scsi_device_id >> 4) & 0x0f; - uint8_t scsi_id = mo_drives[c].scsi_device_id & 0x0f; + const uint8_t scsi_bus = (mo_drives[c].scsi_device_id >> 4) & 0x0f; + const uint8_t scsi_id = mo_drives[c].scsi_device_id & 0x0f; - if (!mo_drives[c].priv) { - mo_drives[c].priv = (mo_t *) malloc(sizeof(mo_t)); - memset(mo_drives[c].priv, 0, sizeof(mo_t)); + if (mo_drives[c].priv == NULL) { + mo_drives[c].priv = (mo_t *) calloc(1, sizeof(mo_t)); + mo_t *dev = (mo_t *) mo_drives[c].priv; + + char n[1024] = { 0 }; + + sprintf(n, "MO %i", c + 1); + dev->log = log_open(n); } - dev = (mo_t *) mo_drives[c].priv; + mo_t *dev = (mo_t *) mo_drives[c].priv; dev->id = c; dev->cur_lun = SCSI_LUN_USE_CDB; if (mo_drives[c].bus_type == MO_BUS_SCSI) { - if (!dev->tf) + if (dev->tf == NULL) dev->tf = (ide_tf_t *) calloc(1, sizeof(ide_tf_t)); /* SCSI MO, attach to the SCSI bus. */ - sd = &scsi_devices[scsi_bus][scsi_id]; + scsi_device_t *sd = &scsi_devices[scsi_bus][scsi_id]; sd->sc = (scsi_common_t *) dev; sd->command = mo_command; @@ -2128,7 +2100,7 @@ mo_drive_reset(int c) sd->type = SCSI_REMOVABLE_DISK; } else if (mo_drives[c].bus_type == MO_BUS_ATAPI) { /* ATAPI MO, attach to the IDE bus. */ - id = ide_get_drive(mo_drives[c].ide_channel); + ide_t *id = ide_get_drive(mo_drives[c].ide_channel); /* If the IDE channel is initialized, we attach to it, otherwise, we do nothing - it's going to be a drive that's not attached to anything. */ @@ -2155,17 +2127,11 @@ mo_drive_reset(int c) void mo_hard_reset(void) { - mo_t *dev; - uint8_t scsi_id; - uint8_t scsi_bus; - for (uint8_t c = 0; c < MO_NUM; c++) { if ((mo_drives[c].bus_type == MO_BUS_ATAPI) || (mo_drives[c].bus_type == MO_BUS_SCSI)) { - mo_log("MO hard_reset drive=%d\n", c); - if (mo_drives[c].bus_type == MO_BUS_SCSI) { - scsi_bus = (mo_drives[c].scsi_device_id >> 4) & 0x0f; - scsi_id = mo_drives[c].scsi_device_id & 0x0f; + const uint8_t scsi_bus = (mo_drives[c].scsi_device_id >> 4) & 0x0f; + const uint8_t scsi_id = mo_drives[c].scsi_device_id & 0x0f; /* Make sure to ignore any SCSI MO drive that has an out of range SCSI Bus. */ if (scsi_bus >= SCSI_BUS_MAX) @@ -2182,7 +2148,9 @@ mo_hard_reset(void) mo_drive_reset(c); - dev = (mo_t *) mo_drives[c].priv; + mo_t *dev = (mo_t *) mo_drives[c].priv; + + mo_log(dev->log, "MO hard_reset drive=%d\n", c); if (dev->tf == NULL) continue; @@ -2193,14 +2161,16 @@ mo_hard_reset(void) mo_init(dev); if (strlen(mo_drives[c].image_path)) - mo_load(dev, mo_drives[c].image_path); + mo_load(dev, mo_drives[c].image_path, 0); mo_mode_sense_load(dev); if (mo_drives[c].bus_type == MO_BUS_SCSI) - mo_log("SCSI MO drive %i attached to SCSI ID %i\n", c, mo_drives[c].scsi_device_id); + mo_log(dev->log, "SCSI MO drive %i attached to SCSI ID %i\n", + c, mo_drives[c].scsi_device_id); else if (mo_drives[c].bus_type == MO_BUS_ATAPI) - mo_log("ATAPI MO drive %i attached to IDE channel %i\n", c, mo_drives[c].ide_channel); + mo_log(dev->log, "ATAPI MO drive %i attached to IDE channel %i\n", + c, mo_drives[c].ide_channel); } } } @@ -2208,19 +2178,15 @@ mo_hard_reset(void) void mo_close(void) { - mo_t *dev; - uint8_t scsi_id; - uint8_t scsi_bus; - for (uint8_t c = 0; c < MO_NUM; c++) { if (mo_drives[c].bus_type == MO_BUS_SCSI) { - scsi_bus = (mo_drives[c].scsi_device_id >> 4) & 0x0f; - scsi_id = mo_drives[c].scsi_device_id & 0x0f; + const uint8_t scsi_bus = (mo_drives[c].scsi_device_id >> 4) & 0x0f; + const uint8_t scsi_id = mo_drives[c].scsi_device_id & 0x0f; memset(&scsi_devices[scsi_bus][scsi_id], 0x00, sizeof(scsi_device_t)); } - dev = (mo_t *) mo_drives[c].priv; + mo_t *dev = (mo_t *) mo_drives[c].priv; if (dev) { mo_disk_unload(dev); @@ -2228,6 +2194,13 @@ mo_close(void) if (dev->tf) free(dev->tf); + if (dev->log != NULL) { + mo_log(dev->log, "Log closed\n"); + + log_close(dev->log); + dev->log = NULL; + } + free(dev); mo_drives[c].priv = NULL; } diff --git a/src/disk/zip.c b/src/disk/zip.c index 4a5a9b968..72781281a 100644 --- a/src/disk/zip.c +++ b/src/disk/zip.c @@ -9,30 +9,27 @@ * Implementation of the Iomega ZIP drive with SCSI(-like) * commands, for both ATAPI and SCSI usage. * - * - * * Authors: Miran Grca, * - * Copyright 2018-2019 Miran Grca. + * Copyright 2018-2025 Miran Grca. */ -#include -#include -#include -#include +#ifdef ENABLE_ZIP_LOG #include -#include -#define HAVE_STDARG_H +#endif +#include +#include +#include +#include #include <86box/86box.h> #include <86box/timer.h> -#include <86box/config.h> -#include <86box/timer.h> #include <86box/device.h> +#include <86box/log.h> #include <86box/scsi.h> #include <86box/scsi_device.h> #include <86box/nvr.h> +#include <86box/path.h> #include <86box/plat.h> #include <86box/ui.h> -#include <86box/hdc.h> #include <86box/hdc_ide.h> #include <86box/zip.h> @@ -40,402 +37,107 @@ zip_drive_t zip_drives[ZIP_NUM]; -/* Table of all SCSI commands and their flags, needed for the new disc change / not ready handler. */ +// clang-format off +/* + Table of all SCSI commands and their flags, needed for the new disc change / + not ready handler. + */ const uint8_t zip_command_flags[0x100] = { - IMPLEMENTED | CHECK_READY | NONDATA, /* 0x00 */ - IMPLEMENTED | ALLOW_UA | NONDATA | SCSI_ONLY, /* 0x01 */ - 0, - IMPLEMENTED | ALLOW_UA, /* 0x03 */ - IMPLEMENTED | CHECK_READY | ALLOW_UA | NONDATA | SCSI_ONLY, /* 0x04 */ - 0, - IMPLEMENTED, /* 0x06 */ - 0, - IMPLEMENTED | CHECK_READY, /* 0x08 */ - 0, - IMPLEMENTED | CHECK_READY, /* 0x0A */ - IMPLEMENTED | CHECK_READY | NONDATA, /* 0x0B */ - IMPLEMENTED, /* 0x0C */ - IMPLEMENTED | ATAPI_ONLY, /* 0x0D */ - 0, 0, 0, 0, - IMPLEMENTED | ALLOW_UA, /* 0x12 */ - IMPLEMENTED | CHECK_READY | NONDATA | SCSI_ONLY, /* 0x13 */ - 0, - IMPLEMENTED, /* 0x15 */ - IMPLEMENTED | SCSI_ONLY, /* 0x16 */ - IMPLEMENTED | SCSI_ONLY, /* 0x17 */ - 0, 0, - IMPLEMENTED, /* 0x1A */ - IMPLEMENTED | CHECK_READY, /* 0x1B */ - 0, - IMPLEMENTED, /* 0x1D */ - IMPLEMENTED | CHECK_READY, /* 0x1E */ - 0, 0, 0, 0, - IMPLEMENTED | ATAPI_ONLY, /* 0x23 */ - 0, - IMPLEMENTED | CHECK_READY, /* 0x25 */ - 0, 0, - IMPLEMENTED | CHECK_READY, /* 0x28 */ - 0, - IMPLEMENTED | CHECK_READY, /* 0x2A */ - IMPLEMENTED | CHECK_READY | NONDATA, /* 0x2B */ - 0, 0, - IMPLEMENTED | CHECK_READY, /* 0x2E */ - IMPLEMENTED | CHECK_READY | NONDATA | SCSI_ONLY, /* 0x2F */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, - IMPLEMENTED | CHECK_READY, /* 0x41 */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, - IMPLEMENTED, /* 0x55 */ - 0, 0, 0, 0, - IMPLEMENTED, /* 0x5A */ - 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - IMPLEMENTED | CHECK_READY, /* 0xA8 */ - 0, - IMPLEMENTED | CHECK_READY, /* 0xAA */ - 0, 0, 0, - IMPLEMENTED | CHECK_READY, /* 0xAE */ - IMPLEMENTED | CHECK_READY | NONDATA | SCSI_ONLY, /* 0xAF */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - IMPLEMENTED, /* 0xBD */ - 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 + [0x00] = IMPLEMENTED | CHECK_READY, + [0x01] = IMPLEMENTED | ALLOW_UA | SCSI_ONLY, + [0x03] = IMPLEMENTED | ALLOW_UA, + [0x04] = IMPLEMENTED | CHECK_READY | ALLOW_UA | SCSI_ONLY, + [0x06] = IMPLEMENTED, + [0x08] = IMPLEMENTED | CHECK_READY, + [0x0a ... 0x0b] = IMPLEMENTED | CHECK_READY, + [0x0c] = IMPLEMENTED, + [0x0d] = IMPLEMENTED | ATAPI_ONLY, + [0x12] = IMPLEMENTED | ALLOW_UA, + [0x13] = IMPLEMENTED | CHECK_READY | SCSI_ONLY, + [0x15] = IMPLEMENTED, + [0x16 ... 0x17] = IMPLEMENTED | SCSI_ONLY, + [0x1a] = IMPLEMENTED, + [0x1b] = IMPLEMENTED | CHECK_READY, + [0x1d] = IMPLEMENTED, + [0x1e] = IMPLEMENTED | CHECK_READY, + [0x23] = IMPLEMENTED | ATAPI_ONLY, + [0x25] = IMPLEMENTED | CHECK_READY, + [0x28] = IMPLEMENTED | CHECK_READY, + [0x2a ... 0x2b] = IMPLEMENTED | CHECK_READY, + [0x2e] = IMPLEMENTED | CHECK_READY, + [0x2f] = IMPLEMENTED | CHECK_READY | SCSI_ONLY, + [0x41] = IMPLEMENTED | CHECK_READY, + [0x55] = IMPLEMENTED, + [0x5a] = IMPLEMENTED, + [0xa8] = IMPLEMENTED | CHECK_READY, + [0xaa] = IMPLEMENTED | CHECK_READY, + [0xae] = IMPLEMENTED | CHECK_READY, + [0xaf] = IMPLEMENTED | CHECK_READY | SCSI_ONLY, + [0xbd] = IMPLEMENTED }; -static uint64_t zip_mode_sense_page_flags = (GPMODEP_R_W_ERROR_PAGE | GPMODEP_DISCONNECT_PAGE | GPMODEP_IOMEGA_PAGE | GPMODEP_ALL_PAGES); -static uint64_t zip_250_mode_sense_page_flags = (GPMODEP_R_W_ERROR_PAGE | GPMODEP_FLEXIBLE_DISK_PAGE | GPMODEP_CACHING_PAGE | GPMODEP_IOMEGA_PAGE | GPMODEP_ALL_PAGES); +static uint64_t zip_mode_sense_page_flags = (GPMODEP_R_W_ERROR_PAGE | GPMODEP_DISCONNECT_PAGE | + GPMODEP_IOMEGA_PAGE | GPMODEP_ALL_PAGES); +static uint64_t zip_250_mode_sense_page_flags = (GPMODEP_R_W_ERROR_PAGE | GPMODEP_FLEXIBLE_DISK_PAGE | + GPMODEP_CACHING_PAGE | GPMODEP_IOMEGA_PAGE | + GPMODEP_ALL_PAGES); -static const mode_sense_pages_t zip_mode_sense_pages_default = - // clang-format off -{ { - { 0, 0 }, - { GPMODE_R_W_ERROR_PAGE, 0x0a, 0xc8, 22, 0, 0, 0, 0, 90, 0, 0x50, 0x20 }, - { GPMODE_DISCONNECT_PAGE, 0x0e, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { GPMODE_IOMEGA_PAGE, 0x04, 0x5c, 0x0f, 0xff, 0x0f } -} }; -// clang-format on +static const mode_sense_pages_t zip_mode_sense_pages_default = { + { [0x01] = { GPMODE_R_W_ERROR_PAGE, 0x0a, 0xc8, 0x16, 0x00, 0x00, 0x00, 0x00, + 0x5a, 0x00, 0x50, 0x20 }, + [0x02] = { GPMODE_DISCONNECT_PAGE, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, + [0x2f] = { GPMODE_IOMEGA_PAGE, 0x04, 0x5c, 0x0f, 0xff, 0x0f } } +}; -static const mode_sense_pages_t zip_250_mode_sense_pages_default = - // clang-format off -{ { - { 0, 0 }, - { GPMODE_R_W_ERROR_PAGE, 0x06, 0xc8, 0x64, 0, 0, 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - {GPMODE_FLEXIBLE_DISK_PAGE, 0x1e, 0x80, 0, 0x40, 0x20, 2, 0, 0, 0xef, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x0b, 0x7d, 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { GPMODE_CACHING_PAGE, 0x0a, 4, 0, 0xff, 0xff, 0, 0, 0xff, 0xff, 0xff, 0xff }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { GPMODE_IOMEGA_PAGE, 0x04, 0x5c, 0x0f, 0x3c, 0x0f } -} }; -// clang-format on +static const mode_sense_pages_t zip_250_mode_sense_pages_default = { + { [0x01] = { GPMODE_R_W_ERROR_PAGE, 0x06, 0xc8, 0x64, 0x00, 0x00, 0x00, 0x00 }, + [0x05] = { GPMODE_FLEXIBLE_DISK_PAGE, 0x1e, 0x80, 0x00, 0x40, 0x20, 0x02, 0x00, + 0x00, 0xef, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x0b, 0x7d, 0x00, 0x00 }, + [0x08] = { GPMODE_CACHING_PAGE, 0x0a, 0x04, 0x00, 0xff, 0xff, 0x00, 0x00, + 0xff, 0xff, 0xff, 0xff }, + [0x2f] = { GPMODE_IOMEGA_PAGE, 0x04, 0x5c, 0x0f, 0x3c, 0x0f } } +}; -static const mode_sense_pages_t zip_mode_sense_pages_default_scsi = - // clang-format off -{ { - { 0, 0 }, - { GPMODE_R_W_ERROR_PAGE, 0x0a, 0xc8, 22, 0, 0, 0, 0, 90, 0, 0x50, 0x20 }, - { GPMODE_DISCONNECT_PAGE, 0x0e, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { GPMODE_IOMEGA_PAGE, 0x04, 0x5c, 0x0f, 0xff, 0x0f } -} }; -// clang-format on +static const mode_sense_pages_t zip_mode_sense_pages_default_scsi = { + { [0x01] = { GPMODE_R_W_ERROR_PAGE, 0x0a, 0xc8, 0x16, 0x00, 0x00, 0x00, 0x00, + 0x5a, 0x00, 0x50, 0x20 }, + [0x02] = { GPMODE_DISCONNECT_PAGE, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, + [0x2f] = { GPMODE_IOMEGA_PAGE, 0x04, 0x5c, 0x0f, 0xff, 0x0f } } +}; -static const mode_sense_pages_t zip_250_mode_sense_pages_default_scsi = - // clang-format off -{ { - { 0, 0 }, - { GPMODE_R_W_ERROR_PAGE, 0x06, 0xc8, 0x64, 0, 0, 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - {GPMODE_FLEXIBLE_DISK_PAGE, 0x1e, 0x80, 0, 0x40, 0x20, 2, 0, 0, 0xef, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x0b, 0x7d, 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { GPMODE_CACHING_PAGE, 0x0a, 4, 0, 0xff, 0xff, 0, 0, 0xff, 0xff, 0xff, 0xff }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { GPMODE_IOMEGA_PAGE, 0x04, 0x5c, 0x0f, 0x3c, 0x0f } -} }; -// clang-format on +static const mode_sense_pages_t zip_250_mode_sense_pages_default_scsi = { + { [0x01] = { GPMODE_R_W_ERROR_PAGE, 0x06, 0xc8, 0x64, 0x00, 0x00, 0x00, 0x00 }, + [0x05] = { GPMODE_FLEXIBLE_DISK_PAGE, 0x1e, 0x80, 0x00, 0x40, 0x20, 0x02, 0x00, + 0x00, 0xef, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x0b, 0x7d, 0x00, 0x00 }, + [0x08] = { GPMODE_CACHING_PAGE, 0x0a, 0x04, 0x00, 0xff, 0xff, 0x00, 0x00, + 0xff, 0xff, 0xff, 0xff }, + [0x2f] = { GPMODE_IOMEGA_PAGE, 0x04, 0x5c, 0x0f, 0x3c, 0x0f } } +}; -static const mode_sense_pages_t zip_mode_sense_pages_changeable = - // clang-format off -{ { - { 0, 0 }, +static const mode_sense_pages_t zip_mode_sense_pages_changeable = { + { [0x01] = { GPMODE_R_W_ERROR_PAGE, 0x0a, 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, + 0x5a, 0xff, 0xff, 0xff }, + [0x02] = { GPMODE_DISCONNECT_PAGE, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, + [0x2f] = { GPMODE_IOMEGA_PAGE, 0x04, 0xff, 0xff, 0xff, 0xff } } +}; - { GPMODE_R_W_ERROR_PAGE, 0x0a, 0xFF, 0xFF, 0, 0, 0, 0, 0xFF, 0xFF, 0xFF, 0xFF }, - { GPMODE_DISCONNECT_PAGE, 0x0e, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { GPMODE_IOMEGA_PAGE, 0x04, 0xff, 0xff, 0xff, 0xff } -} }; -// clang-format on - -static const mode_sense_pages_t zip_250_mode_sense_pages_changeable = - // clang-format off -{ { - { 0, 0 }, - { GPMODE_R_W_ERROR_PAGE, 0x06, 0xFF, 0xFF, 0, 0, 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - {GPMODE_FLEXIBLE_DISK_PAGE, 0x1e, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { GPMODE_CACHING_PAGE, 0x0a, 4, 0, 0xff, 0xff, 0, 0, 0xff, 0xff, 0xff, 0xff }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { GPMODE_IOMEGA_PAGE, 0x04, 0xff, 0xff, 0xff, 0xff } -} }; +static const mode_sense_pages_t zip_250_mode_sense_pages_changeable = { + { [0x01] = { GPMODE_R_W_ERROR_PAGE, 0x06, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 }, + [0x05] = { GPMODE_FLEXIBLE_DISK_PAGE, 0x1e, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00 }, + [0x08] = { GPMODE_CACHING_PAGE, 0x0a, 0x04, 0x00, 0xff, 0xff, 0x00, 0x00, + 0xff, 0xff, 0xff, 0xff }, + [0x2f] = { GPMODE_IOMEGA_PAGE, 0x04, 0xff, 0xff, 0xff, 0xff } } +}; // clang-format on static void zip_command_complete(zip_t *dev); @@ -445,32 +147,22 @@ static void zip_init(zip_t *dev); int zip_do_log = ENABLE_ZIP_LOG; static void -zip_log(const char *fmt, ...) +zip_log(void *priv, const char *fmt, ...) { va_list ap; if (zip_do_log) { va_start(ap, fmt); - pclog_ex(fmt, ap); + log_out(priv, fmt, ap); va_end(ap); } } #else -# define zip_log(fmt, ...) +# define zip_log(priv, fmt, ...) #endif -int -find_zip_for_channel(uint8_t channel) -{ - for (uint8_t i = 0; i < ZIP_NUM; i++) { - if ((zip_drives[i].bus_type == ZIP_BUS_ATAPI) && (zip_drives[i].ide_channel == channel)) - return i; - } - return 0xff; -} - static int -zip_load_abort(zip_t *dev) +zip_load_abort(const zip_t *dev) { if (dev->drv->fp) fclose(dev->drv->fp); @@ -481,104 +173,140 @@ zip_load_abort(zip_t *dev) } int -zip_load(zip_t *dev, char *fn) +image_is_zdi(const char *s) { - int size = 0; + return !strcasecmp(path_get_extension((char *) s), "ZDI"); +} - if (!dev->drv) { +int +zip_is_empty(const uint8_t id) +{ + const zip_t *dev = (const zip_t *) zip_drives[id].priv; + int ret = 0; + + if ((dev->drv == NULL) || (dev->drv->fp == NULL)) + ret = 1; + + return ret; +} + +void +zip_load(const zip_t *dev, const char *fn, const int skip_insert) +{ + const int was_empty = zip_is_empty(dev->id); + int ret = 0; + + if (dev->drv == NULL) zip_eject(dev->id); - return 0; - } + else { + const int is_zdi = image_is_zdi(fn); - dev->drv->fp = plat_fopen(fn, dev->drv->read_only ? "rb" : "rb+"); - if (!dev->drv->fp) { - if (!dev->drv->read_only) { - dev->drv->fp = plat_fopen(fn, "rb"); - if (dev->drv->fp) - dev->drv->read_only = 1; - else - return zip_load_abort(dev); - } else - return zip_load_abort(dev); - } + dev->drv->fp = plat_fopen(fn, dev->drv->read_only ? "rb" : "rb+"); + ret = 1; - fseek(dev->drv->fp, 0, SEEK_END); - size = ftell(dev->drv->fp); - - if ((size == ((ZIP_250_SECTORS << 9) + 0x1000)) || (size == ((ZIP_SECTORS << 9) + 0x1000))) { - /* This is a ZDI image. */ - size -= 0x1000; - dev->drv->base = 0x1000; - } else - dev->drv->base = 0; - - if (dev->drv->is_250) { - if ((size != (ZIP_250_SECTORS << 9)) && (size != (ZIP_SECTORS << 9))) { - zip_log("File is incorrect size for a ZIP image\nMust be exactly %i or %i bytes\n", - ZIP_250_SECTORS << 9, ZIP_SECTORS << 9); - return zip_load_abort(dev); + if (dev->drv->fp == NULL) { + if (!dev->drv->read_only) { + dev->drv->fp = plat_fopen(fn, "rb"); + if (dev->drv->fp == NULL) + ret = zip_load_abort(dev); + else + dev->drv->read_only = 1; + } else + ret = zip_load_abort(dev); } - } else { - if (size != (ZIP_SECTORS << 9)) { - zip_log("File is incorrect size for a ZIP image\nMust be exactly %i bytes\n", - ZIP_SECTORS << 9); - return zip_load_abort(dev); + + if (ret) { + fseek(dev->drv->fp, 0, SEEK_END); + int size = ftell(dev->drv->fp); + + if (is_zdi) { + /* This is a ZDI image. */ + size -= 0x1000; + dev->drv->base = 0x1000; + } else + dev->drv->base = 0; + + if (dev->drv->is_250) { + if ((size != (ZIP_250_SECTORS << 9)) && (size != (ZIP_SECTORS << 9))) { + zip_log(dev->log, "File is incorrect size for a ZIP image\n"); + zip_log(dev->log, "Must be exactly %i or %i bytes\n", + ZIP_250_SECTORS << 9, ZIP_SECTORS << 9); + ret = zip_load_abort(dev); + } + } else if (size != (ZIP_SECTORS << 9)) { + zip_log(dev->log, "File is incorrect size for a ZIP image\n"); + zip_log(dev->log, "Must be exactly %i bytes\n", ZIP_SECTORS << 9); + ret = zip_load_abort(dev); + } + + if (ret) + dev->drv->medium_size = size >> 9; + } + + if (ret) { + if (fseek(dev->drv->fp, dev->drv->base, SEEK_SET) == -1) + log_fatal(dev->log, "zip_load(): Error seeking to the beginning of " + "the file\n"); + + strncpy(dev->drv->image_path, fn, sizeof(dev->drv->image_path) - 1); + /* + After using strncpy, dev->drv->image_path needs to be explicitly null + terminated to make gcc happy. + In the event strlen(dev->drv->image_path) == sizeof(dev->drv->image_path) + (no null terminator) it is placed at the very end. Otherwise, it is placed + right after the string. + */ + const size_t term = strlen(dev->drv->image_path) == + sizeof(dev->drv->image_path) ? sizeof(dev->drv->image_path) - 1 : + strlen(dev->drv->image_path); + dev->drv->image_path[term] = '\0'; } } - dev->drv->medium_size = size >> 9; + if (ret && !skip_insert) { + /* Signal media change to the emulated machine. */ + zip_insert((zip_t *) dev); - if (fseek(dev->drv->fp, dev->drv->base, SEEK_SET) == -1) - fatal("zip_load(): Error seeking to the beginning of the file\n"); - - strncpy(dev->drv->image_path, fn, sizeof(dev->drv->image_path) - 1); - // After using strncpy, dev->drv->image_path needs to be explicitly null terminated to make gcc happy. - // In the event strlen(dev->drv->image_path) == sizeof(dev->drv->image_path) (no null terminator) - // it is placed at the very end. Otherwise, it is placed right after the string. - const size_t term = strlen(dev->drv->image_path) == sizeof(dev->drv->image_path) ? sizeof(dev->drv->image_path) - 1 : strlen(dev->drv->image_path); - dev->drv->image_path[term] = '\0'; - - return 1; + /* The drive was previously empty, transition directly to UNIT ATTENTION. */ + if (was_empty) + zip_insert((zip_t *) dev); + } } void -zip_disk_reload(zip_t *dev) +zip_disk_reload(const zip_t *dev) { - int ret = 0; - - if (strlen(dev->drv->prev_image_path) == 0) - return; - else - ret = zip_load(dev, dev->drv->prev_image_path); - - if (ret) - dev->unit_attention = 1; + if (strlen(dev->drv->prev_image_path) != 0) + (void) zip_load(dev, dev->drv->prev_image_path, 0); } -void -zip_disk_unload(zip_t *dev) +static void +zip_disk_unload(const zip_t *dev) { - if (dev->drv && dev->drv->fp) { + if ((dev->drv != NULL) && (dev->drv->fp != NULL)) { fclose(dev->drv->fp); dev->drv->fp = NULL; } } void -zip_disk_close(zip_t *dev) +zip_disk_close(const zip_t *dev) { - if (dev->drv && dev->drv->fp) { + if ((dev->drv != NULL) && (dev->drv->fp != NULL)) { zip_disk_unload(dev); - memcpy(dev->drv->prev_image_path, dev->drv->image_path, sizeof(dev->drv->prev_image_path)); + memcpy(dev->drv->prev_image_path, dev->drv->image_path, + sizeof(dev->drv->prev_image_path)); memset(dev->drv->image_path, 0, sizeof(dev->drv->image_path)); dev->drv->medium_size = 0; + + zip_insert((zip_t *) dev); } } static void -zip_set_callback(zip_t *dev) +zip_set_callback(const zip_t *dev) { if (dev->drv->bus_type != ZIP_BUS_SCSI) ide_set_callback(ide_drives[dev->drv->ide_channel], dev->callback); @@ -587,54 +315,54 @@ zip_set_callback(zip_t *dev) static void zip_init(zip_t *dev) { - if (dev->id >= ZIP_NUM) - return; - - dev->requested_blocks = 1; - dev->sense[0] = 0xf0; - dev->sense[7] = 10; - dev->drv->bus_mode = 0; - if (dev->drv->bus_type >= ZIP_BUS_ATAPI) - dev->drv->bus_mode |= 2; - if (dev->drv->bus_type < ZIP_BUS_SCSI) - dev->drv->bus_mode |= 1; - zip_log("ZIP %i: Bus type %i, bus mode %i\n", dev->id, dev->drv->bus_type, dev->drv->bus_mode); - if (dev->drv->bus_type < ZIP_BUS_SCSI) { - dev->tf->phase = 1; - dev->tf->request_length = 0xEB14; + if (dev->id < ZIP_NUM) { + dev->requested_blocks = 1; + dev->sense[0] = 0xf0; + dev->sense[7] = 10; + dev->drv->bus_mode = 0; + if (dev->drv->bus_type >= ZIP_BUS_ATAPI) + dev->drv->bus_mode |= 2; + if (dev->drv->bus_type < ZIP_BUS_SCSI) + dev->drv->bus_mode |= 1; + zip_log(dev->log, "Bus type %i, bus mode %i\n", dev->drv->bus_type, dev->drv->bus_mode); + if (dev->drv->bus_type < ZIP_BUS_SCSI) { + dev->tf->phase = 1; + dev->tf->request_length = 0xEB14; + } + dev->tf->status = READY_STAT | DSC_STAT; + dev->tf->pos = 0; + dev->packet_status = PHASE_NONE; + zip_sense_key = zip_asc = zip_ascq = dev->unit_attention = dev->transition = 0; + zip_info = 0x00000000; } - dev->tf->status = READY_STAT | DSC_STAT; - dev->tf->pos = 0; - dev->packet_status = PHASE_NONE; - zip_sense_key = zip_asc = zip_ascq = dev->unit_attention = 0; } static int -zip_supports_pio(zip_t *dev) +zip_supports_pio(const zip_t *dev) { return (dev->drv->bus_mode & 1); } static int -zip_supports_dma(zip_t *dev) +zip_supports_dma(const zip_t *dev) { return (dev->drv->bus_mode & 2); } /* Returns: 0 for none, 1 for PIO, 2 for DMA. */ static int -zip_current_mode(zip_t *dev) +zip_current_mode(const zip_t *dev) { if (!zip_supports_pio(dev) && !zip_supports_dma(dev)) return 0; if (zip_supports_pio(dev) && !zip_supports_dma(dev)) { - zip_log("ZIP %i: Drive does not support DMA, setting to PIO\n", dev->id); + zip_log(dev->log, "Drive does not support DMA, setting to PIO\n"); return 1; } if (!zip_supports_pio(dev) && zip_supports_dma(dev)) return 2; if (zip_supports_pio(dev) && zip_supports_dma(dev)) { - zip_log("ZIP %i: Drive supports both, setting to %s\n", dev->id, + zip_log(dev->log, "Drive supports both, setting to %s\n", (dev->tf->features & 1) ? "DMA" : "PIO"); return (dev->tf->features & 1) ? 2 : 1; } @@ -645,8 +373,7 @@ zip_current_mode(zip_t *dev) static void zip_mode_sense_load(zip_t *dev) { - FILE *fp; - char fn[512]; + char fn[512] = { 0 }; memset(&dev->ms_pages_saved, 0, sizeof(mode_sense_pages_t)); if (dev->drv->is_250) { @@ -661,12 +388,11 @@ zip_mode_sense_load(zip_t *dev) memcpy(&dev->ms_pages_saved, &zip_mode_sense_pages_default, sizeof(mode_sense_pages_t)); } - memset(fn, 0, 512); if (dev->drv->bus_type == ZIP_BUS_SCSI) sprintf(fn, "scsi_zip_%02i_mode_sense_bin", dev->id); else sprintf(fn, "zip_%02i_mode_sense_bin", dev->id); - fp = plat_fopen(nvr_path(fn), "rb"); + FILE *fp = plat_fopen(nvr_path(fn), "rb"); if (fp) { /* Nothing to read, not used by ZIP. */ fclose(fp); @@ -674,31 +400,31 @@ zip_mode_sense_load(zip_t *dev) } static void -zip_mode_sense_save(zip_t *dev) +zip_mode_sense_save(const zip_t *dev) { - FILE *fp; - char fn[512]; + char fn[512] = { 0 }; - memset(fn, 0, 512); if (dev->drv->bus_type == ZIP_BUS_SCSI) sprintf(fn, "scsi_zip_%02i_mode_sense_bin", dev->id); else sprintf(fn, "zip_%02i_mode_sense_bin", dev->id); - fp = plat_fopen(nvr_path(fn), "wb"); + FILE *fp = plat_fopen(nvr_path(fn), "wb"); if (fp) { /* Nothing to write, not used by ZIP. */ fclose(fp); } } -/*SCSI Mode Sense 6/10*/ +/* SCSI Mode Sense 6/10. */ static uint8_t -zip_mode_sense_read(zip_t *dev, uint8_t page_control, uint8_t page, uint8_t pos) +zip_mode_sense_read(const zip_t *dev, const uint8_t pgctl, + const uint8_t page, const uint8_t pos) { - switch (page_control) { + switch (pgctl) { case 0: case 3: - if (dev->drv->is_250 && (page == 5) && (pos == 9) && (dev->drv->medium_size == ZIP_SECTORS)) + if (dev->drv->is_250 && (page == 5) && (pos == 9) && + (dev->drv->medium_size == ZIP_SECTORS)) return 0x60; return dev->ms_pages_saved.pages[page][pos]; case 1: @@ -729,18 +455,17 @@ zip_mode_sense_read(zip_t *dev, uint8_t page_control, uint8_t page, uint8_t pos) } static uint32_t -zip_mode_sense(zip_t *dev, uint8_t *buf, uint32_t pos, uint8_t page, uint8_t block_descriptor_len) +zip_mode_sense(const zip_t *dev, uint8_t *buf, uint32_t pos, + uint8_t page, const uint8_t block_descriptor_len) { - uint64_t pf; - uint8_t page_control = (page >> 6) & 3; + uint64_t pf; + const uint8_t pgctl = (page >> 6) & 3; if (dev->drv->is_250) pf = zip_250_mode_sense_page_flags; else pf = zip_mode_sense_page_flags; - uint8_t msplen; - page &= 0x3f; if (block_descriptor_len) { @@ -757,12 +482,12 @@ zip_mode_sense(zip_t *dev, uint8_t *buf, uint32_t pos, uint8_t page, uint8_t blo for (uint8_t i = 0; i < 0x40; i++) { if ((page == GPMODE_ALL_PAGES) || (page == i)) { if (pf & (1LL << ((uint64_t) page))) { - buf[pos++] = zip_mode_sense_read(dev, page_control, i, 0); - msplen = zip_mode_sense_read(dev, page_control, i, 1); - buf[pos++] = msplen; - zip_log("ZIP %i: MODE SENSE: Page [%02X] length %i\n", dev->id, i, msplen); + const uint8_t msplen = zip_mode_sense_read(dev, pgctl, i, 1); + buf[pos++] = zip_mode_sense_read(dev, pgctl, i, 0); + buf[pos++] = msplen; + zip_log(dev->log, "MODE SENSE: Page [%02X] length %i\n", i, msplen); for (uint8_t j = 0; j < msplen; j++) - buf[pos++] = zip_mode_sense_read(dev, page_control, i, 2 + j); + buf[pos++] = zip_mode_sense_read(dev, pgctl, i, 2 + j); } } } @@ -778,7 +503,10 @@ zip_update_request_length(zip_t *dev, int len, int block_len) dev->max_transfer_len = dev->tf->request_length; - /* For media access commands, make sure the requested DRQ length matches the block length. */ + /* + For media access commands, make sure the requested DRQ length matches the + block length. + */ switch (dev->current_cdb[0]) { case 0x08: case 0x0a: @@ -789,8 +517,10 @@ zip_update_request_length(zip_t *dev, int len, int block_len) /* Round it to the nearest 2048 bytes. */ dev->max_transfer_len = (dev->max_transfer_len >> 9) << 9; - /* Make sure total length is not bigger than sum of the lengths of - all the requested blocks. */ + /* + Make sure total length is not bigger than sum of the lengths of + all the requested blocks. + */ bt = (dev->requested_blocks * block_len); if (len > bt) len = bt; @@ -812,10 +542,16 @@ zip_update_request_length(zip_t *dev, int len, int block_len) dev->packet_len = len; break; } - /* If the DRQ length is odd, and the total remaining length is bigger, make sure it's even. */ + /* + If the DRQ length is odd, and the total remaining length is bigger, + make sure it's even. + */ if ((dev->max_transfer_len & 1) && (dev->max_transfer_len < len)) dev->max_transfer_len &= 0xfffe; - /* If the DRQ length is smaller or equal in size to the total remaining length, set it to that. */ + /* + If the DRQ length is smaller or equal in size to the total remaining length, + set it to that. + */ if (!dev->max_transfer_len) dev->max_transfer_len = 65534; @@ -850,23 +586,22 @@ zip_bus_speed(zip_t *dev) static void zip_command_common(zip_t *dev) { - double bytes_per_second; - double period; - dev->tf->status = BUSY_STAT; dev->tf->phase = 1; dev->tf->pos = 0; if (dev->packet_status == PHASE_COMPLETE) dev->callback = 0.0; else { + double bytes_per_second; + if (dev->drv->bus_type == ZIP_BUS_SCSI) { dev->callback = -1.0; /* Speed depends on SCSI controller */ return; } else bytes_per_second = zip_bus_speed(dev); - period = 1000000.0 / bytes_per_second; - dev->callback = period * (double) (dev->packet_len); + double period = 1000000.0 / bytes_per_second; + dev->callback = period * (double) (dev->packet_len); } zip_set_callback(dev); @@ -907,16 +642,20 @@ zip_command_write_dma(zip_t *dev) zip_command_common(dev); } -/* id = Current ZIP device ID; +/* + dev = Pointer to current ZIP device; len = Total transfer length; block_len = Length of a single block (why does it matter?!); alloc_len = Allocated transfer length; - direction = Transfer direction (0 = read from host, 1 = write to host). */ + direction = Transfer direction (0 = read from host, 1 = write to host). + */ static void -zip_data_command_finish(zip_t *dev, int len, int block_len, int alloc_len, int direction) +zip_data_command_finish(zip_t *dev, int len, const int block_len, + const int alloc_len, const int direction) { - zip_log("ZIP %i: Finishing command (%02X): %i, %i, %i, %i, %i\n", - dev->id, dev->current_cdb[0], len, block_len, alloc_len, direction, dev->tf->request_length); + zip_log(dev->log, "Finishing command (%02X): %i, %i, %i, %i, %i\n", + dev->current_cdb[0], len, block_len, alloc_len, + direction, dev->tf->request_length); dev->tf->pos = 0; if (alloc_len >= 0) { if (alloc_len < len) @@ -945,27 +684,26 @@ zip_data_command_finish(zip_t *dev, int len, int block_len, int alloc_len, int d } } - zip_log("ZIP %i: Status: %i, cylinder %i, packet length: %i, position: %i, phase: %i\n", - dev->id, dev->packet_status, dev->tf->request_length, dev->packet_len, dev->tf->pos, - dev->tf->phase); + zip_log(dev->log, "Status: %i, cylinder %i, packet length: %i, position: %i, phase: %i\n", + dev->packet_status, dev->tf->request_length, dev->packet_len, + dev->tf->pos, dev->tf->phase); } static void zip_sense_clear(zip_t *dev, UNUSED(int command)) { zip_sense_key = zip_asc = zip_ascq = 0; + zip_info = 0x00000000; } static void -zip_set_phase(zip_t *dev, uint8_t phase) +zip_set_phase(const zip_t *dev, const uint8_t phase) { - uint8_t scsi_bus = (dev->drv->scsi_device_id >> 4) & 0x0f; - uint8_t scsi_id = dev->drv->scsi_device_id & 0x0f; + const uint8_t scsi_bus = (dev->drv->scsi_device_id >> 4) & 0x0f; + const uint8_t scsi_id = dev->drv->scsi_device_id & 0x0f; - if (dev->drv->bus_type != ZIP_BUS_SCSI) - return; - - scsi_devices[scsi_bus][scsi_id].phase = phase; + if (dev->drv->bus_type == ZIP_BUS_SCSI) + scsi_devices[scsi_bus][scsi_id].phase = phase; } static void @@ -973,8 +711,6 @@ zip_cmd_error(zip_t *dev) { zip_set_phase(dev, SCSI_PHASE_STATUS); dev->tf->error = ((zip_sense_key & 0xf) << 4) | ABRT_ERR; - if (dev->unit_attention) - dev->tf->error |= MCR_ERR; dev->tf->status = READY_STAT | ERR_STAT; dev->tf->phase = 3; dev->tf->pos = 0; @@ -982,7 +718,8 @@ zip_cmd_error(zip_t *dev) dev->callback = 50.0 * ZIP_TIME; zip_set_callback(dev); ui_sb_update_icon(SB_ZIP | dev->id, 0); - zip_log("ZIP %i: [%02X] ERROR: %02X/%02X/%02X\n", dev->id, dev->current_cdb[0], zip_sense_key, zip_asc, zip_ascq); + zip_log(dev->log, "[%02X] ERROR: %02X/%02X/%02X\n", dev->current_cdb[0], zip_sense_key, + zip_asc, zip_ascq); } static void @@ -990,8 +727,6 @@ zip_unit_attention(zip_t *dev) { zip_set_phase(dev, SCSI_PHASE_STATUS); dev->tf->error = (SENSE_UNIT_ATTENTION << 4) | ABRT_ERR; - if (dev->unit_attention) - dev->tf->error |= MCR_ERR; dev->tf->status = READY_STAT | ERR_STAT; dev->tf->phase = 3; dev->tf->pos = 0; @@ -999,22 +734,22 @@ zip_unit_attention(zip_t *dev) dev->callback = 50.0 * ZIP_TIME; zip_set_callback(dev); ui_sb_update_icon(SB_ZIP | dev->id, 0); - zip_log("ZIP %i: UNIT ATTENTION\n", dev->id); + zip_log(dev->log, "UNIT ATTENTION\n", dev->id); } static void -zip_buf_alloc(zip_t *dev, uint32_t len) +zip_buf_alloc(zip_t *dev, const uint32_t len) { - zip_log("ZIP %i: Allocated buffer length: %i\n", dev->id, len); - if (!dev->buffer) + zip_log(dev->log, "Allocated buffer length: %i\n", len); + if (dev->buffer == NULL) dev->buffer = (uint8_t *) malloc(len); } static void zip_buf_free(zip_t *dev) { - if (dev->buffer) { - zip_log("ZIP %i: Freeing buffer...\n", dev->id); + if (dev->buffer != NULL) { + zip_log(dev->log, "ZIP %i: Freeing buffer...\n"); free(dev->buffer); dev->buffer = NULL; } @@ -1027,6 +762,10 @@ zip_bus_master_error(scsi_common_t *sc) zip_buf_free(dev); zip_sense_key = zip_asc = zip_ascq = 0; + zip_info = (dev->sector_pos >> 24) | + ((dev->sector_pos >> 16) << 8) | + ((dev->sector_pos >> 8) << 16) | + ( dev->sector_pos << 24); zip_cmd_error(dev); } @@ -1036,6 +775,7 @@ zip_not_ready(zip_t *dev) zip_sense_key = SENSE_NOT_READY; zip_asc = ASC_MEDIUM_NOT_PRESENT; zip_ascq = 0; + zip_info = 0x00000000; zip_cmd_error(dev); } @@ -1045,6 +785,10 @@ zip_write_protected(zip_t *dev) zip_sense_key = SENSE_UNIT_ATTENTION; zip_asc = ASC_WRITE_PROTECTED; zip_ascq = 0; + zip_info = (dev->sector_pos >> 24) | + ((dev->sector_pos >> 16) << 8) | + ((dev->sector_pos >> 8) << 16) | + ( dev->sector_pos << 24); zip_cmd_error(dev); } @@ -1054,6 +798,10 @@ zip_write_error(zip_t *dev) zip_sense_key = SENSE_MEDIUM_ERROR; zip_asc = ASC_WRITE_ERROR; zip_ascq = 0; + zip_info = (dev->sector_pos >> 24) | + ((dev->sector_pos >> 16) << 8) | + ((dev->sector_pos >> 8) << 16) | + ( dev->sector_pos << 24); zip_cmd_error(dev); } @@ -1063,24 +811,30 @@ zip_read_error(zip_t *dev) zip_sense_key = SENSE_MEDIUM_ERROR; zip_asc = ASC_UNRECOVERED_READ_ERROR; zip_ascq = 0; + zip_info = (dev->sector_pos >> 24) | + ((dev->sector_pos >> 16) << 8) | + ((dev->sector_pos >> 8) << 16) | + ( dev->sector_pos << 24); zip_cmd_error(dev); } static void -zip_invalid_lun(zip_t *dev) +zip_invalid_lun(zip_t *dev, const uint8_t lun) { zip_sense_key = SENSE_ILLEGAL_REQUEST; zip_asc = ASC_INV_LUN; zip_ascq = 0; + zip_info = lun << 24; zip_cmd_error(dev); } static void -zip_illegal_opcode(zip_t *dev) +zip_illegal_opcode(zip_t *dev, const uint8_t opcode) { zip_sense_key = SENSE_ILLEGAL_REQUEST; zip_asc = ASC_ILLEGAL_OPCODE; zip_ascq = 0; + zip_info = opcode << 24; zip_cmd_error(dev); } @@ -1090,191 +844,244 @@ zip_lba_out_of_range(zip_t *dev) zip_sense_key = SENSE_ILLEGAL_REQUEST; zip_asc = ASC_LBA_OUT_OF_RANGE; zip_ascq = 0; + zip_info = (dev->sector_pos >> 24) | + ((dev->sector_pos >> 16) << 8) | + ((dev->sector_pos >> 8) << 16) | + ( dev->sector_pos << 24); zip_cmd_error(dev); } static void -zip_invalid_field(zip_t *dev) +zip_invalid_field(zip_t *dev, const uint32_t field) { zip_sense_key = SENSE_ILLEGAL_REQUEST; zip_asc = ASC_INV_FIELD_IN_CMD_PACKET; zip_ascq = 0; + zip_info = (field >> 24) | + ((field >> 16) << 8) | + ((field >> 8) << 16) | + ( field << 24); zip_cmd_error(dev); dev->tf->status = 0x53; } static void -zip_invalid_field_pl(zip_t *dev) +zip_invalid_field_pl(zip_t *dev, const uint32_t field) { zip_sense_key = SENSE_ILLEGAL_REQUEST; zip_asc = ASC_INV_FIELD_IN_PARAMETER_LIST; zip_ascq = 0; + zip_info = (field >> 24) | + ((field >> 16) << 8) | + ((field >> 8) << 16) | + ( field << 24); zip_cmd_error(dev); dev->tf->status = 0x53; } static void -zip_data_phase_error(zip_t *dev) +zip_data_phase_error(zip_t *dev, const uint32_t info) { zip_sense_key = SENSE_ILLEGAL_REQUEST; zip_asc = ASC_DATA_PHASE_ERROR; zip_ascq = 0; + zip_info = (info >> 24) | + ((info >> 16) << 8) | + ((info >> 8) << 16) | + ( info << 24); zip_cmd_error(dev); } static int -zip_blocks(zip_t *dev, int32_t *len, UNUSED(int first_batch), int out) +zip_blocks(zip_t *dev, int32_t *len, const int out) { - *len = 0; + int ret = 1; + *len = 0; - if (!dev->sector_len) { + if (!dev->sector_len) zip_command_complete(dev); - return 0; - } + else { + zip_log(dev->log, "%sing %i blocks starting from %i...\n", out ? "Writ" : "Read", + dev->requested_blocks, dev->sector_pos); - zip_log("%sing %i blocks starting from %i...\n", out ? "Writ" : "Read", dev->requested_blocks, dev->sector_pos); - - if (dev->sector_pos >= dev->drv->medium_size) { - zip_log("ZIP %i: Trying to %s beyond the end of disk\n", dev->id, out ? "write" : "read"); - zip_lba_out_of_range(dev); - return 0; - } - - *len = dev->requested_blocks << 9; - - for (int i = 0; i < dev->requested_blocks; i++) { - if (fseek(dev->drv->fp, dev->drv->base + (dev->sector_pos << 9) + (i << 9), SEEK_SET) == -1) { - if (out) - zip_write_error(dev); - else - zip_read_error(dev); - return -1; - } - - if (feof(dev->drv->fp)) - break; - - if (out) { - if (fwrite(dev->buffer + (i << 9), 1, 512, dev->drv->fp) != 512) { - zip_log("zip_blocks(): Error writing data\n"); - zip_write_error(dev); - return -1; - } - - fflush(dev->drv->fp); + if (dev->sector_pos >= dev->drv->medium_size) { + zip_log(dev->log, "Trying to %s beyond the end of disk\n", + out ? "write" : "read"); + zip_lba_out_of_range(dev); } else { - if (fread(dev->buffer + (i << 9), 1, 512, dev->drv->fp) != 512) { - zip_log("zip_blocks(): Error reading data\n"); - zip_read_error(dev); - return -1; + *len = dev->requested_blocks << 9; + + for (int i = 0; i < dev->requested_blocks; i++) { + if (fseek(dev->drv->fp, dev->drv->base + (dev->sector_pos << 9) + + (i << 9), SEEK_SET) == -1) { + if (out) + zip_write_error(dev); + else + zip_read_error(dev); + ret = -1; + } else { + if (feof(dev->drv->fp)) + break; + + if (out) { + if (fwrite(dev->buffer + (i << 9), 1, + 512, dev->drv->fp) != 512) { + zip_log(dev->log, "zip_blocks(): Error writing data\n"); + zip_write_error(dev); + ret = -1; + } else + fflush(dev->drv->fp); + } else if (fread(dev->buffer + (i << 9), 1, + 512, dev->drv->fp) != 512) { + zip_log(dev->log, "zip_blocks(): Error reading data\n"); + zip_read_error(dev); + ret = -1; + } + } + + if (ret == -1) + break; + + dev->sector_pos++; + } + + if (ret == 1) { + zip_log(dev->log, "%s %i bytes of blocks...\n", out ? "Written" : + "Read", *len); + + dev->sector_len -= dev->requested_blocks; } } } - zip_log("%s %i bytes of blocks...\n", out ? "Written" : "Read", *len); - - dev->sector_pos += dev->requested_blocks; - dev->sector_len -= dev->requested_blocks; - - return 1; + return ret; } void zip_insert(zip_t *dev) { - dev->unit_attention = 1; -} - -/*SCSI Sense Initialization*/ -void -zip_sense_code_ok(zip_t *dev) -{ - zip_sense_key = SENSE_NONE; - zip_asc = 0; - zip_ascq = 0; + if ((dev != NULL) && (dev->drv != NULL)) { + if (dev->drv->fp == NULL) { + dev->unit_attention = 0; + dev->transition = 0; + zip_log(dev->log, "Media removal\n"); + } else if (dev->transition) { + dev->unit_attention = 1; + /* Turn off the medium changed status. */ + dev->transition = 0; + zip_log(dev->log, "Media insert\n"); + } else { + dev->unit_attention = 0; + dev->transition = 1; + zip_log(dev->log, "Media transition\n"); + } + } } static int -zip_pre_execution_check(zip_t *dev, uint8_t *cdb) +zip_pre_execution_check(zip_t *dev, const uint8_t *cdb) { - int ready = 0; + int ready; - if ((cdb[0] != GPCMD_REQUEST_SENSE) && (dev->cur_lun == SCSI_LUN_USE_CDB) && (cdb[1] & 0xe0)) { - zip_log("ZIP %i: Attempting to execute a unknown command targeted at SCSI LUN %i\n", dev->id, + if ((cdb[0] != GPCMD_REQUEST_SENSE) && (dev->cur_lun == SCSI_LUN_USE_CDB) && + (cdb[1] & 0xe0)) { + zip_log(dev->log, "Attempting to execute a unknown command targeted at SCSI LUN %i\n", ((dev->tf->request_length >> 5) & 7)); - zip_invalid_lun(dev); + zip_invalid_lun(dev, cdb[1] >> 5); return 0; } if (!(zip_command_flags[cdb[0]] & IMPLEMENTED)) { - zip_log("ZIP %i: Attempting to execute unknown command %02X over %s\n", dev->id, cdb[0], - (dev->drv->bus_type == ZIP_BUS_SCSI) ? "SCSI" : "ATAPI"); + zip_log(dev->log, "Attempting to execute unknown command %02X over %s\n", + cdb[0], (dev->drv->bus_type == ZIP_BUS_SCSI) ? + "SCSI" : "ATAPI"); - zip_illegal_opcode(dev); + zip_illegal_opcode(dev, cdb[0]); return 0; } - if ((dev->drv->bus_type < ZIP_BUS_SCSI) && (zip_command_flags[cdb[0]] & SCSI_ONLY)) { - zip_log("ZIP %i: Attempting to execute SCSI-only command %02X over ATAPI\n", dev->id, cdb[0]); - zip_illegal_opcode(dev); + if ((dev->drv->bus_type < ZIP_BUS_SCSI) && + (zip_command_flags[cdb[0]] & SCSI_ONLY)) { + zip_log(dev->log, "Attempting to execute SCSI-only command %02X " + "over ATAPI\n", cdb[0]); + zip_illegal_opcode(dev, cdb[0]); return 0; } - if ((dev->drv->bus_type == ZIP_BUS_SCSI) && (zip_command_flags[cdb[0]] & ATAPI_ONLY)) { - zip_log("ZIP %i: Attempting to execute ATAPI-only command %02X over SCSI\n", dev->id, cdb[0]); - zip_illegal_opcode(dev); + if ((dev->drv->bus_type == ZIP_BUS_SCSI) && + (zip_command_flags[cdb[0]] & ATAPI_ONLY)) { + zip_log(dev->log, "Attempting to execute ATAPI-only command %02X " + "over SCSI\n", cdb[0]); + zip_illegal_opcode(dev, cdb[0]); return 0; } - ready = (dev->drv->fp != NULL); + if (dev->transition) { + if ((cdb[0] == GPCMD_TEST_UNIT_READY) || (cdb[0] == GPCMD_REQUEST_SENSE)) + ready = 0; + else { + if (!(zip_command_flags[cdb[0]] & ALLOW_UA)) { + zip_log(dev->log, "(ext_medium_changed != 0): zip_insert()\n"); + zip_insert((void *) dev); + } - /* If the drive is not ready, there is no reason to keep the + ready = (dev->drv->fp != NULL); + } + } else + ready = (dev->drv->fp != NULL); + + /* + If the drive is not ready, there is no reason to keep the UNIT ATTENTION condition present, as we only use it to mark - disc changes. */ - if (!ready && dev->unit_attention) + disc changes. + */ + if (!ready && (dev->unit_attention > 0)) dev->unit_attention = 0; - /* If the UNIT ATTENTION condition is set and the command does not allow - execution under it, error out and report the condition. */ + /* + If the UNIT ATTENTION condition is set and the command does not allow + execution under it, error out and report the condition. + */ if (dev->unit_attention == 1) { - /* Only increment the unit attention phase if the command can not pass through it. */ + /* + Only increment the unit attention phase if the command can + not pass through it. + */ if (!(zip_command_flags[cdb[0]] & ALLOW_UA)) { - /* zip_log("ZIP %i: Unit attention now 2\n", dev->id); */ - dev->unit_attention = 2; - zip_log("ZIP %i: UNIT ATTENTION: Command %02X not allowed to pass through\n", dev->id, cdb[0]); + zip_log(dev->log, "Unit attention now 2\n"); + dev->unit_attention++; + zip_log(dev->log, "UNIT ATTENTION: Command %02X not allowed to pass through\n", + cdb[0]); zip_unit_attention(dev); return 0; } } else if (dev->unit_attention == 2) { if (cdb[0] != GPCMD_REQUEST_SENSE) { - /* zip_log("ZIP %i: Unit attention now 0\n", dev->id); */ + zip_log(dev->log, "Unit attention now 0\n"); dev->unit_attention = 0; } } - /* Unless the command is REQUEST SENSE, clear the sense. This will *NOT* - the UNIT ATTENTION condition if it's set. */ + /* + Unless the command is REQUEST SENSE, clear the sense. This will *NOT* clear + the UNIT ATTENTION condition if it's set. + */ if (cdb[0] != GPCMD_REQUEST_SENSE) zip_sense_clear(dev, cdb[0]); - /* Next it's time for NOT READY. */ - if ((zip_command_flags[cdb[0]] & CHECK_READY) && !ready) { - zip_log("ZIP %i: Not ready (%02X)\n", dev->id, cdb[0]); + if (!ready && (zip_command_flags[cdb[0]] & CHECK_READY)) { + zip_log(dev->log, "Not ready (%02X)\n", cdb[0]); zip_not_ready(dev); return 0; } - zip_log("ZIP %i: Continuing with command %02X\n", dev->id, cdb[0]); - + zip_log(dev->log, "Continuing with command %02X\n", cdb[0]); return 1; } static void -zip_seek(zip_t *dev, uint32_t pos) +zip_seek(zip_t *dev, const uint32_t pos) { -#if 0 - zip_log("ZIP %i: Seek %08X\n", dev->id, pos); -#endif dev->sector_pos = pos; } @@ -1299,10 +1106,12 @@ zip_reset(scsi_common_t *sc) dev->packet_status = PHASE_NONE; dev->unit_attention = 0; dev->cur_lun = SCSI_LUN_USE_CDB; + zip_sense_key = zip_asc = zip_ascq = dev->unit_attention = dev->transition = 0; + zip_info = 0x00000000; } static void -zip_request_sense(zip_t *dev, uint8_t *buffer, uint8_t alloc_length, int desc) +zip_request_sense(zip_t *dev, uint8_t *buffer, const uint8_t alloc_length, const int desc) { /*Will return 18 bytes of 0*/ if (alloc_length != 0) { @@ -1316,7 +1125,9 @@ zip_request_sense(zip_t *dev, uint8_t *buffer, uint8_t alloc_length, int desc) } } - buffer[0] = desc ? 0x72 : 0x70; + buffer[0] = desc ? 0x72 : 0xf0; + if (!desc) + buffer[7] = 10; if (dev->unit_attention && (zip_sense_key == 0)) { buffer[desc ? 1 : 2] = SENSE_UNIT_ATTENTION; @@ -1324,7 +1135,8 @@ zip_request_sense(zip_t *dev, uint8_t *buffer, uint8_t alloc_length, int desc) buffer[desc ? 3 : 13] = 0; } - zip_log("ZIP %i: Reporting sense: %02X %02X %02X\n", dev->id, buffer[2], buffer[12], buffer[13]); + zip_log(dev->log, "Reporting sense: %02X %02X %02X\n", buffer[2], + buffer[12], buffer[13]); if (buffer[desc ? 1 : 2] == SENSE_UNIT_ATTENTION) { /* If the last remaining sense is unit attention, clear @@ -1334,30 +1146,33 @@ zip_request_sense(zip_t *dev, uint8_t *buffer, uint8_t alloc_length, int desc) /* Clear the sense stuff as per the spec. */ zip_sense_clear(dev, GPCMD_REQUEST_SENSE); + + if (dev->transition) { + zip_log(dev->log, "ZIP_TRANSITION: zip_insert()\n"); + zip_insert((void *) dev); + } } static void -zip_request_sense_for_scsi(scsi_common_t *sc, uint8_t *buffer, uint8_t alloc_length) +zip_request_sense_for_scsi(scsi_common_t *sc, uint8_t *buffer, const uint8_t alloc_length) { - zip_t *dev = (zip_t *) sc; - int ready = 0; - - ready = (dev->drv->fp != NULL); + zip_t *dev = (zip_t *) sc; + const int ready = (dev->drv->fp != NULL); if (!ready && dev->unit_attention) { - /* If the drive is not ready, there is no reason to keep the - UNIT ATTENTION condition present, as we only use it to mark - disc changes. */ + /* + If the drive is not ready, there is no reason to keep the UNIT ATTENTION + condition present, as we only use it to mark disc changes. + */ dev->unit_attention = 0; } /* Do *NOT* advance the unit attention phase. */ - zip_request_sense(dev, buffer, alloc_length, 0); } static void -zip_set_buf_len(zip_t *dev, int32_t *BufLen, int32_t *src_len) +zip_set_buf_len(const zip_t *dev, int32_t *BufLen, int32_t *src_len) { if (dev->drv->bus_type == ZIP_BUS_SCSI) { if (*BufLen == -1) @@ -1366,28 +1181,27 @@ zip_set_buf_len(zip_t *dev, int32_t *BufLen, int32_t *src_len) *BufLen = MIN(*src_len, *BufLen); *src_len = *BufLen; } - zip_log("ZIP %i: Actual transfer length: %i\n", dev->id, *BufLen); + zip_log(dev->log, "Actual transfer length: %i\n", *BufLen); } } static void -zip_command(scsi_common_t *sc, uint8_t *cdb) +zip_command(scsi_common_t *sc, const uint8_t *cdb) { - zip_t *dev = (zip_t *) sc; - int pos = 0; - int block_desc = 0; - int ret; - int32_t len; - int32_t max_len; - int32_t alloc_length; - uint32_t i = 0; - int size_idx; - int idx = 0; - unsigned preamble_len; - int32_t blen = 0; - int32_t *BufLen; - uint8_t scsi_bus = (dev->drv->scsi_device_id >> 4) & 0x0f; - uint8_t scsi_id = dev->drv->scsi_device_id & 0x0f; + zip_t *dev = (zip_t *) sc; + const uint8_t scsi_bus = (dev->drv->scsi_device_id >> 4) & 0x0f; + const uint8_t scsi_id = dev->drv->scsi_device_id & 0x0f; + int pos = 0; + int idx = 0; + int32_t blen = 0; + uint32_t i; + unsigned preamble_len; + int32_t len; + int32_t max_len; + int32_t alloc_length; + int block_desc; + int size_idx; + int32_t * BufLen; if (dev->drv->bus_type == ZIP_BUS_SCSI) { BufLen = &scsi_devices[scsi_bus][scsi_id].buffer_length; @@ -1403,11 +1217,13 @@ zip_command(scsi_common_t *sc, uint8_t *cdb) memcpy(dev->current_cdb, cdb, 12); if (cdb[0] != 0) { - zip_log("ZIP %i: Command 0x%02X, Sense Key %02X, Asc %02X, Ascq %02X, Unit attention: %i\n", - dev->id, cdb[0], zip_sense_key, zip_asc, zip_ascq, dev->unit_attention); - zip_log("ZIP %i: Request length: %04X\n", dev->id, dev->tf->request_length); + zip_log(dev->log, "Command 0x%02X, Sense Key %02X, Asc %02X, Ascq %02X, " + "Unit attention: %i\n", + cdb[0], zip_sense_key, zip_asc, zip_ascq, dev->unit_attention); + zip_log(dev->log, "Request length: %04X\n", dev->tf->request_length); - zip_log("ZIP %i: CDB: %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X\n", dev->id, + zip_log(dev->log, "CDB: %02X %02X %02X %02X %02X %02X %02X %02X " + "%02X %02X %02X %02X\n", cdb[0], cdb[1], cdb[2], cdb[3], cdb[4], cdb[5], cdb[6], cdb[7], cdb[8], cdb[9], cdb[10], cdb[11]); } @@ -1416,14 +1232,17 @@ zip_command(scsi_common_t *sc, uint8_t *cdb) zip_set_phase(dev, SCSI_PHASE_STATUS); - /* This handles the Not Ready/Unit Attention check if it has to be handled at this point. */ + /* + This handles the Not Ready/Unit Attention check if it has to be handled at + this point. + */ if (zip_pre_execution_check(dev, cdb) == 0) return; switch (cdb[0]) { case GPCMD_SEND_DIAGNOSTIC: if (!(cdb[1] & (1 << 2))) { - zip_invalid_field(dev); + zip_invalid_field(dev, cdb[1]); return; } fallthrough; @@ -1435,13 +1254,12 @@ zip_command(scsi_common_t *sc, uint8_t *cdb) break; case GPCMD_FORMAT_UNIT: - if (dev->drv->read_only) { + if (dev->drv->read_only) zip_write_protected(dev); - return; + else { + zip_set_phase(dev, SCSI_PHASE_STATUS); + zip_command_complete(dev); } - - zip_set_phase(dev, SCSI_PHASE_STATUS); - zip_command_complete(dev); break; case GPCMD_IOMEGA_SENSE: @@ -1451,8 +1269,10 @@ zip_command(scsi_common_t *sc, uint8_t *cdb) zip_set_buf_len(dev, BufLen, &max_len); memset(dev->buffer, 0, 256); if (cdb[2] == 1) { - /* This page is related to disk health status - setting - this page to 0 makes disk health read as "marginal". */ + /* + This page is related to disk health status - setting + this page to 0 makes disk health read as "marginal". + */ dev->buffer[0] = 0x58; dev->buffer[1] = 0x00; for (i = 0x00; i < 0x58; i++) @@ -1468,7 +1288,7 @@ zip_command(scsi_common_t *sc, uint8_t *cdb) for (i = 0x00; i < 0x27; i++) dev->buffer[i + 0x16] = 0x00; } else { - zip_invalid_field(dev); + zip_invalid_field(dev, cdb[2]); zip_buf_free(dev); return; } @@ -1482,9 +1302,11 @@ zip_command(scsi_common_t *sc, uint8_t *cdb) break; case GPCMD_REQUEST_SENSE: - /* If there's a unit attention condition and there's a buffered not - ready, a standalone REQUEST SENSE should forget about the not - ready, and report unit attention straight away. */ + /* + If there's a unit attention condition and there's a buffered not ready, a + standalone REQUEST SENSE should forget about the not ready, and report unit + attention straight away. + */ zip_set_phase(dev, SCSI_PHASE_DATA_IN); max_len = cdb[4]; @@ -1533,17 +1355,20 @@ zip_command(scsi_common_t *sc, uint8_t *cdb) dev->sector_len = 256; dev->sector_pos = ((((uint32_t) cdb[1]) & 0x1f) << 16) | (((uint32_t) cdb[2]) << 8) | ((uint32_t) cdb[3]); - zip_log("ZIP %i: Length: %i, LBA: %i\n", dev->id, dev->sector_len, dev->sector_pos); + zip_log(dev->log, "Length: %i, LBA: %i\n", dev->sector_len, dev->sector_pos); break; case GPCMD_READ_10: dev->sector_len = (cdb[7] << 8) | cdb[8]; - dev->sector_pos = (cdb[2] << 24) | (cdb[3] << 16) | (cdb[4] << 8) | cdb[5]; - zip_log("ZIP %i: Length: %i, LBA: %i\n", dev->id, dev->sector_len, dev->sector_pos); + dev->sector_pos = (cdb[2] << 24) | (cdb[3] << 16) | + (cdb[4] << 8) | cdb[5]; + zip_log(dev->log, "Length: %i, LBA: %i\n", dev->sector_len, dev->sector_pos); break; case GPCMD_READ_12: - dev->sector_len = (((uint32_t) cdb[6]) << 24) | (((uint32_t) cdb[7]) << 16) | + dev->sector_len = (((uint32_t) cdb[6]) << 24) | + (((uint32_t) cdb[7]) << 16) | (((uint32_t) cdb[8]) << 8) | ((uint32_t) cdb[9]); - dev->sector_pos = (((uint32_t) cdb[2]) << 24) | (((uint32_t) cdb[3]) << 16) | + dev->sector_pos = (((uint32_t) cdb[2]) << 24) | + (((uint32_t) cdb[3]) << 16) | (((uint32_t) cdb[4]) << 8) | ((uint32_t) cdb[5]); break; @@ -1551,51 +1376,47 @@ zip_command(scsi_common_t *sc, uint8_t *cdb) break; } - if (dev->sector_pos >= dev->drv->medium_size) { + if (dev->sector_pos >= dev->drv->medium_size) zip_lba_out_of_range(dev); - return; - } + else if (dev->sector_len) { + max_len = dev->sector_len; + dev->requested_blocks = max_len; - if (!dev->sector_len) { + dev->packet_len = max_len * alloc_length; + zip_buf_alloc(dev, dev->packet_len); + + int ret = 0; + + if (dev->sector_len > 0) + ret = zip_blocks(dev, &alloc_length, 0); + + if (ret > 0) { + dev->requested_blocks = max_len; + dev->packet_len = alloc_length; + + zip_set_buf_len(dev, BufLen, (int32_t *) &dev->packet_len); + + zip_data_command_finish(dev, alloc_length, 512, + alloc_length, 0); + + ui_sb_update_icon(SB_ZIP | dev->id, + dev->packet_status != PHASE_COMPLETE); + } else { + zip_set_phase(dev, SCSI_PHASE_STATUS); + dev->packet_status = (ret < 0) ? PHASE_ERROR : PHASE_COMPLETE; + dev->callback = 20.0 * ZIP_TIME; + zip_set_callback(dev); + zip_buf_free(dev); + } + } else { zip_set_phase(dev, SCSI_PHASE_STATUS); - /* zip_log("ZIP %i: All done - callback set\n", dev->id); */ + /* zip_log(dev->log, "All done - callback set\n"); */ dev->packet_status = PHASE_COMPLETE; dev->callback = 20.0 * ZIP_TIME; zip_set_callback(dev); break; } - - max_len = dev->sector_len; - /* - If we're reading all blocks in one go for DMA, why not also for - PIO, it should NOT matter anyway, this step should be identical - and only the way the read dat is transferred to the host should - be different. - */ - dev->requested_blocks = max_len; - - dev->packet_len = max_len * alloc_length; - zip_buf_alloc(dev, dev->packet_len); - - ret = zip_blocks(dev, &alloc_length, 1, 0); - if (ret <= 0) { - zip_set_phase(dev, SCSI_PHASE_STATUS); - dev->packet_status = (ret < 0) ? PHASE_ERROR : PHASE_COMPLETE; - dev->callback = 20.0 * ZIP_TIME; - zip_set_callback(dev); - zip_buf_free(dev); - return; - } - - dev->requested_blocks = max_len; - dev->packet_len = alloc_length; - - zip_set_buf_len(dev, BufLen, (int32_t *) &dev->packet_len); - - zip_data_command_finish(dev, alloc_length, 512, alloc_length, 0); - - ui_sb_update_icon(SB_ZIP | dev->id, dev->packet_status != PHASE_COMPLETE); - return; + break; case GPCMD_VERIFY_6: case GPCMD_VERIFY_10: @@ -1616,7 +1437,7 @@ zip_command(scsi_common_t *sc, uint8_t *cdb) if (dev->drv->read_only) { zip_write_protected(dev); - return; + break; } switch (cdb[0]) { @@ -1636,15 +1457,19 @@ zip_command(scsi_common_t *sc, uint8_t *cdb) case GPCMD_WRITE_10: case GPCMD_WRITE_AND_VERIFY_10: dev->sector_len = (cdb[7] << 8) | cdb[8]; - dev->sector_pos = (cdb[2] << 24) | (cdb[3] << 16) | (cdb[4] << 8) | cdb[5]; - zip_log("ZIP %i: Length: %i, LBA: %i\n", dev->id, dev->sector_len, dev->sector_pos); + dev->sector_pos = (cdb[2] << 24) | (cdb[3] << 16) | + (cdb[4] << 8) | cdb[5]; + zip_log(dev->log, "Length: %i, LBA: %i\n", + dev->sector_len, dev->sector_pos); break; case GPCMD_VERIFY_12: case GPCMD_WRITE_12: case GPCMD_WRITE_AND_VERIFY_12: - dev->sector_len = (((uint32_t) cdb[6]) << 24) | (((uint32_t) cdb[7]) << 16) | + dev->sector_len = (((uint32_t) cdb[6]) << 24) | + (((uint32_t) cdb[7]) << 16) | (((uint32_t) cdb[8]) << 8) | ((uint32_t) cdb[9]); - dev->sector_pos = (((uint32_t) cdb[2]) << 24) | (((uint32_t) cdb[3]) << 16) | + dev->sector_pos = (((uint32_t) cdb[2]) << 24) | + (((uint32_t) cdb[3]) << 16) | (((uint32_t) cdb[4]) << 8) | ((uint32_t) cdb[5]); break; @@ -1652,86 +1477,75 @@ zip_command(scsi_common_t *sc, uint8_t *cdb) break; } - if (dev->sector_pos >= dev->drv->medium_size) { + if (dev->sector_pos >= dev->drv->medium_size) zip_lba_out_of_range(dev); - return; - } + if (dev->sector_len) { + max_len = dev->sector_len; + dev->requested_blocks = max_len; - if (!dev->sector_len) { + dev->packet_len = max_len * alloc_length; + zip_buf_alloc(dev, dev->packet_len); + + dev->requested_blocks = max_len; + dev->packet_len = max_len << 9; + + zip_set_buf_len(dev, BufLen, (int32_t *) &dev->packet_len); + + zip_data_command_finish(dev, dev->packet_len, 512, + dev->packet_len, 1); + + ui_sb_update_icon(SB_ZIP | dev->id, + dev->packet_status != PHASE_COMPLETE); + } else { zip_set_phase(dev, SCSI_PHASE_STATUS); - /* zip_log("ZIP %i: All done - callback set\n", dev->id); */ + /* zip_log(dev->log, "All done - callback set\n"); */ dev->packet_status = PHASE_COMPLETE; dev->callback = 20.0 * ZIP_TIME; zip_set_callback(dev); - break; } - - max_len = dev->sector_len; - /* - If we're writing all blocks in one go for DMA, why not also for - PIO, it should NOT matter anyway, this step should be identical - and only the way the read dat is transferred to the host should - be different. - */ - dev->requested_blocks = max_len; - - dev->packet_len = max_len * alloc_length; - zip_buf_alloc(dev, dev->packet_len); - - dev->requested_blocks = max_len; - dev->packet_len = max_len << 9; - - zip_set_buf_len(dev, BufLen, (int32_t *) &dev->packet_len); - - zip_data_command_finish(dev, dev->packet_len, 512, dev->packet_len, 1); - - ui_sb_update_icon(SB_ZIP | dev->id, dev->packet_status != PHASE_COMPLETE); - return; + break; case GPCMD_WRITE_SAME_10: alloc_length = 512; - if ((cdb[1] & 6) == 6) { - zip_invalid_field(dev); - return; + if ((cdb[1] & 6) == 6) + zip_invalid_field(dev, cdb[1]); + else { + if (dev->drv->read_only) + zip_write_protected(dev); + else { + dev->sector_len = (cdb[7] << 8) | cdb[8]; + dev->sector_pos = (cdb[2] << 24) | (cdb[3] << 16) | + (cdb[4] << 8) | cdb[5]; + + if (dev->sector_pos >= dev->drv->medium_size) + zip_lba_out_of_range(dev); + else if (dev->sector_len) { + zip_buf_alloc(dev, alloc_length); + zip_set_buf_len(dev, BufLen, (int32_t *) &dev->packet_len); + + max_len = 1; + dev->requested_blocks = 1; + + dev->packet_len = alloc_length; + + zip_set_phase(dev, SCSI_PHASE_DATA_OUT); + + zip_data_command_finish(dev, 512, 512, + alloc_length, 1); + + ui_sb_update_icon(SB_ZIP | dev->id, + dev->packet_status != PHASE_COMPLETE); + } else { + zip_set_phase(dev, SCSI_PHASE_STATUS); + /* zip_log(dev->log, "All done - callback set\n"); */ + dev->packet_status = PHASE_COMPLETE; + dev->callback = 20.0 * ZIP_TIME; + zip_set_callback(dev); + } + } } - - if (dev->drv->read_only) { - zip_write_protected(dev); - return; - } - - dev->sector_len = (cdb[7] << 8) | cdb[8]; - dev->sector_pos = (cdb[2] << 24) | (cdb[3] << 16) | (cdb[4] << 8) | cdb[5]; - - if (dev->sector_pos >= dev->drv->medium_size) { - zip_lba_out_of_range(dev); - return; - } - - if (!dev->sector_len) { - zip_set_phase(dev, SCSI_PHASE_STATUS); - /* zip_log("ZIP %i: All done - callback set\n", dev->id); */ - dev->packet_status = PHASE_COMPLETE; - dev->callback = 20.0 * ZIP_TIME; - zip_set_callback(dev); - break; - } - - zip_buf_alloc(dev, alloc_length); - zip_set_buf_len(dev, BufLen, (int32_t *) &dev->packet_len); - - max_len = 1; - dev->requested_blocks = 1; - - dev->packet_len = alloc_length; - - zip_set_phase(dev, SCSI_PHASE_DATA_OUT); - - zip_data_command_finish(dev, 512, 512, alloc_length, 1); - - ui_sb_update_icon(SB_ZIP | dev->id, dev->packet_status != PHASE_COMPLETE); - return; + break; case GPCMD_MODE_SENSE_6: case GPCMD_MODE_SENSE_10: @@ -1750,40 +1564,41 @@ zip_command(scsi_common_t *sc, uint8_t *cdb) zip_buf_alloc(dev, 65536); } - if (!(zip_mode_sense_page_flags & (1LL << (uint64_t) (cdb[2] & 0x3f)))) { - zip_invalid_field(dev); - zip_buf_free(dev); - return; - } + if (zip_mode_sense_page_flags & (1LL << (uint64_t) (cdb[2] & 0x3f))) { + memset(dev->buffer, 0, len); + alloc_length = len; - memset(dev->buffer, 0, len); - alloc_length = len; - - if (cdb[0] == GPCMD_MODE_SENSE_6) { - len = zip_mode_sense(dev, dev->buffer, 4, cdb[2], block_desc); - len = MIN(len, alloc_length); - dev->buffer[0] = len - 1; - dev->buffer[1] = 0; - if (block_desc) - dev->buffer[3] = 8; - } else { - len = zip_mode_sense(dev, dev->buffer, 8, cdb[2], block_desc); - len = MIN(len, alloc_length); - dev->buffer[0] = (len - 2) >> 8; - dev->buffer[1] = (len - 2) & 255; - dev->buffer[2] = 0; - if (block_desc) { - dev->buffer[6] = 0; - dev->buffer[7] = 8; + if (cdb[0] == GPCMD_MODE_SENSE_6) { + len = zip_mode_sense(dev, dev->buffer, 4, cdb[2], + block_desc); + len = MIN(len, alloc_length); + dev->buffer[0] = len - 1; + dev->buffer[1] = 0; + if (block_desc) + dev->buffer[3] = 8; + } else { + len = zip_mode_sense(dev, dev->buffer, 8, cdb[2], + block_desc); + len = MIN(len, alloc_length); + dev->buffer[0] = (len - 2) >> 8; + dev->buffer[1] = (len - 2) & 255; + dev->buffer[2] = 0; + if (block_desc) { + dev->buffer[6] = 0; + dev->buffer[7] = 8; + } } + + zip_set_buf_len(dev, BufLen, &len); + + zip_log(dev->log, "Reading mode page: %02X...\n", cdb[2]); + + zip_data_command_finish(dev, len, len, alloc_length, 0); + } else { + zip_invalid_field(dev, cdb[2]); + zip_buf_free(dev); } - - zip_set_buf_len(dev, BufLen, &len); - - zip_log("ZIP %i: Reading mode page: %02X...\n", dev->id, cdb[2]); - - zip_data_command_finish(dev, len, len, alloc_length, 0); - return; + break; case GPCMD_MODE_SELECT_6: case GPCMD_MODE_SELECT_10: @@ -1856,7 +1671,7 @@ zip_command(scsi_common_t *sc, uint8_t *cdb) break; case 0x83: if (idx + 24 > max_len) { - zip_data_phase_error(dev); + zip_data_phase_error(dev, cdb[2]); zip_buf_free(dev); return; } @@ -1874,19 +1689,21 @@ zip_command(scsi_common_t *sc, uint8_t *cdb) dev->buffer[idx++] = 0x01; dev->buffer[idx++] = 0x00; dev->buffer[idx++] = 68; - ide_padstr8(dev->buffer + idx, 8, "IOMEGA "); /* Vendor */ + /* Vendor */ + ide_padstr8(dev->buffer + idx, 8, "IOMEGA "); idx += 8; + /* Product */ if (dev->drv->is_250) - ide_padstr8(dev->buffer + idx, 40, "ZIP 250 "); /* Product */ + ide_padstr8(dev->buffer + idx, 40, "ZIP 250 "); else - ide_padstr8(dev->buffer + idx, 40, "ZIP 100 "); /* Product */ + ide_padstr8(dev->buffer + idx, 40, "ZIP 100 "); idx += 40; - ide_padstr8(dev->buffer + idx, 20, "53R141"); /* Product */ + ide_padstr8(dev->buffer + idx, 20, "53R141"); idx += 20; break; default: - zip_log("INQUIRY: Invalid page: %02X\n", cdb[2]); - zip_invalid_field(dev); + zip_log(dev->log, "INQUIRY: Invalid page: %02X\n", cdb[2]); + zip_invalid_field(dev, cdb[2]); zip_buf_free(dev); return; } @@ -1896,33 +1713,39 @@ zip_command(scsi_common_t *sc, uint8_t *cdb) memset(dev->buffer, 0, 8); if ((cdb[1] & 0xe0) || ((dev->cur_lun > 0x00) && (dev->cur_lun < 0xff))) - dev->buffer[0] = 0x7f; /*No physical device on this LUN*/ + dev->buffer[0] = 0x7f; /* No physical device on this LUN */ else - dev->buffer[0] = 0x00; /*Hard disk*/ - dev->buffer[1] = 0x80; /*Removable*/ - dev->buffer[2] = (dev->drv->bus_type == ZIP_BUS_SCSI) ? 0x02 : 0x00; /*SCSI-2 compliant*/ + dev->buffer[0] = 0x00; /* Hard disk */ + dev->buffer[1] = 0x80; /* Removable */ + /* SCSI-2 compliant */ + dev->buffer[2] = (dev->drv->bus_type == ZIP_BUS_SCSI) ? 0x02 : 0x00; dev->buffer[3] = (dev->drv->bus_type == ZIP_BUS_SCSI) ? 0x02 : 0x21; #if 0 dev->buffer[4] = 31; #endif dev->buffer[4] = 0; if (dev->drv->bus_type == ZIP_BUS_SCSI) { - dev->buffer[6] = 1; /* 16-bit transfers supported */ - dev->buffer[7] = 0x20; /* Wide bus supported */ + dev->buffer[6] = 1; /* 16-bit transfers supported */ + dev->buffer[7] = 0x20; /* Wide bus supported */ } dev->buffer[7] |= 0x02; - ide_padstr8(dev->buffer + 8, 8, "IOMEGA "); /* Vendor */ + ide_padstr8(dev->buffer + 8, 8, "IOMEGA "); /* Vendor */ if (dev->drv->is_250) { - ide_padstr8(dev->buffer + 16, 16, "ZIP 250 "); /* Product */ - ide_padstr8(dev->buffer + 32, 4, "42.S"); /* Revision */ + /* Product */ + ide_padstr8(dev->buffer + 16, 16, "ZIP 250 "); + /* Revision */ + ide_padstr8(dev->buffer + 32, 4, "42.S"); + /* Date? */ if (max_len >= 44) - ide_padstr8(dev->buffer + 36, 8, "08/08/01"); /* Date? */ + ide_padstr8(dev->buffer + 36, 8, "08/08/01"); if (max_len >= 122) ide_padstr8(dev->buffer + 96, 26, "(c) Copyright IOMEGA 2000 "); /* Copyright string */ } else { - ide_padstr8(dev->buffer + 16, 16, "ZIP 100 "); /* Product */ - ide_padstr8(dev->buffer + 32, 4, "E.08"); /* Revision */ + /* Product */ + ide_padstr8(dev->buffer + 16, 16, "ZIP 100 "); + /* Revision */ + ide_padstr8(dev->buffer + 32, 4, "E.08"); } idx = 36; @@ -1974,7 +1797,8 @@ atapi_out: zip_buf_alloc(dev, 8); - max_len = dev->drv->medium_size - 1; /* IMPORTANT: What's returned is the last LBA block. */ + /* IMPORTANT: What's returned is the last LBA block. */ + max_len = dev->drv->medium_size - 1; memset(dev->buffer, 0, 8); dev->buffer[0] = (max_len >> 24) & 0xff; dev->buffer[1] = (max_len >> 16) & 0xff; @@ -2063,12 +1887,13 @@ atapi_out: break; default: - zip_illegal_opcode(dev); + zip_illegal_opcode(dev, cdb[0]); break; } #if 0 - zip_log("ZIP %i: Phase: %02X, request length: %i\n", dev->id, dev->tf->phase, dev->tf->request_length); + zip_log(dev->log, "Phase: %02X, request length: %i\n", + dev->tf->phase, dev->tf->request_length); #endif if ((dev->packet_status == PHASE_COMPLETE) || (dev->packet_status == PHASE_ERROR)) @@ -2088,29 +1913,16 @@ zip_command_stop(scsi_common_t *sc) static uint8_t zip_phase_data_out(scsi_common_t *sc) { - zip_t *dev = (zip_t *) sc; - + zip_t *dev = (zip_t *) sc; + int len = 0; + uint8_t error = 0; + uint32_t last_to_write; + uint32_t i; uint16_t block_desc_len; uint16_t pos; uint16_t param_list_len; - - uint8_t error = 0; - uint8_t page; - uint8_t page_len; - - uint32_t i = 0; - - uint8_t hdr_len; - uint8_t val; - uint8_t old_val; - uint8_t ch; - - uint32_t last_to_write = 0; - uint32_t c; - uint32_t h; - uint32_t s; - - int len = 0; + uint8_t hdr_len; + uint8_t val; switch (dev->current_cdb[0]) { case GPCMD_VERIFY_6: @@ -2123,7 +1935,7 @@ zip_phase_data_out(scsi_common_t *sc) case GPCMD_WRITE_12: case GPCMD_WRITE_AND_VERIFY_12: if (dev->requested_blocks > 0) - zip_blocks(dev, &len, 1, 1); + zip_blocks(dev, &len, 1); break; case GPCMD_WRITE_SAME_10: if (!dev->current_cdb[7] && !dev->current_cdb[8]) { @@ -2139,22 +1951,23 @@ zip_phase_data_out(scsi_common_t *sc) dev->buffer[3] = i & 0xff; } else if (dev->current_cdb[1] & 4) { /* CHS are 96, 1, 2048 (ZIP 100) and 239, 1, 2048 (ZIP 250) */ - s = (i % 2048); - h = ((i - s) / 2048) % 1; - c = ((i - s) / 2048) / 1; - dev->buffer[0] = (c >> 16) & 0xff; - dev->buffer[1] = (c >> 8) & 0xff; - dev->buffer[2] = c & 0xff; - dev->buffer[3] = h & 0xff; - dev->buffer[4] = (s >> 24) & 0xff; - dev->buffer[5] = (s >> 16) & 0xff; - dev->buffer[6] = (s >> 8) & 0xff; - dev->buffer[7] = s & 0xff; + const uint32_t s = (i % 2048); + const uint32_t h = ((i - s) / 2048) % 1; + const uint32_t c = ((i - s) / 2048) / 1; + dev->buffer[0] = (c >> 16) & 0xff; + dev->buffer[1] = (c >> 8) & 0xff; + dev->buffer[2] = c & 0xff; + dev->buffer[3] = h & 0xff; + dev->buffer[4] = (s >> 24) & 0xff; + dev->buffer[5] = (s >> 16) & 0xff; + dev->buffer[6] = (s >> 8) & 0xff; + dev->buffer[7] = s & 0xff; } - if (fseek(dev->drv->fp, dev->drv->base + (i << 9), SEEK_SET) == -1) - fatal("zip_phase_data_out(): Error seeking\n"); + if (fseek(dev->drv->fp, dev->drv->base + (i << 9), + SEEK_SET) == -1) + log_fatal(dev->log, "zip_phase_data_out(): Error seeking\n"); if (fwrite(dev->buffer, 1, 512, dev->drv->fp) != 512) - fatal("zip_phase_data_out(): Error writing data\n"); + log_fatal(dev->log, "zip_phase_data_out(): Error writing data\n"); } fflush(dev->drv->fp); @@ -2188,27 +2001,27 @@ zip_phase_data_out(scsi_common_t *sc) while (1) { if (pos >= param_list_len) { - zip_log("ZIP %i: Buffer has only block descriptor\n", dev->id); + zip_log(dev->log, "Buffer has only block descriptor\n"); break; } - page = dev->buffer[pos] & 0x3F; - page_len = dev->buffer[pos + 1]; + const uint8_t page = dev->buffer[pos] & 0x3f; + const uint8_t page_len = dev->buffer[pos + 1]; pos += 2; if (!(zip_mode_sense_page_flags & (1LL << ((uint64_t) page)))) error |= 1; - else { - for (i = 0; i < page_len; i++) { - ch = zip_mode_sense_pages_changeable.pages[page][i + 2]; - val = dev->buffer[pos + i]; - old_val = dev->ms_pages_saved.pages[page][i + 2]; - if (val != old_val) { - if (ch) - dev->ms_pages_saved.pages[page][i + 2] = val; - else - error |= 1; + else for (i = 0; i < page_len; i++) { + const uint8_t old_val = dev->ms_pages_saved.pages[page][i + 2]; + const uint8_t ch = zip_mode_sense_pages_changeable.pages[page][i + 2]; + val = dev->buffer[pos + i]; + if (val != old_val) { + if (ch) + dev->ms_pages_saved.pages[page][i + 2] = val; + else { + error |= 1; + zip_invalid_field_pl(dev, val); } } } @@ -2228,7 +2041,6 @@ zip_phase_data_out(scsi_common_t *sc) if (error) { zip_buf_free(dev); - zip_invalid_field_pl(dev); return 0; } break; @@ -2250,7 +2062,7 @@ zip_global_init(void) } static int -zip_get_max(int ide_has_dma, int type) +zip_get_max(UNUSED(const ide_t *ide), const int ide_has_dma, const int type) { int ret; @@ -2274,7 +2086,7 @@ zip_get_max(int ide_has_dma, int type) } static int -zip_get_timings(int ide_has_dma, int type) +zip_get_timings(UNUSED(const ide_t *ide), const int ide_has_dma, const int type) { int ret; @@ -2297,39 +2109,43 @@ zip_get_timings(int ide_has_dma, int type) } static void -zip_100_identify(ide_t *ide) +zip_100_identify(const ide_t *ide) { ide_padstr((char *) (ide->buffer + 23), "E.08", 8); /* Firmware */ ide_padstr((char *) (ide->buffer + 27), "IOMEGA ZIP 100 ATAPI", 40); /* Model */ } static void -zip_250_identify(ide_t *ide, int ide_has_dma) +zip_250_identify(const ide_t *ide, const int ide_has_dma) { - ide_padstr((char *) (ide->buffer + 23), "42.S", 8); /* Firmware */ - ide_padstr((char *) (ide->buffer + 27), "IOMEGA ZIP 250 ATAPI", 40); /* Model */ + /* Firmware */ + ide_padstr((char *) (ide->buffer + 23), "42.S", 8); + /* Model */ + ide_padstr((char *) (ide->buffer + 27), "IOMEGA ZIP 250 ATAPI", 40); if (ide_has_dma) { - ide->buffer[80] = 0x70; /*Supported ATA versions : ATA/ATAPI-4 ATA/ATAPI-6*/ - ide->buffer[81] = 0x19; /*Maximum ATA revision supported : ATA/ATAPI-6 T13 1410D revision 3a*/ + ide->buffer[80] = 0x70; /* Supported ATA versions : ATA/ATAPI-4 ATA/ATAPI-6 */ + /* Maximum ATA revision supported : ATA/ATAPI-6 T13 1410D revision 3a */ + ide->buffer[81] = 0x19; } } static void -zip_identify(ide_t *ide, int ide_has_dma) +zip_identify(const ide_t *ide, const int ide_has_dma) { - const zip_t *zip; + const zip_t *zip = (zip_t *) ide->sc; - zip = (zip_t *) ide->sc; - - /* ATAPI device, direct-access device, removable media, interrupt DRQ: + /* + ATAPI device, direct-access device, removable media, interrupt DRQ: Using (2 << 5) below makes the ASUS P/I-P54TP4XE misdentify the ZIP drive - as a LS-120. */ + as a LS-120. + */ ide->buffer[0] = 0x8000 | (0 << 8) | 0x80 | (1 << 5); - ide_padstr((char *) (ide->buffer + 10), "", 20); /* Serial Number */ - ide->buffer[49] = 0x200; /* LBA supported */ - ide->buffer[126] = 0xfffe; /* Interpret zero byte count limit as maximum length */ + ide_padstr((char *) (ide->buffer + 10), "", 20); /* Serial Number */ + ide->buffer[49] = 0x200; /* LBA supported */ + /* Interpret zero byte count limit as maximum length */ + ide->buffer[126] = 0xfffe; if (zip_drives[zip->id].is_250) zip_250_identify(ide, ide_has_dma); @@ -2338,30 +2154,32 @@ zip_identify(ide_t *ide, int ide_has_dma) } static void -zip_drive_reset(int c) +zip_drive_reset(const int c) { - zip_t *dev; - scsi_device_t *sd; - ide_t *id; - uint8_t scsi_bus = (zip_drives[c].scsi_device_id >> 4) & 0x0f; - uint8_t scsi_id = zip_drives[c].scsi_device_id & 0x0f; + const uint8_t scsi_bus = (zip_drives[c].scsi_device_id >> 4) & 0x0f; + const uint8_t scsi_id = zip_drives[c].scsi_device_id & 0x0f; - if (!zip_drives[c].priv) { - zip_drives[c].priv = (zip_t *) malloc(sizeof(zip_t)); - memset(zip_drives[c].priv, 0, sizeof(zip_t)); + if (zip_drives[c].priv == NULL) { + zip_drives[c].priv = (zip_t *) calloc(1, sizeof(zip_t)); + zip_t *dev = (zip_t *) zip_drives[c].priv; + + char n[1024] = { 0 }; + + sprintf(n, "ZIP %i", c + 1); + dev->log = log_open(n); } - dev = (zip_t *) zip_drives[c].priv; + zip_t *dev = (zip_t *) zip_drives[c].priv; dev->id = c; dev->cur_lun = SCSI_LUN_USE_CDB; if (zip_drives[c].bus_type == ZIP_BUS_SCSI) { - if (!dev->tf) + if (dev->tf == NULL) dev->tf = (ide_tf_t *) calloc(1, sizeof(ide_tf_t)); /* SCSI ZIP, attach to the SCSI bus. */ - sd = &scsi_devices[scsi_bus][scsi_id]; + scsi_device_t *sd = &scsi_devices[scsi_bus][scsi_id]; sd->sc = (scsi_common_t *) dev; sd->command = zip_command; @@ -2372,7 +2190,7 @@ zip_drive_reset(int c) sd->type = SCSI_REMOVABLE_DISK; } else if (zip_drives[c].bus_type == ZIP_BUS_ATAPI) { /* ATAPI CD-ROM, attach to the IDE bus. */ - id = ide_get_drive(zip_drives[c].ide_channel); + ide_t *id = ide_get_drive(zip_drives[c].ide_channel); /* If the IDE channel is initialized, we attach to it, otherwise, we do nothing - it's going to be a drive that's not attached to anything. */ @@ -2399,17 +2217,12 @@ zip_drive_reset(int c) void zip_hard_reset(void) { - zip_t *dev; - uint8_t scsi_id; - uint8_t scsi_bus; - for (uint8_t c = 0; c < ZIP_NUM; c++) { if ((zip_drives[c].bus_type == ZIP_BUS_ATAPI) || (zip_drives[c].bus_type == ZIP_BUS_SCSI)) { - zip_log("ZIP hard_reset drive=%d\n", c); if (zip_drives[c].bus_type == ZIP_BUS_SCSI) { - scsi_bus = (zip_drives[c].scsi_device_id >> 4) & 0x0f; - scsi_id = zip_drives[c].scsi_device_id & 0x0f; + const uint8_t scsi_bus = (zip_drives[c].scsi_device_id >> 4) & 0x0f; + const uint8_t scsi_id = zip_drives[c].scsi_device_id & 0x0f; /* Make sure to ignore any SCSI ZIP drive that has an out of range SCSI bus. */ if (scsi_bus >= SCSI_BUS_MAX) @@ -2426,7 +2239,9 @@ zip_hard_reset(void) zip_drive_reset(c); - dev = (zip_t *) zip_drives[c].priv; + zip_t *dev = (zip_t *) zip_drives[c].priv; + + zip_log(dev->log, "ZIP hard_reset drive=%d\n", c); if (dev->tf == NULL) continue; @@ -2437,14 +2252,16 @@ zip_hard_reset(void) zip_init(dev); if (strlen(zip_drives[c].image_path)) - zip_load(dev, zip_drives[c].image_path); + zip_load(dev, zip_drives[c].image_path, 0); zip_mode_sense_load(dev); if (zip_drives[c].bus_type == ZIP_BUS_SCSI) - zip_log("SCSI ZIP drive %i attached to SCSI ID %i\n", c, zip_drives[c].scsi_device_id); + zip_log(dev->log, "SCSI ZIP drive %i attached to SCSI ID %i\n", + c, zip_drives[c].scsi_device_id); else if (zip_drives[c].bus_type == ZIP_BUS_ATAPI) - zip_log("ATAPI ZIP drive %i attached to IDE channel %i\n", c, zip_drives[c].ide_channel); + zip_log(dev->log, "ATAPI ZIP drive %i attached to IDE channel %i\n", + c, zip_drives[c].ide_channel); } } } @@ -2452,19 +2269,15 @@ zip_hard_reset(void) void zip_close(void) { - zip_t *dev; - uint8_t scsi_bus; - uint8_t scsi_id; - for (uint8_t c = 0; c < ZIP_NUM; c++) { if (zip_drives[c].bus_type == ZIP_BUS_SCSI) { - scsi_bus = (zip_drives[c].scsi_device_id >> 4) & 0x0f; - scsi_id = zip_drives[c].scsi_device_id & 0x0f; + const uint8_t scsi_bus = (zip_drives[c].scsi_device_id >> 4) & 0x0f; + const uint8_t scsi_id = zip_drives[c].scsi_device_id & 0x0f; memset(&scsi_devices[scsi_bus][scsi_id], 0x00, sizeof(scsi_device_t)); } - dev = (zip_t *) zip_drives[c].priv; + zip_t *dev = (zip_t *) zip_drives[c].priv; if (dev) { zip_disk_unload(dev); @@ -2472,6 +2285,13 @@ zip_close(void) if (dev->tf) free(dev->tf); + if (dev->log != NULL) { + zip_log(dev->log, "Log closed\n"); + + log_close(dev->log); + dev->log = NULL; + } + free(dev); zip_drives[c].priv = NULL; } diff --git a/src/floppy/fdc.c b/src/floppy/fdc.c index 4cb2a8491..300d775c5 100644 --- a/src/floppy/fdc.c +++ b/src/floppy/fdc.c @@ -2314,8 +2314,7 @@ fdc_close(void *priv) static void * fdc_init(const device_t *info) { - fdc_t *fdc = (fdc_t *) malloc(sizeof(fdc_t)); - memset(fdc, 0, sizeof(fdc_t)); + fdc_t *fdc = (fdc_t *) calloc(1, sizeof(fdc_t)); fdc->flags = info->local; @@ -2371,7 +2370,7 @@ const device_t fdc_xt_device = { .init = fdc_init, .close = fdc_close, .reset = fdc_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2385,7 +2384,7 @@ const device_t fdc_xt_sec_device = { .init = fdc_init, .close = fdc_close, .reset = fdc_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2399,7 +2398,7 @@ const device_t fdc_xt_ter_device = { .init = fdc_init, .close = fdc_close, .reset = fdc_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2413,7 +2412,7 @@ const device_t fdc_xt_qua_device = { .init = fdc_init, .close = fdc_close, .reset = fdc_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2427,7 +2426,7 @@ const device_t fdc_xt_t1x00_device = { .init = fdc_init, .close = fdc_close, .reset = fdc_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2441,7 +2440,7 @@ const device_t fdc_xt_amstrad_device = { .init = fdc_init, .close = fdc_close, .reset = fdc_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2455,7 +2454,7 @@ const device_t fdc_xt_tandy_device = { .init = fdc_init, .close = fdc_close, .reset = fdc_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2469,7 +2468,7 @@ const device_t fdc_xt_umc_um8398_device = { .init = fdc_init, .close = fdc_close, .reset = fdc_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2483,7 +2482,7 @@ const device_t fdc_pcjr_device = { .init = fdc_init, .close = fdc_close, .reset = fdc_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2497,7 +2496,7 @@ const device_t fdc_at_device = { .init = fdc_init, .close = fdc_close, .reset = fdc_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2511,7 +2510,7 @@ const device_t fdc_at_sec_device = { .init = fdc_init, .close = fdc_close, .reset = fdc_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2525,7 +2524,7 @@ const device_t fdc_at_ter_device = { .init = fdc_init, .close = fdc_close, .reset = fdc_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2539,7 +2538,7 @@ const device_t fdc_at_qua_device = { .init = fdc_init, .close = fdc_close, .reset = fdc_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2553,7 +2552,7 @@ const device_t fdc_at_actlow_device = { .init = fdc_init, .close = fdc_close, .reset = fdc_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2567,7 +2566,7 @@ const device_t fdc_at_smc_device = { .init = fdc_init, .close = fdc_close, .reset = fdc_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2581,7 +2580,7 @@ const device_t fdc_at_ali_device = { .init = fdc_init, .close = fdc_close, .reset = fdc_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2595,7 +2594,7 @@ const device_t fdc_at_winbond_device = { .init = fdc_init, .close = fdc_close, .reset = fdc_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2609,7 +2608,7 @@ const device_t fdc_at_nsc_device = { .init = fdc_init, .close = fdc_close, .reset = fdc_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2623,7 +2622,7 @@ const device_t fdc_at_nsc_dp8473_device = { .init = fdc_init, .close = fdc_close, .reset = fdc_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2638,7 +2637,7 @@ const device_t fdc_ps2_device = { .init = fdc_init, .close = fdc_close, .reset = fdc_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2653,7 +2652,7 @@ const device_t fdc_ps2_mca_device = { .init = fdc_init, .close = fdc_close, .reset = fdc_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/floppy/fdc_compaticard.c b/src/floppy/fdc_compaticard.c index a693c9cb2..4abc4abac 100644 --- a/src/floppy/fdc_compaticard.c +++ b/src/floppy/fdc_compaticard.c @@ -30,6 +30,7 @@ #include <86box/fdd.h> #include <86box/fdc.h> #include <86box/fdc_ext.h> +#include <86box/plat_unused.h> #define DEVICE_COMPATICARD_I 0 #define DEVICE_COMPATICARD_II 1 @@ -57,7 +58,7 @@ typedef struct compaticard_s { } compaticard_t; static void -compaticard_out(uint16_t port, uint8_t val, void *priv) +compaticard_out(UNUSED(uint16_t port), uint8_t val, void *priv) { compaticard_t *dev = (compaticard_t *) priv; @@ -65,7 +66,7 @@ compaticard_out(uint16_t port, uint8_t val, void *priv) } static uint8_t -compaticard_in(uint16_t port, void *priv) +compaticard_in(UNUSED(uint16_t port), void *priv) { compaticard_t *dev = (compaticard_t *) priv; uint8_t ret = (dev->cr_2 &CR_2_MASK); diff --git a/src/floppy/fdc_magitronic.c b/src/floppy/fdc_magitronic.c index 306440b9c..2b708a121 100644 --- a/src/floppy/fdc_magitronic.c +++ b/src/floppy/fdc_magitronic.c @@ -90,8 +90,7 @@ b215_close(void *priv) static void * b215_init(UNUSED(const device_t *info)) { - b215_t *dev = (b215_t *) malloc(sizeof(b215_t)); - memset(dev, 0, sizeof(b215_t)); + b215_t *dev = (b215_t *) calloc(1, sizeof(b215_t)); rom_init(&dev->rom, ROM_B215, ROM_ADDR, 0x2000, 0x1fff, 0, MEM_MAPPING_EXTERNAL); @@ -135,7 +134,7 @@ const device_t fdc_b215_device = { .init = b215_init, .close = b215_close, .reset = NULL, - { .available = b215_available }, + .available = b215_available, .speed_changed = NULL, .force_redraw = NULL, .config = b215_config diff --git a/src/floppy/fdc_monster.c b/src/floppy/fdc_monster.c index 00b6d37f5..51fb108d6 100644 --- a/src/floppy/fdc_monster.c +++ b/src/floppy/fdc_monster.c @@ -13,7 +13,7 @@ * Authors: Jasmine Iwanek, * Miran Grca, * - * Copyright 2022-2024 Jasmine Iwanek. + * Copyright 2022-2025 Jasmine Iwanek. * Copyright 2024 Miran Grca. */ #include @@ -286,7 +286,7 @@ const device_t fdc_monster_device = { .init = monster_fdc_init, .close = monster_fdc_close, .reset = NULL, - { .available = monster_fdc_available }, + .available = monster_fdc_available, .speed_changed = NULL, .force_redraw = NULL, .config = monster_fdc_config diff --git a/src/floppy/fdc_pii15xb.c b/src/floppy/fdc_pii15xb.c index 013d6d39b..587eb64fa 100644 --- a/src/floppy/fdc_pii15xb.c +++ b/src/floppy/fdc_pii15xb.c @@ -97,8 +97,7 @@ pii_init(const device_t *info) { pii_t *dev; - dev = (pii_t *) malloc(sizeof(pii_t)); - memset(dev, 0, sizeof(pii_t)); + dev = (pii_t *) calloc(1, sizeof(pii_t)); if (BIOS_ADDR != 0) rom_init(&dev->bios_rom, DTK_VARIANT, BIOS_ADDR, 0x2000, 0x1ffff, 0, MEM_MAPPING_EXTERNAL); @@ -150,7 +149,7 @@ const device_t fdc_pii151b_device = { .init = pii_init, .close = pii_close, .reset = NULL, - { .available = pii_151b_available }, + .available = pii_151b_available, .speed_changed = NULL, .force_redraw = NULL, .config = pii_config @@ -164,7 +163,7 @@ const device_t fdc_pii158b_device = { .init = pii_init, .close = pii_close, .reset = NULL, - { .available = pii_158_available }, + .available = pii_158_available, .speed_changed = NULL, .force_redraw = NULL, .config = pii_config diff --git a/src/floppy/fdd_86f.c b/src/floppy/fdd_86f.c index 0e8a6590a..140e87899 100644 --- a/src/floppy/fdd_86f.c +++ b/src/floppy/fdd_86f.c @@ -2731,8 +2731,7 @@ d86f_prepare_sector(int drive, int side, int prev_pos, uint8_t *id_buf, uint8_t uint16_t datadam_mfm = 0x4A55; if (fdd_get_turbo(drive) && (dev->version == 0x0063)) { - s = (sector_t *) malloc(sizeof(sector_t)); - memset(s, 0, sizeof(sector_t)); + s = (sector_t *) calloc(1, sizeof(sector_t)); s->c = id_buf[0]; s->h = id_buf[1]; s->r = id_buf[2]; @@ -3921,8 +3920,7 @@ d86f_setup(int drive) d86f_t *dev; /* Allocate a drive structure. */ - dev = (d86f_t *) malloc(sizeof(d86f_t)); - memset(dev, 0x00, sizeof(d86f_t)); + dev = (d86f_t *) calloc(1, sizeof(d86f_t)); dev->state = STATE_IDLE; dev->last_side_sector[0] = NULL; diff --git a/src/floppy/fdd_fdi.c b/src/floppy/fdd_fdi.c index f14bf2cd4..97b6441a0 100644 --- a/src/floppy/fdd_fdi.c +++ b/src/floppy/fdd_fdi.c @@ -316,15 +316,13 @@ fdi_load(int drive, char *fn) writeprot[drive] = fwriteprot[drive] = 1; /* Allocate a drive block. */ - dev = (fdi_t *) malloc(sizeof(fdi_t)); + dev = (fdi_t *) calloc(1, sizeof(fdi_t)); if (dev == NULL) { memset(floppyfns[drive], 0, sizeof(floppyfns[drive])); return; } - memset(dev, 0x00, sizeof(fdi_t)); - d86f_unregister(drive); dev->fp = plat_fopen(fn, "rb"); diff --git a/src/floppy/fdd_imd.c b/src/floppy/fdd_imd.c index 0839c2900..7994530ed 100644 --- a/src/floppy/fdd_imd.c +++ b/src/floppy/fdd_imd.c @@ -635,8 +635,7 @@ imd_load(int drive, char *fn) writeprot[drive] = 0; /* Allocate a drive block. */ - dev = (imd_t *) malloc(sizeof(imd_t)); - memset(dev, 0x00, sizeof(imd_t)); + dev = (imd_t *) calloc(1, sizeof(imd_t)); dev->fp = plat_fopen(fn, "rb+"); if (dev->fp == NULL) { diff --git a/src/floppy/fdd_img.c b/src/floppy/fdd_img.c index 69a753ef5..30e0212cd 100644 --- a/src/floppy/fdd_img.c +++ b/src/floppy/fdd_img.c @@ -681,8 +681,7 @@ img_load(int drive, char *fn) writeprot[drive] = 0; /* Allocate a drive block. */ - dev = (img_t *) malloc(sizeof(img_t)); - memset(dev, 0x00, sizeof(img_t)); + dev = (img_t *) calloc(1, sizeof(img_t)); dev->fp = plat_fopen(fn, "rb+"); if (dev->fp == NULL) { diff --git a/src/floppy/fdd_mfm.c b/src/floppy/fdd_mfm.c index a332d25c9..87da4e08b 100644 --- a/src/floppy/fdd_mfm.c +++ b/src/floppy/fdd_mfm.c @@ -396,8 +396,7 @@ mfm_load(int drive, char *fn) writeprot[drive] = fwriteprot[drive] = 1; /* Allocate a drive block. */ - dev = (mfm_t *) malloc(sizeof(mfm_t)); - memset(dev, 0x00, sizeof(mfm_t)); + dev = (mfm_t *) calloc(1, sizeof(mfm_t)); dev->fp = plat_fopen(fn, "rb"); if (dev->fp == NULL) { diff --git a/src/floppy/fdd_pcjs.c b/src/floppy/fdd_pcjs.c index 76f8ca7dc..6f69042b0 100644 --- a/src/floppy/fdd_pcjs.c +++ b/src/floppy/fdd_pcjs.c @@ -469,7 +469,7 @@ track_flags(int drive) } static void -set_sector(int drive, int side, uint8_t c, uint8_t h, uint8_t r, uint8_t n) +set_sector(int drive, int side, uint8_t c, UNUSED(uint8_t h), uint8_t r, UNUSED(uint8_t n)) { pcjs_t *dev = images[drive]; @@ -617,8 +617,7 @@ pcjs_load(int drive, char *fn) d86f_unregister(drive); /* Allocate a drive block */ - dev = (pcjs_t *) malloc(sizeof(pcjs_t)); - memset(dev, 0x00, sizeof(pcjs_t)); + dev = (pcjs_t *) calloc(1, sizeof(pcjs_t)); /* Open the image file, read-only */ dev->fp = plat_fopen(fn, "rb"); diff --git a/src/floppy/fdd_td0.c b/src/floppy/fdd_td0.c index 0bf4b1c71..f5882158b 100644 --- a/src/floppy/fdd_td0.c +++ b/src/floppy/fdd_td0.c @@ -1214,8 +1214,7 @@ td0_load(int drive, char *fn) writeprot[drive] = 1; - dev = (td0_t *) malloc(sizeof(td0_t)); - memset(dev, 0x00, sizeof(td0_t)); + dev = (td0_t *) calloc(1, sizeof(td0_t)); td0[drive] = dev; dev->fp = plat_fopen(fn, "rb"); diff --git a/src/game/gameport.c b/src/game/gameport.c index 8d2a684fc..39193af88 100644 --- a/src/game/gameport.c +++ b/src/game/gameport.c @@ -8,8 +8,6 @@ * * Implementation of a generic Game Port. * - * - * * Authors: Miran Grca, * Sarah Walker, * RichardG, @@ -18,7 +16,7 @@ * Copyright 2016-2022 Miran Grca. * Copyright 2008-2018 Sarah Walker. * Copyright 2021 RichardG. - * Copyright 2021-2024 Jasmine Iwanek. + * Copyright 2021-2025 Jasmine Iwanek. */ #include #include @@ -35,6 +33,12 @@ #include <86box/gameport.h> #include <86box/plat_unused.h> +device_t game_ports[GAMEPORT_MAX]; + +typedef struct { + const device_t *device; +} GAMEPORT; + typedef struct g_axis_t { pc_timer_t timer; int axis_nr; @@ -48,6 +52,11 @@ typedef struct _gameport_ { struct _gameport_ *next; } gameport_t; +typedef struct _tmacm_ { + struct gameport_t *port1; + struct gameport_t *port2; +} tmacm_t; + typedef struct _joystick_instance_ { uint8_t state; g_axis_t axis[4]; @@ -93,7 +102,7 @@ static const struct { { NULL } }; -static joystick_instance_t *joystick_instance = NULL; +static joystick_instance_t *joystick_instance[GAMEPORT_MAX] = { NULL, NULL }; static uint8_t gameport_pnp_rom[] = { 0x09, 0xf8, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, /* BOX0002, dummy checksum (filled in by isapnp_add_card) */ @@ -275,10 +284,10 @@ gameport_update_joystick_type(void) gameport_add(standalone_gameport_type); /* Reset the joystick interface. */ - if (joystick_instance) { - joystick_instance->intf->close(joystick_instance->dat); - joystick_instance->intf = joysticks[joystick_type].joystick; - joystick_instance->dat = joystick_instance->intf->init(); + if (joystick_instance[0]) { + joystick_instance[0]->intf->close(joystick_instance[0]->dat); + joystick_instance[0]->intf = joysticks[joystick_type].joystick; + joystick_instance[0]->dat = joystick_instance[0]->intf->init(); } } @@ -357,36 +366,32 @@ gameport_add(const device_t *gameport_type) static void * gameport_init(const device_t *info) { - gameport_t *dev = NULL; - - dev = malloc(sizeof(gameport_t)); - memset(dev, 0x00, sizeof(gameport_t)); + gameport_t *dev = calloc(1, sizeof(gameport_t)); /* Allocate global instance. */ - if (!joystick_instance && joystick_type) { - joystick_instance = malloc(sizeof(joystick_instance_t)); - memset(joystick_instance, 0x00, sizeof(joystick_instance_t)); + if (!joystick_instance[0] && joystick_type) { + joystick_instance[0] = calloc(1, sizeof(joystick_instance_t)); - joystick_instance->axis[0].joystick = joystick_instance; - joystick_instance->axis[1].joystick = joystick_instance; - joystick_instance->axis[2].joystick = joystick_instance; - joystick_instance->axis[3].joystick = joystick_instance; + joystick_instance[0]->axis[0].joystick = joystick_instance[0]; + joystick_instance[0]->axis[1].joystick = joystick_instance[0]; + joystick_instance[0]->axis[2].joystick = joystick_instance[0]; + joystick_instance[0]->axis[3].joystick = joystick_instance[0]; - joystick_instance->axis[0].axis_nr = 0; - joystick_instance->axis[1].axis_nr = 1; - joystick_instance->axis[2].axis_nr = 2; - joystick_instance->axis[3].axis_nr = 3; + joystick_instance[0]->axis[0].axis_nr = 0; + joystick_instance[0]->axis[1].axis_nr = 1; + joystick_instance[0]->axis[2].axis_nr = 2; + joystick_instance[0]->axis[3].axis_nr = 3; - timer_add(&joystick_instance->axis[0].timer, timer_over, &joystick_instance->axis[0], 0); - timer_add(&joystick_instance->axis[1].timer, timer_over, &joystick_instance->axis[1], 0); - timer_add(&joystick_instance->axis[2].timer, timer_over, &joystick_instance->axis[2], 0); - timer_add(&joystick_instance->axis[3].timer, timer_over, &joystick_instance->axis[3], 0); + timer_add(&joystick_instance[0]->axis[0].timer, timer_over, &joystick_instance[0]->axis[0], 0); + timer_add(&joystick_instance[0]->axis[1].timer, timer_over, &joystick_instance[0]->axis[1], 0); + timer_add(&joystick_instance[0]->axis[2].timer, timer_over, &joystick_instance[0]->axis[2], 0); + timer_add(&joystick_instance[0]->axis[3].timer, timer_over, &joystick_instance[0]->axis[3], 0); - joystick_instance->intf = joysticks[joystick_type].joystick; - joystick_instance->dat = joystick_instance->intf->init(); + joystick_instance[0]->intf = joysticks[joystick_type].joystick; + joystick_instance[0]->dat = joystick_instance[0]->intf->init(); } - dev->joystick = joystick_instance; + dev->joystick = joystick_instance[0]; /* Map game port to the default address. Not applicable on PnP-only ports. */ dev->len = (info->local >> 16) & 0xff; @@ -402,25 +407,24 @@ gameport_init(const device_t *info) static void * tmacm_init(UNUSED(const device_t *info)) { - uint16_t port = 0x0000; - gameport_t *dev = NULL; + uint16_t port = 0x0000; + tmacm_t *dev = NULL; - dev = malloc(sizeof(gameport_t)); - memset(dev, 0x00, sizeof(gameport_t)); + dev = calloc(1, sizeof(tmacm_t)); port = (uint16_t) device_get_config_hex16("port1_addr"); switch (port) { case 0x201: - dev = gameport_add(&gameport_201_device); + dev->port1 = gameport_add(&gameport_201_device); break; case 0x203: - dev = gameport_add(&gameport_203_device); + dev->port1 = gameport_add(&gameport_203_device); break; case 0x205: - dev = gameport_add(&gameport_205_device); + dev->port1 = gameport_add(&gameport_205_device); break; case 0x207: - dev = gameport_add(&gameport_207_device); + dev->port1 = gameport_add(&gameport_207_device); break; default: break; @@ -429,16 +433,16 @@ tmacm_init(UNUSED(const device_t *info)) port = (uint16_t) device_get_config_hex16("port2_addr"); switch (port) { case 0x209: - dev = gameport_add(&gameport_209_device); + dev->port2 = gameport_add(&gameport_209_device); break; case 0x20b: - dev = gameport_add(&gameport_20b_device); + dev->port2 = gameport_add(&gameport_20b_device); break; case 0x20d: - dev = gameport_add(&gameport_20d_device); + dev->port2 = gameport_add(&gameport_20d_device); break; case 0x20f: - dev = gameport_add(&gameport_20f_device); + dev->port2 = gameport_add(&gameport_20f_device); break; default: break; @@ -456,11 +460,11 @@ gameport_close(void *priv) gameport_remap(dev, 0); /* Free the global instance here, if it wasn't already freed. */ - if (joystick_instance) { - joystick_instance->intf->close(joystick_instance->dat); + if (joystick_instance[0]) { + joystick_instance[0]->intf->close(joystick_instance[0]->dat); - free(joystick_instance); - joystick_instance = NULL; + free(joystick_instance[0]); + joystick_instance[0] = NULL; } free(dev); @@ -474,7 +478,7 @@ const device_t gameport_device = { .init = gameport_init, .close = gameport_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -488,7 +492,7 @@ const device_t gameport_201_device = { .init = gameport_init, .close = gameport_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -502,7 +506,7 @@ const device_t gameport_203_device = { .init = gameport_init, .close = gameport_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -516,7 +520,7 @@ const device_t gameport_205_device = { .init = gameport_init, .close = gameport_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -530,7 +534,7 @@ const device_t gameport_207_device = { .init = gameport_init, .close = gameport_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -544,7 +548,7 @@ const device_t gameport_208_device = { .init = gameport_init, .close = gameport_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -558,7 +562,7 @@ const device_t gameport_209_device = { .init = gameport_init, .close = gameport_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -572,7 +576,7 @@ const device_t gameport_20b_device = { .init = gameport_init, .close = gameport_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -586,7 +590,7 @@ const device_t gameport_20d_device = { .init = gameport_init, .close = gameport_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -600,7 +604,7 @@ const device_t gameport_20f_device = { .init = gameport_init, .close = gameport_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -642,7 +646,7 @@ static const device_config_t tmacm_config[] = { { "" } } }, - { "", "", -1 } + { .name = "", .description = "", .type = CONFIG_END } // clang-format on }; @@ -654,7 +658,7 @@ const device_t gameport_tm_acm_device = { .init = tmacm_init, .close = NULL, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = tmacm_config @@ -668,7 +672,7 @@ const device_t gameport_pnp_device = { .init = gameport_init, .close = gameport_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -682,7 +686,7 @@ const device_t gameport_pnp_1io_device = { .init = gameport_init, .close = gameport_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -696,7 +700,7 @@ const device_t gameport_pnp_6io_device = { .init = gameport_init, .close = gameport_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -710,7 +714,7 @@ const device_t gameport_sio_device = { .init = gameport_init, .close = gameport_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -724,8 +728,68 @@ const device_t gameport_sio_1io_device = { .init = gameport_init, .close = gameport_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL }; + +static const GAMEPORT gameports[] = { + { &device_none }, + { &device_internal }, + { &gameport_device }, + { &gameport_208_device }, + { &gameport_pnp_device }, + { &gameport_tm_acm_device }, + { NULL } + // clang-format on +}; + +/* UI */ +int +gameport_available(int port) +{ + if (gameports[port].device) + return (device_available(gameports[port].device)); + + return 1; +} + +/* UI */ +const device_t * +gameports_getdevice(int port) +{ + return (gameports[port].device); +} + +/* UI */ +int +gameport_has_config(int port) +{ + if (!gameports[port].device) + return 0; + + return (device_has_config(gameports[port].device) ? 1 : 0); +} + +/* UI */ +const char * +gameport_get_internal_name(int port) +{ + return device_get_internal_name(gameports[port].device); +} + +/* UI */ +int +gameport_get_from_internal_name(const char *str) +{ + int c = 0; + + while (gameports[c].device != NULL) { + if (!strcmp(gameports[c].device->internal_name, str)) + return c; + c++; + } + + return 0; +} diff --git a/src/game/joystick_ch_flightstick_pro.c b/src/game/joystick_ch_flightstick_pro.c index 8ca51d531..6aaaa5dc5 100644 --- a/src/game/joystick_ch_flightstick_pro.c +++ b/src/game/joystick_ch_flightstick_pro.c @@ -62,23 +62,23 @@ ch_flightstick_pro_read(UNUSED(void *priv)) { uint8_t ret = 0xf0; - if (JOYSTICK_PRESENT(0)) { - if (joystick_state[0].button[0]) + if (JOYSTICK_PRESENT(0, 0)) { + if (joystick_state[0][0].button[0]) ret &= ~0x10; - if (joystick_state[0].button[1]) + if (joystick_state[0][0].button[1]) ret &= ~0x20; - if (joystick_state[0].button[2]) + if (joystick_state[0][0].button[2]) ret &= ~0x40; - if (joystick_state[0].button[3]) + if (joystick_state[0][0].button[3]) ret &= ~0x80; - if (joystick_state[0].pov[0] != -1) { - if (joystick_state[0].pov[0] > 315 || joystick_state[0].pov[0] < 45) + if (joystick_state[0][0].pov[0] != -1) { + if (joystick_state[0][0].pov[0] > 315 || joystick_state[0][0].pov[0] < 45) ret &= ~0xf0; - else if (joystick_state[0].pov[0] >= 45 && joystick_state[0].pov[0] < 135) + else if (joystick_state[0][0].pov[0] >= 45 && joystick_state[0][0].pov[0] < 135) ret &= ~0xb0; - else if (joystick_state[0].pov[0] >= 135 && joystick_state[0].pov[0] < 225) + else if (joystick_state[0][0].pov[0] >= 135 && joystick_state[0][0].pov[0] < 225) ret &= ~0x70; - else if (joystick_state[0].pov[0] >= 225 && joystick_state[0].pov[0] < 315) + else if (joystick_state[0][0].pov[0] >= 225 && joystick_state[0][0].pov[0] < 315) ret &= ~0x30; } } @@ -95,18 +95,18 @@ ch_flightstick_pro_write(UNUSED(void *priv)) static int ch_flightstick_pro_read_axis(UNUSED(void *priv), int axis) { - if (!JOYSTICK_PRESENT(0)) + if (!JOYSTICK_PRESENT(0, 0)) return AXIS_NOT_PRESENT; switch (axis) { case 0: - return joystick_state[0].axis[0]; + return joystick_state[0][0].axis[0]; case 1: - return joystick_state[0].axis[1]; + return joystick_state[0][0].axis[1]; case 2: return 0; case 3: - return joystick_state[0].axis[2]; + return joystick_state[0][0].axis[2]; default: return 0; } diff --git a/src/game/joystick_standard.c b/src/game/joystick_standard.c index 201574126..122d2c65f 100644 --- a/src/game/joystick_standard.c +++ b/src/game/joystick_standard.c @@ -63,10 +63,10 @@ joystick_standard_read(UNUSED(void *priv)) uint8_t ret = 0xf0; for (int js = 0; js < 2; js++) { - if (JOYSTICK_PRESENT(js)) { - if (joystick_state[js].button[0]) + if (JOYSTICK_PRESENT(0, js)) { + if (joystick_state[0][js].button[0]) ret &= ~0x10; - if (joystick_state[js].button[1]) + if (joystick_state[0][js].button[1]) ret &= ~0x20; } } @@ -79,14 +79,14 @@ joystick_standard_read_4button(UNUSED(void *priv)) { uint8_t ret = 0xf0; - if (JOYSTICK_PRESENT(0)) { - if (joystick_state[0].button[0]) + if (JOYSTICK_PRESENT(0, 0)) { + if (joystick_state[0][0].button[0]) ret &= ~0x10; - if (joystick_state[0].button[1]) + if (joystick_state[0][0].button[1]) ret &= ~0x20; - if (joystick_state[0].button[2]) + if (joystick_state[0][0].button[2]) ret &= ~0x40; - if (joystick_state[0].button[3]) + if (joystick_state[0][0].button[3]) ret &= ~0x80; } @@ -104,21 +104,21 @@ joystick_standard_read_axis(UNUSED(void *priv), int axis) { switch (axis) { case 0: - if (!JOYSTICK_PRESENT(0)) + if (!JOYSTICK_PRESENT(0, 0)) return AXIS_NOT_PRESENT; - return joystick_state[0].axis[0]; + return joystick_state[0][0].axis[0]; case 1: - if (!JOYSTICK_PRESENT(0)) + if (!JOYSTICK_PRESENT(0, 0)) return AXIS_NOT_PRESENT; - return joystick_state[0].axis[1]; + return joystick_state[0][0].axis[1]; case 2: - if (!JOYSTICK_PRESENT(1)) + if (!JOYSTICK_PRESENT(0, 1)) return AXIS_NOT_PRESENT; - return joystick_state[1].axis[0]; + return joystick_state[0][1].axis[0]; case 3: - if (!JOYSTICK_PRESENT(1)) + if (!JOYSTICK_PRESENT(0, 1)) return AXIS_NOT_PRESENT; - return joystick_state[1].axis[1]; + return joystick_state[0][1].axis[1]; default: return 0; } @@ -127,14 +127,14 @@ joystick_standard_read_axis(UNUSED(void *priv), int axis) static int joystick_standard_read_axis_4button(UNUSED(void *priv), int axis) { - if (!JOYSTICK_PRESENT(0)) + if (!JOYSTICK_PRESENT(0, 0)) return AXIS_NOT_PRESENT; switch (axis) { case 0: - return joystick_state[0].axis[0]; + return joystick_state[0][0].axis[0]; case 1: - return joystick_state[0].axis[1]; + return joystick_state[0][0].axis[1]; case 2: case 3: default: @@ -145,16 +145,16 @@ joystick_standard_read_axis_4button(UNUSED(void *priv), int axis) static int joystick_standard_read_axis_3axis(UNUSED(void *priv), int axis) { - if (!JOYSTICK_PRESENT(0)) + if (!JOYSTICK_PRESENT(0, 0)) return AXIS_NOT_PRESENT; switch (axis) { case 0: - return joystick_state[0].axis[0]; + return joystick_state[0][0].axis[0]; case 1: - return joystick_state[0].axis[1]; + return joystick_state[0][0].axis[1]; case 2: - return joystick_state[0].axis[2]; + return joystick_state[0][0].axis[2]; case 3: default: return 0; @@ -164,18 +164,18 @@ joystick_standard_read_axis_3axis(UNUSED(void *priv), int axis) static int joystick_standard_read_axis_4axis(UNUSED(void *priv), int axis) { - if (!JOYSTICK_PRESENT(0)) + if (!JOYSTICK_PRESENT(0, 0)) return AXIS_NOT_PRESENT; switch (axis) { case 0: - return joystick_state[0].axis[0]; + return joystick_state[0][0].axis[0]; case 1: - return joystick_state[0].axis[1]; + return joystick_state[0][0].axis[1]; case 2: - return joystick_state[0].axis[2]; + return joystick_state[0][0].axis[2]; case 3: - return joystick_state[0].axis[3]; + return joystick_state[0][0].axis[3]; default: return 0; } @@ -184,18 +184,18 @@ joystick_standard_read_axis_4axis(UNUSED(void *priv), int axis) static int joystick_standard_read_axis_6button(UNUSED(void *priv), int axis) { - if (!JOYSTICK_PRESENT(0)) + if (!JOYSTICK_PRESENT(0, 0)) return AXIS_NOT_PRESENT; switch (axis) { case 0: - return joystick_state[0].axis[0]; + return joystick_state[0][0].axis[0]; case 1: - return joystick_state[0].axis[1]; + return joystick_state[0][0].axis[1]; case 2: - return joystick_state[0].button[4] ? -32767 : 32768; + return joystick_state[0][0].button[4] ? -32767 : 32768; case 3: - return joystick_state[0].button[5] ? -32767 : 32768; + return joystick_state[0][0].button[5] ? -32767 : 32768; default: return 0; } @@ -203,24 +203,24 @@ joystick_standard_read_axis_6button(UNUSED(void *priv), int axis) static int joystick_standard_read_axis_8button(UNUSED(void *priv), int axis) { - if (!JOYSTICK_PRESENT(0)) + if (!JOYSTICK_PRESENT(0, 0)) return AXIS_NOT_PRESENT; switch (axis) { case 0: - return joystick_state[0].axis[0]; + return joystick_state[0][0].axis[0]; case 1: - return joystick_state[0].axis[1]; + return joystick_state[0][0].axis[1]; case 2: - if (joystick_state[0].button[4]) + if (joystick_state[0][0].button[4]) return -32767; - if (joystick_state[0].button[6]) + if (joystick_state[0][0].button[6]) return 32768; return 0; case 3: - if (joystick_state[0].button[5]) + if (joystick_state[0][0].button[5]) return -32767; - if (joystick_state[0].button[7]) + if (joystick_state[0][0].button[7]) return 32768; return 0; default: diff --git a/src/game/joystick_sw_pad.c b/src/game/joystick_sw_pad.c index 238e84d11..bfdc0e025 100644 --- a/src/game/joystick_sw_pad.c +++ b/src/game/joystick_sw_pad.c @@ -141,7 +141,7 @@ sw_read(void *priv) sw_data *sw = (sw_data *) priv; uint8_t temp = 0; - if (!JOYSTICK_PRESENT(0)) + if (!JOYSTICK_PRESENT(0, 0)) return 0xff; if (timer_is_enabled(&sw->poll_timer)) { @@ -167,7 +167,7 @@ sw_write(void *priv) sw_data *sw = (sw_data *) priv; int64_t time_since_last = timer_get_remaining_us(&sw->trigger_timer); - if (!JOYSTICK_PRESENT(0)) + if (!JOYSTICK_PRESENT(0, 0)) return; if (!sw->poll_left) { @@ -193,20 +193,20 @@ sw_write(void *priv) for (uint8_t js = 0; js < 4; js++) { uint16_t data = 0x3fff; - if (!JOYSTICK_PRESENT(js)) + if (!JOYSTICK_PRESENT(0, js)) break; - if (joystick_state[js].axis[1] < -16383) + if (joystick_state[0][js].axis[1] < -16383) data &= ~1; - if (joystick_state[js].axis[1] > 16383) + if (joystick_state[0][js].axis[1] > 16383) data &= ~2; - if (joystick_state[js].axis[0] > 16383) + if (joystick_state[0][js].axis[0] > 16383) data &= ~4; - if (joystick_state[js].axis[0] < -16383) + if (joystick_state[0][js].axis[0] < -16383) data &= ~8; for (uint8_t button_nr = 0; button_nr < 10; button_nr++) { - if (joystick_state[js].button[button_nr]) + if (joystick_state[0][js].button[button_nr]) data &= ~(1 << (button_nr + 4)); } @@ -230,7 +230,7 @@ sw_write(void *priv) static int sw_read_axis(UNUSED(void *priv), UNUSED(int axis)) { - if (!JOYSTICK_PRESENT(0)) + if (!JOYSTICK_PRESENT(0, 0)) return AXIS_NOT_PRESENT; return 0; /*No analogue support on Sidewinder game pad*/ diff --git a/src/game/joystick_tm_fcs.c b/src/game/joystick_tm_fcs.c index f5c1e64e6..4440b039e 100644 --- a/src/game/joystick_tm_fcs.c +++ b/src/game/joystick_tm_fcs.c @@ -62,14 +62,14 @@ tm_fcs_read(UNUSED(void *priv)) { uint8_t ret = 0xf0; - if (JOYSTICK_PRESENT(0)) { - if (joystick_state[0].button[0]) + if (JOYSTICK_PRESENT(0, 0)) { + if (joystick_state[0][0].button[0]) ret &= ~0x10; - if (joystick_state[0].button[1]) + if (joystick_state[0][0].button[1]) ret &= ~0x20; - if (joystick_state[0].button[2]) + if (joystick_state[0][0].button[2]) ret &= ~0x40; - if (joystick_state[0].button[3]) + if (joystick_state[0][0].button[3]) ret &= ~0x80; } @@ -85,26 +85,26 @@ tm_fcs_write(UNUSED(void *priv)) static int tm_fcs_read_axis(UNUSED(void *priv), int axis) { - if (!JOYSTICK_PRESENT(0)) + if (!JOYSTICK_PRESENT(0, 0)) return AXIS_NOT_PRESENT; switch (axis) { case 0: - return joystick_state[0].axis[0]; + return joystick_state[0][0].axis[0]; case 1: - return joystick_state[0].axis[1]; + return joystick_state[0][0].axis[1]; case 2: return 0; case 3: - if (joystick_state[0].pov[0] == -1) + if (joystick_state[0][0].pov[0] == -1) return 32767; - if (joystick_state[0].pov[0] > 315 || joystick_state[0].pov[0] < 45) + if (joystick_state[0][0].pov[0] > 315 || joystick_state[0][0].pov[0] < 45) return -32768; - if (joystick_state[0].pov[0] >= 45 && joystick_state[0].pov[0] < 135) + if (joystick_state[0][0].pov[0] >= 45 && joystick_state[0][0].pov[0] < 135) return -16384; - if (joystick_state[0].pov[0] >= 135 && joystick_state[0].pov[0] < 225) + if (joystick_state[0][0].pov[0] >= 135 && joystick_state[0][0].pov[0] < 225) return 0; - if (joystick_state[0].pov[0] >= 225 && joystick_state[0].pov[0] < 315) + if (joystick_state[0][0].pov[0] >= 225 && joystick_state[0][0].pov[0] < 315) return 16384; return 0; default: diff --git a/src/include/86box/86box.h b/src/include/86box/86box.h index 96aeb645c..6f6caf743 100644 --- a/src/include/86box/86box.h +++ b/src/include/86box/86box.h @@ -8,14 +8,14 @@ * * Main include file for the application. * - * - * * Authors: Miran Grca, * Fred N. van Kempen, + * Jasmine Iwanek, * * Copyright 2016-2020 Miran Grca. * Copyright 2017-2020 Fred N. van Kempen. * Copyright 2021 Laci bá' + * Copyright 2021-2025 Jasmine Iwanek. */ #ifndef EMU_86BOX_H #define EMU_86BOX_H @@ -33,7 +33,7 @@ #define SCREENSHOT_PATH "screenshots" /* Recently used images */ -#define MAX_PREV_IMAGES 4 +#define MAX_PREV_IMAGES 10 #define MAX_IMAGE_PATH_LEN 2048 /* Max UUID Length */ @@ -131,6 +131,7 @@ extern int bugger_enabled; /* (C) enable ISAbugger */ extern int novell_keycard_enabled; /* (C) enable Novell NetWare 2.x key card emulation. */ extern int postcard_enabled; /* (C) enable POST card */ extern int unittester_enabled; /* (C) enable unit tester device */ +extern int gameport_type[]; /* (C) enable gameports */ extern int isamem_type[]; /* (C) enable ISA mem cards */ extern int isartc_type; /* (C) enable ISA RTC card */ extern int sound_is_float; /* (C) sound uses FP values */ diff --git a/src/include/86box/bswap.h b/src/include/86box/bswap.h index f7d3a3d0e..37c846d59 100644 --- a/src/include/86box/bswap.h +++ b/src/include/86box/bswap.h @@ -133,12 +133,12 @@ bswap64s(uint64_t *s) return endian##_bswap(v, size); \ } \ \ - static __inline void endian##size##_to_cpus(type *p) \ + static __inline void endian##size##_to_cpus(UNUSED(type *p)) \ { \ endian##_bswaps(p, size) \ } \ \ - static __inline void cpu_to_##endian##size##s(type *p) \ + static __inline void cpu_to_##endian##size##s(UNUSED(type *p)) \ { \ endian##_bswaps(p, size) \ } \ diff --git a/src/include/86box/cartridge.h b/src/include/86box/cartridge.h index 2ea7ec734..2b0662703 100644 --- a/src/include/86box/cartridge.h +++ b/src/include/86box/cartridge.h @@ -21,7 +21,7 @@ extern "C" { #endif -#define CART_IMAGE_HISTORY 4 +#define CART_IMAGE_HISTORY 10 extern char cart_fns[2][512]; extern char *cart_image_history[2][CART_IMAGE_HISTORY]; diff --git a/src/include/86box/cassette.h b/src/include/86box/cassette.h index bb0899e24..168d82099 100644 --- a/src/include/86box/cassette.h +++ b/src/include/86box/cassette.h @@ -153,7 +153,7 @@ void pc_cas_print_state(const pc_cassette_t *cas); void pc_cas_clock(pc_cassette_t *cas, unsigned long cnt); void pc_cas_advance(pc_cassette_t *cas); -#define CASSETTE_IMAGE_HISTORY 4 +#define CASSETTE_IMAGE_HISTORY 10 extern pc_cassette_t *cassette; diff --git a/src/include/86box/cdrom.h b/src/include/86box/cdrom.h index f28bba517..7c028d7d6 100644 --- a/src/include/86box/cdrom.h +++ b/src/include/86box/cdrom.h @@ -15,32 +15,40 @@ #ifndef EMU_CDROM_H #define EMU_CDROM_H +#ifndef EMU_VERSION_H +#include <86box/version.h> +#endif + #define CDROM_NUM 8 #define CD_STATUS_EMPTY 0 #define CD_STATUS_DATA_ONLY 1 -#define CD_STATUS_PAUSED 2 -#define CD_STATUS_PLAYING 3 -#define CD_STATUS_STOPPED 4 -#define CD_STATUS_PLAYING_COMPLETED 5 +#define CD_STATUS_DVD 2 +#define CD_STATUS_PAUSED 4 +#define CD_STATUS_PLAYING 5 +#define CD_STATUS_STOPPED 6 +#define CD_STATUS_PLAYING_COMPLETED 7 +#define CD_STATUS_HAS_AUDIO 4 +#define CD_STATUS_MASK 7 /* Medium changed flag. */ #define CD_STATUS_TRANSITION 0x40 #define CD_STATUS_MEDIUM_CHANGED 0x80 -#define CD_TRACK_UNK_DATA 0x10 +#define CD_TRACK_UNK_DATA 0x04 +#define CD_TRACK_NORMAL 0x00 #define CD_TRACK_AUDIO 0x08 +#define CD_TRACK_CDI 0x10 +#define CD_TRACK_XA 0x20 +#define CD_TRACK_MODE_MASK 0x30 #define CD_TRACK_MODE2 0x04 - -#define CD_READ_DATA 0 -#define CD_READ_AUDIO 1 -#define CD_READ_RAW 2 +#define CD_TRACK_MODE2_MASK 0x07 #define CD_TOC_NORMAL 0 #define CD_TOC_SESSION 1 #define CD_TOC_RAW 2 -#define CD_IMAGE_HISTORY 4 +#define CD_IMAGE_HISTORY 10 #define BUF_SIZE 32768 @@ -48,7 +56,34 @@ /* 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 +#define CDROM_EMPTY !dev->host_drive + +#define DVD_LAYER_0_SECTORS 0x00210558ULL + +#define RAW_SECTOR_SIZE 2352 +#define COOKED_SECTOR_SIZE 2048 + +#define DATA_TRACK 0x14 +#define AUDIO_TRACK 0x10 + +#define CD_FPS 75 + +#define FRAMES_TO_MSF(f, M, S, F) \ + { \ + uint64_t value = f; \ + *(F) = (value % CD_FPS) & 0xff; \ + value /= CD_FPS; \ + *(S) = (value % 60) & 0xff; \ + value /= 60; \ + *(M) = value & 0xff; \ + } +#define MSF_TO_FRAMES(M, S, F) ((M) *60 * CD_FPS + (S) *CD_FPS + (F)) + +typedef struct SMSF { + uint16_t min; + uint8_t sec; + uint8_t fr; +} TMSF; #ifdef __cplusplus extern "C" { @@ -62,161 +97,125 @@ enum { CDROM_BUS_USB = 8 }; -enum -{ - CDROM_TYPE_86BOX_100, - CDROM_TYPE_ASUS_CDS500_141, - CDROM_TYPE_ASUS_CDS520_132, - CDROM_TYPE_AZT_CDA46802I_115, - CDROM_TYPE_BTC_BCD36XH_U10, - CDROM_TYPE_GOLDSTAR_CRD_8160B_314, - CDROM_TYPE_HITACHI_CDR_8130_0020, - CDROM_TYPE_HITACHI_GD7500_A1, - CDROM_TYPE_HLDTST_GCR8526B_101, - CDROM_TYPE_HLDTST_GSA4160_A302, - CDROM_TYPE_KENWOOD_UCR_421_208E, - CDROM_TYPE_LG_CRN8245B_130, - CDROM_TYPE_LG_CRD8322B_106, - CDROM_TYPE_LTN48125S_1S07, - CDROM_TYPE_LTN526D_YSR5, - CDROM_TYPE_MATSHITA_583_107, - CDROM_TYPE_MATSHITA_585_Z18P, - CDROM_TYPE_MATSHITA_587_7S13, - CDROM_TYPE_MATSHITA_588_LS15, - CDROM_TYPE_MATSHITA_571_10e, - CDROM_TYPE_MATSHITA_572_10j, - CDROM_TYPE_MITSUMI_FX4820T_D02A, - CDROM_TYPE_NEC_260_100, - CDROM_TYPE_NEC_260_101, - CDROM_TYPE_NEC_273_420, - CDROM_TYPE_NEC_280_105, - CDROM_TYPE_NEC_280_308, - CDROM_TYPE_NEC_CDR_1900A_100, - CDROM_TYPE_PHILIPS_PCA403CD_U31P, - CDROM_TYPE_SONY_CDU76_10i, - CDROM_TYPE_SONY_CDU311_30h, - CDROM_TYPE_SONY_CDU5225_NYS4, - CDROM_TYPE_TEAC_CD516E_10G, - CDROM_TYPE_TEAC_CD524EA_30D, - CDROM_TYPE_TEAC_CD532E_20A, - CDROM_TYPE_TOSHIBA_5302TA_0305, - CDROM_TYPE_TOSHIBA_5702B_TA70, - CDROM_TYPE_TOSHIBA_6202B_1512, - CDROM_TYPE_TOSHIBA_6402B_1008, - CDROM_TYPE_TOSHIBA_6702B_1007, - CDROM_TYPE_TOSHIBA_M1802_1051, - CDROM_TYPE_CHINON_CDS431_H42, - CDROM_TYPE_CHINON_CDX435_M62, - CDROM_TYPE_DEC_RRD45_0436, - CDROM_TYPE_MATSHITA_501_10b, - CDROM_TYPE_NEC_25_10a, - CDROM_TYPE_NEC_38_103, - CDROM_TYPE_NEC_75_103, - CDROM_TYPE_NEC_77_106, - CDROM_TYPE_NEC_211_100, - CDROM_TYPE_NEC_464_105, - CDROM_TYPE_ShinaKen_DM3x1S_104, - CDROM_TYPE_SONY_CDU541_10i, - CDROM_TYPE_SONY_CDU561_18k, - CDROM_TYPE_SONY_CDU76S_100, - CDROM_TYPE_PHILIPS_CDD2600_107, - CDROM_TYPE_PIONEER_DRM604X_2403, - CDROM_TYPE_PLEXTOR_PX32TS_103, - CDROM_TYPE_TEAC_CD50_100, - CDROM_TYPE_TEAC_R55S_10R, - CDROM_TYPE_TEXEL_DM3024_100, - CDROM_TYPE_TEXEL_DM3028_106, - CDROM_TYPE_TOSHIBA_XM_3433, - CDROM_TYPE_TOSHIBA_XM3201B_3232, - CDROM_TYPE_TOSHIBA_XM3301TA_0272, - CDROM_TYPE_TOSHIBA_XM5701TA_3136, - CDROM_TYPE_TOSHIBA_SDM1401_1008, - CDROM_TYPES_NUM -}; - -#define KNOWN_CDROM_DRIVE_TYPES CDROM_TYPES_NUM #define BUS_TYPE_IDE CDROM_BUS_ATAPI #define BUS_TYPE_SCSI CDROM_BUS_SCSI #define BUS_TYPE_BOTH -2 #define BUS_TYPE_NONE -1 -static const struct -{ - const char vendor[9]; - const char model[17]; - const char revision[5]; - const char *name; - const char *internal_name; - const int bus_type; +#define CDV EMU_VERSION_EX + +static const struct cdrom_drive_types_s { + const char vendor[9]; + const char model[17]; + const char revision[5]; + const char * internal_name; + const int bus_type; + /* SCSI standard for SCSI (or both) devices, early for IDE. */ + const int scsi_std; + const int speed; + const int inquiry_len; + const int caddy; + const int transfer_max[4]; } cdrom_drive_types[] = { - { "86BOX", "CD-ROM", "1.00", "86BOX CD-ROM 1.00", "86BOX_CD-ROM_1.00", BUS_TYPE_BOTH }, - { "ASUS", "CD-S500/A", "1.41", "ASUS CD-S500/A 1.41", "ASUS_CD-S500A_1.41", BUS_TYPE_IDE }, - { "ASUS", "CD-S520/A4", "1.32", "ASUS CD-S520/A4 1.32", "ASUS_CD-S520A4_1.32", BUS_TYPE_IDE }, - { "AZT", "CDA46802I", "1.15", "AZT CDA46802I 1.15", "AZT_CDA46802I_1.15", BUS_TYPE_IDE }, - { "BTC", "CD-ROM BCD36XH", "U1.0", "BTC CD-ROM BCD36XH U1.0", "BTC_CD-ROM_BCD36XH_U1.0", BUS_TYPE_IDE }, - { "GOLDSTAR", "CRD-8160B", "3.14", "GOLDSTAR CRD-8160B 3.14", "GOLDSTAR_CRD-8160B_3.14", BUS_TYPE_IDE }, - { "HITACHI", "CDR-8130", "0020", "HITACHI CDR-8130 0020", "HITACHI_CDR-8130_0020", BUS_TYPE_IDE }, - { "HITACHI", "GD-7500", "A1 ", "HITACHI GD-7500 A1", "HITACHI_GD-7500_A1", BUS_TYPE_IDE }, - { "HL-DT-ST", "CD-ROM GCR-8526B", "1.01", "HL-DT-ST CD-ROM GCR-8526B 1.01", "HL-DT-ST_CD-ROM_GCR-8526B_1.01", BUS_TYPE_IDE }, - { "HL-DT-ST", "DVDRAM GSA-4160", "A302", "HL-DT-ST DVDRAM GSA-4160 A302", "HL-DT-ST_DVDRAM_GSA-4160_A302", BUS_TYPE_IDE }, - { "KENWOOD", "CD-ROM UCR-421", "208E", "KENWOOD CD-ROM UCR-421 208E", "KENWOOD_CD-ROM_UCR-421_208E", BUS_TYPE_IDE }, - { "LG", "CD-ROM CRN-8245B", "1.30", "LG CD-ROM CRN-8245B 1.30", "LG_CD-ROM_CRN-8245B_1.30", BUS_TYPE_IDE }, - { "LG", "CD-ROM CRD-8322B", "1.06", "LG CD-ROM CRD-8322B 1.06", "LG_CD-ROM_CRD-8322B_1.06", BUS_TYPE_IDE }, - { "LITE-ON", "LTN48125S", "1S07", "LITE-ON LTN48125S 1S07", "LITE-ON_LTN48125S_1S07", BUS_TYPE_IDE }, - { "LITE-ON", "LTN526D", "YSR5", "LITE-ON LTN526D YSR5", "LITE-ON_LTN526D_YSR5", BUS_TYPE_IDE }, - { "MATSHITA", "CD-ROM CR-583", "1.07", "MATSHITA CD-ROM CR-583 1.07", "MATSHITA_CD-ROM_CR-583_1.07", BUS_TYPE_IDE }, - { "MATSHITA", "CD-ROM CR-585", "Z18P", "MATSHITA CD-ROM CR-585 Z18P", "MATSHITA_CD-ROM_CR-585_Z18P", BUS_TYPE_IDE }, - { "MATSHITA", "CD-ROM CR-587", "7S13", "MATSHITA CD-ROM CR-587 7S13", "MATSHITA_CD-ROM_CR-587_7S13", BUS_TYPE_IDE }, - { "MATSHITA", "CD-ROM CR-588", "LS15", "MATSHITA CD-ROM CR-588 LS15", "MATSHITA_CD-ROM_CR-588_LS15", BUS_TYPE_IDE }, - { "MATSHITA", "CR-571", "1.0e", "MATSHITA CR-571 1.0e", "MATSHITA_CR-571_1.0e", BUS_TYPE_IDE }, - { "MATSHITA", "CR-572", "1.0j", "MATSHITA CR-572 1.0j", "MATSHITA_CR-572_1.0j", BUS_TYPE_IDE }, - { "MITSUMI", "CRMC-FX4820T", "D02A", "MITSUMI CRMC-FX4820T D02A", "MITSUMI_CRMC-FX4820T_D02A", BUS_TYPE_IDE }, - { "NEC", "CD-ROM DRIVE:260", "1.00", "NEC CD-ROM DRIVE:260 1.00", "NEC_CD-ROM_DRIVE260_1.00", BUS_TYPE_IDE }, - { "NEC", "CD-ROM DRIVE:260", "1.01", "NEC CD-ROM DRIVE:260 1.01", "NEC_CD-ROM_DRIVE260_1.01", BUS_TYPE_IDE }, - { "NEC", "CD-ROM DRIVE:273", "4.20", "NEC CD-ROM DRIVE:273 4.20", "NEC_CD-ROM_DRIVE273_4.20", BUS_TYPE_IDE }, - { "NEC", "CD-ROM DRIVE:280", "1.05", "NEC CD-ROM DRIVE:280 1.05", "NEC_CD-ROM_DRIVE280_1.05", BUS_TYPE_IDE }, - { "NEC", "CD-ROM DRIVE:280", "3.08", "NEC CD-ROM DRIVE:280 3.08", "NEC_CD-ROM_DRIVE280_3.08", BUS_TYPE_IDE }, - { "NEC", "CDR-1900A", "1.00", "NEC CDR-1900A 1.00", "NEC_CDR-1900A_1.00", BUS_TYPE_IDE }, - { "PHILIPS", "CD-ROM PCA403CD", "U31P", "PHILIPS CD-ROM PCA403CD U31P", "PHILIPS_CD-ROM_PCA403CD_U31P", BUS_TYPE_IDE }, - { "SONY", "CD-ROM CDU76", "1.0i", "SONY CD-ROM CDU76 1.0i", "SONY_CD-ROM_CDU76_1.0i", BUS_TYPE_IDE }, - { "SONY", "CD-ROM CDU311", "3.0h", "SONY CD-ROM CDU311 3.0h", "SONY_CD-ROM_CDU311_3.0h", BUS_TYPE_IDE }, - { "SONY", "CD-ROM CDU5225", "NYS4", "SONY CD-ROM CDU5225 NYS4", "SONY_CD-ROM_CDU5225_NYS4", BUS_TYPE_IDE }, - { "TEAC", "CD-516E", "1.0G", "TEAC CD-516E 1.0G", "TEAC_CD-516E_1.0G", BUS_TYPE_IDE }, - { "TEAC", "CD-524EA", "3.0D", "TEAC CD-524EA 3.0D", "TEAC_CD-524EA_3.0D", BUS_TYPE_IDE }, - { "TEAC", "CD-532E", "2.0A", "TEAC CD-532E 2.0A", "TEAC_CD_532E_2.0A", BUS_TYPE_IDE }, - { "TOSHIBA", "CD-ROM XM-5302TA", "0305", "TOSHIBA CD-ROM XM-5302TA 0305", "TOSHIBA_CD-ROM_XM-5302TA_0305", BUS_TYPE_IDE }, - { "TOSHIBA", "CD-ROM XM-5702B", "TA70", "TOSHIBA CD-ROM XM-5702B TA70", "TOSHIBA_CD-ROM_XM-5702B_TA70", BUS_TYPE_IDE }, - { "TOSHIBA", "CD-ROM XM-6202B", "1512", "TOSHIBA CD-ROM XM-6202B 1512", "TOSHIBA_CD-ROM_XM-6202B_1512", BUS_TYPE_IDE }, - { "TOSHIBA", "CD-ROM XM-6402B", "1008", "TOSHIBA CD-ROM XM-6402B 1008", "TOSHIBA_CD-ROM_XM-6402B_1008", BUS_TYPE_IDE }, - { "TOSHIBA", "CD-ROM XM-6702B", "1007", "TOSHIBA CD-ROM XM-6702B 1007", "TOSHIBA_CD-ROM_XM-6702B_1007", BUS_TYPE_IDE }, - { "TOSHIBA", "DVD-ROM SD-M1802", "1051", "TOSHIBA DVD-ROM SD-M1802 1051", "TOSHIBA_DVD-ROM_SD-M1802_1051", BUS_TYPE_IDE }, - { "CHINON", "CD-ROM CDS-431", "H42 ", "[SCSI-1] CHINON CD-ROM CDS-431 H42", "CHINON_CD-ROM_CDS-431_H42", BUS_TYPE_SCSI }, - { "CHINON", "CD-ROM CDX-435", "M62 ", "[SCSI-1] CHINON CD-ROM CDX-435 M62", "CHINON_CD-ROM_CDX-435_M62", BUS_TYPE_SCSI }, - { "DEC", "RRD45 (C) DEC", "0436", "[SCSI-1] DEC RRD45 0436", "DEC_RRD45_0436", BUS_TYPE_SCSI }, - { "MATSHITA", "CD-ROM CR-501", "1.0b", "[SCSI-1] MATSHITA CD-ROM CR-501 1.0b", "MATSHITA_CD-ROM_CR-501_1.0b", BUS_TYPE_SCSI }, - { "NEC", "CD-ROM DRIVE:25", "1.0a", "[SCSI-1] NEC CD-ROM DRIVE:25 1.0a", "NEC_CD-ROM_DRIVE25_1.0a", BUS_TYPE_SCSI }, - { "NEC", "CD-ROM DRIVE:38", "1.00", "[SCSI-2] NEC CD-ROM DRIVE:38 1.00", "NEC_CD-ROM_DRIVE38_1.00", BUS_TYPE_SCSI }, - { "NEC", "CD-ROM DRIVE:75", "1.03", "[SCSI-1] NEC CD-ROM DRIVE:75 1.03", "NEC_CD-ROM_DRIVE75_1.03", BUS_TYPE_SCSI }, - { "NEC", "CD-ROM DRIVE:77", "1.06", "[SCSI-1] NEC CD-ROM DRIVE:77 1.06", "NEC_CD-ROM_DRIVE77_1.06", BUS_TYPE_SCSI }, - { "NEC", "CD-ROM DRIVE:211", "1.00", "[SCSI-2] NEC CD-ROM DRIVE:211 1.00", "NEC_CD-ROM_DRIVE211_1.00", BUS_TYPE_SCSI }, - { "NEC", "CD-ROM DRIVE:464", "1.05", "[SCSI-2] NEC CD-ROM DRIVE:464 1.05", "NEC_CD-ROM_DRIVE464_1.05", BUS_TYPE_SCSI }, - { "ShinaKen", "CD-ROM DM-3x1S", "1.04", "[SCSI-1] ShinaKen CD-ROM DM-3x1S 1.04", "ShinaKen_CD-ROM_DM-3x1S_1.04", BUS_TYPE_SCSI }, - { "SONY", "CD-ROM CDU-541", "1.0i", "[SCSI-1] SONY CD-ROM CDU-541 1.0i", "SONY_CD-ROM_CDU-541_1.0i", BUS_TYPE_SCSI }, - { "SONY", "CD-ROM CDU-561", "1.8k", "[SCSI-2] SONY CD-ROM CDU-561 1.8k", "SONY_CD-ROM_CDU-561_1.8k", BUS_TYPE_SCSI }, - { "SONY", "CD-ROM CDU-76S", "1.00", "[SCSI-2] SONY CD-ROM CDU-76S 1.00", "SONY_CD-ROM_CDU-76S_1.00", BUS_TYPE_SCSI }, - { "PHILIPS", "CDD2600", "1.07", "[SCSI-2] PHILIPS CDD2600 1.07", "PHILIPS_CDD2600_1.07", BUS_TYPE_SCSI }, - { "PIONEER", "CD-ROM DRM-604X", "2403", "[SCSI-2] PIONEER CD-ROM DRM-604X 2403", "PIONEER_CD-ROM_DRM-604X_2403", BUS_TYPE_SCSI }, - { "PLEXTOR", "CD-ROM PX-32TS", "1.03", "[SCSI-2] PLEXTOR CD-ROM PX-32TS 1.03", "PLEXTOR_CD-ROM_PX-32TS_1.03", BUS_TYPE_SCSI }, - { "TEAC", "CD 50", "1.00", "[SCSI-2] TEAC CD 50 1.00", "TEAC_CD_50_1.00", BUS_TYPE_SCSI }, - { "TEAC", "CD-ROM R55S", "1.0R", "[SCSI-2] TEAC CD-ROM R55S 1.0R", "TEAC_CD-ROM_R55S_1.0R", BUS_TYPE_SCSI }, - { "TEXEL", "CD-ROM DM-3024", "1.00", "[SCSI-1] TEXEL CD-ROM DM-3024 1.00", "TEXEL_CD-ROM_DM-3024_1.00", BUS_TYPE_SCSI }, - { "TEXEL", "CD-ROM DM-3028", "1.06", "[SCSI-2] TEXEL CD-ROM DM-3028 1.06", "TEXEL_CD-ROM_DM-3028_1.06", BUS_TYPE_SCSI }, - { "TOSHIBA", "CD-ROM DRIVE:XM", "3433", "[SCSI-2] TOSHIBA CD-ROM DRIVE:XM 3433", "TOSHIBA_CD-ROM_DRIVEXM_3433", BUS_TYPE_SCSI }, - { "TOSHIBA", "CD-ROM XM-3201B", "3232", "[SCSI-1] TOSHIBA CD-ROM XM-3201B 3232", "TOSHIBA_CD-ROM_XM-3201B_3232", BUS_TYPE_SCSI }, - { "TOSHIBA", "CD-ROM XM-3301TA", "0272", "[SCSI-2] TOSHIBA CD-ROM XM-3301TA 0272", "TOSHIBA_CD-ROM_XM-3301TA_0272", BUS_TYPE_SCSI }, - { "TOSHIBA", "CD-ROM XM-5701TA", "3136", "[SCSI-2] TOSHIBA CD-ROM XM-5701TA 3136", "TOSHIBA_CD-ROM_XM-5701TA_3136", BUS_TYPE_SCSI }, - { "TOSHIBA", "DVD-ROM SD-M1401", "1008", "[SCSI-2] TOSHIBA DVD-ROM SD-M1401 1008", "TOSHIBA_DVD-ROM_SD-M1401_1008", BUS_TYPE_SCSI }, - { "", "", "", "", "", BUS_TYPE_NONE }, + { EMU_NAME, "86B_CD", CDV, "86cd", BUS_TYPE_BOTH, 2, -1, 36, 0, { 4, 2, 2, 5 } }, + /* SCSI-1 / early ATAPI generic - second on purpose so the later variant is the default. */ + { EMU_NAME, "86B_CD", "1.00", "86cd100", BUS_TYPE_BOTH, 1, -1, 36, 1, { 0, -1, -1, -1 } }, + /* No difference from 86BOX CD-ROM, other than name - but enough people have requested such a name to warrant it. */ + { EMU_NAME, "86B_DVD", "4.30", "86dvd", BUS_TYPE_BOTH, 2, -1, 36, 0, { 4, 2, 2, 5 } }, + { "ASUS", "CD-S500/A", "1.41", "asus_500", BUS_TYPE_IDE, 0, 50, 36, 0, { 4, 2, 2, 2 } }, + { "ASUS", "CD-S520/A4", "1.32", "asus_520", BUS_TYPE_IDE, 0, 52, 36, 0, { 4, 2, 2, 2 } }, + { "AZT", "CDA46802I", "1.15", "azt_cda", BUS_TYPE_IDE, 0, 4, 36, 0, { 3, 0, 0, 0 } }, + { "BTC", "CD-ROM BCD36XH", "U1.0", "btc_36xh", BUS_TYPE_IDE, 0, 36, 36, 0, { 4, 2, 2, -1 } }, + { "GOLDSTAR", "CRD-8160B", "3.14", "goldstar", BUS_TYPE_IDE, 0, 16, 36, 0, { 4, 2, 2, -1 } }, + /* TODO: Find an IDENTIFY and/or INQUIRY dump. */ + { "GOLDSTAR", "GCD-R560B", "1.00", "goldstar", BUS_TYPE_IDE, 0, 6, 36, 0, { 4, 2, 2, -1 } }, + { "HITACHI", "CDR-8130", "0020", "hitachi_r8130", BUS_TYPE_IDE, 0, 16, 36, 0, { 4, 2, 2, -1 } }, + { "HITACHI", "GD-7500", "A1 ", "hitachi_7500", BUS_TYPE_IDE, 0, 40, 36, 0, { 4, 2, 2, 2 } }, /* DVD. */ + { "HL-DT-ST", "CD-ROM GCR-8526B", "1.01", "hldtst_8526b", BUS_TYPE_IDE, 0, 52, 36, 0, { 4, 2, 2, 2 } }, + { "HL-DT-ST", "DVDRAM GSA-4160", "A302", "hldtst_4160", BUS_TYPE_IDE, 0, 40, 36, 0, { 4, 2, 2, 2 } }, + { "KENWOOD", "CD-ROM UCR-421", "208E", "kenwood_421", BUS_TYPE_IDE, 0, 72, 36, 0, { 4, 2, 2, 4 } }, + /* + This is a laptop/notebook drive, as is also evident from the name: + CRN = Notebook, CRD = Desktop. + */ + { "LG", "CD-ROM CRN-8245B", "1.30", "lg_8245b", BUS_TYPE_IDE, 0, 24, 36, 0, { 4, 2, 2, -1 } }, + { "LG", "CD-ROM CRD-8322B", "1.06", "lg_8322b", BUS_TYPE_IDE, 0, 32, 36, 0, { 4, 2, 2, -1 } }, + /* Nothing on Google, deduced 48x from the name. */ + { "LITE-ON", "LTN48125S", "1S07", "liteon_48125s", BUS_TYPE_IDE, 0, 48, 36, 0, { 4, 2, 2, 2 } }, + /* Confirmed to be 52x, was the basis for deducing the other one's speed. */ + { "LITE-ON", "LTN526D", "YSR5", "liteon_526d", BUS_TYPE_IDE, 0, 52, 36, 0, { 4, 2, 2, 2 } }, + { "MATSHITA", "CD-ROM CR-583", "1.07", "matshita_583", BUS_TYPE_IDE, 0, 8, 36, 0, { 4, 2, 2, -1 } }, + { "MATSHITA", "CD-ROM CR-585", "Z18P", "matshita_585", BUS_TYPE_IDE, 0, 24, 36, 0, { 4, 2, 2, -1 } }, + { "MATSHITA", "CD-ROM CR-587", "7S13", "matshita_587", BUS_TYPE_IDE, 0, 24, 36, 0, { 4, 2, 2, -1 } }, + { "MATSHITA", "CD-ROM CR-588", "LS15", "matshita_588", BUS_TYPE_IDE, 0, 32, 36, 0, { 4, 2, 2, -1 } }, + { "MATSHITA", "CR-571", "1.0e", "matshita_571", BUS_TYPE_IDE, 0, 2, 36, 0, { 0, -1, -1, -1 } }, + { "MATSHITA", "CR-572", "1.0j", "matshita_572", BUS_TYPE_IDE, 0, 4, 36, 0, { 0, -1, -1, -1 } }, + { "MITSUMI", "CRMC-FX4820T", "D02A", "mitsumi_4820t", BUS_TYPE_IDE, 0, 48, 36, 0, { 4, 2, 2, 2 } }, + /* TODO: Find an IDENTIFY and/or INQUIRY dump. */ + { "MITSUMI", "CRMC-FX810T4", "????", "mitsumi_810t4", BUS_TYPE_IDE, 0, 8, 36, 0, { 4, 2, 2, -1 } }, + { "NEC", "CD-ROM DRIVE:260", "1.00", "nec_260_early", BUS_TYPE_IDE, 1, 2, 36, 1, { 0, -1, -1, -1 } }, + { "NEC", "CD-ROM DRIVE:260", "1.01", "nec_260", BUS_TYPE_IDE, 1, 4, 36, 1, { 0, -1, -1, -1 } }, + { "NEC", "CD-ROM DRIVE:273", "4.20", "nec_273", BUS_TYPE_IDE, 0, 4, 36, 0, { 0, -1, -1, -1 } }, + { "NEC", "CD-ROM DRIVE:280", "1.05", "nec_280_early", BUS_TYPE_IDE, 0, 6, 36, 1, { 4, 2, 2, -1 } }, + { "NEC", "CD-ROM DRIVE:280", "3.08", "nec_280", BUS_TYPE_IDE, 0, 8, 36, 1, { 4, 2, 2, -1 } }, + { "NEC", "CDR-1300A", "1.05", "nec_1300a", BUS_TYPE_IDE, 0, 6, 36, 0, { 4, 2, 2, -1 } }, + { "NEC", "CDR-1900A", "1.00", "nec_1900a", BUS_TYPE_IDE, 0, 32, 36, 0, { 4, 2, 2, -1 } }, + { "PHILIPS", "CD-ROM PCA403CD", "U31P", "philips_403", BUS_TYPE_IDE, 0, 40, 36, 0, { 4, 2, 2, -1 } }, + { "SONY", "CD-ROM CDU76", "1.0i", "sony_76", BUS_TYPE_IDE, 0, 4, 36, 0, { 2, -1, -1, -1 } }, + { "SONY", "CD-ROM CDU311", "3.0h", "sony_311", BUS_TYPE_IDE, 0, 8, 36, 0, { 3, 2, 1, -1 } }, + { "SONY", "CD-ROM CDU5225", "NYS4", "sony_5225", BUS_TYPE_IDE, 0, 52, 36, 0, { 4, 2, 2, 4 } }, + { "TEAC", "CD-516E", "1.0G", "teac_516e", BUS_TYPE_IDE, 0, 16, 36, 0, { 3, 2, 2, -1 } }, + { "TEAC", "CD-524EA", "3.0D", "teac_524ea", BUS_TYPE_IDE, 0, 24, 36, 0, { 3, 2, 2, -1 } }, + { "TEAC", "CD-532E", "2.0A", "teac_532e", BUS_TYPE_IDE, 0, 32, 36, 0, { 3, 2, 2, -1 } }, + { "TOSHIBA", "CD-ROM XM-5302TA", "0305", "toshiba_5302ta", BUS_TYPE_IDE, 0, 4, 96, 0, { 0, -1, -1, -1 } }, + { "TOSHIBA", "CD-ROM XM-5702B", "TA70", "toshiba_5702b", BUS_TYPE_IDE, 0, 12, 96, 0, { 3, 2, 1, -1 } }, + { "TOSHIBA", "CD-ROM XM-6202B", "1512", "toshiba_6202b", BUS_TYPE_IDE, 0, 32, 96, 0, { 4, 2, 2, -1 } }, + { "TOSHIBA", "CD-ROM XM-6402B", "1008", "toshiba_6402b", BUS_TYPE_IDE, 0, 32, 96, 0, { 4, 2, 2, 2 } }, + { "TOSHIBA", "CD-ROM XM-6702B", "1007", "toshiba_6720b", BUS_TYPE_IDE, 0, 48, 96, 0, { 4, 2, 2, 2 } }, + { "TOSHIBA", "DVD-ROM SD-M1802", "1051", "toshiba_m1802", BUS_TYPE_IDE, 0, 48, 96, 0, { 4, 2, 2, 2 } }, + { "CHINON", "CD-ROM CDS-431", "H42 ", "chinon_431", BUS_TYPE_SCSI, 1, 1, 36, 1, { -1, -1, -1, -1 } }, + { "CHINON", "CD-ROM CDX-435", "M62 ", "chinon_435", BUS_TYPE_SCSI, 1, 2, 36, 1, { -1, -1, -1, -1 } }, + { "DEC", "RRD45 (C) DEC", "0436", "dec_45", BUS_TYPE_SCSI, 1, 4, 36, 0, { -1, -1, -1, -1 } }, + { "MATSHITA", "CD-ROM CR-501", "1.0b", "matshita_501", BUS_TYPE_SCSI, 1, 1, 36, 1, { -1, -1, -1, -1 } }, + { "NEC", "CD-ROM DRIVE:25", "1.0a", "nec_25", BUS_TYPE_SCSI, 1, 2, 36, 0, { -1, -1, -1, -1 } }, + { "NEC", "CD-ROM DRIVE:38", "1.00", "nec_38", BUS_TYPE_SCSI, 2, 1, 36, 0, { -1, -1, -1, -1 } }, + /* The speed of the following two is guesswork based on the CDR-74. */ + { "NEC", "CD-ROM DRIVE:75", "1.03", "nec_75", BUS_TYPE_SCSI, 1, 1, 36, 1, { -1, -1, -1, -1 } }, + { "NEC", "CD-ROM DRIVE:77", "1.06", "nec_77", BUS_TYPE_SCSI, 1, 1, 36, 1, { -1, -1, -1, -1 } }, + { "NEC", "CD-ROM DRIVE:211", "1.00", "nec_211", BUS_TYPE_SCSI, 2, 3, 36, 0, { -1, -1, -1, -1 } }, + /* The speed of the following two is guesswork based on the CDR-400. */ + { "NEC", "CD-ROM DRIVE:464", "1.05", "nec_464", BUS_TYPE_SCSI, 2, 3, 36, 0, { -1, -1, -1, -1 } }, + /* The speed of the following two is guesswork based on the name. */ + { "ShinaKen", "CD-ROM DM-3x1S", "1.04", "shinaken_3x1s", BUS_TYPE_SCSI, 1, 3, 36, 0, { -1, -1, -1, -1 } }, + { "SONY", "CD-ROM CDU-541", "1.0i", "sony_541", BUS_TYPE_SCSI, 1, 1, 36, 1, { -1, -1, -1, -1 } }, + { "SONY", "CD-ROM CDU-561", "1.8k", "sony_561", BUS_TYPE_SCSI, 2, 2, 36, 1, { -1, -1, -1, -1 } }, + { "SONY", "CD-ROM CDU-76S", "1.00", "sony_76s", BUS_TYPE_SCSI, 2, 4, 36, 0, { -1, -1, -1, -1 } }, + { "PHILIPS", "CDD2600", "1.07", "philips_2600", BUS_TYPE_SCSI, 2, 6, 36, 0, { -1, -1, -1, -1 } }, + /* NOTE: The real thing is a CD changer drive! */ + { "PIONEER", "CD-ROM DRM-604X", "2403", "pioneer_604x", BUS_TYPE_SCSI, 2, 4, 47, 0, { -1, -1, -1, -1 } }, + { "PLEXTOR", "CD-ROM PX-32TS", "1.03", "plextor_32ts", BUS_TYPE_SCSI, 2, 32, 36, 0, { -1, -1, -1, -1 } }, + /* The speed of the following two is guesswork based on the R55S. */ + { "TEAC", "CD 50", "1.00", "teac_50", BUS_TYPE_SCSI, 2, 4, 36, 1, { -1, -1, -1, -1 } }, + { "TEAC", "CD-ROM R55S", "1.0R", "teac_55s", BUS_TYPE_SCSI, 2, 4, 36, 0, { -1, -1, -1, -1 } }, + /* Texel is Plextor according to Plextor's own EU website. */ + { "TEXEL", "CD-ROM DM-3024", "1.00", "texel_3024", BUS_TYPE_SCSI, 2, 2, 36, 1, { -1, -1, -1, -1 } }, + /* + Unusual 2.23x according to Google, I'm rounding it upwards to 3x. + Assumed caddy based on the DM-3024. + */ + { "TEXEL", "CD-ROM DM-3028", "1.06", "texel_3028", BUS_TYPE_SCSI, 2, 3, 36, 1, { -1, -1, -1, -1 } }, /* Caddy. */ + /* + The characteristics are a complete guesswork because I can't find + this one on Google. + + Also, INQUIRY length is always 96 on these Toshiba drives. + */ + { "TOSHIBA", "CD-ROM DRIVE:XM", "3433", "toshiba_xm", BUS_TYPE_SCSI, 2, 2, 96, 0, { -1, -1, -1, -1 } }, /* Tray. */ + { "TOSHIBA", "CD-ROM XM-3201B", "3232", "toshiba_3201b", BUS_TYPE_SCSI, 1, 1, 96, 1, { -1, -1, -1, -1 } }, /* Caddy. */ + { "TOSHIBA", "CD-ROM XM-3301TA", "0272", "toshiba_3301ta", BUS_TYPE_SCSI, 2, 2, 96, 0, { -1, -1, -1, -1 } }, /* Tray. */ + { "TOSHIBA", "CD-ROM XM-5701TA", "3136", "toshiba_5701a", BUS_TYPE_SCSI, 2, 12, 96, 0, { -1, -1, -1, -1 } }, /* Tray. */ + { "TOSHIBA", "DVD-ROM SD-M1401", "1008", "toshiba_m1401", BUS_TYPE_SCSI, 2, 40, 96, 0, { -1, -1, -1, -1 } }, /* Tray. */ + { "", "", "", "", BUS_TYPE_NONE, 0, -1, 0, 0, { -1, -1, -1, -1 } } }; /* To shut up the GCC compilers. */ @@ -258,133 +257,185 @@ typedef struct raw_track_info_t { /* Define the various CD-ROM drive operations (ops). */ typedef struct cdrom_ops_t { - void (*get_track_info)(struct cdrom *dev, uint32_t track, int end, track_info_t *ti); - void (*get_raw_track_info)(struct cdrom *dev, int *num, raw_track_info_t *rti); - void (*get_subchannel)(struct cdrom *dev, uint32_t lba, subchannel_t *subc); - int (*is_track_pre)(struct cdrom *dev, uint32_t lba); - int (*sector_size)(struct cdrom *dev, uint32_t lba); - int (*read_sector)(struct cdrom *dev, uint8_t *b, uint32_t lba); - int (*track_type)(struct cdrom *dev, uint32_t lba); - int (*ext_medium_changed)(struct cdrom *dev); - void (*exit)(struct cdrom *dev); + int (*get_track_info)(const void *local, const uint32_t track, + const int end, track_info_t *ti); + void (*get_raw_track_info)(const void *local, int *num, + uint8_t *rti); + int (*is_track_pre)(const void *local, const uint32_t sector); + int (*read_sector)(const void *local, uint8_t *buffer, + const uint32_t sector); + uint8_t (*get_track_type)(const void *local, const uint32_t sector); + uint32_t (*get_last_block)(const void *local); + int (*read_dvd_structure)(const void *local, const uint8_t layer, + const uint8_t format, uint8_t *buffer, + uint32_t *info); + int (*is_dvd)(const void *local); + int (*has_audio)(const void *local); + int (*is_empty)(const void *local); + void (*close)(void *local); + void (*load)(const void *local); } cdrom_ops_t; typedef struct cdrom { - uint8_t id; + uint8_t id; union { - uint8_t res; - uint8_t res0; /* Reserved for other ID's. */ - uint8_t res1; - uint8_t ide_channel; - uint8_t scsi_device_id; + uint8_t res; + uint8_t res0; /* Reserved for other ID's. */ + uint8_t res1; + uint8_t ide_channel; + uint8_t scsi_device_id; }; - uint8_t bus_type; /* 0 = ATAPI, 1 = SCSI */ - uint8_t bus_mode; /* Bit 0 = PIO suported; - Bit 1 = DMA supportd. */ - uint8_t cd_status; /* Struct variable reserved for - media status. */ - uint8_t speed; - uint8_t cur_speed; + uint8_t bus_type; /* 0 = ATAPI, 1 = SCSI */ + uint8_t bus_mode; /* Bit 0 = PIO suported; + Bit 1 = DMA supportd. */ + uint8_t cd_status; /* Struct variable reserved for + media status. */ + uint8_t speed; + uint8_t cur_speed; - void *priv; + void * priv; - char image_path[1024]; - char prev_image_path[1024]; + char image_path[1024]; + char prev_image_path[1024]; - char *image_history[CD_IMAGE_HISTORY]; + char * image_history[CD_IMAGE_HISTORY]; - uint32_t sound_on; - uint32_t cdrom_capacity; - uint32_t seek_pos; - uint32_t seek_diff; - uint32_t cd_end; - uint32_t type; - uint32_t sector_size; + uint32_t sound_on; + uint32_t cdrom_capacity; + uint32_t seek_pos; + uint32_t seek_diff; + uint32_t cd_end; + uint32_t type; + uint32_t sector_size; - int cd_buflen; - int audio_op; - int audio_muted_soft; - int sony_msf; + int cd_buflen; + int audio_op; + int audio_muted_soft; + int sony_msf; + int real_speed; + int is_early; + int is_nec; + + uint32_t inv_field; const cdrom_ops_t *ops; - void *local; + void * local; + void * log; - void (*insert)(void *priv); - void (*close)(void *priv); - uint32_t (*get_volume)(void *p, int channel); - uint32_t (*get_channel)(void *p, int channel); + void (*insert)(void *priv); + void (*close)(void *priv); + uint32_t (*get_volume)(void *p, int channel); + uint32_t (*get_channel)(void *p, int channel); - int16_t cd_buffer[BUF_SIZE]; + int16_t cd_buffer[BUF_SIZE]; - uint8_t subch_buffer[96]; + uint8_t subch_buffer[96]; + + int cdrom_sector_size; + + /* Needs some extra breathing space in case of overflows. */ + uint8_t raw_buffer[4096]; + uint8_t extra_buffer[296]; } cdrom_t; extern cdrom_t cdrom[CDROM_NUM]; -extern char *cdrom_getname(int type); +/* 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 char *cdrom_get_internal_name(int type); -extern int cdrom_get_from_internal_name(char *s); -extern void cdrom_set_type(int model, int type); -extern int cdrom_get_type(int model); +static __inline int +bin2bcd(int x) +{ + return (x % 10) | ((x / 10) << 4); +} -extern int cdrom_lba_to_msf_accurate(int lba); -extern double cdrom_seek_time(cdrom_t *dev); -extern void cdrom_stop(cdrom_t *dev); -extern int cdrom_is_pre(cdrom_t *dev, uint32_t lba); -extern int cdrom_audio_callback(cdrom_t *dev, int16_t *output, int len); -extern uint8_t cdrom_audio_play(cdrom_t *dev, uint32_t pos, uint32_t len, int ismsf); -extern uint8_t cdrom_audio_track_search(cdrom_t *dev, uint32_t pos, int type, uint8_t playbit); -extern uint8_t cdrom_audio_track_search_pioneer(cdrom_t *dev, uint32_t pos, uint8_t playbit); -extern uint8_t cdrom_audio_play_pioneer(cdrom_t *dev, uint32_t pos); -extern uint8_t cdrom_audio_play_toshiba(cdrom_t *dev, uint32_t pos, int type); -extern void cdrom_audio_pause_resume(cdrom_t *dev, uint8_t resume); -extern uint8_t cdrom_audio_scan(cdrom_t *dev, uint32_t pos, int type); -extern uint8_t cdrom_get_audio_status_pioneer(cdrom_t *dev, uint8_t *b); -extern uint8_t cdrom_get_audio_status_sony(cdrom_t *dev, uint8_t *b, int msf); -extern uint8_t cdrom_get_current_status(cdrom_t *dev); -extern void cdrom_get_current_subchannel(cdrom_t *dev, uint8_t *b, int msf); -extern void cdrom_get_current_subchannel_sony(cdrom_t *dev, uint8_t *b, int msf); -extern void cdrom_get_current_subcodeq(cdrom_t *dev, uint8_t *b); -extern uint8_t cdrom_get_current_subcodeq_playstatus(cdrom_t *dev, uint8_t *b); -extern int cdrom_read_toc(cdrom_t *dev, unsigned char *b, int type, - unsigned char start_track, int msf, int max_len); -extern int cdrom_read_toc_sony(cdrom_t *dev, unsigned char *b, unsigned char start_track, int msf, int max_len); -extern void cdrom_get_track_buffer(cdrom_t *dev, uint8_t *buf); -extern void cdrom_get_q(cdrom_t *dev, uint8_t *buf, int *curtoctrk, uint8_t mode); -extern uint8_t cdrom_mitsumi_audio_play(cdrom_t *dev, uint32_t pos, uint32_t len); -extern int cdrom_readsector_raw(cdrom_t *dev, uint8_t *buffer, int sector, int ismsf, - int cdrom_sector_type, int cdrom_sector_flags, int *len, uint8_t vendor_type); -extern uint8_t cdrom_read_disc_info_toc(cdrom_t *dev, unsigned char *b, unsigned char track, int type); +static __inline int +bcd2bin(int x) +{ + return (x >> 4) * 10 + (x & 0x0f); +} -extern void cdrom_seek(cdrom_t *dev, uint32_t pos, uint8_t vendor_type); +extern char *cdrom_get_vendor(const int type); +extern void cdrom_get_model(const int type, char *name, const int id); +extern char *cdrom_get_revision(const int type); +extern int cdrom_get_scsi_std(const int type); +extern int cdrom_is_early(const int type); +extern int cdrom_is_generic(const int type); +extern int cdrom_has_date(const int type); +extern int cdrom_is_sony(const int type); +extern int cdrom_is_caddy(const int type); +extern int cdrom_get_speed(const int type); +extern int cdrom_get_inquiry_len(const int type); +extern int cdrom_has_dma(const int type); +extern int cdrom_get_transfer_max(const int type, const int mode); +extern int cdrom_get_type_count(void); +extern void cdrom_get_identify_model(const int type, char *name, const int id); +extern void cdrom_get_name(const int type, char *name); +extern char *cdrom_get_internal_name(const int type); +extern int cdrom_get_from_internal_name(const char *s); +/* TODO: Configuration migration, remove when no longer needed. */ +extern int cdrom_get_from_name(const char *s); +extern void cdrom_set_type(const int model, const int type); +extern int cdrom_get_type(const int model); -extern void cdrom_close_handler(uint8_t id); -extern void cdrom_insert(uint8_t id); -extern void cdrom_exit(uint8_t id); -extern int cdrom_is_empty(uint8_t id); -extern void cdrom_eject(uint8_t id); -extern void cdrom_reload(uint8_t id); +extern int cdrom_lba_to_msf_accurate(const int lba); +extern double cdrom_seek_time(const cdrom_t *dev); +extern void cdrom_stop(cdrom_t *dev); +extern void cdrom_seek(cdrom_t *dev, const uint32_t pos, const uint8_t vendor_type); +extern int cdrom_is_pre(const cdrom_t *dev, const uint32_t lba); -extern int cdrom_image_open(cdrom_t *dev, const char *fn); -extern void cdrom_image_close(cdrom_t *dev); +extern int cdrom_audio_callback(cdrom_t *dev, int16_t *output, const int len); +extern uint8_t cdrom_audio_play(cdrom_t *dev, const uint32_t pos, const uint32_t len, const int ismsf); +extern uint8_t cdrom_audio_track_search(cdrom_t *dev, const uint32_t pos, + const int type, const uint8_t playbit); +extern uint8_t cdrom_audio_track_search_pioneer(cdrom_t *dev, const uint32_t pos, const uint8_t playbit); +extern uint8_t cdrom_audio_play_pioneer(cdrom_t *dev, const uint32_t pos); +extern uint8_t cdrom_audio_play_toshiba(cdrom_t *dev, const uint32_t pos, const int type); +extern uint8_t cdrom_audio_scan(cdrom_t *dev, const uint32_t pos, const int type); +extern void cdrom_audio_pause_resume(cdrom_t *dev, const uint8_t resume); -extern int cdrom_ioctl_open(cdrom_t *dev, const char *drv); -extern void cdrom_ioctl_close(cdrom_t *dev); +extern uint8_t cdrom_get_current_status(const cdrom_t *dev); +extern void cdrom_get_current_subchannel(cdrom_t *dev, uint8_t *b, const int msf); +extern void cdrom_get_current_subchannel_sony(cdrom_t *dev, uint8_t *b, const int msf); +extern uint8_t cdrom_get_audio_status_pioneer(cdrom_t *dev, uint8_t *b); +extern uint8_t cdrom_get_audio_status_sony(cdrom_t *dev, uint8_t *b, const int msf); +extern void cdrom_get_current_subcodeq(cdrom_t *dev, uint8_t *b); +extern uint8_t cdrom_get_current_subcodeq_playstatus(cdrom_t *dev, uint8_t *b); +extern int cdrom_read_toc(const cdrom_t *dev, uint8_t *b, const int type, + const uint8_t start_track, const int msf, const int max_len); +extern int cdrom_read_toc_sony(const cdrom_t *dev, uint8_t *b, const uint8_t start_track, + const int msf, const int max_len); +#ifdef USE_CDROM_MITSUMI +extern void cdrom_get_track_buffer(cdrom_t *dev, uint8_t *buf); +extern void cdrom_get_q(cdrom_t *dev, uint8_t *buf, int *curtoctrk, uint8_t mode); +extern uint8_t cdrom_mitsumi_audio_play(cdrom_t *dev, uint32_t pos, uint32_t len); +#endif +extern uint8_t cdrom_read_disc_info_toc(cdrom_t *dev, uint8_t *b, + const uint8_t track, const int type); +extern int cdrom_readsector_raw(cdrom_t *dev, uint8_t *buffer, const int sector, const int ismsf, + int cdrom_sector_type, const int cdrom_sector_flags, + int *len, const uint8_t vendor_type); +extern int cdrom_read_dvd_structure(const cdrom_t *dev, const uint8_t layer, const uint8_t format, + uint8_t *buffer, uint32_t *info); +extern void cdrom_read_disc_information(const cdrom_t *dev, uint8_t *buffer); +extern int cdrom_read_track_information(cdrom_t *dev, const uint8_t *cdb, uint8_t *buffer); +extern void cdrom_set_empty(cdrom_t *dev); +extern void cdrom_update_status(cdrom_t *dev); +extern int cdrom_load(cdrom_t *dev, const char *fn, const int skip_insert); -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); -extern void scsi_cdrom_drive_reset(int c); +extern void cdrom_global_init(void); +extern void cdrom_hard_reset(void); +extern void cdrom_close(void); +extern void cdrom_insert(const uint8_t id); +extern void cdrom_exit(const uint8_t id); +extern int cdrom_is_empty(const uint8_t id); +extern void cdrom_eject(const uint8_t id); +extern void cdrom_reload(const uint8_t id); #ifdef __cplusplus } diff --git a/src/include/86box/cdrom_image.h b/src/include/86box/cdrom_image.h index c848af50d..84dd66f37 100644 --- a/src/include/86box/cdrom_image.h +++ b/src/include/86box/cdrom_image.h @@ -6,35 +6,33 @@ * * This file is part of the 86Box distribution. * - * CD-ROM image file handling module header, translated to C - * from cdrom_dosbox.h. + * CD-ROM image file handling module header. * - * Authors: RichardG, - * Miran Grca, + * Authors: Miran Grca, + * RichardG, + * Cacodemon345 * - * Copyright 2016-2022 RichardG. - * Copyright 2016-2022 Miran Grca. + * Copyright 2016-2025 Miran Grca. + * Copyright 2016-2025 RichardG. + * Copyright 2024-2025 Cacodemon345. */ #ifndef CDROM_IMAGE_H #define CDROM_IMAGE_H -/* this header file lists the functions provided by - various platform specific cdrom-ioctl files */ +/* Track file struct. */ +typedef struct track_file_t { + int (*read)(void *priv, uint8_t *buffer, uint64_t seek, size_t count); + uint64_t (*get_length)(void *priv); + void (*close)(void *priv); -#ifdef __cplusplus -extern "C" { -#endif + char fn[260]; + FILE *fp; + void *priv; + void *log; -extern int image_open(uint8_t id, wchar_t *fn); -extern void image_reset(uint8_t id); + int motorola; +} track_file_t; -extern void image_close(uint8_t id); - -void update_status_bar_icon_state(int tag, int state); -extern void cdrom_set_null_handler(uint8_t id); - -#ifdef __cplusplus -} -#endif +extern void * image_open(cdrom_t *dev, const char *path); #endif /*CDROM_IMAGE_H*/ diff --git a/src/include/86box/cdrom_image_backend.h b/src/include/86box/cdrom_image_backend.h deleted file mode 100644 index 64ce88d83..000000000 --- a/src/include/86box/cdrom_image_backend.h +++ /dev/null @@ -1,119 +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. - * - * CD-ROM image file handling module header. - * - * Authors: Miran Grca, - * RichardG, - * Cacodemon345 - * - * Copyright 2016-2025 Miran Grca. - * Copyright 2016-2025 Miran Grca. - * Copyright 2024-2025 Cacodemon345. - */ -#ifndef CDROM_IMAGE_BACKEND_H -#define CDROM_IMAGE_BACKEND_H - -#define RAW_SECTOR_SIZE 2352 -#define COOKED_SECTOR_SIZE 2048 - -#define DATA_TRACK 0x14 -#define AUDIO_TRACK 0x10 - -#define CD_FPS 75 -#define FRAMES_TO_MSF(f, M, S, F) \ - { \ - uint64_t value = f; \ - *(F) = (value % CD_FPS) & 0xff; \ - value /= CD_FPS; \ - *(S) = (value % 60) & 0xff; \ - value /= 60; \ - *(M) = value & 0xff; \ - } -#define MSF_TO_FRAMES(M, S, F) ((M) *60 * CD_FPS + (S) *CD_FPS + (F)) - -typedef struct SMSF { - uint16_t min; - uint8_t sec; - uint8_t fr; -} TMSF; - -/* Track file struct. */ -typedef struct track_file_t { - int (*read)(void *priv, uint8_t *buffer, uint64_t seek, size_t count); - uint64_t (*get_length)(void *priv); - void (*close)(void *priv); - - char fn[260]; - FILE *fp; - void *priv; - - int motorola; -} track_file_t; - -#define INDEX_SPECIAL -2 /* Track A0h onwards. */ -#define INDEX_NONE -1 /* Empty block. */ -#define INDEX_ZERO 0 /* Block not in the file, return all 0x00's. */ -#define INDEX_NORMAL 1 /* Block in the file. */ - -typedef struct track_index_t { - /* Is the current block in the file? If not, return all 0x00's. -1 means not yet loaded. */ - int32_t type; - /* The amount of bytes to skip at the beginning of each sector. */ - int32_t skip; - /* Starting and ending sector LBA - negative in order to accomodate LBA -150 to -1 - to read the pregap of track 1. */ - uint64_t start; - uint64_t length; - uint64_t file_start; - uint64_t file_length; - track_file_t *file; -} track_index_t; - -typedef struct track_t { - uint8_t session; - uint8_t attr; - uint8_t tno; - uint8_t point; - uint8_t extra[4]; - uint8_t mode; - uint8_t form; - uint8_t pad; - uint8_t skip; - uint32_t sector_size; - track_index_t idx[3]; -} track_t; - -typedef struct cd_img_t { - int32_t tracks_num; - track_t *tracks; -} cd_img_t; - -/* Binary file functions. */ -extern void cdi_get_raw_track_info(cd_img_t *cdi, int *num, uint8_t *buffer); -extern int cdi_get_audio_sub(cd_img_t *cdi, uint32_t sector, uint8_t *attr, uint8_t *track, - uint8_t *index, TMSF *rel_pos, TMSF *abs_pos); -extern int cdi_read_sector(cd_img_t *cdi, uint8_t *buffer, int raw, uint32_t sector); -extern int cdi_read_sector_sub(cd_img_t *cdi, uint8_t *buffer, uint32_t sector); -extern int cdi_get_sector_size(cd_img_t *cdi, uint32_t sector); -extern int cdi_is_audio(cd_img_t *cdi, uint32_t sector); -extern int cdi_is_pre(cd_img_t *cdi, uint32_t sector); -extern int cdi_is_mode2(cd_img_t *cdi, uint32_t sector); -extern int cdi_get_mode2_form(cd_img_t *cdi, uint32_t sector); -extern int cdi_load_iso(cd_img_t *cdi, const char *filename); -extern int cdi_load_cue(cd_img_t *cdi, const char *cuefile); -extern void cdi_close(cd_img_t *cdi); -extern int cdi_set_device(cd_img_t *cdi, const char *path); - -/* Virtual ISO functions. */ -extern int viso_read(void *priv, uint8_t *buffer, uint64_t seek, size_t count); -extern uint64_t viso_get_length(void *priv); -extern void viso_close(void *priv); -extern track_file_t *viso_init(const char *dirname, int *error); - -#endif /*CDROM_IMAGE_BACKEND_H*/ diff --git a/src/include/86box/cdrom_image_viso.h b/src/include/86box/cdrom_image_viso.h new file mode 100644 index 000000000..19f0e1de0 --- /dev/null +++ b/src/include/86box/cdrom_image_viso.h @@ -0,0 +1,26 @@ +/* + * 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. + * + * CD-ROM image file handling module header. + * + * Authors: RichardG, + * Miran Grca, + * + * Copyright 2016-2025 RichardG. + * Copyright 2016-2025 Miran Grca. + */ +#ifndef CDROM_IMAGE_VISO_H +#define CDROM_IMAGE_VISO_H + +/* Virtual ISO functions. */ +extern int viso_read(void *priv, uint8_t *buffer, uint64_t seek, size_t count); +extern uint64_t viso_get_length(void *priv); +extern void viso_close(void *priv); +extern track_file_t *viso_init(const uint8_t id, const char *dirname, int *error); + +#endif /*CDROM_IMAGE_VISO_H*/ diff --git a/src/include/86box/cdrom_interface.h b/src/include/86box/cdrom_interface.h index 081f758f6..ba4d0581b 100644 --- a/src/include/86box/cdrom_interface.h +++ b/src/include/86box/cdrom_interface.h @@ -21,11 +21,13 @@ extern int cdrom_interface_current; extern void cdrom_interface_reset(void); -extern const char *cdrom_interface_get_internal_name(int cdinterface); -extern int cdrom_interface_get_from_internal_name(char *s); -extern int cdrom_interface_has_config(int cdinterface); -extern const device_t *cdrom_interface_get_device(int cdinterface); -extern int cdrom_interface_get_flags(int cdinterface); -extern int cdrom_interface_available(int cdinterface); +const char *cdrom_interface_get_internal_name(const int cdinterface); +extern int cdrom_interface_get_from_internal_name(const char *s); +#ifdef EMU_DEVICE_H +extern const device_t *cdrom_interface_get_device(const int cdinterface); +#endif +extern int cdrom_interface_has_config(const int cdinterface); +extern int cdrom_interface_get_flags(const int cdinterface); +extern int cdrom_interface_available(const int cdinterface); #endif /*EMU_CDROM_INTERFACE_H*/ diff --git a/src/include/86box/cdrom_ioctl.h b/src/include/86box/cdrom_ioctl.h deleted file mode 100644 index 5fc157615..000000000 --- a/src/include/86box/cdrom_ioctl.h +++ /dev/null @@ -1,32 +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. - * - * CD-ROM image file handling module header, translated to C - * from cdrom_dosbox.h. - * - * Authors: RichardG, - * Miran Grca, - * - * Copyright 2016-2022 RichardG. - * Copyright 2016-2022 Miran Grca. - */ -#ifndef CDROM_IOCTL_H -#define CDROM_IOCTL_H - -/* this header file lists the functions provided by - various platform specific cdrom-ioctl files */ - -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef __cplusplus -} -#endif - -#endif /*CDROM_IOCTL_H*/ diff --git a/src/include/86box/config.h b/src/include/86box/config.h index a043fb22a..693f38ab7 100644 --- a/src/include/86box/config.h +++ b/src/include/86box/config.h @@ -8,16 +8,16 @@ * * Configuration file handler header. * - * - * * Authors: Sarah Walker, * Miran Grca, * Fred N. van Kempen, * Overdoze, + * Jasmine Iwanek, * * Copyright 2008-2017 Sarah Walker. * Copyright 2016-2017 Miran Grca. * Copyright 2017 Fred N. van Kempen. + * Copyright 2021-2025 Jasmine Iwanek. */ #ifndef EMU_CONFIG_H #define EMU_CONFIG_H @@ -111,6 +111,7 @@ typedef struct config_t { # ifdef USE_SERIAL_DEVICES char serial_devices[SERIAL_MAX][32]; /* Serial device names */ # endif + char gameport_devices[GAMEPORT_MAX][32]; /* gameport device names */ /* Other peripherals category */ int fdc_current[FDC_MAX]; /* Floppy disk controller type */ diff --git a/src/include/86box/fdd.h b/src/include/86box/fdd.h index 0331f4fcc..ff9315f1d 100644 --- a/src/include/86box/fdd.h +++ b/src/include/86box/fdd.h @@ -22,7 +22,7 @@ #define EMU_FDD_H #define FDD_NUM 4 -#define FLOPPY_IMAGE_HISTORY 4 +#define FLOPPY_IMAGE_HISTORY 10 #define SEEK_RECALIBRATE -999 #ifdef __cplusplus diff --git a/src/include/86box/gameport.h b/src/include/86box/gameport.h index 3d3a253e8..c5fc1d192 100644 --- a/src/include/86box/gameport.h +++ b/src/include/86box/gameport.h @@ -8,8 +8,6 @@ * * Definitions for the generic game port handlers. * - * - * * Authors: Miran Grca, * Sarah Walker, * RichardG, @@ -18,11 +16,13 @@ * Copyright 2016-2022 Miran Grca. * Copyright 2008-2018 Sarah Walker. * Copyright 2021 RichardG. - * Copyright 2021-2024 Jasmine Iwanek. + * Copyright 2021-2025 Jasmine Iwanek. */ #ifndef EMU_GAMEPORT_H #define EMU_GAMEPORT_H +#define GAMEPORT_MAX 2 + #define MAX_PLAT_JOYSTICKS 8 #define MAX_JOYSTICKS 4 @@ -45,7 +45,7 @@ #define AXIS_NOT_PRESENT -99999 -#define JOYSTICK_PRESENT(n) (joystick_state[n].plat_joystick_nr != 0) +#define JOYSTICK_PRESENT(gp, js) (joystick_state[gp][js].plat_joystick_nr != 0) #define GAMEPORT_1ADDR 0x010000 #define GAMEPORT_6ADDR 0x060000 @@ -110,10 +110,20 @@ typedef struct joystick_if_t { const char *pov_names[MAX_JOY_POVS]; } joystick_if_t; +extern device_t game_ports[GAMEPORT_MAX]; + #ifdef __cplusplus extern "C" { #endif +extern int gameport_available(int port); +#ifdef EMU_DEVICE_H +extern const device_t *gameport_getdevice(int port); +#endif +extern int gameport_has_config(int port); +extern const char *gameport_get_internal_name(int port); +extern int gameport_get_from_internal_name(const char *str); + #ifdef EMU_DEVICE_H extern const device_t gameport_device; extern const device_t gameport_201_device; @@ -136,7 +146,7 @@ extern const device_t *standalone_gameport_type; #endif extern int gameport_instance_id; extern plat_joystick_t plat_joystick_state[MAX_PLAT_JOYSTICKS]; -extern joystick_t joystick_state[MAX_JOYSTICKS]; +extern joystick_t joystick_state[GAMEPORT_MAX][MAX_JOYSTICKS]; extern int joysticks_present; extern int joystick_type; @@ -173,6 +183,15 @@ extern const joystick_if_t joystick_ch_flightstick_pro; extern const joystick_if_t joystick_sw_pad; extern const joystick_if_t joystick_tm_fcs; + +extern int gameport_available(int); +extern int gameport_has_config(int); +extern const char *gameport_get_internal_name(int); +extern int gampeport_get_from_internal_name(char *); +#ifdef EMU_DEVICE_H +extern const device_t *gameport_getdevice(int); +#endif + #ifdef __cplusplus } #endif diff --git a/src/include/86box/hdc.h b/src/include/86box/hdc.h index a3b667e2e..110804244 100644 --- a/src/include/86box/hdc.h +++ b/src/include/86box/hdc.h @@ -22,11 +22,6 @@ #define MFM_NUM 2 /* 2 drives per controller supported */ #define ESDI_NUM 2 /* 2 drives per controller supported */ #define XTA_NUM 2 /* 2 drives per controller supported */ -#define IDE_NUM 10 /* 8 drives per AT IDE + 2 for XT IDE */ -#define ATAPI_NUM 8 /* 8 drives per AT IDE */ -#define SCSI_NUM 16 /* theoretically the controller can have at \ - * least 7 devices, with each device being \ - * able to support 8 units, but hey... */ /* Controller types. */ #define HDC_NONE 0 diff --git a/src/include/86box/hdc_ide.h b/src/include/86box/hdc_ide.h index 9094f7f00..0280cf301 100644 --- a/src/include/86box/hdc_ide.h +++ b/src/include/86box/hdc_ide.h @@ -19,6 +19,9 @@ #ifndef EMU_IDE_H #define EMU_IDE_H +#define IDE_NUM 10 /* 8 drives per AT IDE + 2 for XT IDE */ +#define ATAPI_NUM 10 /* 8 drives per AT IDE + 2 for XT IDE */ + #define IDE_BUS_MAX 4 #define IDE_CHAN_MAX 2 @@ -121,11 +124,11 @@ typedef struct ide_s { double pending_delay; #ifdef SCSI_DEVICE_H - int (*get_max)(int ide_has_dma, int type); - int (*get_timings)(int ide_has_dma, int type); - void (*identify)(struct ide_s *ide, int ide_has_dma); - void (*stop)(scsi_common_t *sc); - void (*packet_command)(scsi_common_t *sc, uint8_t *cdb); + int (*get_max)(const struct ide_s *ide, const int ide_has_dma, const int type); + int (*get_timings)(const struct ide_s *ide, const int ide_has_dma, const int type); + void (*identify)(const struct ide_s *ide, const int ide_has_dma); + void (*stop)(const scsi_common_t *sc); + void (*packet_command)(scsi_common_t *sc, const uint8_t *cdb); void (*device_reset)(scsi_common_t *sc); uint8_t (*phase_data_out)(scsi_common_t *sc); void (*command_stop)(scsi_common_t *sc); @@ -142,10 +145,8 @@ typedef struct ide_s { #endif } ide_t; -#ifdef EMU_HDC_H extern ide_t *ide_drives[IDE_NUM]; #endif -#endif /* Type: 0 = PIO, diff --git a/src/include/86box/hdd.h b/src/include/86box/hdd.h index a4bded58f..b80c21c13 100644 --- a/src/include/86box/hdd.h +++ b/src/include/86box/hdd.h @@ -148,7 +148,7 @@ typedef struct hard_disk_t { uint8_t ide_channel; uint8_t scsi_id; }; - uint8_t bus; + uint8_t bus_type; uint8_t bus_mode; /* Bit 0 = PIO suported; Bit 1 = DMA supportd. */ uint8_t wp; /* Disk has been mounted READ-ONLY */ diff --git a/src/include/86box/log.h b/src/include/86box/log.h index 7f0b96d60..a37bdec4f 100644 --- a/src/include/86box/log.h +++ b/src/include/86box/log.h @@ -6,24 +6,20 @@ * * This file is part of the 86Box distribution. * - * Main include file for the application. - * - * + * New logging system handler header. * * Authors: Miran Grca, * Fred N. van Kempen, - * Connor Hyde + * Connor Hyde, * - * Copyright 2021 Miran Grca. - * Copyright 2021 Fred N. van Kempen. + * Copyright 2021-25 Miran Grca. + * Copyright 2021-25 Fred N. van Kempen. * Copyright 2025 Connor Hyde. */ #ifndef EMU_LOG_H #define EMU_LOG_H -#ifndef RELEASE_BUILD - # ifdef __cplusplus extern "C" { # endif @@ -35,20 +31,17 @@ extern "C" { /* Function prototypes. */ extern void log_set_suppr_seen(void *priv, int suppr_seen); extern void log_set_dev_name(void *priv, char *dev_name); -# ifdef HAVE_STDARG_H +#ifndef RELEASE_BUILD extern void log_out(void *priv, const char *fmt, va_list); extern void log_out_cyclic(void* priv, const char *fmt, va_list); +#endif /*RELEASE_BUILD*/ extern void log_fatal(void *priv, const char *fmt, ...); -# endif -extern void *log_open(char *dev_name); +extern void *log_open(const char *dev_name); +extern void *log_open_cyclic(const char *dev_name); extern void log_close(void *priv); # ifdef __cplusplus } # endif -#else -# define log_fatal(priv, fmt, ...) fatal(fmt, ...) -#endif /*RELEASE_BUILD*/ - #endif /*EMU_LOG_H*/ diff --git a/src/include/86box/machine.h b/src/include/86box/machine.h index 0cd3564ee..f4f3f8834 100644 --- a/src/include/86box/machine.h +++ b/src/include/86box/machine.h @@ -637,6 +637,7 @@ extern int machine_at_m5pi_init(const machine_t *); extern int machine_at_excalibur_init(const machine_t *); +extern int machine_at_globalyst330_p5_init(const machine_t *); extern int machine_at_p5vl_init(const machine_t *); extern int machine_at_excaliburpci2_init(const machine_t *); @@ -745,6 +746,7 @@ extern int machine_at_tomahawk_init(const machine_t *); extern int machine_at_ficva502_init(const machine_t *); extern int machine_at_ficpa2012_init(const machine_t *); +extern int machine_at_via809ds_init(const machine_t *); extern int machine_at_r534f_init(const machine_t *); extern int machine_at_ms5146_init(const machine_t *); diff --git a/src/include/86box/mo.h b/src/include/86box/mo.h index 4ab567aca..1df16c3fe 100644 --- a/src/include/86box/mo.h +++ b/src/include/86box/mo.h @@ -9,13 +9,13 @@ * Implementation of a generic Magneto-Optical Disk drive * commands, for both ATAPI and SCSI usage. * - * - * * Authors: Natalia Portillo - * Fred N. van Kempen, * Miran Grca, + * Fred N. van Kempen, * - * Copyright 2020 Miran Grca. + * Copyright 2020-2025 Natalia Portillo. + * Copyright 2020-2025 Miran Grca. + * Copyright 2020-2025 Fred N. van Kempen */ #ifndef EMU_MO_H @@ -27,7 +27,7 @@ #define MO_TIME 10.0 -#define MO_IMAGE_HISTORY 4 +#define MO_IMAGE_HISTORY 10 typedef struct mo_type_t { uint32_t sectors; @@ -91,88 +91,87 @@ enum { }; typedef struct mo_drive_t { - uint8_t id; + uint8_t id; union { - uint8_t res; - uint8_t res0; /* Reserved for other ID's. */ - uint8_t res1; - uint8_t ide_channel; - uint8_t scsi_device_id; + uint8_t res; + /* Reserved for other ID's. */ + uint8_t res0; + uint8_t res1; + uint8_t ide_channel; + uint8_t scsi_device_id; }; - uint8_t bus_type; /* 0 = ATAPI, 1 = SCSI */ - uint8_t bus_mode; /* Bit 0 = PIO suported; - Bit 1 = DMA supportd. */ - uint8_t read_only; /* Struct variable reserved for - media status. */ - uint8_t pad; - uint8_t pad0; + uint8_t bus_type; /* 0 = ATAPI, 1 = SCSI */ + uint8_t bus_mode; /* Bit 0 = PIO suported; + Bit 1 = DMA supportd. */ + uint8_t read_only; /* Struct variable reserved for + media status. */ + uint8_t pad; + uint8_t pad0; - FILE *fp; - void *priv; + FILE * fp; + void * priv; - char image_path[1024]; - char prev_image_path[1024]; + char image_path[1024]; + char prev_image_path[1024]; - char *image_history[MO_IMAGE_HISTORY]; + char * image_history[MO_IMAGE_HISTORY]; - uint32_t type; - uint32_t medium_size; - uint32_t base; - uint16_t sector_size; + uint32_t type; + uint32_t medium_size; + uint32_t base; + uint16_t sector_size; } mo_drive_t; typedef struct mo_t { mode_sense_pages_t ms_pages_saved; - mo_drive_t *drv; + mo_drive_t * drv; #ifdef EMU_IDE_H - ide_tf_t * tf; + ide_tf_t * tf; #else - void * tf; + void * tf; #endif - uint8_t *buffer; - uint8_t atapi_cdb[16]; - uint8_t current_cdb[16]; - uint8_t sense[256]; + void * log; - uint8_t id; - uint8_t cur_lun; - uint8_t pad0; - uint8_t pad1; + uint8_t * buffer; + uint8_t atapi_cdb[16]; + uint8_t current_cdb[16]; + uint8_t sense[256]; - uint16_t max_transfer_len; - uint16_t pad2; + uint8_t id; + uint8_t cur_lun; + uint8_t pad0; + uint8_t pad1; - int requested_blocks; - int packet_status; - int total_length; - int do_page_save; - int unit_attention; - int request_pos; - int old_len; - int pad3; + uint16_t max_transfer_len; + uint16_t pad2; - uint32_t sector_pos; - uint32_t sector_len; - uint32_t packet_len; + int requested_blocks; + int packet_status; + int total_length; + int do_page_save; + int unit_attention; + int request_pos; + int old_len; + int transition; - double callback; + uint32_t sector_pos; + uint32_t sector_len; + uint32_t packet_len; - uint8_t (*ven_cmd)(void *sc, uint8_t *cdb, int32_t *BufLen); + double callback; + + uint8_t (*ven_cmd)(void *sc, uint8_t *cdb, int32_t *BufLen); } mo_t; -extern mo_t *mo[MO_NUM]; -extern mo_drive_t mo_drives[MO_NUM]; -#if 0 -extern uint8_t atapi_mo_drives[8]; -extern uint8_t scsi_mo_drives[16]; -#endif +extern mo_drive_t mo_drives[MO_NUM]; #define mo_sense_error dev->sense[0] #define mo_sense_key dev->sense[2] +#define mo_info *(uint32_t *) &(dev->sense[3]) #define mo_asc dev->sense[12] #define mo_ascq dev->sense[13] @@ -180,15 +179,16 @@ extern uint8_t scsi_mo_drives[16]; extern "C" { #endif -extern void mo_disk_close(mo_t *dev); -extern void mo_disk_reload(mo_t *dev); +extern void mo_disk_close(const mo_t *dev); +extern void mo_disk_reload(const mo_t *dev); extern void mo_insert(mo_t *dev); extern void mo_global_init(void); extern void mo_hard_reset(void); extern void mo_reset(scsi_common_t *sc); -extern int mo_load(mo_t *dev, char *fn); +extern int mo_is_empty(const uint8_t id); +extern void mo_load(const mo_t *dev, const char *fn, const int skip_insert); extern void mo_close(void); #ifdef __cplusplus diff --git a/src/include/86box/net_ne2000.h b/src/include/86box/net_ne2000.h index cb17ef8b1..ecf2612b5 100644 --- a/src/include/86box/net_ne2000.h +++ b/src/include/86box/net_ne2000.h @@ -44,7 +44,7 @@ enum { NE2K_NE2000_COMPAT = 4, /* 16-bit ISA NE2000-Compatible */ NE2K_NE2000_COMPAT_8BIT = 5, /* 8-bit ISA NE2000-Compatible, like: https://github.com/skiselev/isa8_eth */ NE2K_ETHERNEXT_MC = 6, /* 16-bit MCA EtherNext/MC */ - NE2K_RTL8019AS = 7, /* 16-bit ISA PnP Realtek 8019AS */ + NE2K_RTL8019AS_PNP = 7, /* 16-bit ISA PnP Realtek 8019AS */ NE2K_DE220P = 8, /* 16-bit ISA PnP D-Link DE-220P */ NE2K_RTL8029AS = 9, /* 32-bit PCI Realtek 8029AS */ /* Check nic_init() if adding items after this point. */ diff --git a/src/include/86box/network.h b/src/include/86box/network.h index fa6408790..2140d62dd 100644 --- a/src/include/86box/network.h +++ b/src/include/86box/network.h @@ -213,7 +213,7 @@ extern const device_t ne2000_device; extern const device_t ne2000_compat_device; extern const device_t ne2000_compat_8bit_device; extern const device_t ethernext_mc_device; -extern const device_t rtl8019as_device; +extern const device_t rtl8019as_pnp_device; extern const device_t de220p_device; extern const device_t rtl8029as_device; diff --git a/src/include/86box/nvr.h b/src/include/86box/nvr.h index 85e0954f0..0f7d22172 100644 --- a/src/include/86box/nvr.h +++ b/src/include/86box/nvr.h @@ -60,6 +60,7 @@ #define TIME_SYNC_ENABLED 1 #define TIME_SYNC_UTC 2 +#ifdef _TIMER_H_ /* Define a generic RTC/NVRAM device. */ typedef struct _nvr_ { char *fn; /* pathname of image file */ @@ -104,8 +105,6 @@ extern const device_t elt_nvr_device; extern void rtc_tick(void); extern void nvr_init(nvr_t *); -extern char *nvr_path(char *str); -extern FILE *nvr_fopen(char *str, char *mode); extern int nvr_load(void); extern void nvr_close(void); extern void nvr_set_ven_save(void (*ven_save)(void)); @@ -114,8 +113,8 @@ extern int nvr_save(void); extern int nvr_is_leap(int year); extern int nvr_get_days(int month, int year); extern void nvr_time_sync(void); -extern void nvr_time_get(struct tm *); -extern void nvr_time_set(struct tm *); +extern void nvr_time_get(void *priv); +extern void nvr_time_set(void *priv); extern void nvr_reg_write(uint16_t reg, uint8_t val, void *priv); extern void nvr_at_handler(int set, uint16_t base, nvr_t *nvr); @@ -132,5 +131,9 @@ extern void nvr_irq_set(int irq, nvr_t *nvr); extern void nvr_smi_enable(int enable, nvr_t *nvr); extern uint8_t nvr_smi_status(nvr_t *nvr); extern void nvr_smi_status_clear(nvr_t *nvr); +#endif + +extern char *nvr_path(char *str); +extern FILE *nvr_fopen(char *str, char *mode); #endif /*EMU_NVR_H*/ diff --git a/src/include/86box/plat.h b/src/include/86box/plat.h index 4a310ab44..f39f6ba51 100644 --- a/src/include/86box/plat.h +++ b/src/include/86box/plat.h @@ -32,8 +32,8 @@ /* String ID numbers. */ enum { STRING_MOUSE_CAPTURE, /* "Click to capture mouse" */ - STRING_MOUSE_RELEASE, /* "Press F8+F12/Ctrl+End to release mouse" */ - STRING_MOUSE_RELEASE_MMB, /* "Press F8+F12/Ctrl+End or middle button to release mouse" */ + STRING_MOUSE_RELEASE, /* "Press F8+F12 to release mouse" */ + STRING_MOUSE_RELEASE_MMB, /* "Press F8+F12 or middle button to release mouse" */ STRING_INVALID_CONFIG, /* "Invalid configuration" */ STRING_NO_ST506_ESDI_CDROM, /* "MFM/RLL or ESDI CD-ROM drives never existed" */ STRING_NET_ERROR, /* "Failed to initialize network driver" */ @@ -47,6 +47,7 @@ enum { STRING_HW_NOT_AVAILABLE_MACHINE, /* "Machine \"%hs\" is not available..." */ STRING_HW_NOT_AVAILABLE_VIDEO, /* "Video card \"%hs\" is not available..." */ STRING_HW_NOT_AVAILABLE_VIDEO2, /* "Video card #2 \"%hs\" is not available..." */ + STRING_HW_NOT_AVAILABLE_DEVICE, /* "Device \"%hs\" is not available..." */ STRING_MONITOR_SLEEP, /* "Monitor in sleep mode" */ STRING_GHOSTPCL_ERROR_TITLE, /* "Unable to initialize GhostPCL" */ STRING_GHOSTPCL_ERROR_DESC /* "gpcl6dll32.dll/gpcl6dll64.dll/libgpcl6 is required..." */ @@ -187,9 +188,6 @@ extern void zip_reload(uint8_t id); extern void mo_eject(uint8_t id); extern void mo_mount(uint8_t id, char *fn, uint8_t wp); extern void mo_reload(uint8_t id); -extern int ioctl_open(uint8_t id, char d); -extern void ioctl_reset(uint8_t id); -extern void ioctl_close(uint8_t id); /* Other stuff. */ extern void startblit(void); diff --git a/src/include/86box/plat_cdrom.h b/src/include/86box/plat_cdrom.h deleted file mode 100644 index 643013a08..000000000 --- a/src/include/86box/plat_cdrom.h +++ /dev/null @@ -1,73 +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. - * - * Definitions for platform specific serial to host passthrough. - * - * - * Authors: Andreas J. Reichel , - * Jasmine Iwanek - * - * Copyright 2021 Andreas J. Reichel. - * Copyright 2021-2022 Jasmine Iwanek. - */ - -#ifndef PLAT_CDROM_H -#define PLAT_CDROM_H - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -#define RAW_SECTOR_SIZE 2352 -#define COOKED_SECTOR_SIZE 2048 - -#define DATA_TRACK 0x14 -#define AUDIO_TRACK 0x10 - -#define CD_FPS 75 -#define FRAMES_TO_MSF(f, M, S, F) \ - { \ - uint64_t value = f; \ - *(F) = (value % CD_FPS) & 0xff; \ - value /= CD_FPS; \ - *(S) = (value % 60) & 0xff; \ - value /= 60; \ - *(M) = value & 0xff; \ - } -#define MSF_TO_FRAMES(M, S, F) ((M) *60 * CD_FPS + (S) *CD_FPS + (F)) - -typedef struct SMSF { - uint16_t min; - uint8_t sec; - uint8_t fr; -} TMSF; - -extern void plat_cdrom_get_raw_track_info(void *local, int *num, raw_track_info_t *rti); -extern int plat_cdrom_is_track_audio(void *local, uint32_t sector); -extern int plat_cdrom_is_track_pre(void *local, uint32_t sector); -extern uint32_t plat_cdrom_get_last_block(void *local); -extern int plat_cdrom_get_audio_track_info(void *local, int end, int track, int *track_num, TMSF *start, - uint8_t *attr); -extern int plat_cdrom_get_audio_sub(void *local, uint32_t sector, uint8_t *attr, uint8_t *track, - uint8_t *index, TMSF *rel_pos, TMSF *abs_pos); -extern int plat_cdrom_get_sector_size(void *local, uint32_t sector); -extern int plat_cdrom_read_sector(void *local, uint8_t *buffer, uint32_t sector); -extern void plat_cdrom_eject(void *local); -extern void plat_cdrom_close(void *local); -extern int plat_cdrom_set_drive(void *local, const char *drv); -extern int plat_cdrom_ext_medium_changed(void *local); -extern uint32_t plat_cdrom_get_track_start(void *local, uint32_t sector, uint8_t *attr, uint8_t *track); -extern int plat_cdrom_get_local_size(void); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/src/include/86box/plat_cdrom_ioctl.h b/src/include/86box/plat_cdrom_ioctl.h new file mode 100644 index 000000000..471222134 --- /dev/null +++ b/src/include/86box/plat_cdrom_ioctl.h @@ -0,0 +1,34 @@ +/* + * 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. + * + * Definitions for platform specific serial to host passthrough. + * + * + * Authors: Andreas J. Reichel , + * Jasmine Iwanek + * + * Copyright 2021 Andreas J. Reichel. + * Copyright 2021-2022 Jasmine Iwanek. + */ + +#ifndef PLAT_CDROM_IOCTL_H +#define PLAT_CDROM_IOCTL_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +extern void * ioctl_open(cdrom_t *dev, const char *drv); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/include/86box/scsi.h b/src/include/86box/scsi.h index 32ad1f912..84a4a608e 100644 --- a/src/include/86box/scsi.h +++ b/src/include/86box/scsi.h @@ -29,15 +29,21 @@ #define SCSI_ID_MAX 16 /* 16 on wide buses */ #define SCSI_LUN_MAX 8 /* always 8 */ -extern int scsi_card_current[SCSI_CARD_MAX]; +extern int scsi_card_current[SCSI_CARD_MAX]; -extern int scsi_card_available(int card); +extern void scsi_reset(void); +extern uint8_t scsi_get_bus(void); + +extern int scsi_card_available(int card); #ifdef EMU_DEVICE_H extern const device_t *scsi_card_getdevice(int card); #endif -extern int scsi_card_has_config(int card); -extern const char *scsi_card_get_internal_name(int card); -extern int scsi_card_get_from_internal_name(char *s); -extern void scsi_card_init(void); +extern int scsi_card_has_config(int card); +extern const char *scsi_card_get_internal_name(int card); +extern int scsi_card_get_from_internal_name(char *s); +extern void scsi_card_init(void); + +extern void scsi_bus_set_speed(uint8_t bus, double speed); +extern double scsi_bus_get_speed(uint8_t bus); #endif /*EMU_SCSI_H*/ diff --git a/src/include/86box/scsi_cdrom.h b/src/include/86box/scsi_cdrom.h index 684a9d589..bc2d4c8bd 100644 --- a/src/include/86box/scsi_cdrom.h +++ b/src/include/86box/scsi_cdrom.h @@ -26,47 +26,56 @@ typedef struct scsi_cdrom_t { /* Common block. */ mode_sense_pages_t ms_pages_saved; - cdrom_t * drv; + cdrom_t * drv; #ifdef EMU_IDE_H - ide_tf_t *tf; + ide_tf_t * tf; #else - void * tf; + void * tf; #endif - uint8_t *buffer; - uint8_t atapi_cdb[16]; - uint8_t current_cdb[16]; - uint8_t sense[256]; + void * log; - uint8_t id; - uint8_t cur_lun; - uint8_t early; - uint8_t pad1; + uint8_t * buffer; + uint8_t atapi_cdb[16]; + uint8_t current_cdb[16]; + uint8_t sense[256]; - uint16_t max_transfer_len; - uint16_t pad2; + uint8_t id; + uint8_t cur_lun; + uint8_t early; + uint8_t sector_type; - int requested_blocks; - int packet_status; - int total_length; - int do_page_save; - int unit_attention; - int request_pos; - int old_len; - int media_status; + uint16_t max_transfer_len; + uint16_t sector_flags; - uint32_t sector_pos; - uint32_t sector_len; - uint32_t packet_len; + int requested_blocks; + int packet_status; + int total_length; + int do_page_save; + int unit_attention; + int request_pos; + int old_len; + int media_status; - double callback; + uint32_t sector_pos; + uint32_t sector_len; + uint32_t packet_len; - uint8_t (*ven_cmd)(void *sc, uint8_t *cdb, int32_t *BufLen); + double callback; - int sony_vendor; + int is_sony; + int use_cdb_9; + + uint8_t ven_cmd_is_data[256]; - mode_sense_pages_t ms_pages_saved_sony; mode_sense_pages_t ms_drive_status_pages_saved; + + uint64_t ms_page_flags; + + mode_sense_pages_t ms_pages_default; + mode_sense_pages_t ms_pages_changeable; + + uint8_t (*ven_cmd)(void *sc, const uint8_t *cdb, int32_t *BufLen); } scsi_cdrom_t; #endif @@ -74,10 +83,12 @@ extern scsi_cdrom_t *scsi_cdrom[CDROM_NUM]; #define scsi_cdrom_sense_error dev->sense[0] #define scsi_cdrom_sense_key dev->sense[2] +#define scsi_cdrom_info *(uint32_t *) &(dev->sense[3]) #define scsi_cdrom_asc dev->sense[12] #define scsi_cdrom_ascq dev->sense[13] #define scsi_cdrom_drive cdrom_drives[id].host_drive extern void scsi_cdrom_reset(scsi_common_t *sc); +extern void scsi_cdrom_drive_reset(const int c); #endif /*EMU_SCSI_CDROM_H*/ diff --git a/src/include/86box/scsi_device.h b/src/include/86box/scsi_device.h index 6fdac5ebd..ffe042481 100644 --- a/src/include/86box/scsi_device.h +++ b/src/include/86box/scsi_device.h @@ -21,6 +21,7 @@ #define SCSI_DEVICE_H /* Configuration. */ +#define SCSI_NUM (SCSI_BUS_MAX * SCSI_ID_MAX) #define SCSI_LUN_USE_CDB 0xff @@ -53,8 +54,8 @@ #define GPCMD_SEEK_6 0x0b #define GPCMD_IOMEGA_SET_PROTECTION_MODE 0x0c #define GPCMD_IOMEGA_EJECT 0x0d /* ATAPI only? */ -#define GPCMD_NO_OPERATION_TOSHIBA 0x0d /* Toshiba Vendor Unique command */ -#define GPCMD_NO_OPERATION_NEC 0x0d /* NEC Vendor Unique command */ +#define GPCMD_NO_OPERATION_TOSHIBA 0x0d /* Toshiba Vendor Unique command. */ +#define GPCMD_NO_OPERATION_NEC 0x0d /* NEC Vendor Unique command. */ #define GPCMD_INQUIRY 0x12 #define GPCMD_VERIFY_6 0x13 #define GPCMD_MODE_SELECT_6 0x15 @@ -66,7 +67,7 @@ #define GPCMD_PREVENT_REMOVAL 0x1e #define GPCMD_READ_FORMAT_CAPACITIES 0x23 #define GPCMD_READ_CDROM_CAPACITY 0x25 -#define GPCMD_UNKNOWN_CHINON 0x26 /*Chinon Vendor Unique command*/ +#define GPCMD_UNKNOWN_CHINON 0x26 /* Chinon Vendor Unique command. */ #define GPCMD_READ_10 0x28 #define GPCMD_READ_GENERATION 0x29 #define GPCMD_WRITE_10 0x2a @@ -218,7 +219,7 @@ #define ASC_INV_FIELD_IN_PARAMETER_LIST 0x26 #define ASC_WRITE_PROTECTED 0x27 #define ASC_MEDIUM_MAY_HAVE_CHANGED 0x28 -#define ASC_CAPACITY_DATA_CHANGED 0x2A +#define ASC_CAPACITY_DATA_CHANGED 0x2a #define ASC_INCOMPATIBLE_FORMAT 0x30 #define ASC_MEDIUM_NOT_PRESENT 0x3a #define ASC_DATA_PHASE_ERROR 0x4b @@ -233,16 +234,12 @@ #define ASCQ_AUDIO_PLAY_OPERATION_PAUSED 0x12 #define ASCQ_AUDIO_PLAY_OPERATION_COMPLETED 0x13 -/* Tell RISC OS that we have a 4x CD-ROM drive (600kb/sec data, 706kb/sec raw). - Not that it means anything */ -#define CDROM_SPEED 706 /* 0x2C2 */ - -#define BUFFER_SIZE (256 * 1024) - -#define RW_DELAY (TIMER_USEC * 500) - /* Some generally useful CD-ROM information */ +#ifdef CONSERVATIVE_MAXIMUM #define CD_MINS 90 /* max. minutes per CD */ +#else +#define CD_MINS 100 /* max. minutes per CD - yes, 100-minute CD's in fact existed */ +#endif #define CD_SECS 60 /* seconds per minute */ #define CD_FRAMES 75 /* frames per second */ #define CD_FRAMESIZE 2048 /* bytes per frame, "cooked" mode */ @@ -276,6 +273,10 @@ /* Profile list from MMC-6 revision 1 table 91 */ #define MMC_PROFILE_NONE 0x0000 +#define MMC_PROFILE_REMOVABLE_DISK 0x0002 +#define MMC_PROFILE_MO 0x0003 +#define MMC_PROFILE_MO_WORM 0x0004 +#define MMC_PROFILE_AS_MO 0x0005 #define MMC_PROFILE_CD_ROM 0x0008 #define MMC_PROFILE_CD_R 0x0009 #define MMC_PROFILE_CD_RW 0x000A @@ -304,7 +305,6 @@ #define MMC_PROFILE_HDDVD_RW_DL 0x005A #define MMC_PROFILE_INVALID 0xFFFF -#define EARLY_ONLY 64 #define SCSI_ONLY 32 #define ATAPI_ONLY 16 #define IMPLEMENTED 8 @@ -312,8 +312,6 @@ #define CHECK_READY 2 #define ALLOW_UA 1 -#define MSFtoLBA(m, s, f) ((((m * 60) + s) * 75) + f) - #define MSG_COMMAND_COMPLETE 0x00 #define BUS_DBP 0x01 @@ -333,6 +331,20 @@ #define BUS_IDLE (1 << 31) +#define STATE_IDLE 0 +#define STATE_COMMAND 1 +#define STATE_DATAIN 2 +#define STATE_DATAOUT 3 +#define STATE_STATUS 4 +#define STATE_MESSAGEIN 5 +#define STATE_SELECT 6 +#define STATE_MESSAGEOUT 7 +#define STATE_MESSAGE_ID 8 + +#define PIO_TX_BUS 0 +#define DMA_IN_TX_BUS 1 +#define DMA_OUT_TX_BUS 2 + #define PHASE_IDLE 0x00 #define PHASE_COMMAND 0x01 #define PHASE_DATA_IN 0x02 @@ -357,7 +369,7 @@ #define MODE_SELECT_PHASE_PAGE 4 typedef struct mode_sense_pages_t { - uint8_t pages[0x40][0x40]; + uint8_t pages[0x40][0x40]; } mode_sense_pages_t; /* This is so we can access the common elements to all SCSI device structs @@ -365,61 +377,107 @@ typedef struct mode_sense_pages_t { typedef struct scsi_common_s { mode_sense_pages_t ms_pages_saved; - void * priv; + void * priv; #ifdef EMU_IDE_H - ide_tf_t *tf; + ide_tf_t * tf; #else - void * tf; + void * tf; #endif - uint8_t *temp_buffer; - uint8_t atapi_cdb[16]; /* This is atapi_cdb in ATAPI-supporting devices, - and pad in SCSI-only devices. */ - uint8_t current_cdb[16]; - uint8_t sense[256]; + void * log; - uint8_t id; - uint8_t cur_lun; - uint8_t pad0; - uint8_t pad1; + uint8_t * temp_buffer; + /* + This is atapi_cdb in ATAPI-supporting devices, + and pad in SCSI-only devices. + */ + uint8_t atapi_cdb[16]; + uint8_t current_cdb[16]; + uint8_t sense[256]; - uint16_t max_transfer_len; - uint16_t pad2; + uint8_t id; + uint8_t cur_lun; + uint8_t pad0; + uint8_t pad1; - int requested_blocks; - int packet_status; - int total_length; - int do_page_save; - int unit_attention; - int request_pos; - int old_len; - int media_status; + uint16_t max_transfer_len; + uint16_t pad2; - uint32_t sector_pos; - uint32_t sector_len; - uint32_t packet_len; + int requested_blocks; + int packet_status; + int total_length; + int do_page_save; + int unit_attention; + int request_pos; + int old_len; + int media_status; - double callback; + uint32_t sector_pos; + uint32_t sector_len; + uint32_t packet_len; - uint8_t (*ven_cmd)(void *sc, uint8_t *cdb, int32_t *BufLen); + double callback; + + uint8_t (*ven_cmd)(void *sc, uint8_t *cdb, int32_t *BufLen); } scsi_common_t; typedef struct scsi_device_t { - int32_t buffer_length; + int32_t buffer_length; - uint8_t status; - uint8_t phase; - uint16_t type; + uint8_t status; + uint8_t phase; - scsi_common_t *sc; + uint16_t type; - void (*command)(scsi_common_t *sc, uint8_t *cdb); - void (*request_sense)(scsi_common_t *sc, uint8_t *buffer, uint8_t alloc_length); - void (*reset)(scsi_common_t *sc); - uint8_t (*phase_data_out)(scsi_common_t *sc); - void (*command_stop)(scsi_common_t *sc); + scsi_common_t * sc; + + void (*command)(scsi_common_t *sc, const uint8_t *cdb); + void (*request_sense)(scsi_common_t *sc, uint8_t *buffer, + uint8_t alloc_length); + void (*reset)(scsi_common_t *sc); + uint8_t (*phase_data_out)(scsi_common_t *sc); + void (*command_stop)(scsi_common_t *sc); } scsi_device_t; +typedef struct scsi_bus_t { + uint8_t data; + uint8_t msglun; + uint8_t data_wait; + uint8_t target_id; + uint8_t bus_device; + uint8_t pad; + uint8_t pad0; + uint8_t pad1; + + uint8_t command[16]; + uint8_t msgout[4]; + uint8_t pad2[4]; + + int tx_mode; + int clear_req; + int wait_data; + int wait_complete; + int bus_out; + int bus_in; + int command_pos; + int command_issued; + int data_pos; + int msgout_pos; + int is_msgout; + int state; + int dma_on_pio_enabled; + + uint32_t bus_phase; + + double period; + double speed; + double divider; + double multi; + + void *priv; + void (*timer)(void *priv, double period); +} scsi_bus_t; + /* These are based on the INQUIRY values. */ #define SCSI_NONE 0x0060 #define SCSI_FIXED_DISK 0x0000 @@ -430,15 +488,8 @@ typedef struct scsi_device_t { extern scsi_device_t scsi_devices[SCSI_BUS_MAX][SCSI_ID_MAX]; #endif /* EMU_SCSI_H */ -extern int cdrom_add_error_and_subchannel(uint8_t *b, int real_sector_type); -extern int cdrom_LBAtoMSF_accurate(void); - -extern int mode_select_init(uint8_t command, uint16_t pl_length, uint8_t do_save); -extern int mode_select_terminate(int force); -extern int mode_select_write(uint8_t val); - -extern uint8_t *scsi_device_sense(scsi_device_t *dev); extern double scsi_device_get_callback(scsi_device_t *dev); +extern uint8_t *scsi_device_sense(scsi_device_t *dev); extern void scsi_device_request_sense(scsi_device_t *dev, uint8_t *buffer, uint8_t alloc_length); extern void scsi_device_reset(scsi_device_t *dev); @@ -446,14 +497,16 @@ extern int scsi_device_present(scsi_device_t *dev); extern int scsi_device_valid(scsi_device_t *dev); extern int scsi_device_cdb_length(scsi_device_t *dev); extern void scsi_device_command_phase0(scsi_device_t *dev, uint8_t *cdb); -extern void scsi_device_command_phase1(scsi_device_t *dev); extern void scsi_device_command_stop(scsi_device_t *dev); +extern void scsi_device_command_phase1(scsi_device_t *dev); extern void scsi_device_identify(scsi_device_t *dev, uint8_t lun); extern void scsi_device_close_all(void); extern void scsi_device_init(void); extern void scsi_reset(void); extern uint8_t scsi_get_bus(void); +extern int scsi_bus_read(scsi_bus_t *scsi_bus); +extern void scsi_bus_update(scsi_bus_t *scsi_bus, int bus); extern void scsi_bus_set_speed(uint8_t bus, double speed); extern double scsi_bus_get_speed(uint8_t bus); diff --git a/src/include/86box/scsi_disk.h b/src/include/86box/scsi_disk.h index 8c7e045fb..7099b836a 100644 --- a/src/include/86box/scsi_disk.h +++ b/src/include/86box/scsi_disk.h @@ -19,42 +19,44 @@ typedef struct scsi_disk_t { mode_sense_pages_t ms_pages_saved; - hard_disk_t *drv; + hard_disk_t * drv; #ifdef EMU_IDE_H - ide_tf_t * tf; + ide_tf_t * tf; #else - void * tf; + void * tf; #endif - uint8_t *temp_buffer; - uint8_t atapi_cdb[16]; - uint8_t current_cdb[16]; - uint8_t sense[256]; + void * log; - uint8_t id; - uint8_t cur_lun; - uint8_t pad0; - uint8_t pad1; + uint8_t * temp_buffer; + uint8_t atapi_cdb[16]; + uint8_t current_cdb[16]; + uint8_t sense[256]; - uint16_t max_transfer_len; - uint16_t pad2; + uint8_t id; + uint8_t cur_lun; + uint8_t pad0; + uint8_t pad1; - int requested_blocks; - int packet_status; - int total_length; - int do_page_save; - int unit_attention; - int request_pos; - int pad6; - int pad7; + uint16_t max_transfer_len; + uint16_t pad2; - uint32_t sector_pos; - uint32_t sector_len; - uint32_t packet_len; + int requested_blocks; + int packet_status; + int total_length; + int do_page_save; + int unit_attention; + int request_pos; + int pad6; + int pad7; - double callback; + uint32_t sector_pos; + uint32_t sector_len; + uint32_t packet_len; - uint8_t (*ven_cmd)(void *sc, uint8_t *cdb, int32_t *BufLen); + double callback; + + uint8_t (*ven_cmd)(void *sc, uint8_t *cdb, int32_t *BufLen); } scsi_disk_t; extern scsi_disk_t *scsi_disk[HDD_NUM]; diff --git a/src/include/86box/scsi_ncr5380.h b/src/include/86box/scsi_ncr5380.h index 09307fed6..5a43ba76a 100644 --- a/src/include/86box/scsi_ncr5380.h +++ b/src/include/86box/scsi_ncr5380.h @@ -44,6 +44,9 @@ #define ICR_ACK 0x10 #define ICR_ARB_LOST 0x20 #define ICR_ARB_IN_PROGRESS 0x40 +#define ICR_RST 0x80 +#define ICR_PHASE 0x9e +#define ICR_WRITE 0x9f #define MODE_ARBITRATE 0x01 #define MODE_DMA 0x02 @@ -63,70 +66,34 @@ #define TCR_REQ 0x08 #define TCR_LAST_BYTE_SENT 0x80 - -#define STATE_IDLE 0 -#define STATE_COMMAND 1 -#define STATE_DATAIN 2 -#define STATE_DATAOUT 3 -#define STATE_STATUS 4 -#define STATE_MESSAGEIN 5 -#define STATE_SELECT 6 -#define STATE_MESSAGEOUT 7 -#define STATE_MESSAGE_ID 8 - -#define DMA_IDLE 0 -#define DMA_SEND 1 -#define DMA_INITIATOR_RECEIVE 2 - typedef struct ncr_t { uint8_t icr; uint8_t mode; uint8_t tcr; - uint8_t data_wait; uint8_t isr; uint8_t output_data; - uint8_t target_id; uint8_t tx_data; - uint8_t msglun; uint8_t irq_state; + uint8_t isr_reg; - uint8_t command[20]; - uint8_t msgout[4]; uint8_t bus; - int msgout_pos; - int is_msgout; - - int dma_mode; - int cur_bus; - int bus_in; - int new_phase; - int state; - int clear_req; - int wait_data; - int wait_data_back; - int wait_complete; - int command_pos; - int data_pos; - int irq; double period; void *priv; - void (*dma_mode_ext)(void *priv, void *ext_priv); + void (*dma_mode_ext)(void *priv, void *ext_priv, uint8_t val); int (*dma_send_ext)(void *priv, void *ext_priv); int (*dma_initiator_receive_ext)(void *priv, void *ext_priv); void (*timer)(void *ext_priv, double period); + + scsi_bus_t scsibus; } ncr_t; -extern int ncr5380_cmd_len[8]; - extern void ncr5380_irq(ncr_t *ncr, int set_irq); -extern void ncr5380_set_irq(ncr_t *ncr, int irq); +extern void ncr5380_set_irq(ncr_t *ncr, int irq); extern uint32_t ncr5380_get_bus_host(ncr_t *ncr); -extern void ncr5380_bus_read(ncr_t *ncr); -extern void ncr5380_bus_update(ncr_t *ncr, int bus); extern void ncr5380_write(uint16_t port, uint8_t val, ncr_t *ncr); extern uint8_t ncr5380_read(uint16_t port, ncr_t *ncr); diff --git a/src/include/86box/version.h.in b/src/include/86box/version.h.in index 5ebf7dba9..17c5b3068 100644 --- a/src/include/86box/version.h.in +++ b/src/include/86box/version.h.in @@ -14,6 +14,8 @@ * * Copyright 2020 Miran Grca. */ +#ifndef EMU_VERSION_H +#define EMU_VERSION_H #define _LSTR(s) L ## s #define LSTR(s) _LSTR(s) @@ -58,3 +60,5 @@ # define EMU_DOCS_URL "https://86box.readthedocs.io" #endif #define EMU_DOCS_URL_W LSTR(EMU_DOCS_URL) + +#endif /*EMU_VERSION_H*/ diff --git a/src/include/86box/vid_svga.h b/src/include/86box/vid_svga.h index 2b26df2f3..3be4ee9e5 100644 --- a/src/include/86box/vid_svga.h +++ b/src/include/86box/vid_svga.h @@ -189,6 +189,7 @@ typedef struct svga_t { void (*render)(struct svga_t *svga); void (*render8514)(struct svga_t *svga); + void (*render_xga)(struct svga_t *svga); void (*recalctimings_ex)(struct svga_t *svga); void (*video_out)(uint16_t addr, uint8_t val, void *priv); @@ -306,6 +307,7 @@ typedef struct svga_t { void * xga; } svga_t; +extern void ibm8514_set_poll(svga_t *svga); extern void ibm8514_poll(void *priv); extern void ibm8514_recalctimings(svga_t *svga); extern uint8_t ibm8514_ramdac_in(uint16_t port, void *priv); @@ -328,10 +330,11 @@ extern void ati8514_mca_write(int port, uint8_t val, void *priv); extern void ati8514_pos_write(uint16_t port, uint8_t val, void *priv); extern void ati8514_init(svga_t *svga, void *ext8514, void *dev8514); -extern void xga_write_test(uint32_t addr, uint8_t val, void *priv); -extern uint8_t xga_read_test(uint32_t addr, void *priv); -extern void xga_poll(void *priv); -extern void xga_recalctimings(svga_t *svga); +extern void xga_write_test(uint32_t addr, uint8_t val, void *priv); +extern uint8_t xga_read_test(uint32_t addr, void *priv); +extern void xga_set_poll(svga_t *svga); +extern void xga_poll(void *priv); +extern void xga_recalctimings(svga_t *svga); extern uint32_t svga_decode_addr(svga_t *svga, uint32_t addr, int write); @@ -376,6 +379,7 @@ uint32_t svga_mask_addr(uint32_t addr, svga_t *svga); uint32_t svga_mask_changedaddr(uint32_t addr, svga_t *svga); void svga_doblit(int wx, int wy, svga_t *svga); +void svga_set_poll(svga_t *svga); void svga_poll(void *priv); enum { diff --git a/src/include/86box/vid_xga.h b/src/include/86box/vid_xga.h index b90b53978..b2001dba9 100644 --- a/src/include/86box/vid_xga.h +++ b/src/include/86box/vid_xga.h @@ -240,8 +240,6 @@ typedef struct xga_t { uint16_t px_map_height[4]; uint32_t px_map_base[4]; } accel; - - int big_endian_linear; } xga_t; #endif /*VIDEO_XGA_H*/ diff --git a/src/include/86box/zip.h b/src/include/86box/zip.h index 739ba388b..06c6e8485 100644 --- a/src/include/86box/zip.h +++ b/src/include/86box/zip.h @@ -13,7 +13,7 @@ * * Authors: Miran Grca, * - * Copyright 2018-2019 Miran Grca. + * Copyright 2018-2025 Miran Grca. */ #ifndef EMU_ZIP_H @@ -29,7 +29,7 @@ #define ZIP_250_SECTORS (489532) -#define ZIP_IMAGE_HISTORY 4 +#define ZIP_IMAGE_HISTORY 10 enum { ZIP_BUS_DISABLED = 0, @@ -39,76 +39,79 @@ enum { }; typedef struct zip_drive_t { - uint8_t id; + uint8_t id; union { - uint8_t res; - uint8_t res0; /* Reserved for other ID's. */ - uint8_t res1; - uint8_t ide_channel; - uint8_t scsi_device_id; + uint8_t res; + /* Reserved for other ID's. */ + uint8_t res0; + uint8_t res1; + uint8_t ide_channel; + uint8_t scsi_device_id; }; - uint8_t bus_type; /* 0 = ATAPI, 1 = SCSI */ - uint8_t bus_mode; /* Bit 0 = PIO suported; - Bit 1 = DMA supportd. */ - uint8_t read_only; /* Struct variable reserved for - media status. */ - uint8_t pad; - uint8_t pad0; + uint8_t bus_type; /* 0 = ATAPI, 1 = SCSI */ + uint8_t bus_mode; /* Bit 0 = PIO suported; + Bit 1 = DMA supportd. */ + uint8_t read_only; /* Struct variable reserved for + media status. */ + uint8_t pad; + uint8_t pad0; - FILE *fp; - void *priv; + FILE * fp; + void * priv; - char image_path[1024]; - char prev_image_path[1024]; + char image_path[1024]; + char prev_image_path[1024]; - char *image_history[ZIP_IMAGE_HISTORY]; + char * image_history[ZIP_IMAGE_HISTORY]; - uint32_t is_250; - uint32_t medium_size; - uint32_t base; + uint32_t is_250; + uint32_t medium_size; + uint32_t base; } zip_drive_t; typedef struct zip_t { mode_sense_pages_t ms_pages_saved; - zip_drive_t *drv; + zip_drive_t * drv; #ifdef EMU_IDE_H - ide_tf_t * tf; + ide_tf_t * tf; #else - void * tf; + void * tf; #endif - uint8_t *buffer; - uint8_t atapi_cdb[16]; - uint8_t current_cdb[16]; - uint8_t sense[256]; + void * log; - uint8_t id; - uint8_t cur_lun; - uint8_t pad0; - uint8_t pad1; + uint8_t * buffer; + uint8_t atapi_cdb[16]; + uint8_t current_cdb[16]; + uint8_t sense[256]; - uint16_t max_transfer_len; - uint16_t pad2; + uint8_t id; + uint8_t cur_lun; + uint8_t pad0; + uint8_t pad1; - int requested_blocks; - int packet_status; - int total_length; - int do_page_save; - int unit_attention; - int request_pos; - int old_len; - int pad3; + uint16_t max_transfer_len; + uint16_t pad2; - uint32_t sector_pos; - uint32_t sector_len; - uint32_t packet_len; + int requested_blocks; + int packet_status; + int total_length; + int do_page_save; + int unit_attention; + int request_pos; + int old_len; + int transition; - double callback; + uint32_t sector_pos; + uint32_t sector_len; + uint32_t packet_len; - uint8_t (*ven_cmd)(void *sc, uint8_t *cdb, int32_t *BufLen); + double callback; + + uint8_t (*ven_cmd)(void *sc, uint8_t *cdb, int32_t *BufLen); } zip_t; extern zip_t *zip[ZIP_NUM]; @@ -118,6 +121,7 @@ extern uint8_t scsi_zip_drives[16]; #define zip_sense_error dev->sense[0] #define zip_sense_key dev->sense[2] +#define zip_info *(uint32_t *) &(dev->sense[3]) #define zip_asc dev->sense[12] #define zip_ascq dev->sense[13] @@ -125,15 +129,16 @@ extern uint8_t scsi_zip_drives[16]; extern "C" { #endif -extern void zip_disk_close(zip_t *dev); -extern void zip_disk_reload(zip_t *dev); +extern void zip_disk_close(const zip_t *dev); +extern void zip_disk_reload(const zip_t *dev); extern void zip_insert(zip_t *dev); extern void zip_global_init(void); extern void zip_hard_reset(void); extern void zip_reset(scsi_common_t *sc); -extern int zip_load(zip_t *dev, char *fn); +extern int zip_is_empty(const uint8_t id); +extern void zip_load(const zip_t *dev, const char *fn, const int skip_insert); extern void zip_close(void); #ifdef __cplusplus diff --git a/src/ioapic.c b/src/ioapic.c index c3939f249..b5ca4c7a7 100644 --- a/src/ioapic.c +++ b/src/ioapic.c @@ -122,7 +122,7 @@ const device_t ioapic_device = { .init = ioapic_init, .close = ioapic_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/log.c b/src/log.c index a4d84e616..c8dddf62e 100644 --- a/src/log.c +++ b/src/log.c @@ -6,16 +6,14 @@ * * This file is part of the 86Box distribution. * - * The handler of the new logging system. - * - * + * New logging system handler. * * Authors: Miran Grca, * Fred N. van Kempen, - * Connor Hyde + * Connor Hyde, * - * Copyright 2021 Miran Grca. - * Copyright 2021 Fred N. van Kempen. + * Copyright 2021-25 Miran Grca. + * Copyright 2021-25 Fred N. van Kempen. * Copyright 2025 Connor Hyde. */ #include @@ -37,21 +35,44 @@ #include <86box/version.h> #include <86box/log.h> -#ifndef RELEASE_BUILD typedef struct log_t { - char buff[1024]; - char *dev_name; - int seen; - int suppr_seen; - char cyclic_buff[LOG_SIZE_BUFFER_CYCLIC_LINES][LOG_SIZE_BUFFER]; // Cyclical log buffer. This is 32kb, might calloc? - int32_t cyclic_last_line; - int32_t log_cycles; + char buff[1024]; + char dev_name[1024]; + int seen; + int suppr_seen; + /* Cyclical log buffer. */ + char **cyclic_buff; + int32_t cyclic_last_line; + int32_t log_cycles; } log_t; -extern FILE *stdlog; /* file to log output to */ -// Functions only used in this translation unit +/* File to log output to. */ +extern FILE *stdlog; +/* Functions only used in this translation unit. */ void log_ensure_stdlog_open(void); +void +log_set_dev_name(void *priv, char *dev_name) +{ + log_t *log = (log_t *) priv; + + memcpy(log->dev_name, dev_name, strlen(dev_name) + 1); +} + +static void +log_copy(log_t *log, char *dest, const char *src, size_t dest_size) +{ + memset(dest, 0x00, dest_size * sizeof(char)); + + if ((log != NULL) && strcmp(log->dev_name, "")) { + strcat(dest, log->dev_name); + strcat(dest, ": "); + } + + strcat(dest, src); +} + +#ifndef RELEASE_BUILD void log_ensure_stdlog_open(void) { @@ -73,31 +94,12 @@ log_set_suppr_seen(void *priv, int suppr_seen) log->suppr_seen = suppr_seen; } -void -log_set_dev_name(void *priv, char *dev_name) -{ - log_t *log = (log_t *) priv; - - log->dev_name = dev_name; -} - -static void -log_copy(log_t *log, char *dest, const char *src, size_t dest_size) -{ - memset(dest, 0x00, dest_size * sizeof(char)); - if (log && log->dev_name && strcmp(log->dev_name, "")) { - strcat(dest, log->dev_name); - strcat(dest, ": "); - } - strcat(dest, src); -} - /* - * Log something to the logfile or stdout. - * - * To avoid excessively-large logfiles because some - * module repeatedly logs, we keep track of what is - * being logged, and catch repeating entries. + Log something to the logfile or stdout. + + To avoid excessively-large logfiles because some + module repeatedly logs, we keep track of what is + being logged, and catch repeating entries. */ void log_out(void *priv, const char *fmt, va_list ap) @@ -107,154 +109,164 @@ log_out(void *priv, const char *fmt, va_list ap) char fmt2[1024]; if (log == NULL) - return; + pclog("WARNING: Logging called with a NULL log pointer\n"); + else if (fmt == NULL) + pclog("WARNING: Logging called with a NULL format pointer\n"); + else if (fmt[0] != '\0') { + log_ensure_stdlog_open(); - if (strcmp(fmt, "") == 0) - return; - - log_ensure_stdlog_open(); - - vsprintf(temp, fmt, ap); - if (log->suppr_seen && !strcmp(log->buff, temp)) - log->seen++; - else { - if (log->suppr_seen && log->seen) { - log_copy(log, fmt2, "*** %d repeats ***\n", 1024); - fprintf(stdlog, fmt2, log->seen); + vsprintf(temp, fmt, ap); + if (log->suppr_seen && !strcmp(log->buff, temp)) + log->seen++; + else { + if (log->suppr_seen && log->seen) { + log_copy(log, fmt2, "*** %d repeats ***\n", 1024); + fprintf(stdlog, fmt2, log->seen); + } + log->seen = 0; + strcpy(log->buff, temp); + log_copy(log, fmt2, temp, 1024); + fprintf(stdlog, fmt2, ap); } - log->seen = 0; - strcpy(log->buff, temp); - log_copy(log, fmt2, temp, 1024); - fprintf(stdlog, fmt2, ap); - } - fflush(stdlog); + fflush(stdlog); + } } - /* -Starfrost, 7-8 January 2025: + Starfrost, 7-8 January 2025: -For RIVA 128 emulation I needed a way to suppress logging if a repeated pattern of the same set of lines were found. + For RIVA 128 emulation I needed a way to suppress logging if a repeated + pattern of the same set of lines were found. -Implements a version of the Rabin-Karp algorithm https://en.wikipedia.org/wiki/Rabin%E2%80%93Karp_algorithm + Implements a version of the Rabin-Karp algorithm: + https://en.wikipedia.org/wiki/Rabin%E2%80%93Karp_algorithm . */ void log_out_cyclic(void* priv, const char* fmt, va_list ap) { -#ifndef RELEASE_BUILD - // get our new logging system instance. - log_t* log = (log_t*)priv; + /* Get our new logging system instance. */ + log_t* log = (log_t*) priv; - // does the log actually exist? - if (!log) - return; + /* Does the log actually exist? */ + if (log == NULL) + pclog("WARNING: Cyclical logging called with a NULL log pointer\n"); + else if (log->cyclic_buff == NULL) + pclog("WARNING: Cyclical logging called with a non-cyclic log\n"); + else if (fmt == NULL) + pclog("WARNING: Cyclical logging called with a NULL format pointer\n"); + /* Is the string empty? */ + else if (fmt[0] != '\0') { + /* Ensure stdlog is open. */ + log_ensure_stdlog_open(); - // is the string empty? - if (fmt[0] == '\0') - return; - - // ensure stdlog is open - log_ensure_stdlog_open(); + char temp[LOG_SIZE_BUFFER] = {0}; - char temp[LOG_SIZE_BUFFER] = {0}; + log->cyclic_last_line %= LOG_SIZE_BUFFER_CYCLIC_LINES; - log->cyclic_last_line %= LOG_SIZE_BUFFER_CYCLIC_LINES; + vsprintf(temp, fmt, ap); - vsprintf(temp, fmt, ap); + log_copy(log, log->cyclic_buff[log->cyclic_last_line], temp, + LOG_SIZE_BUFFER); - log_copy(log, log->cyclic_buff[log->cyclic_last_line], temp, LOG_SIZE_BUFFER); + uint32_t hashes[LOG_SIZE_BUFFER_CYCLIC_LINES] = {0}; - uint32_t hashes[LOG_SIZE_BUFFER_CYCLIC_LINES] = {0}; + /* Random numbers. */ + uint32_t base = 257; + uint32_t mod = 1000000007; - // Random numbers - uint32_t base = 257; - uint32_t mod = 1000000007; + uint32_t repeat_order = 0; + bool is_cycle = false; - uint32_t repeat_order = 0; - bool is_cycle = false; + /* Compute the set of hashes for the current log buffer. */ + for (int32_t log_line = 0; log_line < LOG_SIZE_BUFFER_CYCLIC_LINES; + log_line++) { + if (log->cyclic_buff[log_line][0] == '\0') + continue; /* Skip. */ - // compute the set of hashes for the current log buffer - for (int32_t log_line = 0; log_line < LOG_SIZE_BUFFER_CYCLIC_LINES; log_line++) - { - if (log->cyclic_buff[log_line][0] == '\0') - continue; // skip - - for (int32_t log_line_char = 0; log_line_char < LOG_SIZE_BUFFER; log_line_char++) - { - hashes[log_line] = hashes[log_line] * base + log->cyclic_buff[log_line][log_line_char] % mod; + for (int32_t log_line_char = 0; log_line_char < LOG_SIZE_BUFFER; + log_line_char++) + hashes[log_line] = hashes[log_line] * base + + log->cyclic_buff[log_line][log_line_char] % mod; } - } - - // Now see if there are real cycles... - // We implement a minimum repeat size. - for (int32_t check_size = LOG_MINIMUM_REPEAT_ORDER; check_size < LOG_SIZE_BUFFER_CYCLIC_LINES / 2; check_size++) - { - //TODO: Log what we need for cycle 1. - //TODO: Command line option that lets us turn off this behaviour. - for (int32_t log_line_to_check = 0; log_line_to_check < check_size; log_line_to_check++) - { - if (hashes[log_line_to_check] == hashes[(log_line_to_check + check_size) % LOG_SIZE_BUFFER_CYCLIC_LINES]) - { - repeat_order = check_size; - break; + /* + Now see if there are real cycles. + We implement a minimum repeat size. + */ + for (int32_t check_size = LOG_MINIMUM_REPEAT_ORDER; + check_size < LOG_SIZE_BUFFER_CYCLIC_LINES / 2; check_size++) { + /* + TODO: Log what we need for cycle 1. + TODO: Command line option that lets us turn off this behaviour. + */ + for (int32_t log_line_to_check = 0; log_line_to_check < check_size; + log_line_to_check++) { + if (hashes[log_line_to_check] == + hashes[(log_line_to_check + check_size) % + LOG_SIZE_BUFFER_CYCLIC_LINES]) { + repeat_order = check_size; + break; + } } + + is_cycle = (repeat_order != 0); + + /* If there still is a cycle, break. */ + if (is_cycle) + break; + } - is_cycle = (repeat_order != 0); + if (is_cycle) { + if (log->cyclic_last_line % repeat_order == 0) { + log->log_cycles++; - // if there still is a cycle.. - if (is_cycle) - break; - - } + if (log->log_cycles == 1) { + /* + 'Replay' the last few log entries so they actually + show up. - if (is_cycle) - { - if (log->cyclic_last_line % repeat_order == 0) - { - log->log_cycles++; + TODO: Is this right? + */ - if (log->log_cycles == 1) - { - // 'Replay' the last few log entries so they actually show up - // Todo: is this right? + for (uint32_t index = log->cyclic_last_line - 1; + index > (log->cyclic_last_line - repeat_order); + index--) { + /* *Very important* to prevent out of bounds index. */ + uint32_t real_index = index % + LOG_SIZE_BUFFER_CYCLIC_LINES; + log_copy(log, temp, log->cyclic_buff[real_index], + LOG_SIZE_BUFFER); - for (uint32_t index = log->cyclic_last_line - 1; index > (log->cyclic_last_line - repeat_order); index--) - { - // *very important* to prevent out of bounds index - uint32_t real_index = index % LOG_SIZE_BUFFER_CYCLIC_LINES; - log_copy(log, temp, log->cyclic_buff[real_index], LOG_SIZE_BUFFER); - - fprintf(stdlog, "%s", log->cyclic_buff[real_index]); + fprintf(stdlog, "%s", log->cyclic_buff[real_index]); + } + /* Restore the original line. */ + log_copy(log, temp, + log->cyclic_buff[log->cyclic_last_line], + LOG_SIZE_BUFFER); + + /* Allow normal logging. */ + fprintf(stdlog, "%s", temp); } - // restore the original line - log_copy(log, temp, log->cyclic_buff[log->cyclic_last_line], LOG_SIZE_BUFFER); - - fprintf(stdlog, "%s", temp); // allow normal logging + if (log->log_cycles > 1 && log->log_cycles < 100) + fprintf(stdlog, "***** Cyclical Log Repeat of Order %d " + "#%d *****\n", repeat_order, log->log_cycles); + else if (log->log_cycles == 100) + fprintf(stdlog, "Logged the same cycle 100 times... " + "Silence until something interesting happens\n"); } - - - if (log->log_cycles > 1 && log->log_cycles < 100) - fprintf(stdlog, "***** Cyclical Log Repeat of Order %d #%d *****\n", repeat_order, log->log_cycles); - else if (log->log_cycles == 100) - fprintf(stdlog, "Logged the same cycle 100 times...shutting up until something interesting happens\n"); + } else { + log->log_cycles = 0; + fprintf(stdlog, "%s", temp); } - } - else - { - log->log_cycles = 0; - fprintf(stdlog, "%s", temp); - } - - log->cyclic_last_line++; - -#endif + log->cyclic_last_line++; + } } +#endif void log_fatal(void *priv, const char *fmt, ...) @@ -267,6 +279,13 @@ log_fatal(void *priv, const char *fmt, ...) if (log == NULL) return; + if (log->cyclic_buff != NULL) { + for (int i = 0; i < LOG_SIZE_BUFFER_CYCLIC_LINES; i++) + if (log->cyclic_buff[i] != NULL) + free(log->cyclic_buff[i]); + free(log->cyclic_buff); + } + va_start(ap, fmt); log_copy(log, fmt2, fmt, 1024); vsprintf(temp, fmt2, ap); @@ -275,21 +294,42 @@ log_fatal(void *priv, const char *fmt, ...) exit(-1); } -void * -log_open(char *dev_name) +static void * +log_open_common(const char *dev_name, const int cyclic) { - log_t *log = malloc(sizeof(log_t)); + log_t *log = calloc(1, sizeof(log_t)); - memset(log, 0, sizeof(log_t)); - - log->dev_name = dev_name; + memcpy(log->dev_name, dev_name, strlen(dev_name) + 1); log->suppr_seen = 1; log->cyclic_last_line = 0; log->log_cycles = 0; + if (cyclic) { + log->cyclic_buff = calloc(LOG_SIZE_BUFFER_CYCLIC_LINES, + sizeof(char *)); + for (int i = 0; i < LOG_SIZE_BUFFER_CYCLIC_LINES; i++) + log->cyclic_buff[i] = calloc(LOG_SIZE_BUFFER, sizeof(char)); + } + return (void *) log; } +void * +log_open(const char *dev_name) +{ + return log_open_common(dev_name, 0); +} + +/* + This is so that not all logs get the 32k cyclical buffer + they may not need. + */ +void * +log_open_cyclic(const char *dev_name) +{ + return log_open_common(dev_name, 1); +} + void log_close(void *priv) { @@ -297,4 +337,3 @@ log_close(void *priv) free(log); } -#endif diff --git a/src/machine/m_amstrad.c b/src/machine/m_amstrad.c index 530362b89..3dba578bd 100644 --- a/src/machine/m_amstrad.c +++ b/src/machine/m_amstrad.c @@ -619,8 +619,7 @@ vid_init_1512(amstrad_t *ams) amsvid_t *vid; /* Allocate a video controller block. */ - vid = (amsvid_t *) malloc(sizeof(amsvid_t)); - memset(vid, 0x00, sizeof(amsvid_t)); + vid = (amsvid_t *) calloc(1, sizeof(amsvid_t)); video_inform(VIDEO_FLAG_TYPE_CGA, &timing_pc1512); @@ -726,7 +725,7 @@ const device_t vid_1512_device = { .init = NULL, .close = vid_close_1512, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = vid_speed_change_1512, .force_redraw = NULL, .config = vid_1512_config @@ -823,8 +822,7 @@ vid_init_1640(amstrad_t *ams) amsvid_t *vid; /* Allocate a video controller block. */ - vid = (amsvid_t *) malloc(sizeof(amsvid_t)); - memset(vid, 0x00, sizeof(amsvid_t)); + vid = (amsvid_t *) calloc(1, sizeof(amsvid_t)); rom_init(&vid->bios_rom, "roms/machines/pc1640/40100", 0xc0000, 0x8000, 0x7fff, 0, 0); @@ -906,7 +904,7 @@ const device_t vid_1640_device = { .init = NULL, .close = vid_close_1640, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = vid_speed_changed_1640, .force_redraw = NULL, .config = vid_1640_config @@ -1620,8 +1618,7 @@ vid_init_200(amstrad_t *ams) mda_t *mda; /* Allocate a video controller block. */ - vid = (amsvid_t *) malloc(sizeof(amsvid_t)); - memset(vid, 0x00, sizeof(amsvid_t)); + vid = (amsvid_t *) calloc(1, sizeof(amsvid_t)); vid->emulation = device_get_config_int("video_emulation"); @@ -1831,7 +1828,7 @@ const device_t vid_200_device = { .init = NULL, .close = vid_close_200, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = vid_speed_changed_200, .force_redraw = NULL, .config = vid_200_config @@ -1931,7 +1928,7 @@ const device_t vid_ppc512_device = { .init = NULL, .close = vid_close_200, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = vid_speed_changed_200, .force_redraw = NULL, .config = vid_ppc512_config @@ -1965,7 +1962,7 @@ const device_t vid_pc2086_device = { .init = NULL, .close = NULL, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = vid_pc2086_config @@ -1999,7 +1996,7 @@ const device_t vid_pc3086_device = { .init = NULL, .close = NULL, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = vid_pc3086_config @@ -2870,8 +2867,7 @@ machine_amstrad_init(const machine_t *model, int type) { amstrad_t *ams; - ams = (amstrad_t *) malloc(sizeof(amstrad_t)); - memset(ams, 0x00, sizeof(amstrad_t)); + ams = (amstrad_t *) calloc(1, sizeof(amstrad_t)); ams->type = type; amstrad_latch = 0x80000000; diff --git a/src/machine/m_at_compaq.c b/src/machine/m_at_compaq.c index 0ac541e90..904122bad 100644 --- a/src/machine/m_at_compaq.c +++ b/src/machine/m_at_compaq.c @@ -629,8 +629,7 @@ compaq_plasma_recalcattrs(compaq_plasma_t *self) static void * compaq_plasma_init(UNUSED(const device_t *info)) { - compaq_plasma_t *self = malloc(sizeof(compaq_plasma_t)); - memset(self, 0, sizeof(compaq_plasma_t)); + compaq_plasma_t *self = calloc(1, sizeof(compaq_plasma_t)); video_inform(VIDEO_FLAG_TYPE_CGA, &timing_compaq_plasma); if (compaq_machine_type == COMPAQ_PORTABLEIII) @@ -714,7 +713,7 @@ const device_t compaq_plasma_device = { .init = compaq_plasma_init, .close = compaq_plasma_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = compaq_plasma_speed_changed, .force_redraw = NULL, .config = compaq_plasma_config diff --git a/src/machine/m_at_grid.c b/src/machine/m_at_grid.c index 2fc757129..03b7288b9 100644 --- a/src/machine/m_at_grid.c +++ b/src/machine/m_at_grid.c @@ -38,6 +38,7 @@ #include <86box/mem.h> #include <86box/rom.h> #include <86box/vid_cga.h> +#include <86box/plat_unused.h> #define GRID_APPROM_SELECT 0x440 #define GRID_APPROM_ENABLE 0x405 @@ -263,7 +264,7 @@ static uint8_t grid_io_read(uint16_t port, void *priv) { } static void * -grid_init(const device_t *info) +grid_init(UNUSED(const device_t *info)) { grid_t *dev = calloc(1, sizeof(grid_t)); @@ -324,7 +325,7 @@ const device_t grid_device = { .init = grid_init, .close = grid_close, .reset = grid_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/machine/m_at_socket4.c b/src/machine/m_at_socket4.c index c3213f1ac..78df5b0cb 100644 --- a/src/machine/m_at_socket4.c +++ b/src/machine/m_at_socket4.c @@ -384,6 +384,37 @@ machine_at_m5pi_init(const machine_t *model) return ret; } +int +machine_at_globalyst330_p5_init(const machine_t *model) +{ + int ret; + + ret = bios_load_linear("roms/machines/globalyst330_p5/MiTAC_PB5500C_v1.02_120794_ATT.BIN", + 0x000e0000, 131072, 0); + + if (bios_only || !ret) + return ret; + + machine_at_common_init(model); + + pci_init(PCI_CONFIG_TYPE_1); + pci_register_slot(0x10, PCI_CARD_NORTHBRIDGE, 0, 0, 0, 0); + pci_register_slot(0x11, PCI_CARD_NORMAL, 1, 2, 3, 4); + pci_register_slot(0x12, PCI_CARD_NORMAL, 5, 6, 7, 8); + pci_register_slot(0x13, PCI_CARD_NORMAL, 9, 10, 11, 12); + pci_register_slot(0x14, PCI_CARD_NORMAL, 13, 14, 15, 16); + + device_add(&opti5x7_pci_device); + device_add(&opti822_device); + device_add(&sst_flash_29ee010_device); + device_add(&keyboard_at_ami_device); + + if (fdc_current[0] == FDC_INTERNAL) + device_add(&fdc_at_device); + + return ret; +} + int machine_at_excalibur_init(const machine_t *model) { diff --git a/src/machine/m_at_socket7.c b/src/machine/m_at_socket7.c index 2dbb83684..14b641540 100644 --- a/src/machine/m_at_socket7.c +++ b/src/machine/m_at_socket7.c @@ -1271,6 +1271,38 @@ machine_at_ficpa2012_init(const machine_t *model) return ret; } +int +machine_at_via809ds_init(const machine_t *model) +{ + int ret; + + ret = bios_load_linear("roms/machines/via809ds/v30422sg.rom", + 0x000e0000, 131072, 0); + + if (bios_only || !ret) + return ret; + + machine_at_common_init_ex(model, 2); + + pci_init(PCI_CONFIG_TYPE_1); + pci_register_slot(0x00, PCI_CARD_NORTHBRIDGE, 0, 0, 0, 0); + pci_register_slot(0x07, PCI_CARD_SOUTHBRIDGE, 1, 2, 3, 4); + pci_register_slot(0x08, PCI_CARD_NORMAL, 1, 2, 3, 4); + pci_register_slot(0x09, PCI_CARD_NORMAL, 2, 3, 4, 1); + pci_register_slot(0x0A, PCI_CARD_NORMAL, 3, 4, 1, 2); + pci_register_slot(0x0B, PCI_CARD_NORMAL, 4, 1, 2, 3); /* assumed */ + pci_register_slot(0x01, PCI_CARD_AGPBRIDGE, 1, 2, 3, 4); + + device_add(&via_vp3_device); + device_add(&via_vt82c586b_device); + device_add(&keyboard_ps2_ami_pci_device); + device_add(&fdc37c669_device); + device_add(&intel_flash_bxt_device); + spd_register(SPD_TYPE_SDRAM, 0x7, 512); + + return ret; +} + int machine_at_r534f_init(const machine_t *model) { diff --git a/src/machine/m_at_t3100e_vid.c b/src/machine/m_at_t3100e_vid.c index 50c9ec05a..c827a05e5 100644 --- a/src/machine/m_at_t3100e_vid.c +++ b/src/machine/m_at_t3100e_vid.c @@ -655,8 +655,7 @@ t3100e_recalcattrs(t3100e_t *t3100e) void * t3100e_init(UNUSED(const device_t *info)) { - t3100e_t *t3100e = malloc(sizeof(t3100e_t)); - memset(t3100e, 0, sizeof(t3100e_t)); + t3100e_t *t3100e = calloc(1, sizeof(t3100e_t)); loadfont("roms/machines/t3100e/t3100e_font.bin", 5); cga_init(&t3100e->cga); video_inform(VIDEO_FLAG_TYPE_CGA, &timing_t3100e); @@ -711,7 +710,7 @@ const device_t t3100e_device = { .init = t3100e_init, .close = t3100e_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = t3100e_speed_changed, .force_redraw = NULL, .config = NULL diff --git a/src/machine/m_europc.c b/src/machine/m_europc.c index 42034e2f6..b98a1f51e 100644 --- a/src/machine/m_europc.c +++ b/src/machine/m_europc.c @@ -703,7 +703,7 @@ const device_t europc_device = { .init = europc_boot, .close = europc_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = europc_config diff --git a/src/machine/m_pcjr.c b/src/machine/m_pcjr.c index 16020826d..ca9e72fca 100644 --- a/src/machine/m_pcjr.c +++ b/src/machine/m_pcjr.c @@ -1513,7 +1513,7 @@ const device_t pcjr_device = { .init = NULL, .close = NULL, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = speed_changed, .force_redraw = NULL, .config = pcjr_config @@ -1532,8 +1532,7 @@ machine_pcjr_init(UNUSED(const machine_t *model)) if (bios_only || !ret) return ret; - pcjr = malloc(sizeof(pcjr_t)); - memset(pcjr, 0x00, sizeof(pcjr_t)); + pcjr = calloc(1, sizeof(pcjr_t)); pic_init_pcjr(); pit_common_init(0, pit_irq0_timer_pcjr, NULL); diff --git a/src/machine/m_ps1.c b/src/machine/m_ps1.c index 3c9f1819f..92846c401 100644 --- a/src/machine/m_ps1.c +++ b/src/machine/m_ps1.c @@ -287,7 +287,7 @@ const device_t ps1_2011_device = { .init = NULL, .close = NULL, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = &ps1_2011_config[0] @@ -299,8 +299,7 @@ ps1_setup(int model) ps1_t *ps; void *priv; - ps = (ps1_t *) malloc(sizeof(ps1_t)); - memset(ps, 0x00, sizeof(ps1_t)); + ps = (ps1_t *) calloc(1, sizeof(ps1_t)); ps->model = model; io_sethandler(0x0091, 1, diff --git a/src/machine/m_ps1_hdc.c b/src/machine/m_ps1_hdc.c index e1bacad6c..d407953b4 100644 --- a/src/machine/m_ps1_hdc.c +++ b/src/machine/m_ps1_hdc.c @@ -1297,8 +1297,7 @@ ps1_hdc_init(UNUSED(const device_t *info)) int c; /* Allocate and initialize device block. */ - dev = malloc(sizeof(hdc_t)); - memset(dev, 0x00, sizeof(hdc_t)); + dev = calloc(1, sizeof(hdc_t)); /* Set up controller parameters for PS/1 2011. */ dev->base = 0x0320; @@ -1311,7 +1310,7 @@ ps1_hdc_init(UNUSED(const device_t *info)) /* Load any disks for this device class. */ c = 0; for (uint8_t i = 0; i < HDD_NUM; i++) { - if ((hdd[i].bus == HDD_BUS_XTA) && (hdd[i].xta_channel < 1)) { + if ((hdd[i].bus_type == HDD_BUS_XTA) && (hdd[i].xta_channel < 1)) { drive = &dev->drives[hdd[i].xta_channel]; if (!hdd_image_load(i)) { @@ -1386,7 +1385,7 @@ const device_t ps1_hdc_device = { .init = ps1_hdc_init, .close = ps1_hdc_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/machine/m_ps2_isa.c b/src/machine/m_ps2_isa.c index c0c4f7c79..7d024c335 100644 --- a/src/machine/m_ps2_isa.c +++ b/src/machine/m_ps2_isa.c @@ -151,8 +151,7 @@ ps2_isa_setup(int model, int cpu_type) ps2_isa_t *ps2; void *priv; - ps2 = (ps2_isa_t *) malloc(sizeof(ps2_isa_t)); - memset(ps2, 0x00, sizeof(ps2_isa_t)); + ps2 = (ps2_isa_t *) calloc(1, sizeof(ps2_isa_t)); ps2->model = model; ps2->cpu_type = cpu_type; diff --git a/src/machine/m_tandy.c b/src/machine/m_tandy.c index 11bd41a66..7072c5e78 100644 --- a/src/machine/m_tandy.c +++ b/src/machine/m_tandy.c @@ -1359,8 +1359,7 @@ vid_init(tandy_t *dev) int display_type; t1kvid_t *vid; - vid = malloc(sizeof(t1kvid_t)); - memset(vid, 0x00, sizeof(t1kvid_t)); + vid = calloc(1, sizeof(t1kvid_t)); vid->memctrl = -1; video_inform(VIDEO_FLAG_TYPE_CGA, &timing_dram); @@ -1416,7 +1415,7 @@ const device_t vid_device = { .init = NULL, .close = vid_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = vid_speed_changed, .force_redraw = NULL, .config = vid_config @@ -1430,7 +1429,7 @@ const device_t vid_device_hx = { .init = NULL, .close = vid_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = vid_speed_changed, .force_redraw = NULL, .config = vid_config @@ -1444,7 +1443,7 @@ const device_t vid_device_sl = { .init = NULL, .close = vid_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = vid_speed_changed, .force_redraw = NULL, .config = NULL @@ -1540,8 +1539,7 @@ eep_init(const device_t *info) t1keep_t *eep; FILE *fp = NULL; - eep = (t1keep_t *) malloc(sizeof(t1keep_t)); - memset(eep, 0x00, sizeof(t1keep_t)); + eep = (t1keep_t *) calloc(1, sizeof(t1keep_t)); switch (info->local) { case TYPE_TANDY1000HX: @@ -1592,7 +1590,7 @@ static const device_t eep_1000hx_device = { .init = eep_init, .close = eep_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -1606,7 +1604,7 @@ static const device_t eep_1000sl2_device = { .init = eep_init, .close = eep_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/machine/m_xt_olivetti.c b/src/machine/m_xt_olivetti.c index 817b0d0cc..b6e4fb94a 100644 --- a/src/machine/m_xt_olivetti.c +++ b/src/machine/m_xt_olivetti.c @@ -2075,7 +2075,7 @@ const device_t m24_kbd_device = { .init = NULL, .close = m24_kbd_close, .reset = m24_kbd_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2119,7 +2119,7 @@ const device_t m19_vid_device = { .init = NULL, .close = m19_vid_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = m19_vid_speed_changed, .force_redraw = NULL, .config = m19_vid_config @@ -2313,8 +2313,7 @@ machine_xt_m24_init(const machine_t *model) if (bios_only || !ret) return ret; - m24_kbd = (m24_kbd_t *) malloc(sizeof(m24_kbd_t)); - memset(m24_kbd, 0x00, sizeof(m24_kbd_t)); + m24_kbd = (m24_kbd_t *) calloc(1, sizeof(m24_kbd_t)); machine_common_init(model); @@ -2330,10 +2329,9 @@ machine_xt_m24_init(const machine_t *model) nmi_init(); /* Allocate an NVR for this machine. */ - nvr = (nvr_t *) malloc(sizeof(nvr_t)); + nvr = (nvr_t *) calloc(1, sizeof(nvr_t)); if (nvr == NULL) return 0; - memset(nvr, 0x00, sizeof(nvr_t)); mm58174_init(nvr, model->nvrmask + 1); @@ -2374,8 +2372,7 @@ machine_xt_m240_init(const machine_t *model) if (bios_only || !ret) return ret; - m24_kbd = (m24_kbd_t *) malloc(sizeof(m24_kbd_t)); - memset(m24_kbd, 0x00, sizeof(m24_kbd_t)); + m24_kbd = (m24_kbd_t *) calloc(1, sizeof(m24_kbd_t)); machine_common_init(model); @@ -2404,10 +2401,9 @@ machine_xt_m240_init(const machine_t *model) nmi_init(); /* Allocate an NVR for this machine. */ - nvr = (nvr_t *) malloc(sizeof(nvr_t)); + nvr = (nvr_t *) calloc(1, sizeof(nvr_t)); if (nvr == NULL) return 0; - memset(nvr, 0x00, sizeof(nvr_t)); mm58274_init(nvr, model->nvrmask + 1); @@ -2438,8 +2434,7 @@ machine_xt_m19_init(const machine_t *model) m19_vid_t *vid; /* Do not move memory allocation elsewhere. */ - vid = (m19_vid_t *) malloc(sizeof(m19_vid_t)); - memset(vid, 0x00, sizeof(m19_vid_t)); + vid = (m19_vid_t *) calloc(1, sizeof(m19_vid_t)); machine_common_init(model); diff --git a/src/machine/m_xt_philips.c b/src/machine/m_xt_philips.c index 1fc284a46..604ccebaf 100644 --- a/src/machine/m_xt_philips.c +++ b/src/machine/m_xt_philips.c @@ -142,7 +142,7 @@ const device_t philips_device = { .init = philips_init, .close = philips_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/machine/m_xt_t1000_vid.c b/src/machine/m_xt_t1000_vid.c index 4ec13b5c4..efad869e1 100644 --- a/src/machine/m_xt_t1000_vid.c +++ b/src/machine/m_xt_t1000_vid.c @@ -651,8 +651,7 @@ t1000_recalcattrs(t1000_t *t1000) static void * t1000_init(UNUSED(const device_t *info)) { - t1000_t *t1000 = malloc(sizeof(t1000_t)); - memset(t1000, 0, sizeof(t1000_t)); + t1000_t *t1000 = calloc(1, sizeof(t1000_t)); loadfont("roms/machines/t1000/t1000font.bin", 8); cga_init(&t1000->cga); video_inform(VIDEO_FLAG_TYPE_CGA, &timing_t1000); @@ -741,7 +740,7 @@ const device_t t1000_video_device = { .init = t1000_init, .close = t1000_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = t1000_speed_changed, .force_redraw = NULL, .config = t1000_config @@ -755,7 +754,7 @@ const device_t t1200_video_device = { .init = t1000_init, .close = t1000_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = t1000_speed_changed, .force_redraw = NULL, .config = t1000_config diff --git a/src/machine/m_xt_xi8088.c b/src/machine/m_xt_xi8088.c index 9b55dc021..886c1be6e 100644 --- a/src/machine/m_xt_xi8088.c +++ b/src/machine/m_xt_xi8088.c @@ -168,7 +168,7 @@ const device_t xi8088_device = { .init = xi8088_init, .close = NULL, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = xi8088_config diff --git a/src/machine/m_xt_zenith.c b/src/machine/m_xt_zenith.c index f5e231772..833529ffb 100644 --- a/src/machine/m_xt_zenith.c +++ b/src/machine/m_xt_zenith.c @@ -73,8 +73,7 @@ zenith_scratchpad_init(UNUSED(const device_t *info)) { zenith_t *dev; - dev = (zenith_t *) malloc(sizeof(zenith_t)); - memset(dev, 0x00, sizeof(zenith_t)); + dev = (zenith_t *) calloc(1, sizeof(zenith_t)); dev->scratchpad_ram = malloc(0x4000); @@ -103,7 +102,7 @@ static const device_t zenith_scratchpad_device = { .init = zenith_scratchpad_init, .close = zenith_scratchpad_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/machine/machine_table.c b/src/machine/machine_table.c index f2fb53a6f..26b42bc5b 100644 --- a/src/machine/machine_table.c +++ b/src/machine/machine_table.c @@ -9582,6 +9582,46 @@ const machine_t machines[] = { }, /* OPTi 596/597/822 */ + /* Has a VIA VT82C42N KBC with AMI 'F' firmware */ + { + .name = "[OPTi 597] AT&T Globalyst 330 (Pentium)", + .internal_name = "globalyst330_p5", + .type = MACHINE_TYPE_SOCKET4, + .chipset = MACHINE_CHIPSET_OPTI_547_597, + .init = machine_at_globalyst330_p5_init, + .p1_handler = NULL, + .gpio_handler = NULL, + .available_flag = MACHINE_AVAILABLE, + .gpio_acpi_handler = NULL, + .cpu = { + .package = CPU_PKG_SOCKET4, + .block = CPU_BLOCK_NONE, + .min_bus = 60000000, + .max_bus = 66666667, + .min_voltage = 5000, + .max_voltage = 5000, + .min_multi = MACHINE_MULTIPLIER_FIXED, + .max_multi = MACHINE_MULTIPLIER_FIXED + }, + .bus_flags = MACHINE_PCIV, + .flags = MACHINE_APM, + .ram = { + .min = 8192, + .max = 65536, + .step = 8192 + }, + .nvrmask = 127, + .kbc_device = NULL, + .kbc_p1 = 0xff, + .gpio = 0xffffffff, + .gpio_acpi = 0xffffffff, + .device = NULL, + .fdc_device = NULL, + .sio_device = NULL, + .vid_device = NULL, + .snd_device = NULL, + .net_device = NULL + }, /* This has AMIKey 'F' KBC firmware. */ { .name = "[OPTi 597] Supermicro P5VL-PCI", @@ -11081,9 +11121,9 @@ const machine_t machines[] = { .bus_flags = MACHINE_PS2_PCI, .flags = MACHINE_IDE_DUAL | MACHINE_APM, .ram = { - .min = 8192, - .max = 196608, - .step = 8192 + .min = 4096, + .max = 524288, + .step = 4096 }, .nvrmask = 511, .kbc_device = NULL, @@ -11116,14 +11156,14 @@ const machine_t machines[] = { .min_voltage = 3450, .max_voltage = 3520, .min_multi = 1.5, - .max_multi = 3.0 + .max_multi = 2.5 }, .bus_flags = MACHINE_PS2_PCI, .flags = MACHINE_IDE_DUAL | MACHINE_APM, .ram = { - .min = 8192, + .min = 4096, .max = 524288, - .step = 8192 + .step = 4096 }, .nvrmask = 127, .kbc_device = NULL, @@ -11161,9 +11201,9 @@ const machine_t machines[] = { .bus_flags = MACHINE_PS2_PCI | MACHINE_BUS_USB, .flags = MACHINE_IDE_DUAL | MACHINE_APM | MACHINE_USB, .ram = { - .min = 8192, + .min = 4096, .max = 524288, - .step = 8192 + .step = 4096 }, .nvrmask = 127, .kbc_device = NULL, @@ -11206,7 +11246,7 @@ const machine_t machines[] = { .ram = { .min = 8192, .max = 131072, - .step = 8192 + .step = 4096 }, .nvrmask = 511, .kbc_device = NULL, @@ -11430,7 +11470,7 @@ const machine_t machines[] = { /* Has a SM(S)C FDC37C935 Super I/O chip with on-chip KBC with Phoenix MultiKey/42 (version 1.38) KBC firmware. */ { - .name = "[i430HX] Acer M3A", + .name = "[i430HX] Acer AcerPower Ultima", .internal_name = "acerm3a", .type = MACHINE_TYPE_SOCKET7, .chipset = MACHINE_CHIPSET_INTEL_430HX, @@ -11452,9 +11492,9 @@ const machine_t machines[] = { .bus_flags = MACHINE_PS2_PCI | MACHINE_BUS_USB, .flags = MACHINE_IDE_DUAL | MACHINE_APM | MACHINE_GAMEPORT | MACHINE_USB, /* Machine has internal SCSI */ .ram = { - .min = 8192, - .max = 196608, - .step = 8192 + .min = 4096, + .max = 524288, + .step = 4096 }, .nvrmask = 511, .kbc_device = NULL, @@ -11483,18 +11523,18 @@ const machine_t machines[] = { .package = CPU_PKG_SOCKET5_7, .block = CPU_BLOCK_NONE, .min_bus = 50000000, - .max_bus = 83333333, + .max_bus = 75000000, .min_voltage = 2500, .max_voltage = 3520, .min_multi = 1.5, - .max_multi = 3.0 + .max_multi = 4.0 }, .bus_flags = MACHINE_PS2_PCI, .flags = MACHINE_IDE_DUAL | MACHINE_APM, .ram = { - .min = 8192, - .max = 262144, - .step = 8192 + .min = 4096, + .max = 524288, + .step = 4096 }, .nvrmask = 127, .kbc_device = NULL, @@ -11527,14 +11567,14 @@ const machine_t machines[] = { .min_voltage = 2500, .max_voltage = 3520, .min_multi = 1.5, - .max_multi = 3.0 + .max_multi = 3.5 }, .bus_flags = MACHINE_PS2_PCI | MACHINE_BUS_USB, /* Machine has AMB */ .flags = MACHINE_IDE_DUAL | MACHINE_APM | MACHINE_USB, .ram = { - .min = 8192, + .min = 4096, .max = 524288, - .step = 8192 + .step = 4096 }, .nvrmask = 127, .kbc_device = NULL, @@ -11563,7 +11603,7 @@ const machine_t machines[] = { .cpu = { .package = CPU_PKG_SOCKET5_7, .block = CPU_BLOCK_NONE, - .min_bus = 50000000, + .min_bus = 60000000, .max_bus = 66666667, .min_voltage = 2800, .max_voltage = 3520, @@ -11573,9 +11613,9 @@ const machine_t machines[] = { .bus_flags = MACHINE_PS2_PCI | MACHINE_BUS_USB, .flags = MACHINE_IDE_DUAL | MACHINE_APM | MACHINE_GAMEPORT | MACHINE_USB, .ram = { - .min = 8192, - .max = 131072, - .step = 8192 + .min = 4096, + .max = 524288, + .step = 4096 }, .nvrmask = 511, .kbc_device = NULL, @@ -11593,7 +11633,7 @@ const machine_t machines[] = { PC87306 Super I/O chip, command 0xA1 returns '5'. Command 0xA0 copyright string: (C)1994 AMI . */ { - .name = "[i430HX] Intel TC430HX", + .name = "[i430HX] Intel TC430HX (Tucson)", .internal_name = "tc430hx", .type = MACHINE_TYPE_SOCKET7, .chipset = MACHINE_CHIPSET_INTEL_430HX, @@ -11610,14 +11650,14 @@ const machine_t machines[] = { .min_voltage = 2800, .max_voltage = 3520, .min_multi = 1.5, - .max_multi = 3.0 + .max_multi = 3.5 }, .bus_flags = MACHINE_PS2_PCI | MACHINE_BUS_USB, .flags = MACHINE_VIDEO | MACHINE_IDE_DUAL | MACHINE_APM | MACHINE_GAMEPORT | MACHINE_USB, /* Has internal sound: Yamaha YMF701-S */ .ram = { .min = 8192, - .max = 131072, - .step = 8192 + .max = 524288, + .step = 4096 }, .nvrmask = 255, .kbc_device = NULL, @@ -11633,7 +11673,7 @@ const machine_t machines[] = { }, /* OEM version of Intel TC430HX, has AMI MegaKey KBC firmware on the PC87306 Super I/O chip. */ { - .name = "[i430HX] Toshiba Infinia 7200", + .name = "[i430HX] Toshiba Infinia 7201", .internal_name = "infinia7200", .type = MACHINE_TYPE_SOCKET7, .chipset = MACHINE_CHIPSET_INTEL_430HX, @@ -11650,14 +11690,14 @@ const machine_t machines[] = { .min_voltage = 2800, .max_voltage = 3520, .min_multi = 1.5, - .max_multi = 3.0 + .max_multi = 3.5 }, .bus_flags = MACHINE_PS2_PCI | MACHINE_BUS_USB, .flags = MACHINE_VIDEO | MACHINE_IDE_DUAL | MACHINE_APM | MACHINE_GAMEPORT | MACHINE_USB, /* Has internal sound: Yamaha YMF701-S */ .ram = { .min = 8192, - .max = 131072, - .step = 8192 + .max = 524288, + .step = 4096 }, .nvrmask = 255, .kbc_device = NULL, @@ -11673,7 +11713,7 @@ const machine_t machines[] = { }, /* OEM-only Intel CU430HX, has AMI MegaKey KBC firmware on the PC87306 Super I/O chip. */ { - .name = "[i430HX] Intel CU430HX", + .name = "[i430HX] Intel CU430HX (Cumberland)", .internal_name = "cu430hx", .type = MACHINE_TYPE_SOCKET7, .chipset = MACHINE_CHIPSET_INTEL_430HX, @@ -11690,14 +11730,14 @@ const machine_t machines[] = { .min_voltage = 2800, .max_voltage = 3520, .min_multi = 1.5, - .max_multi = 3.0 + .max_multi = 3.5 }, .bus_flags = MACHINE_PS2_PCI | MACHINE_BUS_USB, .flags = MACHINE_IDE_DUAL | MACHINE_SOUND | MACHINE_APM | MACHINE_USB, .ram = { .min = 8192, - .max = 196608, - .step = 8192 + .max = 524288, + .step = 4096 }, .nvrmask = 255, .kbc_device = NULL, @@ -11730,14 +11770,14 @@ const machine_t machines[] = { .min_voltage = 2800, .max_voltage = 3520, .min_multi = 1.5, - .max_multi = 3.0 + .max_multi = 3.5 }, .bus_flags = MACHINE_PS2_PCI | MACHINE_BUS_USB, .flags = MACHINE_IDE_DUAL | MACHINE_SOUND | MACHINE_APM | MACHINE_USB, .ram = { .min = 8192, - .max = 196608, - .step = 8192 + .max = 524288, + .step = 4096 }, .nvrmask = 255, .kbc_device = NULL, @@ -11751,6 +11791,46 @@ const machine_t machines[] = { .snd_device = &sb_vibra16c_onboard_device, .net_device = NULL }, + /* Unknown PS/2 KBC. */ + { + .name = "[i430HX] Radisys EPC-2102", + .internal_name = "epc2102", + .type = MACHINE_TYPE_SOCKET7, + .chipset = MACHINE_CHIPSET_INTEL_430HX, + .init = machine_at_epc2102_init, + .p1_handler = NULL, + .gpio_handler = NULL, + .available_flag = MACHINE_AVAILABLE, + .gpio_acpi_handler = NULL, + .cpu = { + .package = CPU_PKG_SOCKET5_7, + .block = CPU_BLOCK_NONE, + .min_bus = 50000000, + .max_bus = 66666667, + .min_voltage = 2500, + .max_voltage = 3520, + .min_multi = 1.5, + .max_multi = 3.5 + }, + .bus_flags = MACHINE_PS2_PCI, + .flags = MACHINE_IDE_DUAL | MACHINE_APM, + .ram = { + .min = 4096, + .max = 524288, + .step = 4096 + }, + .nvrmask = 127, + .kbc_device = NULL, + .kbc_p1 = 0xff, + .gpio = 0xffffffff, + .gpio_acpi = 0xffffffff, + .device = NULL, + .fdc_device = NULL, + .sio_device = NULL, + .vid_device = NULL, + .snd_device = NULL, + .net_device = NULL + }, /* According to tests from real hardware: This has AMI MegaKey KBC firmware on the PC87306 Super I/O chip, command 0xA1 returns '5'. Command 0xA0 copyright string: (C)1994 AMI . @@ -11779,8 +11859,8 @@ const machine_t machines[] = { .flags = MACHINE_IDE_DUAL | MACHINE_APM, .ram = { .min = 8192, - .max = 196608, - .step = 8192 + .max = 524288, + .step = 4096 }, .nvrmask = 255, .kbc_device = NULL, @@ -11819,9 +11899,9 @@ const machine_t machines[] = { .bus_flags = MACHINE_PS2_PCI | MACHINE_BUS_USB, .flags = MACHINE_IDE_DUAL | MACHINE_APM | MACHINE_USB, .ram = { - .min = 8192, - .max = 786432, - .step = 8192 + .min = 4096, + .max = 524288, + .step = 4096 }, .nvrmask = 255, .kbc_device = NULL, @@ -11861,9 +11941,9 @@ const machine_t machines[] = { .bus_flags = MACHINE_PS2_PCI | MACHINE_BUS_USB, .flags = MACHINE_IDE_DUAL | MACHINE_SCSI | MACHINE_APM | MACHINE_USB, .ram = { - .min = 8192, + .min = 4096, .max = 131072, - .step = 8192 + .step = 4096 }, .nvrmask = 127, .kbc_device = NULL, @@ -11896,14 +11976,14 @@ const machine_t machines[] = { .min_voltage = 2500, .max_voltage = 3520, .min_multi = 1.5, - .max_multi = 3.0 + .max_multi = 3.5 }, .bus_flags = MACHINE_PS2_PCI | MACHINE_BUS_USB, /* Machine has AMB */ .flags = MACHINE_IDE_DUAL | MACHINE_APM | MACHINE_USB, .ram = { - .min = 8192, + .min = 4096, .max = 131072, - .step = 8192 + .step = 4096 }, .nvrmask = 127, .kbc_device = NULL, @@ -11937,14 +12017,14 @@ const machine_t machines[] = { .min_voltage = 2500, .max_voltage = 3520, .min_multi = 1.5, - .max_multi = 3.0 + .max_multi = 3.5 }, .bus_flags = MACHINE_PS2_PCI | MACHINE_BUS_USB, .flags = MACHINE_IDE_DUAL | MACHINE_APM | MACHINE_USB, .ram = { - .min = 8192, + .min = 4096, .max = 131072, - .step = 8192 + .step = 4096 }, .nvrmask = 127, .kbc_device = NULL, @@ -11982,9 +12062,9 @@ const machine_t machines[] = { .bus_flags = MACHINE_PS2_PCI | MACHINE_BUS_USB, .flags = MACHINE_IDE_DUAL | MACHINE_APM | MACHINE_USB, .ram = { - .min = 8192, + .min = 4096, .max = 131072, - .step = 8192 + .step = 4096 }, .nvrmask = 127, .kbc_device = NULL, @@ -12001,7 +12081,7 @@ const machine_t machines[] = { /* Has a SM(S)C FDC37C932QF Super I/O chip with on-chip KBC with AMI MegaKey (revision '5') KBC firmware. */ { - .name = "[i430VX] Compaq Presario 2240", + .name = "[i430VX] Compaq Presario 224x", .internal_name = "presario2240", .type = MACHINE_TYPE_SOCKET7, .chipset = MACHINE_CHIPSET_INTEL_430VX, @@ -12013,19 +12093,19 @@ const machine_t machines[] = { .cpu = { .package = CPU_PKG_SOCKET5_7, .block = CPU_BLOCK_NONE, - .min_bus = 50000000, + .min_bus = 66666667, .max_bus = 66666667, .min_voltage = 2800, .max_voltage = 3520, .min_multi = 1.5, - .max_multi = 3.0 + .max_multi = 3.5 }, .bus_flags = MACHINE_PS2_PCI, .flags = MACHINE_IDE_DUAL | MACHINE_VIDEO | MACHINE_APM | MACHINE_ACPI, .ram = { - .min = 8192, - .max = 131072, - .step = 8192 + .min = 16384, + .max = 49152, + .step = 4096 }, .nvrmask = 511, .kbc_device = NULL, @@ -12042,7 +12122,7 @@ const machine_t machines[] = { /* Has a SM(S)C FDC37C931APM Super I/O chip with on-chip KBC with Compaq KBC firmware. */ { - .name = "[i430VX] Compaq Presario 4500", + .name = "[i430VX] Compaq Presario 45xx", .internal_name = "presario4500", .type = MACHINE_TYPE_SOCKET7, .chipset = MACHINE_CHIPSET_INTEL_430VX, @@ -12054,19 +12134,19 @@ const machine_t machines[] = { .cpu = { .package = CPU_PKG_SOCKET5_7, .block = CPU_BLOCK_NONE, - .min_bus = 50000000, + .min_bus = 66666667, .max_bus = 66666667, .min_voltage = 2800, .max_voltage = 3520, .min_multi = 1.5, - .max_multi = 3.0 + .max_multi = 3.5 }, .bus_flags = MACHINE_PS2_PCI, .flags = MACHINE_IDE_DUAL | MACHINE_VIDEO | MACHINE_APM | MACHINE_ACPI, .ram = { - .min = 8192, - .max = 131072, - .step = 8192 + .min = 16384, + .max = 49152, + .step = 4096 }, .nvrmask = 511, .kbc_device = NULL, @@ -12083,7 +12163,7 @@ const machine_t machines[] = { /* Has a SM(S)C FDC37C932FR Super I/O chip with on-chip KBC with AMI MegaKey (revision '5') KBC firmware. */ { - .name = "[i430VX] Dell Hannibal+", + .name = "[i430VX] Dell Dimension XPS Pxxxa/Mxxxa", .internal_name = "dellhannibalp", .type = MACHINE_TYPE_SOCKET7, .chipset = MACHINE_CHIPSET_INTEL_430VX, @@ -12100,14 +12180,14 @@ const machine_t machines[] = { .min_voltage = 2500, .max_voltage = 3520, .min_multi = 1.5, - .max_multi = 3.0 + .max_multi = 3.5 }, .bus_flags = MACHINE_PS2_PCI | MACHINE_BUS_USB, .flags = MACHINE_IDE_DUAL | MACHINE_APM | MACHINE_USB, .ram = { .min = 8192, .max = 131072, - .step = 8192 + .step = 4096 }, .nvrmask = 511, .kbc_device = NULL, @@ -12145,9 +12225,9 @@ const machine_t machines[] = { .bus_flags = MACHINE_PS2_PCI | MACHINE_BUS_USB, .flags = MACHINE_IDE_DUAL | MACHINE_APM | MACHINE_USB, .ram = { - .min = 8192, + .min = 4096, .max = 131072, - .step = 8192 + .step = 4096 }, .nvrmask = 127, .kbc_device = NULL, @@ -12177,7 +12257,7 @@ const machine_t machines[] = { .package = CPU_PKG_SOCKET5_7, .block = CPU_BLOCK_NONE, .min_bus = 50000000, - .max_bus = 66666667, + .max_bus = 75000000, .min_voltage = 2500, .max_voltage = 3520, .min_multi = 1.5, @@ -12186,9 +12266,9 @@ const machine_t machines[] = { .bus_flags = MACHINE_PS2_PCI | MACHINE_BUS_USB, .flags = MACHINE_IDE_DUAL | MACHINE_APM | MACHINE_USB, .ram = { - .min = 8192, + .min = 4096, .max = 131072, - .step = 8192 + .step = 4096 }, .nvrmask = 511, .kbc_device = NULL, @@ -12229,7 +12309,7 @@ const machine_t machines[] = { .ram = { .min = 8192, .max = 131072, - .step = 8192 + .step = 4096 }, .nvrmask = 511, .kbc_device = NULL, @@ -12263,14 +12343,14 @@ const machine_t machines[] = { .min_voltage = 2200, .max_voltage = 3520, .min_multi = 1.5, - .max_multi = 3.0 + .max_multi = 3.5 }, .bus_flags = MACHINE_PS2_PCI, .flags = MACHINE_IDE_DUAL | MACHINE_APM, .ram = { - .min = 16384, + .min = 8192, .max = 131072, - .step = 8192 + .step = 4096 }, .nvrmask = 511, .kbc_device = NULL, @@ -12288,7 +12368,7 @@ const machine_t machines[] = { PC87306 Super I/O chip, command 0xA1 returns '5'. Command 0xA0 copyright string: (C)1994 AMI . */ { - .name = "[i430VX] Packard Bell PB680", + .name = "[i430VX] Packard Bell Multimedia C110", .internal_name = "pb680", .type = MACHINE_TYPE_SOCKET7, .chipset = MACHINE_CHIPSET_INTEL_430VX, @@ -12312,7 +12392,7 @@ const machine_t machines[] = { .ram = { .min = 8192, .max = 131072, - .step = 8192 + .step = 4096 }, .nvrmask = 255, .kbc_device = NULL, @@ -12329,7 +12409,7 @@ const machine_t machines[] = { /* Has a SM(S)C FDC37C935 Super I/O chip with on-chip KBC with Phoenix MultiKey/42 (version 1.38) KBC firmware. */ { - .name = "[i430VX] Packard Bell PB810", + .name = "[i430VX] Packard Bell Multimedia M415", .internal_name = "pb810", .type = MACHINE_TYPE_SOCKET7, .chipset = MACHINE_CHIPSET_INTEL_430VX, @@ -12346,14 +12426,14 @@ const machine_t machines[] = { .min_voltage = 2500, .max_voltage = 3520, .min_multi = 1.5, - .max_multi = 3.0 + .max_multi = 4.0 }, .bus_flags = MACHINE_PS2_PCI, .flags = MACHINE_IDE_DUAL | MACHINE_SOUND | MACHINE_APM, .ram = { - .min = 8192, + .min = 4096, .max = 131072, - .step = 8192 + .step = 4096 }, .nvrmask = 511, .kbc_device = NULL, @@ -12387,54 +12467,14 @@ const machine_t machines[] = { .min_voltage = 2600, .max_voltage = 3520, .min_multi = 1.5, - .max_multi = 3.0 + .max_multi = 3.5 }, .bus_flags = MACHINE_PS2_PCI | MACHINE_BUS_USB, .flags = MACHINE_IDE_DUAL | MACHINE_APM | MACHINE_USB, .ram = { - .min = 8192, + .min = 4096, .max = 131072, - .step = 8192 - }, - .nvrmask = 127, - .kbc_device = NULL, - .kbc_p1 = 0xff, - .gpio = 0xffffffff, - .gpio_acpi = 0xffffffff, - .device = NULL, - .fdc_device = NULL, - .sio_device = NULL, - .vid_device = NULL, - .snd_device = NULL, - .net_device = NULL - }, - /* Unknown PS/2 KBC. */ - { - .name = "[i430HX] Radisys EPC-2102", - .internal_name = "epc2102", - .type = MACHINE_TYPE_SOCKET7, - .chipset = MACHINE_CHIPSET_INTEL_430HX, - .init = machine_at_epc2102_init, - .p1_handler = NULL, - .gpio_handler = NULL, - .available_flag = MACHINE_AVAILABLE, - .gpio_acpi_handler = NULL, - .cpu = { - .package = CPU_PKG_SOCKET5_7, - .block = CPU_BLOCK_NONE, - .min_bus = 50000000, - .max_bus = 83333333, - .min_voltage = 2500, - .max_voltage = 3520, - .min_multi = 1.5, - .max_multi = 3.0 - }, - .bus_flags = MACHINE_PS2_PCI, - .flags = MACHINE_IDE_DUAL | MACHINE_APM, - .ram = { - .min = 8192, - .max = 262144, - .step = 8192 + .step = 4096 }, .nvrmask = 127, .kbc_device = NULL, @@ -12473,9 +12513,9 @@ const machine_t machines[] = { .bus_flags = MACHINE_PS2_PCI | MACHINE_BUS_USB, .flags = MACHINE_IDE_DUAL | MACHINE_GAMEPORT | MACHINE_APM | MACHINE_USB, .ram = { - .min = 8192, + .min = 4096, .max = 131072, - .step = 8192 + .step = 4096 }, .nvrmask = 127, .kbc_device = NULL, @@ -12550,7 +12590,7 @@ const machine_t machines[] = { .min_voltage = 2500, .max_voltage = 3520, .min_multi = 1.5, - .max_multi = 3.0 + .max_multi = 3.5 }, .bus_flags = MACHINE_PS2_PCI | MACHINE_BUS_USB, .flags = MACHINE_IDE_DUAL | MACHINE_APM | MACHINE_ACPI | MACHINE_USB, @@ -12573,7 +12613,7 @@ const machine_t machines[] = { }, /* [TEST] Has AMI Megakey '5' KBC firmware on the SM(S)C FDC37C67x Super I/O chip. */ { - .name = "[i430TX] Gateway Tomahawk", + .name = "[i430TX] Gateway E-1000", .internal_name = "tomahawk", .type = MACHINE_TYPE_SOCKET7, .chipset = MACHINE_CHIPSET_INTEL_430TX, @@ -12585,12 +12625,12 @@ const machine_t machines[] = { .cpu = { .package = CPU_PKG_SOCKET5_7, .block = CPU_BLOCK_NONE, - .min_bus = 50000000, + .min_bus = 60000000, .max_bus = 66666667, .min_voltage = 2100, .max_voltage = 3520, .min_multi = 1.5, - .max_multi = 3.0 + .max_multi = 5.5 }, .bus_flags = MACHINE_PS2_PCI | MACHINE_BUS_USB, .flags = MACHINE_IDE_DUAL | MACHINE_APM | MACHINE_ACPI | MACHINE_VIDEO | MACHINE_SOUND | MACHINE_NIC | MACHINE_USB, @@ -12614,7 +12654,7 @@ const machine_t machines[] = { #ifdef USE_AN430TX /* This has the Phoenix MultiKey KBC firmware. */ { - .name = "[i430TX] Intel AN430TX", + .name = "[i430TX] Intel AN430TX (Anchorage)", .internal_name = "an430tx", .type = MACHINE_TYPE_SOCKET7, .chipset = MACHINE_CHIPSET_INTEL_430TX, @@ -12631,7 +12671,7 @@ const machine_t machines[] = { .min_voltage = 2800, .max_voltage = 3520, .min_multi = 1.5, - .max_multi = 3.0 + .max_multi = 3.5 }, .bus_flags = MACHINE_PS2_PCI, .flags = MACHINE_IDE_DUAL | MACHINE_APM | MACHINE_ACPI, @@ -12655,7 +12695,7 @@ const machine_t machines[] = { #endif /* USE_AN430TX */ /* This has the AMIKey KBC firmware, which is an updated 'F' type. */ { - .name = "[i430TX] Intel YM430TX", + .name = "[i430TX] Intel YM430TX (Yamamoto)", .internal_name = "ym430tx", .type = MACHINE_TYPE_SOCKET7, .chipset = MACHINE_CHIPSET_INTEL_430TX, @@ -12672,14 +12712,14 @@ const machine_t machines[] = { .min_voltage = 2800, .max_voltage = 3520, .min_multi = 1.5, - .max_multi = 3.0 + .max_multi = 3.5 }, .bus_flags = MACHINE_PS2_PCI | MACHINE_BUS_USB, .flags = MACHINE_IDE_DUAL | MACHINE_APM | MACHINE_ACPI | MACHINE_USB, .ram = { - .min = 8192, + .min = 4096, .max = 262144, - .step = 8192 + .step = 4096 }, .nvrmask = 255, .kbc_device = NULL, @@ -12693,7 +12733,7 @@ const machine_t machines[] = { .snd_device = NULL, .net_device = NULL }, - /* PhoenixBIOS 4.0 Rel 6.0 for 430TX, most likely has AMI KBC of some sort. Also has onboard Yamaha YMF701 which can't be emulated yet. */ + /* PhoenixBIOS 4.0 Rel 6.0 for 430TX, has onboard Yamaha YMF701 which is not emulated yet. */ /* Has a SM(S)C FDC37C935 Super I/O chip with on-chip KBC with Phoenix MultiKey/42 (version 1.38) KBC firmware. */ { @@ -12709,12 +12749,12 @@ const machine_t machines[] = { .cpu = { .package = CPU_PKG_SOCKET5_7, .block = CPU_BLOCK(CPU_WINCHIP, CPU_WINCHIP2), - .min_bus = 50000000, + .min_bus = 60000000, .max_bus = 66666667, .min_voltage = 2500, .max_voltage = 3520, .min_multi = 1.5, - .max_multi = 3.0 + .max_multi = 3.5 }, .bus_flags = MACHINE_PS2_PCI | MACHINE_BUS_USB, .flags = MACHINE_IDE_DUAL | MACHINE_APM | MACHINE_ACPI | MACHINE_GAMEPORT | MACHINE_USB, /* Machine has internal sound: Yamaha YMF701-S */ @@ -12755,13 +12795,13 @@ const machine_t machines[] = { .min_voltage = 2700, .max_voltage = 3520, .min_multi = 1.5, - .max_multi = 3.0 + .max_multi = 3.5 }, .bus_flags = MACHINE_PS2_PCI | MACHINE_BUS_USB, .flags = MACHINE_IDE_DUAL | MACHINE_APM | MACHINE_ACPI | MACHINE_USB, .ram = { .min = 8192, - .max = 786432, + .max = 262144, .step = 8192 }, .nvrmask = 255, @@ -12796,14 +12836,14 @@ const machine_t machines[] = { .min_voltage = 2700, .max_voltage = 3520, .min_multi = 1.5, - .max_multi = 3.0 + .max_multi = 3.5 }, .bus_flags = MACHINE_PS2_PCI | MACHINE_BUS_USB, .flags = MACHINE_IDE_DUAL | MACHINE_APM | MACHINE_ACPI | MACHINE_USB, .ram = { - .min = 8192, + .min = 4096, .max = 262144, - .step = 8192 + .step = 4096 }, .nvrmask = 255, .kbc_device = NULL, @@ -12831,8 +12871,8 @@ const machine_t machines[] = { .cpu = { .package = CPU_PKG_SOCKET5_7, .block = CPU_BLOCK_NONE, - .min_bus = 55000000, - .max_bus = 75000000, + .min_bus = 60000000, + .max_bus = 66666667, .min_voltage = 2800, .max_voltage = 3520, .min_multi = 1.5, @@ -12841,9 +12881,9 @@ const machine_t machines[] = { .bus_flags = MACHINE_PS2_PCI | MACHINE_BUS_USB, .flags = MACHINE_IDE_DUAL | MACHINE_APM | MACHINE_ACPI | MACHINE_USB, .ram = { - .min = 8192, + .min = 4096, .max = 262144, - .step = 8192 + .step = 4096 }, .nvrmask = 255, .kbc_device = NULL, @@ -12872,18 +12912,18 @@ const machine_t machines[] = { .package = CPU_PKG_SOCKET5_7, .block = CPU_BLOCK_NONE, .min_bus = 50000000, - .max_bus = 66666667, + .max_bus = 75000000, .min_voltage = 2100, .max_voltage = 3520, .min_multi = 1.5, - .max_multi = 3.0 + .max_multi = 3.5 }, .bus_flags = MACHINE_PS2_PCI | MACHINE_BUS_USB, .flags = MACHINE_IDE_DUAL | MACHINE_APM | MACHINE_ACPI | MACHINE_USB, .ram = { - .min = 8192, + .min = 4096, .max = 262144, - .step = 8192 + .step = 4096 }, .nvrmask = 255, .kbc_device = NULL, @@ -12899,7 +12939,7 @@ const machine_t machines[] = { }, /* [TEST] Has AMIKey 'H' KBC firmware. */ { - .name = "[i430TX] TriGem Richmond", + .name = "[i430TX] TriGem RD535 (Richmond)", .internal_name = "richmond", .type = MACHINE_TYPE_SOCKET7, .chipset = MACHINE_CHIPSET_INTEL_430TX, @@ -12911,12 +12951,12 @@ const machine_t machines[] = { .cpu = { .package = CPU_PKG_SOCKET5_7, .block = CPU_BLOCK_NONE, - .min_bus = 50000000, + .min_bus = 60000000, .max_bus = 66666667, .min_voltage = 2100, .max_voltage = 3520, .min_multi = 1.5, - .max_multi = 3.0 + .max_multi = 3.5 }, .bus_flags = MACHINE_PS2_PCI | MACHINE_BUS_USB, .flags = MACHINE_IDE_DUAL | MACHINE_APM | MACHINE_ACPI | MACHINE_USB, @@ -13023,11 +13063,52 @@ const machine_t machines[] = { .snd_device = NULL, .net_device = NULL }, - + /* Has the VIA VT82C586B southbridge with on-chip KBC identical to the VIA + VT82C42N. */ + { + .name = "[VIA VP3] PC Partner VIA809DS", + .internal_name = "via809ds", + .type = MACHINE_TYPE_SOCKET7, + .chipset = MACHINE_CHIPSET_VIA_APOLLO_VP3, + .init = machine_at_via809ds_init, + .p1_handler = NULL, + .gpio_handler = NULL, + .available_flag = MACHINE_AVAILABLE, + .gpio_acpi_handler = NULL, + .cpu = { + .package = CPU_PKG_SOCKET5_7, + .block = CPU_BLOCK_NONE, + .min_bus = 50000000, + .max_bus = 75000000, + .min_voltage = 2100, + .max_voltage = 3520, + .min_multi = 1.5, + .max_multi = 5.5 + }, + .bus_flags = MACHINE_PS2_AGP | MACHINE_BUS_USB, + .flags = MACHINE_IDE_DUAL | MACHINE_APM | MACHINE_ACPI | MACHINE_USB, + .ram = { + .min = 8192, + .max = 1048576, + .step = 8192 + }, + .nvrmask = 127, + .kbc_device = NULL, + .kbc_p1 = 0xff, + .gpio = 0xffffffff, + .gpio_acpi = 0xffffffff, + .device = NULL, + .fdc_device = NULL, + .sio_device = NULL, + .vid_device = NULL, + .snd_device = NULL, + .net_device = NULL + }, + /* SiS 5571 */ /* Has the SiS 5571 chipset with on-chip KBC. */ { - .name = "[SiS 5571] Daewoo CB52X-SI", + .name = "[SiS 5571] Daewoo CD520", .internal_name = "cb52xsi", .type = MACHINE_TYPE_SOCKET7, .chipset = MACHINE_CHIPSET_SIS_5571, diff --git a/src/mem/catalyst_flash.c b/src/mem/catalyst_flash.c index 7cd40e9d7..fd2bb739f 100644 --- a/src/mem/catalyst_flash.c +++ b/src/mem/catalyst_flash.c @@ -192,8 +192,7 @@ catalyst_flash_init(UNUSED(const device_t *info)) FILE *fp; flash_t *dev; - dev = malloc(sizeof(flash_t)); - memset(dev, 0, sizeof(flash_t)); + dev = calloc(1, sizeof(flash_t)); sprintf(flash_path, "%s.bin", machine_get_internal_name_ex(machine)); @@ -240,7 +239,7 @@ const device_t catalyst_flash_device = { .init = catalyst_flash_init, .close = catalyst_flash_close, .reset = catalyst_flash_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/mem/i2c_eeprom.c b/src/mem/i2c_eeprom.c index 8e4a6cc14..a8ae7ed04 100644 --- a/src/mem/i2c_eeprom.c +++ b/src/mem/i2c_eeprom.c @@ -128,8 +128,7 @@ log2i(uint32_t i) void * i2c_eeprom_init(void *i2c, uint8_t addr, uint8_t *data, uint32_t size, uint8_t writable) { - i2c_eeprom_t *dev = (i2c_eeprom_t *) malloc(sizeof(i2c_eeprom_t)); - memset(dev, 0, sizeof(i2c_eeprom_t)); + i2c_eeprom_t *dev = (i2c_eeprom_t *) calloc(1, sizeof(i2c_eeprom_t)); /* Round size up to the next power of 2. */ uint32_t pow_size = 1 << log2i(size); diff --git a/src/mem/intel_flash.c b/src/mem/intel_flash.c index 7949f302a..7375b1f42 100644 --- a/src/mem/intel_flash.c +++ b/src/mem/intel_flash.c @@ -351,8 +351,7 @@ intel_flash_init(const device_t *info) flash_t *dev; uint8_t type = info->local & 0xff; - dev = malloc(sizeof(flash_t)); - memset(dev, 0, sizeof(flash_t)); + dev = calloc(1, sizeof(flash_t)); sprintf(flash_path, "%s.bin", machine_get_internal_name_ex(machine)); @@ -564,7 +563,7 @@ const device_t intel_flash_bxt_ami_device = { .init = intel_flash_init, .close = intel_flash_close, .reset = intel_flash_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -578,7 +577,7 @@ const device_t intel_flash_bxt_device = { .init = intel_flash_init, .close = intel_flash_close, .reset = intel_flash_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -592,7 +591,7 @@ const device_t intel_flash_bxb_device = { .init = intel_flash_init, .close = intel_flash_close, .reset = intel_flash_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/mem/row.c b/src/mem/row.c index ccd0325a4..633d0e31a 100644 --- a/src/mem/row.c +++ b/src/mem/row.c @@ -334,15 +334,15 @@ row_init(const device_t *info) /* NOTE: NOT const, so that we can patch it at init. */ device_t row_device = { - .name = "DRAM Rows", + .name = "DRAM Rows", .internal_name = "dram_rows", - .flags = DEVICE_AT, - .local = 0x0000, - .init = row_init, - .close = row_close, - .reset = row_reset, - { .available = NULL }, + .flags = DEVICE_AT, + .local = 0x0000, + .init = row_init, + .close = row_close, + .reset = row_reset, + .available = NULL, .speed_changed = NULL, - .force_redraw = NULL, - .config = NULL + .force_redraw = NULL, + .config = NULL }; diff --git a/src/mem/smram.c b/src/mem/smram.c index 0532e2dd5..afbc5475c 100644 --- a/src/mem/smram.c +++ b/src/mem/smram.c @@ -245,12 +245,11 @@ smram_add(void) return NULL; } - temp_smram = (smram_t *) malloc(sizeof(smram_t)); + temp_smram = (smram_t *) calloc(1, sizeof(smram_t)); if (temp_smram == NULL) { - fatal("smram_add(): temp_smram malloc failed\n"); + fatal("smram_add(): temp_smram calloc failed\n"); return NULL; } - memset(temp_smram, 0x00, sizeof(smram_t)); memset(&(temp_smram->mapping), 0x00, sizeof(mem_mapping_t)); /* Add struct to the beginning of the list if necessary.*/ diff --git a/src/mem/spd.c b/src/mem/spd.c index a0896a05a..01cd7b464 100644 --- a/src/mem/spd.c +++ b/src/mem/spd.c @@ -221,8 +221,7 @@ spd_register(uint8_t ram_type, uint8_t slot_mask, uint16_t max_module_size) if (!(slot_mask & (1 << slot))) continue; /* slot disabled */ - spd_modules[slot] = (spd_t *) malloc(sizeof(spd_t)); - memset(spd_modules[slot], 0, sizeof(spd_t)); + spd_modules[slot] = (spd_t *) calloc(1, sizeof(spd_t)); spd_modules[slot]->slot = slot; spd_modules[slot]->size = rows[row]; @@ -595,7 +594,7 @@ static const device_t spd_device = { .init = spd_init, .close = spd_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/mem/sst_flash.c b/src/mem/sst_flash.c index cd6ec7cd9..5a9c9c877 100644 --- a/src/mem/sst_flash.c +++ b/src/mem/sst_flash.c @@ -505,8 +505,7 @@ static void * sst_init(const device_t *info) { FILE *fp; - sst_t *dev = malloc(sizeof(sst_t)); - memset(dev, 0, sizeof(sst_t)); + sst_t *dev = calloc(1, sizeof(sst_t)); sprintf(flash_path, "%s.bin", machine_get_internal_name_ex(machine)); @@ -576,7 +575,7 @@ const device_t sst_flash_29ee010_device = { .init = sst_init, .close = sst_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -590,7 +589,7 @@ const device_t sst_flash_29ee020_device = { .init = sst_init, .close = sst_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -604,7 +603,7 @@ const device_t winbond_flash_w29c512_device = { .init = sst_init, .close = sst_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -618,7 +617,7 @@ const device_t winbond_flash_w29c010_device = { .init = sst_init, .close = sst_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -632,7 +631,7 @@ const device_t winbond_flash_w29c020_device = { .init = sst_init, .close = sst_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -646,7 +645,7 @@ const device_t winbond_flash_w29c040_device = { .init = sst_init, .close = sst_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -660,7 +659,7 @@ const device_t sst_flash_39sf512_device = { .init = sst_init, .close = sst_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -674,7 +673,7 @@ const device_t sst_flash_39sf010_device = { .init = sst_init, .close = sst_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -688,7 +687,7 @@ const device_t sst_flash_39sf020_device = { .init = sst_init, .close = sst_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -702,7 +701,7 @@ const device_t sst_flash_39sf040_device = { .init = sst_init, .close = sst_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -716,7 +715,7 @@ const device_t sst_flash_39lf512_device = { .init = sst_init, .close = sst_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -730,7 +729,7 @@ const device_t sst_flash_39lf010_device = { .init = sst_init, .close = sst_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -744,7 +743,7 @@ const device_t sst_flash_39lf020_device = { .init = sst_init, .close = sst_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -758,7 +757,7 @@ const device_t sst_flash_39lf040_device = { .init = sst_init, .close = sst_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -772,7 +771,7 @@ const device_t sst_flash_39lf080_device = { .init = sst_init, .close = sst_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -786,7 +785,7 @@ const device_t sst_flash_39lf016_device = { .init = sst_init, .close = sst_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -808,7 +807,7 @@ const device_t sst_flash_49lf002_device = { .init = sst_init, .close = sst_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -822,7 +821,7 @@ const device_t sst_flash_49lf020_device = { .init = sst_init, .close = sst_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -836,7 +835,7 @@ const device_t sst_flash_49lf020a_device = { .init = sst_init, .close = sst_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -850,7 +849,7 @@ const device_t sst_flash_49lf003_device = { .init = sst_init, .close = sst_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -864,7 +863,7 @@ const device_t sst_flash_49lf030_device = { .init = sst_init, .close = sst_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -878,7 +877,7 @@ const device_t sst_flash_49lf004_device = { .init = sst_init, .close = sst_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -892,7 +891,7 @@ const device_t sst_flash_49lf004c_device = { .init = sst_init, .close = sst_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -906,7 +905,7 @@ const device_t sst_flash_49lf040_device = { .init = sst_init, .close = sst_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -920,7 +919,7 @@ const device_t sst_flash_49lf008_device = { .init = sst_init, .close = sst_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -934,7 +933,7 @@ const device_t sst_flash_49lf008c_device = { .init = sst_init, .close = sst_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -948,7 +947,7 @@ const device_t sst_flash_49lf080_device = { .init = sst_init, .close = sst_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -962,7 +961,7 @@ const device_t sst_flash_49lf016_device = { .init = sst_init, .close = sst_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -977,7 +976,7 @@ const device_t sst_flash_49lf160_device = { .init = sst_init, .close = sst_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -991,7 +990,7 @@ const device_t amd_flash_29f020a_device = { .init = sst_init, .close = sst_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/network/net_3c501.c b/src/network/net_3c501.c index 2cafb1d46..73dd5ef62 100644 --- a/src/network/net_3c501.c +++ b/src/network/net_3c501.c @@ -56,7 +56,6 @@ #include <86box/thread.h> #include <86box/timer.h> #include <86box/network.h> -#include <86box/bswap.h> #include <86box/plat_unused.h> /* Maximum number of times we report a link down to the guest (failure to send frame) */ @@ -1080,8 +1079,7 @@ threec501_nic_init(UNUSED(const device_t *info)) uint32_t mac; threec501_t *dev; - dev = malloc(sizeof(threec501_t)); - memset(dev, 0x00, sizeof(threec501_t)); + dev = calloc(1, sizeof(threec501_t)); dev->maclocal[0] = 0x02; /* 02:60:8C (3Com OID) */ dev->maclocal[1] = 0x60; dev->maclocal[2] = 0x8C; @@ -1222,7 +1220,7 @@ const device_t threec501_device = { .init = threec501_nic_init, .close = threec501_nic_close, .reset = elnkR3Reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = threec501_config diff --git a/src/network/net_3c503.c b/src/network/net_3c503.c index 6191c02bf..cd5016147 100644 --- a/src/network/net_3c503.c +++ b/src/network/net_3c503.c @@ -60,7 +60,6 @@ #include <86box/timer.h> #include <86box/network.h> #include <86box/net_dp8390.h> -#include <86box/bswap.h> #include <86box/plat_unused.h> typedef struct threec503_t { @@ -573,8 +572,7 @@ threec503_nic_init(UNUSED(const device_t *info)) uint32_t mac; threec503_t *dev; - dev = malloc(sizeof(threec503_t)); - memset(dev, 0x00, sizeof(threec503_t)); + dev = calloc(1, sizeof(threec503_t)); dev->maclocal[0] = 0x02; /* 02:60:8C (3Com OID) */ dev->maclocal[1] = 0x60; dev->maclocal[2] = 0x8C; @@ -739,15 +737,15 @@ static const device_config_t threec503_config[] = { }; const device_t threec503_device = { - .name = "3Com EtherLink II", + .name = "3Com EtherLink II", .internal_name = "3c503", - .flags = DEVICE_ISA, - .local = 0, - .init = threec503_nic_init, - .close = threec503_nic_close, - .reset = NULL, - { .available = NULL }, + .flags = DEVICE_ISA, + .local = 0, + .init = threec503_nic_init, + .close = threec503_nic_close, + .reset = NULL, + .available = NULL, .speed_changed = NULL, - .force_redraw = NULL, - .config = threec503_config + .force_redraw = NULL, + .config = threec503_config }; diff --git a/src/network/net_dp8390.c b/src/network/net_dp8390.c index d6062604f..623dec56c 100644 --- a/src/network/net_dp8390.c +++ b/src/network/net_dp8390.c @@ -918,8 +918,7 @@ dp8390_set_defaults(dp8390_t *dev, uint8_t flags) void dp8390_mem_alloc(dp8390_t *dev, uint32_t start, uint32_t size) { - dev->mem = (uint8_t *) malloc(size * sizeof(uint8_t)); - memset(dev->mem, 0, size * sizeof(uint8_t)); + dev->mem = (uint8_t *) calloc(size, sizeof(uint8_t)); dev->mem_start = start; dev->mem_end = start + size; dev->mem_size = size; @@ -1007,8 +1006,7 @@ dp8390_soft_reset(dp8390_t *dev) static void * dp8390_init(UNUSED(const device_t *info)) { - dp8390_t *dp8390 = (dp8390_t *) malloc(sizeof(dp8390_t)); - memset(dp8390, 0, sizeof(dp8390_t)); + dp8390_t *dp8390 = (dp8390_t *) calloc(1, sizeof(dp8390_t)); /* Set values assuming WORD and only the clear IRQ flag - - the NIC can then call dp8390_set_defaults() again to @@ -1047,7 +1045,7 @@ const device_t dp8390_device = { .init = dp8390_init, .close = dp8390_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/network/net_eeprom_nmc93cxx.c b/src/network/net_eeprom_nmc93cxx.c index 3ad6bd030..b4fdce1e6 100644 --- a/src/network/net_eeprom_nmc93cxx.c +++ b/src/network/net_eeprom_nmc93cxx.c @@ -277,7 +277,7 @@ const device_t nmc93cxx_device = { .init = nmc93cxx_eeprom_init, .close = nmc93cxx_eeprom_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/network/net_modem.c b/src/network/net_modem.c index bb312ec31..83dfe04d7 100644 --- a/src/network/net_modem.c +++ b/src/network/net_modem.c @@ -1133,7 +1133,7 @@ modem_dtr_callback_timer(void *priv) } void -modem_dtr_callback(serial_t *serial, int status, void *priv) +modem_dtr_callback(UNUSED(serial_t *serial), int status, void *priv) { modem_t *dev = (modem_t *) priv; dev->dtrstate = !!status; @@ -1483,7 +1483,7 @@ modem_cmdpause_timer_callback(void *priv) /* Initialize the device for use by the user. */ static void * -modem_init(const device_t *info) +modem_init(UNUSED(const device_t *info)) { modem_t *modem = (modem_t *) calloc(1, sizeof(modem_t)); const char *phonebook_file = NULL; @@ -1608,7 +1608,7 @@ const device_t modem_device = { .init = modem_init, .close = modem_close, .reset = NULL, - { .poll = NULL }, + .poll = NULL, .speed_changed = modem_speed_changed, .force_redraw = NULL, .config = modem_config diff --git a/src/network/net_ne2000.c b/src/network/net_ne2000.c index 324154947..2f6c60d51 100644 --- a/src/network/net_ne2000.c +++ b/src/network/net_ne2000.c @@ -66,7 +66,6 @@ #include <86box/network.h> #include <86box/net_dp8390.h> #include <86box/net_ne2000.h> -#include <86box/bswap.h> #include <86box/isapnp.h> #include <86box/plat_fallthrough.h> #include <86box/plat_unused.h> @@ -313,7 +312,7 @@ asic_write(nic_t *dev, uint32_t off, uint32_t val, unsigned len) static uint32_t page3_read(nic_t *dev, uint32_t off, UNUSED(unsigned int len)) { - if (dev->board >= NE2K_RTL8019AS) + if (dev->board >= NE2K_RTL8019AS_PNP) switch (off) { case 0x1: /* 9346CR */ return (dev->_9346cr); @@ -328,7 +327,7 @@ page3_read(nic_t *dev, uint32_t off, UNUSED(unsigned int len)) return (dev->config3 & 0x46); case 0x8: /* CSNSAV */ - return ((dev->board == NE2K_RTL8019AS) ? dev->pnp_csnsav : 0x00); + return ((dev->board == NE2K_RTL8019AS_PNP) ? dev->pnp_csnsav : 0x00); case 0xe: /* 8029ASID0 */ if (dev->board == NE2K_RTL8029AS) @@ -351,7 +350,7 @@ page3_read(nic_t *dev, uint32_t off, UNUSED(unsigned int len)) static void page3_write(nic_t *dev, uint32_t off, uint32_t val, UNUSED(unsigned len)) { - if (dev->board >= NE2K_RTL8019AS) { + if (dev->board >= NE2K_RTL8019AS_PNP) { nelog(3, "%s: Page2 write to register 0x%02x, len=%u, value=0x%04x\n", dev->name, off, len, val); @@ -912,17 +911,15 @@ nic_init(const device_t *info) { uint32_t mac; uint32_t mac_oui; - char *rom; + char *rom = NULL; nic_t *dev; int set_oui = 0; - dev = malloc(sizeof(nic_t)); - memset(dev, 0x00, sizeof(nic_t)); + dev = calloc(1, sizeof(nic_t)); dev->name = info->name; dev->board = info->local; - rom = NULL; - if (dev->board >= NE2K_RTL8019AS) { + if (dev->board >= NE2K_RTL8019AS_PNP) { dev->base_address = 0x340; dev->base_irq = 12; if (dev->board == NE2K_RTL8029AS) { @@ -1045,18 +1042,18 @@ nic_init(const device_t *info) dp8390_mem_alloc(dev->dp8390, 0x4000, 0x8000); break; - case NE2K_RTL8019AS: + case NE2K_RTL8019AS_PNP: case NE2K_RTL8029AS: dev->is_pci = (dev->board == NE2K_RTL8029AS) ? 1 : 0; dev->maclocal[0] = 0x00; /* 00:E0:4C (Realtek OID) */ dev->maclocal[1] = 0xE0; dev->maclocal[2] = 0x4C; - rom = (dev->board == NE2K_RTL8019AS) ? ROM_PATH_RTL8019 : ROM_PATH_RTL8029; + rom = (dev->board == NE2K_RTL8019AS_PNP) ? ROM_PATH_RTL8019 : ROM_PATH_RTL8029; if (dev->is_pci) dp8390_set_defaults(dev->dp8390, DP8390_FLAG_EVEN_MAC); else dp8390_set_defaults(dev->dp8390, DP8390_FLAG_EVEN_MAC | DP8390_FLAG_CLEAR_IRQ); - dp8390_set_id(dev->dp8390, 0x50, (dev->board == NE2K_RTL8019AS) ? 0x70 : 0x43); + dp8390_set_id(dev->dp8390, 0x50, (dev->board == NE2K_RTL8019AS_PNP) ? 0x70 : 0x43); dp8390_mem_alloc(dev->dp8390, 0x4000, 0x8000); break; @@ -1093,13 +1090,13 @@ nic_init(const device_t *info) * Make this device known to the I/O system. * PnP and PCI devices start with address spaces inactive. */ - if ((dev->board < NE2K_RTL8019AS) && (dev->board != NE2K_ETHERNEXT_MC)) + if ((dev->board < NE2K_RTL8019AS_PNP) && (dev->board != NE2K_ETHERNEXT_MC)) nic_ioset(dev, dev->base_address); /* Set up our BIOS ROM space, if any. */ nic_rom_init(dev, rom); - if (dev->board >= NE2K_RTL8019AS) { + if (dev->board >= NE2K_RTL8019AS_PNP) { if (dev->is_pci) { /* * Configure the PCI space registers. @@ -1147,7 +1144,7 @@ nic_init(const device_t *info) pci_add_card(PCI_ADD_NORMAL, nic_pci_read, nic_pci_write, dev, &dev->pci_slot); } - /* Initialize the RTL8029 EEPROM. */ + /* Initialize the RTL80x9 EEPROM. */ memset(dev->eeprom, 0x00, sizeof(dev->eeprom)); if (dev->board == NE2K_RTL8029AS) { @@ -1161,7 +1158,7 @@ nic_init(const device_t *info) const char *pnp_rom_file = NULL; int pnp_rom_len = 0x4a; switch (dev->board) { - case NE2K_RTL8019AS: + case NE2K_RTL8019AS_PNP: pnp_rom_file = "roms/network/rtl8019as/RTL8019A.BIN"; break; @@ -1185,7 +1182,7 @@ nic_init(const device_t *info) } switch (info->local) { - case NE2K_RTL8019AS: + case NE2K_RTL8019AS_PNP: case NE2K_DE220P: dev->pnp_card = isapnp_add_card(pnp_rom, pnp_rom_len, nic_pnp_config_changed, nic_pnp_csn_changed, @@ -1633,7 +1630,7 @@ const device_t ne1000_device = { .init = nic_init, .close = nic_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = ne1000_config @@ -1647,7 +1644,7 @@ const device_t ne1000_compat_device = { .init = nic_init, .close = nic_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = ne1000_compat_config @@ -1661,7 +1658,7 @@ const device_t ne2000_device = { .init = nic_init, .close = nic_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = ne2000_config @@ -1675,7 +1672,7 @@ const device_t ne2000_compat_device = { .init = nic_init, .close = nic_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = ne2000_compat_config @@ -1689,7 +1686,7 @@ const device_t ne2000_compat_8bit_device = { .init = nic_init, .close = nic_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = ne2000_compat_8bit_config @@ -1703,21 +1700,21 @@ const device_t ethernext_mc_device = { .init = nic_init, .close = nic_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = mca_mac_config }; -const device_t rtl8019as_device = { +const device_t rtl8019as_pnp_device = { .name = "Realtek RTL8019AS", .internal_name = "ne2kpnp", .flags = DEVICE_ISA | DEVICE_AT, - .local = NE2K_RTL8019AS, + .local = NE2K_RTL8019AS_PNP, .init = nic_init, .close = nic_close, .reset = NULL, - { .available = rtl8019as_available }, + .available = rtl8019as_available, .speed_changed = NULL, .force_redraw = NULL, .config = rtl8019as_config @@ -1731,7 +1728,7 @@ const device_t de220p_device = { .init = nic_init, .close = nic_close, .reset = NULL, - { .available = de220p_available }, + .available = de220p_available, .speed_changed = NULL, .force_redraw = NULL, .config = rtl8019as_config @@ -1745,7 +1742,7 @@ const device_t rtl8029as_device = { .init = nic_init, .close = nic_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = rtl8029as_config diff --git a/src/network/net_null.c b/src/network/net_null.c index 6fb3f3440..6d5f68e46 100644 --- a/src/network/net_null.c +++ b/src/network/net_null.c @@ -218,8 +218,8 @@ net_null_close(void *priv) } const netdrv_t net_null_drv = { - &net_null_in_available, - &net_null_init, - &net_null_close, - NULL + .notify_in = &net_null_in_available, + .init = &net_null_init, + .close = &net_null_close, + .priv = NULL }; diff --git a/src/network/net_pcap.c b/src/network/net_pcap.c index 852191c55..2af34d786 100644 --- a/src/network/net_pcap.c +++ b/src/network/net_pcap.c @@ -572,8 +572,8 @@ net_pcap_close(void *priv) } const netdrv_t net_pcap_drv = { - &net_pcap_in_available, - &net_pcap_init, - &net_pcap_close, - NULL + .notify_in = &net_pcap_in_available, + .init = &net_pcap_init, + .close = &net_pcap_close, + .priv = NULL }; diff --git a/src/network/net_pcnet.c b/src/network/net_pcnet.c index b1fca8feb..5487486b4 100644 --- a/src/network/net_pcnet.c +++ b/src/network/net_pcnet.c @@ -46,9 +46,9 @@ #include <86box/thread.h> #include <86box/network.h> #include <86box/net_pcnet.h> -#include <86box/bswap.h> #include <86box/plat_fallthrough.h> #include <86box/plat_unused.h> +#include <86box/bswap.h> /* PCI info. */ #define PCI_VENDID 0x1022 /* AMD */ @@ -2916,8 +2916,7 @@ pcnet_init(const device_t *info) int c; uint16_t checksum; - dev = malloc(sizeof(nic_t)); - memset(dev, 0x00, sizeof(nic_t)); + dev = calloc(1, sizeof(nic_t)); dev->name = info->name; dev->board = info->local & 0xff; @@ -3220,7 +3219,7 @@ const device_t pcnet_am79c960_device = { .init = pcnet_init, .close = pcnet_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = pcnet_isa_config @@ -3234,7 +3233,7 @@ const device_t pcnet_am79c960_eb_device = { .init = pcnet_init, .close = pcnet_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = pcnet_isa_config @@ -3248,7 +3247,7 @@ const device_t pcnet_am79c960_vlb_device = { .init = pcnet_init, .close = pcnet_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = pcnet_vlb_config @@ -3262,7 +3261,7 @@ const device_t pcnet_am79c961_device = { .init = pcnet_init, .close = pcnet_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = pcnet_pci_config @@ -3276,7 +3275,7 @@ const device_t pcnet_am79c970a_device = { .init = pcnet_init, .close = pcnet_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = pcnet_pci_config @@ -3290,7 +3289,7 @@ const device_t pcnet_am79c973_device = { .init = pcnet_init, .close = pcnet_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = pcnet_pci_config @@ -3304,7 +3303,7 @@ const device_t pcnet_am79c973_onboard_device = { .init = pcnet_init, .close = pcnet_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = pcnet_pci_config diff --git a/src/network/net_plip.c b/src/network/net_plip.c index 8b0bf460c..f80effeec 100644 --- a/src/network/net_plip.c +++ b/src/network/net_plip.c @@ -445,8 +445,7 @@ plip_rx(void *priv, uint8_t *buf, int io_len) static void * plip_lpt_init(void *lpt) { - plip_t *dev = (plip_t *) malloc(sizeof(plip_t)); - memset(dev, 0, sizeof(plip_t)); + plip_t *dev = (plip_t *) calloc(1, sizeof(plip_t)); plip_log(1, "PLIP: lpt_init()\n"); @@ -508,7 +507,7 @@ const device_t plip_device = { .init = plip_net_init, .close = NULL, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/network/net_rtl8139.c b/src/network/net_rtl8139.c index 0dac29a8c..74b041b35 100644 --- a/src/network/net_rtl8139.c +++ b/src/network/net_rtl8139.c @@ -44,10 +44,10 @@ #include <86box/thread.h> #include <86box/network.h> #include <86box/net_eeprom_nmc93cxx.h> -#include <86box/bswap.h> #include <86box/nvr.h> #include "cpu.h" #include <86box/plat_unused.h> +#include <86box/bswap.h> #define PCI_PERIOD 30 /* 30 ns period = 33.333333 Mhz frequency */ @@ -1210,7 +1210,7 @@ rtl8139_CpCmd_read(RTL8139State *s) } static void -rtl8139_IntrMitigate_write(UNUSED(RTL8139State *s), uint32_t val) +rtl8139_IntrMitigate_write(UNUSED(RTL8139State *s), UNUSED(uint32_t val)) { rtl8139_log("C+ IntrMitigate register write(w) val=0x%04x\n", val); } @@ -3151,7 +3151,7 @@ rtl8139_pci_read(UNUSED(int func), int addr, void *priv) } static void -rtl8139_pci_write(int func, int addr, uint8_t val, void *priv) +rtl8139_pci_write(UNUSED(int func), int addr, uint8_t val, void *priv) { RTL8139State *s = (RTL8139State *) priv; @@ -3333,7 +3333,7 @@ const device_t rtl8139c_plus_device = { .init = nic_init, .close = nic_close, .reset = rtl8139_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = rtl8139c_config diff --git a/src/network/net_slirp.c b/src/network/net_slirp.c index 92434973d..11f1a74b2 100644 --- a/src/network/net_slirp.c +++ b/src/network/net_slirp.c @@ -133,7 +133,7 @@ net_slirp_clock_get_ns(UNUSED(void *opaque)) static void * net_slirp_timer_new(SlirpTimerCb cb, void *cb_opaque, UNUSED(void *opaque)) { - pc_timer_t *timer = malloc(sizeof(pc_timer_t)); + pc_timer_t *timer = calloc(1, sizeof(pc_timer_t)); timer_add(timer, cb, cb_opaque, 0); return timer; } @@ -422,8 +422,7 @@ net_slirp_init(const netcard_t *card, const uint8_t *mac_addr, UNUSED(void *priv #ifndef _WIN32 slirp->pfd_size = 16 * sizeof(struct pollfd); - slirp->pfd = malloc(slirp->pfd_size); - memset(slirp->pfd, 0, slirp->pfd_size); + slirp->pfd = calloc(1, slirp->pfd_size); #endif /* Set the IP addresses to use. */ @@ -544,7 +543,8 @@ net_slirp_close(void *priv) } const netdrv_t net_slirp_drv = { - &net_slirp_in_available, - &net_slirp_init, - &net_slirp_close + .notify_in = &net_slirp_in_available, + .init = &net_slirp_init, + .close = &net_slirp_close, + .priv = NULL }; diff --git a/src/network/net_tulip.c b/src/network/net_tulip.c index ca43b0844..2c3aab379 100644 --- a/src/network/net_tulip.c +++ b/src/network/net_tulip.c @@ -32,9 +32,9 @@ #include <86box/thread.h> #include <86box/network.h> #include <86box/net_eeprom_nmc93cxx.h> -#include <86box/bswap.h> #include <86box/plat_fallthrough.h> #include <86box/plat_unused.h> +#include <86box/bswap.h> #define ROM_PATH_DEC21140 "roms/network/dec21140/BIOS13502.BIN" @@ -1700,7 +1700,7 @@ const device_t dec_tulip_device = { .init = nic_init, .close = nic_close, .reset = tulip_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = dec_tulip_21143_config @@ -1714,7 +1714,7 @@ const device_t dec_tulip_21140_device = { .init = nic_init, .close = nic_close, .reset = tulip_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = dec_tulip_21140_config @@ -1728,7 +1728,7 @@ const device_t dec_tulip_21140_vpc_device = { .init = nic_init, .close = nic_close, .reset = tulip_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = dec_tulip_21140_config @@ -1742,7 +1742,7 @@ const device_t dec_tulip_21040_device = { .init = nic_init, .close = nic_close, .reset = tulip_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = dec_tulip_21143_config diff --git a/src/network/net_vde.c b/src/network/net_vde.c index d783c9c9d..4f8d5c21f 100644 --- a/src/network/net_vde.c +++ b/src/network/net_vde.c @@ -302,9 +302,9 @@ void *net_vde_init(const netcard_t *card, const uint8_t *mac_addr, void *priv, c // VDE Driver structure //- const netdrv_t net_vde_drv = { - &net_vde_in_available, - &net_vde_init, - &net_vde_close, - NULL + .notify_in = &net_vde_in_available, + .init = &net_vde_init, + .close = &net_vde_close, + .priv = NULL }; diff --git a/src/network/net_wd8003.c b/src/network/net_wd8003.c index 72a4b7fd0..1e5496851 100644 --- a/src/network/net_wd8003.c +++ b/src/network/net_wd8003.c @@ -63,7 +63,6 @@ #include <86box/network.h> #include <86box/net_dp8390.h> #include <86box/net_wd8003.h> -#include <86box/bswap.h> #include <86box/plat_fallthrough.h> #include <86box/plat_unused.h> @@ -651,8 +650,7 @@ wd_init(const device_t *info) uint32_t mac; wd_t *dev; - dev = malloc(sizeof(wd_t)); - memset(dev, 0x00, sizeof(wd_t)); + dev = calloc(1, sizeof(wd_t)); dev->name = info->name; dev->board = info->local; @@ -1084,7 +1082,7 @@ const device_t wd8003e_device = { .init = wd_init, .close = wd_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = wd8003_config @@ -1098,7 +1096,7 @@ const device_t wd8003eb_device = { .init = wd_init, .close = wd_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = wd8003eb_config @@ -1112,7 +1110,7 @@ const device_t wd8013ebt_device = { .init = wd_init, .close = wd_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = wd8013_config @@ -1126,7 +1124,7 @@ const device_t wd8003eta_device = { .init = wd_init, .close = wd_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = mca_mac_config @@ -1140,7 +1138,7 @@ const device_t wd8003ea_device = { .init = wd_init, .close = wd_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = mca_mac_config @@ -1154,7 +1152,7 @@ const device_t wd8013epa_device = { .init = wd_init, .close = wd_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = wd8013epa_config diff --git a/src/network/network.c b/src/network/network.c index f4b03ee79..66990e51d 100644 --- a/src/network/network.c +++ b/src/network/network.c @@ -96,7 +96,7 @@ static const NETWORK_CARD net_cards[] = { { &ne1000_device }, { &ne2000_device }, { &pcnet_am79c960_eb_device }, - { &rtl8019as_device }, + { &rtl8019as_pnp_device }, { &wd8003e_device }, { &wd8003eb_device }, { &wd8013ebt_device }, diff --git a/src/nvr.c b/src/nvr.c index d833618d0..d0b05b93a 100644 --- a/src/nvr.c +++ b/src/nvr.c @@ -326,14 +326,15 @@ nvr_time_sync(void) /* Get current time from internal clock. */ void -nvr_time_get(struct tm *tm) +nvr_time_get(void *priv) { - uint8_t dom; - uint8_t mon; - uint8_t sum; - uint8_t wd; - uint16_t cent; - uint16_t yr; + struct tm *tm = (struct tm *) priv; + uint8_t dom; + uint8_t mon; + uint8_t sum; + uint8_t wd; + uint16_t cent; + uint16_t yr; tm->tm_sec = intclk.tm_sec; tm->tm_min = intclk.tm_min; @@ -352,8 +353,10 @@ nvr_time_get(struct tm *tm) /* Set internal clock time. */ void -nvr_time_set(struct tm *tm) +nvr_time_set(void *priv) { + struct tm *tm = (struct tm *) priv; + intclk.tm_sec = tm->tm_sec; intclk.tm_min = tm->tm_min; intclk.tm_hour = tm->tm_hour; diff --git a/src/nvr_at.c b/src/nvr_at.c index 9465839a7..147795f8e 100644 --- a/src/nvr_at.c +++ b/src/nvr_at.c @@ -1224,7 +1224,7 @@ const device_t at_nvr_old_device = { .init = nvr_at_init, .close = nvr_at_close, .reset = nvr_at_reset, - { .available = NULL }, + .available = NULL, .speed_changed = nvr_at_speed_changed, .force_redraw = NULL, .config = NULL @@ -1238,7 +1238,7 @@ const device_t at_nvr_device = { .init = nvr_at_init, .close = nvr_at_close, .reset = nvr_at_reset, - { .available = NULL }, + .available = NULL, .speed_changed = nvr_at_speed_changed, .force_redraw = NULL, .config = NULL @@ -1252,7 +1252,7 @@ const device_t at_mb_nvr_device = { .init = nvr_at_init, .close = nvr_at_close, .reset = nvr_at_reset, - { .available = NULL }, + .available = NULL, .speed_changed = nvr_at_speed_changed, .force_redraw = NULL, .config = NULL @@ -1266,7 +1266,7 @@ const device_t ps_nvr_device = { .init = nvr_at_init, .close = nvr_at_close, .reset = nvr_at_reset, - { .available = NULL }, + .available = NULL, .speed_changed = nvr_at_speed_changed, .force_redraw = NULL, .config = NULL @@ -1280,7 +1280,7 @@ const device_t amstrad_nvr_device = { .init = nvr_at_init, .close = nvr_at_close, .reset = nvr_at_reset, - { .available = NULL }, + .available = NULL, .speed_changed = nvr_at_speed_changed, .force_redraw = NULL, .config = NULL @@ -1294,7 +1294,7 @@ const device_t ibmat_nvr_device = { .init = nvr_at_init, .close = nvr_at_close, .reset = nvr_at_reset, - { .available = NULL }, + .available = NULL, .speed_changed = nvr_at_speed_changed, .force_redraw = NULL, .config = NULL @@ -1308,7 +1308,7 @@ const device_t piix4_nvr_device = { .init = nvr_at_init, .close = nvr_at_close, .reset = nvr_at_reset, - { .available = NULL }, + .available = NULL, .speed_changed = nvr_at_speed_changed, .force_redraw = NULL, .config = NULL @@ -1322,7 +1322,7 @@ const device_t ps_no_nmi_nvr_device = { .init = nvr_at_init, .close = nvr_at_close, .reset = nvr_at_reset, - { .available = NULL }, + .available = NULL, .speed_changed = nvr_at_speed_changed, .force_redraw = NULL, .config = NULL @@ -1336,7 +1336,7 @@ const device_t amstrad_no_nmi_nvr_device = { .init = nvr_at_init, .close = nvr_at_close, .reset = nvr_at_reset, - { .available = NULL }, + .available = NULL, .speed_changed = nvr_at_speed_changed, .force_redraw = NULL, .config = NULL @@ -1350,7 +1350,7 @@ const device_t ami_1992_nvr_device = { .init = nvr_at_init, .close = nvr_at_close, .reset = nvr_at_reset, - { .available = NULL }, + .available = NULL, .speed_changed = nvr_at_speed_changed, .force_redraw = NULL, .config = NULL @@ -1364,7 +1364,7 @@ const device_t ami_1994_nvr_device = { .init = nvr_at_init, .close = nvr_at_close, .reset = nvr_at_reset, - { .available = NULL }, + .available = NULL, .speed_changed = nvr_at_speed_changed, .force_redraw = NULL, .config = NULL @@ -1378,7 +1378,7 @@ const device_t ami_1995_nvr_device = { .init = nvr_at_init, .close = nvr_at_close, .reset = nvr_at_reset, - { .available = NULL }, + .available = NULL, .speed_changed = nvr_at_speed_changed, .force_redraw = NULL, .config = NULL @@ -1392,7 +1392,7 @@ const device_t via_nvr_device = { .init = nvr_at_init, .close = nvr_at_close, .reset = nvr_at_reset, - { .available = NULL }, + .available = NULL, .speed_changed = nvr_at_speed_changed, .force_redraw = NULL, .config = NULL @@ -1406,7 +1406,7 @@ const device_t p6rp4_nvr_device = { .init = nvr_at_init, .close = nvr_at_close, .reset = nvr_at_reset, - { .available = NULL }, + .available = NULL, .speed_changed = nvr_at_speed_changed, .force_redraw = NULL, .config = NULL @@ -1420,7 +1420,7 @@ const device_t amstrad_megapc_nvr_device = { .init = nvr_at_init, .close = nvr_at_close, .reset = nvr_at_reset, - { .available = NULL }, + .available = NULL, .speed_changed = nvr_at_speed_changed, .force_redraw = NULL, .config = NULL @@ -1434,7 +1434,7 @@ const device_t elt_nvr_device = { .init = nvr_at_init, .close = nvr_at_close, .reset = nvr_at_reset, - { .available = NULL }, + .available = NULL, .speed_changed = nvr_at_speed_changed, .force_redraw = NULL, .config = NULL diff --git a/src/nvr_ps2.c b/src/nvr_ps2.c index 67eaccc38..3ca0b0ba5 100644 --- a/src/nvr_ps2.c +++ b/src/nvr_ps2.c @@ -114,8 +114,7 @@ ps2_nvr_init(const device_t *info) FILE *fp = NULL; int c; - nvr = (ps2_nvr_t *) malloc(sizeof(ps2_nvr_t)); - memset(nvr, 0x00, sizeof(ps2_nvr_t)); + nvr = (ps2_nvr_t *) calloc(1, sizeof(ps2_nvr_t)); if (info->local) nvr->size = 2048; @@ -170,7 +169,7 @@ const device_t ps2_nvr_device = { .init = ps2_nvr_init, .close = ps2_nvr_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -184,7 +183,7 @@ const device_t ps2_nvr_55ls_device = { .init = ps2_nvr_init, .close = ps2_nvr_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/pci_dummy.c b/src/pci_dummy.c index 704f85d8c..bceb58c22 100644 --- a/src/pci_dummy.c +++ b/src/pci_dummy.c @@ -278,7 +278,7 @@ pci_dummy_card_init(UNUSED(const device_t *info)) { pci_dummy_t *dev = (pci_dummy_t *) calloc(1, sizeof(pci_dummy_t)); - pci_add_card(PCI_ADD_NORMAL, pci_dummy_pci_read, pci_dummy_pci_write, dev, &dev->pci_slot); + pci_add_card(PCI_ADD_NORMAL, pci_dummy_pci_read, pci_dummy_pci_write, dev, &dev->pci_slot); return dev; } @@ -291,7 +291,7 @@ const device_t pci_dummy_device = { .init = pci_dummy_card_init, .close = pci_dummy_close, .reset = pci_dummy_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/pic.c b/src/pic.c index fa7ff3662..7f6eda40d 100644 --- a/src/pic.c +++ b/src/pic.c @@ -245,7 +245,7 @@ pic_update_pending_at(void) } static void -pic_callback(void *priv) +pic_callback(UNUSED(void *priv)) { update_pending(); } diff --git a/src/pit.c b/src/pit.c index 8b9f23a79..a283d1205 100644 --- a/src/pit.c +++ b/src/pit.c @@ -960,7 +960,7 @@ const device_t i8253_device = { .init = pit_init, .close = pit_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = pit_speed_changed, .force_redraw = NULL, .config = NULL @@ -974,7 +974,7 @@ const device_t i8253_ext_io_device = { .init = pit_init, .close = pit_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -988,7 +988,7 @@ const device_t i8254_device = { .init = pit_init, .close = pit_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = pit_speed_changed, .force_redraw = NULL, .config = NULL @@ -1002,7 +1002,7 @@ const device_t i8254_sec_device = { .init = pit_init, .close = pit_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = pit_speed_changed, .force_redraw = NULL, .config = NULL @@ -1016,7 +1016,7 @@ const device_t i8254_ext_io_device = { .init = pit_init, .close = pit_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -1030,7 +1030,7 @@ const device_t i8254_ps2_device = { .init = pit_init, .close = pit_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = pit_speed_changed, .force_redraw = NULL, .config = NULL @@ -1250,14 +1250,14 @@ pit_set_clock(uint32_t clock) } const pit_intf_t pit_classic_intf = { - &pit_read, - &pit_write, - &pit_ctr_get_count, - &pit_ctr_set_gate, - &pit_ctr_set_using_timer, - &pit_ctr_set_out_func, - &pit_ctr_set_load_func, - &ctr_clock, - &pit_set_pit_const, - NULL, + .read = &pit_read, + .write = &pit_write, + .get_count = &pit_ctr_get_count, + .set_gate = &pit_ctr_set_gate, + .set_using_timer = &pit_ctr_set_using_timer, + .set_out_func = &pit_ctr_set_out_func, + .set_load_func = &pit_ctr_set_load_func, + .ctr_clock = &ctr_clock, + .set_pit_const = &pit_set_pit_const, + .data = NULL, }; diff --git a/src/pit_fast.c b/src/pit_fast.c index 0d56a6616..b92b59f3c 100644 --- a/src/pit_fast.c +++ b/src/pit_fast.c @@ -751,7 +751,7 @@ const device_t i8253_fast_device = { .init = pitf_init, .close = pitf_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = pitf_speed_changed, .force_redraw = NULL, .config = NULL @@ -765,7 +765,7 @@ const device_t i8254_fast_device = { .init = pitf_init, .close = pitf_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = pitf_speed_changed, .force_redraw = NULL, .config = NULL @@ -779,7 +779,7 @@ const device_t i8254_sec_fast_device = { .init = pitf_init, .close = pitf_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = pitf_speed_changed, .force_redraw = NULL, .config = NULL @@ -793,7 +793,7 @@ const device_t i8254_ext_io_fast_device = { .init = pitf_init, .close = pitf_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -807,21 +807,21 @@ const device_t i8254_ps2_fast_device = { .init = pitf_init, .close = pitf_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = pitf_speed_changed, .force_redraw = NULL, .config = NULL }; const pit_intf_t pit_fast_intf = { - &pitf_read, - &pitf_write, - &pitf_ctr_get_count, - &pitf_ctr_set_gate, - &pitf_ctr_set_using_timer, - &pitf_ctr_set_out_func, - &pitf_ctr_set_load_func, - &pitf_ctr_clock, - &pitf_set_pit_const, - NULL, + .read = &pitf_read, + .write = &pitf_write, + .get_count = &pitf_ctr_get_count, + .set_gate = &pitf_ctr_set_gate, + .set_using_timer = &pitf_ctr_set_using_timer, + .set_out_func = &pitf_ctr_set_out_func, + .set_load_func = &pitf_ctr_set_load_func, + .ctr_clock = &pitf_ctr_clock, + .set_pit_const = &pitf_set_pit_const, + .data = NULL, }; diff --git a/src/port_6x.c b/src/port_6x.c index 971b92d28..b8183d651 100644 --- a/src/port_6x.c +++ b/src/port_6x.c @@ -212,7 +212,7 @@ const device_t port_6x_device = { .init = port_6x_init, .close = port_6x_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -226,7 +226,7 @@ const device_t port_6x_xi8088_device = { .init = port_6x_init, .close = port_6x_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -240,7 +240,7 @@ const device_t port_6x_ps2_device = { .init = port_6x_init, .close = port_6x_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -254,7 +254,7 @@ const device_t port_6x_olivetti_device = { .init = port_6x_init, .close = port_6x_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/port_92.c b/src/port_92.c index 18e60326c..d1a53a321 100644 --- a/src/port_92.c +++ b/src/port_92.c @@ -235,7 +235,7 @@ const device_t port_92_device = { .init = port_92_init, .close = port_92_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -249,7 +249,7 @@ const device_t port_92_key_device = { .init = port_92_init, .close = port_92_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -263,7 +263,7 @@ const device_t port_92_inv_device = { .init = port_92_init, .close = port_92_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -277,7 +277,7 @@ const device_t port_92_word_device = { .init = port_92_init, .close = port_92_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -291,7 +291,7 @@ const device_t port_92_pci_device = { .init = port_92_init, .close = port_92_close, .reset = port_92_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/printer/prt_escp.c b/src/printer/prt_escp.c index 0b40bec90..0198444a0 100644 --- a/src/printer/prt_escp.c +++ b/src/printer/prt_escp.c @@ -1952,7 +1952,7 @@ read_status(void *priv) static void * escp_init(void *lpt) { - escp_t *dev; + escp_t *dev = NULL; /* Initialize FreeType. */ if (ft_lib == NULL) { @@ -1964,8 +1964,7 @@ escp_init(void *lpt) } /* Initialize a device instance. */ - dev = (escp_t *) malloc(sizeof(escp_t)); - memset(dev, 0x00, sizeof(escp_t)); + dev = (escp_t *) calloc(1, sizeof(escp_t)); dev->ctrl = 0x04; dev->lpt = lpt; diff --git a/src/printer/prt_ps.c b/src/printer/prt_ps.c index dcd018881..1a9d5c0e8 100644 --- a/src/printer/prt_ps.c +++ b/src/printer/prt_ps.c @@ -366,13 +366,12 @@ ps_read_status(void *priv) static void * ps_init(void *lpt) { - ps_t *dev; + ps_t *dev = (ps_t *) calloc(1, sizeof(ps_t)); gsapi_revision_t rev; - dev = (ps_t *) malloc(sizeof(ps_t)); - memset(dev, 0x00, sizeof(ps_t)); dev->ctrl = 0x04; dev->lpt = lpt; + dev->pcl = false; /* Try loading the DLL. */ ghostscript_handle = dynld_module(PATH_GHOSTSCRIPT_DLL, ghostscript_imports); @@ -415,11 +414,9 @@ ps_init(void *lpt) static void * pcl_init(void *lpt) { - ps_t *dev; + ps_t *dev = (ps_t *) calloc(1, sizeof(ps_t)); gsapi_revision_t rev; - dev = (ps_t *) malloc(sizeof(ps_t)); - memset(dev, 0x00, sizeof(ps_t)); dev->ctrl = 0x04; dev->lpt = lpt; dev->pcl = true; diff --git a/src/printer/prt_text.c b/src/printer/prt_text.c index ddf9faf53..e04ef9680 100644 --- a/src/printer/prt_text.c +++ b/src/printer/prt_text.c @@ -421,11 +421,9 @@ read_status(void *priv) static void * prnt_init(void *lpt) { - prnt_t *dev; - /* Initialize a device instance. */ - dev = (prnt_t *) malloc(sizeof(prnt_t)); - memset(dev, 0x00, sizeof(prnt_t)); + prnt_t *dev = (prnt_t *) calloc(1, sizeof(prnt_t)); + dev->ctrl = 0x04; dev->lpt = lpt; diff --git a/src/qt/CMakeLists.txt b/src/qt/CMakeLists.txt index d7ea91f70..c08a03016 100644 --- a/src/qt/CMakeLists.txt +++ b/src/qt/CMakeLists.txt @@ -189,6 +189,7 @@ add_library(ui STATIC qt_mediahistorymanager.hpp ../qt_resources.qrc + ./qdarkstyle/dark/darkstyle.qrc ) if(RTMIDI) @@ -203,6 +204,7 @@ if(WIN32) enable_language(RC) target_sources(86Box PUBLIC 86Box-qt.rc) target_sources(plat PRIVATE win_dynld.c) + target_link_libraries(86Box dwmapi) # CMake 3.22 messed this up for clang/clang++ # See https://gitlab.kitware.com/cmake/cmake/-/issues/22611 diff --git a/src/qt/dummy_cdrom_ioctl.c b/src/qt/dummy_cdrom_ioctl.c index fb0224bc6..bddfabb5b 100644 --- a/src/qt/dummy_cdrom_ioctl.c +++ b/src/qt/dummy_cdrom_ioctl.c @@ -17,241 +17,226 @@ * Copyright 2023 Miran Grca. */ #include +#ifdef ENABLE_IOCTL_LOG #include +#endif #include #include #include #include #include #define HAVE_STDARG_H -#include <86box/86box.h> #include <86box/scsi_device.h> #include <86box/cdrom.h> +#include <86box/log.h> #include <86box/plat_unused.h> -#include <86box/plat_cdrom.h> +#include <86box/plat_cdrom_ioctl.h> /* 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) -typedef struct dummy_cdrom_ioctl_t { - int toc_valid; -} dummy_cdrom_ioctl_t; +typedef struct ioctl_t { + cdrom_t *dev; + void *log; + void *handle; + char path[256]; +} ioctl_t; -#ifdef ENABLE_DUMMY_CDROM_IOCTL_LOG -int dummy_cdrom_ioctl_do_log = ENABLE_DUMMY_CDROM_IOCTL_LOG; +#ifdef ENABLE_IOCTL_LOG +int ioctl_do_log = ENABLE_IOCTL_LOG; void -dummy_cdrom_ioctl_log(const char *fmt, ...) +ioctl_log(void *priv, const char *fmt, ...) { - va_list ap; - - if (dummy_cdrom_ioctl_do_log) { + if (ioctl_do_log) { + va_list ap; va_start(ap, fmt); - pclog_ex(fmt, ap); + log_out(priv, fmt, ap); va_end(ap); } } #else -# define dummy_cdrom_ioctl_log(fmt, ...) +# define ioctl_log(priv, fmt, ...) #endif -static int -plat_cdrom_open(void *local) +/* Internal functions. */ +static void +ioctl_close_handle(UNUSED(const ioctl_t *ioctl)) { - return 0; } static int -plat_cdrom_load(void *local) +ioctl_open_handle(UNUSED(ioctl_t *ioctl)) { return 0; } static void -plat_cdrom_read_toc(void *local) +ioctl_read_toc(ioctl_t *ioctl) { - dummy_cdrom_ioctl_t *ioctl = (dummy_cdrom_ioctl_t *) local; - - if (!ioctl->toc_valid) - ioctl->toc_valid = 1; } -void -plat_cdrom_get_raw_track_info(UNUSED(void *local), int *num, raw_track_info_t *rti) +/* Shared functions. */ +static int +ioctl_get_track_info(UNUSED(const void *local), UNUSED(const uint32_t track), + UNUSED(int end), UNUSED(track_info_t *ti)) +{ + return 0; +} + +static void +ioctl_get_raw_track_info(UNUSED(const void *local), int *num, uint8_t *rti) { *num = 1; memset(rti, 0x00, 11); } -int -plat_cdrom_is_track_audio(void *local, uint32_t sector) +static int +ioctl_is_track_pre(const void *local, UNUSED(const uint32_t sector)) { - dummy_cdrom_ioctl_t *ioctl = (dummy_cdrom_ioctl_t *) local; + ioctl_t *ioctl = (ioctl_t *) local; - plat_cdrom_read_toc(ioctl); - - const int ret = 0; - - dummy_cdrom_ioctl_log("plat_cdrom_is_track_audio(%08X): %i\n", sector, ret); - - return ret; -} - -int -plat_cdrom_is_track_pre(void *local, uint32_t sector) -{ - dummy_cdrom_ioctl_t *ioctl = (dummy_cdrom_ioctl_t *) local; - - plat_cdrom_read_toc(ioctl); + ioctl_read_toc(ioctl); const int ret = 0; - dummy_cdrom_ioctl_log("plat_cdrom_is_track_audio(%08X): %i\n", sector, ret); + ioctl_log("ioctl_is_track_audio(%08X): %i\n", sector, ret); return ret; } -uint32_t -plat_cdrom_get_track_start(void *local, uint32_t sector, uint8_t *attr, uint8_t *track) +static int +ioctl_read_sector(const void *local, UNUSED(uint8_t *buffer), UNUSED(uint32_t const sector)) { - dummy_cdrom_ioctl_t *ioctl = (dummy_cdrom_ioctl_t *) local; + ioctl_t *ioctl = (ioctl_t *) local; - plat_cdrom_read_toc(ioctl); + ioctl_open_handle(ioctl); - return 0x00000000; -} + ioctl_close_handle(ioctl); -uint32_t -plat_cdrom_get_last_block(void *local) -{ - dummy_cdrom_ioctl_t *ioctl = (dummy_cdrom_ioctl_t *) local; - - plat_cdrom_read_toc(ioctl); - - return 0x00000000; -} - -int -plat_cdrom_ext_medium_changed(UNUSED(void *local)) -{ -#if 0 - dummy_cdrom_ioctl_t *ioctl = (dummy_cdrom_ioctl_t *) local; - - plat_cdrom_read_toc(ioctl); -#endif - - int ret = 0; - - dummy_cdrom_ioctl_log("plat_cdrom_ext_medium_changed(): %i\n", ret); - - return ret; -} - -/* This replaces both Info and EndInfo, they are specified by a variable. */ -int -plat_cdrom_get_audio_track_info(void *local, UNUSED(int end), int track, int *track_num, TMSF *start, uint8_t *attr) -{ - dummy_cdrom_ioctl_t *ioctl = (dummy_cdrom_ioctl_t *) local; - - plat_cdrom_read_toc(ioctl); - - if ((track < 1) || (track == 0xaa)) { - dummy_cdrom_ioctl_log("plat_cdrom_get_audio_track_info(%02i)\n", track); - return 0; - } - - start->min = 0; - start->sec = 0; - start->fr = 2; - - *track_num = 1; - *attr = 0x14; - - dummy_cdrom_ioctl_log("plat_cdrom_get_audio_track_info(%02i): %02i:%02i:%02i, %02i, %02X\n", - track, start->min, start->sec, start->fr, *track_num, *attr); - - return 1; -} - -/* TODO: See if track start is adjusted by 150 or not. */ -int -plat_cdrom_get_audio_sub(UNUSED(void *local), UNUSED(uint32_t sector), uint8_t *attr, uint8_t *track, uint8_t *index, - TMSF *rel_pos, TMSF *abs_pos) -{ - *track = 1; - *attr = 0x14; - *index = 1; - - rel_pos->min = 0; - rel_pos->sec = 0; - rel_pos->fr = 0; - abs_pos->min = 0; - abs_pos->sec = 0; - abs_pos->fr = 2; - - dummy_cdrom_ioctl_log("plat_cdrom_get_audio_sub(): %02i, %02X, %02i, %02i:%02i:%02i, %02i:%02i:%02i\n", - *track, *attr, *index, rel_pos->min, rel_pos->sec, rel_pos->fr, abs_pos->min, abs_pos->sec, abs_pos->fr); - - return 1; -} - -int -plat_cdrom_get_sector_size(UNUSED(void *local), UNUSED(uint32_t sector)) -{ - dummy_cdrom_ioctl_log("BytesPerSector=2048\n"); - - return 2048; -} - -int -plat_cdrom_read_sector(void *local, uint8_t *buffer, uint32_t sector) -{ - dummy_cdrom_ioctl_t *ioctl = (dummy_cdrom_ioctl_t *) local; - - plat_cdrom_open(ioctl); - - /* Raw */ - dummy_cdrom_ioctl_log("Raw\n"); - - plat_cdrom_close(ioctl); - - dummy_cdrom_ioctl_log("ReadSector sector=%d.\n", sector); + ioctl_log("ReadSector sector=%d.\n", sector); return 0; } -void -plat_cdrom_eject(void *local) +static uint8_t +ioctl_get_track_type(UNUSED(const void *local), UNUSED(const uint32_t sector)) { - dummy_cdrom_ioctl_t *ioctl = (dummy_cdrom_ioctl_t *) local; - - plat_cdrom_open(ioctl); - plat_cdrom_close(ioctl); + return 0x00; } -void -plat_cdrom_close(UNUSED(void *local)) +static uint32_t +ioctl_get_last_block(const void *local) { + ioctl_t *ioctl = (ioctl_t *) local; + + ioctl_read_toc(ioctl); + + return 0x00000000; } -int -plat_cdrom_set_drive(void *local, const char *drv) +static int +ioctl_read_dvd_structure(UNUSED(const void *local), UNUSED(const uint8_t layer), UNUSED(const uint8_t format), + UNUSED(uint8_t *buffer), UNUSED(uint32_t *info)) { - dummy_cdrom_ioctl_t *ioctl = (dummy_cdrom_ioctl_t *) local; + return -0x00052100; +} - plat_cdrom_close(ioctl); +static int +ioctl_is_dvd(UNUSED(const void *local)) +{ + return 0; +} - ioctl->toc_valid = 0; - - plat_cdrom_load(ioctl); +static int +ioctl_has_audio(UNUSED(const void *local)) +{ + return 0; +} +static int +ioctl_is_empty(const void *local) +{ return 1; } -int -plat_cdrom_get_local_size(void) +static int +ioctl_ext_medium_changed(UNUSED(void *local)) { - return sizeof(dummy_cdrom_ioctl_t); +#if 0 + ioctl_t *ioctl = (ioctl_t *) local; +#endif + int ret = 0; + + ioctl_log("ioctl_ext_medium_changed(): %i\n", ret); + + return ret; +} + +static void +ioctl_close(void *local) +{ + ioctl_t *ioctl = (ioctl_t *) local; + + ioctl_close_handle(ioctl); + ioctl->handle = NULL; + + ioctl_log(ioctl->log, "Log closed\n"); + + log_close(ioctl->log); + ioctl->log = NULL; +} + +static void +ioctl_load(const void *local) +{ + const ioctl_t *ioctl = (const ioctl_t *) local; + + if (ioctl_open_handle((ioctl_t *) ioctl)) { + ioctl_close_handle((ioctl_t *) ioctl); + + ioctl_read_toc((ioctl_t *) ioctl); + } +} + +static const cdrom_ops_t ioctl_ops = { + ioctl_get_track_info, + ioctl_get_raw_track_info, + ioctl_is_track_pre, + ioctl_read_sector, + ioctl_get_track_type, + ioctl_get_last_block, + ioctl_read_dvd_structure, + ioctl_is_dvd, + ioctl_has_audio, + ioctl_is_empty, + ioctl_close, + ioctl_load +}; + +/* Public functions. */ +void * +ioctl_open(cdrom_t *dev, const char *drv) +{ + ioctl_t *ioctl = (ioctl_t *) calloc(1, sizeof(ioctl_t)); + + if (ioctl != NULL) { + char n[1024] = { 0 }; + + sprintf(n, "CD-ROM %i IOCtl", dev->id + 1); + ioctl->log = log_open(n); + + memset(ioctl->path, 0x00, sizeof(ioctl->path)); + + sprintf(ioctl->path, "%s", drv); + ioctl_log(ioctl->log, "Path is %s\n", ioctl->path); + + ioctl->dev = dev; + + dev->ops = &ioctl_ops; + } + + return ioctl; } diff --git a/src/qt/languages/86box.pot b/src/qt/languages/86box.pot index c427d1300..ac2db7d07 100644 --- a/src/qt/languages/86box.pot +++ b/src/qt/languages/86box.pot @@ -687,7 +687,10 @@ msgstr "" msgid "Video card \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." msgstr "" -msgid "Video card #2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." +msgid "Video card #2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Disabling the second video card." +msgstr "" + +msgid "Device \"%hs\" is not available due to missing ROMs. Ignoring the device." msgstr "" msgid "Machine" diff --git a/src/qt/languages/ca-ES.po b/src/qt/languages/ca-ES.po index cf0556c36..e49ab3223 100644 --- a/src/qt/languages/ca-ES.po +++ b/src/qt/languages/ca-ES.po @@ -376,7 +376,7 @@ msgid "Time synchronization" msgstr "Sincronització horària" msgid "Disabled" -msgstr "Desactuvat" +msgstr "Deshabilitat" msgid "Enabled (local time)" msgstr "Activat (hora local)" @@ -687,8 +687,11 @@ msgstr "La màquina \"%hs\" no està disponible perquè falten ROM al directori msgid "Video card \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." msgstr "La targeta de vídeo \"%hs\" no està disponible perquè falten ROM al directori roms/video. Canvi a una targeta de vídeo disponible." -msgid "Video card #2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." -msgstr "La targeta de vídeo 2 \"%hs\" no està disponible perquè falten ROM al directori roms/video. Canvi a una targeta de vídeo disponible." +msgid "Video card #2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Disabling the second video card." +msgstr "La targeta de vídeo 2 \"%hs\" no està disponible perquè falten ROM al directori roms/video. Deshabilitant la segona targeta de vídeo." + +msgid "Device \"%hs\" is not available due to missing ROMs. Ignoring the device." +msgstr "El dispositiu \"%hs\" no està disponible perquè falten ROM. Ignorant el dispositiu." msgid "Machine" msgstr "Màquina" @@ -2120,3 +2123,9 @@ msgstr "Clon IBM 8514/A (ISA)" msgid "Vendor" msgstr "Frabricant" + +msgid "Generic PC/XT Memory Expansion" +msgstr "Expansió de memòria genèrica PC/XT" + +msgid "Generic PC/AT Memory Expansion" +msgstr "Expansió de memòria genèrica PC/AT" diff --git a/src/qt/languages/cs-CZ.po b/src/qt/languages/cs-CZ.po index 070c8a0df..cafadd63b 100644 --- a/src/qt/languages/cs-CZ.po +++ b/src/qt/languages/cs-CZ.po @@ -687,8 +687,11 @@ msgstr "Počítač \"%hs\" není dostupný, jelikož chybí obraz jeho paměti R msgid "Video card \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." msgstr "Video adaptér \"%hs\" není dostupný, jelikož chybí obraz jeho paměti ROM ve složce \"roms/video\". Konfigurace se přepne na jiný dostupný adaptér." -msgid "Video card #2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." -msgstr "Video adaptér 2 \"%hs\" není dostupný, jelikož chybí obraz jeho paměti ROM ve složce \"roms/video\". Konfigurace se přepne na jiný dostupný adaptér." +msgid "Video card #2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Disabling the second video card." +msgstr "Video adaptér 2 \"%hs\" není dostupný, jelikož chybí obraz jeho paměti ROM ve složce \"roms/video\". Druhá grafická karta se zakáže." + +msgid "Device \"%hs\" is not available due to missing ROMs. Ignoring the device." +msgstr "Zařízení \"%hs\" není dostupné, jelikož chybí obraz jeho paměti ROM. Zařízení je ignorováno." msgid "Machine" msgstr "Počítač" @@ -2120,3 +2123,9 @@ msgstr "Klon IBM 8514/A (ISA)" msgid "Vendor" msgstr "Výrobce" + +msgid "Generic PC/XT Memory Expansion" +msgstr "Obecné rozšíření paměti PC/XT" + +msgid "Generic PC/AT Memory Expansion" +msgstr "Obecné rozšíření paměti PC/AT" diff --git a/src/qt/languages/de-DE.po b/src/qt/languages/de-DE.po index e94b8ebf4..aa666cc48 100644 --- a/src/qt/languages/de-DE.po +++ b/src/qt/languages/de-DE.po @@ -687,8 +687,11 @@ msgstr "Das System \"%hs\" ist aufgrund von fehlenden ROMs im Verzeichnis roms/m msgid "Video card \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." msgstr "Die Videokarte \"%hs\" ist aufgrund von fehlenden ROMs im Verzeichnis roms/video nicht verfügbar. Es wird auf eine verfügbare Videokarte gewechselt." -msgid "Video card #2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." -msgstr "Die Videokarte 2 \"%hs\" ist aufgrund von fehlenden ROMs im Verzeichnis roms/video nicht verfügbar. Es wird auf eine verfügbare Videokarte gewechselt." +msgid "Video card #2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Disabling the second video card." +msgstr "Das Gerät \"%hs\" ist aufgrund von fehlenden ROMs nicht verfügbar. Es wird ignoriert." + +msgid "Device \"%hs\" is not available due to missing ROMs. Ignoring the device." +msgstr "Die Videokarte 2 \"%hs\" ist aufgrund von fehlenden ROMs im Verzeichnis roms/video nicht verfügbar. Es wird deaktiviert." msgid "Machine" msgstr "System" @@ -2123,3 +2126,9 @@ msgstr "IBM 8514/A-Klon (ISA)" msgid "Vendor" msgstr "Hersteller" + +msgid "Generic PC/XT Memory Expansion" +msgstr "Generische PC/XT-Speichererweiterung" + +msgid "Generic PC/AT Memory Expansion" +msgstr "Generische PC/AT-Speichererweiterung" diff --git a/src/qt/languages/es-ES.po b/src/qt/languages/es-ES.po index 7a457b225..5cac8968f 100644 --- a/src/qt/languages/es-ES.po +++ b/src/qt/languages/es-ES.po @@ -687,8 +687,11 @@ msgstr "La máquina \"%hs\" no está disponible debido a ROMs faltantes en el di msgid "Video card \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." msgstr "La tarjeta de vídeo \"%hs\" no está disponible debido a ROMs faltantes en el directorio roms/machines. Cambiando a una tarjeta de vídeo disponible." -msgid "Video card #2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." -msgstr "La tarjeta de vídeo 2 \"%hs\" no está disponible debido a ROMs faltantes en el directorio roms/machines. Cambiando a una tarjeta de vídeo disponible." +msgid "Video card #2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Disabling the second video card." +msgstr "La tarjeta de vídeo 2 \"%hs\" no está disponible debido a ROMs faltantes en el directorio roms/machines. Deshabilitanto la segunda tarjeta de vídeo." + +msgid "Device \"%hs\" is not available due to missing ROMs. Ignoring the device." +msgstr "El dispositivo \"%hs\" no está disponible debido a ROMs faltantes. Ignorando el dispositivo." msgid "Machine" msgstr "Máquina" @@ -2119,3 +2122,9 @@ msgstr "Clon IBM 8514/A (ISA)" msgid "Vendor" msgstr "Fabricante" + +msgid "Generic PC/XT Memory Expansion" +msgstr "Expansión de Memoria Generica PC/XT" + +msgid "Generic PC/AT Memory Expansion" +msgstr "Expansión de Memoria Generica PC/AT" diff --git a/src/qt/languages/fi-FI.po b/src/qt/languages/fi-FI.po index 6aa71a867..21dcfd1bc 100644 --- a/src/qt/languages/fi-FI.po +++ b/src/qt/languages/fi-FI.po @@ -682,13 +682,16 @@ msgid "Surface images" msgstr "Pintalevykuvat" msgid "Machine \"%hs\" is not available due to missing ROMs in the roms/machines directory. Switching to an available machine." -msgstr "Konetta \"%hs\" ei voi käyttää puuttuvien ROM-tiedostojen vuoksi. Vaihdetaan käyttökelpoiseen koneeseen." +msgstr "Konetta \"%hs\" ei voi käyttää, koska roms/machines-hakemistosta puuttuvien ROM-tiedostojen vuoksi. Vaihdetaan käyttökelpoiseen koneeseen." msgid "Video card \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." -msgstr "Näytönohjainta \"%hs\" ei voi käyttää puuttuvien ROM-tiedostojen vuoksi. Vaihdetaan käyttökelpoiseen näytönohjaimeen." +msgstr "Näytönohjainta \"%hs\" ei voi käyttää, koska roms/machines-hakemistosta puuttuvien ROM-tiedostojen vuoksi. Vaihdetaan käyttökelpoiseen näytönohjaimeen." -msgid "Video card 2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." -msgstr "Näytönohjainta 2 \"%hs\" ei voi käyttää puuttuvien ROM-tiedostojen vuoksi. Vaihdetaan käyttökelpoiseen näytönohjaimeen." +msgid "Video card #2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." +msgstr "Näytönohjainta 2 \"%hs\" ei voi käyttää, koska roms/machines-hakemistosta puuttuvien ROM-tiedostojen vuoksi. Toisen näytönohjaimen poistaminen käytöstä." + +msgid "Device \"%hs\" is not available due to missing ROMs. Ignoring the device." +msgstr "Laite \"%hs\" ei voi käyttää puuttuvien ROM-tiedostojen vuoksi. Laitteen huomiotta jättäminen." msgid "Machine" msgstr "Tietokone" @@ -2120,3 +2123,9 @@ msgstr "IBM 8514/A-klooni (ISA)" msgid "Vendor" msgstr "Valmistaja" + +msgid "Generic PC/XT Memory Expansion" +msgstr "Yleinen PC/XT-muistilaajennus" + +msgid "Generic PC/AT Memory Expansion" +msgstr "Yleinen PC/AT-muistilaajennus" diff --git a/src/qt/languages/fr-FR.po b/src/qt/languages/fr-FR.po index c8e4aa6cd..ff8a5168f 100644 --- a/src/qt/languages/fr-FR.po +++ b/src/qt/languages/fr-FR.po @@ -687,8 +687,11 @@ msgstr "La machine \"%hs\" n'est pas disponible en raison de l'absence de ROMs d msgid "Video card \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." msgstr "La carte vidéo \"%hs\" n'est pas disponible en raison de l'absence de ROMs dans le répertoire roms/video. Basculer vers une carte vidéo disponible." -msgid "Video card #2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." -msgstr "La carte vidéo 2 \"%hs\" n'est pas disponible en raison de l'absence de ROMs dans le répertoire roms/video. Basculer vers une carte vidéo disponible." +msgid "Video card #2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Disabling the second video card." +msgstr "La carte vidéo 2 \"%hs\" n'est pas disponible en raison de l'absence de ROMs dans le répertoire roms/video. Désactiver la deuxième carte vidéo." + +msgid "Device \"%hs\" is not available due to missing ROMs. Ignoring the device." +msgstr "Le dispositif \"%hs\" n'est pas disponible en raison de l'absence de ROMs. Ignorer le dispositif." msgid "Machine" msgstr "Machine" @@ -2120,3 +2123,9 @@ msgstr "Clon IBM 8514/A (ISA)" msgid "Vendor" msgstr "Fabricant" + +msgid "Generic PC/XT Memory Expansion" +msgstr "Expansion de la mémoire générique PC/XT" + +msgid "Generic PC/AT Memory Expansion" +msgstr "Expansion de la mémoire générique PC/AT" diff --git a/src/qt/languages/hr-HR.po b/src/qt/languages/hr-HR.po index c1c76f468..9d242f8e0 100644 --- a/src/qt/languages/hr-HR.po +++ b/src/qt/languages/hr-HR.po @@ -687,8 +687,11 @@ msgstr "Sistem \"%hs\" nije dostupan jer ne postoje potrebni ROM-ovi u mapu roms msgid "Video card \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." msgstr "Video kartica \"%hs\" nije dostupna jer ne postoje potrebni ROM-ovi u mapu roms/video. Prebacivanje na dostupnu video karticu." -msgid "Video card #2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." -msgstr "Video kartica 2 \"%hs\" nije dostupna jer ne postoje potrebni ROM-ovi u mapu roms/video. Prebacivanje na dostupnu video karticu." +msgid "Video card #2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Disabling the second video card." +msgstr "Video kartica 2 \"%hs\" nije dostupna jer ne postoje potrebni ROM-ovi u mapu roms/video. Isključivanje druge video karice." + +msgid "Device \"%hs\" is not available due to missing ROMs. Ignoring the device." +msgstr "Uređaj \"%hs\" nije dostupan jer ne postoje potrebni ROM-ovi. Ignoriranje uređaja." msgid "Machine" msgstr "Sistem" @@ -2120,3 +2123,9 @@ msgstr "Klon IBM 8514/A (ISA)" msgid "Vendor" msgstr "Proizvođać" + +msgid "Generic PC/XT Memory Expansion" +msgstr "Generičko proširenje memorije PC/XT" + +msgid "Generic PC/AT Memory Expansion" +msgstr "Generičko proširenje memorije PC/AT" diff --git a/src/qt/languages/hu-HU.po b/src/qt/languages/hu-HU.po index 732a75df7..2b5adacf4 100644 --- a/src/qt/languages/hu-HU.po +++ b/src/qt/languages/hu-HU.po @@ -687,8 +687,11 @@ msgstr "A számítógép \"%hs\" nem elérhető a \"roms/machines\" mappából h msgid "Video card \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." msgstr "A videokártya \"%hs\" nem elérhető a \"roms/video\" mappából hiányzó ROM-képek miatt. Ehelyett egy másik kártya kerül futtatásra." -msgid "Video card #2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." -msgstr "A videokártya 2 \"%hs\" nem elérhető a \"roms/video\" mappából hiányzó ROM-képek miatt. Ehelyett egy másik kártya kerül futtatásra." +msgid "Video card #2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Disabling the second video card." +msgstr "A videokártya 2 \"%hs\" nem elérhető a \"roms/video\" mappából hiányzó ROM-képek miatt. A második videokártya kerül letiltásra." + +msgid "Device \"%hs\" is not available due to missing ROMs. Ignoring the device." +msgstr "Az eszköz \"%hs\" nem elérhető a hiányzó ROM-képek miatt. Az eszköz figyelmen kívül marad." msgid "Machine" msgstr "Számítógép" @@ -2120,3 +2123,9 @@ msgstr "IBM 8514/A klón (ISA)" msgid "Vendor" msgstr "Gyártó" + +msgid "Generic PC/XT Memory Expansion" +msgstr "Általános PC/XT memóriabővítők" + +msgid "Generic PC/AT Memory Expansion" +msgstr "Általános PC/AT memóriabővítők" diff --git a/src/qt/languages/it-IT.po b/src/qt/languages/it-IT.po index 088b625af..c9af80127 100644 --- a/src/qt/languages/it-IT.po +++ b/src/qt/languages/it-IT.po @@ -687,6 +687,12 @@ msgstr "La macchina \"%hs\" non è disponibile a causa di immagini ROM mancanti msgid "Video card \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." msgstr "La scheda video \"%hs\" non è disponibile a causa di immagini ROM mancanti nella directory roms/video. Cambiando ad una scheda video disponibile." +msgid "Video card #2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Disabling the second video card." +msgstr "La scheda video 2 \"%hs\" non è disponibile a causa di immagini ROM mancanti nella directory roms/video. Disabilitando la seconda scheda video." + +msgid "Device \"%hs\" is not available due to missing ROMs. Ignoring the device." +msgstr "Il dispositivo \"%hs\" non è disponibile a causa di immagini ROM mancanti. Ignorando il dispositivo." + msgid "Machine" msgstr "Piastra madre" @@ -2117,3 +2123,9 @@ msgstr "Clone IBM 8514/A(ISA)" msgid "Vendor" msgstr "Fabricante" + +msgid "Generic PC/XT Memory Expansion" +msgstr "Espansione di memoria generica PC/XT" + +msgid "Generic PC/AT Memory Expansion" +msgstr "Espansione di memoria generica PC/AT" diff --git a/src/qt/languages/ja-JP.po b/src/qt/languages/ja-JP.po index 8ad510745..9a3289b51 100644 --- a/src/qt/languages/ja-JP.po +++ b/src/qt/languages/ja-JP.po @@ -687,8 +687,11 @@ msgstr "roms/machines ディレクトリにROMがないため、マシン「%hs msgid "Video card \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." msgstr "roms/video ディレクトリにROMがないため、ビデオ カード「%hs」は使用できません。使用可能なビデオカードに切り替えます。" -msgid "Video card 2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." -msgstr "roms/video ディレクトリにROMがないため、ビデオ カード2「%hs」は使用できません。使用可能なビデオカードに切り替えます。" +msgid "Video card #2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Disabling the second video card." +msgstr "roms/video ディレクトリにROMがないため、ビデオ カード2「%hs」は使用できません。2枚目のビデオカードを無効にします。" + +msgid "Device \"%hs\" is not available due to missing ROMs. Ignoring the device." +msgstr "ROMがないため、デバイス「%hs」は使用できません。装置を無視する。" msgid "Machine" msgstr "マシン" @@ -2120,3 +2123,9 @@ msgstr "IBM 8514/A クローン(ISA)" msgid "Vendor" msgstr "業者" + +msgid "Generic PC/XT Memory Expansion" +msgstr "汎用PC/XTメモリ拡張カード" + +msgid "Generic PC/AT Memory Expansion" +msgstr "汎用PC/ATメモリ拡張カード" diff --git a/src/qt/languages/ko-KR.po b/src/qt/languages/ko-KR.po index 485789f56..c6928ad43 100644 --- a/src/qt/languages/ko-KR.po +++ b/src/qt/languages/ko-KR.po @@ -687,8 +687,11 @@ msgstr "roms/machines 디렉토리에 필요한 롬파일이 없어 기종 \"%hs msgid "Video card \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." msgstr "roms/video 디렉토리에 필요한 롬파일이 없어 비디오 카드 \"%hs\"을(를) 사용할 수 없습니다. 사용 가능한 기종으로 변경합니다." -msgid "Video card 2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." -msgstr "roms/video 디렉토리에 필요한 롬파일이 없어 비디오 카드 2 \"%hs\"을(를) 사용할 수 없습니다. 사용 가능한 기종으로 변경합니다." +msgid "Video card #2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Disabling the second video card." +msgstr "roms/video 디렉토리에 필요한 롬파일이 없어 비디오 카드 2 \"%hs\"을(를) 사용할 수 없습니다. 두 번째 비디오 카드를 비활성화합니다." + +msgid "Device \"%hs\" is not available due to missing ROMs. Ignoring the device." +msgstr "필요한 롬파일이 없어 장치 \"%hs\"을(를) 사용할 수 없습니다. 장치를 무시합니다." msgid "Machine" msgstr "기종" @@ -2120,3 +2123,9 @@ msgstr "IBM 8514/A 클론(ISA)" msgid "Vendor" msgstr "제조사" + +msgid "Generic PC/XT Memory Expansion" +msgstr "일반 PC/XT 메모리 확장 카드" + +msgid "Generic PC/AT Memory Expansion" +msgstr "일반 PC/AT 메모리 확장 카드" diff --git a/src/qt/languages/nl-NL.po b/src/qt/languages/nl-NL.po index b54bc1cb0..27870db90 100644 --- a/src/qt/languages/nl-NL.po +++ b/src/qt/languages/nl-NL.po @@ -687,8 +687,11 @@ msgstr "Machine \"%hs\" is niet beschikbaar door ontbrekende ROMs in de map roms msgid "Video card \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." msgstr "Videokaart \"%hs\" is niet beschikbaar door ontbrekende ROMs in de map roms/video. Overschakel over naar een beschikbare videokaart." -msgid "Video card #2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." -msgstr "Videokaart #2 \"%hs\" is niet beschikbaar door ontbrekende ROMs in de map roms/video. Overschakel over naar een beschikbare videokaart." +msgid "Video card #2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Disabling the second video card." +msgstr "Videokaart #2 \"%hs\" is niet beschikbaar door ontbrekende ROMs in de map roms/video. Uitschakel de tweede videokaart." + +msgid "Device \"%hs\" is not available due to missing ROMs. Ignoring the device." +msgstr "Het apparaat \"%hs\" is niet beschikbaar door ontbrekende ROMs. Negeer het apparaat." msgid "Machine" msgstr "Machine" @@ -2121,12 +2124,6 @@ msgstr "IBM 8514/A-kloon (ISA)" msgid "Vendor" msgstr "Verkoper" -msgid "30 Hz (JMP2 = 1)" -msgstr "30 Hz (JMP2 = 1)" - -msgid "60 Hz (JMP2 = 2)" -msgstr "60 Hz (JMP2 = 2)" - msgid "Generic PC/XT Memory Expansion" msgstr "Generieke PC/XT geheugenuitbreiding" diff --git a/src/qt/languages/pl-PL.po b/src/qt/languages/pl-PL.po index 9fa67bf9e..e42904458 100644 --- a/src/qt/languages/pl-PL.po +++ b/src/qt/languages/pl-PL.po @@ -687,8 +687,11 @@ msgstr "Maszyna \"%hs\" nie jest dostępna, ponieważ brakuje obrazów ROM w kat msgid "Video card \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." msgstr "Karta wideo \"%hs\" nie jest dostępna, ponieważ brakuje obrazów ROM w katalogu roms/video. Przełączanie na dostępną kartę wideo." -msgid "Video card 2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." -msgstr "Karta wideo 2 \"%hs\" nie jest dostępna, ponieważ brakuje obrazów ROM w katalogu roms/video. Przełączanie na dostępną kartę wideo." +msgid "Video card #2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Disabling the second video card." +msgstr "Karta wideo 2 \"%hs\" nie jest dostępna, ponieważ brakuje obrazów ROM w katalogu roms/video. Wyłączenie drugiej karty graficznej." + +msgid "Device \"%hs\" is not available due to missing ROMs. Ignoring the device." +msgstr "Urządzenie \"%hs\" nie jest dostępne, ponieważ brakuje obrazów ROM. Ignorowanie urządzenia." msgid "Machine" msgstr "Maszyna" @@ -871,10 +874,10 @@ msgid "Invalid configuration" msgstr "Nieprawidłowa konfiguracja" msgid "%1 is required for automatic conversion of PostScript files to PDF.\n\nAny documents sent to the generic PostScript printer will be saved as PostScript (.ps) files." -msgstr "%1 jest wymagany do automatycznej konwersji plików PostScript do PDF.\n\nDokumenty wysłane do ogólnej drukarki PostScript zostaną zapisane jako pliki PostScript (.ps)." +msgstr "%1 jest wymagany do automatycznej konwersji plików PostScript do PDF.\n\nDokumenty wysłane do generycznej drukarki PostScript zostaną zapisane jako pliki PostScript (.ps)." msgid "%1 is required for automatic conversion of PCL files to PDF.\n\nAny documents sent to the generic PCL printer will be saved as Printer Command Language (.pcl) files." -msgstr "%1 jest wymagany do automatycznej konwersji plików PCL do PDF.\n\nDokumenty wysłane do ogólnej drukarki PCL zostaną zapisane jako pliki Printer Command Language (.pcl)." +msgstr "%1 jest wymagany do automatycznej konwersji plików PCL do PDF.\n\nDokumenty wysłane do generycznej drukarki PCL zostaną zapisane jako pliki Printer Command Language (.pcl)." msgid "Entering fullscreen mode" msgstr "Przechodzenie do trybu pełnoekranowego" @@ -1942,7 +1945,7 @@ msgid "New" msgstr "Nowość" msgid "Color (generic)" -msgstr "Kolor (ogólny)" +msgstr "Kolor (generyczny)" msgid "Green Monochrome" msgstr "Zielony monochromatyczny" @@ -2056,16 +2059,16 @@ msgid "Stereo LPT DAC" msgstr "Stereofoniczny przetwornik cyfrowo-analogowy LPT" msgid "Generic Text Printer" -msgstr "Ogólna drukarka tekstowa" +msgstr "Generyczna drukarka tekstowa" msgid "Generic ESC/P Dot-Matrix Printer" msgstr "Generyczna drukarka igłowa ESC/P" msgid "Generic PostScript Printer" -msgstr "Ogólna drukarka PostScript" +msgstr "Generyczna drukarka PostScript" msgid "Generic PCL5e Printer" -msgstr "Drukarka PCL5e" +msgstr "Generyczna drukarka PCL5e" msgid "Parallel Line Internet Protocol" msgstr "Protokół internetowy linii równoległej" @@ -2120,3 +2123,9 @@ msgstr "Klon IBM 8514/A (ISA)" msgid "Vendor" msgstr "Producent" + +msgid "Generic PC/XT Memory Expansion" +msgstr "Generyczne rozszerzenie pamięci PC/XT" + +msgid "Generic PC/AT Memory Expansion" +msgstr "Generyczne rozszerzenie pamięci PC/AT" diff --git a/src/qt/languages/pt-BR.po b/src/qt/languages/pt-BR.po index c9ff9615b..de1bcd544 100644 --- a/src/qt/languages/pt-BR.po +++ b/src/qt/languages/pt-BR.po @@ -687,8 +687,11 @@ msgstr "A máquina \"%hs\" não está disponível devido à falta de ROMs no dir msgid "Video card \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." msgstr "A placa de vídeo \"%hs\" não está disponível devido à falta de ROMs no diretório roms/video. Mudando para uma placa de vídeo disponível." -msgid "Video card #2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." -msgstr "A placa de vídeo 2 \"%hs\" não está disponível devido à falta de ROMs no diretório roms/video. Mudando para uma placa de vídeo disponível." +msgid "Video card #2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Disabling the second video card." +msgstr "A placa de vídeo 2 \"%hs\" não está disponível devido à falta de ROMs no diretório roms/video. Desativando a segunda placa vídeo." + +msgid "Device \"%hs\" is not available due to missing ROMs. Ignoring the device." +msgstr "O dispositivo \"%hs\" não está disponível devido à falta de ROMs. Ignorando o dispositivo." msgid "Machine" msgstr "Máquina" @@ -2121,12 +2124,6 @@ msgstr "Clone IBM 8514/A (ISA)" msgid "Vendor" msgstr "Fabricante" -msgid "30 Hz (JMP2 = 1)" -msgstr "30 Hz (JMP2 = 1)" - -msgid "60 Hz (JMP2 = 2)" -msgstr "60 Hz (JMP2 = 2)" - msgid "Generic PC/XT Memory Expansion" msgstr "Expansão de memória genérica PC/XT" diff --git a/src/qt/languages/pt-PT.po b/src/qt/languages/pt-PT.po index 1494ce1dc..d4c8bf170 100644 --- a/src/qt/languages/pt-PT.po +++ b/src/qt/languages/pt-PT.po @@ -687,8 +687,11 @@ msgstr "A máquina \"%hs\" não está disponível devido à falta de ROMs na pas msgid "Video card \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." msgstr "A placa vídeo \"%hs\" não está disponível devido à falta de ROMs na pasta roms/video. A mudar para uma placa vídeo disponível." -msgid "Video card #2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." -msgstr "A placa vídeo 2 \"%hs\" não está disponível devido à falta de ROMs na pasta roms/video. A mudar para uma placa vídeo disponível." +msgid "Video card #2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Disabling the second video card." +msgstr "A placa vídeo 2 \"%hs\" não está disponível devido à falta de ROMs na pasta roms/video. A desativar a segunda placa vídeo." + +msgid "Device \"%hs\" is not available due to missing ROMs. Ignoring the device." +msgstr "O dispositivo \"%hs\" não está disponível devido à falta de ROMs A ignorar o dispositivo." msgid "Machine" msgstr "Máquina" @@ -2120,3 +2123,9 @@ msgstr "Clone IBM 8514/A (ISA)" msgid "Vendor" msgstr "Fabricante" + +msgid "Generic PC/XT Memory Expansion" +msgstr "Expansão de memória genérica PC/XT" + +msgid "Generic PC/AT Memory Expansion" +msgstr "Expansão de memória genérica PC/AT" diff --git a/src/qt/languages/ru-RU.po b/src/qt/languages/ru-RU.po index 8476090d1..a2e352faa 100644 --- a/src/qt/languages/ru-RU.po +++ b/src/qt/languages/ru-RU.po @@ -687,8 +687,11 @@ msgstr "Системная плата \"%hs\" недоступна из-за о msgid "Video card \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." msgstr "Видеокарта \"%hs\" недоступна из-за отсутствия файла её ПЗУ в каталоге roms/video. Переключение на доступную видеокарту." -msgid "Video card #2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." -msgstr "Видеокарта 2 \"%hs\" недоступна из-за отсутствия файла её ПЗУ в каталоге roms/video. Переключение на доступную видеокарту." +msgid "Video card #2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Disabling the second video card." +msgstr "Видеокарта 2 \"%hs\" недоступна из-за отсутствия файла её ПЗУ в каталоге roms/video. Вторая видеокарта отключена." + +msgid "Device \"%hs\" is not available due to missing ROMs. Ignoring the device." +msgstr "Устройство \"%hs\" недоступно из-за отсутствия файла его ПЗУ. Устройство проигнорировано." msgid "Machine" msgstr "Компьютер" diff --git a/src/qt/languages/sk-SK.po b/src/qt/languages/sk-SK.po index 708c24dd8..6b2074d47 100644 --- a/src/qt/languages/sk-SK.po +++ b/src/qt/languages/sk-SK.po @@ -687,8 +687,11 @@ msgstr "Počítač \"%hs\" ie je dostupný, pretože chýba obraz jeho pamäte R msgid "Video card \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." msgstr "Video adaptér \"%hs\" nie je dostupný, pretože chýba obraz jeho pamäte ROM v zložke \"roms/video\". Konfigurácia sa prepne na iný dostupný adaptér." -msgid "Video card #2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." -msgstr "Video adaptér 2 \"%hs\" nie je dostupný, pretože chýba obraz jeho pamäte ROM v zložke \"roms/video\". Konfigurácia sa prepne na iný dostupný adaptér." +msgid "Video card #2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Disabling the second video card." +msgstr "Video adaptér 2 \"%hs\" nie je dostupný, pretože chýba obraz jeho pamäte ROM v zložke \"roms/video\". Druhá grafická karta sa zakáže." + +msgid "Device \"%hs\" is not available due to missing ROMs. Ignoring the device." +msgstr "Zariadenie \"%hs\" nie je dostupné, pretože chýba obraz jeho pamäte ROM. Zariadenie sa ignoruje." msgid "Machine" msgstr "Počítač" @@ -2120,3 +2123,9 @@ msgstr "Klon IBM 8514/A (ISA)" msgid "Vendor" msgstr "Výrobca" + +msgid "Generic PC/XT Memory Expansion" +msgstr "Všeobecné rozšírenie pamäte PC/XT" + +msgid "Generic PC/AT Memory Expansion" +msgstr "Všeobecné rozšírenie pamäte PC/AT" diff --git a/src/qt/languages/sl-SI.po b/src/qt/languages/sl-SI.po index c9c99d6b2..9d8ccaaf9 100644 --- a/src/qt/languages/sl-SI.po +++ b/src/qt/languages/sl-SI.po @@ -685,10 +685,13 @@ msgid "Machine \"%hs\" is not available due to missing ROMs in the roms/machines msgstr "Sistem \"%hs\" ni na voljo zaradi manjkajočih ROM-ov v mapi roms/machines. Preklapljam na drug sistem, ki je na voljo." msgid "Video card \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." -msgstr "Grafična kartica \"%hs\" ni na voljo zaradi manjkajočih ROM-ov v mapi roms/video. Preklapljam na drugo grafično kartico, ki je na voljo.." +msgstr "Grafična kartica \"%hs\" ni na voljo zaradi manjkajočih ROM-ov v mapi roms/video. Preklapljam na drugo grafično kartico, ki je na voljo." -msgid "Video card #2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." -msgstr "Grafična kartica 2 \"%hs\" ni na voljo zaradi manjkajočih ROM-ov v mapi roms/video. Preklapljam na drugo grafično kartico, ki je na voljo.." +msgid "Video card #2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Disabling the second video card." +msgstr "Grafična kartica 2 \"%hs\" ni na voljo zaradi manjkajočih ROM-ov v mapi roms/video. Onemogočam drugo grafično kartico." + +msgid "Device \"%hs\" is not available due to missing ROMs. Ignoring the device." +msgstr "Naprava \"%hs\" ni na voljo zaradi manjkajočih ROM-ov. Preziram napravo." msgid "Machine" msgstr "Sistem" @@ -2120,3 +2123,9 @@ msgstr "Klon IBM 8514/A (ISA)" msgid "Vendor" msgstr "Proizvajalec" + +msgid "Generic PC/XT Memory Expansion" +msgstr "Generična razširitev pomnilnika PC/XT" + +msgid "Generic PC/AT Memory Expansion" +msgstr "Generična razširitev pomnilnika PC/AT" diff --git a/src/qt/languages/tr-TR.po b/src/qt/languages/tr-TR.po index 3a0cc2b96..288412154 100644 --- a/src/qt/languages/tr-TR.po +++ b/src/qt/languages/tr-TR.po @@ -687,8 +687,11 @@ msgstr "\"%hs\" makinesi roms/machines klasöründe gerekli ROM imajlarının me msgid "Video card \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." msgstr "\"%hs\" ekran kartı roms/video klasöründe gerekli ROM imajlarının mevcut olmaması nedeniyle kullanılamıyor. Bundan dolayı kullanılabilen bir ekran kartına geçiş yapılacaktır." -msgid "Video card #2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." -msgstr "\"%hs\" ikinci ekran kartı roms/video klasöründe gerekli ROM imajlarının mevcut olmaması nedeniyle kullanılamıyor. Bundan dolayı kullanılabilen bir ekran kartına geçiş yapılacaktır." +msgid "Video card #2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Disabling the second video card." +msgstr "\"%hs\" ikinci ekran kartı roms/video klasöründe gerekli ROM imajlarının mevcut olmaması nedeniyle kullanılamıyor. İkinci ekran kartı devre dışı bırakılır." + +msgid "Device \"%hs\" is not available due to missing ROMs. Ignoring the device." +msgstr "\"%hs\" cihazı gerekli ROM imajlarının mevcut olmaması nedeniyle kullanılamıyor. Cihaz yok sayılıyor." msgid "Machine" msgstr "Makine" @@ -2120,3 +2123,9 @@ msgstr "IBM 8514/A klonu (ISA)" msgid "Vendor" msgstr "Üretici" + +msgid "Generic PC/XT Memory Expansion" +msgstr "Sıradan PC/XT bellek artırma" + +msgid "Generic PC/AT Memory Expansion" +msgstr "Sıradan PC/AT bellek artırma" diff --git a/src/qt/languages/uk-UA.po b/src/qt/languages/uk-UA.po index 6cef7c294..5ce59be01 100644 --- a/src/qt/languages/uk-UA.po +++ b/src/qt/languages/uk-UA.po @@ -687,8 +687,11 @@ msgstr "Системна плата \"%hs\" недоступна через ві msgid "Video card \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." msgstr "Відеокарта \"%hs\" недоступна через відсутність файлу її ПЗУ в каталозі roms/video. Переключення на доступну відеокарту." -msgid "Video card #2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." -msgstr "Відеокарта 2 \"%hs\" недоступна через відсутність файлу її ПЗУ в каталозі roms/video. Переключення на доступну відеокарту." +msgid "Video card #2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Disabling the second video card." +msgstr "Відеокарта 2 \"%hs\" недоступна через відсутність файлу її ПЗУ в каталозі roms/video. Відключення другої відеокарти." + +msgid "Device \"%hs\" is not available due to missing ROMs. Ignoring the device." +msgstr "Пристрій \"%hs\" недоступний через відсутність файлу його ПЗУ. Ігнорування пристрою." msgid "Machine" msgstr "Комп'ютер" @@ -2126,3 +2129,9 @@ msgstr "30 Гц (JMP2 = 1)" msgid "60 Hz (JMP2 = 2)" msgstr "60 Гц (JMP2 = 2)" + +msgid "Generic PC/XT Memory Expansion" +msgstr "Загальне розширення пам'яті PC/XT" + +msgid "Generic PC/AT Memory Expansion" +msgstr "Загальне розширення пам'яті PC/AT" diff --git a/src/qt/languages/vi-VN.po b/src/qt/languages/vi-VN.po index 15802fc2d..707c7ae7f 100644 --- a/src/qt/languages/vi-VN.po +++ b/src/qt/languages/vi-VN.po @@ -687,8 +687,11 @@ msgstr "Mẫu máy \"%hs\" không giả lập được do thiếu file ROM tươ msgid "Video card \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." msgstr "Card đồ họa \"%hs\" không giả lập được do thiếu file ROM tương ứng trong mục roms/video. Hãy chọn card đồ họa khác." -msgid "Video card #2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." -msgstr "Card đồ họa 2 \"%hs\" không giả lập được do thiếu file ROM tương ứng trong mục roms/video. Hãy chọn card đồ họa khác." +msgid "Video card #2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Disabling the second video card." +msgstr "Card đồ họa 2 \"%hs\" không giả lập được do thiếu file ROM tương ứng trong mục roms/video. Vô hiệu hóa card đồ họa thứ hai." + +msgid "Device \"%hs\" is not available due to missing ROMs. Ignoring the device." +msgstr "Thiết bị \"%hs\" không giả lập được do thiếu file ROM. Bỏ qua thiết bị." msgid "Machine" msgstr "Mẫu máy" @@ -2120,3 +2123,9 @@ msgstr "IBM 8514/A dòng vô tính (ISA)" msgid "Vendor" msgstr "Nhà sản xuất" + +msgid "Generic PC/XT Memory Expansion" +msgstr "Chung mở rộng bộ nhớ qua PC/XT" + +msgid "Generic PC/AT Memory Expansion" +msgstr "Chung mở rộng bộ nhớ qua PC/AT" diff --git a/src/qt/languages/zh-CN.po b/src/qt/languages/zh-CN.po index 6b659b504..81451b2b3 100644 --- a/src/qt/languages/zh-CN.po +++ b/src/qt/languages/zh-CN.po @@ -687,8 +687,11 @@ msgstr "由于 roms/machines 文件夹中缺少合适的 ROM,机型 \"%hs\" msgid "Video card \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." msgstr "由于 roms/video 文件夹中缺少合适的 ROM,显卡 \"%hs\" 不可用。将切换到其他可用显卡。" -msgid "Video card #2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." -msgstr "由于 roms/video 文件夹中缺少合适的 ROM,显卡 2 \"%hs\" 不可用。将切换到其他可用显卡。" +msgid "Video card #2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Disabling the second video card." +msgstr "由于 roms/video 文件夹中缺少合适的 ROM,显卡 2 \"%hs\" 不可用。禁用第二块显卡。" + +msgid "Device \"%hs\" is not available due to missing ROMs. Ignoring the device." +msgstr "由于缺少合适的 ROM,设备 \"%hs\" 不可用。忽略设备。" msgid "Machine" msgstr "机型" @@ -2120,3 +2123,9 @@ msgstr "IBM 8514/A 克隆 (ISA)" msgid "Vendor" msgstr "制造商" + +msgid "Generic PC/XT Memory Expansion" +msgstr "通用 PC/XT 内存扩展" + +msgid "Generic PC/AT Memory Expansion" +msgstr "通用 PC/AT 内存扩展" diff --git a/src/qt/languages/zh-TW.po b/src/qt/languages/zh-TW.po index f9e917d98..9bf8edfc6 100644 --- a/src/qt/languages/zh-TW.po +++ b/src/qt/languages/zh-TW.po @@ -687,8 +687,11 @@ msgstr "由於 roms/machines 資料夾中缺少合適的 ROM,機型 \"%hs\" msgid "Video card \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." msgstr "由於 roms/video 資料夾中缺少合適的 ROM,顯示卡 \"%hs\" 不可用。將切換到其他可用顯示卡。" -msgid "Video card #2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." -msgstr "由於 roms/video 資料夾中缺少合適的 ROM,顯示卡 2 \"%hs\" 不可用。將切換到其他可用顯示卡。" +msgid "Video card #2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Disabling the second video card." +msgstr "由於 roms/video 資料夾中缺少合適的 ROM,顯示卡 2 \"%hs\" 不可用。禁用第二块显卡。" + +msgid "Device \"%hs\" is not available due to missing ROMs. Ignoring the device." +msgstr "由於缺少合適的 ROM,裝置 \"%hs\" 不可用。忽略设备。" msgid "Machine" msgstr "機型" @@ -2120,3 +2123,9 @@ msgstr "IBM 8514/A 克隆 (ISA)" msgid "Vendor" msgstr "製造商" + +msgid "Generic PC/XT Memory Expansion" +msgstr "通用 PC/XT 記憶體擴充" + +msgid "Generic PC/AT Memory Expansion" +msgstr "通用 PC/AT 記憶體擴充" diff --git a/src/qt/qdarkstyle/dark/darkstyle.qrc b/src/qt/qdarkstyle/dark/darkstyle.qrc new file mode 100644 index 000000000..ce0d85be6 --- /dev/null +++ b/src/qt/qdarkstyle/dark/darkstyle.qrc @@ -0,0 +1,216 @@ + + + + rc/arrow_down.png + rc/arrow_down@2x.png + rc/arrow_down_disabled.png + rc/arrow_down_disabled@2x.png + rc/arrow_down_focus.png + rc/arrow_down_focus@2x.png + rc/arrow_down_pressed.png + rc/arrow_down_pressed@2x.png + rc/arrow_left.png + rc/arrow_left@2x.png + rc/arrow_left_disabled.png + rc/arrow_left_disabled@2x.png + rc/arrow_left_focus.png + rc/arrow_left_focus@2x.png + rc/arrow_left_pressed.png + rc/arrow_left_pressed@2x.png + rc/arrow_right.png + rc/arrow_right@2x.png + rc/arrow_right_disabled.png + rc/arrow_right_disabled@2x.png + rc/arrow_right_focus.png + rc/arrow_right_focus@2x.png + rc/arrow_right_pressed.png + rc/arrow_right_pressed@2x.png + rc/arrow_up.png + rc/arrow_up@2x.png + rc/arrow_up_disabled.png + rc/arrow_up_disabled@2x.png + rc/arrow_up_focus.png + rc/arrow_up_focus@2x.png + rc/arrow_up_pressed.png + rc/arrow_up_pressed@2x.png + rc/base_icon.png + rc/base_icon@2x.png + rc/base_icon_disabled.png + rc/base_icon_disabled@2x.png + rc/base_icon_focus.png + rc/base_icon_focus@2x.png + rc/base_icon_pressed.png + rc/base_icon_pressed@2x.png + rc/branch_closed.png + rc/branch_closed@2x.png + rc/branch_closed_disabled.png + rc/branch_closed_disabled@2x.png + rc/branch_closed_focus.png + rc/branch_closed_focus@2x.png + rc/branch_closed_pressed.png + rc/branch_closed_pressed@2x.png + rc/branch_end.png + rc/branch_end@2x.png + rc/branch_end_disabled.png + rc/branch_end_disabled@2x.png + rc/branch_end_focus.png + rc/branch_end_focus@2x.png + rc/branch_end_pressed.png + rc/branch_end_pressed@2x.png + rc/branch_line.png + rc/branch_line@2x.png + rc/branch_line_disabled.png + rc/branch_line_disabled@2x.png + rc/branch_line_focus.png + rc/branch_line_focus@2x.png + rc/branch_line_pressed.png + rc/branch_line_pressed@2x.png + rc/branch_more.png + rc/branch_more@2x.png + rc/branch_more_disabled.png + rc/branch_more_disabled@2x.png + rc/branch_more_focus.png + rc/branch_more_focus@2x.png + rc/branch_more_pressed.png + rc/branch_more_pressed@2x.png + rc/branch_open.png + rc/branch_open@2x.png + rc/branch_open_disabled.png + rc/branch_open_disabled@2x.png + rc/branch_open_focus.png + rc/branch_open_focus@2x.png + rc/branch_open_pressed.png + rc/branch_open_pressed@2x.png + rc/checkbox_checked.png + rc/checkbox_checked@2x.png + rc/checkbox_checked_disabled.png + rc/checkbox_checked_disabled@2x.png + rc/checkbox_checked_focus.png + rc/checkbox_checked_focus@2x.png + rc/checkbox_checked_pressed.png + rc/checkbox_checked_pressed@2x.png + rc/checkbox_indeterminate.png + rc/checkbox_indeterminate@2x.png + rc/checkbox_indeterminate_disabled.png + rc/checkbox_indeterminate_disabled@2x.png + rc/checkbox_indeterminate_focus.png + rc/checkbox_indeterminate_focus@2x.png + rc/checkbox_indeterminate_pressed.png + rc/checkbox_indeterminate_pressed@2x.png + rc/checkbox_unchecked.png + rc/checkbox_unchecked@2x.png + rc/checkbox_unchecked_disabled.png + rc/checkbox_unchecked_disabled@2x.png + rc/checkbox_unchecked_focus.png + rc/checkbox_unchecked_focus@2x.png + rc/checkbox_unchecked_pressed.png + rc/checkbox_unchecked_pressed@2x.png + rc/line_horizontal.png + rc/line_horizontal@2x.png + rc/line_horizontal_disabled.png + rc/line_horizontal_disabled@2x.png + rc/line_horizontal_focus.png + rc/line_horizontal_focus@2x.png + rc/line_horizontal_pressed.png + rc/line_horizontal_pressed@2x.png + rc/line_vertical.png + rc/line_vertical@2x.png + rc/line_vertical_disabled.png + rc/line_vertical_disabled@2x.png + rc/line_vertical_focus.png + rc/line_vertical_focus@2x.png + rc/line_vertical_pressed.png + rc/line_vertical_pressed@2x.png + rc/radio_checked.png + rc/radio_checked@2x.png + rc/radio_checked_disabled.png + rc/radio_checked_disabled@2x.png + rc/radio_checked_focus.png + rc/radio_checked_focus@2x.png + rc/radio_checked_pressed.png + rc/radio_checked_pressed@2x.png + rc/radio_unchecked.png + rc/radio_unchecked@2x.png + rc/radio_unchecked_disabled.png + rc/radio_unchecked_disabled@2x.png + rc/radio_unchecked_focus.png + rc/radio_unchecked_focus@2x.png + rc/radio_unchecked_pressed.png + rc/radio_unchecked_pressed@2x.png + rc/toolbar_move_horizontal.png + rc/toolbar_move_horizontal@2x.png + rc/toolbar_move_horizontal_disabled.png + rc/toolbar_move_horizontal_disabled@2x.png + rc/toolbar_move_horizontal_focus.png + rc/toolbar_move_horizontal_focus@2x.png + rc/toolbar_move_horizontal_pressed.png + rc/toolbar_move_horizontal_pressed@2x.png + rc/toolbar_move_vertical.png + rc/toolbar_move_vertical@2x.png + rc/toolbar_move_vertical_disabled.png + rc/toolbar_move_vertical_disabled@2x.png + rc/toolbar_move_vertical_focus.png + rc/toolbar_move_vertical_focus@2x.png + rc/toolbar_move_vertical_pressed.png + rc/toolbar_move_vertical_pressed@2x.png + rc/toolbar_separator_horizontal.png + rc/toolbar_separator_horizontal@2x.png + rc/toolbar_separator_horizontal_disabled.png + rc/toolbar_separator_horizontal_disabled@2x.png + rc/toolbar_separator_horizontal_focus.png + rc/toolbar_separator_horizontal_focus@2x.png + rc/toolbar_separator_horizontal_pressed.png + rc/toolbar_separator_horizontal_pressed@2x.png + rc/toolbar_separator_vertical.png + rc/toolbar_separator_vertical@2x.png + rc/toolbar_separator_vertical_disabled.png + rc/toolbar_separator_vertical_disabled@2x.png + rc/toolbar_separator_vertical_focus.png + rc/toolbar_separator_vertical_focus@2x.png + rc/toolbar_separator_vertical_pressed.png + rc/toolbar_separator_vertical_pressed@2x.png + rc/transparent.png + rc/transparent@2x.png + rc/transparent_disabled.png + rc/transparent_disabled@2x.png + rc/transparent_focus.png + rc/transparent_focus@2x.png + rc/transparent_pressed.png + rc/transparent_pressed@2x.png + rc/window_close.png + rc/window_close@2x.png + rc/window_close_disabled.png + rc/window_close_disabled@2x.png + rc/window_close_focus.png + rc/window_close_focus@2x.png + rc/window_close_pressed.png + rc/window_close_pressed@2x.png + rc/window_grip.png + rc/window_grip@2x.png + rc/window_grip_disabled.png + rc/window_grip_disabled@2x.png + rc/window_grip_focus.png + rc/window_grip_focus@2x.png + rc/window_grip_pressed.png + rc/window_grip_pressed@2x.png + rc/window_minimize.png + rc/window_minimize@2x.png + rc/window_minimize_disabled.png + rc/window_minimize_disabled@2x.png + rc/window_minimize_focus.png + rc/window_minimize_focus@2x.png + rc/window_minimize_pressed.png + rc/window_minimize_pressed@2x.png + rc/window_undock.png + rc/window_undock@2x.png + rc/window_undock_disabled.png + rc/window_undock_disabled@2x.png + rc/window_undock_focus.png + rc/window_undock_focus@2x.png + rc/window_undock_pressed.png + rc/window_undock_pressed@2x.png + + + darkstyle.qss + + diff --git a/src/qt/qdarkstyle/dark/darkstyle.qss b/src/qt/qdarkstyle/dark/darkstyle.qss new file mode 100644 index 000000000..6e1ec4b06 --- /dev/null +++ b/src/qt/qdarkstyle/dark/darkstyle.qss @@ -0,0 +1,2214 @@ +/* --------------------------------------------------------------------------- + + WARNING! File created programmatically. All changes made in this file will be lost! + + Created by the qtsass compiler v0.4.0 + + The definitions are in the "qdarkstyle.qss._styles.scss" module + +--------------------------------------------------------------------------- */ +/* Light Style - QDarkStyleSheet ------------------------------------------ */ +/* + +See Qt documentation: + + - https://doc.qt.io/qt-5/stylesheet.html + - https://doc.qt.io/qt-5/stylesheet-reference.html + - https://doc.qt.io/qt-5/stylesheet-examples.html + +--------------------------------------------------------------------------- */ +/* Reset elements ------------------------------------------------------------ + +Resetting everything helps to unify styles across different operating systems + +--------------------------------------------------------------------------- */ + +/* Changed to be fully grayscale. */ + +* { + padding: 0px; + margin: 0px; + border: 0px; + border-style: none; + border-image: none; + outline: 0; +} + +/* specific reset for elements inside QToolBar */ +QToolBar * { + margin: 0px; + padding: 0px; +} + +/* QWidget ---------------------------------------------------------------- + +--------------------------------------------------------------------------- */ +QWidget { + background-color: #272727; + border: 0px solid #525252; + padding: 0px; + color: #E3E3E3; + selection-background-color: #616161; + selection-color: #E3E3E3; +} + +QWidget:disabled { + background-color: #272727; + color: #8B8B8B; + selection-background-color: #444444; + selection-color: #8B8B8B; +} + +QWidget::item:selected { + background-color: #616161; +} + +QWidget::item:hover:!selected { + background-color: #666666; +} + +/* QMainWindow ------------------------------------------------------------ + +This adjusts the splitter in the dock widget, not qsplitter +https://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qmainwindow + +--------------------------------------------------------------------------- */ +QMainWindow::separator { + background-color: #525252; + border: 0px solid #272727; + spacing: 0px; + padding: 2px; +} + +QMainWindow::separator:hover { + background-color: #767676; + border: 0px solid #666666; +} + +QMainWindow::separator:horizontal { + width: 5px; + margin-top: 2px; + margin-bottom: 2px; + image: url(":/qss_icons/dark/rc/toolbar_separator_vertical.png"); +} + +QMainWindow::separator:vertical { + height: 5px; + margin-left: 2px; + margin-right: 2px; + image: url(":/qss_icons/dark/rc/toolbar_separator_horizontal.png"); +} + +/* QToolTip --------------------------------------------------------------- + +https://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qtooltip + +--------------------------------------------------------------------------- */ +QToolTip { + background-color: #616161; + color: #E3E3E3; + /* If you remove the border property, background stops working on Windows */ + border: none; + /* Remove padding, for fix combo box tooltip */ + padding: 0px; + /* Remove opacity, fix #174 - may need to use RGBA */ +} + +/* QStatusBar ------------------------------------------------------------- + +https://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qstatusbar + +--------------------------------------------------------------------------- */ +QStatusBar { + border: 1px solid #272727; + /* Fixes Spyder #9120, #9121 */ + background: #272727; + /* Fixes #205, white vertical borders separating items */ +} + +QStatusBar::item { + border: none; +} + +QStatusBar QToolTip { + background-color: #666666; + border: 1px solid #272727; + color: #272727; + /* Remove padding, for fix combo box tooltip */ + padding: 0px; + /* Reducing transparency to read better */ + opacity: 230; +} + +QStatusBar QLabel { + /* Fixes Spyder #9120, #9121 */ + background: transparent; + padding: 0px; +} + +/* QCheckBox -------------------------------------------------------------- + +https://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qcheckbox + +--------------------------------------------------------------------------- */ +QCheckBox { + background-color: #272727; + color: #E3E3E3; + spacing: 4px; + outline: none; + padding-top: 4px; + padding-bottom: 4px; +} + +QCheckBox:focus { + border: none; +} + +QCheckBox QWidget:disabled { + background-color: #272727; + color: #8B8B8B; +} + +QCheckBox::indicator { + margin-left: 2px; + height: 14px; + width: 14px; +} + +QCheckBox::indicator:unchecked { + image: url(":/qss_icons/dark/rc/checkbox_unchecked.png"); +} + +QCheckBox::indicator:unchecked:hover, QCheckBox::indicator:unchecked:focus, QCheckBox::indicator:unchecked:pressed { + border: none; + image: url(":/qss_icons/dark/rc/checkbox_unchecked_focus.png"); +} + +QCheckBox::indicator:unchecked:disabled { + image: url(":/qss_icons/dark/rc/checkbox_unchecked_disabled.png"); +} + +QCheckBox::indicator:checked { + image: url(":/qss_icons/dark/rc/checkbox_checked.png"); +} + +QCheckBox::indicator:checked:hover, QCheckBox::indicator:checked:focus, QCheckBox::indicator:checked:pressed { + border: none; + image: url(":/qss_icons/dark/rc/checkbox_checked_focus.png"); +} + +QCheckBox::indicator:checked:disabled { + image: url(":/qss_icons/dark/rc/checkbox_checked_disabled.png"); +} + +QCheckBox::indicator:indeterminate { + image: url(":/qss_icons/dark/rc/checkbox_indeterminate.png"); +} + +QCheckBox::indicator:indeterminate:disabled { + image: url(":/qss_icons/dark/rc/checkbox_indeterminate_disabled.png"); +} + +QCheckBox::indicator:indeterminate:focus, QCheckBox::indicator:indeterminate:hover, QCheckBox::indicator:indeterminate:pressed { + image: url(":/qss_icons/dark/rc/checkbox_indeterminate_focus.png"); +} + +/* QGroupBox -------------------------------------------------------------- + +https://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qgroupbox + +--------------------------------------------------------------------------- */ +QGroupBox { + font-weight: bold; + border: 1px solid #525252; + border-radius: 4px; + padding: 2px; + margin-top: 6px; + margin-bottom: 4px; +} + +QGroupBox::title { + subcontrol-origin: margin; + subcontrol-position: top left; + left: 4px; + padding-left: 2px; + padding-right: 4px; + padding-top: -4px; +} + +QGroupBox::indicator { + margin-left: 2px; + margin-top: 2px; + padding: 0; + height: 14px; + width: 14px; +} + +QGroupBox::indicator:unchecked { + border: none; + image: url(":/qss_icons/dark/rc/checkbox_unchecked.png"); +} + +QGroupBox::indicator:unchecked:hover, QGroupBox::indicator:unchecked:focus, QGroupBox::indicator:unchecked:pressed { + border: none; + image: url(":/qss_icons/dark/rc/checkbox_unchecked_focus.png"); +} + +QGroupBox::indicator:unchecked:disabled { + image: url(":/qss_icons/dark/rc/checkbox_unchecked_disabled.png"); +} + +QGroupBox::indicator:checked { + border: none; + image: url(":/qss_icons/dark/rc/checkbox_checked.png"); +} + +QGroupBox::indicator:checked:hover, QGroupBox::indicator:checked:focus, QGroupBox::indicator:checked:pressed { + border: none; + image: url(":/qss_icons/dark/rc/checkbox_checked_focus.png"); +} + +QGroupBox::indicator:checked:disabled { + image: url(":/qss_icons/dark/rc/checkbox_checked_disabled.png"); +} + +/* QRadioButton ----------------------------------------------------------- + +https://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qradiobutton + +--------------------------------------------------------------------------- */ +QRadioButton { + background-color: #272727; + color: #E3E3E3; + spacing: 4px; + padding-top: 4px; + padding-bottom: 4px; + border: none; + outline: none; +} + +QRadioButton:focus { + border: none; +} + +QRadioButton:disabled { + background-color: #272727; + color: #8B8B8B; + border: none; + outline: none; +} + +QRadioButton QWidget { + background-color: #272727; + color: #E3E3E3; + spacing: 0px; + padding: 0px; + outline: none; + border: none; +} + +QRadioButton::indicator { + border: none; + outline: none; + margin-left: 2px; + height: 14px; + width: 14px; +} + +QRadioButton::indicator:unchecked { + image: url(":/qss_icons/dark/rc/radio_unchecked.png"); +} + +QRadioButton::indicator:unchecked:hover, QRadioButton::indicator:unchecked:focus, QRadioButton::indicator:unchecked:pressed { + border: none; + outline: none; + image: url(":/qss_icons/dark/rc/radio_unchecked_focus.png"); +} + +QRadioButton::indicator:unchecked:disabled { + image: url(":/qss_icons/dark/rc/radio_unchecked_disabled.png"); +} + +QRadioButton::indicator:checked { + border: none; + outline: none; + image: url(":/qss_icons/dark/rc/radio_checked.png"); +} + +QRadioButton::indicator:checked:hover, QRadioButton::indicator:checked:focus, QRadioButton::indicator:checked:pressed { + border: none; + outline: none; + image: url(":/qss_icons/dark/rc/radio_checked_focus.png"); +} + +QRadioButton::indicator:checked:disabled { + outline: none; + image: url(":/qss_icons/dark/rc/radio_checked_disabled.png"); +} + +/* QMenuBar --------------------------------------------------------------- + +https://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qmenubar + +--------------------------------------------------------------------------- */ +QMenuBar { + background-color: #272727; + padding: 2px; + border: 1px solid #525252; + color: #E3E3E3; + selection-background-color: #666666; +} + +QMenuBar:focus { + border: 1px solid #616161; +} + +QMenuBar::item { + background: transparent; + padding-left: 7px; + padding-right: 7px; +} + +QMenuBar::item:selected { + padding: 4px; + background: transparent; + border: 0px solid #525252; + background-color: #383838; +} + +QMenuBar::item:pressed { + padding: 4px; + border: 0px solid #525252; + background-color: #383838; + color: #E3E3E3; +} + +/* QMenu ------------------------------------------------------------------ + +https://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qmenu + +--------------------------------------------------------------------------- */ +QMenu { + border: 0px solid #525252; + color: #E3E3E3; + margin: 0px; + background-color: #2C2C2C; + selection-background-color: #666666; +} + +QMenu::separator { + height: 1px; + background-color: #767676; + color: #E3E3E3; +} + +QMenu::item { + background-color: #2C2C2C; + padding: 4px 24px 4px 28px; + /* Reserve space for selection border */ + border: 1px transparent #525252; +} + +QMenu::item:selected { + color: #E3E3E3; + background-color: #353535; +} + +QMenu::item:pressed { + background-color: #353535; +} + +QMenu::icon { + padding-left: 10px; + width: 14px; + height: 14px; +} + +QMenu::indicator { + padding-left: 8px; + width: 12px; + height: 12px; + /* non-exclusive indicator = check box style indicator (see QActionGroup::setExclusive) */ + /* exclusive indicator = radio button style indicator (see QActionGroup::setExclusive) */ +} + +QMenu::indicator:non-exclusive:unchecked { + image: url(":/qss_icons/dark/rc/checkbox_unchecked.png"); +} + +QMenu::indicator:non-exclusive:unchecked:hover, QMenu::indicator:non-exclusive:unchecked:focus, QMenu::indicator:non-exclusive:unchecked:pressed { + border: none; + image: url(":/qss_icons/dark/rc/checkbox_unchecked_focus.png"); +} + +QMenu::indicator:non-exclusive:unchecked:disabled { + image: url(":/qss_icons/dark/rc/checkbox_unchecked_disabled.png"); +} + +QMenu::indicator:non-exclusive:checked { + image: url(":/qss_icons/dark/rc/checkbox_checked.png"); +} + +QMenu::indicator:non-exclusive:checked:hover, QMenu::indicator:non-exclusive:checked:focus, QMenu::indicator:non-exclusive:checked:pressed { + border: none; + image: url(":/qss_icons/dark/rc/checkbox_checked_focus.png"); +} + +QMenu::indicator:non-exclusive:checked:disabled { + image: url(":/qss_icons/dark/rc/checkbox_checked_disabled.png"); +} + +QMenu::indicator:non-exclusive:indeterminate { + image: url(":/qss_icons/dark/rc/checkbox_indeterminate.png"); +} + +QMenu::indicator:non-exclusive:indeterminate:disabled { + image: url(":/qss_icons/dark/rc/checkbox_indeterminate_disabled.png"); +} + +QMenu::indicator:non-exclusive:indeterminate:focus, QMenu::indicator:non-exclusive:indeterminate:hover, QMenu::indicator:non-exclusive:indeterminate:pressed { + image: url(":/qss_icons/dark/rc/checkbox_indeterminate_focus.png"); +} + +QMenu::indicator:exclusive:unchecked { + image: url(":/qss_icons/dark/rc/radio_unchecked.png"); +} + +QMenu::indicator:exclusive:unchecked:hover, QMenu::indicator:exclusive:unchecked:focus, QMenu::indicator:exclusive:unchecked:pressed { + border: none; + outline: none; + image: url(":/qss_icons/dark/rc/radio_unchecked_focus.png"); +} + +QMenu::indicator:exclusive:unchecked:disabled { + image: url(":/qss_icons/dark/rc/radio_unchecked_disabled.png"); +} + +QMenu::indicator:exclusive:checked { + border: none; + outline: none; + image: url(":/qss_icons/dark/rc/radio_checked.png"); +} + +QMenu::indicator:exclusive:checked:hover, QMenu::indicator:exclusive:checked:focus, QMenu::indicator:exclusive:checked:pressed { + border: none; + outline: none; + image: url(":/qss_icons/dark/rc/radio_checked_focus.png"); +} + +QMenu::indicator:exclusive:checked:disabled { + outline: none; + image: url(":/qss_icons/dark/rc/radio_checked_disabled.png"); +} + +QMenu::right-arrow { + margin: 5px; + padding-left: 12px; + image: url(":/qss_icons/dark/rc/arrow_right.png"); + height: 12px; + width: 12px; +} + +/* QAbstractItemView ------------------------------------------------------ + +https://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qcombobox + +--------------------------------------------------------------------------- */ +QAbstractItemView { + alternate-background-color: #272727; + color: #E3E3E3; + border: 1px solid #525252; + border-radius: 4px; +} + +QAbstractItemView QLineEdit { + padding: 2px; +} + +/* QAbstractScrollArea ---------------------------------------------------- + +https://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qabstractscrollarea + +--------------------------------------------------------------------------- */ +QAbstractScrollArea { + background-color: #272727; + border: 1px solid #525252; + border-radius: 4px; + /* fix #159 */ + padding: 2px; + /* remove min-height to fix #244 */ + color: #E3E3E3; +} + +QAbstractScrollArea:disabled { + color: #8B8B8B; +} + +/* QScrollArea ------------------------------------------------------------ + +--------------------------------------------------------------------------- */ +QScrollArea QWidget QWidget:disabled { + background-color: #272727; +} + +/* QScrollBar ------------------------------------------------------------- + +https://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qscrollbar + +--------------------------------------------------------------------------- */ +QScrollBar:horizontal { + height: 16px; + margin: 2px 16px 2px 16px; + border: 1px solid #525252; + border-radius: 4px; + background-color: #272727; +} + +QScrollBar:vertical { + background-color: #272727; + width: 16px; + margin: 16px 2px 16px 2px; + border: 1px solid #525252; + border-radius: 4px; +} + +QScrollBar::handle:horizontal { + background-color: #767676; + border: 1px solid #525252; + border-radius: 4px; + min-width: 8px; +} + +QScrollBar::handle:horizontal:hover { + background-color: #616161; + border: #616161; + border-radius: 4px; + min-width: 8px; +} + +QScrollBar::handle:horizontal:focus { + border: 1px solid #666666; +} + +QScrollBar::handle:vertical { + background-color: #767676; + border: 1px solid #525252; + min-height: 8px; + border-radius: 4px; +} + +QScrollBar::handle:vertical:hover { + background-color: #616161; + border: #616161; + border-radius: 4px; + min-height: 8px; +} + +QScrollBar::handle:vertical:focus { + border: 1px solid #666666; +} + +QScrollBar::add-line:horizontal { + margin: 0px 0px 0px 0px; + border-image: url(":/qss_icons/dark/rc/arrow_right_disabled.png"); + height: 12px; + width: 12px; + subcontrol-position: right; + subcontrol-origin: margin; +} + +QScrollBar::add-line:horizontal:hover, QScrollBar::add-line:horizontal:on { + border-image: url(":/qss_icons/dark/rc/arrow_right.png"); + height: 12px; + width: 12px; + subcontrol-position: right; + subcontrol-origin: margin; +} + +QScrollBar::add-line:vertical { + margin: 3px 0px 3px 0px; + border-image: url(":/qss_icons/dark/rc/arrow_down_disabled.png"); + height: 12px; + width: 12px; + subcontrol-position: bottom; + subcontrol-origin: margin; +} + +QScrollBar::add-line:vertical:hover, QScrollBar::add-line:vertical:on { + border-image: url(":/qss_icons/dark/rc/arrow_down.png"); + height: 12px; + width: 12px; + subcontrol-position: bottom; + subcontrol-origin: margin; +} + +QScrollBar::sub-line:horizontal { + margin: 0px 3px 0px 3px; + border-image: url(":/qss_icons/dark/rc/arrow_left_disabled.png"); + height: 12px; + width: 12px; + subcontrol-position: left; + subcontrol-origin: margin; +} + +QScrollBar::sub-line:horizontal:hover, QScrollBar::sub-line:horizontal:on { + border-image: url(":/qss_icons/dark/rc/arrow_left.png"); + height: 12px; + width: 12px; + subcontrol-position: left; + subcontrol-origin: margin; +} + +QScrollBar::sub-line:vertical { + margin: 3px 0px 3px 0px; + border-image: url(":/qss_icons/dark/rc/arrow_up_disabled.png"); + height: 12px; + width: 12px; + subcontrol-position: top; + subcontrol-origin: margin; +} + +QScrollBar::sub-line:vertical:hover, QScrollBar::sub-line:vertical:on { + border-image: url(":/qss_icons/dark/rc/arrow_up.png"); + height: 12px; + width: 12px; + subcontrol-position: top; + subcontrol-origin: margin; +} + +QScrollBar::up-arrow:horizontal, QScrollBar::down-arrow:horizontal { + background: none; +} + +QScrollBar::up-arrow:vertical, QScrollBar::down-arrow:vertical { + background: none; +} + +QScrollBar::add-page:horizontal, QScrollBar::sub-page:horizontal { + background: none; +} + +QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical { + background: none; +} + +/* QTextEdit -------------------------------------------------------------- + +https://doc.qt.io/qt-5/stylesheet-examples.html#customizing-specific-widgets + +--------------------------------------------------------------------------- */ +QTextEdit { + background-color: #272727; + color: #E3E3E3; + border-radius: 4px; + border: 1px solid #525252; +} + +QTextEdit:focus { + border: 1px solid #666666; +} + +QTextEdit:selected { + background: #616161; + color: #525252; +} + +/* QPlainTextEdit --------------------------------------------------------- + +--------------------------------------------------------------------------- */ +QPlainTextEdit { + background-color: #272727; + color: #E3E3E3; + border-radius: 4px; + border: 1px solid #525252; +} + +QPlainTextEdit:focus { + border: 1px solid #666666; +} + +QPlainTextEdit:selected { + background: #616161; + color: #525252; +} + +/* QSizeGrip -------------------------------------------------------------- + +https://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qsizegrip + +--------------------------------------------------------------------------- */ +QSizeGrip { + background: transparent; + width: 12px; + height: 12px; + image: url(":/qss_icons/dark/rc/window_grip.png"); +} + +/* QToolBar --------------------------------------------------------------- + +https://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qtoolbar + +--------------------------------------------------------------------------- */ +QToolBar { + background-color: #272727; + border-bottom: 1px solid #272727; + padding: 1px; + font-weight: bold; +} + +QToolBar:disabled { + /* Fixes #272 */ + background-color: #272727; +} + +QToolBar::handle:horizontal { + width: 16px; + image: url(":/qss_icons/dark/rc/toolbar_move_horizontal.png"); +} + +QToolBar::handle:vertical { + height: 16px; + image: url(":/qss_icons/dark/rc/toolbar_move_vertical.png"); +} + +QToolBar::separator:horizontal { + width: 16px; + image: url(":/qss_icons/dark/rc/toolbar_separator_horizontal.png"); +} + +QToolBar::separator:vertical { + height: 16px; + image: url(":/qss_icons/dark/rc/toolbar_separator_vertical.png"); +} + +QToolButton#qt_toolbar_ext_button { + background: #272727; + border: 0px; + color: #E3E3E3; + image: url(":/qss_icons/dark/rc/arrow_right.png"); +} + +/* QAbstractSpinBox ------------------------------------------------------- + +--------------------------------------------------------------------------- */ +QAbstractSpinBox { + background-color: #272727; + border: 1px solid #525252; + color: #E3E3E3; + /* This fixes 103, 111 */ + padding-top: 2px; + /* This fixes 103, 111 */ + padding-bottom: 2px; + padding-left: 4px; + padding-right: 4px; + border-radius: 4px; + /* min-width: 5px; removed to fix 109 */ +} + +QAbstractSpinBox:up-button { + background-color: transparent #272727; + subcontrol-origin: border; + subcontrol-position: top right; + border-left: 1px solid #525252; + border-bottom: 1px solid #525252; + border-top-left-radius: 0; + border-bottom-left-radius: 0; + margin: 1px; + width: 12px; + margin-bottom: -1px; +} + +QAbstractSpinBox::up-arrow, QAbstractSpinBox::up-arrow:disabled, QAbstractSpinBox::up-arrow:off { + image: url(":/qss_icons/dark/rc/arrow_up_disabled.png"); + height: 8px; + width: 8px; +} + +QAbstractSpinBox::up-arrow:hover { + image: url(":/qss_icons/dark/rc/arrow_up.png"); +} + +QAbstractSpinBox:down-button { + background-color: transparent #272727; + subcontrol-origin: border; + subcontrol-position: bottom right; + border-left: 1px solid #525252; + border-top: 1px solid #525252; + border-top-left-radius: 0; + border-bottom-left-radius: 0; + margin: 1px; + width: 12px; + margin-top: -1px; +} + +QAbstractSpinBox::down-arrow, QAbstractSpinBox::down-arrow:disabled, QAbstractSpinBox::down-arrow:off { + image: url(":/qss_icons/dark/rc/arrow_down_disabled.png"); + height: 8px; + width: 8px; +} + +QAbstractSpinBox::down-arrow:hover { + image: url(":/qss_icons/dark/rc/arrow_down.png"); +} + +QAbstractSpinBox:hover { + border: 1px solid #616161; + color: #E3E3E3; +} + +QAbstractSpinBox:focus { + border: 1px solid #666666; +} + +QAbstractSpinBox:selected { + background: #616161; + color: #525252; +} + +/* ------------------------------------------------------------------------ */ +/* DISPLAYS --------------------------------------------------------------- */ +/* ------------------------------------------------------------------------ */ +/* QLabel ----------------------------------------------------------------- + +https://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qframe + +--------------------------------------------------------------------------- */ +QLabel { + background-color: #272727; + border: 0px solid #525252; + padding: 2px; + margin: 0px; + color: #E3E3E3; +} + +QLabel:disabled { + background-color: #272727; + border: 0px solid #525252; + color: #8B8B8B; +} + +/* QTextBrowser ----------------------------------------------------------- + +https://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qabstractscrollarea + +--------------------------------------------------------------------------- */ +QTextBrowser { + background-color: #272727; + border: 1px solid #525252; + color: #E3E3E3; + border-radius: 4px; +} + +QTextBrowser:disabled { + background-color: #272727; + border: 1px solid #525252; + color: #8B8B8B; + border-radius: 4px; +} + +QTextBrowser:hover, QTextBrowser:!hover, QTextBrowser:selected, QTextBrowser:pressed { + border: 1px solid #525252; +} + +/* QGraphicsView ---------------------------------------------------------- + +--------------------------------------------------------------------------- */ +QGraphicsView { + background-color: #272727; + border: 1px solid #525252; + color: #E3E3E3; + border-radius: 4px; +} + +QGraphicsView:disabled { + background-color: #272727; + border: 1px solid #525252; + color: #8B8B8B; + border-radius: 4px; +} + +QGraphicsView:hover, QGraphicsView:!hover, QGraphicsView:selected, QGraphicsView:pressed { + border: 1px solid #525252; +} + +/* QCalendarWidget -------------------------------------------------------- + +--------------------------------------------------------------------------- */ +QCalendarWidget { + border: 1px solid #525252; + border-radius: 4px; +} + +QCalendarWidget:disabled { + background-color: #272727; + color: #8B8B8B; +} + +/* QLCDNumber ------------------------------------------------------------- + +--------------------------------------------------------------------------- */ +QLCDNumber { + background-color: #272727; + color: #E3E3E3; +} + +QLCDNumber:disabled { + background-color: #272727; + color: #8B8B8B; +} + +/* QProgressBar ----------------------------------------------------------- + +https://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qprogressbar + +--------------------------------------------------------------------------- */ +QProgressBar { + background-color: #272727; + border: 1px solid #525252; + color: #E3E3E3; + border-radius: 4px; + text-align: center; +} + +QProgressBar:disabled { + background-color: #272727; + border: 1px solid #525252; + color: #8B8B8B; + border-radius: 4px; + text-align: center; +} + +QProgressBar::chunk { + background-color: #616161; + color: #272727; + border-radius: 4px; +} + +QProgressBar::chunk:disabled { + background-color: #444444; + color: #8B8B8B; + border-radius: 4px; +} + +/* ------------------------------------------------------------------------ */ +/* BUTTONS ---------------------------------------------------------------- */ +/* ------------------------------------------------------------------------ */ +/* QPushButton ------------------------------------------------------------ + +https://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qpushbutton + +--------------------------------------------------------------------------- */ +QPushButton { + background-color: #333333; + color: #E3E3E3; + border-radius: 4px; + padding: 4px; + outline: none; + border: 1px solid white; +} + +QPushButton:disabled { + background-color: #333333; + color: #8B8B8B; + border-radius: 4px; + padding: 4px; + border: 1px solid #9B9B9B; +} + +QPushButton:checked { + background-color: #666666; + border-radius: 4px; + padding: 4px; + outline: none; +} + +QPushButton:checked:disabled { + background-color: #525252; + color: #8B8B8B; + border-radius: 4px; + padding: 4px; + outline: none; +} + +QPushButton:checked:selected { + background: #454545; +} + +QPushButton:hover { + background-color: #454545; + color: #E3E3E3; + border: 1px solid #9B9B9B; +} + +QPushButton:pressed { + background-color: #666666; + border: 1px solid #9B9B9B; +} + +QPushButton:selected { + background: #333333; + color: #E3E3E3; +} + +QPushButton::menu-indicator { + subcontrol-origin: padding; + subcontrol-position: bottom right; + bottom: 4px; +} + +QDialogButtonBox QPushButton { + /* Issue #194 #248 - Special case of QPushButton inside dialogs, for better UI */ + min-width: 80px; +} + +/* QToolButton ------------------------------------------------------------ + +https://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qtoolbutton + +--------------------------------------------------------------------------- */ +QToolButton { + background-color: #272727; + color: #E3E3E3; + border-radius: 4px; + padding: 2px; + outline: none; + border: none; + /* The subcontrols below are used only in the DelayedPopup mode */ + /* The subcontrols below are used only in the MenuButtonPopup mode */ + /* The subcontrol below is used only in the InstantPopup or DelayedPopup mode */ +} + +QToolButton:disabled { + background-color: #272727; + color: #8B8B8B; + border-radius: 4px; + padding: 2px; +} + +QToolButton:checked { + background-color: #767676; + border-radius: 4px; + padding: 2px; + outline: none; +} + +QToolButton:checked:disabled { + background-color: #767676; + color: #8B8B8B; + border-radius: 4px; + padding: 2px; + outline: none; +} + +QToolButton:checked:hover { + background-color: #666666; + color: #E3E3E3; +} + +QToolButton:checked:pressed { + background-color: #767676; +} + +QToolButton:checked:selected { + background: #767676; + color: #E3E3E3; +} + +QToolButton:hover { + background-color: #666666; + color: #E3E3E3; +} + +QToolButton:pressed { + background-color: #767676; +} + +QToolButton:selected { + background: #767676; + color: #E3E3E3; +} + +QToolButton[popupMode="0"] { + /* Only for DelayedPopup */ + padding-right: 2px; +} + +QToolButton[popupMode="1"] { + /* Only for MenuButtonPopup */ + padding-right: 20px; +} + +QToolButton[popupMode="1"]::menu-button { + border: none; +} + +QToolButton[popupMode="1"]::menu-button:hover { + border: none; + border-left: 1px solid #525252; + border-radius: 0; +} + +QToolButton[popupMode="2"] { + /* Only for InstantPopup */ + padding-right: 2px; +} + +QToolButton::menu-button { + padding: 2px; + border-radius: 4px; + width: 12px; + border: none; + outline: none; +} + +QToolButton::menu-button:hover { + border: 1px solid #616161; +} + +QToolButton::menu-button:checked:hover { + border: 1px solid #616161; +} + +QToolButton::menu-indicator { + image: url(":/qss_icons/dark/rc/arrow_down.png"); + height: 8px; + width: 8px; + top: 0; + /* Exclude a shift for better image */ + left: -2px; + /* Shift it a bit */ +} + +QToolButton::menu-arrow { + image: url(":/qss_icons/dark/rc/arrow_down.png"); + height: 8px; + width: 8px; +} + +QToolButton::menu-arrow:hover { + image: url(":/qss_icons/dark/rc/arrow_down_focus.png"); +} + +/* QCommandLinkButton ----------------------------------------------------- + +--------------------------------------------------------------------------- */ +QCommandLinkButton { + background-color: transparent; + border: 1px solid #525252; + color: #E3E3E3; + border-radius: 4px; + padding: 0px; + margin: 0px; +} + +QCommandLinkButton:disabled { + background-color: transparent; + color: #8B8B8B; +} + +/* ------------------------------------------------------------------------ */ +/* INPUTS - NO FIELDS ----------------------------------------------------- */ +/* ------------------------------------------------------------------------ */ +/* QComboBox -------------------------------------------------------------- + +https://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qcombobox + +--------------------------------------------------------------------------- */ +QComboBox { + border: 1px solid #525252; + border-radius: 4px; + selection-background-color: #616161; + padding-left: 4px; + padding-right: 4px; + /* padding-right = 36; 4 + 16*2 See scrollbar size */ + /* changed to 4px to fix #239 */ + /* Fixes #103, #111 */ + min-height: 1.5em; + /* padding-top: 2px; removed to fix #132 */ + /* padding-bottom: 2px; removed to fix #132 */ + /* min-width: 75px; removed to fix #109 */ + /* Needed to remove indicator - fix #132 */ +} + +QComboBox QAbstractItemView { + border: 1px solid #525252; + border-radius: 0; + background-color: #272727; + selection-background-color: #616161; +} + +QComboBox QAbstractItemView:hover { + background-color: #272727; + color: #E3E3E3; +} + +QComboBox QAbstractItemView:selected { + background: #616161; + color: #525252; +} + +QComboBox QAbstractItemView:alternate { + background: #272727; +} + +QComboBox:disabled { + background-color: #272727; + color: #8B8B8B; +} + +QComboBox:hover { + border: 1px solid #616161; + background-color: #454545; +} + +QComboBox:focus { + border: 1px solid #666666; +} + +QComboBox:on { + selection-background-color: #616161; + background-color: #666666; +} + +QComboBox::indicator { + border: none; + border-radius: 0; + background-color: transparent; + selection-background-color: transparent; + color: transparent; + selection-color: transparent; + /* Needed to remove indicator - fix #132 */ +} + +QComboBox::indicator:alternate { + background: #272727; +} + +QComboBox::item { + /* Remove to fix #282, #285 and MR #288*/ + /*&:checked { + font-weight: bold; + } + + &:selected { + border: 0px solid transparent; + } + */ +} + +QComboBox::item:alternate { + background: #272727; +} + +QComboBox::drop-down { + subcontrol-origin: padding; + subcontrol-position: top right; + width: 12px; + border-left: 1px solid #525252; +} + +QComboBox::down-arrow { + image: url(":/qss_icons/dark/rc/arrow_down_disabled.png"); + height: 8px; + width: 8px; +} + +QComboBox::down-arrow:on, QComboBox::down-arrow:hover, QComboBox::down-arrow:focus { + image: url(":/qss_icons/dark/rc/arrow_down.png"); +} + +/* QSlider ---------------------------------------------------------------- + +https://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qslider + +--------------------------------------------------------------------------- */ +QSlider:disabled { + background: #272727; +} + +QSlider:focus { + border: none; +} + +QSlider::groove:horizontal { + background: #525252; + border: 1px solid #525252; + height: 4px; + margin: 0px; + border-radius: 4px; +} + +QSlider::groove:vertical { + background: #525252; + border: 1px solid #525252; + width: 4px; + margin: 0px; + border-radius: 4px; +} + +QSlider::add-page:vertical { + background: #616161; + border: 1px solid #525252; + width: 4px; + margin: 0px; + border-radius: 4px; +} + +QSlider::add-page:vertical :disabled { + background: #444444; +} + +QSlider::sub-page:horizontal { + background: #616161; + border: 1px solid #525252; + height: 4px; + margin: 0px; + border-radius: 4px; +} + +QSlider::sub-page:horizontal:disabled { + background: #444444; +} + +QSlider::handle:horizontal { + background: #A9A9A9; + border: 1px solid #525252; + width: 8px; + height: 8px; + margin: -8px 0px; + border-radius: 4px; +} + +QSlider::handle:horizontal:hover { + background: #616161; + border: 1px solid #616161; +} + +QSlider::handle:horizontal:focus { + border: 1px solid #666666; +} + +QSlider::handle:vertical { + background: #A9A9A9; + border: 1px solid #525252; + width: 8px; + height: 8px; + margin: 0 -8px; + border-radius: 4px; +} + +QSlider::handle:vertical:hover { + background: #616161; + border: 1px solid #616161; +} + +QSlider::handle:vertical:focus { + border: 1px solid #666666; +} + +/* QLineEdit -------------------------------------------------------------- + +https://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qlineedit + +--------------------------------------------------------------------------- */ +QLineEdit { + background-color: #272727; + padding-top: 2px; + /* This QLineEdit fix 103, 111 */ + padding-bottom: 2px; + /* This QLineEdit fix 103, 111 */ + padding-left: 4px; + padding-right: 4px; + border-style: solid; + border: 1px solid #525252; + border-radius: 4px; + color: #E3E3E3; +} + +QLineEdit:disabled { + background-color: #272727; + color: #8B8B8B; +} + +QLineEdit:hover { + border: 1px solid #616161; + color: #E3E3E3; +} + +QLineEdit:focus { + border: 1px solid #666666; +} + +QLineEdit:selected { + background-color: #616161; + color: #525252; +} + +/* QTabWiget -------------------------------------------------------------- + +https://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qtabwidget-and-qtabbar + +--------------------------------------------------------------------------- */ +QTabWidget { + padding: 2px; + selection-background-color: #525252; +} + +QTabWidget QWidget { + /* Fixes #189 */ + border-radius: 4px; +} + +QTabWidget::pane { + border: 1px solid #525252; + border-radius: 4px; + margin: 0px; + /* Fixes double border inside pane with pyqt5 */ + padding: 0px; +} + +QTabWidget::pane:selected { + background-color: #525252; + border: 1px solid #616161; +} + +/* QTabBar ---------------------------------------------------------------- + +https://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qtabwidget-and-qtabbar + +--------------------------------------------------------------------------- */ +QTabBar, QDockWidget QTabBar { + qproperty-drawBase: 0; + border-radius: 4px; + margin: 0px; + padding: 2px; + border: 0; + /* left: 5px; move to the right by 5px - removed for fix */ +} + +QTabBar::close-button, QDockWidget QTabBar::close-button { + border: 0; + margin: 0; + padding: 4px; + image: url(":/qss_icons/dark/rc/window_close.png"); +} + +QTabBar::close-button:hover, QDockWidget QTabBar::close-button:hover { + image: url(":/qss_icons/dark/rc/window_close_focus.png"); +} + +QTabBar::close-button:pressed, QDockWidget QTabBar::close-button:pressed { + image: url(":/qss_icons/dark/rc/window_close_pressed.png"); +} + +QTabBar::tab, QDockWidget QTabBar::tab { + /* !selected and disabled ----------------------------------------- */ + /* selected ------------------------------------------------------- */ +} + +QTabBar::tab:top:selected:disabled, QDockWidget QTabBar::tab:top:selected:disabled { + border-bottom: 3px solid #444444; + color: #8B8B8B; + background-color: #525252; +} + +QTabBar::tab:bottom:selected:disabled, QDockWidget QTabBar::tab:bottom:selected:disabled { + border-top: 3px solid #444444; + color: #8B8B8B; + background-color: #525252; +} + +QTabBar::tab:left:selected:disabled, QDockWidget QTabBar::tab:left:selected:disabled { + border-right: 3px solid #444444; + color: #8B8B8B; + background-color: #525252; +} + +QTabBar::tab:right:selected:disabled, QDockWidget QTabBar::tab:right:selected:disabled { + border-left: 3px solid #444444; + color: #8B8B8B; + background-color: #525252; +} + +QTabBar::tab:top:!selected:disabled, QDockWidget QTabBar::tab:top:!selected:disabled { + border-bottom: 3px solid #272727; + color: #8B8B8B; + background-color: #272727; +} + +QTabBar::tab:bottom:!selected:disabled, QDockWidget QTabBar::tab:bottom:!selected:disabled { + border-top: 3px solid #272727; + color: #8B8B8B; + background-color: #272727; +} + +QTabBar::tab:left:!selected:disabled, QDockWidget QTabBar::tab:left:!selected:disabled { + border-right: 3px solid #272727; + color: #8B8B8B; + background-color: #272727; +} + +QTabBar::tab:right:!selected:disabled, QDockWidget QTabBar::tab:right:!selected:disabled { + border-left: 3px solid #272727; + color: #8B8B8B; + background-color: #272727; +} + +QTabBar::tab:top:!selected, QDockWidget QTabBar::tab:top:!selected { + border-bottom: 2px solid #272727; + margin-top: 2px; +} + +QTabBar::tab:bottom:!selected, QDockWidget QTabBar::tab:bottom:!selected { + border-top: 2px solid #272727; + margin-bottom: 2px; +} + +QTabBar::tab:left:!selected, QDockWidget QTabBar::tab:left:!selected { + border-left: 2px solid #272727; + margin-right: 2px; +} + +QTabBar::tab:right:!selected, QDockWidget QTabBar::tab:right:!selected { + border-right: 2px solid #272727; + margin-left: 2px; +} + +QTabBar::tab:top, QDockWidget QTabBar::tab:top { + background-color: #525252; + margin-left: 2px; + padding-left: 4px; + padding-right: 4px; + padding-top: 2px; + padding-bottom: 2px; + min-width: 5px; + border-bottom: 3px solid #525252; + border-top-left-radius: 4px; + border-top-right-radius: 4px; +} + +QTabBar::tab:top:selected, QDockWidget QTabBar::tab:top:selected { + background-color: #666666; + border-bottom: 3px solid #898989; + border-top-left-radius: 4px; + border-top-right-radius: 4px; +} + +QTabBar::tab:top:!selected:hover, QDockWidget QTabBar::tab:top:!selected:hover { + border: 1px solid #666666; + border-bottom: 3px solid #666666; + /* Fixes spyder-ide/spyder#9766 and #243 */ + padding-left: 3px; + padding-right: 3px; +} + +QTabBar::tab:bottom, QDockWidget QTabBar::tab:bottom { + border-top: 3px solid #525252; + background-color: #525252; + margin-left: 2px; + padding-left: 4px; + padding-right: 4px; + padding-top: 2px; + padding-bottom: 2px; + border-bottom-left-radius: 4px; + border-bottom-right-radius: 4px; + min-width: 5px; +} + +QTabBar::tab:bottom:selected, QDockWidget QTabBar::tab:bottom:selected { + background-color: #666666; + border-top: 3px solid #898989; + border-bottom-left-radius: 4px; + border-bottom-right-radius: 4px; +} + +QTabBar::tab:bottom:!selected:hover, QDockWidget QTabBar::tab:bottom:!selected:hover { + border: 1px solid #666666; + border-top: 3px solid #666666; + /* Fixes spyder-ide/spyder#9766 and #243 */ + padding-left: 3px; + padding-right: 3px; +} + +QTabBar::tab:left, QDockWidget QTabBar::tab:left { + background-color: #525252; + margin-top: 2px; + padding-left: 2px; + padding-right: 2px; + padding-top: 4px; + padding-bottom: 4px; + border-top-left-radius: 4px; + border-bottom-left-radius: 4px; + min-height: 5px; +} + +QTabBar::tab:left:selected, QDockWidget QTabBar::tab:left:selected { + background-color: #666666; + border-right: 3px solid #898989; +} + +QTabBar::tab:left:!selected:hover, QDockWidget QTabBar::tab:left:!selected:hover { + border: 1px solid #666666; + border-right: 3px solid #666666; + /* Fixes different behavior #271 */ + margin-right: 0px; + padding-right: -1px; +} + +QTabBar::tab:right, QDockWidget QTabBar::tab:right { + background-color: #525252; + margin-top: 2px; + padding-left: 2px; + padding-right: 2px; + padding-top: 4px; + padding-bottom: 4px; + border-top-right-radius: 4px; + border-bottom-right-radius: 4px; + min-height: 5px; +} + +QTabBar::tab:right:selected, QDockWidget QTabBar::tab:right:selected { + background-color: #666666; + border-left: 3px solid #898989; +} + +QTabBar::tab:right:!selected:hover, QDockWidget QTabBar::tab:right:!selected:hover { + border: 1px solid #666666; + border-left: 3px solid #666666; + /* Fixes different behavior #271 */ + margin-left: 0px; + padding-left: 0px; +} + +QTabBar QToolButton, QDockWidget QTabBar QToolButton { + /* Fixes #136 */ + background-color: #525252; + height: 12px; + width: 12px; +} + +QTabBar QToolButton:pressed, QDockWidget QTabBar QToolButton:pressed { + background-color: #525252; +} + +QTabBar QToolButton:pressed:hover, QDockWidget QTabBar QToolButton:pressed:hover { + border: 1px solid #616161; +} + +QTabBar QToolButton::left-arrow:enabled, QDockWidget QTabBar QToolButton::left-arrow:enabled { + image: url(":/qss_icons/dark/rc/arrow_left.png"); +} + +QTabBar QToolButton::left-arrow:disabled, QDockWidget QTabBar QToolButton::left-arrow:disabled { + image: url(":/qss_icons/dark/rc/arrow_left_disabled.png"); +} + +QTabBar QToolButton::right-arrow:enabled, QDockWidget QTabBar QToolButton::right-arrow:enabled { + image: url(":/qss_icons/dark/rc/arrow_right.png"); +} + +QTabBar QToolButton::right-arrow:disabled, QDockWidget QTabBar QToolButton::right-arrow:disabled { + image: url(":/qss_icons/dark/rc/arrow_right_disabled.png"); +} + +/* QDockWiget ------------------------------------------------------------- + +--------------------------------------------------------------------------- */ +QDockWidget { + outline: 1px solid #525252; + background-color: #272727; + border: 1px solid #525252; + border-radius: 4px; + titlebar-close-icon: url(":/qss_icons/dark/rc/transparent.png"); + titlebar-normal-icon: url(":/qss_icons/dark/rc/transparent.png"); +} + +QDockWidget::title { + /* Better size for title bar */ + padding: 3px; + spacing: 4px; + border: none; + background-color: #525252; +} + +QDockWidget::close-button { + icon-size: 12px; + border: none; + background: transparent; + background-image: transparent; + border: 0; + margin: 0; + padding: 0; + image: url(":/qss_icons/dark/rc/window_close.png"); +} + +QDockWidget::close-button:hover { + image: url(":/qss_icons/dark/rc/window_close_focus.png"); +} + +QDockWidget::close-button:pressed { + image: url(":/qss_icons/dark/rc/window_close_pressed.png"); +} + +QDockWidget::float-button { + icon-size: 12px; + border: none; + background: transparent; + background-image: transparent; + border: 0; + margin: 0; + padding: 0; + image: url(":/qss_icons/dark/rc/window_undock.png"); +} + +QDockWidget::float-button:hover { + image: url(":/qss_icons/dark/rc/window_undock_focus.png"); +} + +QDockWidget::float-button:pressed { + image: url(":/qss_icons/dark/rc/window_undock_pressed.png"); +} + +/* QTreeView QListView QTableView ----------------------------------------- + +https://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qtreeview +https://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qlistview +https://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qtableview + +--------------------------------------------------------------------------- */ +QTreeView:branch:selected, QTreeView:branch:hover { + background: url(":/qss_icons/dark/rc/transparent.png"); +} + +QTreeView:branch:has-siblings:!adjoins-item { + border-image: url(":/qss_icons/dark/rc/branch_line.png") 0; +} + +QTreeView:branch:has-siblings:adjoins-item { + border-image: url(":/qss_icons/dark/rc/branch_more.png") 0; +} + +QTreeView:branch:!has-children:!has-siblings:adjoins-item { + border-image: url(":/qss_icons/dark/rc/branch_end.png") 0; +} + +QTreeView:branch:has-children:!has-siblings:closed, QTreeView:branch:closed:has-children:has-siblings { + border-image: none; + image: url(":/qss_icons/dark/rc/branch_closed.png"); +} + +QTreeView:branch:open:has-children:!has-siblings, QTreeView:branch:open:has-children:has-siblings { + border-image: none; + image: url(":/qss_icons/dark/rc/branch_open.png"); +} + +QTreeView:branch:has-children:!has-siblings:closed:hover, QTreeView:branch:closed:has-children:has-siblings:hover { + image: url(":/qss_icons/dark/rc/branch_closed_focus.png"); +} + +QTreeView:branch:open:has-children:!has-siblings:hover, QTreeView:branch:open:has-children:has-siblings:hover { + image: url(":/qss_icons/dark/rc/branch_open_focus.png"); +} + +QTreeView::indicator:checked, +QListView::indicator:checked, +QTableView::indicator:checked, +QColumnView::indicator:checked { + image: url(":/qss_icons/dark/rc/checkbox_checked.png"); +} + +QTreeView::indicator:checked:hover, QTreeView::indicator:checked:focus, QTreeView::indicator:checked:pressed, +QListView::indicator:checked:hover, +QListView::indicator:checked:focus, +QListView::indicator:checked:pressed, +QTableView::indicator:checked:hover, +QTableView::indicator:checked:focus, +QTableView::indicator:checked:pressed, +QColumnView::indicator:checked:hover, +QColumnView::indicator:checked:focus, +QColumnView::indicator:checked:pressed { + image: url(":/qss_icons/dark/rc/checkbox_checked_focus.png"); +} + +QTreeView::indicator:unchecked, +QListView::indicator:unchecked, +QTableView::indicator:unchecked, +QColumnView::indicator:unchecked { + image: url(":/qss_icons/dark/rc/checkbox_unchecked.png"); +} + +QTreeView::indicator:unchecked:hover, QTreeView::indicator:unchecked:focus, QTreeView::indicator:unchecked:pressed, +QListView::indicator:unchecked:hover, +QListView::indicator:unchecked:focus, +QListView::indicator:unchecked:pressed, +QTableView::indicator:unchecked:hover, +QTableView::indicator:unchecked:focus, +QTableView::indicator:unchecked:pressed, +QColumnView::indicator:unchecked:hover, +QColumnView::indicator:unchecked:focus, +QColumnView::indicator:unchecked:pressed { + image: url(":/qss_icons/dark/rc/checkbox_unchecked_focus.png"); +} + +QTreeView::indicator:indeterminate, +QListView::indicator:indeterminate, +QTableView::indicator:indeterminate, +QColumnView::indicator:indeterminate { + image: url(":/qss_icons/dark/rc/checkbox_indeterminate.png"); +} + +QTreeView::indicator:indeterminate:hover, QTreeView::indicator:indeterminate:focus, QTreeView::indicator:indeterminate:pressed, +QListView::indicator:indeterminate:hover, +QListView::indicator:indeterminate:focus, +QListView::indicator:indeterminate:pressed, +QTableView::indicator:indeterminate:hover, +QTableView::indicator:indeterminate:focus, +QTableView::indicator:indeterminate:pressed, +QColumnView::indicator:indeterminate:hover, +QColumnView::indicator:indeterminate:focus, +QColumnView::indicator:indeterminate:pressed { + image: url(":/qss_icons/dark/rc/checkbox_indeterminate_focus.png"); +} + +QTreeView, +QListView, +QTableView, +QColumnView { + background-color: #272727; + border: 1px solid #525252; + color: #E3E3E3; + gridline-color: #525252; + border-radius: 4px; +} + +QTreeView:disabled, +QListView:disabled, +QTableView:disabled, +QColumnView:disabled { + background-color: #272727; + color: #8B8B8B; +} + +QTreeView:selected, +QListView:selected, +QTableView:selected, +QColumnView:selected { + background-color: #616161; + color: #525252; +} + +QTreeView:focus, +QListView:focus, +QTableView:focus, +QColumnView:focus { + border: 1px solid #666666; +} + +QTreeView::item:pressed, +QListView::item:pressed, +QTableView::item:pressed, +QColumnView::item:pressed { + background-color: #616161; +} + +QTreeView::item:selected:active, +QListView::item:selected:active, +QTableView::item:selected:active, +QColumnView::item:selected:active { + background-color: #616161; +} + +QTreeView::item:selected:!active, +QListView::item:selected:!active, +QTableView::item:selected:!active, +QColumnView::item:selected:!active { + color: #E3E3E3; + background-color: #414141; +} + +QTreeView::item:!selected:hover, +QListView::item:!selected:hover, +QTableView::item:!selected:hover, +QColumnView::item:!selected:hover { + outline: 0; + color: #E3E3E3; + background-color: #414141; +} + +QTableCornerButton::section { + background-color: #272727; + border: 1px transparent #525252; + border-radius: 0px; +} + +/* QHeaderView ------------------------------------------------------------ + +https://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qheaderview + +--------------------------------------------------------------------------- */ +QHeaderView { + background-color: #525252; + border: 0px transparent #525252; + padding: 0; + margin: 0; + border-radius: 0; +} + +QHeaderView:disabled { + background-color: #525252; + border: 1px transparent #525252; +} + +QHeaderView::section { + background-color: #525252; + color: #E3E3E3; + border-radius: 0; + text-align: left; + font-size: 13px; +} + +QHeaderView::section::horizontal { + padding-top: 0; + padding-bottom: 0; + padding-left: 4px; + padding-right: 4px; + border-left: 1px solid #272727; +} + +QHeaderView::section::horizontal::first, QHeaderView::section::horizontal::only-one { + border-left: 1px solid #525252; +} + +QHeaderView::section::horizontal:disabled { + color: #8B8B8B; +} + +QHeaderView::section::vertical { + padding-top: 0; + padding-bottom: 0; + padding-left: 4px; + padding-right: 4px; + border-top: 1px solid #272727; +} + +QHeaderView::section::vertical::first, QHeaderView::section::vertical::only-one { + border-top: 1px solid #525252; +} + +QHeaderView::section::vertical:disabled { + color: #8B8B8B; +} + +QHeaderView::down-arrow { + /* Those settings (border/width/height/background-color) solve bug */ + /* transparent arrow background and size */ + background-color: #525252; + border: none; + height: 12px; + width: 12px; + padding-left: 2px; + padding-right: 2px; + image: url(":/qss_icons/dark/rc/arrow_down.png"); +} + +QHeaderView::up-arrow { + background-color: #525252; + border: none; + height: 12px; + width: 12px; + padding-left: 2px; + padding-right: 2px; + image: url(":/qss_icons/dark/rc/arrow_up.png"); +} + +/* QToolBox -------------------------------------------------------------- + +https://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qtoolbox + +--------------------------------------------------------------------------- */ +QToolBox { + padding: 0px; + border: 0px; + border: 1px solid #525252; +} + +QToolBox:selected { + padding: 0px; + border: 2px solid #616161; +} + +QToolBox::tab { + background-color: #272727; + border: 1px solid #525252; + color: #E3E3E3; + border-top-left-radius: 4px; + border-top-right-radius: 4px; +} + +QToolBox::tab:disabled { + color: #8B8B8B; +} + +QToolBox::tab:selected { + background-color: #767676; + border-bottom: 2px solid #616161; +} + +QToolBox::tab:selected:disabled { + background-color: #525252; + border-bottom: 2px solid #444444; +} + +QToolBox::tab:!selected { + background-color: #525252; + border-bottom: 2px solid #525252; +} + +QToolBox::tab:!selected:disabled { + background-color: #272727; +} + +QToolBox::tab:hover { + border-color: #666666; + border-bottom: 2px solid #666666; +} + +QToolBox QScrollArea { + padding: 0px; + border: 0px; + background-color: #272727; +} + +/* QFrame ----------------------------------------------------------------- + +https://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qframe +https://doc.qt.io/qt-5/qframe.html#-prop +https://doc.qt.io/qt-5/qframe.html#details +https://stackoverflow.com/questions/14581498/qt-stylesheet-for-hline-vline-color + +--------------------------------------------------------------------------- */ +/* (dot) .QFrame fix #141, #126, #123 */ +.QFrame { + border-radius: 4px; + border: 1px solid #525252; + /* No frame */ + /* HLine */ + /* HLine */ +} + +.QFrame[frameShape="0"] { + border-radius: 4px; + border: 1px transparent #525252; +} + +.QFrame[frameShape="4"] { + max-height: 2px; + border: none; + background-color: #525252; +} + +.QFrame[frameShape="5"] { + max-width: 2px; + border: none; + background-color: #525252; +} + +/* QSplitter -------------------------------------------------------------- + +https://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qsplitter + +--------------------------------------------------------------------------- */ +QSplitter { + background-color: #525252; + spacing: 0px; + padding: 0px; + margin: 0px; +} + +QSplitter::handle { + background-color: #525252; + border: 0px solid #272727; + spacing: 0px; + padding: 1px; + margin: 0px; +} + +QSplitter::handle:hover { + background-color: #A9A9A9; +} + +QSplitter::handle:horizontal { + width: 5px; + image: url(":/qss_icons/dark/rc/line_vertical.png"); +} + +QSplitter::handle:vertical { + height: 5px; + image: url(":/qss_icons/dark/rc/line_horizontal.png"); +} + +/* QDateEdit, QDateTimeEdit ----------------------------------------------- + +--------------------------------------------------------------------------- */ +QDateEdit, QDateTimeEdit { + selection-background-color: #616161; + border-style: solid; + border: 1px solid #525252; + border-radius: 4px; + /* This fixes 103, 111 */ + padding-top: 2px; + /* This fixes 103, 111 */ + padding-bottom: 2px; + padding-left: 4px; + padding-right: 4px; + min-width: 10px; +} + +QDateEdit:on, QDateTimeEdit:on { + selection-background-color: #616161; +} + +QDateEdit::drop-down, QDateTimeEdit::drop-down { + subcontrol-origin: padding; + subcontrol-position: top right; + width: 12px; + border-left: 1px solid #525252; +} + +QDateEdit::down-arrow, QDateTimeEdit::down-arrow { + image: url(":/qss_icons/dark/rc/arrow_down_disabled.png"); + height: 8px; + width: 8px; +} + +QDateEdit::down-arrow:on, QDateEdit::down-arrow:hover, QDateEdit::down-arrow:focus, QDateTimeEdit::down-arrow:on, QDateTimeEdit::down-arrow:hover, QDateTimeEdit::down-arrow:focus { + image: url(":/qss_icons/dark/rc/arrow_down.png"); +} + +QDateEdit QAbstractItemView, QDateTimeEdit QAbstractItemView { + background-color: #272727; + border-radius: 4px; + border: 1px solid #525252; + selection-background-color: #616161; +} + +/* QAbstractView ---------------------------------------------------------- + +--------------------------------------------------------------------------- */ +QAbstractView:hover { + border: 1px solid #616161; + color: #E3E3E3; +} + +QAbstractView:selected { + background: #616161; + color: #525252; +} + +/* PlotWidget ------------------------------------------------------------- + +--------------------------------------------------------------------------- */ +PlotWidget { + /* Fix cut labels in plots #134 */ + padding: 0px; +} diff --git a/src/qt/qdarkstyle/dark/rc/.keep b/src/qt/qdarkstyle/dark/rc/.keep new file mode 100644 index 000000000..8d1c8b69c --- /dev/null +++ b/src/qt/qdarkstyle/dark/rc/.keep @@ -0,0 +1 @@ + diff --git a/src/qt/qdarkstyle/dark/rc/arrow_down.png b/src/qt/qdarkstyle/dark/rc/arrow_down.png new file mode 100644 index 000000000..412b76e6f Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/arrow_down.png differ diff --git a/src/qt/qdarkstyle/dark/rc/arrow_down@2x.png b/src/qt/qdarkstyle/dark/rc/arrow_down@2x.png new file mode 100644 index 000000000..74d0099ec Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/arrow_down@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/arrow_down_disabled.png b/src/qt/qdarkstyle/dark/rc/arrow_down_disabled.png new file mode 100644 index 000000000..972df9cd1 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/arrow_down_disabled.png differ diff --git a/src/qt/qdarkstyle/dark/rc/arrow_down_disabled@2x.png b/src/qt/qdarkstyle/dark/rc/arrow_down_disabled@2x.png new file mode 100644 index 000000000..b0fb4ad11 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/arrow_down_disabled@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/arrow_down_focus.png b/src/qt/qdarkstyle/dark/rc/arrow_down_focus.png new file mode 100644 index 000000000..22df2c525 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/arrow_down_focus.png differ diff --git a/src/qt/qdarkstyle/dark/rc/arrow_down_focus@2x.png b/src/qt/qdarkstyle/dark/rc/arrow_down_focus@2x.png new file mode 100644 index 000000000..06b80be4b Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/arrow_down_focus@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/arrow_down_pressed.png b/src/qt/qdarkstyle/dark/rc/arrow_down_pressed.png new file mode 100644 index 000000000..50f41cc6f Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/arrow_down_pressed.png differ diff --git a/src/qt/qdarkstyle/dark/rc/arrow_down_pressed@2x.png b/src/qt/qdarkstyle/dark/rc/arrow_down_pressed@2x.png new file mode 100644 index 000000000..ef20f2cb0 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/arrow_down_pressed@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/arrow_left.png b/src/qt/qdarkstyle/dark/rc/arrow_left.png new file mode 100644 index 000000000..b7aeac5f8 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/arrow_left.png differ diff --git a/src/qt/qdarkstyle/dark/rc/arrow_left@2x.png b/src/qt/qdarkstyle/dark/rc/arrow_left@2x.png new file mode 100644 index 000000000..fef91a8c8 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/arrow_left@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/arrow_left_disabled.png b/src/qt/qdarkstyle/dark/rc/arrow_left_disabled.png new file mode 100644 index 000000000..79b1f0565 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/arrow_left_disabled.png differ diff --git a/src/qt/qdarkstyle/dark/rc/arrow_left_disabled@2x.png b/src/qt/qdarkstyle/dark/rc/arrow_left_disabled@2x.png new file mode 100644 index 000000000..144fdb5f8 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/arrow_left_disabled@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/arrow_left_focus.png b/src/qt/qdarkstyle/dark/rc/arrow_left_focus.png new file mode 100644 index 000000000..ef0284994 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/arrow_left_focus.png differ diff --git a/src/qt/qdarkstyle/dark/rc/arrow_left_focus@2x.png b/src/qt/qdarkstyle/dark/rc/arrow_left_focus@2x.png new file mode 100644 index 000000000..ca821dcac Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/arrow_left_focus@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/arrow_left_pressed.png b/src/qt/qdarkstyle/dark/rc/arrow_left_pressed.png new file mode 100644 index 000000000..c723d3bff Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/arrow_left_pressed.png differ diff --git a/src/qt/qdarkstyle/dark/rc/arrow_left_pressed@2x.png b/src/qt/qdarkstyle/dark/rc/arrow_left_pressed@2x.png new file mode 100644 index 000000000..f0bcb5229 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/arrow_left_pressed@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/arrow_right.png b/src/qt/qdarkstyle/dark/rc/arrow_right.png new file mode 100644 index 000000000..78d67f2db Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/arrow_right.png differ diff --git a/src/qt/qdarkstyle/dark/rc/arrow_right@2x.png b/src/qt/qdarkstyle/dark/rc/arrow_right@2x.png new file mode 100644 index 000000000..ce0a8faeb Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/arrow_right@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/arrow_right_disabled.png b/src/qt/qdarkstyle/dark/rc/arrow_right_disabled.png new file mode 100644 index 000000000..88da1f980 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/arrow_right_disabled.png differ diff --git a/src/qt/qdarkstyle/dark/rc/arrow_right_disabled@2x.png b/src/qt/qdarkstyle/dark/rc/arrow_right_disabled@2x.png new file mode 100644 index 000000000..5351587e3 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/arrow_right_disabled@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/arrow_right_focus.png b/src/qt/qdarkstyle/dark/rc/arrow_right_focus.png new file mode 100644 index 000000000..92271a8ed Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/arrow_right_focus.png differ diff --git a/src/qt/qdarkstyle/dark/rc/arrow_right_focus@2x.png b/src/qt/qdarkstyle/dark/rc/arrow_right_focus@2x.png new file mode 100644 index 000000000..d6c31bdda Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/arrow_right_focus@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/arrow_right_pressed.png b/src/qt/qdarkstyle/dark/rc/arrow_right_pressed.png new file mode 100644 index 000000000..22902cf4f Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/arrow_right_pressed.png differ diff --git a/src/qt/qdarkstyle/dark/rc/arrow_right_pressed@2x.png b/src/qt/qdarkstyle/dark/rc/arrow_right_pressed@2x.png new file mode 100644 index 000000000..f6181eb64 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/arrow_right_pressed@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/arrow_up.png b/src/qt/qdarkstyle/dark/rc/arrow_up.png new file mode 100644 index 000000000..50321f29b Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/arrow_up.png differ diff --git a/src/qt/qdarkstyle/dark/rc/arrow_up@2x.png b/src/qt/qdarkstyle/dark/rc/arrow_up@2x.png new file mode 100644 index 000000000..8c73c3be3 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/arrow_up@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/arrow_up_disabled.png b/src/qt/qdarkstyle/dark/rc/arrow_up_disabled.png new file mode 100644 index 000000000..48054a8ae Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/arrow_up_disabled.png differ diff --git a/src/qt/qdarkstyle/dark/rc/arrow_up_disabled@2x.png b/src/qt/qdarkstyle/dark/rc/arrow_up_disabled@2x.png new file mode 100644 index 000000000..e99960594 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/arrow_up_disabled@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/arrow_up_focus.png b/src/qt/qdarkstyle/dark/rc/arrow_up_focus.png new file mode 100644 index 000000000..567ec8bdf Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/arrow_up_focus.png differ diff --git a/src/qt/qdarkstyle/dark/rc/arrow_up_focus@2x.png b/src/qt/qdarkstyle/dark/rc/arrow_up_focus@2x.png new file mode 100644 index 000000000..f6998104b Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/arrow_up_focus@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/arrow_up_pressed.png b/src/qt/qdarkstyle/dark/rc/arrow_up_pressed.png new file mode 100644 index 000000000..223320106 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/arrow_up_pressed.png differ diff --git a/src/qt/qdarkstyle/dark/rc/arrow_up_pressed@2x.png b/src/qt/qdarkstyle/dark/rc/arrow_up_pressed@2x.png new file mode 100644 index 000000000..9954cf519 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/arrow_up_pressed@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/base_icon.png b/src/qt/qdarkstyle/dark/rc/base_icon.png new file mode 100644 index 000000000..bb00857a4 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/base_icon.png differ diff --git a/src/qt/qdarkstyle/dark/rc/base_icon@2x.png b/src/qt/qdarkstyle/dark/rc/base_icon@2x.png new file mode 100644 index 000000000..bc4ab78a2 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/base_icon@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/base_icon_disabled.png b/src/qt/qdarkstyle/dark/rc/base_icon_disabled.png new file mode 100644 index 000000000..bb00857a4 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/base_icon_disabled.png differ diff --git a/src/qt/qdarkstyle/dark/rc/base_icon_disabled@2x.png b/src/qt/qdarkstyle/dark/rc/base_icon_disabled@2x.png new file mode 100644 index 000000000..bc4ab78a2 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/base_icon_disabled@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/base_icon_focus.png b/src/qt/qdarkstyle/dark/rc/base_icon_focus.png new file mode 100644 index 000000000..bb00857a4 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/base_icon_focus.png differ diff --git a/src/qt/qdarkstyle/dark/rc/base_icon_focus@2x.png b/src/qt/qdarkstyle/dark/rc/base_icon_focus@2x.png new file mode 100644 index 000000000..bc4ab78a2 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/base_icon_focus@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/base_icon_pressed.png b/src/qt/qdarkstyle/dark/rc/base_icon_pressed.png new file mode 100644 index 000000000..bb00857a4 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/base_icon_pressed.png differ diff --git a/src/qt/qdarkstyle/dark/rc/base_icon_pressed@2x.png b/src/qt/qdarkstyle/dark/rc/base_icon_pressed@2x.png new file mode 100644 index 000000000..bc4ab78a2 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/base_icon_pressed@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/branch_closed.png b/src/qt/qdarkstyle/dark/rc/branch_closed.png new file mode 100644 index 000000000..4c152b795 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/branch_closed.png differ diff --git a/src/qt/qdarkstyle/dark/rc/branch_closed@2x.png b/src/qt/qdarkstyle/dark/rc/branch_closed@2x.png new file mode 100644 index 000000000..a641a550b Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/branch_closed@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/branch_closed_disabled.png b/src/qt/qdarkstyle/dark/rc/branch_closed_disabled.png new file mode 100644 index 000000000..165fae29b Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/branch_closed_disabled.png differ diff --git a/src/qt/qdarkstyle/dark/rc/branch_closed_disabled@2x.png b/src/qt/qdarkstyle/dark/rc/branch_closed_disabled@2x.png new file mode 100644 index 000000000..421e8e094 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/branch_closed_disabled@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/branch_closed_focus.png b/src/qt/qdarkstyle/dark/rc/branch_closed_focus.png new file mode 100644 index 000000000..ccc249a59 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/branch_closed_focus.png differ diff --git a/src/qt/qdarkstyle/dark/rc/branch_closed_focus@2x.png b/src/qt/qdarkstyle/dark/rc/branch_closed_focus@2x.png new file mode 100644 index 000000000..88dd0a62b Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/branch_closed_focus@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/branch_closed_pressed.png b/src/qt/qdarkstyle/dark/rc/branch_closed_pressed.png new file mode 100644 index 000000000..2aae68a0a Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/branch_closed_pressed.png differ diff --git a/src/qt/qdarkstyle/dark/rc/branch_closed_pressed@2x.png b/src/qt/qdarkstyle/dark/rc/branch_closed_pressed@2x.png new file mode 100644 index 000000000..3849a7ff0 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/branch_closed_pressed@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/branch_end.png b/src/qt/qdarkstyle/dark/rc/branch_end.png new file mode 100644 index 000000000..f92994650 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/branch_end.png differ diff --git a/src/qt/qdarkstyle/dark/rc/branch_end@2x.png b/src/qt/qdarkstyle/dark/rc/branch_end@2x.png new file mode 100644 index 000000000..582832220 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/branch_end@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/branch_end_disabled.png b/src/qt/qdarkstyle/dark/rc/branch_end_disabled.png new file mode 100644 index 000000000..bb4344c78 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/branch_end_disabled.png differ diff --git a/src/qt/qdarkstyle/dark/rc/branch_end_disabled@2x.png b/src/qt/qdarkstyle/dark/rc/branch_end_disabled@2x.png new file mode 100644 index 000000000..8feb46d46 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/branch_end_disabled@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/branch_end_focus.png b/src/qt/qdarkstyle/dark/rc/branch_end_focus.png new file mode 100644 index 000000000..ff713cf5f Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/branch_end_focus.png differ diff --git a/src/qt/qdarkstyle/dark/rc/branch_end_focus@2x.png b/src/qt/qdarkstyle/dark/rc/branch_end_focus@2x.png new file mode 100644 index 000000000..0bd0e4ba3 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/branch_end_focus@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/branch_end_pressed.png b/src/qt/qdarkstyle/dark/rc/branch_end_pressed.png new file mode 100644 index 000000000..2020162f2 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/branch_end_pressed.png differ diff --git a/src/qt/qdarkstyle/dark/rc/branch_end_pressed@2x.png b/src/qt/qdarkstyle/dark/rc/branch_end_pressed@2x.png new file mode 100644 index 000000000..2a5c4fabf Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/branch_end_pressed@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/branch_line.png b/src/qt/qdarkstyle/dark/rc/branch_line.png new file mode 100644 index 000000000..2e8c72ab6 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/branch_line.png differ diff --git a/src/qt/qdarkstyle/dark/rc/branch_line@2x.png b/src/qt/qdarkstyle/dark/rc/branch_line@2x.png new file mode 100644 index 000000000..c8f07af31 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/branch_line@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/branch_line_disabled.png b/src/qt/qdarkstyle/dark/rc/branch_line_disabled.png new file mode 100644 index 000000000..9c8c47b3d Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/branch_line_disabled.png differ diff --git a/src/qt/qdarkstyle/dark/rc/branch_line_disabled@2x.png b/src/qt/qdarkstyle/dark/rc/branch_line_disabled@2x.png new file mode 100644 index 000000000..9b868f2a5 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/branch_line_disabled@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/branch_line_focus.png b/src/qt/qdarkstyle/dark/rc/branch_line_focus.png new file mode 100644 index 000000000..c2ab3e19e Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/branch_line_focus.png differ diff --git a/src/qt/qdarkstyle/dark/rc/branch_line_focus@2x.png b/src/qt/qdarkstyle/dark/rc/branch_line_focus@2x.png new file mode 100644 index 000000000..512ee13a2 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/branch_line_focus@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/branch_line_pressed.png b/src/qt/qdarkstyle/dark/rc/branch_line_pressed.png new file mode 100644 index 000000000..3ca15c5d0 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/branch_line_pressed.png differ diff --git a/src/qt/qdarkstyle/dark/rc/branch_line_pressed@2x.png b/src/qt/qdarkstyle/dark/rc/branch_line_pressed@2x.png new file mode 100644 index 000000000..368553102 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/branch_line_pressed@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/branch_more.png b/src/qt/qdarkstyle/dark/rc/branch_more.png new file mode 100644 index 000000000..976354bc4 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/branch_more.png differ diff --git a/src/qt/qdarkstyle/dark/rc/branch_more@2x.png b/src/qt/qdarkstyle/dark/rc/branch_more@2x.png new file mode 100644 index 000000000..9c1ab07d0 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/branch_more@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/branch_more_disabled.png b/src/qt/qdarkstyle/dark/rc/branch_more_disabled.png new file mode 100644 index 000000000..29d99a63e Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/branch_more_disabled.png differ diff --git a/src/qt/qdarkstyle/dark/rc/branch_more_disabled@2x.png b/src/qt/qdarkstyle/dark/rc/branch_more_disabled@2x.png new file mode 100644 index 000000000..aba830362 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/branch_more_disabled@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/branch_more_focus.png b/src/qt/qdarkstyle/dark/rc/branch_more_focus.png new file mode 100644 index 000000000..20a6f27b8 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/branch_more_focus.png differ diff --git a/src/qt/qdarkstyle/dark/rc/branch_more_focus@2x.png b/src/qt/qdarkstyle/dark/rc/branch_more_focus@2x.png new file mode 100644 index 000000000..6f42eea84 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/branch_more_focus@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/branch_more_pressed.png b/src/qt/qdarkstyle/dark/rc/branch_more_pressed.png new file mode 100644 index 000000000..4f4d9fb91 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/branch_more_pressed.png differ diff --git a/src/qt/qdarkstyle/dark/rc/branch_more_pressed@2x.png b/src/qt/qdarkstyle/dark/rc/branch_more_pressed@2x.png new file mode 100644 index 000000000..5f18f8341 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/branch_more_pressed@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/branch_open.png b/src/qt/qdarkstyle/dark/rc/branch_open.png new file mode 100644 index 000000000..fdf0f8b43 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/branch_open.png differ diff --git a/src/qt/qdarkstyle/dark/rc/branch_open@2x.png b/src/qt/qdarkstyle/dark/rc/branch_open@2x.png new file mode 100644 index 000000000..703cd6af3 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/branch_open@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/branch_open_disabled.png b/src/qt/qdarkstyle/dark/rc/branch_open_disabled.png new file mode 100644 index 000000000..8328e84d7 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/branch_open_disabled.png differ diff --git a/src/qt/qdarkstyle/dark/rc/branch_open_disabled@2x.png b/src/qt/qdarkstyle/dark/rc/branch_open_disabled@2x.png new file mode 100644 index 000000000..d8d0faecb Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/branch_open_disabled@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/branch_open_focus.png b/src/qt/qdarkstyle/dark/rc/branch_open_focus.png new file mode 100644 index 000000000..711ce0979 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/branch_open_focus.png differ diff --git a/src/qt/qdarkstyle/dark/rc/branch_open_focus@2x.png b/src/qt/qdarkstyle/dark/rc/branch_open_focus@2x.png new file mode 100644 index 000000000..b38e17a33 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/branch_open_focus@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/branch_open_pressed.png b/src/qt/qdarkstyle/dark/rc/branch_open_pressed.png new file mode 100644 index 000000000..441c27344 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/branch_open_pressed.png differ diff --git a/src/qt/qdarkstyle/dark/rc/branch_open_pressed@2x.png b/src/qt/qdarkstyle/dark/rc/branch_open_pressed@2x.png new file mode 100644 index 000000000..0e43e8b73 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/branch_open_pressed@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/checkbox_checked.png b/src/qt/qdarkstyle/dark/rc/checkbox_checked.png new file mode 100644 index 000000000..3687e56c0 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/checkbox_checked.png differ diff --git a/src/qt/qdarkstyle/dark/rc/checkbox_checked@2x.png b/src/qt/qdarkstyle/dark/rc/checkbox_checked@2x.png new file mode 100644 index 000000000..e7a6b1afe Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/checkbox_checked@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/checkbox_checked_disabled.png b/src/qt/qdarkstyle/dark/rc/checkbox_checked_disabled.png new file mode 100644 index 000000000..e3cb2f127 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/checkbox_checked_disabled.png differ diff --git a/src/qt/qdarkstyle/dark/rc/checkbox_checked_disabled@2x.png b/src/qt/qdarkstyle/dark/rc/checkbox_checked_disabled@2x.png new file mode 100644 index 000000000..0c8c28a24 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/checkbox_checked_disabled@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/checkbox_checked_focus.png b/src/qt/qdarkstyle/dark/rc/checkbox_checked_focus.png new file mode 100644 index 000000000..58982ce87 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/checkbox_checked_focus.png differ diff --git a/src/qt/qdarkstyle/dark/rc/checkbox_checked_focus@2x.png b/src/qt/qdarkstyle/dark/rc/checkbox_checked_focus@2x.png new file mode 100644 index 000000000..ba33ba4fb Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/checkbox_checked_focus@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/checkbox_checked_pressed.png b/src/qt/qdarkstyle/dark/rc/checkbox_checked_pressed.png new file mode 100644 index 000000000..f104bb240 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/checkbox_checked_pressed.png differ diff --git a/src/qt/qdarkstyle/dark/rc/checkbox_checked_pressed@2x.png b/src/qt/qdarkstyle/dark/rc/checkbox_checked_pressed@2x.png new file mode 100644 index 000000000..bb972d68f Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/checkbox_checked_pressed@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/checkbox_indeterminate.png b/src/qt/qdarkstyle/dark/rc/checkbox_indeterminate.png new file mode 100644 index 000000000..8159551de Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/checkbox_indeterminate.png differ diff --git a/src/qt/qdarkstyle/dark/rc/checkbox_indeterminate@2x.png b/src/qt/qdarkstyle/dark/rc/checkbox_indeterminate@2x.png new file mode 100644 index 000000000..75864b46d Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/checkbox_indeterminate@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/checkbox_indeterminate_disabled.png b/src/qt/qdarkstyle/dark/rc/checkbox_indeterminate_disabled.png new file mode 100644 index 000000000..181625a00 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/checkbox_indeterminate_disabled.png differ diff --git a/src/qt/qdarkstyle/dark/rc/checkbox_indeterminate_disabled@2x.png b/src/qt/qdarkstyle/dark/rc/checkbox_indeterminate_disabled@2x.png new file mode 100644 index 000000000..0d32c78f3 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/checkbox_indeterminate_disabled@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/checkbox_indeterminate_focus.png b/src/qt/qdarkstyle/dark/rc/checkbox_indeterminate_focus.png new file mode 100644 index 000000000..d7b19f61a Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/checkbox_indeterminate_focus.png differ diff --git a/src/qt/qdarkstyle/dark/rc/checkbox_indeterminate_focus@2x.png b/src/qt/qdarkstyle/dark/rc/checkbox_indeterminate_focus@2x.png new file mode 100644 index 000000000..d6403ca42 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/checkbox_indeterminate_focus@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/checkbox_indeterminate_pressed.png b/src/qt/qdarkstyle/dark/rc/checkbox_indeterminate_pressed.png new file mode 100644 index 000000000..37f46ca3d Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/checkbox_indeterminate_pressed.png differ diff --git a/src/qt/qdarkstyle/dark/rc/checkbox_indeterminate_pressed@2x.png b/src/qt/qdarkstyle/dark/rc/checkbox_indeterminate_pressed@2x.png new file mode 100644 index 000000000..aa7493edc Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/checkbox_indeterminate_pressed@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/checkbox_unchecked.png b/src/qt/qdarkstyle/dark/rc/checkbox_unchecked.png new file mode 100644 index 000000000..e363ed620 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/checkbox_unchecked.png differ diff --git a/src/qt/qdarkstyle/dark/rc/checkbox_unchecked@2x.png b/src/qt/qdarkstyle/dark/rc/checkbox_unchecked@2x.png new file mode 100644 index 000000000..520f5e2a2 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/checkbox_unchecked@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/checkbox_unchecked_disabled.png b/src/qt/qdarkstyle/dark/rc/checkbox_unchecked_disabled.png new file mode 100644 index 000000000..066185ee7 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/checkbox_unchecked_disabled.png differ diff --git a/src/qt/qdarkstyle/dark/rc/checkbox_unchecked_disabled@2x.png b/src/qt/qdarkstyle/dark/rc/checkbox_unchecked_disabled@2x.png new file mode 100644 index 000000000..9c80ad75a Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/checkbox_unchecked_disabled@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/checkbox_unchecked_focus.png b/src/qt/qdarkstyle/dark/rc/checkbox_unchecked_focus.png new file mode 100644 index 000000000..366b868de Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/checkbox_unchecked_focus.png differ diff --git a/src/qt/qdarkstyle/dark/rc/checkbox_unchecked_focus@2x.png b/src/qt/qdarkstyle/dark/rc/checkbox_unchecked_focus@2x.png new file mode 100644 index 000000000..4ab217356 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/checkbox_unchecked_focus@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/checkbox_unchecked_pressed.png b/src/qt/qdarkstyle/dark/rc/checkbox_unchecked_pressed.png new file mode 100644 index 000000000..d9a0bf71c Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/checkbox_unchecked_pressed.png differ diff --git a/src/qt/qdarkstyle/dark/rc/checkbox_unchecked_pressed@2x.png b/src/qt/qdarkstyle/dark/rc/checkbox_unchecked_pressed@2x.png new file mode 100644 index 000000000..9e2b0515e Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/checkbox_unchecked_pressed@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/line_horizontal.png b/src/qt/qdarkstyle/dark/rc/line_horizontal.png new file mode 100644 index 000000000..4f88ddf7b Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/line_horizontal.png differ diff --git a/src/qt/qdarkstyle/dark/rc/line_horizontal@2x.png b/src/qt/qdarkstyle/dark/rc/line_horizontal@2x.png new file mode 100644 index 000000000..63be00c16 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/line_horizontal@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/line_horizontal_disabled.png b/src/qt/qdarkstyle/dark/rc/line_horizontal_disabled.png new file mode 100644 index 000000000..941f14a38 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/line_horizontal_disabled.png differ diff --git a/src/qt/qdarkstyle/dark/rc/line_horizontal_disabled@2x.png b/src/qt/qdarkstyle/dark/rc/line_horizontal_disabled@2x.png new file mode 100644 index 000000000..972fa0800 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/line_horizontal_disabled@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/line_horizontal_focus.png b/src/qt/qdarkstyle/dark/rc/line_horizontal_focus.png new file mode 100644 index 000000000..221fd4607 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/line_horizontal_focus.png differ diff --git a/src/qt/qdarkstyle/dark/rc/line_horizontal_focus@2x.png b/src/qt/qdarkstyle/dark/rc/line_horizontal_focus@2x.png new file mode 100644 index 000000000..7e6505cae Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/line_horizontal_focus@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/line_horizontal_pressed.png b/src/qt/qdarkstyle/dark/rc/line_horizontal_pressed.png new file mode 100644 index 000000000..9f9113323 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/line_horizontal_pressed.png differ diff --git a/src/qt/qdarkstyle/dark/rc/line_horizontal_pressed@2x.png b/src/qt/qdarkstyle/dark/rc/line_horizontal_pressed@2x.png new file mode 100644 index 000000000..465680c3b Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/line_horizontal_pressed@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/line_vertical.png b/src/qt/qdarkstyle/dark/rc/line_vertical.png new file mode 100644 index 000000000..6ee62c156 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/line_vertical.png differ diff --git a/src/qt/qdarkstyle/dark/rc/line_vertical@2x.png b/src/qt/qdarkstyle/dark/rc/line_vertical@2x.png new file mode 100644 index 000000000..d65e74c62 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/line_vertical@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/line_vertical_disabled.png b/src/qt/qdarkstyle/dark/rc/line_vertical_disabled.png new file mode 100644 index 000000000..c7c4c8959 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/line_vertical_disabled.png differ diff --git a/src/qt/qdarkstyle/dark/rc/line_vertical_disabled@2x.png b/src/qt/qdarkstyle/dark/rc/line_vertical_disabled@2x.png new file mode 100644 index 000000000..b052de522 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/line_vertical_disabled@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/line_vertical_focus.png b/src/qt/qdarkstyle/dark/rc/line_vertical_focus.png new file mode 100644 index 000000000..36baa0936 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/line_vertical_focus.png differ diff --git a/src/qt/qdarkstyle/dark/rc/line_vertical_focus@2x.png b/src/qt/qdarkstyle/dark/rc/line_vertical_focus@2x.png new file mode 100644 index 000000000..24a2b771c Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/line_vertical_focus@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/line_vertical_pressed.png b/src/qt/qdarkstyle/dark/rc/line_vertical_pressed.png new file mode 100644 index 000000000..60e357446 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/line_vertical_pressed.png differ diff --git a/src/qt/qdarkstyle/dark/rc/line_vertical_pressed@2x.png b/src/qt/qdarkstyle/dark/rc/line_vertical_pressed@2x.png new file mode 100644 index 000000000..c9494051c Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/line_vertical_pressed@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/radio_checked.png b/src/qt/qdarkstyle/dark/rc/radio_checked.png new file mode 100644 index 000000000..acb890155 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/radio_checked.png differ diff --git a/src/qt/qdarkstyle/dark/rc/radio_checked@2x.png b/src/qt/qdarkstyle/dark/rc/radio_checked@2x.png new file mode 100644 index 000000000..e19047621 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/radio_checked@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/radio_checked_disabled.png b/src/qt/qdarkstyle/dark/rc/radio_checked_disabled.png new file mode 100644 index 000000000..49df43922 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/radio_checked_disabled.png differ diff --git a/src/qt/qdarkstyle/dark/rc/radio_checked_disabled@2x.png b/src/qt/qdarkstyle/dark/rc/radio_checked_disabled@2x.png new file mode 100644 index 000000000..a9ffd40ce Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/radio_checked_disabled@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/radio_checked_focus.png b/src/qt/qdarkstyle/dark/rc/radio_checked_focus.png new file mode 100644 index 000000000..4bd472e16 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/radio_checked_focus.png differ diff --git a/src/qt/qdarkstyle/dark/rc/radio_checked_focus@2x.png b/src/qt/qdarkstyle/dark/rc/radio_checked_focus@2x.png new file mode 100644 index 000000000..aed5e0c94 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/radio_checked_focus@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/radio_checked_pressed.png b/src/qt/qdarkstyle/dark/rc/radio_checked_pressed.png new file mode 100644 index 000000000..ebb323b8c Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/radio_checked_pressed.png differ diff --git a/src/qt/qdarkstyle/dark/rc/radio_checked_pressed@2x.png b/src/qt/qdarkstyle/dark/rc/radio_checked_pressed@2x.png new file mode 100644 index 000000000..ffe0fd851 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/radio_checked_pressed@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/radio_unchecked.png b/src/qt/qdarkstyle/dark/rc/radio_unchecked.png new file mode 100644 index 000000000..9ffddc4a0 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/radio_unchecked.png differ diff --git a/src/qt/qdarkstyle/dark/rc/radio_unchecked@2x.png b/src/qt/qdarkstyle/dark/rc/radio_unchecked@2x.png new file mode 100644 index 000000000..2160a32ed Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/radio_unchecked@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/radio_unchecked_disabled.png b/src/qt/qdarkstyle/dark/rc/radio_unchecked_disabled.png new file mode 100644 index 000000000..7ddff642d Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/radio_unchecked_disabled.png differ diff --git a/src/qt/qdarkstyle/dark/rc/radio_unchecked_disabled@2x.png b/src/qt/qdarkstyle/dark/rc/radio_unchecked_disabled@2x.png new file mode 100644 index 000000000..4de5d0d2d Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/radio_unchecked_disabled@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/radio_unchecked_focus.png b/src/qt/qdarkstyle/dark/rc/radio_unchecked_focus.png new file mode 100644 index 000000000..e62b996b1 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/radio_unchecked_focus.png differ diff --git a/src/qt/qdarkstyle/dark/rc/radio_unchecked_focus@2x.png b/src/qt/qdarkstyle/dark/rc/radio_unchecked_focus@2x.png new file mode 100644 index 000000000..eaf7bc26b Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/radio_unchecked_focus@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/radio_unchecked_pressed.png b/src/qt/qdarkstyle/dark/rc/radio_unchecked_pressed.png new file mode 100644 index 000000000..8aaa343e8 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/radio_unchecked_pressed.png differ diff --git a/src/qt/qdarkstyle/dark/rc/radio_unchecked_pressed@2x.png b/src/qt/qdarkstyle/dark/rc/radio_unchecked_pressed@2x.png new file mode 100644 index 000000000..ba4f83b91 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/radio_unchecked_pressed@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/toolbar_move_horizontal.png b/src/qt/qdarkstyle/dark/rc/toolbar_move_horizontal.png new file mode 100644 index 000000000..fa449d6ee Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/toolbar_move_horizontal.png differ diff --git a/src/qt/qdarkstyle/dark/rc/toolbar_move_horizontal@2x.png b/src/qt/qdarkstyle/dark/rc/toolbar_move_horizontal@2x.png new file mode 100644 index 000000000..682575ee2 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/toolbar_move_horizontal@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/toolbar_move_horizontal_disabled.png b/src/qt/qdarkstyle/dark/rc/toolbar_move_horizontal_disabled.png new file mode 100644 index 000000000..568b0fbe1 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/toolbar_move_horizontal_disabled.png differ diff --git a/src/qt/qdarkstyle/dark/rc/toolbar_move_horizontal_disabled@2x.png b/src/qt/qdarkstyle/dark/rc/toolbar_move_horizontal_disabled@2x.png new file mode 100644 index 000000000..4d15f1478 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/toolbar_move_horizontal_disabled@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/toolbar_move_horizontal_focus.png b/src/qt/qdarkstyle/dark/rc/toolbar_move_horizontal_focus.png new file mode 100644 index 000000000..cdb96bfb9 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/toolbar_move_horizontal_focus.png differ diff --git a/src/qt/qdarkstyle/dark/rc/toolbar_move_horizontal_focus@2x.png b/src/qt/qdarkstyle/dark/rc/toolbar_move_horizontal_focus@2x.png new file mode 100644 index 000000000..23e06a015 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/toolbar_move_horizontal_focus@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/toolbar_move_horizontal_pressed.png b/src/qt/qdarkstyle/dark/rc/toolbar_move_horizontal_pressed.png new file mode 100644 index 000000000..9ce6f8d89 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/toolbar_move_horizontal_pressed.png differ diff --git a/src/qt/qdarkstyle/dark/rc/toolbar_move_horizontal_pressed@2x.png b/src/qt/qdarkstyle/dark/rc/toolbar_move_horizontal_pressed@2x.png new file mode 100644 index 000000000..4d8e53e8e Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/toolbar_move_horizontal_pressed@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/toolbar_move_vertical.png b/src/qt/qdarkstyle/dark/rc/toolbar_move_vertical.png new file mode 100644 index 000000000..bbc8abb1f Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/toolbar_move_vertical.png differ diff --git a/src/qt/qdarkstyle/dark/rc/toolbar_move_vertical@2x.png b/src/qt/qdarkstyle/dark/rc/toolbar_move_vertical@2x.png new file mode 100644 index 000000000..136ebae2c Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/toolbar_move_vertical@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/toolbar_move_vertical_disabled.png b/src/qt/qdarkstyle/dark/rc/toolbar_move_vertical_disabled.png new file mode 100644 index 000000000..37453ac25 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/toolbar_move_vertical_disabled.png differ diff --git a/src/qt/qdarkstyle/dark/rc/toolbar_move_vertical_disabled@2x.png b/src/qt/qdarkstyle/dark/rc/toolbar_move_vertical_disabled@2x.png new file mode 100644 index 000000000..cca8f6d96 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/toolbar_move_vertical_disabled@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/toolbar_move_vertical_focus.png b/src/qt/qdarkstyle/dark/rc/toolbar_move_vertical_focus.png new file mode 100644 index 000000000..b54877181 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/toolbar_move_vertical_focus.png differ diff --git a/src/qt/qdarkstyle/dark/rc/toolbar_move_vertical_focus@2x.png b/src/qt/qdarkstyle/dark/rc/toolbar_move_vertical_focus@2x.png new file mode 100644 index 000000000..d4dd49dec Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/toolbar_move_vertical_focus@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/toolbar_move_vertical_pressed.png b/src/qt/qdarkstyle/dark/rc/toolbar_move_vertical_pressed.png new file mode 100644 index 000000000..768ebaf4c Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/toolbar_move_vertical_pressed.png differ diff --git a/src/qt/qdarkstyle/dark/rc/toolbar_move_vertical_pressed@2x.png b/src/qt/qdarkstyle/dark/rc/toolbar_move_vertical_pressed@2x.png new file mode 100644 index 000000000..2f170ffd8 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/toolbar_move_vertical_pressed@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/toolbar_separator_horizontal.png b/src/qt/qdarkstyle/dark/rc/toolbar_separator_horizontal.png new file mode 100644 index 000000000..01e350132 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/toolbar_separator_horizontal.png differ diff --git a/src/qt/qdarkstyle/dark/rc/toolbar_separator_horizontal@2x.png b/src/qt/qdarkstyle/dark/rc/toolbar_separator_horizontal@2x.png new file mode 100644 index 000000000..68d768e5e Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/toolbar_separator_horizontal@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/toolbar_separator_horizontal_disabled.png b/src/qt/qdarkstyle/dark/rc/toolbar_separator_horizontal_disabled.png new file mode 100644 index 000000000..f8796f9e6 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/toolbar_separator_horizontal_disabled.png differ diff --git a/src/qt/qdarkstyle/dark/rc/toolbar_separator_horizontal_disabled@2x.png b/src/qt/qdarkstyle/dark/rc/toolbar_separator_horizontal_disabled@2x.png new file mode 100644 index 000000000..1d9f20421 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/toolbar_separator_horizontal_disabled@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/toolbar_separator_horizontal_focus.png b/src/qt/qdarkstyle/dark/rc/toolbar_separator_horizontal_focus.png new file mode 100644 index 000000000..b592e61c1 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/toolbar_separator_horizontal_focus.png differ diff --git a/src/qt/qdarkstyle/dark/rc/toolbar_separator_horizontal_focus@2x.png b/src/qt/qdarkstyle/dark/rc/toolbar_separator_horizontal_focus@2x.png new file mode 100644 index 000000000..a593a7e76 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/toolbar_separator_horizontal_focus@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/toolbar_separator_horizontal_pressed.png b/src/qt/qdarkstyle/dark/rc/toolbar_separator_horizontal_pressed.png new file mode 100644 index 000000000..a806257e0 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/toolbar_separator_horizontal_pressed.png differ diff --git a/src/qt/qdarkstyle/dark/rc/toolbar_separator_horizontal_pressed@2x.png b/src/qt/qdarkstyle/dark/rc/toolbar_separator_horizontal_pressed@2x.png new file mode 100644 index 000000000..e1e8e3c14 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/toolbar_separator_horizontal_pressed@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/toolbar_separator_vertical.png b/src/qt/qdarkstyle/dark/rc/toolbar_separator_vertical.png new file mode 100644 index 000000000..2a14f5cbd Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/toolbar_separator_vertical.png differ diff --git a/src/qt/qdarkstyle/dark/rc/toolbar_separator_vertical@2x.png b/src/qt/qdarkstyle/dark/rc/toolbar_separator_vertical@2x.png new file mode 100644 index 000000000..35371feea Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/toolbar_separator_vertical@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/toolbar_separator_vertical_disabled.png b/src/qt/qdarkstyle/dark/rc/toolbar_separator_vertical_disabled.png new file mode 100644 index 000000000..48b2657f5 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/toolbar_separator_vertical_disabled.png differ diff --git a/src/qt/qdarkstyle/dark/rc/toolbar_separator_vertical_disabled@2x.png b/src/qt/qdarkstyle/dark/rc/toolbar_separator_vertical_disabled@2x.png new file mode 100644 index 000000000..a2173c5ee Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/toolbar_separator_vertical_disabled@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/toolbar_separator_vertical_focus.png b/src/qt/qdarkstyle/dark/rc/toolbar_separator_vertical_focus.png new file mode 100644 index 000000000..e31c694b0 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/toolbar_separator_vertical_focus.png differ diff --git a/src/qt/qdarkstyle/dark/rc/toolbar_separator_vertical_focus@2x.png b/src/qt/qdarkstyle/dark/rc/toolbar_separator_vertical_focus@2x.png new file mode 100644 index 000000000..ce743cc86 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/toolbar_separator_vertical_focus@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/toolbar_separator_vertical_pressed.png b/src/qt/qdarkstyle/dark/rc/toolbar_separator_vertical_pressed.png new file mode 100644 index 000000000..4ee7aaaab Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/toolbar_separator_vertical_pressed.png differ diff --git a/src/qt/qdarkstyle/dark/rc/toolbar_separator_vertical_pressed@2x.png b/src/qt/qdarkstyle/dark/rc/toolbar_separator_vertical_pressed@2x.png new file mode 100644 index 000000000..d8bf93bf6 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/toolbar_separator_vertical_pressed@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/transparent.png b/src/qt/qdarkstyle/dark/rc/transparent.png new file mode 100644 index 000000000..67753617f Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/transparent.png differ diff --git a/src/qt/qdarkstyle/dark/rc/transparent@2x.png b/src/qt/qdarkstyle/dark/rc/transparent@2x.png new file mode 100644 index 000000000..4012944b5 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/transparent@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/transparent_disabled.png b/src/qt/qdarkstyle/dark/rc/transparent_disabled.png new file mode 100644 index 000000000..67753617f Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/transparent_disabled.png differ diff --git a/src/qt/qdarkstyle/dark/rc/transparent_disabled@2x.png b/src/qt/qdarkstyle/dark/rc/transparent_disabled@2x.png new file mode 100644 index 000000000..4012944b5 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/transparent_disabled@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/transparent_focus.png b/src/qt/qdarkstyle/dark/rc/transparent_focus.png new file mode 100644 index 000000000..67753617f Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/transparent_focus.png differ diff --git a/src/qt/qdarkstyle/dark/rc/transparent_focus@2x.png b/src/qt/qdarkstyle/dark/rc/transparent_focus@2x.png new file mode 100644 index 000000000..4012944b5 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/transparent_focus@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/transparent_pressed.png b/src/qt/qdarkstyle/dark/rc/transparent_pressed.png new file mode 100644 index 000000000..67753617f Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/transparent_pressed.png differ diff --git a/src/qt/qdarkstyle/dark/rc/transparent_pressed@2x.png b/src/qt/qdarkstyle/dark/rc/transparent_pressed@2x.png new file mode 100644 index 000000000..4012944b5 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/transparent_pressed@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/window_close.png b/src/qt/qdarkstyle/dark/rc/window_close.png new file mode 100644 index 000000000..0b67d3bcc Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/window_close.png differ diff --git a/src/qt/qdarkstyle/dark/rc/window_close@2x.png b/src/qt/qdarkstyle/dark/rc/window_close@2x.png new file mode 100644 index 000000000..bb8ac7da5 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/window_close@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/window_close_disabled.png b/src/qt/qdarkstyle/dark/rc/window_close_disabled.png new file mode 100644 index 000000000..46de804b8 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/window_close_disabled.png differ diff --git a/src/qt/qdarkstyle/dark/rc/window_close_disabled@2x.png b/src/qt/qdarkstyle/dark/rc/window_close_disabled@2x.png new file mode 100644 index 000000000..8e4cd15d8 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/window_close_disabled@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/window_close_focus.png b/src/qt/qdarkstyle/dark/rc/window_close_focus.png new file mode 100644 index 000000000..bb7d8c511 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/window_close_focus.png differ diff --git a/src/qt/qdarkstyle/dark/rc/window_close_focus@2x.png b/src/qt/qdarkstyle/dark/rc/window_close_focus@2x.png new file mode 100644 index 000000000..692ce24f2 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/window_close_focus@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/window_close_pressed.png b/src/qt/qdarkstyle/dark/rc/window_close_pressed.png new file mode 100644 index 000000000..53ae7f38e Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/window_close_pressed.png differ diff --git a/src/qt/qdarkstyle/dark/rc/window_close_pressed@2x.png b/src/qt/qdarkstyle/dark/rc/window_close_pressed@2x.png new file mode 100644 index 000000000..e02b12292 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/window_close_pressed@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/window_grip.png b/src/qt/qdarkstyle/dark/rc/window_grip.png new file mode 100644 index 000000000..db9ccb877 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/window_grip.png differ diff --git a/src/qt/qdarkstyle/dark/rc/window_grip@2x.png b/src/qt/qdarkstyle/dark/rc/window_grip@2x.png new file mode 100644 index 000000000..30b0639f4 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/window_grip@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/window_grip_disabled.png b/src/qt/qdarkstyle/dark/rc/window_grip_disabled.png new file mode 100644 index 000000000..97c0e0f90 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/window_grip_disabled.png differ diff --git a/src/qt/qdarkstyle/dark/rc/window_grip_disabled@2x.png b/src/qt/qdarkstyle/dark/rc/window_grip_disabled@2x.png new file mode 100644 index 000000000..7a3d8de6d Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/window_grip_disabled@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/window_grip_focus.png b/src/qt/qdarkstyle/dark/rc/window_grip_focus.png new file mode 100644 index 000000000..99b27c9ce Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/window_grip_focus.png differ diff --git a/src/qt/qdarkstyle/dark/rc/window_grip_focus@2x.png b/src/qt/qdarkstyle/dark/rc/window_grip_focus@2x.png new file mode 100644 index 000000000..833cb90a9 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/window_grip_focus@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/window_grip_pressed.png b/src/qt/qdarkstyle/dark/rc/window_grip_pressed.png new file mode 100644 index 000000000..afea9749e Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/window_grip_pressed.png differ diff --git a/src/qt/qdarkstyle/dark/rc/window_grip_pressed@2x.png b/src/qt/qdarkstyle/dark/rc/window_grip_pressed@2x.png new file mode 100644 index 000000000..c1c1a0e4b Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/window_grip_pressed@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/window_minimize.png b/src/qt/qdarkstyle/dark/rc/window_minimize.png new file mode 100644 index 000000000..d8c54ebf2 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/window_minimize.png differ diff --git a/src/qt/qdarkstyle/dark/rc/window_minimize@2x.png b/src/qt/qdarkstyle/dark/rc/window_minimize@2x.png new file mode 100644 index 000000000..5421a3690 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/window_minimize@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/window_minimize_disabled.png b/src/qt/qdarkstyle/dark/rc/window_minimize_disabled.png new file mode 100644 index 000000000..cc51ed0ee Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/window_minimize_disabled.png differ diff --git a/src/qt/qdarkstyle/dark/rc/window_minimize_disabled@2x.png b/src/qt/qdarkstyle/dark/rc/window_minimize_disabled@2x.png new file mode 100644 index 000000000..c1676469f Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/window_minimize_disabled@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/window_minimize_focus.png b/src/qt/qdarkstyle/dark/rc/window_minimize_focus.png new file mode 100644 index 000000000..1dcd083c0 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/window_minimize_focus.png differ diff --git a/src/qt/qdarkstyle/dark/rc/window_minimize_focus@2x.png b/src/qt/qdarkstyle/dark/rc/window_minimize_focus@2x.png new file mode 100644 index 000000000..2a4c868e0 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/window_minimize_focus@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/window_minimize_pressed.png b/src/qt/qdarkstyle/dark/rc/window_minimize_pressed.png new file mode 100644 index 000000000..0bb532126 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/window_minimize_pressed.png differ diff --git a/src/qt/qdarkstyle/dark/rc/window_minimize_pressed@2x.png b/src/qt/qdarkstyle/dark/rc/window_minimize_pressed@2x.png new file mode 100644 index 000000000..5a515c806 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/window_minimize_pressed@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/window_undock.png b/src/qt/qdarkstyle/dark/rc/window_undock.png new file mode 100644 index 000000000..d1f454259 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/window_undock.png differ diff --git a/src/qt/qdarkstyle/dark/rc/window_undock@2x.png b/src/qt/qdarkstyle/dark/rc/window_undock@2x.png new file mode 100644 index 000000000..f0efa3429 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/window_undock@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/window_undock_disabled.png b/src/qt/qdarkstyle/dark/rc/window_undock_disabled.png new file mode 100644 index 000000000..6a609492b Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/window_undock_disabled.png differ diff --git a/src/qt/qdarkstyle/dark/rc/window_undock_disabled@2x.png b/src/qt/qdarkstyle/dark/rc/window_undock_disabled@2x.png new file mode 100644 index 000000000..c2e1b8fa7 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/window_undock_disabled@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/window_undock_focus.png b/src/qt/qdarkstyle/dark/rc/window_undock_focus.png new file mode 100644 index 000000000..d6eebbdc2 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/window_undock_focus.png differ diff --git a/src/qt/qdarkstyle/dark/rc/window_undock_focus@2x.png b/src/qt/qdarkstyle/dark/rc/window_undock_focus@2x.png new file mode 100644 index 000000000..1aef06053 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/window_undock_focus@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/window_undock_pressed.png b/src/qt/qdarkstyle/dark/rc/window_undock_pressed.png new file mode 100644 index 000000000..8b6beb19e Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/window_undock_pressed.png differ diff --git a/src/qt/qdarkstyle/dark/rc/window_undock_pressed@2x.png b/src/qt/qdarkstyle/dark/rc/window_undock_pressed@2x.png new file mode 100644 index 000000000..677ded425 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/window_undock_pressed@2x.png differ diff --git a/src/qt/qt_joystickconfiguration.cpp b/src/qt/qt_joystickconfiguration.cpp index 8489dfd22..62a9302d1 100644 --- a/src/qt/qt_joystickconfiguration.cpp +++ b/src/qt/qt_joystickconfiguration.cpp @@ -41,7 +41,7 @@ JoystickConfiguration::JoystickConfiguration(int type, int joystick_nr, QWidget Models::AddEntry(model, plat_joystick_state[c].name, c + 1); } - ui->comboBoxDevice->setCurrentIndex(joystick_state[joystick_nr].plat_joystick_nr); + ui->comboBoxDevice->setCurrentIndex(joystick_state[0][joystick_nr].plat_joystick_nr); layout()->setSizeConstraint(QLayout::SetFixedSize); } @@ -119,7 +119,7 @@ JoystickConfiguration::on_comboBoxDevice_currentIndexChanged(int index) } int nr_axes = plat_joystick_state[joystick].nr_axes; - int mapping = joystick_state[joystick_nr].axis_mapping[c]; + int mapping = joystick_state[0][joystick_nr].axis_mapping[c]; if (mapping & POV_X) cbox->setCurrentIndex(nr_axes + (mapping & 3) * 2); else if (mapping & POV_Y) @@ -147,7 +147,7 @@ JoystickConfiguration::on_comboBoxDevice_currentIndexChanged(int index) Models::AddEntry(model, plat_joystick_state[joystick].button[d].name, 0); } - cbox->setCurrentIndex(joystick_state[joystick_nr].button_mapping[c]); + cbox->setCurrentIndex(joystick_state[0][joystick_nr].button_mapping[c]); ui->ct->addWidget(label, row, 0); ui->ct->addWidget(cbox, row, 1); @@ -179,7 +179,7 @@ JoystickConfiguration::on_comboBoxDevice_currentIndexChanged(int index) Models::AddEntry(model, plat_joystick_state[joystick].axis[d].name, 0); } - int mapping = joystick_state[joystick_nr].pov_mapping[c / 2][c & 1]; + int mapping = joystick_state[0][joystick_nr].pov_mapping[c / 2][c & 1]; int nr_povs = plat_joystick_state[joystick].nr_povs; if (mapping & POV_X) cbox->setCurrentIndex((mapping & 3) * 2); diff --git a/src/qt/qt_machinestatus.cpp b/src/qt/qt_machinestatus.cpp index ebc18e198..d1335873c 100644 --- a/src/qt/qt_machinestatus.cpp +++ b/src/qt/qt_machinestatus.cpp @@ -369,12 +369,12 @@ MachineStatus::iterateNIC(const std::function &cb) } static int -hdd_count(int bus) +hdd_count(const int bus_type) { int c = 0; for (uint8_t i = 0; i < HDD_NUM; i++) { - if (hdd[i].bus == bus) { + if (hdd[i].bus_type == bus_type) { c++; } } diff --git a/src/qt/qt_main.cpp b/src/qt/qt_main.cpp index f77370574..72b0eef53 100644 --- a/src/qt/qt_main.cpp +++ b/src/qt/qt_main.cpp @@ -31,6 +31,8 @@ #include #include #include +#include +#include #ifdef QT_STATIC /* Static builds need plugin imports */ @@ -42,15 +44,6 @@ Q_IMPORT_PLUGIN(QWindowsVistaStylePlugin) # endif #endif -#ifdef Q_OS_WINDOWS -# include "qt_rendererstack.hpp" -# include "qt_winrawinputfilter.hpp" -# include "qt_winmanagerfilter.hpp" -# include <86box/win.h> -# include -# include -#endif - extern "C" { #include <86box/86box.h> #include <86box/config.h> @@ -64,6 +57,15 @@ extern "C" { #include <86box/version.h> } +#ifdef Q_OS_WINDOWS +# include "qt_rendererstack.hpp" +# include "qt_winrawinputfilter.hpp" +# include "qt_winmanagerfilter.hpp" +# include <86box/win.h> +# include +# include +#endif + #include #include #include @@ -339,6 +341,10 @@ main_thread_fn() static std::thread *main_thread; +#ifdef Q_OS_WINDOWS +extern bool windows_is_light_theme(); +#endif + int main(int argc, char *argv[]) { @@ -354,6 +360,23 @@ main(int argc, char *argv[]) QApplication app(argc, argv); QLocale::setDefault(QLocale::C); +#ifdef Q_OS_WINDOWS + Q_INIT_RESOURCE(darkstyle); + QApplication::setAttribute(Qt::AA_NativeWindows); + + if (!windows_is_light_theme()) { + QFile f(":qdarkstyle/dark/darkstyle.qss"); + + if (!f.exists()) { + printf("Unable to set stylesheet, file not found\n"); + } else { + f.open(QFile::ReadOnly | QFile::Text); + QTextStream ts(&f); + qApp->setStyleSheet(ts.readAll()); + } + } +#endif + qt_set_sequence_auto_mnemonic(false); Q_INIT_RESOURCE(qt_resources); Q_INIT_RESOURCE(qt_translations); diff --git a/src/qt/qt_mainwindow.hpp b/src/qt/qt_mainwindow.hpp index 9db428051..25e33d77c 100644 --- a/src/qt/qt_mainwindow.hpp +++ b/src/qt/qt_mainwindow.hpp @@ -177,6 +177,7 @@ private: friend class ProgSettings; friend class RendererCommon; friend class RendererStack; // For UI variable access by non-primary renderer windows. + friend class WindowsRawInputFilter; // Needed to reload renderers on style sheet changes. }; #endif // QT_MAINWINDOW_HPP diff --git a/src/qt/qt_mediamenu.cpp b/src/qt/qt_mediamenu.cpp index 902ca10d6..fdea16c2a 100644 --- a/src/qt/qt_mediamenu.cpp +++ b/src/qt/qt_mediamenu.cpp @@ -537,10 +537,7 @@ MediaMenu::cdromMount(int i, const QString &filename) if ((fn.data() != NULL) && (strlen(fn.data()) >= 1) && (fn.data()[strlen(fn.data()) - 1] == '\\')) fn.data()[strlen(fn.data()) - 1] = '/'; #endif - if ((fn.data() != nullptr) && fn.contains("ioctl://")) - cdrom_ioctl_open(&(cdrom[i]), fn.data()); - else - cdrom_image_open(&(cdrom[i]), fn.data()); + cdrom_load(&(cdrom[i]), fn.data(), 1); /* Signal media change to the emulated machine. */ if (cdrom[i].insert) { @@ -806,14 +803,21 @@ MediaMenu::zipSelectImage(int i, bool wp) void MediaMenu::zipMount(int i, const QString &filename, bool wp) { - const auto dev = static_cast(zip_drives[i].priv); + const auto dev = static_cast(zip_drives[i].priv); + int was_empty = zip_is_empty(i); zip_disk_close(dev); zip_drives[i].read_only = wp; if (!filename.isEmpty()) { QByteArray filenameBytes = filename.toUtf8(); - zip_load(dev, filenameBytes.data()); + zip_load(dev, filenameBytes.data(), 1); + + /* Signal media change to the emulated machine. */ zip_insert(dev); + + /* The drive was previously empty, transition directly to UNIT ATTENTION. */ + if (was_empty) + zip_insert(dev); } mhm.addImageToHistory(i, ui::MediaType::Zip, zip_drives[i].prev_image_path, zip_drives[i].image_path); @@ -935,14 +939,21 @@ MediaMenu::moSelectImage(int i, bool wp) void MediaMenu::moMount(int i, const QString &filename, bool wp) { - const auto dev = static_cast(mo_drives[i].priv); + const auto dev = static_cast(mo_drives[i].priv); + int was_empty = mo_is_empty(i); mo_disk_close(dev); mo_drives[i].read_only = wp; if (!filename.isEmpty()) { QByteArray filenameBytes = filename.toUtf8(); - mo_load(dev, filenameBytes.data()); + mo_load(dev, filenameBytes.data(), 1); + + /* Signal media change to the emulated machine. */ mo_insert(dev); + + /* The drive was previously empty, transition directly to UNIT ATTENTION. */ + if (was_empty) + mo_insert(dev); } mhm.addImageToHistory(i, ui::MediaType::Mo, mo_drives[i].prev_image_path, mo_drives[i].image_path); diff --git a/src/qt/qt_platform.cpp b/src/qt/qt_platform.cpp index f8b512f78..dd6c34efc 100644 --- a/src/qt/qt_platform.cpp +++ b/src/qt/qt_platform.cpp @@ -156,6 +156,7 @@ strnicmp(const char *s1, const char *s2, size_t n) void do_start(void) { + // } void @@ -557,7 +558,7 @@ endblit() std::this_thread::sleep_for(std::chrono::milliseconds(1)); } } -} +} /*extern "C" */ #ifdef Q_OS_WINDOWS size_t @@ -595,6 +596,8 @@ c16stombs(char dst[], const uint16_t src[], int len) } #endif +# define MOUSE_CAPTURE_KEYSEQ "F8+F12" + #ifdef _WIN32 # if defined(__amd64__) || defined(_M_X64) || defined(__aarch64__) || defined(_M_ARM64) # define LIB_NAME_GS "gsdll64.dll" @@ -604,12 +607,10 @@ c16stombs(char dst[], const uint16_t src[], int len) # define LIB_NAME_GPCL "gpcl6dll32.dll" # endif # define LIB_NAME_PCAP "Npcap" -# define MOUSE_CAPTURE_KEYSEQ "F8+F12" #else # define LIB_NAME_GS "libgs" # define LIB_NAME_GPCL "libgpcl6" # define LIB_NAME_PCAP "libpcap" -# define MOUSE_CAPTURE_KEYSEQ "Ctrl+End" #endif QMap ProgSettings::translatedstrings; @@ -632,7 +633,8 @@ ProgSettings::reloadStrings() translatedstrings[STRING_GHOSTPCL_ERROR_DESC] = QCoreApplication::translate("", "%1 is required for automatic conversion of PCL files to PDF.\n\nAny documents sent to the generic PCL printer will be saved as Printer Command Language (.pcl) files.").arg(LIB_NAME_GPCL).toStdWString(); translatedstrings[STRING_HW_NOT_AVAILABLE_MACHINE] = QCoreApplication::translate("", "Machine \"%hs\" is not available due to missing ROMs in the roms/machines directory. Switching to an available machine.").toStdWString(); translatedstrings[STRING_HW_NOT_AVAILABLE_VIDEO] = QCoreApplication::translate("", "Video card \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card.").toStdWString(); - translatedstrings[STRING_HW_NOT_AVAILABLE_VIDEO2] = QCoreApplication::translate("", "Video card #2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Disabling the second video card.").toStdWString(); + translatedstrings[STRING_HW_NOT_AVAILABLE_VIDEO2] = QCoreApplication::translate("", "Video card #2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Disabling the second video card.").toStdWString(); + translatedstrings[STRING_HW_NOT_AVAILABLE_DEVICE] = QCoreApplication::translate("", "Device \"%hs\" is not available due to missing ROMs. Ignoring the device.").toStdWString(); translatedstrings[STRING_HW_NOT_AVAILABLE_TITLE] = QCoreApplication::translate("", "Hardware not available").toStdWString(); translatedstrings[STRING_MONITOR_SLEEP] = QCoreApplication::translate("", "Monitor in sleep mode").toStdWString(); translatedstrings[STRING_NET_ERROR] = QCoreApplication::translate("", "Failed to initialize network driver").toStdWString(); diff --git a/src/qt/qt_settingsfloppycdrom.cpp b/src/qt/qt_settingsfloppycdrom.cpp index db54315e4..cc58d3cde 100644 --- a/src/qt/qt_settingsfloppycdrom.cpp +++ b/src/qt/qt_settingsfloppycdrom.cpp @@ -90,6 +90,14 @@ setCDROMSpeed(QAbstractItemModel *model, const QModelIndex &idx, uint8_t speed) model->setData(i, speed, Qt::UserRole); } +static QString +CDROMName(int type) +{ + char temp[512]; + cdrom_get_name(type, temp); + return QObject::tr((const char *) temp); +} + static void setCDROMType(QAbstractItemModel *model, const QModelIndex &idx, int type) { @@ -97,7 +105,7 @@ setCDROMType(QAbstractItemModel *model, const QModelIndex &idx, int type) if (idx.siblingAtColumn(0).data(Qt::UserRole).toUInt() == CDROM_BUS_DISABLED) model->setData(i, QCoreApplication::translate("", "None")); else if (idx.siblingAtColumn(0).data(Qt::UserRole).toUInt() != CDROM_BUS_MITSUMI) - model->setData(i, QObject::tr(cdrom_getname(type))); + model->setData(i, CDROMName(type)); model->setData(i, type, Qt::UserRole); } @@ -156,8 +164,12 @@ SettingsFloppyCDROM::SettingsFloppyCDROM(QWidget *parent) auto idx = model->index(i, 0); int type = cdrom_get_type(i); setCDROMBus(model, idx, cdrom[i].bus_type, cdrom[i].res); - setCDROMSpeed(model, idx.siblingAtColumn(1), cdrom[i].speed); setCDROMType(model, idx.siblingAtColumn(2), type); + int speed = cdrom_get_speed(type); + if (speed == -1) + setCDROMSpeed(model, idx.siblingAtColumn(1), cdrom[i].speed); + else + setCDROMSpeed(model, idx.siblingAtColumn(1), speed); if (cdrom[i].bus_type == CDROM_BUS_ATAPI) Harddrives::busTrackClass->device_track(1, DEV_CDROM, cdrom[i].bus_type, cdrom[i].ide_channel); else if (cdrom[i].bus_type == CDROM_BUS_SCSI) @@ -186,7 +198,7 @@ SettingsFloppyCDROM::SettingsFloppyCDROM(QWidget *parent) if (((bus_type == CDROM_BUS_ATAPI) || (bus_type == CDROM_BUS_SCSI)) && ((cdrom_drive_types[j].bus_type == bus_type) || (cdrom_drive_types[j].bus_type == BUS_TYPE_BOTH))) { - QString name = tr(cdrom_getname(j)); + QString name = CDROMName(j); Models::AddEntry(modelType, name, j); if ((cdrom[cdromIdx].bus_type == bus_type) && (cdrom[cdromIdx].type == j)) selectedTypeRow = eligibleRows; @@ -246,7 +258,6 @@ SettingsFloppyCDROM::onCDROMRowChanged(const QModelIndex ¤t) { uint8_t bus = current.siblingAtColumn(0).data(Qt::UserRole).toUInt(); uint8_t channel = current.siblingAtColumn(0).data(Qt::UserRole + 1).toUInt(); - uint8_t speed = current.siblingAtColumn(1).data(Qt::UserRole).toUInt(); int type = current.siblingAtColumn(2).data(Qt::UserRole).toInt(); ui->comboBoxBus->setCurrentIndex(-1); @@ -260,7 +271,14 @@ SettingsFloppyCDROM::onCDROMRowChanged(const QModelIndex ¤t) if (!match.isEmpty()) ui->comboBoxChannel->setCurrentIndex(match.first().row()); + int speed = cdrom_get_speed(type); + if (speed == -1) { + speed = current.siblingAtColumn(1).data(Qt::UserRole).toUInt(); + ui->comboBoxSpeed->setEnabled(true); + } else + ui->comboBoxSpeed->setEnabled(false); ui->comboBoxSpeed->setCurrentIndex(speed == 0 ? 7 : speed - 1); + ui->comboBoxCDROMType->setCurrentIndex(type); enableCurrentlySelectedChannel(); } @@ -351,7 +369,7 @@ SettingsFloppyCDROM::on_comboBoxBus_activated(int) if (((bus_type == CDROM_BUS_ATAPI) || (bus_type == CDROM_BUS_SCSI)) && ((cdrom_drive_types[j].bus_type == bus_type) || (cdrom_drive_types[j].bus_type == BUS_TYPE_BOTH))) { - QString name = tr(cdrom_getname(j)); + QString name = CDROMName(j); Models::AddEntry(modelType, name, j); if ((cdrom[cdromIdx].bus_type == bus_type) && (cdrom[cdromIdx].type == j)) selectedTypeRow = eligibleRows; @@ -401,9 +419,22 @@ SettingsFloppyCDROM::on_comboBoxChannel_activated(int) void SettingsFloppyCDROM::on_comboBoxCDROMType_activated(int) { + int type = ui->comboBoxCDROMType->currentData().toUInt(); + setCDROMType(ui->tableViewCDROM->model(), ui->tableViewCDROM->selectionModel()->currentIndex(), - ui->comboBoxCDROMType->currentData().toUInt()); + type); ui->tableViewCDROM->resizeColumnsToContents(); ui->tableViewCDROM->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch); + + int speed = cdrom_get_speed(type); + if (speed == -1) { + speed = ui->comboBoxSpeed->currentData().toUInt(); + ui->comboBoxSpeed->setEnabled(true); + } else + ui->comboBoxSpeed->setEnabled(false); + ui->comboBoxSpeed->setCurrentIndex(speed == 0 ? 7 : speed - 1); + + auto idx = ui->tableViewCDROM->selectionModel()->currentIndex(); + setCDROMSpeed(ui->tableViewCDROM->model(), idx.siblingAtColumn(1), speed); } diff --git a/src/qt/qt_settingsharddisks.cpp b/src/qt/qt_settingsharddisks.cpp index 4f6811ff1..e679dafa5 100644 --- a/src/qt/qt_settingsharddisks.cpp +++ b/src/qt/qt_settingsharddisks.cpp @@ -55,7 +55,7 @@ normalize_hd_list() memset(ihdd, 0x00, HDD_NUM * sizeof(hard_disk_t)); for (uint8_t i = 0; i < HDD_NUM; i++) { - if (temp_hdd[i].bus != HDD_BUS_DISABLED) { + if (temp_hdd[i].bus_type != HDD_BUS_DISABLED) { memcpy(&(ihdd[j]), &(temp_hdd[i]), sizeof(hard_disk_t)); j++; } @@ -79,14 +79,14 @@ addRow(QAbstractItemModel *model, hard_disk_t *hd) int row = model->rowCount(); model->insertRow(row); - QString busName = Harddrives::BusChannelName(hd->bus, hd->channel); + QString busName = Harddrives::BusChannelName(hd->bus_type, hd->channel); model->setData(model->index(row, ColumnBus), busName); model->setData(model->index(row, ColumnBus), ProgSettings::loadIcon("/hard_disk.ico"), Qt::DecorationRole); - model->setData(model->index(row, ColumnBus), hd->bus, DataBus); - model->setData(model->index(row, ColumnBus), hd->bus, DataBusPrevious); + model->setData(model->index(row, ColumnBus), hd->bus_type, DataBus); + model->setData(model->index(row, ColumnBus), hd->bus_type, DataBusPrevious); model->setData(model->index(row, ColumnBus), hd->channel, DataBusChannel); model->setData(model->index(row, ColumnBus), hd->channel, DataBusChannelPrevious); - Harddrives::busTrackClass->device_track(1, DEV_HDD, hd->bus, hd->channel); + Harddrives::busTrackClass->device_track(1, DEV_HDD, hd->bus_type, hd->channel); QString fileName = hd->fn; if (fileName.startsWith(userPath, Qt::CaseInsensitive)) { model->setData(model->index(row, ColumnFilename), fileName.mid(userPath.size())); @@ -120,7 +120,7 @@ SettingsHarddisks::SettingsHarddisks(QWidget *parent) ui->tableView->setModel(model); for (int i = 0; i < HDD_NUM; i++) { - if (hdd[i].bus > 0) { + if (hdd[i].bus_type > 0) { addRow(model, &hdd[i]); } } @@ -153,7 +153,7 @@ SettingsHarddisks::save() int rows = model->rowCount(); for (int i = 0; i < rows; ++i) { auto idx = model->index(i, ColumnBus); - hdd[i].bus = idx.data(DataBus).toUInt(); + hdd[i].bus_type = idx.data(DataBus).toUInt(); hdd[i].channel = idx.data(DataBusChannel).toUInt(); hdd[i].tracks = idx.siblingAtColumn(ColumnCylinders).data().toUInt(); hdd[i].hpc = idx.siblingAtColumn(ColumnHeads).data().toUInt(); @@ -313,11 +313,11 @@ addDriveFromDialog(Ui::SettingsHarddisks *ui, const HarddiskDialog &dlg) hard_disk_t hd; memset(&hd, 0, sizeof(hd)); - hd.bus = dlg.bus(); - hd.channel = dlg.channel(); - hd.tracks = dlg.cylinders(); - hd.hpc = dlg.heads(); - hd.spt = dlg.sectors(); + hd.bus_type = dlg.bus(); + hd.channel = dlg.channel(); + hd.tracks = dlg.cylinders(); + hd.hpc = dlg.heads(); + hd.spt = dlg.sectors(); strncpy(hd.fn, fn.data(), sizeof(hd.fn) - 1); hd.speed_preset = dlg.speed(); diff --git a/src/qt/qt_settingsinput.cpp b/src/qt/qt_settingsinput.cpp index d7b69442c..d7c61e8d2 100644 --- a/src/qt/qt_settingsinput.cpp +++ b/src/qt/qt_settingsinput.cpp @@ -136,7 +136,7 @@ static int get_axis(JoystickConfiguration &jc, int axis, int joystick_nr) { int axis_sel = jc.selectedAxis(axis); - int nr_axes = plat_joystick_state[joystick_state[joystick_nr].plat_joystick_nr - 1].nr_axes; + int nr_axes = plat_joystick_state[joystick_state[0][joystick_nr].plat_joystick_nr - 1].nr_axes; if (axis_sel < nr_axes) { return axis_sel; @@ -153,7 +153,7 @@ static int get_pov(JoystickConfiguration &jc, int pov, int joystick_nr) { int pov_sel = jc.selectedPov(pov); - int nr_povs = plat_joystick_state[joystick_state[joystick_nr].plat_joystick_nr - 1].nr_povs * 2; + int nr_povs = plat_joystick_state[joystick_state[0][joystick_nr].plat_joystick_nr - 1].nr_povs * 2; if (pov_sel < nr_povs) { if (pov_sel & 1) @@ -176,19 +176,19 @@ updateJoystickConfig(int type, int joystick_nr, QWidget *parent) break; } - joystick_state[joystick_nr].plat_joystick_nr = jc.selectedDevice(); - if (joystick_state[joystick_nr].plat_joystick_nr) { + joystick_state[0][joystick_nr].plat_joystick_nr = jc.selectedDevice(); + if (joystick_state[0][joystick_nr].plat_joystick_nr) { for (int axis_nr = 0; axis_nr < joystick_get_axis_count(type); axis_nr++) { - joystick_state[joystick_nr].axis_mapping[axis_nr] = get_axis(jc, axis_nr, joystick_nr); + joystick_state[0][joystick_nr].axis_mapping[axis_nr] = get_axis(jc, axis_nr, joystick_nr); } for (int button_nr = 0; button_nr < joystick_get_button_count(type); button_nr++) { - joystick_state[joystick_nr].button_mapping[button_nr] = jc.selectedButton(button_nr); + joystick_state[0][joystick_nr].button_mapping[button_nr] = jc.selectedButton(button_nr); } for (int pov_nr = 0; pov_nr < joystick_get_pov_count(type) * 2; pov_nr += 2) { - joystick_state[joystick_nr].pov_mapping[pov_nr][0] = get_pov(jc, pov_nr, joystick_nr); - joystick_state[joystick_nr].pov_mapping[pov_nr][1] = get_pov(jc, pov_nr + 1, joystick_nr); + joystick_state[0][joystick_nr].pov_mapping[pov_nr][0] = get_pov(jc, pov_nr, joystick_nr); + joystick_state[0][joystick_nr].pov_mapping[pov_nr][1] = get_pov(jc, pov_nr + 1, joystick_nr); } } } diff --git a/src/qt/qt_styleoverride.cpp b/src/qt/qt_styleoverride.cpp index 7ec5a341c..60a7162a5 100644 --- a/src/qt/qt_styleoverride.cpp +++ b/src/qt/qt_styleoverride.cpp @@ -19,6 +19,13 @@ #include #include +#ifdef Q_OS_WINDOWS +#include +#ifndef DWMWA_USE_IMMERSIVE_DARK_MODE +#define DWMWA_USE_IMMERSIVE_DARK_MODE 20 +#endif +#endif + int StyleOverride::styleHint( StyleHint hint, @@ -48,6 +55,11 @@ StyleOverride::polish(QWidget *widget) widget->setWindowFlag(Qt::MSWindowsFixedSizeDialogHint, true); } widget->setWindowFlag(Qt::WindowContextHelpButtonHint, false); +#ifdef Q_OS_WINDOWS + extern bool windows_is_light_theme(); + BOOL DarkMode = !windows_is_light_theme(); + DwmSetWindowAttribute((HWND)widget->winId(), DWMWA_USE_IMMERSIVE_DARK_MODE, (LPCVOID)&DarkMode, sizeof(DarkMode)); +#endif } if (qobject_cast(widget)) { diff --git a/src/qt/qt_winrawinputfilter.cpp b/src/qt/qt_winrawinputfilter.cpp index 73e8a2995..13e0ec9a7 100644 --- a/src/qt/qt_winrawinputfilter.cpp +++ b/src/qt/qt_winrawinputfilter.cpp @@ -34,15 +34,27 @@ #include "qt_winrawinputfilter.hpp" #include +#include +#include +#include +#include #include #include +#include +#ifndef DWMWA_USE_IMMERSIVE_DARK_MODE +#define DWMWA_USE_IMMERSIVE_DARK_MODE 20 +#endif #include <86box/keyboard.h> #include <86box/mouse.h> #include <86box/plat.h> #include <86box/86box.h> +#include <86box/cdrom.h> +#include <86box/video.h> +#include +#include extern void win_keyboard_handle(uint32_t scancode, int up, int e0, int e1); @@ -50,6 +62,35 @@ extern void win_keyboard_handle(uint32_t scancode, int up, int e0, int e1); #include #include "qt_rendererstack.hpp" +#include "ui_qt_mainwindow.h" + +bool windows_is_light_theme() { + // based on https://stackoverflow.com/questions/51334674/how-to-detect-windows-10-light-dark-mode-in-win32-application + + // The value is expected to be a REG_DWORD, which is a signed 32-bit little-endian + auto buffer = std::vector(4); + auto cbData = static_cast(buffer.size() * sizeof(char)); + auto res = RegGetValueW( + HKEY_CURRENT_USER, + L"Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", + L"AppsUseLightTheme", + RRF_RT_REG_DWORD, // expected value type + nullptr, + buffer.data(), + &cbData); + + if (res != ERROR_SUCCESS) { + return 1; + } + + // convert bytes written to our buffer to an int, assuming little-endian + auto i = int(buffer[3] << 24 | + buffer[2] << 16 | + buffer[1] << 8 | + buffer[0]); + + return i == 1; +} extern "C" void win_joystick_handle(PRAWINPUT); std::unique_ptr @@ -113,34 +154,142 @@ WindowsRawInputFilter::~WindowsRawInputFilter() RegisterRawInputDevices(rid, 2, sizeof(rid[0])); } +static void +notify_drives(ULONG unitmask, int empty) +{ + char p[1024] = { 0 }; + + for (int i = 0; i < 26; ++i) { + if (unitmask & 0x1) { + cdrom_t *dev = NULL; + + sprintf(p, "ioctl://\\\\.\\%c:", 'A' + i); + + for (int i = 0; i < CDROM_NUM; i++) + if (!stricmp(cdrom[i].image_path, p)) { + dev = &(cdrom[i]); + if (empty) + cdrom_set_empty(dev); + else + cdrom_update_status(dev); + // pclog("CD-ROM %i : Drive notified of media %s\n", + // dev->id, empty ? "removal" : "change"); + } + } + + unitmask = unitmask >> 1; + } +} + +static void +device_change(WPARAM wParam, LPARAM lParam) +{ + PDEV_BROADCAST_HDR lpdb = (PDEV_BROADCAST_HDR) lParam; + + switch(wParam) { + case DBT_DEVICEARRIVAL: + case DBT_DEVICEREMOVECOMPLETE: + /* Check whether a CD or DVD was inserted into a drive. */ + if (lpdb->dbch_devicetype == DBT_DEVTYP_VOLUME) { + PDEV_BROADCAST_VOLUME lpdbv = (PDEV_BROADCAST_VOLUME) lpdb; + + if (lpdbv->dbcv_flags & DBTF_MEDIA) + notify_drives(lpdbv->dbcv_unitmask, + (wParam == DBT_DEVICEREMOVECOMPLETE)); + } + break; + + default: + /* + Process other WM_DEVICECHANGE notifications for other + devices or reasons. + */ + break; + } +} + bool WindowsRawInputFilter::nativeEventFilter(const QByteArray &eventType, void *message, result_t *result) { if (eventType == "windows_generic_MSG") { MSG *msg = static_cast(message); - if (msg->message == WM_INPUT) { - - if (window->isActiveWindow() && menus_open == 0) - handle_input((HRAWINPUT) msg->lParam); - else - { - for (auto &w : window->renderers) { - if (w && w->isActiveWindow()) { - handle_input((HRAWINPUT) msg->lParam); - break; + if (msg != nullptr) switch(msg->message) { + case WM_INPUT: + if (window->isActiveWindow() && (menus_open == 0)) + handle_input((HRAWINPUT) msg->lParam); + else { + for (auto &w : window->renderers) { + if (w && w->isActiveWindow()) { + handle_input((HRAWINPUT) msg->lParam); + break; + } } } - } - - return true; - } - - /* Stop processing of Alt-F4 */ - if (msg->message == WM_SYSKEYDOWN) { - if (msg->wParam == 0x73) { return true; - } + case WM_SETTINGCHANGE: + if ((((void *) msg->lParam) != nullptr) && + (wcscmp(L"ImmersiveColorSet", (wchar_t*)msg->lParam) == 0)) { + + if (!windows_is_light_theme()) { + QFile f(":qdarkstyle/dark/darkstyle.qss"); + + if (!f.exists()) + printf("Unable to set stylesheet, file not found\n"); + else { + f.open(QFile::ReadOnly | QFile::Text); + QTextStream ts(&f); + qApp->setStyleSheet(ts.readAll()); + } + QTimer::singleShot(1000, [this] () { + BOOL DarkMode = TRUE; + auto vid_stack = (RendererStack::Renderer) vid_api; + DwmSetWindowAttribute((HWND) window->winId(), + DWMWA_USE_IMMERSIVE_DARK_MODE, + (LPCVOID) &DarkMode, + sizeof(DarkMode)); + window->ui->stackedWidget->switchRenderer(vid_stack); + for (int i = 1; i < MONITORS_NUM; i++) { + if ((window->renderers[i] != nullptr) && + !window->renderers[i]->isHidden()) + window->renderers[i]->switchRenderer(vid_stack); + } + }); + } else { + qApp->setStyleSheet(""); + QTimer::singleShot(1000, [this] () { + BOOL DarkMode = FALSE; + DwmSetWindowAttribute((HWND) window->winId(), + DWMWA_USE_IMMERSIVE_DARK_MODE, + (LPCVOID) &DarkMode, + sizeof(DarkMode)); + }); + } + + QTimer::singleShot(1000, [this] () { + window->resizeContents(monitors[0].mon_scrnsz_x, + monitors[0].mon_scrnsz_y); + for (int i = 1; i < MONITORS_NUM; i++) { + auto mon = &(monitors[i]); + + if ((window->renderers[i] != nullptr) && + !window->renderers[i]->isHidden()) + window->resizeContentsMonitor(mon->mon_scrnsz_x, + mon->mon_scrnsz_y, + i); + } + }); + } + break; + case WM_SYSKEYDOWN: + /* Stop processing of Alt-F4 */ + if (msg->wParam == 0x73) + return true; + break; + case WM_DEVICECHANGE: + if (msg->hwnd == (HWND) window->winId()) + device_change(msg->wParam, msg->lParam); + break; } } diff --git a/src/qt/sdl_joystick.c b/src/qt/sdl_joystick.c index 03159ba7f..83a2a67b1 100644 --- a/src/qt/sdl_joystick.c +++ b/src/qt/sdl_joystick.c @@ -8,13 +8,13 @@ * * SDL2 joystick interface. * - * - * * Authors: Sarah Walker, - * Joakim L. Gilje + * Joakim L. Gilje, + * Jasmine Iwanek, jriwanek@gmail.com> * - * Copyright 2017-2021 Sarah Walker - * Copyright 2021 Joakim L. Gilje + * Copyright 2017-2021 Sarah Walker. + * Copyright 2021 Joakim L. Gilje. + * Copyright 2021-2025 Jasmine Iwanek. */ #include @@ -33,8 +33,8 @@ #include <86box/gameport.h> #include <86box/plat_unused.h> -int joysticks_present; -joystick_t joystick_state[MAX_JOYSTICKS]; +int joysticks_present = 0; +joystick_t joystick_state[GAMEPORT_MAX][MAX_JOYSTICKS]; plat_joystick_t plat_joystick_state[MAX_PLAT_JOYSTICKS]; static SDL_Joystick *sdl_joy[MAX_PLAT_JOYSTICKS]; @@ -89,7 +89,7 @@ joystick_close(void) } static int -joystick_get_axis(int joystick_nr, int mapping) +joystick_get_axis(int gameport, int joystick_nr, int mapping) { if (mapping & POV_X) { switch (plat_joystick_state[joystick_nr].p[mapping & 3]) { @@ -144,44 +144,44 @@ joystick_process(void) #if 0 pclog("joystick %i - x=%i y=%i b[0]=%i b[1]=%i %i\n", js, - joystick_state[js].x, - joystick_state[js].y, - joystick_state[js].b[0], - joystick_state[js].b[1], + joystick_state[0][js].x, + joystick_state[0][js].y, + joystick_state[0][js].b[0], + joystick_state[0][js].b[1], joysticks_present); #endif } for (int js = 0; js < joystick_get_max_joysticks(joystick_type); js++) { - if (joystick_state[js].plat_joystick_nr) { - int joystick_nr = joystick_state[js].plat_joystick_nr - 1; + if (joystick_state[0][js].plat_joystick_nr) { + int joystick_nr = joystick_state[0][js].plat_joystick_nr - 1; for (int axis_nr = 0; axis_nr < joystick_get_axis_count(joystick_type); axis_nr++) - joystick_state[js].axis[axis_nr] = joystick_get_axis(joystick_nr, joystick_state[js].axis_mapping[axis_nr]); + joystick_state[0][js].axis[axis_nr] = joystick_get_axis(0, joystick_nr, joystick_state[0][js].axis_mapping[axis_nr]); for (int button_nr = 0; button_nr < joystick_get_button_count(joystick_type); button_nr++) - joystick_state[js].button[button_nr] = plat_joystick_state[joystick_nr].b[joystick_state[js].button_mapping[button_nr]]; + joystick_state[0][js].button[button_nr] = plat_joystick_state[joystick_nr].b[joystick_state[0][js].button_mapping[button_nr]]; for (int pov_nr = 0; pov_nr < joystick_get_pov_count(joystick_type); pov_nr++) { - int x = joystick_get_axis(joystick_nr, joystick_state[js].pov_mapping[pov_nr][0]); - int y = joystick_get_axis(joystick_nr, joystick_state[js].pov_mapping[pov_nr][1]); + int x = joystick_get_axis(0, joystick_nr, joystick_state[0][js].pov_mapping[pov_nr][0]); + int y = joystick_get_axis(0, joystick_nr, joystick_state[0][js].pov_mapping[pov_nr][1]); double angle = (atan2((double) y, (double) x) * 360.0) / (2 * M_PI); double magnitude = sqrt((double) x * (double) x + (double) y * (double) y); if (magnitude < 16384) - joystick_state[js].pov[pov_nr] = -1; + joystick_state[0][js].pov[pov_nr] = -1; else - joystick_state[js].pov[pov_nr] = ((int) angle + 90 + 360) % 360; + joystick_state[0][js].pov[pov_nr] = ((int) angle + 90 + 360) % 360; } } else { for (int axis_nr = 0; axis_nr < joystick_get_axis_count(joystick_type); axis_nr++) - joystick_state[js].axis[axis_nr] = 0; + joystick_state[0][js].axis[axis_nr] = 0; for (int button_nr = 0; button_nr < joystick_get_button_count(joystick_type); button_nr++) - joystick_state[js].button[button_nr] = 0; + joystick_state[0][js].button[button_nr] = 0; for (int pov_nr = 0; pov_nr < joystick_get_pov_count(joystick_type); pov_nr++) - joystick_state[js].pov[pov_nr] = -1; + joystick_state[0][js].pov[pov_nr] = -1; } } } diff --git a/src/qt/win_cdrom_ioctl.c b/src/qt/win_cdrom_ioctl.c index 9d82d68cc..621cf0b76 100644 --- a/src/qt/win_cdrom_ioctl.c +++ b/src/qt/win_cdrom_ioctl.c @@ -19,142 +19,123 @@ #define UNICODE #define BITMAP WINDOWS_BITMAP #include -#include #undef BITMAP #include -#include #include "ntddcdrm.h" #include "ntddscsi.h" +#ifdef ENABLE_IOCTL_LOG #include -#include +#endif #include #include #include #include +#include #include -#define HAVE_STDARG_H #include <86box/86box.h> -#include <86box/scsi_device.h> #include <86box/cdrom.h> -#include <86box/plat_unused.h> -#include <86box/plat_cdrom.h> +#include <86box/log.h> +#include <86box/plat_cdrom_ioctl.h> +#include <86box/scsi_device.h> -/* 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) - -typedef struct win_cdrom_ioctl_t { - int toc_valid; +typedef struct ioctl_t { + cdrom_t *dev; + void *log; + int is_dvd; + int has_audio; + int32_t tracks_num; uint8_t cur_toc[65536]; CDROM_READ_TOC_EX cur_read_toc_ex; int blocks_num; uint8_t cur_rti[65536]; HANDLE handle; WCHAR path[256]; - WCHAR old_path[256]; -} win_cdrom_ioctl_t; +} ioctl_t; -#ifdef ENABLE_WIN_CDROM_IOCTL_LOG -int win_cdrom_ioctl_do_log = ENABLE_WIN_CDROM_IOCTL_LOG; +static int ioctl_read_dvd_structure(const void *local, uint8_t layer, uint8_t format, + uint8_t *buffer, uint32_t *info); + +#ifdef ENABLE_IOCTL_LOG +int ioctl_do_log = ENABLE_IOCTL_LOG; void -win_cdrom_ioctl_log(const char *fmt, ...) +ioctl_log(void *priv, const char *fmt, ...) { - va_list ap; - - if (win_cdrom_ioctl_do_log) { + if (ioctl_do_log) { + va_list ap; va_start(ap, fmt); - pclog_ex(fmt, ap); + log_out(priv, fmt, ap); va_end(ap); } } #else -# define win_cdrom_ioctl_log(fmt, ...) +# define ioctl_log(priv, fmt, ...) #endif +/* Internal functions. */ static void -plat_cdrom_close_handle(win_cdrom_ioctl_t *ioctl) +ioctl_close_handle(const ioctl_t *ioctl) { if (ioctl->handle != NULL) CloseHandle(ioctl->handle); } static int -plat_cdrom_open(void *local) +ioctl_open_handle(ioctl_t *ioctl) { - win_cdrom_ioctl_t *ioctl = (win_cdrom_ioctl_t *) local; - - plat_cdrom_close_handle(local); - + ioctl_log(ioctl->log, "ioctl->path = \"%ls\"\n", ioctl->path); ioctl->handle = CreateFileW((LPCWSTR) ioctl->path, GENERIC_READ | GENERIC_WRITE, - FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); - win_cdrom_ioctl_log("handle=%p, error=%x\n", ioctl->handle, (unsigned int) GetLastError()); + FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, + OPEN_EXISTING, 0, NULL); + + ioctl_log(ioctl->log, "handle=%p, error=%x\n", + ioctl->handle, (unsigned int) GetLastError()); return (ioctl->handle != INVALID_HANDLE_VALUE); } static int -plat_cdrom_load(void *local) -{ - win_cdrom_ioctl_t *ioctl = (win_cdrom_ioctl_t *) local; - - plat_cdrom_close(local); - - ioctl->handle = CreateFileW((LPCWSTR) ioctl->path, GENERIC_READ | GENERIC_WRITE, - FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); - win_cdrom_ioctl_log("handle=%p, error=%x\n", ioctl->handle, (unsigned int) GetLastError()); - if (ioctl->handle != INVALID_HANDLE_VALUE) { - long size; - DeviceIoControl(ioctl->handle, IOCTL_STORAGE_LOAD_MEDIA, NULL, 0, NULL, 0, (LPDWORD) &size, NULL); - return 1; - } - return 0; -} - -static int -plat_cdrom_read_normal_toc(win_cdrom_ioctl_t *ioctl, uint8_t *toc_buf) +ioctl_read_normal_toc(ioctl_t *ioctl, uint8_t *toc_buf) { long size = 0; PCDROM_TOC_FULL_TOC_DATA cur_full_toc = NULL; + ioctl->tracks_num = 0; memset(toc_buf, 0x00, 65536); cur_full_toc = (PCDROM_TOC_FULL_TOC_DATA) calloc(1, 65536); - if (ioctl->blocks_num != 0) { - memset(ioctl->cur_rti, 0x00, ioctl->blocks_num * 11); - ioctl->blocks_num = 0; - } ioctl->cur_read_toc_ex.Format = CDROM_READ_TOC_EX_FORMAT_TOC; - win_cdrom_ioctl_log("cur_read_toc_ex.Format = %i\n", ioctl->cur_read_toc_ex.Format); + ioctl_log(ioctl->log, "cur_read_toc_ex.Format = %i\n", ioctl->cur_read_toc_ex.Format); ioctl->cur_read_toc_ex.Msf = 1; - ioctl->cur_read_toc_ex.SessionTrack = 0; + ioctl->cur_read_toc_ex.SessionTrack = 1; - plat_cdrom_open(ioctl); - int temp = DeviceIoControl(ioctl->handle, IOCTL_CDROM_READ_TOC_EX, &ioctl->cur_read_toc_ex, 65535, - cur_full_toc, 65535, (LPDWORD) &size, NULL); - plat_cdrom_close(ioctl); - win_cdrom_ioctl_log("temp = %i\n", temp); + ioctl_open_handle(ioctl); + const int temp = DeviceIoControl(ioctl->handle, IOCTL_CDROM_READ_TOC_EX, + &ioctl->cur_read_toc_ex, 65535, + cur_full_toc, 65535, + (LPDWORD) &size, NULL); + ioctl_close_handle(ioctl); + ioctl_log(ioctl->log, "temp = %i\n", temp); if (temp != 0) { - int length = ((cur_full_toc->Length[0] << 8) | cur_full_toc->Length[1]) + 2; + const int length = ((cur_full_toc->Length[0] << 8) | cur_full_toc->Length[1]) + 2; memcpy(toc_buf, cur_full_toc, length); + ioctl->tracks_num = (length - 4) / 8; } free(cur_full_toc); -#ifdef ENABLE_WIN_CDROM_IOCTL_LOG +#ifdef ENABLE_IOCTL_LOG PCDROM_TOC toc = (PCDROM_TOC) toc_buf; - const int tracks_num = (((toc->Length[0] << 8) | toc->Length[1]) - 2) / 8; - win_cdrom_ioctl_log("%i tracks: %02X %02X %02X %02X\n", - tracks_num, toc_buf[0], toc_buf[1], toc_buf[2], toc_buf[3]); + ioctl_log(ioctl->log, "%i tracks: %02X %02X %02X %02X\n", + ioctl->tracks_num, toc_buf[0], toc_buf[1], toc_buf[2], toc_buf[3]); - for (int i = 0; i < tracks_num; i++) { - uint8_t *t = (uint8_t *) &toc->TrackData[i]; - win_cdrom_ioctl_log("Track %03i: %02X %02X %02X %02X %02X %02X %02X %02X\n", - i, t[0], t[1], t[2], t[3], t[4], t[5], t[6], t[7]); + for (int i = 0; i < ioctl->tracks_num; i++) { + const uint8_t *t = (const uint8_t *) &toc->TrackData[i]; + ioctl_log(ioctl->log, "Track %03i: %02X %02X %02X %02X %02X %02X %02X %02X\n", + i, t[0], t[1], t[2], t[3], t[4], t[5], t[6], t[7]); } #endif @@ -162,427 +143,667 @@ plat_cdrom_read_normal_toc(win_cdrom_ioctl_t *ioctl, uint8_t *toc_buf) } static void -plat_cdrom_read_raw_toc(win_cdrom_ioctl_t *ioctl) +ioctl_read_raw_toc(ioctl_t *ioctl) { - long size = 0; - PCDROM_TOC_FULL_TOC_DATA cur_full_toc = NULL; + PCDROM_TOC_FULL_TOC_DATA cur_full_toc = NULL; + long size = 0; + raw_track_info_t *rti = (raw_track_info_t *) ioctl->cur_rti; + uint8_t *buffer = (uint8_t *) calloc (1, 2052); + ioctl->is_dvd = (ioctl_read_dvd_structure(ioctl, 0, 0, buffer, NULL) > 0); + free(buffer); + + ioctl->has_audio = 0; + ioctl->blocks_num = 0; memset(ioctl->cur_rti, 0x00, 65536); cur_full_toc = (PCDROM_TOC_FULL_TOC_DATA) calloc(1, 65536); - if (ioctl->blocks_num != 0) { - memset(ioctl->cur_rti, 0x00, ioctl->blocks_num * 11); - ioctl->blocks_num = 0; - } ioctl->cur_read_toc_ex.Format = CDROM_READ_TOC_EX_FORMAT_FULL_TOC; - win_cdrom_ioctl_log("cur_read_toc_ex.Format = %i\n", ioctl->cur_read_toc_ex.Format); + ioctl_log(ioctl->log, "cur_read_toc_ex.Format = %i\n", ioctl->cur_read_toc_ex.Format); ioctl->cur_read_toc_ex.Msf = 1; - ioctl->cur_read_toc_ex.SessionTrack = 0; + ioctl->cur_read_toc_ex.SessionTrack = 1; - plat_cdrom_open(ioctl); - int status = DeviceIoControl(ioctl->handle, IOCTL_CDROM_READ_TOC_EX, &ioctl->cur_read_toc_ex, 65535, - cur_full_toc, 65535, (LPDWORD) &size, NULL); - plat_cdrom_close(ioctl); - win_cdrom_ioctl_log("status = %i\n", status); + ioctl_open_handle(ioctl); + const int status = DeviceIoControl(ioctl->handle, IOCTL_CDROM_READ_TOC_EX, + &ioctl->cur_read_toc_ex, 65535, + cur_full_toc, 65535, + (LPDWORD) &size, NULL); + ioctl_close_handle(ioctl); + ioctl_log(ioctl->log, "status = %i\n", status); - if (status != 0) { - ioctl->blocks_num = (((cur_full_toc->Length[0] << 8) | cur_full_toc->Length[1]) - 2) / 11; + if ((status == 0) && (ioctl->tracks_num >= 1)) { + /* + This is needed because in some circumstances (eg. a DVD .MDS + mounted in Daemon Tools), reading the raw TOC fails but + reading the cooked TOC does not, so we have to construct the + raw TOC from the cooked TOC. + */ + const CDROM_TOC *toc = (const CDROM_TOC *) ioctl->cur_toc; + const TRACK_DATA *ct = &(toc->TrackData[ioctl->tracks_num - 1]); + + rti[0].adr_ctl = ((ct->Adr & 0xf) << 4) | (ct->Control & 0xf); + rti[0].point = 0xa0; + rti[0].pm = toc->FirstTrack; + + rti[1].adr_ctl = rti[0].adr_ctl; + rti[1].point = 0xa1; + rti[1].pm = toc->LastTrack; + + rti[2].adr_ctl = rti[0].adr_ctl; + rti[2].point = 0xa2; + rti[2].pm = ct->Address[1]; + rti[2].ps = ct->Address[2]; + rti[2].pf = ct->Address[3]; + + ioctl->blocks_num = 3; + + for (int i = 0; i < (ioctl->tracks_num - 1); i++) { + raw_track_info_t *crt = &(rti[ioctl->blocks_num]); + + ct = &(toc->TrackData[i]); + + crt->adr_ctl = ((ct->Adr & 0xf) << 4) | (ct->Control & 0xf); + crt->point = ct->TrackNumber; + crt->pm = ct->Address[1]; + crt->ps = ct->Address[2]; + crt->pf = ct->Address[3]; + + ioctl->blocks_num++; + } + } else if (status != 0) { + ioctl->blocks_num = (((cur_full_toc->Length[0] << 8) | + cur_full_toc->Length[1]) - 2) / 11; memcpy(ioctl->cur_rti, cur_full_toc->Descriptors, ioctl->blocks_num * 11); } -#ifdef ENABLE_WIN_CDROM_IOCTL_LOG - uint8_t *u = (uint8_t *) cur_full_toc; + if (ioctl->blocks_num) for (int i = 0; i < ioctl->tracks_num; i++) { + const raw_track_info_t *crt = &(rti[i]); - win_cdrom_ioctl_log("%i blocks: %02X %02X %02X %02X\n", - ioctl->blocks_num, u[0], u[1], u[2], u[3]); + if ((crt->point >= 1) && (crt->point <= 99) && !(crt->adr_ctl & 0x04)) { + ioctl->has_audio = 1; + break; + } + } + +#ifdef ENABLE_IOCTL_LOG + uint8_t *u = (uint8_t *) cur_full_toc; + + ioctl_log(ioctl->log, "%i blocks: %02X %02X %02X %02X\n", + ioctl->blocks_num, u[0], u[1], u[2], u[3]); - raw_track_info_t *rti = (raw_track_info_t *) ioctl->cur_rti; for (int i = 0; i < ioctl->blocks_num; i++) { uint8_t *t = (uint8_t *) &rti[i]; - win_cdrom_ioctl_log("Block %03i: %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X\n", - i, t[0], t[1], t[2], t[3], t[4], t[5], t[6], t[7], t[8], t[9], t[10]); + ioctl_log(ioctl->log, "Block %03i: %02X %02X %02X %02X %02X %02X %02X %02X " + "%02X %02X %02X\n", + i, t[0], t[1], t[2], t[3], t[4], t[5], t[6], t[7], t[8], + t[9], t[10]); } #endif free(cur_full_toc); } -void -plat_cdrom_get_raw_track_info(void *local, int *num, raw_track_info_t *rti) +static void +ioctl_read_toc(ioctl_t *ioctl) { - win_cdrom_ioctl_t *ioctl = (win_cdrom_ioctl_t *) local; + (void) ioctl_read_normal_toc(ioctl, ioctl->cur_toc); + ioctl_read_raw_toc(ioctl); +} + +static int +ioctl_get_track(const ioctl_t *ioctl, const uint32_t sector) { + raw_track_info_t *rti = (raw_track_info_t *) ioctl->cur_rti; + int track = -1; + + for (int i = (ioctl->blocks_num - 1); i >= 0; i--) { + const raw_track_info_t *ct = &(rti[i]); + const uint32_t start = (ct->pm * 60 * 75) + (ct->ps * 75) + ct->pf - 150; + + ioctl_log(ioctl->log, "ioctl_get_track(): ct: %02X, %08X\n", + ct->point, start); + + if ((ct->point >= 1) && (ct->point <= 99) && (sector >= start)) { + track = i; + ioctl_log(ioctl->log, "ioctl_get_track(): found track: %i\n", i); + break; + } + } + + return track; +} + +static int +ioctl_is_track_audio(const ioctl_t *ioctl, const uint32_t pos) +{ + const raw_track_info_t *rti = (const raw_track_info_t *) ioctl->cur_rti; + int ret = 0; + + if (ioctl->has_audio && !ioctl->is_dvd) { + const int track = ioctl_get_track(ioctl, pos); + const int control = rti[track].adr_ctl; + + ret = !(control & 0x04); + + ioctl_log(ioctl->log, "ioctl_is_track_audio(%08X, %02X): %i\n", pos, track, ret); + } + + return ret; +} + +/* Shared functions. */ +static int +ioctl_get_track_info(const void *local, const uint32_t track, + int end, track_info_t *ti) +{ + const ioctl_t * ioctl = (const ioctl_t *) local; + const CDROM_TOC *toc = (const CDROM_TOC *) ioctl->cur_toc; + int ret = 1; + + if ((track < 1) || (track == 0xaa) || (track > (toc->LastTrack + 1))) { + ioctl_log(ioctl->log, "ioctl_get_track_info(%02i)\n", track); + ret = 0; + } else { + const TRACK_DATA * td = &toc->TrackData[track - 1]; + + ti->m = td->Address[1]; + ti->s = td->Address[2]; + ti->f = td->Address[3]; + + ti->number = td->TrackNumber; + ti->attr = td->Control; + ti->attr |= ((td->Adr << 4) & 0xf0); + + ioctl_log(ioctl->log, "ioctl_get_track_info(%02i): %02i:%02i:%02i, %02i, %02X\n", + track, ti->m, ti->s, ti->f, ti->number, ti->attr); + } + + return ret; +} + +static void +ioctl_get_raw_track_info(const void *local, int *num, uint8_t *rti) +{ + const ioctl_t *ioctl = (const ioctl_t *) local; *num = ioctl->blocks_num; memcpy(rti, ioctl->cur_rti, ioctl->blocks_num * 11); } -static void -plat_cdrom_read_toc(win_cdrom_ioctl_t *ioctl) +static int +ioctl_is_track_pre(const void *local, const uint32_t sector) { - if (!ioctl->toc_valid) { - ioctl->toc_valid = 1; - (void) plat_cdrom_read_normal_toc(ioctl, ioctl->cur_toc); - plat_cdrom_read_raw_toc(ioctl); + const ioctl_t *ioctl = (const ioctl_t *) local; + const raw_track_info_t *rti = (const raw_track_info_t *) ioctl->cur_rti; + int ret = 0; + + if (ioctl->has_audio && !ioctl->is_dvd) { + const int track = ioctl_get_track(ioctl, sector); + const int control = rti[track].adr_ctl; + + ret = control & 0x01; + + ioctl_log(ioctl->log, "ioctl_is_track_pre(%08X, %02X): %i\n", sector, track, ret); } -} - -int -plat_cdrom_is_track_audio(void *local, uint32_t sector) -{ - win_cdrom_ioctl_t *ioctl = (win_cdrom_ioctl_t *) local; - PCDROM_TOC toc = (PCDROM_TOC) ioctl->cur_toc; - int control = 0; - uint32_t cur_addr = 0; - uint32_t next_addr = 0; - - plat_cdrom_read_toc(ioctl); - - for (int c = 0; toc->TrackData[c].TrackNumber != 0xaa; c++) { - PTRACK_DATA cur_td = &toc->TrackData[c]; - PTRACK_DATA next_td = &toc->TrackData[c + 1]; - - cur_addr = MSFtoLBA(cur_td->Address[1], cur_td->Address[2], cur_td->Address[3]) - 150; - next_addr = MSFtoLBA(next_td->Address[1], next_td->Address[2], next_td->Address[3]) - 150; - - win_cdrom_ioctl_log("F: %i, L: %i, C: %i (%i), c: %02X, A: %08X, S: %08X\n", - toc->FirstTrack, toc->LastTrack, cur_td->TrackNumber, c, - cur_td->Control, cur_addr, sector); - - if ((cur_td->TrackNumber >= toc->FirstTrack) && (cur_td->TrackNumber <= toc->LastTrack) && - (sector >= cur_addr) && (sector < next_addr)) { - control = cur_td->Control; - break; - } - } - - const int ret = !(control & 0x04); - - win_cdrom_ioctl_log("plat_cdrom_is_track_audio(%08X): %i\n", sector, ret); return ret; } -int -plat_cdrom_is_track_pre(void *local, uint32_t sector) +static int +ioctl_read_sector(const void *local, uint8_t *buffer, uint32_t const sector) { - win_cdrom_ioctl_t *ioctl = (win_cdrom_ioctl_t *) local; - PCDROM_TOC toc = (PCDROM_TOC) ioctl->cur_toc; - int control = 0; - uint32_t cur_addr = 0; - uint32_t next_addr = 0; + typedef struct SCSI_PASS_THROUGH_DIRECT_BUF { + SCSI_PASS_THROUGH_DIRECT spt; + ULONG Filler; + UCHAR SenseBuf[64]; + } SCSI_PASS_THROUGH_DIRECT_BUF; - plat_cdrom_read_toc(ioctl); + const ioctl_t * ioctl = (const ioctl_t *) local; + const raw_track_info_t * rti = (raw_track_info_t *) ioctl->cur_rti; + unsigned long int unused = 0; + const int sc_offs = (sector == 0xffffffff) ? 0 : 2352; + int len = (sector == 0xffffffff) ? 16 : 2368; + int m = 0; + int s = 0; + int f = 0; + uint32_t lba = sector; + int ret; + SCSI_PASS_THROUGH_DIRECT_BUF req; - for (int c = 0; toc->TrackData[c].TrackNumber != 0xaa; c++) { - PTRACK_DATA cur_td = &toc->TrackData[c]; - PTRACK_DATA next_td = &toc->TrackData[c + 1]; + ioctl_open_handle((ioctl_t *) ioctl); - cur_addr = MSFtoLBA(cur_td->Address[1], cur_td->Address[2], cur_td->Address[3]) - 150; - next_addr = MSFtoLBA(next_td->Address[1], next_td->Address[2], next_td->Address[3]) - 150; + if (ioctl->is_dvd) { + int track; - win_cdrom_ioctl_log("F: %i, L: %i, C: %i (%i), c: %02X, A: %08X, S: %08X\n", - toc->FirstTrack, toc->LastTrack, cur_td->TrackNumber, c, - cur_td->Control, cur_addr, sector); + req.spt.DataTransferLength = 0; + ret = 0; - if ((cur_td->TrackNumber >= toc->FirstTrack) && (cur_td->TrackNumber <= toc->LastTrack) && - (sector >= cur_addr) && (sector < next_addr)) { - control = cur_td->Control; - break; + if (lba == 0xffffffff) { + lba = ioctl->dev->seek_pos; + track = ioctl_get_track(ioctl, lba); + + if (track != -1) { + req.spt.DataTransferLength = len; + ret = 1; + } + } else { + len = COOKED_SECTOR_SIZE; + track = ioctl_get_track(ioctl, lba); + + if (track != -1) { + DWORD newPos = SetFilePointer(ioctl->handle, (long) lba * COOKED_SECTOR_SIZE, + 0, FILE_BEGIN); + + if (newPos != 0xffffffff) + ret = ReadFile(ioctl->handle, &(buffer[16]), + COOKED_SECTOR_SIZE, (LPDWORD) &req.spt.DataTransferLength, + NULL); + } } + + if (ret && (req.spt.DataTransferLength >= len) && (track != -1)) { + const raw_track_info_t *ct = &(rti[track]); + const uint32_t start = (ct->pm * 60 * 75) + (ct->ps * 75) + ct->pf; + + m = s = f = 0; + + /* Construct sector header and sub-header. */ + if (sector != 0xffffffff) { + /* Sync bytes. */ + buffer[0] = 0x00; + memset(&(buffer[1]), 0xff, 10); + buffer[11] = 0x00; + + /* Sector header. */ + FRAMES_TO_MSF(lba + 150, &m, &s, &f); + buffer[12] = bin2bcd(m); + buffer[13] = bin2bcd(s); + buffer[14] = bin2bcd(f); + + /* Mode 1 data. */ + buffer[15] = 0x01; + } + + /* Construct Q. */ + buffer[sc_offs + 0] = (ct->adr_ctl >> 4) | ((ct->adr_ctl & 0xf) << 4); + buffer[sc_offs + 1] = bin2bcd(ct->point); + buffer[sc_offs + 2] = 1; + FRAMES_TO_MSF((int32_t) (lba + 150 - start), &m, &s, &f); + buffer[sc_offs + 3] = bin2bcd(m); + buffer[sc_offs + 4] = bin2bcd(s); + buffer[sc_offs + 5] = bin2bcd(f); + FRAMES_TO_MSF(lba + 150, &m, &s, &f); + buffer[sc_offs + 7] = bin2bcd(m); + buffer[sc_offs + 8] = bin2bcd(s); + buffer[sc_offs + 9] = bin2bcd(f); + } + } else { + memset(&req, 0x00, sizeof(SCSI_PASS_THROUGH_DIRECT_BUF)); + req.spt.Length = sizeof(SCSI_PASS_THROUGH_DIRECT); + req.spt.PathId = 0; + req.spt.TargetId = 1; + req.spt.Lun = 0; + req.spt.CdbLength = 12; + req.spt.DataIn = SCSI_IOCTL_DATA_IN; + req.spt.SenseInfoLength = sizeof(req.SenseBuf); + req.spt.DataTransferLength = len; + req.spt.TimeOutValue = 6; + req.spt.DataBuffer = buffer; + req.spt.SenseInfoOffset = offsetof(SCSI_PASS_THROUGH_DIRECT_BUF, SenseBuf); + + /* Fill in the CDB. */ + req.spt.Cdb[0] = 0xbe; /* READ CD */ + req.spt.Cdb[1] = 0x00; + req.spt.Cdb[2] = (sector >> 24) & 0xff; + req.spt.Cdb[3] = (sector >> 16) & 0xff; + req.spt.Cdb[4] = (sector >> 8) & 0xff; + req.spt.Cdb[5] = sector & 0xff; /* Starting Logical Block Address. */ + req.spt.Cdb[6] = 0x00; + req.spt.Cdb[7] = 0x00; + req.spt.Cdb[8] = 0x01; /* Transfer Length. */ + /* If sector is FFFFFFFF, only return the subchannel. */ + req.spt.Cdb[9] = (sector == 0xffffffff) ? 0x00 : 0xf8; + req.spt.Cdb[10] = 0x02; + req.spt.Cdb[11] = 0x00; + DWORD length = sizeof(SCSI_PASS_THROUGH_DIRECT_BUF); + +#ifdef ENABLE_IOCTL_LOG + uint8_t *cdb = (uint8_t *) req.spt.Cdb; + ioctl_log(ioctl->log, "Host CDB: %02X %02X %02X %02X %02X %02X " + "%02X %02X %02X %02X %02X %02X\n", + ioctl->dev->id, cdb[0], cdb[1], cdb[2], cdb[3], cdb[4], cdb[5], + cdb[6], cdb[7], cdb[8], cdb[9], cdb[10], cdb[11]); +#endif + + ret = DeviceIoControl(ioctl->handle, IOCTL_SCSI_PASS_THROUGH_DIRECT, + &req, length, + &req, length, &unused, NULL); } - const int ret = (control & 0x01); + ioctl_log(ioctl->log, "ioctl_read_sector: ret = %d, req.spt.DataTransferLength = %lu\n", + ret, req.spt.DataTransferLength); + ioctl_log(ioctl->log, "Sense: %08X, %08X\n", req.spt.SenseInfoLength, req.spt.SenseInfoOffset); + if (req.spt.SenseInfoLength >= 16) { + uint8_t *cdb = (uint8_t *) req.SenseBuf; + if ((cdb[2] == 0x03) && (cdb[12] == 0x11)) + /* Treat this as an error to corectly indicate CIRC error to the guest. */ + ret = 0; + ioctl_log(ioctl->log, "Host sense: %02X %02X %02X %02X %02X %02X %02X %02X\n", + cdb[0], cdb[1], cdb[ 2], cdb[ 3], cdb[ 4], cdb[ 5], cdb[ 6], cdb[ 7]); + ioctl_log(ioctl->log, " %02X %02X %02X %02X %02X %02X %02X %02X\n", + cdb[8], cdb[9], cdb[10], cdb[11], cdb[12], cdb[13], cdb[14], cdb[15]); + } - win_cdrom_ioctl_log("plat_cdrom_is_track_audio(%08X): %i\n", sector, ret); + ret = (!!ret > 0) ? (req.spt.DataTransferLength >= len) : -1; + ioctl_log(ioctl->log, "iocl_read_sector: final ret = %i\n", ret); + + /* Construct raw subchannel data from Q only. */ + if ((ret > 0) && (req.spt.DataTransferLength >= len)) + for (int i = 11; i >= 0; i--) + for (int j = 7; j >= 0; j--) + buffer[2352 + (i * 8) + j] = ((buffer[sc_offs + i] >> (7 - j)) & 0x01) << 6; + + ioctl_close_handle((ioctl_t *) ioctl); return ret; } -uint32_t -plat_cdrom_get_track_start(void *local, uint32_t sector, uint8_t *attr, uint8_t *track) +static uint8_t +ioctl_get_track_type(const void *local, const uint32_t sector) { - win_cdrom_ioctl_t *ioctl = (win_cdrom_ioctl_t *) local; - PCDROM_TOC toc = (PCDROM_TOC) ioctl->cur_toc; - uint32_t cur_addr = 0; - uint32_t next_addr = 0; + ioctl_t * ioctl = (ioctl_t *) local; + int track = ioctl_get_track(ioctl, sector); + raw_track_info_t * rti = (raw_track_info_t *) ioctl->cur_rti; + const raw_track_info_t *trk = &(rti[track]); + uint8_t ret = 0x00; - plat_cdrom_read_toc(ioctl); + if (ioctl_is_track_audio(ioctl, sector)) + ret = CD_TRACK_AUDIO; + else if (track != -1) for (int i = 0; i < ioctl->blocks_num; i++) { + const raw_track_info_t *ct = &(rti[i]); + const raw_track_info_t *nt = &(rti[i + 1]); - for (int c = 0; toc->TrackData[c].TrackNumber != 0xaa; c++) { - PTRACK_DATA cur_td = &toc->TrackData[c]; - PTRACK_DATA next_td = &toc->TrackData[c + 1]; + if (ct->point == 0xa0) { + uint8_t first = ct->pm; + uint8_t last = nt->pm; - cur_addr = MSFtoLBA(cur_td->Address[1], cur_td->Address[2], cur_td->Address[3]) - 150; - next_addr = MSFtoLBA(next_td->Address[1], next_td->Address[2], next_td->Address[3]) - 150; - - win_cdrom_ioctl_log("F: %i, L: %i, C: %i (%i), c: %02X, a: %02X, A: %08X, S: %08X\n", - toc->FirstTrack, toc->LastTrack, cur_td->TrackNumber, c, - cur_td->Control, cur_td->Adr, cur_addr, sector); - - if ((cur_td->TrackNumber >= toc->FirstTrack) && (cur_td->TrackNumber <= toc->LastTrack) && - (sector >= cur_addr) && (sector < next_addr)) { - *track = cur_td->TrackNumber; - *attr = cur_td->Control; - *attr |= ((cur_td->Adr << 4) & 0xf0); - break; + if ((trk->point >= first) && (trk->point <= last)) { + ret = ct->ps; + break; + } } } - win_cdrom_ioctl_log("plat_cdrom_get_track_start(%08X): %i\n", sector, cur_addr); - - return cur_addr; + return ret; } -uint32_t -plat_cdrom_get_last_block(void *local) +static uint32_t +ioctl_get_last_block(const void *local) { - win_cdrom_ioctl_t *ioctl = (win_cdrom_ioctl_t *) local; - PCDROM_TOC toc = (PCDROM_TOC) ioctl->cur_toc; - uint32_t lb = 0; - uint32_t address = 0; - - plat_cdrom_read_toc(ioctl); + const ioctl_t *ioctl = (const ioctl_t *) local; + const CDROM_TOC *toc = (const CDROM_TOC *) ioctl->cur_toc; + uint32_t lb = 0; for (int c = 0; c <= toc->LastTrack; c++) { - PTRACK_DATA td = &toc->TrackData[c]; - - address = MSFtoLBA(td->Address[1], td->Address[2], td->Address[3]) - 150; + const TRACK_DATA *td = &toc->TrackData[c]; + const uint32_t address = MSFtoLBA(td->Address[1], td->Address[2], + td->Address[3]) - 150; if (address > lb) lb = address; } - win_cdrom_ioctl_log("LBCapacity=%d\n", lb); + ioctl_log(ioctl->log, "LBCapacity=%d\n", lb); return lb; } -int -plat_cdrom_ext_medium_changed(void *local) -{ - win_cdrom_ioctl_t *ioctl = (win_cdrom_ioctl_t *) local; - PCDROM_TOC toc = (PCDROM_TOC) ioctl->cur_toc; - uint8_t new_toc_buf[65536] = { 0 }; - PCDROM_TOC new_toc = (PCDROM_TOC) new_toc_buf; - int ret = 0; - int temp = plat_cdrom_read_normal_toc(ioctl, new_toc_buf); - PTRACK_DATA cur_ltd = &toc->TrackData[toc->LastTrack]; - - if (temp != 0) - plat_cdrom_read_raw_toc(ioctl); - - PTRACK_DATA new_ltd = &new_toc->TrackData[new_toc->LastTrack]; - - if (temp == 0) - /* There has been some kind of error - not a medium change, but a not ready - condition. */ - ret = -1; - else if (!ioctl->toc_valid || (memcmp(ioctl->path, ioctl->old_path, sizeof(ioctl->path)) != 0)) { - /* Changed to a different host drive - we already detect such medium changes. */ - ioctl->toc_valid = 1; - memcpy(toc, new_toc, 65535); - if (memcmp(ioctl->path, ioctl->old_path, sizeof(ioctl->path)) != 0) - memcpy(ioctl->old_path, ioctl->path, sizeof(ioctl->path)); - } else if (memcmp(&(new_ltd->Address[1]), &(cur_ltd->Address[1]), 3)) { - /* The TOC has changed. */ - ioctl->toc_valid = 1; - memcpy(toc, new_toc, 65535); - if (memcmp(ioctl->path, ioctl->old_path, sizeof(ioctl->path)) != 0) - memcpy(ioctl->old_path, ioctl->path, sizeof(ioctl->path)); - ret = 1; - } - - win_cdrom_ioctl_log("plat_cdrom_ext_medium_changed(): %i\n", ret); - - return ret; -} - -/* This replaces both Info and EndInfo, they are specified by a variable. */ -int -plat_cdrom_get_audio_track_info(void *local, UNUSED(int end), int track, int *track_num, TMSF *start, uint8_t *attr) -{ - win_cdrom_ioctl_t *ioctl = (win_cdrom_ioctl_t *) local; - PCDROM_TOC toc = (PCDROM_TOC) ioctl->cur_toc; - - plat_cdrom_read_toc(ioctl); - - if ((track < 1) || (track == 0xaa) || (track > (toc->LastTrack + 1))) { - win_cdrom_ioctl_log("plat_cdrom_get_audio_track_info(%02i)\n", track); - return 0; - } - - PTRACK_DATA td = &toc->TrackData[track - 1]; - - start->min = td->Address[1]; - start->sec = td->Address[2]; - start->fr = td->Address[3]; - - *track_num = td->TrackNumber; - *attr = td->Control; - *attr |= ((td->Adr << 4) & 0xf0); - - win_cdrom_ioctl_log("plat_cdrom_get_audio_track_info(%02i): %02i:%02i:%02i, %02i, %02X\n", - track, start->min, start->sec, start->fr, *track_num, *attr); - - return 1; -} - -/* TODO: See if track start is adjusted by 150 or not. */ -int -plat_cdrom_get_audio_sub(void *local, UNUSED(uint32_t sector), uint8_t *attr, uint8_t *track, uint8_t *index, - TMSF *rel_pos, TMSF *abs_pos) -{ - win_cdrom_ioctl_t * ioctl = (win_cdrom_ioctl_t *) local; - CDROM_SUB_Q_DATA_FORMAT insub; - SUB_Q_CHANNEL_DATA sub; - long size = 0; - - insub.Format = IOCTL_CDROM_CURRENT_POSITION; - - plat_cdrom_open(ioctl); - DeviceIoControl(ioctl->handle, IOCTL_CDROM_READ_Q_CHANNEL, &insub, sizeof(insub), &sub, sizeof(sub), - (LPDWORD) &size, NULL); - plat_cdrom_close(ioctl); - - if (sub.CurrentPosition.TrackNumber < 1) - return 0; - - *track = sub.CurrentPosition.TrackNumber; - *attr = sub.CurrentPosition.Control; - *attr |= ((sub.CurrentPosition.ADR << 4) & 0xf0); - *index = sub.CurrentPosition.IndexNumber; - - rel_pos->min = sub.CurrentPosition.TrackRelativeAddress[1]; - rel_pos->sec = sub.CurrentPosition.TrackRelativeAddress[2]; - rel_pos->fr = sub.CurrentPosition.TrackRelativeAddress[3]; - abs_pos->min = sub.CurrentPosition.AbsoluteAddress[1]; - abs_pos->sec = sub.CurrentPosition.AbsoluteAddress[2]; - abs_pos->fr = sub.CurrentPosition.AbsoluteAddress[3]; - - win_cdrom_ioctl_log("plat_cdrom_get_audio_sub(): %02i, %02X, %02i, %02i:%02i:%02i, %02i:%02i:%02i\n", - *track, *attr, *index, rel_pos->min, rel_pos->sec, rel_pos->fr, abs_pos->min, abs_pos->sec, - abs_pos->fr); - - return 1; -} - -int -plat_cdrom_get_sector_size(void *local, UNUSED(uint32_t sector)) -{ - win_cdrom_ioctl_t * ioctl = (win_cdrom_ioctl_t *) local; - long size; - DISK_GEOMETRY dgCDROM; - - plat_cdrom_open(ioctl); - DeviceIoControl(ioctl->handle, IOCTL_CDROM_GET_DRIVE_GEOMETRY, NULL, 0, &dgCDROM, sizeof(dgCDROM), - (LPDWORD) &size, NULL); - plat_cdrom_close(ioctl); - - win_cdrom_ioctl_log("BytesPerSector=%d\n", dgCDROM.BytesPerSector); - return dgCDROM.BytesPerSector; -} - -int -plat_cdrom_read_sector(void *local, uint8_t *buffer, uint32_t sector) +static int +ioctl_read_dvd_structure(const void *local, const uint8_t layer, const uint8_t format, + uint8_t *buffer, uint32_t *info) { typedef struct SCSI_PASS_THROUGH_DIRECT_BUF { SCSI_PASS_THROUGH_DIRECT spt; ULONG Filler; - UCHAR SenseBuf[32]; + UCHAR SenseBuf[64]; } SCSI_PASS_THROUGH_DIRECT_BUF; - win_cdrom_ioctl_t * ioctl = (win_cdrom_ioctl_t *) local; - int sc_offs = (sector == 0xffffffff) ? 0 : 2352; + const ioctl_t * ioctl = (const ioctl_t *) local; unsigned long int unused = 0; - int ret; + const int len = 2052; SCSI_PASS_THROUGH_DIRECT_BUF req; - memset(&req, 0x00, sizeof(req)); - req.Filler = 0; + ioctl_open_handle((ioctl_t *) ioctl); + + memset(&req, 0x00, sizeof(SCSI_PASS_THROUGH_DIRECT_BUF)); req.spt.Length = sizeof(SCSI_PASS_THROUGH_DIRECT); + req.spt.PathId = 0; + req.spt.TargetId = 1; + req.spt.Lun = 0; req.spt.CdbLength = 12; req.spt.DataIn = SCSI_IOCTL_DATA_IN; - req.spt.SenseInfoOffset = offsetof(SCSI_PASS_THROUGH_DIRECT_BUF, SenseBuf); req.spt.SenseInfoLength = sizeof(req.SenseBuf); + req.spt.DataTransferLength = len; req.spt.TimeOutValue = 6; - req.spt.DataTransferLength = 2368; req.spt.DataBuffer = buffer; + req.spt.SenseInfoOffset = offsetof(SCSI_PASS_THROUGH_DIRECT_BUF, SenseBuf); /* Fill in the CDB. */ - req.spt.Cdb[0] = 0xbe; /* READ CD */ - req.spt.Cdb[1] = 0x00; /* DAP = 0, Any Sector Type. */ - req.spt.Cdb[2] = (sector >> 24) & 0xff; - req.spt.Cdb[3] = (sector >> 16) & 0xff; - req.spt.Cdb[4] = (sector >> 8) & 0xff; - req.spt.Cdb[5] = sector & 0xff; /* Starting Logical Block Address. */ - req.spt.Cdb[6] = 0x00; - req.spt.Cdb[7] = 0x00; - req.spt.Cdb[8] = 0x01; /* Transfer Length. */ - /* If sector is FFFFFFFF, only return the subchannel. */ - req.spt.Cdb[9] = (sector == 0xffffffff) ? 0x00 : 0xf8; - req.spt.Cdb[10] = 0x02; + req.spt.Cdb[0] = 0xad; + req.spt.Cdb[1] = 0x00; + req.spt.Cdb[2] = 0x00; + req.spt.Cdb[3] = 0x00; + req.spt.Cdb[4] = 0x00; + req.spt.Cdb[5] = 0x00; + req.spt.Cdb[6] = layer; /* Layer Number */ + req.spt.Cdb[7] = format; /* Format */ + req.spt.Cdb[8] = 0x08; /* Allocation Length */ + req.spt.Cdb[9] = 0x04; + req.spt.Cdb[10] = 0x00; /* AGID */ req.spt.Cdb[11] = 0x00; - plat_cdrom_open(ioctl); - ret = DeviceIoControl(ioctl->handle, IOCTL_SCSI_PASS_THROUGH_DIRECT, &req, sizeof(req), &req, sizeof(req), - &unused, NULL); - plat_cdrom_close(ioctl); + DWORD length = sizeof(SCSI_PASS_THROUGH_DIRECT_BUF); - /* Construct raw subchannel data from Q only. */ - if (ret && (req.spt.DataTransferLength >= 2368)) - for (int i = 11; i >= 0; i--) - for (int j = 7; j >= 0; j--) - buffer[2352 + (i * 8) + j] = ((buffer[sc_offs + i] >> (7 - j)) & 0x01) << 6; +#ifdef ENABLE_IOCTL_LOG + uint8_t *cdb = (uint8_t *) req.spt.Cdb; + ioctl_log(ioctl->log, "Host CDB: %02X %02X %02X %02X %02X %02X " + "%02X %02X %02X %02X %02X %02X\n", + cdb[0], cdb[1], cdb[2], cdb[3], cdb[4], cdb[5], + cdb[6], cdb[7], cdb[8], cdb[9], cdb[10], cdb[11]); +#endif - win_cdrom_ioctl_log("plat_cdrom_read_scsi_direct: ret = %d, req.spt.DataTransferLength = %lu\n", - ret, req.spt.DataTransferLength); - win_cdrom_ioctl_log("Sense: %08X, %08X\n", req.spt.SenseInfoLength, req.spt.SenseInfoOffset); - return ret && (req.spt.DataTransferLength >= 2368); + int ret = DeviceIoControl(ioctl->handle, IOCTL_SCSI_PASS_THROUGH_DIRECT, + &req, length, + &req, length, + &unused, NULL); + + ioctl_log(ioctl->log, "ioctl_read_dvd_structure(): ret = %d, " + "req.spt.DataTransferLength = %lu\n", + ret, req.spt.DataTransferLength); + ioctl_log(ioctl->log, "Sense: %08X, %08X\n", req.spt.SenseInfoLength, + req.spt.SenseInfoOffset); + + if (req.spt.SenseInfoLength >= 16) { + uint8_t *sb = (uint8_t *) req.SenseBuf; + /* Return sense to the host as is. */ + ret = -((sb[2] << 16) | (sb[12] << 8) | sb[13]); + if (info != NULL) + *info = *(uint32_t *) &(sb[3]); + ioctl_log(ioctl->log, "Host sense: %02X %02X %02X %02X %02X %02X %02X %02X\n", + sb[0], sb[1], sb[ 2], sb[ 3], sb[ 4], sb[ 5], sb[ 6], sb[ 7]); + ioctl_log(ioctl->log, " %02X %02X %02X %02X %02X %02X %02X %02X\n", + sb[8], sb[9], sb[10], sb[11], sb[12], sb[13], sb[14], sb[15]); + } else + ret = ret ? (req.spt.DataTransferLength >= len) : 0; + + ioctl_close_handle((ioctl_t *) ioctl); + + return ret; } -void -plat_cdrom_eject(void *local) +static int +ioctl_is_dvd(const void *local) { - win_cdrom_ioctl_t *ioctl = (win_cdrom_ioctl_t *) local; - long size; + const ioctl_t *ioctl = (const ioctl_t *) local; - plat_cdrom_open(ioctl); - DeviceIoControl(ioctl->handle, IOCTL_STORAGE_EJECT_MEDIA, NULL, 0, NULL, 0, (LPDWORD) &size, NULL); - plat_cdrom_close(ioctl); + return ioctl->is_dvd; } -void -plat_cdrom_close(void *local) +static int +ioctl_has_audio(const void *local) { - win_cdrom_ioctl_t *ioctl = (win_cdrom_ioctl_t *) local; + const ioctl_t *ioctl = (const ioctl_t *) local; - plat_cdrom_close_handle(ioctl); + return ioctl->has_audio; +} + +static int +ioctl_is_empty(const void *local) +{ + typedef struct SCSI_PASS_THROUGH_DIRECT_BUF { + SCSI_PASS_THROUGH_DIRECT spt; + ULONG Filler; + UCHAR SenseBuf[64]; + } SCSI_PASS_THROUGH_DIRECT_BUF; + + const ioctl_t * ioctl = (const ioctl_t *) local; + unsigned long int unused = 0; + SCSI_PASS_THROUGH_DIRECT_BUF req; + + ioctl_open_handle((ioctl_t *) ioctl); + + memset(&req, 0x00, sizeof(SCSI_PASS_THROUGH_DIRECT_BUF)); + req.spt.Length = sizeof(SCSI_PASS_THROUGH_DIRECT); + req.spt.PathId = 0; + req.spt.TargetId = 1; + req.spt.Lun = 0; + req.spt.CdbLength = 12; + req.spt.DataIn = SCSI_IOCTL_DATA_IN; + req.spt.SenseInfoLength = sizeof(req.SenseBuf); + req.spt.DataTransferLength = 0; + req.spt.TimeOutValue = 6; + req.spt.DataBuffer = NULL; + req.spt.SenseInfoOffset = offsetof(SCSI_PASS_THROUGH_DIRECT_BUF, SenseBuf); + + /* Fill in the CDB. */ + req.spt.Cdb[0] = 0x00; + req.spt.Cdb[1] = 0x00; + req.spt.Cdb[2] = 0x00; + req.spt.Cdb[3] = 0x00; + req.spt.Cdb[4] = 0x00; + req.spt.Cdb[5] = 0x00; + req.spt.Cdb[6] = 0x00; + req.spt.Cdb[7] = 0x00; + req.spt.Cdb[8] = 0x00; + req.spt.Cdb[9] = 0x00; + req.spt.Cdb[10] = 0x00; + req.spt.Cdb[11] = 0x00; + + DWORD length = sizeof(SCSI_PASS_THROUGH_DIRECT_BUF); + +#ifdef ENABLE_IOCTL_LOG + uint8_t *cdb = (uint8_t *) req.spt.Cdb; + ioctl_log(ioctl->log, "Host CDB: %02X %02X %02X %02X %02X %02X " + "%02X %02X %02X %02X %02X %02X\n", + cdb[0], cdb[1], cdb[2], cdb[3], cdb[4], cdb[5], + cdb[6], cdb[7], cdb[8], cdb[9], cdb[10], cdb[11]); +#endif + + int ret = DeviceIoControl(ioctl->handle, IOCTL_SCSI_PASS_THROUGH_DIRECT, + &req, length, + &req, length, + &unused, NULL); + + ioctl_log(ioctl->log, "ioctl_read_dvd_structure(): ret = %d, " + "req.spt.DataTransferLength = %lu\n", + ret, req.spt.DataTransferLength); + ioctl_log(ioctl->log, "Sense: %08X, %08X\n", req.spt.SenseInfoLength, + req.spt.SenseInfoOffset); + + if (req.spt.SenseInfoLength >= 16) { + uint8_t *sb = (uint8_t *) req.SenseBuf; + /* Return sense to the host as is. */ + ret = ((sb[2] == SENSE_NOT_READY) && (sb[12] == ASC_MEDIUM_NOT_PRESENT)); + ioctl_log(ioctl->log, "Host sense: %02X %02X %02X %02X %02X %02X %02X %02X\n", + sb[0], sb[1], sb[ 2], sb[ 3], sb[ 4], sb[ 5], sb[ 6], sb[ 7]); + ioctl_log(ioctl->log, " %02X %02X %02X %02X %02X %02X %02X %02X\n", + sb[8], sb[9], sb[10], sb[11], sb[12], sb[13], sb[14], sb[15]); + } else + ret = 0; + + ioctl_close_handle((ioctl_t *) ioctl); + + return ret; +} + +static void +ioctl_close(void *local) +{ + ioctl_t *ioctl = (ioctl_t *) local; + + ioctl_close_handle(ioctl); ioctl->handle = NULL; + + ioctl_log(ioctl->log, "Log closed\n"); + + log_close(ioctl->log); + ioctl->log = NULL; } -int -plat_cdrom_set_drive(void *local, const char *drv) +static void +ioctl_load(const void *local) { - win_cdrom_ioctl_t *ioctl = (win_cdrom_ioctl_t *) local; + const ioctl_t *ioctl = (const ioctl_t *) local; - plat_cdrom_close(ioctl); + if (ioctl_open_handle((ioctl_t *) ioctl)) { + long size; + DeviceIoControl(ioctl->handle, IOCTL_STORAGE_LOAD_MEDIA, + NULL, 0, NULL, 0, + (LPDWORD) &size, NULL); + ioctl_close_handle((ioctl_t *) ioctl); - memcpy(ioctl->old_path, ioctl->path, sizeof(ioctl->path)); - memset(ioctl->path, 0x00, sizeof(ioctl->path)); - - wsprintf(ioctl->path, L"%S", drv); - win_cdrom_ioctl_log("Path is %S\n", ioctl->path); - - ioctl->toc_valid = 0; - - plat_cdrom_load(ioctl); - - return 1; + ioctl_read_toc((ioctl_t *) ioctl); + } } -int -plat_cdrom_get_local_size(void) +static const cdrom_ops_t ioctl_ops = { + ioctl_get_track_info, + ioctl_get_raw_track_info, + ioctl_is_track_pre, + ioctl_read_sector, + ioctl_get_track_type, + ioctl_get_last_block, + ioctl_read_dvd_structure, + ioctl_is_dvd, + ioctl_has_audio, + ioctl_is_empty, + ioctl_close, + ioctl_load +}; + +/* Public functions. */ +void * +ioctl_open(cdrom_t *dev, const char *drv) { - return sizeof(win_cdrom_ioctl_t); + ioctl_t *ioctl = (ioctl_t *) calloc(1, sizeof(ioctl_t)); + + if (ioctl != NULL) { + char n[1024] = { 0 }; + + sprintf(n, "CD-ROM %i IOCtl", dev->id + 1); + ioctl->log = log_open(n); + + memset(ioctl->path, 0x00, sizeof(ioctl->path)); + + wsprintf(ioctl->path, L"%S", &(drv[8])); + ioctl_log(ioctl->log, "Path is %S\n", ioctl->path); + + ioctl->dev = dev; + + dev->ops = &ioctl_ops; + + ioctl_load(ioctl); + } + + return ioctl; } diff --git a/src/qt/win_joystick_rawinput.c b/src/qt/win_joystick_rawinput.c index c293dcaca..5173d4f05 100644 --- a/src/qt/win_joystick_rawinput.c +++ b/src/qt/win_joystick_rawinput.c @@ -8,15 +8,13 @@ * * RawInput joystick interface. * - * - * * Authors: Miran Grca, * GH Cao, - * Jasmine Iwanek, + * Jasmine Iwanek, * * Copyright 2016-2018 Miran Grca. * Copyright 2020 GH Cao. - * Copyright 2021-2023 Jasmine Iwanek. + * Copyright 2021-2025 Jasmine Iwanek. */ #include #include @@ -98,9 +96,9 @@ typedef struct { } pov[MAX_JOY_POVS]; } raw_joystick_t; -plat_joystick_t plat_joystick_state[MAX_PLAT_JOYSTICKS]; -joystick_t joystick_state[MAX_JOYSTICKS]; int joysticks_present = 0; +joystick_t joystick_state[GAMEPORT_MAX][MAX_JOYSTICKS]; +plat_joystick_t plat_joystick_state[MAX_PLAT_JOYSTICKS]; raw_joystick_t raw_joystick_state[MAX_PLAT_JOYSTICKS]; @@ -419,7 +417,7 @@ win_joystick_handle(PRAWINPUT raw) if (r == HIDP_STATUS_SUCCESS) { for (int i = 0; i < usage_length; i++) { - int button = raw_joystick_state[j].usage_button[usage_list[i]]; + int button = raw_joystick_state[j].usage_button[usage_list[i]]; plat_joystick_state[j].b[button] = 128; } } @@ -455,7 +453,7 @@ win_joystick_handle(PRAWINPUT raw) plat_joystick_state[j].a[axis_nr] = value; #if 0 - joystick_log("%s %-06d ", plat_joystick_state[j].axis[axis_nr].name, plat_joystick_state[j].a[axis_nr]); + joystick_log("%s %-06d ", plat_joystick_state[0][j].axis[axis_nr].name, plat_joystick_state[j].a[axis_nr]); #endif } @@ -477,7 +475,7 @@ win_joystick_handle(PRAWINPUT raw) plat_joystick_state[j].p[pov_nr] = value; #if 0 - joystick_log("%s %-3d ", plat_joystick_state[j].pov[pov_nr].name, plat_joystick_state[j].p[pov_nr]); + joystick_log("%s %-3d ", plat_joystick_state[0][j].pov[pov_nr].name, plat_joystick_state[j].p[pov_nr]); #endif } #if 0 @@ -512,35 +510,35 @@ joystick_process(void) return; for (int js = 0; js < joystick_get_max_joysticks(joystick_type); js++) { - if (joystick_state[js].plat_joystick_nr) { - int joystick_nr = joystick_state[js].plat_joystick_nr - 1; + if (joystick_state[0][js].plat_joystick_nr) { + int joystick_nr = joystick_state[0][js].plat_joystick_nr - 1; for (int axis_nr = 0; axis_nr < joystick_get_axis_count(joystick_type); axis_nr++) - joystick_state[js].axis[axis_nr] = joystick_get_axis(joystick_nr, joystick_state[js].axis_mapping[axis_nr]); + joystick_state[0][js].axis[axis_nr] = joystick_get_axis(joystick_nr, joystick_state[0][js].axis_mapping[axis_nr]); for (int button_nr = 0; button_nr < joystick_get_button_count(joystick_type); button_nr++) - joystick_state[js].button[button_nr] = plat_joystick_state[joystick_nr].b[joystick_state[js].button_mapping[button_nr]]; + joystick_state[0][js].button[button_nr] = plat_joystick_state[joystick_nr].b[joystick_state[0][js].button_mapping[button_nr]]; for (int pov_nr = 0; pov_nr < joystick_get_pov_count(joystick_type); pov_nr++) { - int x = joystick_get_axis(joystick_nr, joystick_state[js].pov_mapping[pov_nr][0]); - int y = joystick_get_axis(joystick_nr, joystick_state[js].pov_mapping[pov_nr][1]); + int x = joystick_get_axis(joystick_nr, joystick_state[0][js].pov_mapping[pov_nr][0]); + int y = joystick_get_axis(joystick_nr, joystick_state[0][js].pov_mapping[pov_nr][1]); double angle = (atan2((double) y, (double) x) * 360.0) / (2 * M_PI); double magnitude = sqrt((double) x * (double) x + (double) y * (double) y); if (magnitude < 16384) - joystick_state[js].pov[pov_nr] = -1; + joystick_state[0][js].pov[pov_nr] = -1; else - joystick_state[js].pov[pov_nr] = ((int) angle + 90 + 360) % 360; + joystick_state[0][js].pov[pov_nr] = ((int) angle + 90 + 360) % 360; } } else { for (int axis_nr = 0; axis_nr < joystick_get_axis_count(joystick_type); axis_nr++) - joystick_state[js].axis[axis_nr] = 0; + joystick_state[0][js].axis[axis_nr] = 0; for (int button_nr = 0; button_nr < joystick_get_button_count(joystick_type); button_nr++) - joystick_state[js].button[button_nr] = 0; + joystick_state[0][js].button[button_nr] = 0; for (int pov_nr = 0; pov_nr < joystick_get_pov_count(joystick_type); pov_nr++) - joystick_state[js].pov[pov_nr] = -1; + joystick_state[0][js].pov[pov_nr] = -1; } } } diff --git a/src/qt/win_opendir.c b/src/qt/win_opendir.c index 051ed20bb..46c7eb21e 100644 --- a/src/qt/win_opendir.c +++ b/src/qt/win_opendir.c @@ -40,21 +40,19 @@ opendir(const char *name) DIR *p; /* Create a new control structure. */ - p = (DIR *) malloc(sizeof(DIR)); + p = (DIR *) calloc(1, sizeof(DIR)); if (p == NULL) return (NULL); - memset(p, 0x00, sizeof(DIR)); p->flags = (DIR_F_LOWER | DIR_F_SANE); p->offset = 0; p->sts = 0; /* Create a work area. */ - p->dta = (char *) malloc(sizeof(FINDATA)); + p->dta = (char *) calloc(1, sizeof(FINDATA)); if (p->dta == NULL) { free(p); return (NULL); } - memset(p->dta, 0x00, sizeof(struct _finddata_t)); /* Add search filespec. */ strcpy(p->dir, name); diff --git a/src/scsi/scsi_aha154x.c b/src/scsi/scsi_aha154x.c index 937213b85..b6a1698c5 100644 --- a/src/scsi/scsi_aha154x.c +++ b/src/scsi/scsi_aha154x.c @@ -925,8 +925,7 @@ aha_setnvr(x54x_t *dev) return; /* Allocate and initialize the EEPROM. */ - dev->nvr = (uint8_t *) malloc(NVR_SIZE); - memset(dev->nvr, 0x00, NVR_SIZE); + dev->nvr = (uint8_t *) calloc(1, NVR_SIZE); fp = nvr_fopen(dev->nvr_path, "rb"); if (fp) { @@ -1447,7 +1446,7 @@ const device_t aha154xa_device = { .init = aha_init, .close = x54x_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = aha_154xb_config @@ -1461,7 +1460,7 @@ const device_t aha154xb_device = { .init = aha_init, .close = x54x_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = aha_154xb_config @@ -1475,7 +1474,7 @@ const device_t aha154xc_device = { .init = aha_init, .close = x54x_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = aha_154x_config @@ -1489,7 +1488,7 @@ const device_t aha154xcf_device = { .init = aha_init, .close = x54x_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = aha_154xcf_config @@ -1503,7 +1502,7 @@ const device_t aha154xcp_device = { .init = aha_init, .close = aha1542cp_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = aha_154xcp_config @@ -1517,7 +1516,7 @@ const device_t aha1640_device = { .init = aha_init, .close = x54x_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/scsi/scsi_buslogic.c b/src/scsi/scsi_buslogic.c index b0aeedfa4..b235f2c3c 100644 --- a/src/scsi/scsi_buslogic.c +++ b/src/scsi/scsi_buslogic.c @@ -1546,8 +1546,7 @@ buslogic_init(const device_t *info) dev = x54x_init(info); dev->bus = scsi_get_bus(); - dev->ven_data = malloc(sizeof(buslogic_data_t)); - memset(dev->ven_data, 0x00, sizeof(buslogic_data_t)); + dev->ven_data = calloc(1, sizeof(buslogic_data_t)); bl = (buslogic_data_t *) dev->ven_data; @@ -1870,7 +1869,7 @@ const device_t buslogic_542b_device = { .init = buslogic_init, .close = x54x_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = BT_ISA_Config @@ -1884,7 +1883,7 @@ const device_t buslogic_545s_device = { .init = buslogic_init, .close = x54x_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = BT_ISA_Config @@ -1898,7 +1897,7 @@ const device_t buslogic_542bh_device = { .init = buslogic_init, .close = x54x_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = BT_ISA_Config @@ -1912,7 +1911,7 @@ const device_t buslogic_545c_device = { .init = buslogic_init, .close = x54x_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = BT_ISA_Config @@ -1926,7 +1925,7 @@ const device_t buslogic_640a_device = { .init = buslogic_init, .close = x54x_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -1940,7 +1939,7 @@ const device_t buslogic_445s_device = { .init = buslogic_init, .close = x54x_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = BT_ISA_Config @@ -1954,7 +1953,7 @@ const device_t buslogic_445c_device = { .init = buslogic_init, .close = x54x_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = BT_ISA_Config @@ -1968,7 +1967,7 @@ const device_t buslogic_958d_pci_device = { .init = buslogic_init, .close = x54x_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = BT958D_Config diff --git a/src/scsi/scsi_cdrom.c b/src/scsi/scsi_cdrom.c index 91773c62c..04c6532df 100644 --- a/src/scsi/scsi_cdrom.c +++ b/src/scsi/scsi_cdrom.c @@ -9,46 +9,41 @@ * Implementation of the CD-ROM drive with SCSI(-like) * commands, for both ATAPI and SCSI usage. * - * - * * Authors: Miran Grca, * - * Copyright 2016-2020 Miran Grca. + * Copyright 2016-2025 Miran Grca. */ -#include #include #include +#ifdef ENABLE_SCSI_CDROM_LOG +#include +#endif #include #include #include #include -#include -#define HAVE_STDARG_H #include <86box/86box.h> -#include <86box/config.h> #include <86box/timer.h> +#include <86box/cdrom.h> #include <86box/device.h> -#include <86box/scsi.h> -#include <86box/scsi_device.h> +#include <86box/log.h> #include <86box/machine.h> #include <86box/nvr.h> -#include <86box/hdc.h> -#include <86box/hdc_ide.h> -#include <86box/sound.h> #include <86box/plat.h> -#include <86box/ui.h> -#include <86box/cdrom.h> +#include <86box/scsi.h> +#include <86box/scsi_device.h> +#include <86box/hdc_ide.h> #include <86box/scsi_cdrom.h> -#include <86box/version.h> +#include <86box/ui.h> #define IDE_ATAPI_IS_EARLY id->sc->pad0 #pragma pack(push, 1) typedef struct gesn_cdb_t { - uint8_t opcode; - uint8_t polled; - uint8_t reserved2[2]; - uint8_t class; + uint8_t opcode; + uint8_t polled; + uint8_t reserved2[2]; + uint8_t class; uint8_t reserved3[2]; uint16_t len; uint8_t control; @@ -61,411 +56,192 @@ typedef struct gesn_event_header_t { } gesn_event_header_t; #pragma pack(pop) -/* Table of all SCSI commands and their flags, needed for the new disc change / not ready handler. */ +// clang-format off +/* + Table of all SCSI commands and their flags, needed for the new disc change / + not ready handler. + */ uint8_t scsi_cdrom_command_flags[0x100] = { - IMPLEMENTED | CHECK_READY | NONDATA, /* 0x00 */ - IMPLEMENTED | ALLOW_UA | NONDATA | SCSI_ONLY, /* 0x01 */ - 0, /* 0x02 */ - IMPLEMENTED | ALLOW_UA, /* 0x03 */ - 0, 0, 0, 0, /* 0x04-0x07 */ - IMPLEMENTED | CHECK_READY, /* 0x08 */ - 0, 0, /* 0x09-0x0A */ - IMPLEMENTED | CHECK_READY | NONDATA, /* 0x0B */ - 0, /* 0x0C */ - IMPLEMENTED | CHECK_READY | SCSI_ONLY, /* 0x0D */ - 0, 0, 0, 0, /* 0x0E-0x11 */ - IMPLEMENTED | ALLOW_UA, /* 0x12 */ - IMPLEMENTED | CHECK_READY | NONDATA | SCSI_ONLY, /* 0x13 */ - 0, /* 0x14 */ - IMPLEMENTED, /* 0x15 */ - 0, 0, 0, 0, /* 0x16-0x19 */ - IMPLEMENTED, /* 0x1A */ - IMPLEMENTED | CHECK_READY, /* 0x1B */ - 0, 0, /* 0x1C-0x1D */ - IMPLEMENTED | CHECK_READY, /* 0x1E */ - 0, 0, 0, /* 0x1F-0x21*/ - IMPLEMENTED | CHECK_READY | SCSI_ONLY, /* 0x22*/ - 0, 0, /* 0x23-0x24 */ - IMPLEMENTED | CHECK_READY, /* 0x25 */ - IMPLEMENTED | CHECK_READY | SCSI_ONLY, /* 0x26 */ - 0, /* 0x27 */ - IMPLEMENTED | CHECK_READY, /* 0x28 */ - 0, 0, /* 0x29-0x2A */ - IMPLEMENTED | CHECK_READY | NONDATA, /* 0x2B */ - 0, 0, 0, /* 0x2C-0x2E */ - IMPLEMENTED | CHECK_READY | NONDATA | SCSI_ONLY, /* 0x2F */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x30-0x3F */ - 0, 0, /* 0x40-0x41 */ - IMPLEMENTED | CHECK_READY, /* 0x42 */ - IMPLEMENTED | CHECK_READY, /* 0x43 - Read TOC - can get through UNIT_ATTENTION, per VIDE-CDD.SYS - NOTE: The ATAPI reference says otherwise, but I think this is a question of - interpreting things right - the UNIT ATTENTION condition we have here - is a tradition from not ready to ready, by definition the drive - eventually becomes ready, make the condition go away. */ - IMPLEMENTED | CHECK_READY, /* 0x44 */ - IMPLEMENTED | CHECK_READY, /* 0x45 */ - IMPLEMENTED | ALLOW_UA, /* 0x46 */ - IMPLEMENTED | CHECK_READY, /* 0x47 */ - IMPLEMENTED | CHECK_READY, /* 0x48 */ - IMPLEMENTED | CHECK_READY, /* 0x49 */ - IMPLEMENTED | ALLOW_UA, /* 0x4A */ - IMPLEMENTED | CHECK_READY, /* 0x4B */ - 0, 0, /* 0x4C-0x4D */ - IMPLEMENTED | CHECK_READY, /* 0x4E */ - 0, 0, /* 0x4F-0x50 */ - IMPLEMENTED | CHECK_READY, /* 0x51 */ - IMPLEMENTED | CHECK_READY, /* 0x52 */ - 0, 0, /* 0x53-0x54 */ - IMPLEMENTED, /* 0x55 */ - 0, 0, 0, 0, /* 0x56-0x59 */ - IMPLEMENTED, /* 0x5A */ - 0, 0, 0, 0, 0, /* 0x5B-0x5F */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x60-0x6F */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x70-0x7F */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x80-0x8F */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x90-0x9F */ - 0, 0, 0, 0, 0, /* 0xA0-0xA4 */ - IMPLEMENTED | CHECK_READY, /* 0xA5 */ - 0, 0, /* 0xA6-0xA7 */ - IMPLEMENTED | CHECK_READY, /* 0xA8 */ - IMPLEMENTED | CHECK_READY, /* 0xA9 */ - 0, 0, 0, /* 0xAA-0xAC */ - IMPLEMENTED | CHECK_READY, /* 0xAD */ - 0, /* 0xAE */ - IMPLEMENTED | CHECK_READY | NONDATA | SCSI_ONLY, /* 0xAF */ - 0, 0, 0, 0, /* 0xB0-0xB3 */ - IMPLEMENTED | CHECK_READY | ATAPI_ONLY, /* 0xB4 */ - 0, 0, 0, /* 0xB5-0xB7 */ - IMPLEMENTED | CHECK_READY | ATAPI_ONLY, /* 0xB8 */ - IMPLEMENTED | CHECK_READY, /* 0xB9 */ - IMPLEMENTED | CHECK_READY, /* 0xBA */ - IMPLEMENTED, /* 0xBB */ - IMPLEMENTED | CHECK_READY, /* 0xBC */ - IMPLEMENTED, /* 0xBD */ - IMPLEMENTED | CHECK_READY, /* 0xBE */ - IMPLEMENTED | CHECK_READY, /* 0xBF */ - IMPLEMENTED | CHECK_READY | SCSI_ONLY, /* 0xC0 */ - IMPLEMENTED | CHECK_READY | SCSI_ONLY, /* 0xC1 */ - IMPLEMENTED | CHECK_READY | SCSI_ONLY, /* 0xC2 */ - IMPLEMENTED | CHECK_READY | SCSI_ONLY, /* 0xC3 */ - IMPLEMENTED | CHECK_READY | SCSI_ONLY, /* 0xC4 */ - IMPLEMENTED | CHECK_READY | SCSI_ONLY, /* 0xC5 */ - IMPLEMENTED | CHECK_READY | SCSI_ONLY, /* 0xC6 */ - IMPLEMENTED | CHECK_READY | SCSI_ONLY, /* 0xC7 */ - IMPLEMENTED | CHECK_READY | SCSI_ONLY, /* 0xC8 */ - IMPLEMENTED | CHECK_READY | SCSI_ONLY, /* 0xC9 */ - IMPLEMENTED | CHECK_READY | SCSI_ONLY, /* 0xCA */ - IMPLEMENTED | CHECK_READY | SCSI_ONLY, /* 0xCB */ - IMPLEMENTED | CHECK_READY | SCSI_ONLY, /* 0xCC */ - IMPLEMENTED | CHECK_READY | SCSI_ONLY, /* 0xCD */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xCE-0xD7 */ - IMPLEMENTED | CHECK_READY | SCSI_ONLY, /* 0xD8 */ - IMPLEMENTED | CHECK_READY | SCSI_ONLY, /* 0xD9 */ - IMPLEMENTED | CHECK_READY | SCSI_ONLY, /* 0xDA */ - IMPLEMENTED | CHECK_READY | SCSI_ONLY, /* 0xDB */ - IMPLEMENTED | CHECK_READY | SCSI_ONLY, /* 0xDC */ - IMPLEMENTED | CHECK_READY | SCSI_ONLY, /* 0xDD */ - IMPLEMENTED | CHECK_READY | SCSI_ONLY, /* 0xDE */ - 0, /* 0xDF */ - IMPLEMENTED | CHECK_READY | SCSI_ONLY, /* 0xE0 */ - IMPLEMENTED | CHECK_READY | SCSI_ONLY, /* 0xE1 */ - 0, /* 0xE2 */ - IMPLEMENTED | CHECK_READY | SCSI_ONLY, /* 0xE3 */ - IMPLEMENTED | CHECK_READY | SCSI_ONLY, /* 0xE4 */ - IMPLEMENTED | CHECK_READY | SCSI_ONLY, /* 0xE5 */ - IMPLEMENTED | CHECK_READY | SCSI_ONLY, /* 0xE6 */ - IMPLEMENTED | CHECK_READY | SCSI_ONLY, /* 0xE7 */ - IMPLEMENTED | CHECK_READY | SCSI_ONLY, /* 0xE8 */ - IMPLEMENTED | CHECK_READY | SCSI_ONLY, /* 0xE9 */ - 0, /* 0xEA */ - IMPLEMENTED | CHECK_READY | SCSI_ONLY, /* 0xEB */ - 0, /* 0xEC */ - IMPLEMENTED | CHECK_READY | SCSI_ONLY, /* 0xED */ - IMPLEMENTED | CHECK_READY | SCSI_ONLY, /* 0xEE */ - 0, /* 0xEF */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 /* 0xF0-0xFF */ + [0x00] = IMPLEMENTED | CHECK_READY, + [0x01] = IMPLEMENTED | ALLOW_UA | SCSI_ONLY, + [0x03] = IMPLEMENTED | ALLOW_UA, + [0x08] = IMPLEMENTED | CHECK_READY, + [0x0b] = IMPLEMENTED | CHECK_READY, + [0x0d] = IMPLEMENTED | CHECK_READY | SCSI_ONLY, + [0x12] = IMPLEMENTED | ALLOW_UA, + [0x13] = IMPLEMENTED | CHECK_READY | SCSI_ONLY, + [0x15] = IMPLEMENTED, + [0x1a] = IMPLEMENTED, + [0x1b] = IMPLEMENTED | CHECK_READY, + [0x1e] = IMPLEMENTED | CHECK_READY, + [0x22] = IMPLEMENTED | CHECK_READY | SCSI_ONLY, + [0x25] = IMPLEMENTED | CHECK_READY, + [0x26] = IMPLEMENTED | CHECK_READY | SCSI_ONLY, + [0x28] = IMPLEMENTED | CHECK_READY, + [0x2b] = IMPLEMENTED | CHECK_READY, + [0x2f] = IMPLEMENTED | CHECK_READY | SCSI_ONLY, + [0x42] = IMPLEMENTED | CHECK_READY, + /* + Read TOC/PMA/ATIP - can get through UNIT_ATTENTION, per VIDE-CDD.SYS. + + NOTE: The ATAPI reference says otherwise, but I think this is a question of + interpreting things right - the UNIT ATTENTION condition we have here + is a tradition from not ready to ready, by definition the drive + eventually becomes ready, make the condition go away. + */ + [0x43 ... 0x45] = IMPLEMENTED | CHECK_READY, + [0x46] IMPLEMENTED | ALLOW_UA, + [0x47 ... 0x49] = IMPLEMENTED | CHECK_READY, + [0x4a] = IMPLEMENTED | ALLOW_UA, + [0x4b] = IMPLEMENTED | CHECK_READY, + [0x4e] = IMPLEMENTED | CHECK_READY, + [0x51 ... 0x52] = IMPLEMENTED | CHECK_READY, + [0x55] = IMPLEMENTED, + [0x5a] = IMPLEMENTED, + [0xa5] = IMPLEMENTED | CHECK_READY, + [0xa8 ... 0xa9] = IMPLEMENTED | CHECK_READY, + [0xad] = IMPLEMENTED, + [0xaf] = IMPLEMENTED | CHECK_READY | SCSI_ONLY, + [0xb4] = IMPLEMENTED | CHECK_READY | ATAPI_ONLY, + [0xb8] = IMPLEMENTED | CHECK_READY | ATAPI_ONLY, + [0xb9 ... 0xba] = IMPLEMENTED | CHECK_READY, + [0xbb] = IMPLEMENTED, + [0xbc] = IMPLEMENTED | CHECK_READY, + [0xbd] = IMPLEMENTED, + [0xbe ... 0xbf] = IMPLEMENTED | CHECK_READY, + [0xc0 ... 0xcd] = IMPLEMENTED | CHECK_READY | SCSI_ONLY, + [0xd8 ... 0xde] = IMPLEMENTED | CHECK_READY | SCSI_ONLY, + [0xe0 ... 0xe1] = IMPLEMENTED | CHECK_READY | SCSI_ONLY, + [0xe3 ... 0xe9] = IMPLEMENTED | CHECK_READY | SCSI_ONLY, + [0xeb] = IMPLEMENTED | CHECK_READY | SCSI_ONLY, + [0xed ... 0xee] = IMPLEMENTED | CHECK_READY | SCSI_ONLY }; -static uint64_t scsi_cdrom_mode_sense_page_flags = (GPMODEP_UNIT_ATN_PAGE | GPMODEP_R_W_ERROR_PAGE | GPMODEP_DISCONNECT_PAGE | GPMODEP_FORMAT_DEVICE_PAGE | GPMODEP_CDROM_PAGE | GPMODEP_CDROM_AUDIO_PAGE | (1ULL << 0x0fULL) | GPMODEP_CAPABILITIES_PAGE | GPMODEP_ALL_PAGES); -static uint64_t scsi_cdrom_mode_sense_page_flags_sony = (GPMODEP_R_W_ERROR_PAGE | GPMODEP_DISCONNECT_PAGE | GPMODEP_CDROM_PAGE_SONY | GPMODEP_CDROM_AUDIO_PAGE_SONY | (1ULL << 0x0fULL) | GPMODEP_CAPABILITIES_PAGE | GPMODEP_ALL_PAGES); -static uint64_t scsi_cdrom_drive_status_page_flags = ((1ULL << 0x01ULL) | (1ULL << 0x02ULL) | (1ULL << 0x0fULL) | GPMODEP_ALL_PAGES); +static uint64_t scsi_cdrom_ms_page_flags = (GPMODEP_R_W_ERROR_PAGE | GPMODEP_CDROM_PAGE | + GPMODEP_CDROM_AUDIO_PAGE | (1ULL << 0x0fULL) | + GPMODEP_CAPABILITIES_PAGE | GPMODEP_ALL_PAGES); +static uint64_t scsi_cdrom_ms_page_flags_scsi = (GPMODEP_UNIT_ATN_PAGE | GPMODEP_R_W_ERROR_PAGE | + GPMODEP_DISCONNECT_PAGE | GPMODEP_FORMAT_DEVICE_PAGE | + GPMODEP_CDROM_PAGE | GPMODEP_CDROM_AUDIO_PAGE | + (1ULL << 0x0fULL) | GPMODEP_CAPABILITIES_PAGE | + GPMODEP_ALL_PAGES); +static uint64_t scsi_cdrom_ms_page_flags_sony_scsi = (GPMODEP_R_W_ERROR_PAGE | GPMODEP_DISCONNECT_PAGE | + GPMODEP_CDROM_PAGE_SONY | GPMODEP_CDROM_AUDIO_PAGE_SONY | + (1ULL << 0x0fULL) | GPMODEP_CAPABILITIES_PAGE | + GPMODEP_ALL_PAGES); + +static uint64_t scsi_cdrom_drive_status_page_flags = ((1ULL << 0x01ULL) | (1ULL << 0x02ULL) | + (1ULL << 0x0fULL) | GPMODEP_ALL_PAGES); static const mode_sense_pages_t scsi_cdrom_drive_status_pages = { - {{ 0, 0 }, - { 0x01, 0, 2, 0x0f, 0xbf }, /*Drive Status Data Format*/ - { 0x02, 0, 1, 0 }, /*Audio Play Status Format*/ - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }} + { [0x01] = { 0x01, 0x00, 0x02, 0x0f, 0xbf }, /* Drive Status Data Format */ + [0x02] = { 0x02, 0x00, 0x01, 0x00 } } /* Audio Play Status Format */ }; -static const mode_sense_pages_t scsi_cdrom_mode_sense_pages_default = { - {{ 0, 0 }, - { GPMODE_R_W_ERROR_PAGE, 6, 0, 5, 0, 0, 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { GPMODE_CDROM_PAGE, 6, 0, 1, 0, 60, 0, 75 }, - { GPMODE_CDROM_AUDIO_PAGE | 0x80, 0xE, 4, 0, 0, 0, 0, 75, 1, 255, 2, 255, 0, 0, 0, 0 }, - { 0x0F, 0x14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { GPMODE_CAPABILITIES_PAGE, 0x12, 7, 0, 0x3f, 1, 0x0d, 3, 2, 0xC2, 1, 0, 0, 0, 2, 0xC2, 0, 0, 0, 0 }} +static const mode_sense_pages_t scsi_cdrom_ms_pages_default = { + { [0x01] = { GPMODE_R_W_ERROR_PAGE, 0x06, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00 }, + [0x0d] = { GPMODE_CDROM_PAGE, 0x06, 0x00, 0x01, 0x00, 0x3c, 0x00, 0x4b }, + [0x0e] = { GPMODE_CDROM_AUDIO_PAGE | 0x80, 0x0e, 0x04, 0x00, 0x00, 0x00, 0x00, 0x4b, + 0x01, 0xff, 0x02, 0xff, 0x00, 0x00, 0x00, 0x00 }, + [0x0f] = { 0x0f, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, + [0x2a] = { GPMODE_CAPABILITIES_PAGE, 0x12, 0x07, 0x00, 0x7f, 0x01, 0x0d, 0x03, + 0x02, 0xc2, 0x01, 0x00, 0x00, 0x00, 0x02, 0xc2, + 0x00, 0x00, 0x00, 0x00 } } }; -static const mode_sense_pages_t scsi_cdrom_mode_sense_pages_default_scsi = { - {{ GPMODE_UNIT_ATN_PAGE, 6, 0, 0, 0, 0, 0, 0 }, /*Guess-work*/ - { GPMODE_R_W_ERROR_PAGE, 6, 0, 5, 0, 0, 0, 0 }, - { GPMODE_DISCONNECT_PAGE, 0x0e, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, - { GPMODE_FORMAT_DEVICE_PAGE, 0x16, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { GPMODE_CDROM_PAGE, 6, 0, 1, 0, 60, 0, 75 }, - { GPMODE_CDROM_AUDIO_PAGE | 0x80, 0xE, 5, 4, 0, 128, 0, 75, 1, 255, 2, 255, 0, 0, 0, 0 }, - { 0x0F, 0x14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { GPMODE_CAPABILITIES_PAGE, 0x12, 7, 0, 0x3f, 1, 0x0d, 3, 2, 0xC2, 1, 0, 0, 0, 2, 0xC2, 0, 0, 0, 0 }} +static const mode_sense_pages_t scsi_cdrom_ms_pages_default_scsi = { + { [0x00] = { GPMODE_UNIT_ATN_PAGE, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, /* Guesswork */ + [0x01] = { GPMODE_R_W_ERROR_PAGE, 0x06, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00 }, + [0x02] = { GPMODE_DISCONNECT_PAGE, 0x0e, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, + [0x03] = { GPMODE_FORMAT_DEVICE_PAGE, 0x16, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, + 0x00, 0x01, 0x01, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, + [0x0d] = { GPMODE_CDROM_PAGE, 0x06, 0x00, 0x01, 0x00, 0x3c, 0x00, 0x4b }, + [0x0e] = { GPMODE_CDROM_AUDIO_PAGE | 0x80, 0x0e, 0x05, 0x04, 0x00, 0x80, 0x00, 0x4b, + 0x01, 0xff, 0x02, 0xff, 0x00, 0x00, 0x00, 0x00 }, + [0x0f] = { 0x0f, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, + [0x2a] = { GPMODE_CAPABILITIES_PAGE, 0x12, 0x07, 0x00, 0x7f, 0x01, 0x0d, 0x03, + 0x02, 0xc2, 0x01, 0x00, 0x00, 0x00, 0x02, 0xc2, + 0x00, 0x00, 0x00, 0x00 } } }; -static const mode_sense_pages_t scsi_cdrom_mode_sense_pages_default_sony_scsi = { - {{ 0, 0 }, - { GPMODE_R_W_ERROR_PAGE, 6, 0, 5, 0, 0, 0, 0 }, - { GPMODE_DISCONNECT_PAGE, 0x0e, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { GPMODE_CDROM_PAGE_SONY, 2, 0, 5 }, - { GPMODE_CDROM_AUDIO_PAGE_SONY | 0x80, 0xE, 5, 0, 0, 0, 0, 0, 1, 255, 2, 255, 0, 0, 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { GPMODE_CDROM_PAGE, 6, 0, 1, 0, 60, 0, 75 }, - { GPMODE_CDROM_AUDIO_PAGE | 0x80, 0xE, 5, 4, 0, 128, 0, 75, 1, 255, 2, 255, 0, 0, 0, 0 }, - { 0x0F, 0x14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { GPMODE_CAPABILITIES_PAGE, 0x12, 7, 0, 0x3f, 1, 0x0d, 3, 2, 0xC2, 1, 0, 0, 0, 2, 0xC2, 0, 0, 0, 0 }} +static const mode_sense_pages_t scsi_cdrom_ms_pages_default_sony_scsi = { + { { 0, 0 }, + [0x01] = { GPMODE_R_W_ERROR_PAGE, 0x06, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00 }, + [0x02] = { GPMODE_DISCONNECT_PAGE, 0x0e, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, + [0x08] = { GPMODE_CDROM_PAGE_SONY, 0x02, 0x00, 0x05 }, + [0x09] = { GPMODE_CDROM_AUDIO_PAGE_SONY | 0x80, 0x0e, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0xff, 0x02, 0xff, 0x00, 0x00, 0x00, 0x00 }, + [0x0d] = { GPMODE_CDROM_PAGE, 0x06, 0x00, 0x01, 0x00, 0x3c, 0x00, 0x4b }, + [0x0e] = { GPMODE_CDROM_AUDIO_PAGE | 0x80, 0x0e, 0x05, 0x04, 0x00, 0x80, 0x00, 0x4b, + 0x01, 0xff, 0x02, 0xff, 0x00, 0x00, 0x00, 0x00 }, + [0x0f] = { 0x0f, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, + [0x2a] = { GPMODE_CAPABILITIES_PAGE, 0x12, 0x07, 0x00, 0x7f, 0x01, 0x0d, 0x03, + 0x02, 0xc2, 0x01, 0x00, 0x00, 0x00, 0x02, 0xc2, + 0x00, 0x00, 0x00, 0x00 } } }; -static const mode_sense_pages_t scsi_cdrom_mode_sense_pages_changeable = { - {{ GPMODE_UNIT_ATN_PAGE, 6, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }, /*Guess-work*/ - { GPMODE_R_W_ERROR_PAGE, 6, 0xFF, 0xFF, 0, 0, 0, 0 }, - { GPMODE_DISCONNECT_PAGE, 0x0E, 0xFF, 0, 0, 0, 0, 0, 0, 0, 0xFF, 0xFF, 0, 0, 0, 0 }, - { GPMODE_FORMAT_DEVICE_PAGE, 0x16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { GPMODE_CDROM_PAGE, 6, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }, - { GPMODE_CDROM_AUDIO_PAGE | 0x80, 0xE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }, - { 0x0F, 0x14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { GPMODE_CAPABILITIES_PAGE, 0x12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }} +static const mode_sense_pages_t scsi_cdrom_ms_pages_changeable = { + { [0x01] = { GPMODE_R_W_ERROR_PAGE, 0x06, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 }, + [0x02] = { GPMODE_DISCONNECT_PAGE, 0x0e, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 }, + [0x0d] = { GPMODE_CDROM_PAGE, 0x06, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }, + [0x0e] = { GPMODE_CDROM_AUDIO_PAGE | 0x80, 0x0e, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }, + [0x0f] = { 0x0f, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, + [0x2a] = { GPMODE_CAPABILITIES_PAGE, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00 } } }; -static const mode_sense_pages_t scsi_cdrom_mode_sense_pages_changeable_sony = { - {{ 0, 0 }, - { GPMODE_R_W_ERROR_PAGE, 6, 0xFF, 0xFF, 0, 0, 0, 0 }, - { GPMODE_DISCONNECT_PAGE, 0x0E, 0xFF, 0, 0, 0, 0, 0, 0, 0, 0xFF, 0xFF, 0, 0, 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { GPMODE_CDROM_PAGE_SONY, 2, 0xFF, 0xFF }, - { GPMODE_CDROM_AUDIO_PAGE_SONY | 0x80, 0xE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { GPMODE_CDROM_PAGE, 6, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }, - { GPMODE_CDROM_AUDIO_PAGE | 0x80, 0xE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }, - { 0x0F, 0x14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { GPMODE_CAPABILITIES_PAGE, 0x12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }} +static const mode_sense_pages_t scsi_cdrom_ms_pages_changeable_scsi = { + { [0x00] = { GPMODE_UNIT_ATN_PAGE, 0x06, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }, /* Guesswork */ + [0x01] = { GPMODE_R_W_ERROR_PAGE, 0x06, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 }, + [0x02] = { GPMODE_DISCONNECT_PAGE, 0x0e, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 }, + [0x03] = { GPMODE_FORMAT_DEVICE_PAGE, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, + [0x0d] = { GPMODE_CDROM_PAGE, 0x06, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }, + [0x0e] = { GPMODE_CDROM_AUDIO_PAGE | 0x80, 0x0e, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }, + [0x0f] = { 0x0f, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, + [0x2a] = { GPMODE_CAPABILITIES_PAGE, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00 } } }; +static const mode_sense_pages_t scsi_cdrom_ms_pages_changeable_sony_scsi = { + { [0x01] = { GPMODE_R_W_ERROR_PAGE, 0x06, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 }, + [0x02] = { GPMODE_DISCONNECT_PAGE, 0x0e, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 }, + [0x08] = { GPMODE_CDROM_PAGE_SONY, 0x02, 0xff, 0xff }, + [0x09] = { GPMODE_CDROM_AUDIO_PAGE_SONY | 0x80, 0x0e, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }, + [0x0d] = { GPMODE_CDROM_PAGE, 0x06, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }, + [0x0e] = { GPMODE_CDROM_AUDIO_PAGE | 0x80, 0x0e, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }, + [0x0f] = { 0x0f, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, + [0x2a] = { GPMODE_CAPABILITIES_PAGE, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00 } } +}; +// clang-format on + static gesn_cdb_t *gesn_cdb; static gesn_event_header_t *gesn_event_header; @@ -480,22 +256,21 @@ static void scsi_cdrom_init(scsi_cdrom_t *dev); int scsi_cdrom_do_log = ENABLE_SCSI_CDROM_LOG; static void -scsi_cdrom_log(const char *format, ...) +scsi_cdrom_log(void *priv, const char *format, ...) { - va_list ap; - if (scsi_cdrom_do_log) { + va_list ap; va_start(ap, format); - pclog_ex(format, ap); + log_out(priv, format, ap); va_end(ap); } } #else -# define scsi_cdrom_log(format, ...) +# define scsi_cdrom_log(priv, format, ...) #endif static void -scsi_cdrom_set_callback(scsi_cdrom_t *dev) +scsi_cdrom_set_callback(const scsi_cdrom_t *dev) { if (dev && dev->drv && (dev->drv->bus_type != CDROM_BUS_SCSI)) ide_set_callback(ide_drives[dev->drv->ide_channel], dev->callback); @@ -504,47 +279,51 @@ scsi_cdrom_set_callback(scsi_cdrom_t *dev) static void scsi_cdrom_init(scsi_cdrom_t *dev) { - if (!dev) - return; + if (dev != NULL) { + /* Do a reset (which will also rezero it). */ + scsi_cdrom_reset((scsi_common_t *) dev); - /* Do a reset (which will also rezero it). */ - scsi_cdrom_reset((scsi_common_t *) dev); + /* Configure the drive. */ + dev->requested_blocks = 1; - /* Configure the drive. */ - dev->requested_blocks = 1; + dev->drv->bus_mode = 0; + if (dev->drv->bus_type >= CDROM_BUS_ATAPI) + dev->drv->bus_mode |= 2; + if (dev->drv->bus_type < CDROM_BUS_SCSI) + dev->drv->bus_mode |= 1; + scsi_cdrom_log(dev->log, "Bus type %i, bus mode %i\n", + dev->drv->bus_type, dev->drv->bus_mode); - dev->drv->bus_mode = 0; - if (dev->drv->bus_type >= CDROM_BUS_ATAPI) - dev->drv->bus_mode |= 2; - if (dev->drv->bus_type < CDROM_BUS_SCSI) - dev->drv->bus_mode |= 1; - scsi_cdrom_log("CD-ROM %i: Bus type %i, bus mode %i\n", - dev->id, dev->drv->bus_type, dev->drv->bus_mode); + dev->sense[0] = 0xf0; + dev->sense[7] = 10; + /* NEC only */ + if (dev->drv->is_early) + dev->tf->status = READY_STAT | DSC_STAT; + else + dev->tf->status = 0; + dev->tf->pos = 0; + dev->packet_status = PHASE_NONE; + scsi_cdrom_sense_key = scsi_cdrom_asc = scsi_cdrom_ascq = dev->unit_attention = 0; + scsi_cdrom_info = 0x00000000; + dev->drv->cd_status &= ~CD_STATUS_TRANSITION; + dev->drv->cur_speed = dev->drv->real_speed; + scsi_cdrom_mode_sense_load(dev); - dev->sense[0] = 0xf0; - dev->sense[7] = 10; - /* NEC only */ - if ((dev->drv->type == CDROM_TYPE_NEC_260_100) || (dev->drv->type == CDROM_TYPE_NEC_260_101)) - dev->tf->status = READY_STAT | DSC_STAT; - else - dev->tf->status = 0; - dev->tf->pos = 0; - dev->packet_status = PHASE_NONE; - scsi_cdrom_sense_key = scsi_cdrom_asc = scsi_cdrom_ascq = dev->unit_attention = 0; - dev->drv->cur_speed = dev->drv->speed; - scsi_cdrom_mode_sense_load(dev); - if (dev->drv->type == CDROM_TYPE_PIONEER_DRM604X_2403) - scsi_cdrom_drive_status_load(dev); + const char *vendor = cdrom_get_vendor(dev->drv->type); + + if ((dev->drv->bus_type == CDROM_BUS_SCSI) && !strcmp(vendor, "PIONEER")) + scsi_cdrom_drive_status_load(dev); + } } /* Returns: 0 for none, 1 for PIO, 2 for DMA. */ static int -scsi_cdrom_current_mode(scsi_cdrom_t *dev) +scsi_cdrom_current_mode(const scsi_cdrom_t *dev) { if (dev->drv->bus_type == CDROM_BUS_SCSI) return 2; else if (dev->drv->bus_type == CDROM_BUS_ATAPI) { - scsi_cdrom_log("CD-ROM %i: ATAPI drive, setting to %s\n", dev->id, + scsi_cdrom_log(dev->log, "ATAPI drive, setting to %s\n", (dev->tf->features & 1) ? "DMA" : "PIO", dev->id); return (dev->tf->features & 1) ? 2 : 1; @@ -554,50 +333,25 @@ scsi_cdrom_current_mode(scsi_cdrom_t *dev) } static uint32_t -scsi_cdrom_get_channel(void *priv, int channel) +scsi_cdrom_get_channel(void *priv, const int channel) { const scsi_cdrom_t *dev = (scsi_cdrom_t *) priv; - uint32_t ret; + uint32_t ret = channel + 1; - if (!dev) - return channel + 1; - - switch (dev->drv->type) { - case CDROM_TYPE_DEC_RRD45_0436: - case CDROM_TYPE_ShinaKen_DM3x1S_104 ... CDROM_TYPE_SONY_CDU76S_100: - case CDROM_TYPE_TEXEL_DM3024_100 ... CDROM_TYPE_TEXEL_DM3028_106: - ret = dev->ms_pages_saved_sony.pages[dev->sony_vendor ? - GPMODE_CDROM_AUDIO_PAGE_SONY : GPMODE_CDROM_AUDIO_PAGE] - [channel ? 10 : 8]; - break; - default: - ret = dev->ms_pages_saved.pages[GPMODE_CDROM_AUDIO_PAGE][channel ? 10 : 8]; - break; - } + if (dev != NULL) + ret = dev->ms_pages_saved.pages[GPMODE_CDROM_AUDIO_PAGE][channel ? 10 : 8]; return ret; } static uint32_t -scsi_cdrom_get_volume(void *priv, int channel) +scsi_cdrom_get_volume(void *priv, const int channel) { const scsi_cdrom_t *dev = (scsi_cdrom_t *) priv; - uint32_t ret; + uint32_t ret = 255; - if (!dev) - return 255; - - switch (dev->drv->type) { - case CDROM_TYPE_DEC_RRD45_0436: - case CDROM_TYPE_ShinaKen_DM3x1S_104 ... CDROM_TYPE_SONY_CDU76S_100: - case CDROM_TYPE_TEXEL_DM3024_100 ... CDROM_TYPE_TEXEL_DM3028_106: - ret = dev->ms_pages_saved_sony.pages[dev->sony_vendor ? GPMODE_CDROM_AUDIO_PAGE_SONY : - GPMODE_CDROM_AUDIO_PAGE][channel ? 11 : 9]; - break; - default: - ret = dev->ms_pages_saved.pages[GPMODE_CDROM_AUDIO_PAGE][channel ? 11 : 9]; - break; - } + if (dev != NULL) + ret = dev->ms_pages_saved.pages[GPMODE_CDROM_AUDIO_PAGE][channel ? 11 : 9]; return ret; } @@ -605,129 +359,90 @@ scsi_cdrom_get_volume(void *priv, int channel) static void scsi_cdrom_mode_sense_load(scsi_cdrom_t *dev) { - FILE *fp; - char file_name[512]; + char file_name[512] = { 0 }; - switch (dev->drv->type) { - case CDROM_TYPE_DEC_RRD45_0436: - case CDROM_TYPE_ShinaKen_DM3x1S_104 ... CDROM_TYPE_SONY_CDU76S_100: - case CDROM_TYPE_TEXEL_DM3024_100 ... CDROM_TYPE_TEXEL_DM3028_106: - memset(&dev->ms_pages_saved_sony, 0, sizeof(mode_sense_pages_t)); - memcpy(&dev->ms_pages_saved_sony, &scsi_cdrom_mode_sense_pages_default_sony_scsi, - sizeof(mode_sense_pages_t)); + memset(&dev->ms_pages_saved, 0x00, sizeof(mode_sense_pages_t)); + memcpy(&dev->ms_pages_saved, &dev->ms_pages_default, + sizeof(mode_sense_pages_t)); - memset(file_name, 0, 512); - sprintf(file_name, "scsi_cdrom_%02i_mode_sense_sony_bin", dev->id); - fp = plat_fopen(nvr_path(file_name), "rb"); - if (fp) { - if (fread(dev->ms_pages_saved_sony.pages[GPMODE_CDROM_AUDIO_PAGE_SONY], 1, - 0x10, fp) != 0x10) - fatal("scsi_cdrom_mode_sense_load(): Error reading data\n"); - fclose(fp); - } - break; - default: - memset(&dev->ms_pages_saved, 0, sizeof(mode_sense_pages_t)); - if (dev->drv->bus_type == CDROM_BUS_SCSI) - memcpy(&dev->ms_pages_saved, &scsi_cdrom_mode_sense_pages_default_scsi, - sizeof(mode_sense_pages_t)); - else - memcpy(&dev->ms_pages_saved, &scsi_cdrom_mode_sense_pages_default, - sizeof(mode_sense_pages_t)); - - memset(file_name, 0, 512); - if (dev->drv->bus_type == CDROM_BUS_SCSI) - sprintf(file_name, "scsi_cdrom_%02i_mode_sense_bin", dev->id); - else - sprintf(file_name, "cdrom_%02i_mode_sense_bin", dev->id); - fp = plat_fopen(nvr_path(file_name), "rb"); - if (fp) { - if (fread(dev->ms_pages_saved.pages[GPMODE_CDROM_AUDIO_PAGE], 1, 0x10, fp) != 0x10) - fatal("scsi_cdrom_mode_sense_load(): Error reading data\n"); - fclose(fp); - } - break; + if (dev->drv->bus_type == CDROM_BUS_SCSI) + sprintf(file_name, "scsi_cdrom_%02i_mode_sense_bin", dev->id); + else + sprintf(file_name, "cdrom_%02i_mode_sense_bin", dev->id); + FILE *fp = plat_fopen(nvr_path(file_name), "rb"); + if (fp) { + if (fread(dev->ms_pages_saved.pages[GPMODE_CDROM_AUDIO_PAGE], 1, 0x10, fp) != 0x10) + log_fatal(dev->log, "scsi_cdrom_mode_sense_load(): Error reading data\n"); + (void) fread(dev->ms_pages_saved.pages[GPMODE_CDROM_AUDIO_PAGE_SONY], 1, + 0x10, fp); + fclose(fp); } } static void -scsi_cdrom_mode_sense_save(scsi_cdrom_t *dev) +scsi_cdrom_mode_sense_save(const scsi_cdrom_t *dev) { - FILE *fp; - char file_name[512]; + char file_name[512] = { 0 }; - memset(file_name, 0, 512); - - switch (dev->drv->type) { - case CDROM_TYPE_DEC_RRD45_0436: - case CDROM_TYPE_ShinaKen_DM3x1S_104 ... CDROM_TYPE_SONY_CDU76S_100: - case CDROM_TYPE_TEXEL_DM3024_100 ... CDROM_TYPE_TEXEL_DM3028_106: - sprintf(file_name, "scsi_cdrom_%02i_mode_sense_sony_bin", dev->id); - fp = plat_fopen(nvr_path(file_name), "wb"); - if (fp) { - fwrite(dev->ms_pages_saved_sony.pages[GPMODE_CDROM_AUDIO_PAGE_SONY], 1, 0x10, fp); - fclose(fp); - } - break; - default: - if (dev->drv->bus_type == CDROM_BUS_SCSI) - sprintf(file_name, "scsi_cdrom_%02i_mode_sense_bin", dev->id); - else - sprintf(file_name, "cdrom_%02i_mode_sense_bin", dev->id); - fp = plat_fopen(nvr_path(file_name), "wb"); - if (fp) { - fwrite(dev->ms_pages_saved.pages[GPMODE_CDROM_AUDIO_PAGE], 1, 0x10, fp); - fclose(fp); - } - break; + if (dev->drv->bus_type == CDROM_BUS_SCSI) + sprintf(file_name, "scsi_cdrom_%02i_mode_sense_bin", dev->id); + else + sprintf(file_name, "cdrom_%02i_mode_sense_bin", dev->id); + FILE *fp = plat_fopen(nvr_path(file_name), "wb"); + if (fp) { + fwrite(dev->ms_pages_saved.pages[GPMODE_CDROM_AUDIO_PAGE], 1, 0x10, fp); + fwrite(dev->ms_pages_saved.pages[GPMODE_CDROM_AUDIO_PAGE_SONY], 1, 0x10, fp); + fclose(fp); } } -/*SCSI Drive Status (Pioneer only)*/ +/* SCSI Drive Status (Pioneer only). */ static void scsi_cdrom_drive_status_load(scsi_cdrom_t *dev) { - memset(&dev->ms_drive_status_pages_saved, 0, sizeof(mode_sense_pages_t)); - memcpy(&dev->ms_drive_status_pages_saved, &scsi_cdrom_drive_status_pages, sizeof(mode_sense_pages_t)); + memset(&dev->ms_drive_status_pages_saved, 0x00, sizeof(mode_sense_pages_t)); + memcpy(&dev->ms_drive_status_pages_saved, &scsi_cdrom_drive_status_pages, + sizeof(mode_sense_pages_t)); } static uint8_t -scsi_cdrom_drive_status_read(scsi_cdrom_t *dev, UNUSED(uint8_t page_control), uint8_t page, uint8_t pos) +scsi_cdrom_drive_status_read(const scsi_cdrom_t *dev, const uint8_t page, + const uint8_t pos) { return dev->ms_drive_status_pages_saved.pages[page][pos]; } static uint32_t -scsi_cdrom_drive_status(scsi_cdrom_t *dev, uint8_t *buf, uint32_t pos, uint8_t page) +scsi_cdrom_drive_status(const scsi_cdrom_t *dev, uint8_t *buf, uint8_t page) { - uint8_t page_control = (page >> 6) & 3; - uint16_t msplen; + uint32_t pos = 0; page &= 0x3f; for (uint8_t i = 0; i < 0x40; i++) { - if (page == i) { - if (scsi_cdrom_drive_status_page_flags & (1LL << ((uint64_t) (page & 0x3f)))) { - buf[pos++] = scsi_cdrom_drive_status_read(dev, page_control, i, 0); - msplen = (scsi_cdrom_drive_status_read(dev, page_control, i, 1) << 8); - msplen |= scsi_cdrom_drive_status_read(dev, page_control, i, 2); - buf[pos++] = (msplen >> 8) & 0xff; - buf[pos++] = msplen & 0xff; - scsi_cdrom_log("CD-ROM %i: DRIVE STATUS: Page [%02X] length %i\n", dev->id, i, msplen); - for (uint16_t j = 0; j < msplen; j++) { - if (i == 0x01) { - buf[pos++] = scsi_cdrom_drive_status_read(dev, page_control, i, 3 + j); - if (!(j & 1)) { /*MSB of Drive Status*/ - if (dev->drv->ops) /*Bit 11 of Drive Status, */ - buf[pos] &= ~0x08; /*Disc is present*/ - else - buf[pos] |= 0x08; /*Disc not present*/ - } - } else if ((i == 0x02) && (j == 0)) { - buf[pos++] = ((dev->drv->cd_status == CD_STATUS_PLAYING) ? 0x01 : 0x00); - } else - buf[pos++] = scsi_cdrom_drive_status_read(dev, page_control, i, 3 + j); - } + if ((page == i) && (scsi_cdrom_drive_status_page_flags & + (1LL << ((uint64_t) (page & 0x3f))))) { + buf[pos++] = scsi_cdrom_drive_status_read(dev, i, 0); + uint16_t len = (scsi_cdrom_drive_status_read(dev, i, 1) << 8); + len |= scsi_cdrom_drive_status_read(dev, i, 2); + buf[pos++] = (len >> 8) & 0xff; + buf[pos++] = len & 0xff; + scsi_cdrom_log(dev->log, "CD-ROM %i: DRIVE STATUS: Page [%02X] length %i\n", + i, len); + for (uint16_t j = 0; j < len; j++) { + if (i == 0x01) { + buf[pos++] = scsi_cdrom_drive_status_read(dev, i, 3 + j); + if (!(j & 1)) { /* MSB of Drive Status. */ + if (dev->drv->ops) /* Bit 11 of Drive Status, */ + buf[pos] &= ~0x08; /* Disc is present. */ + else + buf[pos] |= 0x08; /* Disc not present. */ + } + } else if ((i == 0x02) && (j == 0)) + buf[pos++] = ((dev->drv->cd_status == CD_STATUS_PLAYING) ? + 0x01 : 0x00); + else + buf[pos++] = scsi_cdrom_drive_status_read(dev, i, 3 + j); } } } @@ -737,52 +452,36 @@ scsi_cdrom_drive_status(scsi_cdrom_t *dev, uint8_t *buf, uint32_t pos, uint8_t p /*SCSI Mode Sense 6/10*/ static uint8_t -scsi_cdrom_mode_sense_read(scsi_cdrom_t *dev, uint8_t page_control, uint8_t page, uint8_t pos) +scsi_cdrom_mode_sense_read(const scsi_cdrom_t *dev, const uint8_t pgctl, + const uint8_t page, const uint8_t pos) { - switch (dev->drv->type) { - case CDROM_TYPE_DEC_RRD45_0436: - case CDROM_TYPE_ShinaKen_DM3x1S_104 ... CDROM_TYPE_SONY_CDU76S_100: - case CDROM_TYPE_TEXEL_DM3024_100 ... CDROM_TYPE_TEXEL_DM3028_106: - switch (page_control) { - case 0: - case 3: - return dev->ms_pages_saved_sony.pages[page][pos]; - case 1: - return scsi_cdrom_mode_sense_pages_changeable_sony.pages[page][pos]; - case 2: - return scsi_cdrom_mode_sense_pages_default_sony_scsi.pages[page][pos]; + uint8_t ret = 0; - default: - break; - } + switch (pgctl) { + case 0: case 3: + ret = dev->ms_pages_saved.pages[page][pos]; break; + + case 1: + ret = dev->ms_pages_changeable.pages[page][pos]; + break; + + case 2: + ret = dev->ms_pages_default.pages[page][pos]; + break; + default: - switch (page_control) { - case 0: - case 3: - return dev->ms_pages_saved.pages[page][pos]; - case 1: - return scsi_cdrom_mode_sense_pages_changeable.pages[page][pos]; - case 2: - if (dev->drv->bus_type == CDROM_BUS_SCSI) - return scsi_cdrom_mode_sense_pages_default_scsi.pages[page][pos]; - else - return scsi_cdrom_mode_sense_pages_default.pages[page][pos]; + break; + } - default: - break; - } - break; - } - - return 0; + return ret; } static uint32_t -scsi_cdrom_mode_sense(scsi_cdrom_t *dev, uint8_t *buf, uint32_t pos, uint8_t page, uint8_t block_descriptor_len) +scsi_cdrom_mode_sense(const scsi_cdrom_t *dev, uint8_t *buf, uint32_t pos, + uint8_t page, const uint8_t block_descriptor_len) { - uint8_t page_control = (page >> 6) & 3; - uint8_t msplen; + const uint8_t pgctl = (page >> 6) & 3; page &= 0x3f; @@ -799,45 +498,45 @@ scsi_cdrom_mode_sense(scsi_cdrom_t *dev, uint8_t *buf, uint32_t pos, uint8_t pag for (uint8_t i = 0; i < 0x40; i++) { if ((page == GPMODE_ALL_PAGES) || (page == i)) { - if (scsi_cdrom_mode_sense_page_flags & (1LL << ((uint64_t) (page & 0x3f)))) { - buf[pos++] = scsi_cdrom_mode_sense_read(dev, page_control, i, 0); - msplen = scsi_cdrom_mode_sense_read(dev, page_control, i, 1); - buf[pos++] = msplen; - scsi_cdrom_log("CD-ROM %i: MODE SENSE: Page [%02X] length %i\n", dev->id, i, msplen); + if (dev->ms_page_flags & (1LL << ((uint64_t) (page & 0x3f)))) { + const uint8_t msplen = scsi_cdrom_mode_sense_read(dev, pgctl, i, 1); + + buf[pos++] = scsi_cdrom_mode_sense_read(dev, pgctl, i, 0); + buf[pos++] = msplen; + + scsi_cdrom_log(dev->log, "MODE SENSE: Page [%02X] length %i\n", + i, msplen); + for (uint8_t j = 0; j < msplen; j++) { - /* If we are returning changeable values, always return them from the page, - so they are all correctly. */ - if (page_control == 1) - buf[pos++] = scsi_cdrom_mode_sense_read(dev, page_control, i, 2 + j); + /* + If we are returning changeable values, always return + them from the page, so they are all correct. + */ + if (pgctl == 1) + buf[pos++] = scsi_cdrom_mode_sense_read(dev, pgctl, i, 2 + j); else { if ((i == GPMODE_CAPABILITIES_PAGE) && (j == 4)) { - buf[pos] = scsi_cdrom_mode_sense_read(dev, page_control, i, 2 + j) & 0x1f; - /* The early CD-ROM drives we emulate (NEC CDR-260 for ATAPI and - early vendor SCSI CD-ROM models) are caddy drives, the later - ones are tray drives. */ - if (dev->drv->bus_type == CDROM_BUS_SCSI) - buf[pos++] |= ((dev->drv->type == CDROM_TYPE_86BOX_100) ? 0x20 : 0x00); - else - buf[pos++] |= ((dev->drv->type == CDROM_TYPE_NEC_260_100) || - ((dev->drv->type == CDROM_TYPE_NEC_260_101)) ? 0x00 : 0x20); - } else if ((i == GPMODE_CAPABILITIES_PAGE) && (j >= 6) && (j <= 7)) { + buf[pos] = scsi_cdrom_mode_sense_read(dev, pgctl, i, 2 + j) & 0x1f; + buf[pos++] |= (cdrom_is_caddy(dev->drv->type) ? 0x00 : 0x20); + } else if ((i == GPMODE_CAPABILITIES_PAGE) && (j >= 6) && + (j <= 7)) { if (j & 1) - buf[pos++] = ((dev->drv->speed * 176) & 0xff); + buf[pos++] = ((dev->drv->real_speed * 176) & 0xff); else - buf[pos++] = ((dev->drv->speed * 176) >> 8); - } else if ((i == GPMODE_CAPABILITIES_PAGE) && (j >= 8) && (j <= 9) && - (dev->drv->type == CDROM_TYPE_PIONEER_DRM604X_2403)) { - if (j & 1) - buf[pos++] = ((dev->drv->speed * 176) & 0xff); - else - buf[pos++] = ((dev->drv->speed * 176) >> 8); - } else if ((i == GPMODE_CAPABILITIES_PAGE) && (j >= 12) && (j <= 13)) { + buf[pos++] = ((dev->drv->real_speed * 176) >> 8); + } else if ((i == GPMODE_CAPABILITIES_PAGE) && (j >= 12) && + (j <= 13)) { if (j & 1) buf[pos++] = ((dev->drv->cur_speed * 176) & 0xff); else buf[pos++] = ((dev->drv->cur_speed * 176) >> 8); - } else - buf[pos++] = scsi_cdrom_mode_sense_read(dev, page_control, i, 2 + j); + } else if (dev->is_sony && (i == GPMODE_CDROM_AUDIO_PAGE_SONY) && + (j >= 6) && (j <= 13)) + buf[pos++] = scsi_cdrom_mode_sense_read(dev, pgctl, + GPMODE_CDROM_AUDIO_PAGE, 2 + j); + else + buf[pos++] = scsi_cdrom_mode_sense_read(dev, pgctl, + i, 2 + j); } } } @@ -848,15 +547,17 @@ scsi_cdrom_mode_sense(scsi_cdrom_t *dev, uint8_t *buf, uint32_t pos, uint8_t pag } static void -scsi_cdrom_update_request_length(scsi_cdrom_t *dev, int len, int block_len) +scsi_cdrom_update_request_length(scsi_cdrom_t *dev, int len, const int block_len) { - int32_t bt; int32_t min_len = 0; - double dlen; + int32_t bt; dev->max_transfer_len = dev->tf->request_length; - /* For media access commands, make sure the requested DRQ length matches the block length. */ + /* + For media access commands, make sure the requested DRQ length + matches the block length. + */ switch (dev->current_cdb[0]) { case 0x08: case 0x28: @@ -865,21 +566,26 @@ scsi_cdrom_update_request_length(scsi_cdrom_t *dev, int len, int block_len) case 0xbe: /* Round it to the nearest (block length) bytes. */ if ((dev->current_cdb[0] == 0xb9) || (dev->current_cdb[0] == 0xbe)) { - /* READ CD MSF and READ CD: Round the request length to the sector size - the device must ensure - that a media access comand does not DRQ in the middle of a sector. One of the drivers that - relies on the correctness of this behavior is MTMCDAI.SYS (the Mitsumi CD-ROM driver) for DOS - which uses the READ CD command to read data on some CD types. */ + /* + READ CD MSF and READ CD: Round the request length to the sector size - the + device must ensure that a media access comand does not DRQ in the middle + of a sector. One of the drivers that relies on the correctness of this + behavior is MTMCDAI.SYS (the Mitsumi CD-ROM driver) for DOS which uses + the READ CD command to read data on some CD types. + */ /* Round to sector length. */ - dlen = ((double) dev->max_transfer_len) / ((double) block_len); + const double dlen = ((double) dev->max_transfer_len) / ((double) block_len); dev->max_transfer_len = ((uint16_t) floor(dlen)) * block_len; } else { /* Round it to the nearest 2048 bytes. */ - dev->max_transfer_len = (dev->max_transfer_len >> 11) << 11; + dev->max_transfer_len = (dev->max_transfer_len / dev->drv->sector_size) * dev->drv->sector_size; } - /* Make sure total length is not bigger than sum of the lengths of - all the requested blocks. */ + /* + Make sure total length is not bigger than sum of the lengths of + all the requested blocks. + */ bt = (dev->requested_blocks * block_len); if (len > bt) len = bt; @@ -901,10 +607,16 @@ scsi_cdrom_update_request_length(scsi_cdrom_t *dev, int len, int block_len) dev->packet_len = len; break; } - /* If the DRQ length is odd, and the total remaining length is bigger, make sure it's even. */ + /* + If the DRQ length is odd, and the total remaining length is bigger, + make sure it's even. + */ if ((dev->max_transfer_len & 1) && (dev->max_transfer_len < len)) dev->max_transfer_len &= 0xfffe; - /* If the DRQ length is smaller or equal in size to the total remaining length, set it to that. */ + /* + If the DRQ length is smaller or equal in size to the total remaining length, + set it to that. + */ if (!dev->max_transfer_len) dev->max_transfer_len = 65534; @@ -939,8 +651,7 @@ scsi_cdrom_bus_speed(scsi_cdrom_t *dev) static void scsi_cdrom_command_common(scsi_cdrom_t *dev) { - double bytes_per_second = 0.0; - double period; + const uint8_t cmd = dev->current_cdb[0]; /* MAP: BUSY_STAT, no DRQ, phase 1. */ dev->tf->status = BUSY_STAT; @@ -948,37 +659,46 @@ scsi_cdrom_command_common(scsi_cdrom_t *dev) dev->tf->pos = 0; dev->callback = 0; - scsi_cdrom_log("CD-ROM %i: Current speed: %ix\n", dev->id, dev->drv->cur_speed); + scsi_cdrom_log(dev->log, "Current speed: %ix\n", dev->drv->cur_speed); if (dev->packet_status == PHASE_COMPLETE) dev->callback = 0; else { - switch (dev->current_cdb[0]) { + double bytes_per_second; + double period; + + switch (cmd) { case GPCMD_REZERO_UNIT: case 0x0b: case 0x2b: /* Seek time is in us. */ period = cdrom_seek_time(dev->drv); - scsi_cdrom_log("CD-ROM %i: Seek period: %" PRIu64 " us\n", - dev->id, (uint64_t) period); + scsi_cdrom_log(dev->log, "Seek period: %" PRIu64 " us\n", + (uint64_t) period); dev->callback += period; scsi_cdrom_set_callback(dev); return; + case 0x43: + dev->drv->seek_diff = dev->drv->seek_pos + 150; + dev->drv->seek_pos = 0; + fallthrough; case 0x08: case 0x28: + case 0x42: case 0x44: case 0xa8: /* Seek time is in us. */ period = cdrom_seek_time(dev->drv); - scsi_cdrom_log("CD-ROM %i: Seek period: %" PRIu64 " us\n", - dev->id, (uint64_t) period); - scsi_cdrom_log("CD-ROM %i: Seek period: %" PRIu64 " us, speed: %" PRIu64 " bytes per second, " - "should be: %" PRIu64 " bytes per second\n", - dev->id, (uint64_t) period, (uint64_t) (1000000.0 / period), + scsi_cdrom_log(dev->log, "Seek period: %" PRIu64 " us\n", + (uint64_t) period); + scsi_cdrom_log(dev->log, "Seek period: %" PRIu64 " us, speed: %" + PRIu64 " bytes per second, should be: %" + PRIu64 " bytes per second\n", + (uint64_t) period, (uint64_t) (1000000.0 / period), (uint64_t) (176400.0 * (double) dev->drv->cur_speed)); dev->callback += period; fallthrough; case 0x25: - case 0x42 ... 0x44: + // case 0x42 ... 0x44: case 0x51 ... 0x52: case 0xad: case 0xb8 ... 0xb9: @@ -987,57 +707,25 @@ scsi_cdrom_command_common(scsi_cdrom_t *dev) dev->callback += 40.0; /* Account for seek time. */ /* 44100 * 16 bits * 2 channels = 176400 bytes per second */ + /* + TODO: This is a bit of a lie - the actual period is closer to + 75 * 2448 bytes per second, because the subchannel data + has to be read as well. + */ bytes_per_second = 176400.0; bytes_per_second *= (double) dev->drv->cur_speed; break; + case 0xc0 ... 0xc3: case 0xc6 ... 0xc7: - switch (dev->drv->type) { - case CDROM_TYPE_TOSHIBA_XM_3433 ... CDROM_TYPE_TOSHIBA_SDM1401_1008: - bytes_per_second = 176400.0; - bytes_per_second *= (double) dev->drv->cur_speed; - break; - } - case 0xc0: - switch (dev->drv->type) { - case CDROM_TYPE_DEC_RRD45_0436: - case CDROM_TYPE_ShinaKen_DM3x1S_104 ... CDROM_TYPE_SONY_CDU76S_100: - case CDROM_TYPE_TEXEL_DM3024_100 ... CDROM_TYPE_TEXEL_DM3028_106: - /* 44100 * 16 bits * 2 channels = 176400 bytes per second */ - bytes_per_second = 176400.0; - bytes_per_second *= (double) dev->drv->cur_speed; - break; - } - case 0xc1: - switch (dev->drv->type) { - case CDROM_TYPE_DEC_RRD45_0436: - case CDROM_TYPE_ShinaKen_DM3x1S_104 ... CDROM_TYPE_SONY_CDU76S_100: - case CDROM_TYPE_PIONEER_DRM604X_2403: - case CDROM_TYPE_TEXEL_DM3024_100 ... CDROM_TYPE_TEXEL_DM3028_106: - /* 44100 * 16 bits * 2 channels = 176400 bytes per second */ - bytes_per_second = 176400.0; - bytes_per_second *= (double) dev->drv->cur_speed; - break; - } - case 0xc2 ... 0xc3: - switch (dev->drv->type) { - case CDROM_TYPE_DEC_RRD45_0436: - case CDROM_TYPE_ShinaKen_DM3x1S_104 ... CDROM_TYPE_SONY_CDU76S_100: - case CDROM_TYPE_PIONEER_DRM604X_2403: - case CDROM_TYPE_TEXEL_DM3024_100 ... CDROM_TYPE_TEXEL_DM3028_106: - if (dev->current_cdb[0] == 0xc2) - dev->callback += 40.0; - /* 44100 * 16 bits * 2 channels = 176400 bytes per second */ - bytes_per_second = 176400.0; - bytes_per_second *= (double) dev->drv->cur_speed; - break; - } case 0xdd ... 0xde: - switch (dev->drv->type) { - case CDROM_TYPE_NEC_25_10a ... CDROM_TYPE_NEC_464_105: - /* 44100 * 16 bits * 2 channels = 176400 bytes per second */ - bytes_per_second = 176400.0; - bytes_per_second *= (double) dev->drv->cur_speed; - break; + if (dev->ven_cmd_is_data[cmd]) { + if (dev->current_cdb[0] == 0xc2) + dev->callback += 40.0; + /* Account for seek time. */ + /* 44100 * 16 bits * 2 channels = 176400 bytes per second */ + bytes_per_second = 176400.0; + bytes_per_second *= (double) dev->drv->cur_speed; + break; } fallthrough; default: @@ -1050,9 +738,23 @@ scsi_cdrom_command_common(scsi_cdrom_t *dev) } period = 1000000.0 / bytes_per_second; - scsi_cdrom_log("CD-ROM %i: Byte transfer period: %" PRIu64 " us\n", dev->id, (uint64_t) period); - period = period * (double) (dev->packet_len); - scsi_cdrom_log("CD-ROM %i: Sector transfer period: %" PRIu64 " us\n", dev->id, (uint64_t) period); + scsi_cdrom_log(dev->log, "Byte transfer period: %" PRIu64 " us\n", + (uint64_t) period); + switch (cmd) { + default: + period = period * (double) (dev->packet_len); + break; + case 0x42: case 0x44: + /* READ SUBCHANNEL or READ HEADER - period of 1 entire sector. */ + period = period * 2352.0; + break; + case 0x43: + /* READ TOC - period of 175 entire frames. */ + period = period * 150.0 * 2352.0; + break; + } + scsi_cdrom_log(dev->log, "Sector transfer period: %" PRIu64 " us\n", + (uint64_t) period); dev->callback += period; } scsi_cdrom_set_callback(dev); @@ -1096,16 +798,18 @@ scsi_cdrom_command_write_dma(scsi_cdrom_t *dev) scsi_cdrom_command_common(dev); } -/* id = Current CD-ROM device ID; +/* + dev = Pointer to current CD-ROM device; len = Total transfer length; block_len = Length of a single block (it matters because media access commands on ATAPI); alloc_len = Allocated transfer length; - direction = Transfer direction (0 = read from host, 1 = write to host). */ + direction = Transfer direction (0 = read from host, 1 = write to host). + */ static void scsi_cdrom_data_command_finish(scsi_cdrom_t *dev, int len, int block_len, int alloc_len, int direction) { - scsi_cdrom_log("CD-ROM %i: Finishing command (%02X): %i, %i, %i, %i, %i\n", - dev->id, dev->current_cdb[0], len, block_len, alloc_len, direction, + scsi_cdrom_log(dev->log, "Finishing command (%02X): %i, %i, %i, %i, %i\n", + dev->current_cdb[0], len, block_len, alloc_len, direction, dev->tf->request_length); dev->tf->pos = 0; if (alloc_len >= 0) { @@ -1135,72 +839,74 @@ scsi_cdrom_data_command_finish(scsi_cdrom_t *dev, int len, int block_len, int al } } - scsi_cdrom_log("CD-ROM %i: Status: %i, cylinder %i, packet length: %i, position: %i, phase: %i\n", - dev->id, dev->packet_status, dev->tf->request_length, dev->packet_len, dev->tf->pos, - dev->tf->phase); + scsi_cdrom_log(dev->log, "Status: %i, cylinder %i, packet length: %i, position: %i, " + "phase: %i\n", dev->packet_status, dev->tf->request_length, dev->packet_len, + dev->tf->pos, dev->tf->phase); } static void scsi_cdrom_sense_clear(scsi_cdrom_t *dev, UNUSED(int command)) { scsi_cdrom_sense_key = scsi_cdrom_asc = scsi_cdrom_ascq = 0; + scsi_cdrom_info = 0x00000000; } static void -scsi_cdrom_set_phase(scsi_cdrom_t *dev, uint8_t phase) +scsi_cdrom_set_phase(const scsi_cdrom_t *dev, const uint8_t phase) { - uint8_t scsi_bus = (dev->drv->scsi_device_id >> 4) & 0x0f; - uint8_t scsi_id = dev->drv->scsi_device_id & 0x0f; + const uint8_t scsi_bus = (dev->drv->scsi_device_id >> 4) & 0x0f; + const uint8_t scsi_id = dev->drv->scsi_device_id & 0x0f; - if (dev->drv->bus_type != CDROM_BUS_SCSI) - return; - - scsi_devices[scsi_bus][scsi_id].phase = phase; + if (dev->drv->bus_type == CDROM_BUS_SCSI) + scsi_devices[scsi_bus][scsi_id].phase = phase; } static void scsi_cdrom_cmd_error(scsi_cdrom_t *dev) { scsi_cdrom_set_phase(dev, SCSI_PHASE_STATUS); - dev->tf->error = ((scsi_cdrom_sense_key & 0xf) << 4) | ABRT_ERR; - dev->tf->status = READY_STAT | ERR_STAT; - dev->tf->phase = 3; - dev->tf->pos = 0; - dev->packet_status = PHASE_ERROR; - dev->callback = 50.0 * CDROM_TIME; - scsi_cdrom_set_callback(dev); - ui_sb_update_icon(SB_CDROM | dev->id, 0); - scsi_cdrom_log("CD-ROM %i: ERROR: %02X/%02X/%02X\n", dev->id, scsi_cdrom_sense_key, scsi_cdrom_asc, scsi_cdrom_ascq); -} - -static void -scsi_cdrom_unit_attention(scsi_cdrom_t *dev) -{ - scsi_cdrom_set_phase(dev, SCSI_PHASE_STATUS); - dev->tf->error = (SENSE_UNIT_ATTENTION << 4) | ABRT_ERR; - dev->tf->status = READY_STAT | ERR_STAT; + dev->tf->error = ((scsi_cdrom_sense_key & 0xf) << 4) | ABRT_ERR; + dev->tf->status = READY_STAT | ERR_STAT; dev->tf->phase = 3; dev->tf->pos = 0; dev->packet_status = PHASE_ERROR; dev->callback = 50.0 * CDROM_TIME; scsi_cdrom_set_callback(dev); ui_sb_update_icon(SB_CDROM | dev->id, 0); - scsi_cdrom_log("CD-ROM %i: UNIT ATTENTION\n", dev->id); + scsi_cdrom_log(dev->log, "ERROR: %02X/%02X/%02X\n", scsi_cdrom_sense_key, + scsi_cdrom_asc, scsi_cdrom_ascq); } static void -scsi_cdrom_buf_alloc(scsi_cdrom_t *dev, uint32_t len) +scsi_cdrom_unit_attention(scsi_cdrom_t *dev) { - if (!dev->buffer) + scsi_cdrom_set_phase(dev, SCSI_PHASE_STATUS); + dev->tf->error = (SENSE_UNIT_ATTENTION << 4) | ABRT_ERR; + dev->tf->status = READY_STAT | ERR_STAT; + dev->tf->phase = 3; + dev->tf->pos = 0; + dev->packet_status = PHASE_ERROR; + dev->callback = 50.0 * CDROM_TIME; + scsi_cdrom_set_callback(dev); + ui_sb_update_icon(SB_CDROM | dev->id, 0); + scsi_cdrom_log(dev->log, "UNIT ATTENTION\n"); +} + +static void +scsi_cdrom_buf_alloc(scsi_cdrom_t *dev, const uint32_t len) +{ + if (dev->buffer == NULL) dev->buffer = (uint8_t *) malloc(len); - scsi_cdrom_log("CD-ROM %i: Allocated buffer length: %i, buffer = %p\n", dev->id, len, dev->buffer); + + scsi_cdrom_log(dev->log, "Allocated buffer length: %i, buffer = %p\n", + len, dev->buffer); } static void scsi_cdrom_buf_free(scsi_cdrom_t *dev) { if (dev->buffer) { - scsi_cdrom_log("CD-ROM %i: Freeing buffer...\n", dev->id); + scsi_cdrom_log(dev->log, "Freeing buffer...\n"); free(dev->buffer); dev->buffer = NULL; } @@ -1211,179 +917,221 @@ scsi_cdrom_bus_master_error(scsi_common_t *sc) { scsi_cdrom_t *dev = (scsi_cdrom_t *) sc; - scsi_cdrom_log("CD-ROM %i: Bus master error\n", dev->id); + scsi_cdrom_log(dev->log, "Bus master error\n"); scsi_cdrom_buf_free(dev); scsi_cdrom_sense_key = scsi_cdrom_asc = scsi_cdrom_ascq = 0; + scsi_cdrom_info = (dev->sector_pos >> 24) | + ((dev->sector_pos >> 16) << 8) | + ((dev->sector_pos >> 8) << 16) | + ( dev->sector_pos << 24); + scsi_cdrom_cmd_error(dev); +} + +static void +scsi_cdrom_error_common(scsi_cdrom_t *dev, uint8_t sense_key, uint8_t asc, uint8_t ascq, uint32_t info) +{ + scsi_cdrom_log(dev->log, "Medium not present\n"); + scsi_cdrom_sense_key = sense_key; + scsi_cdrom_asc = asc; + scsi_cdrom_ascq = ascq; + scsi_cdrom_info = info; scsi_cdrom_cmd_error(dev); } static void scsi_cdrom_not_ready(scsi_cdrom_t *dev) { - scsi_cdrom_log("CD-ROM %i: Medium not present\n", dev->id); + scsi_cdrom_log(dev->log, "Medium not present\n"); scsi_cdrom_sense_key = SENSE_NOT_READY; scsi_cdrom_asc = ASC_MEDIUM_NOT_PRESENT; scsi_cdrom_ascq = 0; + scsi_cdrom_info = 0x00000000; scsi_cdrom_cmd_error(dev); } static void scsi_cdrom_circ_error(scsi_cdrom_t *dev) { - scsi_cdrom_log("CD-ROM %i: CIRC unrecovered error\n", dev->id); + scsi_cdrom_log(dev->log, "CIRC unrecovered error\n"); scsi_cdrom_sense_key = SENSE_MEDIUM_ERROR; scsi_cdrom_asc = ASC_UNRECOVERED_READ_ERROR; scsi_cdrom_ascq = ASCQ_CIRC_UNRECOVERED_ERROR; + scsi_cdrom_info = (dev->sector_pos >> 24) | + ((dev->sector_pos >> 16) << 8) | + ((dev->sector_pos >> 8) << 16) | + ( dev->sector_pos << 24); scsi_cdrom_cmd_error(dev); } static void -scsi_cdrom_invalid_lun(scsi_cdrom_t *dev) +scsi_cdrom_invalid_lun(scsi_cdrom_t *dev, const uint8_t lun) { - scsi_cdrom_log("CD-ROM %i: Invalid LUN\n", dev->id); + scsi_cdrom_log(dev->log, "Invalid LUN\n"); scsi_cdrom_sense_key = SENSE_ILLEGAL_REQUEST; scsi_cdrom_asc = ASC_INV_LUN; scsi_cdrom_ascq = 0; + scsi_cdrom_info = lun << 24; scsi_cdrom_cmd_error(dev); } static void -scsi_cdrom_illegal_opcode(scsi_cdrom_t *dev) +scsi_cdrom_illegal_opcode(scsi_cdrom_t *dev, const uint8_t opcode) { - scsi_cdrom_log("CD-ROM %i: Illegal opcode\n", dev->id); + scsi_cdrom_log(dev->log, "Illegal opcode\n"); scsi_cdrom_sense_key = SENSE_ILLEGAL_REQUEST; scsi_cdrom_asc = ASC_ILLEGAL_OPCODE; scsi_cdrom_ascq = 0; + scsi_cdrom_info = opcode << 24; scsi_cdrom_cmd_error(dev); } static void scsi_cdrom_lba_out_of_range(scsi_cdrom_t *dev) { - scsi_cdrom_log("CD-ROM %i: LBA out of range\n", dev->id); + scsi_cdrom_log(dev->log, "LBA out of range\n"); scsi_cdrom_sense_key = SENSE_ILLEGAL_REQUEST; scsi_cdrom_asc = ASC_LBA_OUT_OF_RANGE; scsi_cdrom_ascq = 0; + scsi_cdrom_info = (dev->sector_pos >> 24) | + ((dev->sector_pos >> 16) << 8) | + ((dev->sector_pos >> 8) << 16) | + ( dev->sector_pos << 24); scsi_cdrom_cmd_error(dev); } static void -scsi_cdrom_invalid_field(scsi_cdrom_t *dev) +scsi_cdrom_invalid_field(scsi_cdrom_t *dev, const uint32_t field) { - scsi_cdrom_log("CD-ROM %i: Invalid field in command packet\n", dev->id); + scsi_cdrom_log(dev->log, "Invalid field in command packet\n"); scsi_cdrom_sense_key = SENSE_ILLEGAL_REQUEST; scsi_cdrom_asc = ASC_INV_FIELD_IN_CMD_PACKET; scsi_cdrom_ascq = 0; + scsi_cdrom_info = (field >> 24) | + ((field >> 16) << 8) | + ((field >> 8) << 16) | + ( field << 24); scsi_cdrom_cmd_error(dev); dev->tf->status = 0x53; } static void -scsi_cdrom_invalid_field_pl(scsi_cdrom_t *dev) +scsi_cdrom_invalid_field_pl(scsi_cdrom_t *dev, const uint32_t field) { - scsi_cdrom_log("CD-ROM %i: Invalid field in parameter list\n", dev->id); + scsi_cdrom_log(dev->log, "Invalid field in parameter list\n"); scsi_cdrom_sense_key = SENSE_ILLEGAL_REQUEST; scsi_cdrom_asc = ASC_INV_FIELD_IN_PARAMETER_LIST; scsi_cdrom_ascq = 0; + scsi_cdrom_info = (field >> 24) | + ((field >> 16) << 8) | + ((field >> 8) << 16) | + ( field << 24); scsi_cdrom_cmd_error(dev); dev->tf->status = 0x53; } +static void +scsi_cdrom_incompatible_format(scsi_cdrom_t *dev, const uint32_t val) +{ + scsi_cdrom_log(dev->log, "Incompatible format\n"); + scsi_cdrom_sense_key = SENSE_ILLEGAL_REQUEST; + scsi_cdrom_asc = ASC_INCOMPATIBLE_FORMAT; + scsi_cdrom_ascq = 2; + scsi_cdrom_info = (val >> 24) | + ((val >> 16) << 8) | + ((val >> 8) << 16) | + ( val << 24); + scsi_cdrom_cmd_error(dev); +} + +static void +scsi_cdrom_data_phase_error(scsi_cdrom_t *dev, const uint32_t info) +{ + scsi_cdrom_log(dev->log, "Data phase error\n"); + scsi_cdrom_sense_key = SENSE_ILLEGAL_REQUEST; + scsi_cdrom_asc = ASC_DATA_PHASE_ERROR; + scsi_cdrom_ascq = 0; + scsi_cdrom_info = (info >> 24) | + ((info >> 16) << 8) | + ((info >> 8) << 16) | + ( info << 24); + scsi_cdrom_cmd_error(dev); +} + static void scsi_cdrom_illegal_mode(scsi_cdrom_t *dev) { - scsi_cdrom_log("CD-ROM %i: Illegal mode for this track\n", dev->id); + scsi_cdrom_log(dev->log, "Illegal mode for this track\n"); scsi_cdrom_sense_key = SENSE_ILLEGAL_REQUEST; scsi_cdrom_asc = ASC_ILLEGAL_MODE_FOR_THIS_TRACK; scsi_cdrom_ascq = 0; - scsi_cdrom_cmd_error(dev); -} - -static void -scsi_cdrom_incompatible_format(scsi_cdrom_t *dev) -{ - scsi_cdrom_log("CD-ROM %i: Incompatible format\n", dev->id); - scsi_cdrom_sense_key = SENSE_ILLEGAL_REQUEST; - scsi_cdrom_asc = ASC_INCOMPATIBLE_FORMAT; - scsi_cdrom_ascq = 2; - scsi_cdrom_cmd_error(dev); -} - -static void -scsi_cdrom_data_phase_error(scsi_cdrom_t *dev) -{ - scsi_cdrom_log("CD-ROM %i: Data phase error\n", dev->id); - scsi_cdrom_sense_key = SENSE_ILLEGAL_REQUEST; - scsi_cdrom_asc = ASC_DATA_PHASE_ERROR; - scsi_cdrom_ascq = 0; + scsi_cdrom_info = (dev->sector_pos >> 24) | + ((dev->sector_pos >> 16) << 8) | + ((dev->sector_pos >> 8) << 16) | + ( dev->sector_pos << 24); scsi_cdrom_cmd_error(dev); } static int -scsi_cdrom_read_data(scsi_cdrom_t *dev, int msf, int type, int flags, int32_t *len, int vendor_type) +scsi_cdrom_read_data(scsi_cdrom_t *dev, const int msf, const int type, const int flags, + int32_t *len, const int vendor_type) { - int ret = 0; - int data_pos = 0; int temp_len = 0; - uint32_t cdsize = 0; + int ret = 0; - if (dev->drv->cd_status == CD_STATUS_EMPTY) { + if (dev->drv->cd_status == CD_STATUS_EMPTY) scsi_cdrom_not_ready(dev); - return 0; - } + else { + const uint32_t cdsize = dev->drv->cdrom_capacity; - cdsize = dev->drv->cdrom_capacity; + if (dev->sector_pos >= cdsize) { + scsi_cdrom_log(dev->log, "Trying to read from beyond the end of " + "disc (%i >= %i)\n", dev->sector_pos, cdsize); + scsi_cdrom_lba_out_of_range(dev); + ret = -1; + } else { + int data_pos = 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, - dev->sector_pos, cdsize); - scsi_cdrom_lba_out_of_range(dev); - return -1; - } + dev->old_len = 0; + *len = 0; -/* FIXME: Temporarily disabled this because the Triones ATAPI DMA driver seems to - always request a 4-sector read but sets the DMA bus master to transfer less - data than that. */ -#if 0 - if ((dev->sector_pos + dev->sector_len - 1) >= cdsize) { - scsi_cdrom_log("CD-ROM %i: Trying to read to beyond the end of disc (%i >= %i)\n", dev->id, - (dev->sector_pos + dev->sector_len - 1), cdsize); - scsi_cdrom_lba_out_of_range(dev); - return -1; - } -#endif + ret = 1; - dev->old_len = 0; - *len = 0; + for (int i = 0; i < dev->requested_blocks; i++) { + ret = cdrom_readsector_raw(dev->drv, dev->buffer + data_pos, + dev->sector_pos + i, msf, type, + flags, &temp_len, vendor_type); - for (int i = 0; i < dev->requested_blocks; i++) { - ret = cdrom_readsector_raw(dev->drv, dev->buffer + data_pos, - dev->sector_pos + i, msf, type, flags, &temp_len, vendor_type); + data_pos += temp_len; + dev->old_len += temp_len; - data_pos += temp_len; - dev->old_len += temp_len; + *len += temp_len; - *len += temp_len; + if (ret == 0) { + scsi_cdrom_illegal_mode(dev); + break; + } - if (!ret) { - scsi_cdrom_illegal_mode(dev); - return 0; - } else if (ret < 0) { - scsi_cdrom_circ_error(dev); - return -1; + if (ret < 0) { + scsi_cdrom_circ_error(dev); + break; + } + } } } - return 1; + return ret; } static int -scsi_cdrom_read_blocks(scsi_cdrom_t *dev, int32_t *len, int first_batch, int vendor_type) +scsi_cdrom_read_blocks(scsi_cdrom_t *dev, int32_t *len, const int vendor_type) { - int ret = 0; + int ret = 1; int msf = 0; - int type = 0; - int flags = 0; + int type = dev->sector_type; + int flags = dev->sector_flags; + + /* Any of these commands stop the audio playing. */ + cdrom_stop(dev->drv); switch (dev->current_cdb[0]) { case GPCMD_READ_CD_MSF_OLD: @@ -1395,152 +1143,40 @@ scsi_cdrom_read_blocks(scsi_cdrom_t *dev, int32_t *len, int first_batch, int ven type = (dev->current_cdb[1] >> 2) & 7; flags = dev->current_cdb[9] | (((uint32_t) dev->current_cdb[10]) << 8); break; + case GPCMD_READ_HEADER: + type = 0x00; + flags = 0x20; + break; default: - type = 8; /* Internal type code indicating both Mode 1 and Mode 2 Form 1 are allowed. */ - flags = (dev->drv->sector_size == 2340) ? 0x78 : 0x10; + if (dev->sector_type == 0xff) { + scsi_cdrom_illegal_mode(dev); + ret = 0; + } break; } - if (!dev->sector_len) { - scsi_cdrom_command_complete(dev); - return -1; + if (ret) { + if (!dev->sector_len) { + scsi_cdrom_command_complete(dev); + return -1; + } + + scsi_cdrom_log(dev->log, "Reading %i blocks starting from %i...\n", + dev->requested_blocks, dev->sector_pos); + + ret = scsi_cdrom_read_data(dev, msf, type, flags, len, vendor_type); + + scsi_cdrom_log(dev->log, "Read %i bytes of blocks (ret = %i)...\n", *len, ret); } - scsi_cdrom_log("Reading %i blocks starting from %i...\n", dev->requested_blocks, dev->sector_pos); + if ((ret > 0) && (dev->current_cdb[0] != GPCMD_READ_HEADER)) { + dev->sector_pos += dev->requested_blocks; + dev->drv->seek_pos = dev->sector_pos; - ret = scsi_cdrom_read_data(dev, msf, type, flags, len, vendor_type); - - scsi_cdrom_log("Read %i bytes of blocks...\n", *len); - - if (ret == -1) - return ret; - else if (!ret || (!first_batch && (dev->old_len != *len))) { - if (!first_batch && (dev->old_len != *len)) - scsi_cdrom_illegal_mode(dev); - - return 0; + dev->sector_len -= dev->requested_blocks; } - dev->sector_pos += dev->requested_blocks; - dev->drv->seek_pos = dev->sector_pos; - dev->sector_len -= dev->requested_blocks; - return 1; -} - -/*SCSI Read DVD Structure*/ -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 = 0; - - switch (format) { - case 0x00: /* Physical format information */ - if (dev->drv->cd_status == CD_STATUS_EMPTY) { - scsi_cdrom_not_ready(dev); - return 0; - } - - total_sectors = (uint64_t) dev->drv->cdrom_capacity; - - if (layer != 0) { - scsi_cdrom_invalid_field(dev); - return 0; - } - - total_sectors >>= 2; - if (total_sectors == 0) { - /* return -ASC_MEDIUM_NOT_PRESENT; */ - scsi_cdrom_not_ready(dev); - return 0; - } - - buf[4] = 18; /* Length of Layer Information */ - buf[5] = 0; - - buf[6] = 1; /* DVD-ROM, part version 1 */ - buf[7] = 0xf; /* 120mm disc, minimum rate unspecified */ - buf[8] = 1; /* one layer, read-only (per MMC-2 spec) */ - buf[9] = 0; /* default densities */ - - /* FIXME: 0x30000 per spec? */ - buf[10] = 0x00; - buf[11] = 0x03; - buf[12] = buf[13] = 0; /* start sector */ - - buf[14] = 0x00; - buf[15] = (total_sectors >> 16) & 0xff; /* end sector */ - buf[16] = (total_sectors >> 8) & 0xff; - buf[17] = total_sectors & 0xff; - - buf[18] = 0x00; - buf[19] = (total_sectors >> 16) & 0xff; /* l0 end sector */ - buf[20] = (total_sectors >> 8) & 0xff; - buf[21] = total_sectors & 0xff; - - /* 20 bytes of data + 4 byte header */ - return (20 + 4); - - case 0x01: /* DVD copyright information */ - buf[4] = 0; /* no copyright data */ - buf[5] = 0; /* no region restrictions */ - - /* Size of buffer, not including 2 byte size field */ - buf[0] = ((4 + 2) >> 8) & 0xff; - buf[1] = (4 + 2) & 0xff; - - /* 4 byte header + 4 byte data */ - return (4 + 4); - - case 0x03: /* BCA information - invalid field for no BCA info */ - scsi_cdrom_invalid_field(dev); - return 0; - - case 0x04: /* DVD disc manufacturing information */ - /* Size of buffer, not including 2 byte size field */ - buf[0] = ((2048 + 2) >> 8) & 0xff; - buf[1] = (2048 + 2) & 0xff; - - /* 2k data + 4 byte header */ - return (2048 + 4); - - case 0xff: - /* - * This lists all the command capabilities above. Add new ones - * in order and update the length and buffer return values. - */ - - buf[4] = 0x00; /* Physical format */ - buf[5] = 0x40; /* Not writable, is readable */ - buf[6] = ((20 + 4) >> 8) & 0xff; - buf[7] = (20 + 4) & 0xff; - - buf[8] = 0x01; /* Copyright info */ - buf[9] = 0x40; /* Not writable, is readable */ - buf[10] = ((4 + 4) >> 8) & 0xff; - buf[11] = (4 + 4) & 0xff; - - buf[12] = 0x03; /* BCA info */ - buf[13] = 0x40; /* Not writable, is readable */ - buf[14] = ((188 + 4) >> 8) & 0xff; - buf[15] = (188 + 4) & 0xff; - - buf[16] = 0x04; /* Manufacturing info */ - buf[17] = 0x40; /* Not writable, is readable */ - buf[18] = ((2048 + 4) >> 8) & 0xff; - buf[19] = (2048 + 4) & 0xff; - - /* Size of buffer, not including 2 byte size field */ - buf[6] = ((16 + 2) >> 8) & 0xff; - buf[7] = (16 + 2) & 0xff; - - /* data written + 4 byte header */ - return (16 + 4); - - default: /* TODO: formats beyond DVD-ROM requires */ - scsi_cdrom_invalid_field(dev); - return 0; - } + return ret; } static void @@ -1554,104 +1190,77 @@ scsi_cdrom_insert(void *priv) if (dev->drv->ops == NULL) { dev->unit_attention = 0; dev->drv->cd_status = CD_STATUS_EMPTY; - scsi_cdrom_log("CD-ROM %i: Media removal\n", dev->id); + scsi_cdrom_log(dev->log, "Media removal\n"); } else if (dev->drv->cd_status & CD_STATUS_TRANSITION) { dev->unit_attention = 1; /* Turn off the medium changed status. */ dev->drv->cd_status &= ~CD_STATUS_TRANSITION; - scsi_cdrom_log("CD-ROM %i: Media insert\n", dev->id); + scsi_cdrom_log(dev->log, "Media insert\n"); } else { dev->unit_attention = 0; dev->drv->cd_status |= CD_STATUS_TRANSITION; - scsi_cdrom_log("CD-ROM %i: Media transition\n", dev->id); - } -} - -static void -scsi_cdrom_ext_insert(void *priv, int ext_medium_changed) -{ - scsi_cdrom_t *dev = (scsi_cdrom_t *) priv; - - if ((dev == NULL) || (dev->drv == NULL)) - return; - - if ((dev->drv->ops == NULL) || (ext_medium_changed == -1)) { - dev->unit_attention = 0; - dev->drv->cd_status = CD_STATUS_EMPTY; - scsi_cdrom_log("CD-ROM %i: External media removal\n", dev->id); - } else if (ext_medium_changed == 1) { - dev->unit_attention = 0; - dev->drv->cd_status |= CD_STATUS_TRANSITION; - scsi_cdrom_log("CD-ROM %i: External media transition\n", dev->id); + scsi_cdrom_log(dev->log, "Media transition\n"); } } static int -scsi_command_check_ready(scsi_cdrom_t *dev, uint8_t *cdb) +scsi_command_check_ready(const scsi_cdrom_t *dev, const uint8_t *cdb) { int ret = 0; if (scsi_cdrom_command_flags[cdb[0]] & CHECK_READY) { - /*Note by TC1995: Some vendor commands from X vendor don't really check for ready status - but they do on Y vendor. Quite confusing I know.*/ - if (scsi_cdrom_command_flags[cdb[0]] & SCSI_ONLY) switch (dev->drv->type) { - default: - ret = 1; - break; - case CDROM_TYPE_DEC_RRD45_0436: - case CDROM_TYPE_ShinaKen_DM3x1S_104 ... CDROM_TYPE_SONY_CDU76S_100: - case CDROM_TYPE_TEXEL_DM3024_100 ... CDROM_TYPE_TEXEL_DM3028_106: - if (cdb[0] == 0xc0) - break; - ret = 1; - break; - } else + /* + Note by TC1995: Some vendor commands from X vendor don't really + check for ready status but they do on Y vendor. + Quite confusing I know. + */ + if (!dev->is_sony || (cdb[0] != 0xc0)) ret = 1; - } + } else if ((cdb[0] == GPCMD_READ_DVD_STRUCTURE) && (cdb[7] < 0xc0)) + ret = 1; return ret; } static int -scsi_cdrom_pre_execution_check(scsi_cdrom_t *dev, uint8_t *cdb) +scsi_cdrom_pre_execution_check(scsi_cdrom_t *dev, const uint8_t *cdb) { - int ready = 0; - int ext_medium_changed = 0; + int ready; - if (dev->drv && dev->drv->ops && dev->drv->ops->ext_medium_changed) - ext_medium_changed = dev->drv->ops->ext_medium_changed(dev->drv); - - if ((cdb[0] != GPCMD_REQUEST_SENSE) && (dev->cur_lun == SCSI_LUN_USE_CDB) && (cdb[1] & 0xe0)) { - scsi_cdrom_log("CD-ROM %i: Attempting to execute a unknown command targeted at SCSI LUN %i\n", - dev->id, ((dev->tf->request_length >> 5) & 7)); - scsi_cdrom_invalid_lun(dev); + if ((cdb[0] != GPCMD_REQUEST_SENSE) && (dev->cur_lun == SCSI_LUN_USE_CDB) && + (cdb[1] & 0xe0)) { + scsi_cdrom_log(dev->log, "Attempting to execute a unknown command targeted " + "at SCSI LUN %i\n", ((dev->tf->request_length >> 5) & 7)); + scsi_cdrom_invalid_lun(dev, cdb[1] >> 5); return 0; } if (!(scsi_cdrom_command_flags[cdb[0]] & IMPLEMENTED)) { - scsi_cdrom_log("CD-ROM %i: Attempting to execute unknown command %02X over %s\n", dev->id, cdb[0], - (dev->drv->bus_type == CDROM_BUS_SCSI) ? "SCSI" : "ATAPI"); + scsi_cdrom_log(dev->log, "Attempting to execute unknown command %02X over %s\n", + cdb[0], (dev->drv->bus_type == CDROM_BUS_SCSI) ? "SCSI" : "ATAPI"); - scsi_cdrom_illegal_opcode(dev); + scsi_cdrom_illegal_opcode(dev, cdb[0]); return 0; } - if ((dev->drv->bus_type < CDROM_BUS_SCSI) && (scsi_cdrom_command_flags[cdb[0]] & SCSI_ONLY)) { - scsi_cdrom_log("CD-ROM %i: Attempting to execute SCSI-only command %02X over ATAPI\n", dev->id, cdb[0]); - scsi_cdrom_illegal_opcode(dev); + if ((dev->drv->bus_type < CDROM_BUS_SCSI) && + (scsi_cdrom_command_flags[cdb[0]] & SCSI_ONLY)) { + scsi_cdrom_log(dev->log, "Attempting to execute SCSI-only command %02X over " + "ATAPI\n", cdb[0]); + scsi_cdrom_illegal_opcode(dev, cdb[0]); return 0; } - if ((dev->drv->bus_type == CDROM_BUS_SCSI) && (scsi_cdrom_command_flags[cdb[0]] & ATAPI_ONLY)) { - scsi_cdrom_log("CD-ROM %i: Attempting to execute ATAPI-only command %02X over SCSI\n", dev->id, cdb[0]); - scsi_cdrom_illegal_opcode(dev); + if ((dev->drv->bus_type == CDROM_BUS_SCSI) && + (scsi_cdrom_command_flags[cdb[0]] & ATAPI_ONLY)) { + scsi_cdrom_log(dev->log, "Attempting to execute ATAPI-only command %02X over " + "SCSI\n", cdb[0]); + scsi_cdrom_illegal_opcode(dev, cdb[0]); return 0; } - if (ext_medium_changed != 0) - scsi_cdrom_ext_insert((void *) dev, ext_medium_changed); - - if ((dev->drv->cd_status == CD_STATUS_PLAYING) || (dev->drv->cd_status == CD_STATUS_PAUSED)) { + if ((dev->drv->cd_status == CD_STATUS_PLAYING) || + (dev->drv->cd_status == CD_STATUS_PAUSED)) { ready = 1; goto skip_ready_check; } @@ -1660,44 +1269,51 @@ scsi_cdrom_pre_execution_check(scsi_cdrom_t *dev, uint8_t *cdb) if ((cdb[0] == GPCMD_TEST_UNIT_READY) || (cdb[0] == GPCMD_REQUEST_SENSE)) ready = 0; else { - if ((ext_medium_changed != 0) || !(scsi_cdrom_command_flags[cdb[0]] & ALLOW_UA)) { - scsi_cdrom_log("(ext_medium_changed != 0): scsi_cdrom_insert()\n"); + if (!(scsi_cdrom_command_flags[cdb[0]] & ALLOW_UA)) scsi_cdrom_insert((void *) dev); - } - ready = (dev->drv->cd_status != CD_STATUS_EMPTY) || (ext_medium_changed == -1); + ready = (dev->drv->cd_status != CD_STATUS_EMPTY); } } else ready = (dev->drv->cd_status != CD_STATUS_EMPTY); skip_ready_check: - /* If the drive is not ready, there is no reason to keep the + /* + If the drive is not ready, there is no reason to keep the UNIT ATTENTION condition present, as we only use it to mark - disc changes. */ + disc changes. + */ if (!ready && (dev->unit_attention > 0)) dev->unit_attention = 0; - /* If the UNIT ATTENTION condition is set and the command does not allow - execution under it, error out and report the condition. */ + /* + If the UNIT ATTENTION condition is set and the command does not allow + execution under it, error out and report the condition. + */ if (dev->unit_attention == 1) { - /* Only increment the unit attention phase if the command can not pass through it. */ + /* + Only increment the unit attention phase if the command can + not pass through it. + */ if (!(scsi_cdrom_command_flags[cdb[0]] & ALLOW_UA)) { - scsi_cdrom_log("CD-ROM %i: Unit attention now 2\n", dev->id); + scsi_cdrom_log(dev->log, "Unit attention now 2\n"); dev->unit_attention++; - scsi_cdrom_log("CD-ROM %i: UNIT ATTENTION: Command %02X not allowed to pass through\n", - dev->id, cdb[0]); + scsi_cdrom_log(dev->log, "UNIT ATTENTION: Command %02X not allowed to " + "pass through\n", cdb[0]); scsi_cdrom_unit_attention(dev); return 0; } } else if (dev->unit_attention == 2) { if (cdb[0] != GPCMD_REQUEST_SENSE) { - scsi_cdrom_log("CD-ROM %i: Unit attention now 0\n", dev->id); + scsi_cdrom_log(dev->log, "Unit attention now 0\n"); dev->unit_attention = 0; } } - /* Unless the command is REQUEST SENSE, clear the sense. This will *NOT* clear - the UNIT ATTENTION condition if it's set. */ + /* + Unless the command is REQUEST SENSE, clear the sense. This will *NOT* clear + the UNIT ATTENTION condition if it's set. + */ if (cdb[0] != GPCMD_REQUEST_SENSE) scsi_cdrom_sense_clear(dev, cdb[0]); @@ -1708,12 +1324,12 @@ skip_ready_check: dev->media_status = MEC_MEDIA_REMOVAL; if (!ready && scsi_command_check_ready(dev, cdb)) { - scsi_cdrom_log("CD-ROM %i: Not ready (%02X)\n", dev->id, cdb[0]); + scsi_cdrom_log(dev->log, "Not ready (%02X)\n", cdb[0]); scsi_cdrom_not_ready(dev); return 0; } - scsi_cdrom_log("CD-ROM %i: Continuing with command %02X\n", dev->id, cdb[0]); + scsi_cdrom_log(dev->log, "Continuing with command %02X\n", cdb[0]); return 1; } @@ -1724,41 +1340,103 @@ scsi_cdrom_rezero(scsi_cdrom_t *dev) cdrom_seek(dev->drv, 0, 0); } +static int +scsi_cdrom_update_sector_flags(scsi_cdrom_t *dev) +{ + int ret = 0; + + switch (dev->drv->sector_size) { + default: + dev->sector_type = 0xff; + scsi_cdrom_log(dev->log, "Invalid sector size: %i\n", dev->drv->sector_size); + scsi_cdrom_invalid_field_pl(dev, dev->drv->sector_size); + ret = 1; + break; + case 128: case 256: case 512: case 2048: + /* + Internal type code indicating both Mode 1 and Mode 2 Form 1 are allowed. + Upper 4 bits indicate the divisor. + */ + dev->sector_type = 0x08 | ((2048 / dev->drv->sector_size) << 4); + dev->sector_flags = 0x0010; + break; + case 2056: + dev->sector_type = 0x18; + dev->sector_flags = 0x0050; + break; + case 2324: case 2328: + dev->sector_type = (dev->drv->sector_size == 2328) ? 0x1a : 0x1b; + dev->sector_flags = 0x0018; + break; + case 2332: case 2336: + dev->sector_type = (dev->drv->sector_size == 2336) ? 0x1c : 0x1d; + dev->sector_flags = 0x0058; + break; + case 2340: + dev->sector_type = 0x18; + dev->sector_flags = 0x0078; + break; + case 2352: + dev->sector_type = 0x00; + dev->sector_flags = 0x00f8; + break; + case 2368: + dev->sector_type = 0x00; + dev->sector_flags = 0x01f8; + break; + case 2448: + dev->sector_type = 0x00; + dev->sector_flags = 0x02f8; + break; + } + + return ret; +} + void scsi_cdrom_reset(scsi_common_t *sc) { scsi_cdrom_t *dev = (scsi_cdrom_t *) sc; - if (!dev) - return; + if (dev != NULL) { + scsi_cdrom_rezero(dev); + dev->tf->status = 0; + dev->callback = 0.0; + scsi_cdrom_set_callback(dev); + dev->tf->phase = 1; + dev->tf->request_length = 0xeb14; + dev->packet_status = PHASE_NONE; + dev->unit_attention = 0xff; + dev->cur_lun = SCSI_LUN_USE_CDB; - scsi_cdrom_rezero(dev); - dev->tf->status = 0; - dev->callback = 0.0; - scsi_cdrom_set_callback(dev); - dev->tf->phase = 1; - dev->tf->request_length = 0xeb14; - dev->packet_status = PHASE_NONE; - dev->unit_attention = 0xff; - dev->cur_lun = SCSI_LUN_USE_CDB; + dev->drv->sector_size = 2048; + (void) scsi_cdrom_update_sector_flags(dev); + + scsi_cdrom_sense_key = scsi_cdrom_asc = scsi_cdrom_ascq = dev->unit_attention = 0; + scsi_cdrom_info = 0x00000000; + dev->drv->cd_status &= ~CD_STATUS_TRANSITION; + } } static void scsi_cdrom_request_sense(scsi_cdrom_t *dev, uint8_t *buffer, uint8_t alloc_length) { - /*Will return 18 bytes of 0*/ + /* Will return 18 bytes of 0x00. */ if (alloc_length != 0) { - memset(buffer, 0, alloc_length); + memset(buffer, 0x00, alloc_length); memcpy(buffer, dev->sense, alloc_length); } - buffer[0] = 0x70; + buffer[0] = 0xf0; + buffer[7] = 0x0a; if ((scsi_cdrom_sense_key > 0) && (dev->drv->cd_status == CD_STATUS_PLAYING_COMPLETED)) { buffer[2] = SENSE_ILLEGAL_REQUEST; buffer[12] = ASC_AUDIO_PLAY_OPERATION; buffer[13] = ASCQ_AUDIO_PLAY_OPERATION_COMPLETED; - } else if ((scsi_cdrom_sense_key == 0) && ((dev->drv->cd_status == CD_STATUS_PAUSED) || ((dev->drv->cd_status >= CD_STATUS_PLAYING) && (dev->drv->cd_status != CD_STATUS_STOPPED)))) { + } else if ((scsi_cdrom_sense_key == 0) && + ((dev->drv->cd_status == CD_STATUS_PAUSED) || ((dev->drv->cd_status >= CD_STATUS_PLAYING) && + (dev->drv->cd_status != CD_STATUS_STOPPED)))) { buffer[2] = SENSE_ILLEGAL_REQUEST; buffer[12] = ASC_AUDIO_PLAY_OPERATION; buffer[13] = (dev->drv->cd_status == CD_STATUS_PLAYING) ? ASCQ_AUDIO_PLAY_OPERATION_IN_PROGRESS : ASCQ_AUDIO_PLAY_OPERATION_PAUSED; @@ -1768,7 +1446,8 @@ scsi_cdrom_request_sense(scsi_cdrom_t *dev, uint8_t *buffer, uint8_t alloc_lengt buffer[13] = 0; } - scsi_cdrom_log("CD-ROM %i: Reporting sense: %02X %02X %02X\n", dev->id, buffer[2], buffer[12], buffer[13]); + scsi_cdrom_log(dev->log, "Reporting sense: %02X %02X %02X\n", buffer[2], buffer[12], + buffer[13]); if (buffer[2] == SENSE_UNIT_ATTENTION) { /* If the last remaining sense is unit attention, clear @@ -1777,7 +1456,7 @@ scsi_cdrom_request_sense(scsi_cdrom_t *dev, uint8_t *buffer, uint8_t alloc_lengt } if (dev->drv->cd_status & CD_STATUS_TRANSITION) { - scsi_cdrom_log("CD_STATUS_TRANSITION: scsi_cdrom_insert()\n"); + scsi_cdrom_log(dev->log, "CD_STATUS_TRANSITION: scsi_cdrom_insert()\n"); scsi_cdrom_insert((void *) dev); } } @@ -1786,18 +1465,12 @@ void scsi_cdrom_request_sense_for_scsi(scsi_common_t *sc, uint8_t *buffer, uint8_t alloc_length) { scsi_cdrom_t *dev = (scsi_cdrom_t *) sc; - int ext_medium_changed = 0; - - if (dev->drv && dev->drv->ops && dev->drv->ops->ext_medium_changed) - ext_medium_changed = dev->drv->ops->ext_medium_changed(dev->drv); - - if (ext_medium_changed != 0) - scsi_cdrom_ext_insert((void *) dev, ext_medium_changed); if ((dev->drv->cd_status == CD_STATUS_EMPTY) && dev->unit_attention) { - /* If the drive is not ready, there is no reason to keep the - UNIT ATTENTION condition present, as we only use it to mark - disc changes. */ + /* + If the drive is not ready, there is no reason to keep the UNIT ATTENTION + condition present, as we only use it to mark disc changes. + */ dev->unit_attention = 0; } @@ -1806,7 +1479,7 @@ scsi_cdrom_request_sense_for_scsi(scsi_common_t *sc, uint8_t *buffer, uint8_t al } static void -scsi_cdrom_set_buf_len(scsi_cdrom_t *dev, int32_t *BufLen, int32_t *src_len) +scsi_cdrom_set_buf_len(const scsi_cdrom_t *dev, int32_t *BufLen, int32_t *src_len) { if (dev->drv->bus_type == CDROM_BUS_SCSI) { if (*BufLen == -1) @@ -1815,44 +1488,48 @@ scsi_cdrom_set_buf_len(scsi_cdrom_t *dev, int32_t *BufLen, int32_t *src_len) *BufLen = MIN(*src_len, *BufLen); *src_len = *BufLen; } - scsi_cdrom_log("CD-ROM %i: Actual transfer length: %i\n", dev->id, *BufLen); + scsi_cdrom_log(dev->log, "Actual transfer length: %i\n", *BufLen); } } static void -scsi_cdrom_stop(scsi_common_t *sc) +scsi_cdrom_stop(const scsi_common_t *sc) { - scsi_cdrom_t *dev = (scsi_cdrom_t *) sc; + const scsi_cdrom_t *dev = (const scsi_cdrom_t *) sc; cdrom_stop(dev->drv); } static void -scsi_cdrom_set_speed(scsi_cdrom_t *dev, uint8_t *cdb) +scsi_cdrom_set_speed(scsi_cdrom_t *dev, const uint8_t *cdb) { + /* Stop the audio playing. */ + cdrom_stop(dev->drv); + dev->drv->cur_speed = (cdb[3] | (cdb[2] << 8)) / 176; if (dev->drv->cur_speed < 1) dev->drv->cur_speed = 1; - else if (dev->drv->cur_speed > dev->drv->speed) - dev->drv->cur_speed = dev->drv->speed; + else if (dev->drv->cur_speed > dev->drv->real_speed) + dev->drv->cur_speed = dev->drv->real_speed; scsi_cdrom_set_phase(dev, SCSI_PHASE_STATUS); scsi_cdrom_command_complete(dev); } static uint8_t -scsi_cdrom_command_chinon(void *sc, uint8_t *cdb, int32_t *BufLen) +scsi_cdrom_command_chinon(void *sc, const uint8_t *cdb, UNUSED(int32_t *BufLen)) { scsi_cdrom_t *dev = (scsi_cdrom_t *) sc; uint8_t cmd_stat = 0x00; switch (cdb[0]) { + default: + break; + case GPCMD_UNKNOWN_CHINON: - if (dev->drv->type == CDROM_TYPE_CHINON_CDS431_H42) { - scsi_cdrom_set_phase(dev, SCSI_PHASE_STATUS); - scsi_cdrom_stop(sc); - scsi_cdrom_command_complete(dev); - cmd_stat = 0x01; - } + scsi_cdrom_set_phase(dev, SCSI_PHASE_STATUS); + scsi_cdrom_stop(sc); + scsi_cdrom_command_complete(dev); + cmd_stat = 0x01; break; case GPCMD_EJECT_CHINON: @@ -1875,12 +1552,10 @@ scsi_cdrom_command_chinon(void *sc, uint8_t *cdb, int32_t *BufLen) } static uint8_t -scsi_cdrom_command_dec_sony_texel(void *sc, uint8_t *cdb, int32_t *BufLen) +scsi_cdrom_command_dec_sony_texel(void *sc, const uint8_t *cdb, int32_t *BufLen) { scsi_cdrom_t *dev = (scsi_cdrom_t *) sc; - int msf = 0; - int pos = dev->drv->seek_pos; - int ret = 1; + int msf; uint8_t cmd_stat = 0x00; int len; int max_len; @@ -1888,9 +1563,11 @@ scsi_cdrom_command_dec_sony_texel(void *sc, uint8_t *cdb, int32_t *BufLen) int real_pos; switch (cdb[0]) { + default: + break; + case GPCMD_SET_ADDRESS_FORMAT_SONY: scsi_cdrom_set_phase(dev, SCSI_PHASE_STATUS); - dev->sony_vendor = 1; dev->drv->sony_msf = cdb[8] & 1; scsi_cdrom_command_complete(dev); cmd_stat = 0x01; @@ -1899,7 +1576,6 @@ scsi_cdrom_command_dec_sony_texel(void *sc, uint8_t *cdb, int32_t *BufLen) case GPCMD_READ_TOC_SONY: scsi_cdrom_set_phase(dev, SCSI_PHASE_DATA_IN); msf = dev->drv->sony_msf; - dev->sony_vendor = 1; max_len = cdb[7]; max_len <<= 8; @@ -1907,14 +1583,14 @@ scsi_cdrom_command_dec_sony_texel(void *sc, uint8_t *cdb, int32_t *BufLen) scsi_cdrom_buf_alloc(dev, 65536); - if (!dev->drv->ops) + if (dev->drv->ops == NULL) scsi_cdrom_not_ready(dev); else { len = cdrom_read_toc_sony(dev->drv, dev->buffer, cdb[5], msf, max_len); if (len == -1) /* If the returned length is -1, this means cdrom_read_toc_sony() has encountered an error. */ - scsi_cdrom_invalid_field(dev); + scsi_cdrom_invalid_field(dev, dev->drv->inv_field); else { scsi_cdrom_set_buf_len(dev, BufLen, &len); scsi_cdrom_data_command_finish(dev, len, len, len, 0); @@ -1925,15 +1601,14 @@ scsi_cdrom_command_dec_sony_texel(void *sc, uint8_t *cdb, int32_t *BufLen) case GPCMD_READ_SUBCHANNEL_SONY: scsi_cdrom_set_phase(dev, SCSI_PHASE_DATA_IN); - dev->sony_vendor = 1; max_len = cdb[7]; max_len <<= 8; max_len |= cdb[8]; msf = dev->drv->sony_msf; - scsi_cdrom_log("CD-ROM %i: Getting sub-channel type (%s), code-q = %02x\n", - dev->id, msf ? "MSF" : "LBA", cdb[2] & 0x40); + scsi_cdrom_log(dev->log, "Getting sub-channel type (%s), code-q = %02x\n", + msf ? "MSF" : "LBA", cdb[2] & 0x40); if (cdb[2] & 0x40) { scsi_cdrom_buf_alloc(dev, 9); @@ -1945,7 +1620,7 @@ scsi_cdrom_command_dec_sony_texel(void *sc, uint8_t *cdb, int32_t *BufLen) scsi_cdrom_data_command_finish(dev, len, len, len, 0); } else { scsi_cdrom_set_phase(dev, SCSI_PHASE_STATUS); - scsi_cdrom_log("CD-ROM %i: Drive Status All done - callback set\n", dev->id); + scsi_cdrom_log(dev->log, "Drive Status All done - callback set\n"); dev->packet_status = PHASE_COMPLETE; dev->callback = 20.0 * CDROM_TIME; scsi_cdrom_set_callback(dev); @@ -1955,7 +1630,6 @@ scsi_cdrom_command_dec_sony_texel(void *sc, uint8_t *cdb, int32_t *BufLen) case GPCMD_READ_HEADER_SONY: scsi_cdrom_set_phase(dev, SCSI_PHASE_DATA_IN); - dev->sony_vendor = 1; alloc_length = ((cdb[7] << 8) | cdb[8]); scsi_cdrom_buf_alloc(dev, 4); @@ -1979,7 +1653,6 @@ scsi_cdrom_command_dec_sony_texel(void *sc, uint8_t *cdb, int32_t *BufLen) case GPCMD_PLAYBACK_STATUS_SONY: scsi_cdrom_set_phase(dev, SCSI_PHASE_DATA_IN); - dev->sony_vendor = 1; max_len = cdb[7]; max_len <<= 8; @@ -1999,7 +1672,7 @@ scsi_cdrom_command_dec_sony_texel(void *sc, uint8_t *cdb, int32_t *BufLen) &dev->buffer[6], msf); dev->buffer[5] = 0x00; - scsi_cdrom_log("Audio Status = %02x\n", dev->buffer[4]); + scsi_cdrom_log(dev->log, "Audio Status = %02x\n", dev->buffer[4]); len = MIN(len, max_len); scsi_cdrom_set_buf_len(dev, BufLen, &len); @@ -2010,7 +1683,6 @@ scsi_cdrom_command_dec_sony_texel(void *sc, uint8_t *cdb, int32_t *BufLen) case GPCMD_PAUSE_SONY: scsi_cdrom_set_phase(dev, SCSI_PHASE_STATUS); - dev->sony_vendor = 1; cdrom_audio_pause_resume(dev->drv, !(cdb[1] & 0x10)); scsi_cdrom_command_complete(dev); cmd_stat = 0x01; @@ -2018,19 +1690,19 @@ scsi_cdrom_command_dec_sony_texel(void *sc, uint8_t *cdb, int32_t *BufLen) case GPCMD_PLAY_TRACK_SONY: scsi_cdrom_set_phase(dev, SCSI_PHASE_STATUS); - dev->sony_vendor = 1; msf = 3; if ((cdb[5] != 1) || (cdb[8] != 1)) scsi_cdrom_illegal_mode(dev); else { - pos = cdb[4]; + const int pos = cdb[4]; - if ((dev->drv->image_path[0] == 0x00) || (dev->drv->cd_status <= CD_STATUS_DATA_ONLY)) + if ((dev->drv->image_path[0] == 0x00) || + (dev->drv->cd_status <= CD_STATUS_DVD)) scsi_cdrom_illegal_mode(dev); else { /* In this case, len is unused so just pass a fixed value of 1 intead. */ - ret = cdrom_audio_play(dev->drv, pos, 1 /*len*/, msf); + const int ret = cdrom_audio_play(dev->drv, pos, 1, msf); if (ret) scsi_cdrom_command_complete(dev); @@ -2042,27 +1714,29 @@ scsi_cdrom_command_dec_sony_texel(void *sc, uint8_t *cdb, int32_t *BufLen) break; case GPCMD_PLAY_MSF_SONY: - cdb[0] = GPCMD_PLAY_AUDIO_MSF; - dev->current_cdb[0] = cdb[0]; - dev->sony_vendor = 1; - /* Keep cmd_stat at 0x00, therefore, it's going to process it as GPCMD_PLAY_AUDIO_MSF. */ + dev->current_cdb[0] = GPCMD_PLAY_AUDIO_MSF; + /* + Keep cmd_stat at 0x00, therefore, it's going to process it + as GPCMD_PLAY_AUDIO_MSF. + */ break; case GPCMD_PLAY_AUDIO_SONY: - cdb[0] = GPCMD_PLAY_AUDIO_10; - dev->current_cdb[0] = cdb[0]; - dev->sony_vendor = 1; - /* Keep cmd_stat at 0x00, therefore, it's going to process it as GPCMD_PLAY_AUDIO_10. */ + dev->current_cdb[0] = GPCMD_PLAY_AUDIO_10; + /* + Keep cmd_stat at 0x00, therefore, it's going to process it + as GPCMD_PLAY_AUDIO_10. + */ break; case GPCMD_PLAYBACK_CONTROL_SONY: scsi_cdrom_set_phase(dev, SCSI_PHASE_DATA_OUT); - dev->sony_vendor = 1; len = (cdb[7] << 8) | cdb[8]; if (len == 0) { scsi_cdrom_set_phase(dev, SCSI_PHASE_STATUS); - scsi_cdrom_log("CD-ROM %i: PlayBack Control Sony All done - callback set\n", dev->id); + scsi_cdrom_log(dev->log, "PlayBack Control Sony All done - " + "callback set\n"); dev->packet_status = PHASE_COMPLETE; dev->callback = 20.0 * CDROM_TIME; scsi_cdrom_set_callback(dev); @@ -2079,70 +1753,93 @@ scsi_cdrom_command_dec_sony_texel(void *sc, uint8_t *cdb, int32_t *BufLen) } static uint8_t -scsi_cdrom_command_matsushita(void *sc, uint8_t *cdb, int32_t *BufLen) +scsi_cdrom_command_matsushita(void *sc, const uint8_t *cdb, UNUSED(int32_t *BufLen)) { - scsi_cdrom_t *dev = (scsi_cdrom_t *) sc; - uint8_t cmd_stat = 0x00; + scsi_cdrom_t *dev = (scsi_cdrom_t *) sc; + const uint8_t cmd_stat = 0x00; switch (cdb[0]) { + default: + break; + case GPCMD_READ_SUBCHANNEL_MATSUSHITA: - cdb[0] = GPCMD_READ_SUBCHANNEL; - dev->current_cdb[0] = cdb[0]; - /* Keep cmd_stat at 0x00, therefore, it's going to process it as GPCMD_READ_SUBCHANNEL. */ + dev->current_cdb[0] = GPCMD_READ_SUBCHANNEL; + /* + Keep cmd_stat at 0x00, therefore, it's going to process it + as GPCMD_READ_SUBCHANNEL. + */ break; case GPCMD_READ_TOC_MATSUSHITA: - cdb[0] = GPCMD_READ_TOC_PMA_ATIP; - dev->current_cdb[0] = cdb[0]; - /* Keep cmd_stat at 0x00, therefore, it's going to process it as GPCMD_READ_TOC_PMA_ATIP. */ + dev->current_cdb[0] = GPCMD_READ_TOC_PMA_ATIP; + /* + Keep cmd_stat at 0x00, therefore, it's going to process it + as GPCMD_READ_TOC_PMA_ATIP. + */ break; case GPCMD_READ_HEADER_MATSUSHITA: - cdb[0] = GPCMD_READ_HEADER; - dev->current_cdb[0] = cdb[0]; - /* Keep cmd_stat at 0x00, therefore, it's going to process it as GPCMD_READ_HEADER. */ + dev->current_cdb[0] = GPCMD_READ_HEADER; + /* + Keep cmd_stat at 0x00, therefore, it's going to process it + as GPCMD_READ_HEADER. + */ break; case GPCMD_PLAY_AUDIO_MATSUSHITA: - cdb[0] = GPCMD_PLAY_AUDIO_10; - dev->current_cdb[0] = cdb[0]; - /* Keep cmd_stat at 0x00, therefore, it's going to process it as GPCMD_PLAY_AUDIO_10. */ + dev->current_cdb[0] = GPCMD_PLAY_AUDIO_10; + /* + Keep cmd_stat at 0x00, therefore, it's going to process it + as GPCMD_PLAY_AUDIO_10. + */ break; case GPCMD_PLAY_AUDIO_MSF_MATSUSHITA: - cdb[0] = GPCMD_PLAY_AUDIO_MSF; - dev->current_cdb[0] = cdb[0]; - /* Keep cmd_stat at 0x00, therefore, it's going to process it as GPCMD_PLAY_AUDIO_MSF. */ + dev->current_cdb[0] = GPCMD_PLAY_AUDIO_MSF; + /* + Keep cmd_stat at 0x00, therefore, it's going to process it + as GPCMD_PLAY_AUDIO_MSF. + */ break; case GPCMD_PLAY_AUDIO_TRACK_INDEX_MATSUSHITA: - cdb[0] = GPCMD_PLAY_AUDIO_TRACK_INDEX; - dev->current_cdb[0] = cdb[0]; - /* Keep cmd_stat at 0x00, therefore, it's going to process it as GPCMD_PLAY_AUDIO_TRACK_INDEX. */ + dev->current_cdb[0] = GPCMD_PLAY_AUDIO_TRACK_INDEX; + /* + Keep cmd_stat at 0x00, therefore, it's going to process it + as GPCMD_PLAY_AUDIO_TRACK_INDEX. + */ break; case GPCMD_PLAY_AUDIO_TRACK_RELATIVE_10_MATSUSHITA: - cdb[0] = GPCMD_PLAY_AUDIO_TRACK_RELATIVE_10; - dev->current_cdb[0] = cdb[0]; - /* Keep cmd_stat at 0x00, therefore, it's going to process it as GPCMD_PLAY_AUDIO_TRACK_RELATIVE_10. */ + dev->current_cdb[0] = GPCMD_PLAY_AUDIO_TRACK_RELATIVE_10; + /* + Keep cmd_stat at 0x00, therefore, it's going to process it + as GPCMD_PLAY_AUDIO_TRACK_RELATIVE_10. + */ break; case GPCMD_PAUSE_RESUME_MATSUSHITA: - cdb[0] = GPCMD_PAUSE_RESUME; - dev->current_cdb[0] = cdb[0]; - /* Keep cmd_stat at 0x00, therefore, it's going to process it as GPCMD_PAUSE_RESUME. */ + dev->current_cdb[0] = GPCMD_PAUSE_RESUME; + /* + Keep cmd_stat at 0x00, therefore, it's going to process it + as GPCMD_PAUSE_RESUME. + */ break; case GPCMD_PLAY_AUDIO_12_MATSUSHITA: - cdb[0] = GPCMD_PLAY_AUDIO_12; - dev->current_cdb[0] = cdb[0]; - /* Keep cmd_stat at 0x00, therefore, it's going to process it as GPCMD_PLAY_AUDIO_12. */ + dev->current_cdb[0] = GPCMD_PLAY_AUDIO_12; + /* + Keep cmd_stat at 0x00, therefore, it's going to process it + as GPCMD_PLAY_AUDIO_12. + */ break; case GPCMD_PLAY_AUDIO_TRACK_RELATIVE_12_MATSUSHITA: - cdb[0] = GPCMD_PLAY_AUDIO_TRACK_RELATIVE_12; - dev->current_cdb[0] = cdb[0]; - /* Keep cmd_stat at 0x00, therefore, it's going to process it as GPCMD_PLAY_AUDIO_TRACK_RELATIVE_12. */ + dev->current_cdb[0] = GPCMD_PLAY_AUDIO_TRACK_RELATIVE_12; + /* + Keep cmd_stat at 0x00, therefore, it's going to process it + as GPCMD_PLAY_AUDIO_TRACK_RELATIVE_12. + */ break; } @@ -2150,16 +1847,19 @@ scsi_cdrom_command_matsushita(void *sc, uint8_t *cdb, int32_t *BufLen) } static uint8_t -scsi_cdrom_command_nec(void *sc, uint8_t *cdb, int32_t *BufLen) +scsi_cdrom_command_nec(void *sc, const uint8_t *cdb, int32_t *BufLen) { scsi_cdrom_t *dev = (scsi_cdrom_t *) sc; - int pos = dev->drv->seek_pos; - int ret = 1; uint8_t cmd_stat = 0x00; + int pos; + int ret; int len; int alloc_length; switch (cdb[0]) { + default: + break; + case GPCMD_NO_OPERATION_NEC: scsi_cdrom_set_phase(dev, SCSI_PHASE_STATUS); scsi_cdrom_command_complete(dev); @@ -2174,7 +1874,7 @@ scsi_cdrom_command_nec(void *sc, uint8_t *cdb, int32_t *BufLen) case GPCMD_AUDIO_TRACK_SEARCH_NEC: scsi_cdrom_set_phase(dev, SCSI_PHASE_STATUS); - if ((dev->drv->image_path[0] == 0x00) || (dev->drv->cd_status <= CD_STATUS_DATA_ONLY)) + if ((dev->drv->image_path[0] == 0x00) || (dev->drv->cd_status <= CD_STATUS_DVD)) scsi_cdrom_illegal_mode(dev); else { pos = (cdb[2] << 24) | (cdb[3] << 16) | (cdb[4] << 8) | cdb[5]; @@ -2191,7 +1891,7 @@ scsi_cdrom_command_nec(void *sc, uint8_t *cdb, int32_t *BufLen) case GPCMD_PLAY_AUDIO_NEC: scsi_cdrom_set_phase(dev, SCSI_PHASE_STATUS); - if ((dev->drv->image_path[0] == 0x00) || (dev->drv->cd_status <= CD_STATUS_DATA_ONLY)) + if ((dev->drv->image_path[0] == 0x00) || (dev->drv->cd_status <= CD_STATUS_DVD)) ret = 0; else { pos = (cdb[2] << 24) | (cdb[3] << 16) | (cdb[4] << 8) | cdb[5]; @@ -2234,11 +1934,11 @@ scsi_cdrom_command_nec(void *sc, uint8_t *cdb, int32_t *BufLen) alloc_length = cdb[1] & 0x1f; len = 10; - if (!dev->drv->ops) + if (dev->drv->ops == NULL) scsi_cdrom_not_ready(dev); else if (alloc_length <= 0) { scsi_cdrom_set_phase(dev, SCSI_PHASE_STATUS); - scsi_cdrom_log("CD-ROM %i: Subcode Q All done - callback set\n", dev->id); + scsi_cdrom_log(dev->log, "Subcode Q All done - callback set\n"); dev->packet_status = PHASE_COMPLETE; dev->callback = 20.0 * CDROM_TIME; scsi_cdrom_set_callback(dev); @@ -2248,7 +1948,7 @@ scsi_cdrom_command_nec(void *sc, uint8_t *cdb, int32_t *BufLen) memset(dev->buffer, 0, len); dev->buffer[0] = cdrom_get_current_subcodeq_playstatus(dev->drv, &dev->buffer[1]); - scsi_cdrom_log("Audio Status = %02x\n", dev->buffer[0]); + scsi_cdrom_log(dev->log, "Audio Status = %02x\n", dev->buffer[0]); scsi_cdrom_set_buf_len(dev, BufLen, &alloc_length); scsi_cdrom_data_command_finish(dev, len, len, len, 0); @@ -2264,17 +1964,14 @@ scsi_cdrom_command_nec(void *sc, uint8_t *cdb, int32_t *BufLen) */ scsi_cdrom_buf_alloc(dev, 22); - if (!dev->drv->ops) - scsi_cdrom_not_ready(dev); - else { - ret = cdrom_read_disc_info_toc(dev->drv, dev->buffer, cdb[2], cdb[1] & 3); - len = 22; - if (ret) { - scsi_cdrom_set_buf_len(dev, BufLen, &len); - scsi_cdrom_data_command_finish(dev, len, len, len, 0); - } else - scsi_cdrom_invalid_field(dev); - } + ret = cdrom_read_disc_info_toc(dev->drv, dev->buffer, cdb[2], cdb[1] & 3); + len = 22; + if (ret) { + scsi_cdrom_set_buf_len(dev, BufLen, &len); + scsi_cdrom_data_command_finish(dev, len, len, len, 0); + } else + scsi_cdrom_invalid_field(dev, dev->drv->inv_field); + cmd_stat = 0x01; break; } @@ -2283,17 +1980,20 @@ scsi_cdrom_command_nec(void *sc, uint8_t *cdb, int32_t *BufLen) } static uint8_t -scsi_cdrom_command_pioneer(void *sc, uint8_t *cdb, int32_t *BufLen) +scsi_cdrom_command_pioneer(void *sc, const uint8_t *cdb, int32_t *BufLen) { scsi_cdrom_t *dev = (scsi_cdrom_t *) sc; - int pos = dev->drv->seek_pos; - int ret = 1; uint8_t cmd_stat = 0x00; + int pos; + int ret; int len; int max_len; int alloc_length; switch (cdb[0]) { + default: + break; + case GPCMD_MAGAZINE_EJECT_PIONEER: scsi_cdrom_set_phase(dev, SCSI_PHASE_STATUS); scsi_cdrom_stop(sc); @@ -2306,7 +2006,7 @@ scsi_cdrom_command_pioneer(void *sc, uint8_t *cdb, int32_t *BufLen) scsi_cdrom_set_phase(dev, SCSI_PHASE_DATA_IN); scsi_cdrom_buf_alloc(dev, 4); - if (!dev->drv->ops) + if (dev->drv->ops == NULL) scsi_cdrom_not_ready(dev); else { ret = cdrom_read_disc_info_toc(dev->drv, dev->buffer, cdb[2], cdb[1] & 3); @@ -2316,7 +2016,7 @@ scsi_cdrom_command_pioneer(void *sc, uint8_t *cdb, int32_t *BufLen) scsi_cdrom_set_buf_len(dev, BufLen, &len); scsi_cdrom_data_command_finish(dev, len, len, len, 0); } else - scsi_cdrom_invalid_field(dev); + scsi_cdrom_invalid_field(dev, dev->drv->inv_field); } cmd_stat = 0x01; break; @@ -2327,11 +2027,11 @@ scsi_cdrom_command_pioneer(void *sc, uint8_t *cdb, int32_t *BufLen) alloc_length = cdb[1] & 0x1f; len = 9; - if (!dev->drv->ops) + if (dev->drv->ops == NULL) scsi_cdrom_not_ready(dev); else if (!alloc_length) { scsi_cdrom_set_phase(dev, SCSI_PHASE_STATUS); - scsi_cdrom_log("CD-ROM %i: Subcode Q All done - callback set\n", dev->id); + scsi_cdrom_log(dev->log, "Subcode Q All done - callback set\n"); dev->packet_status = PHASE_COMPLETE; dev->callback = 20.0 * CDROM_TIME; scsi_cdrom_set_callback(dev); @@ -2341,7 +2041,7 @@ scsi_cdrom_command_pioneer(void *sc, uint8_t *cdb, int32_t *BufLen) memset(dev->buffer, 0, len); cdrom_get_current_subcodeq(dev->drv, &dev->buffer[1]); - scsi_cdrom_log("Audio Status = %02x\n", dev->buffer[0]); + scsi_cdrom_log(dev->log, "Audio Status = %02x\n", dev->buffer[0]); scsi_cdrom_set_buf_len(dev, BufLen, &alloc_length); scsi_cdrom_data_command_finish(dev, len, len, len, 0); @@ -2351,7 +2051,7 @@ scsi_cdrom_command_pioneer(void *sc, uint8_t *cdb, int32_t *BufLen) case GPCMD_AUDIO_TRACK_SEARCH_PIONEER: scsi_cdrom_set_phase(dev, SCSI_PHASE_STATUS); - if ((dev->drv->image_path[0] == 0x00) || (dev->drv->cd_status <= CD_STATUS_DATA_ONLY)) + if ((dev->drv->image_path[0] == 0x00) || (dev->drv->cd_status <= CD_STATUS_DVD)) ret = 0; else { pos = (cdb[2] << 24) | (cdb[3] << 16) | (cdb[4] << 8) | cdb[5]; @@ -2370,7 +2070,7 @@ scsi_cdrom_command_pioneer(void *sc, uint8_t *cdb, int32_t *BufLen) case GPCMD_PLAY_AUDIO_PIONEER: scsi_cdrom_set_phase(dev, SCSI_PHASE_STATUS); - if ((dev->drv->image_path[0] == 0x00) || (dev->drv->cd_status <= CD_STATUS_DATA_ONLY)) + if ((dev->drv->image_path[0] == 0x00) || (dev->drv->cd_status <= CD_STATUS_DVD)) ret = 0; else { pos = (cdb[2] << 24) | (cdb[3] << 16) | (cdb[4] << 8) | cdb[5]; @@ -2412,7 +2112,7 @@ scsi_cdrom_command_pioneer(void *sc, uint8_t *cdb, int32_t *BufLen) memset(dev->buffer, 0, 6); dev->buffer[0] = cdrom_get_audio_status_pioneer(dev->drv, &dev->buffer[1]); /*Audio status*/ - scsi_cdrom_log("Audio Status = %02x\n", dev->buffer[4]); + scsi_cdrom_log(dev->log, "Audio Status = %02x\n", dev->buffer[4]); len = MIN(len, max_len); scsi_cdrom_set_buf_len(dev, BufLen, &len); @@ -2428,10 +2128,10 @@ scsi_cdrom_command_pioneer(void *sc, uint8_t *cdb, int32_t *BufLen) scsi_cdrom_buf_alloc(dev, 65536); if (!(scsi_cdrom_drive_status_page_flags & (1LL << (uint64_t) (cdb[2] & 0x3f)))) - scsi_cdrom_invalid_field(dev); + scsi_cdrom_invalid_field(dev, cdb[2]); else if (len <= 0) { scsi_cdrom_set_phase(dev, SCSI_PHASE_STATUS); - scsi_cdrom_log("CD-ROM %i: Drive Status All done - callback set\n", dev->id); + scsi_cdrom_log(dev->log, "Drive Status All done - callback set\n"); dev->packet_status = PHASE_COMPLETE; dev->callback = 20.0 * CDROM_TIME; scsi_cdrom_set_callback(dev); @@ -2439,12 +2139,13 @@ scsi_cdrom_command_pioneer(void *sc, uint8_t *cdb, int32_t *BufLen) memset(dev->buffer, 0, len); alloc_length = len; - len = scsi_cdrom_drive_status(dev, dev->buffer, 0, cdb[2]); + len = scsi_cdrom_drive_status(dev, dev->buffer, cdb[2]); len = MIN(len, alloc_length); scsi_cdrom_set_buf_len(dev, BufLen, &len); - scsi_cdrom_log("CD-ROM %i: Reading drive status page: %02X...\n", dev->id, cdb[2]); + scsi_cdrom_log(dev->log, "Reading drive status page: %02X...\n", + cdb[2]); scsi_cdrom_data_command_finish(dev, len, len, alloc_length, 0); } @@ -2456,16 +2157,19 @@ scsi_cdrom_command_pioneer(void *sc, uint8_t *cdb, int32_t *BufLen) } static uint8_t -scsi_cdrom_command_toshiba(void *sc, uint8_t *cdb, int32_t *BufLen) +scsi_cdrom_command_toshiba(void *sc, const uint8_t *cdb, int32_t *BufLen) { scsi_cdrom_t *dev = (scsi_cdrom_t *) sc; - int pos = dev->drv->seek_pos; - int ret = 1; uint8_t cmd_stat = 0x00; + int pos; + int ret; int len; int alloc_length; switch (cdb[0]) { + default: + break; + case GPCMD_NO_OPERATION_TOSHIBA: scsi_cdrom_set_phase(dev, SCSI_PHASE_STATUS); scsi_cdrom_command_complete(dev); @@ -2474,7 +2178,7 @@ scsi_cdrom_command_toshiba(void *sc, uint8_t *cdb, int32_t *BufLen) case GPCMD_AUDIO_TRACK_SEARCH_TOSHIBA: scsi_cdrom_set_phase(dev, SCSI_PHASE_STATUS); - if ((dev->drv->image_path[0] == 0x00) || (dev->drv->cd_status <= CD_STATUS_DATA_ONLY)) { + if ((dev->drv->image_path[0] == 0x00) || (dev->drv->cd_status <= CD_STATUS_DVD)) { scsi_cdrom_illegal_mode(dev); break; } @@ -2492,7 +2196,7 @@ scsi_cdrom_command_toshiba(void *sc, uint8_t *cdb, int32_t *BufLen) case GPCMD_PLAY_AUDIO_TOSHIBA: scsi_cdrom_set_phase(dev, SCSI_PHASE_STATUS); - if ((dev->drv->image_path[0] == 0x00) || (dev->drv->cd_status <= CD_STATUS_DATA_ONLY)) + if ((dev->drv->image_path[0] == 0x00) || (dev->drv->cd_status <= CD_STATUS_DVD)) scsi_cdrom_illegal_mode(dev); else { pos = (cdb[2] << 24) | (cdb[3] << 16) | (cdb[4] << 8) | cdb[5]; @@ -2534,11 +2238,11 @@ scsi_cdrom_command_toshiba(void *sc, uint8_t *cdb, int32_t *BufLen) alloc_length = cdb[1] & 0x1f; len = 10; - if (!dev->drv->ops) + if (dev->drv->ops == NULL) scsi_cdrom_not_ready(dev); else if (alloc_length <= 0) { scsi_cdrom_set_phase(dev, SCSI_PHASE_STATUS); - scsi_cdrom_log("CD-ROM %i: Subcode Q All done - callback set\n", dev->id); + scsi_cdrom_log(dev->log, "Subcode Q All done - callback set\n"); dev->packet_status = PHASE_COMPLETE; dev->callback = 20.0 * CDROM_TIME; scsi_cdrom_set_callback(dev); @@ -2548,7 +2252,7 @@ scsi_cdrom_command_toshiba(void *sc, uint8_t *cdb, int32_t *BufLen) memset(dev->buffer, 0, len); dev->buffer[0] = cdrom_get_current_subcodeq_playstatus(dev->drv, &dev->buffer[1]); - scsi_cdrom_log("Audio Status = %02x\n", dev->buffer[0]); + scsi_cdrom_log(dev->log, "Audio Status = %02x\n", dev->buffer[0]); scsi_cdrom_set_buf_len(dev, BufLen, &alloc_length); scsi_cdrom_data_command_finish(dev, len, len, len, 0); @@ -2560,7 +2264,7 @@ scsi_cdrom_command_toshiba(void *sc, uint8_t *cdb, int32_t *BufLen) scsi_cdrom_set_phase(dev, SCSI_PHASE_DATA_IN); scsi_cdrom_buf_alloc(dev, 4); - if (!dev->drv->ops) + if (dev->drv->ops == NULL) scsi_cdrom_not_ready(dev); else { ret = cdrom_read_disc_info_toc(dev->drv, dev->buffer, cdb[2], cdb[1] & 3); @@ -2569,7 +2273,7 @@ scsi_cdrom_command_toshiba(void *sc, uint8_t *cdb, int32_t *BufLen) scsi_cdrom_set_buf_len(dev, BufLen, &len); scsi_cdrom_data_command_finish(dev, len, len, len, 0); } else - scsi_cdrom_invalid_field(dev); + scsi_cdrom_invalid_field(dev, dev->drv->inv_field); } cmd_stat = 0x01; break; @@ -2579,22 +2283,19 @@ scsi_cdrom_command_toshiba(void *sc, uint8_t *cdb, int32_t *BufLen) } void -scsi_cdrom_command(scsi_common_t *sc, uint8_t *cdb) +scsi_cdrom_command(scsi_common_t *sc, const uint8_t *cdb) { scsi_cdrom_t *dev = (scsi_cdrom_t *) sc; - int msf = 0; int pos = dev->drv->seek_pos; int idx = 0; - int block_desc = 0; int ret = 1; - int format = 0; - int track = 0; - char device_identify[9] = { '8', '6', 'B', '_', 'C', 'D', '0', '0', 0 }; - char device_identify_ex[15] = { '8', '6', 'B', '_', 'C', 'D', '0', '0', ' ', 'v', '1', '.', '0', '0', 0 }; int32_t blen = 0; uint32_t profiles[2] = { MMC_PROFILE_CD_ROM, MMC_PROFILE_DVD_ROM }; uint8_t scsi_bus = (dev->drv->scsi_device_id >> 4) & 0x0f; uint8_t scsi_id = dev->drv->scsi_device_id & 0x0f; + char model[2048] = { 0 }; + int msf; + int block_desc; int len; int max_len; int used_len; @@ -2603,9 +2304,7 @@ scsi_cdrom_command(scsi_common_t *sc, uint8_t *cdb) uint32_t feature; unsigned preamble_len; int toc_format; - int real_pos; int32_t *BufLen; - uint8_t *b; if (dev->drv->bus_type == CDROM_BUS_SCSI) { BufLen = &scsi_devices[scsi_bus][scsi_id].buffer_length; @@ -2618,33 +2317,29 @@ scsi_cdrom_command(scsi_common_t *sc, uint8_t *cdb) dev->packet_len = 0; dev->request_pos = 0; - device_identify[7] = dev->id + 0x30; - - device_identify_ex[7] = dev->id + 0x30; - device_identify_ex[10] = EMU_VERSION_EX[0]; - device_identify_ex[12] = EMU_VERSION_EX[2]; - device_identify_ex[13] = EMU_VERSION_EX[3]; - memcpy(dev->current_cdb, cdb, 12); - dev->sony_vendor = 0; - // if (cdb[0] != 0) { - scsi_cdrom_log("CD-ROM %i: Command 0x%02X, Sense Key %02X, Asc %02X, Ascq %02X, Unit attention: %i\n", - dev->id, cdb[0], scsi_cdrom_sense_key, scsi_cdrom_asc, scsi_cdrom_ascq, - dev->unit_attention); - scsi_cdrom_log("CD-ROM %i: Request length: %04X\n", dev->id, dev->tf->request_length); +#if ENABLE_SCSI_CDROM_LOG == 2 + scsi_cdrom_log(dev->log, "Command 0x%02X, Sense Key %02X, Asc %02X, Ascq %02X, " + "Unit attention: %i\n", cdb[0], scsi_cdrom_sense_key, scsi_cdrom_asc, + scsi_cdrom_ascq, dev->unit_attention); + scsi_cdrom_log(dev->log, "Request length: %04X\n", dev->tf->request_length); - scsi_cdrom_log("CD-ROM %i: CDB: %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X\n", - dev->id, cdb[0], cdb[1], cdb[2], cdb[3], cdb[4], cdb[5], cdb[6], cdb[7], + scsi_cdrom_log(dev->log, "CDB: %02X %02X %02X %02X %02X %02X %02X " + "%02X %02X %02X %02X %02X\n", + cdb[0], cdb[1], cdb[2], cdb[3], cdb[4], cdb[5], cdb[6], cdb[7], cdb[8], cdb[9], cdb[10], cdb[11]); - // } +#endif msf = cdb[1] & 2; dev->sector_len = 0; scsi_cdrom_set_phase(dev, SCSI_PHASE_STATUS); - /* This handles the Not Ready/Unit Attention check if it has to be handled at this point. */ + /* + This handles the Not Ready/Unit Attention check if it has to be + handled at this point. + */ if (scsi_cdrom_pre_execution_check(dev, cdb) == 0) return; @@ -2653,7 +2348,7 @@ scsi_cdrom_command(scsi_common_t *sc, uint8_t *cdb) scsi_cdrom_sense_clear(dev, cdb[0]); } - if ((dev->ven_cmd == NULL) || (dev->ven_cmd(sc, cdb, BufLen) == 0x00)) switch (cdb[0]) { + if ((dev->ven_cmd == NULL) || (dev->ven_cmd(sc, cdb, BufLen) == 0x00)) switch (dev->current_cdb[0]) { case GPCMD_TEST_UNIT_READY: scsi_cdrom_set_phase(dev, SCSI_PHASE_STATUS); scsi_cdrom_command_complete(dev); @@ -2668,8 +2363,6 @@ scsi_cdrom_command(scsi_common_t *sc, uint8_t *cdb) break; case GPCMD_REQUEST_SENSE: - /* If there's a unit attention condition and there's a buffered not ready, a standalone REQUEST SENSE - should forget about the not ready, and report unit attention straight away. */ scsi_cdrom_set_phase(dev, SCSI_PHASE_DATA_IN); max_len = cdb[4]; @@ -2695,7 +2388,8 @@ scsi_cdrom_command(scsi_common_t *sc, uint8_t *cdb) case GPCMD_AUDIO_SCAN: scsi_cdrom_set_phase(dev, SCSI_PHASE_STATUS); - if ((dev->drv->image_path[0] == 0x00) || (dev->drv->cd_status <= CD_STATUS_DATA_ONLY)) { + if ((dev->drv->image_path[0] == 0x00) || + (dev->drv->cd_status <= CD_STATUS_DVD)) { scsi_cdrom_illegal_mode(dev); break; } @@ -2737,22 +2431,19 @@ scsi_cdrom_command(scsi_common_t *sc, uint8_t *cdb) if (toc_format == 0) toc_format = (cdb[9] >> 6) & 3; - if (!dev->drv->ops) { + if (dev->drv->ops == NULL) scsi_cdrom_not_ready(dev); - return; - } - - if (toc_format < 3) { + else if (toc_format < 3) { len = cdrom_read_toc(dev->drv, dev->buffer, toc_format, cdb[6], msf, max_len); /* If the returned length is -1, this means cdrom_read_toc() has encountered an error. */ if (len == -1) - scsi_cdrom_invalid_field(dev); + scsi_cdrom_invalid_field(dev, dev->drv->inv_field); else { scsi_cdrom_set_buf_len(dev, BufLen, &len); scsi_cdrom_data_command_finish(dev, len, len, len, 0); } } else - scsi_cdrom_invalid_field(dev); + scsi_cdrom_invalid_field(dev, toc_format); break; case GPCMD_READ_6: @@ -2763,32 +2454,38 @@ scsi_cdrom_command(scsi_common_t *sc, uint8_t *cdb) case GPCMD_READ_CD: case GPCMD_READ_CD_MSF: scsi_cdrom_set_phase(dev, SCSI_PHASE_DATA_IN); - alloc_length = 2048; + alloc_length = dev->drv->sector_size; switch (cdb[0]) { case GPCMD_READ_6: dev->sector_len = cdb[4]; - /* For READ (6) and WRITE (6), a length of 0 indicates a transfer of 256 sectors. */ + /* + For READ (6) and WRITE (6), a length of 0 indicates a transfer of + 256 sectors. + */ if (dev->sector_len == 0) dev->sector_len = 256; - dev->sector_pos = ((((uint32_t) cdb[1]) & 0x1f) << 16) | (((uint32_t) cdb[2]) << 8) | - ((uint32_t) cdb[3]); - scsi_cdrom_log("CD-ROM %i: READ (6): Length: %i, LBA: %i\n", dev->id, dev->sector_len, - dev->sector_pos); + dev->sector_pos = ((((uint32_t) cdb[1]) & 0x1f) << 16) | + (((uint32_t) cdb[2]) << 8) | ((uint32_t) cdb[3]); + scsi_cdrom_log(dev->log, "READ (6): Length: %i, LBA: %i\n", + dev->sector_len, dev->sector_pos); break; case GPCMD_READ_10: dev->sector_len = (cdb[7] << 8) | cdb[8]; - dev->sector_pos = (cdb[2] << 24) | (cdb[3] << 16) | (cdb[4] << 8) | cdb[5]; - scsi_cdrom_log("CD-ROM %i: READ (10): Length: %i, LBA: %i\n", dev->id, dev->sector_len, - dev->sector_pos); + dev->sector_pos = (cdb[2] << 24) | (cdb[3] << 16) | + (cdb[4] << 8) | cdb[5]; + scsi_cdrom_log(dev->log, "READ (10): Length: %i, LBA: %i\n", + dev->sector_len, dev->sector_pos); break; case GPCMD_READ_12: - dev->sector_len = (((uint32_t) cdb[6]) << 24) | (((uint32_t) cdb[7]) << 16) | + dev->sector_len = (((uint32_t) cdb[6]) << 24) | + (((uint32_t) cdb[7]) << 16) | (((uint32_t) cdb[8]) << 8) | ((uint32_t) cdb[9]); - dev->sector_pos = (((uint32_t) cdb[2]) << 24) | (((uint32_t) cdb[3]) << 16) | + dev->sector_pos = (((uint32_t) cdb[2]) << 24) | + (((uint32_t) cdb[3]) << 16) | (((uint32_t) cdb[4]) << 8) | ((uint32_t) cdb[5]); - scsi_cdrom_log("CD-ROM %i: READ (12): Length: %i, LBA: %i\n", dev->id, dev->sector_len, - dev->sector_pos); + scsi_cdrom_log(dev->log, "READ (12): Length: %i, LBA: %i\n", + dev->sector_len, dev->sector_pos); break; case GPCMD_READ_CD_MSF_OLD: case GPCMD_READ_CD_MSF: @@ -2806,15 +2503,20 @@ scsi_cdrom_command(scsi_common_t *sc, uint8_t *cdb) dev->sector_len++; } else { dev->sector_len = (cdb[6] << 16) | (cdb[7] << 8) | cdb[8]; - dev->sector_pos = (cdb[2] << 24) | (cdb[3] << 16) | (cdb[4] << 8) | cdb[5]; + dev->sector_pos = (cdb[2] << 24) | (cdb[3] << 16) | + (cdb[4] << 8) | cdb[5]; } - if (((cdb[9] & 0xf8) == 0x08) || ((cdb[9] == 0x00) && ((cdb[10] & 0x07) != 0x00))) { + if (((cdb[9] & 0xf8) == 0x08) || ((cdb[9] == 0x00) && + ((cdb[10] & 0x07) != 0x00))) { /* Illegal mode */ - scsi_cdrom_invalid_field(dev); + scsi_cdrom_invalid_field(dev, cdb[9]); ret = 0; } else if ((cdb[9] == 0x00) && ((cdb[10] & 0x07) == 0x00)) - /* If all the flag bits are cleared, then treat it as a non-data command. */ + /* + If all the flag bits are cleared, then treat it as a + non-data command. + */ dev->sector_len = 0; break; @@ -2825,39 +2527,30 @@ scsi_cdrom_command(scsi_common_t *sc, uint8_t *cdb) if (ret) { if (dev->sector_len > 0) { max_len = dev->sector_len; - dev->requested_blocks = max_len; /* - If we're reading all blocks in one go for DMA, - why not also for PIO, it should NOT matter - anyway, this step should be identical and only - the way the read dat is transferred to the host - should be different. - */ + dev->requested_blocks = max_len; dev->packet_len = max_len * alloc_length; scsi_cdrom_buf_alloc(dev, dev->packet_len); dev->drv->seek_diff = ABS((int) (pos - dev->sector_pos)); + dev->drv->seek_pos = dev->sector_pos; - if ((cdb[0] == GPCMD_READ_10) || (cdb[0] == GPCMD_READ_12)) { - switch (dev->drv->type) { - case CDROM_TYPE_NEC_25_10a ... CDROM_TYPE_NEC_464_105: - case CDROM_TYPE_TOSHIBA_XM_3433 ... CDROM_TYPE_TOSHIBA_SDM1401_1008: - ret = scsi_cdrom_read_blocks(dev, &alloc_length, 1, cdb[9] & 0xc0); - break; - default: - ret = scsi_cdrom_read_blocks(dev, &alloc_length, 1, 0); - break; - } - } else - ret = scsi_cdrom_read_blocks(dev, &alloc_length, 1, 0); + if (dev->use_cdb_9 && ((cdb[0] == GPCMD_READ_10) || + (cdb[0] == GPCMD_READ_12))) + ret = scsi_cdrom_read_blocks(dev, &alloc_length, + cdb[9] & 0xc0); + else + ret = scsi_cdrom_read_blocks(dev, &alloc_length, 0); if (ret > 0) { dev->requested_blocks = max_len; dev->packet_len = alloc_length; - scsi_cdrom_set_buf_len(dev, BufLen, (int32_t *) &dev->packet_len); + scsi_cdrom_set_buf_len(dev, BufLen, + (int32_t *) &dev->packet_len); - scsi_cdrom_data_command_finish(dev, alloc_length, alloc_length / dev->requested_blocks, + scsi_cdrom_data_command_finish(dev, alloc_length, + alloc_length / dev->requested_blocks, alloc_length, 0); if (dev->packet_status != PHASE_COMPLETE) @@ -2872,7 +2565,7 @@ scsi_cdrom_command(scsi_common_t *sc, uint8_t *cdb) } } else { scsi_cdrom_set_phase(dev, SCSI_PHASE_STATUS); - /* scsi_cdrom_log("CD-ROM %i: All done - callback set\n", dev->id); */ + /* scsi_cdrom_log(dev->log, "All done - callback set\n"); */ dev->packet_status = PHASE_COMPLETE; dev->callback = 20.0 * CDROM_TIME; scsi_cdrom_set_callback(dev); @@ -2882,39 +2575,80 @@ scsi_cdrom_command(scsi_common_t *sc, uint8_t *cdb) case GPCMD_READ_HEADER: scsi_cdrom_set_phase(dev, SCSI_PHASE_DATA_IN); + alloc_length = 2352; - alloc_length = ((cdb[7] << 8) | cdb[8]); - scsi_cdrom_buf_alloc(dev, 8); - + len = (cdb[7] << 8) | cdb[8]; dev->sector_len = 1; dev->sector_pos = (cdb[2] << 24) | (cdb[3] << 16) | (cdb[4] << 8) | cdb[5]; - if (msf) - real_pos = cdrom_lba_to_msf_accurate(dev->sector_pos); - else - real_pos = dev->sector_pos; - dev->buffer[0] = 1; /*2048 bytes user data*/ - dev->buffer[1] = dev->buffer[2] = dev->buffer[3] = 0; - dev->buffer[4] = (real_pos >> 24); - dev->buffer[5] = ((real_pos >> 16) & 0xff); - dev->buffer[6] = ((real_pos >> 8) & 0xff); - dev->buffer[7] = real_pos & 0xff; + scsi_cdrom_log(dev->log, "READ HEADER: Length: %i, LBA: %i\n", + dev->sector_len, dev->sector_pos); - len = 8; - len = MIN(len, alloc_length); + if (len > 0) { + max_len = 1; + dev->requested_blocks = max_len; - scsi_cdrom_set_buf_len(dev, BufLen, &len); + dev->packet_len = len; + scsi_cdrom_buf_alloc(dev, 2352); - scsi_cdrom_data_command_finish(dev, len, len, len, 0); + dev->drv->seek_diff = ABS((int) (pos - dev->sector_pos)); + dev->drv->seek_pos = dev->sector_pos; + + ret = scsi_cdrom_read_blocks(dev, &alloc_length, 0); + + if (ret > 0) { + uint8_t header[4] = { 0 }; + + memcpy(header, dev->buffer, 4); + + dev->buffer[0] = header[3]; + + if (cdb[1] & 0x02) { + memset(&(dev->buffer[1]), 0x00, 4); + dev->buffer[5] = header[0]; + dev->buffer[6] = header[1]; + dev->buffer[7] = header[2]; + } else { + memset(&(dev->buffer[1]), 0x00, 3); + uint32_t lba = ((header[0] * 60 * 75) + + (header[1] * 75) + + header[2]) - 150; + dev->buffer[4] = (lba >> 24) & 0xff; + dev->buffer[5] = (lba >> 16) & 0xff; + dev->buffer[6] = (lba >> 8) & 0xff; + dev->buffer[7] = lba & 0xff; + } + + len = MIN(8, len); + + scsi_cdrom_set_buf_len(dev, BufLen, &len); + + scsi_cdrom_data_command_finish(dev, len, len, + len, 0); + + ui_sb_update_icon(SB_CDROM | dev->id, 0); + } else { + scsi_cdrom_set_phase(dev, SCSI_PHASE_STATUS); + dev->packet_status = (ret < 0) ? PHASE_ERROR : PHASE_COMPLETE; + dev->callback = 20.0 * CDROM_TIME; + scsi_cdrom_set_callback(dev); + } + } else { + scsi_cdrom_set_phase(dev, SCSI_PHASE_STATUS); + /* scsi_cdrom_log(dev->log, "All done - callback set\n"); */ + dev->packet_status = PHASE_COMPLETE; + dev->callback = 20.0 * CDROM_TIME; + scsi_cdrom_set_callback(dev); + } break; case GPCMD_MODE_SENSE_6: case GPCMD_MODE_SENSE_10: scsi_cdrom_set_phase(dev, SCSI_PHASE_DATA_IN); - if (dev->drv->bus_type == CDROM_BUS_SCSI) - block_desc = ((cdb[1] >> 3) & 1) ? 0 : 1; - else + if (dev->drv->bus_type == CDROM_BUS_ATAPI) block_desc = 0; + else + block_desc = !((cdb[1] >> 3) & 1); if (cdb[0] == GPCMD_MODE_SENSE_6) { len = cdb[4]; @@ -2924,32 +2658,23 @@ scsi_cdrom_command(scsi_common_t *sc, uint8_t *cdb) scsi_cdrom_buf_alloc(dev, 65536); } - switch (dev->drv->type) { - case CDROM_TYPE_DEC_RRD45_0436: - case CDROM_TYPE_ShinaKen_DM3x1S_104 ... CDROM_TYPE_SONY_CDU76S_100: - case CDROM_TYPE_TEXEL_DM3024_100 ... CDROM_TYPE_TEXEL_DM3028_106: - if (!(scsi_cdrom_mode_sense_page_flags_sony & (1LL << (uint64_t) (cdb[2] & 0x3f)))) - ret = 0; - break; - default: - if (!(scsi_cdrom_mode_sense_page_flags & (1LL << (uint64_t) (cdb[2] & 0x3f)))) - ret = 0; - break; - } + if (!(dev->ms_page_flags & (1LL << (uint64_t) (cdb[2] & 0x3f)))) + ret = 0; if (ret == 1) { memset(dev->buffer, 0, len); alloc_length = len; - /* This determines the media type ID to return - this is - a SCSI/ATAPI-specific thing, so it makes the most sense - to keep this here. - Also, the max_len variable is reused as this command - does otherwise not use it, to avoid having to declare - another variable. */ + /* + This determines the media type ID to return which is a SCSI/ATAPI-specific + thing, so it makes the most sense to keep this here. + + Also, the max_len variable is reused as this command does otherwise not + use it, to avoid having to declare another variable. + */ if (dev->drv->cd_status == CD_STATUS_EMPTY) max_len = 70; /* No media inserted. */ - else if (dev->drv->cdrom_capacity > CD_MAX_SECTORS) + else if (dev->drv->cd_status == CD_STATUS_DVD) max_len = 65; /* DVD. */ else if (dev->drv->cd_status == CD_STATUS_DATA_ONLY) max_len = 1; /* Data CD. */ @@ -2964,7 +2689,8 @@ scsi_cdrom_command(scsi_common_t *sc, uint8_t *cdb) if (block_desc) dev->buffer[3] = 8; } else { - len = scsi_cdrom_mode_sense(dev, dev->buffer, 8, cdb[2], block_desc); + len = scsi_cdrom_mode_sense(dev, dev->buffer, 8, + cdb[2], block_desc); len = MIN(len, alloc_length); dev->buffer[0] = (len - 2) >> 8; dev->buffer[1] = (len - 2) & 255; @@ -2977,11 +2703,11 @@ scsi_cdrom_command(scsi_common_t *sc, uint8_t *cdb) scsi_cdrom_set_buf_len(dev, BufLen, &alloc_length); - scsi_cdrom_log("CD-ROM %i: Reading mode page: %02X...\n", dev->id, cdb[2]); + scsi_cdrom_log(dev->log, "Reading mode page: %02X...\n", cdb[2]); scsi_cdrom_data_command_finish(dev, len, len, alloc_length, 0); } else - scsi_cdrom_invalid_field(dev); + scsi_cdrom_invalid_field(dev, cdb[2]); break; case GPCMD_MODE_SELECT_6: @@ -3014,21 +2740,17 @@ scsi_cdrom_command(scsi_common_t *sc, uint8_t *cdb) /* Only feature 0 is supported */ if ((feature > 3) && (feature != 0x010) && (feature != 0x1d) && (feature != 0x01e) && (feature != 0x01f) && (feature != 0x103)) - scsi_cdrom_invalid_field(dev); + scsi_cdrom_invalid_field(dev, feature); else { scsi_cdrom_buf_alloc(dev, 65536); memset(dev->buffer, 0, max_len); - alloc_length = 0; - b = dev->buffer; + uint8_t *b = dev->buffer; + + alloc_length = 0; - /* - The number of sectors from the media tells us which profile - to use as current. 0 means there is no media. - */ if (dev->drv->cd_status != CD_STATUS_EMPTY) { - len = dev->drv->cdrom_capacity; - if (len > CD_MAX_SECTORS) { + if (dev->drv->cd_status == CD_STATUS_DVD) { b[6] = (MMC_PROFILE_DVD_ROM >> 8) & 0xff; b[7] = MMC_PROFILE_DVD_ROM & 0xff; ret = 1; @@ -3044,7 +2766,8 @@ scsi_cdrom_command(scsi_common_t *sc, uint8_t *cdb) b += 8; if ((feature == 0) || ((cdb[1] & 3) < 2)) { - b[2] = (0 << 2) | 0x02 | 0x01; /* persistent and current */ + /* Persistent and current. */ + b[2] = (0 << 2) | 0x02 | 0x01; b[3] = 8; alloc_length += 4; @@ -3062,8 +2785,9 @@ scsi_cdrom_command(scsi_common_t *sc, uint8_t *cdb) } } if ((feature == 1) || ((cdb[1] & 3) < 2)) { + /* Persistent and current. */ b[1] = 1; - b[2] = (2 << 2) | 0x02 | 0x01; /* persistent and current */ + b[2] = (2 << 2) | 0x02 | 0x01; b[3] = 8; if (dev->drv->bus_type == CDROM_BUS_SCSI) @@ -3086,25 +2810,18 @@ scsi_cdrom_command(scsi_common_t *sc, uint8_t *cdb) } if ((feature == 3) || ((cdb[1] & 3) < 2)) { b[1] = 2; - b[2] = (0 << 2) | 0x02 | 0x01; /* persistent and current */ + /* Persistent and current. */ + b[2] = (0 << 2) | 0x02 | 0x01; b[3] = 4; - b[4] = 0x0d; - - /* The early CD-ROM drives we emulate (NEC CDR-260 for ATAPI and - early vendor SCSI CD-ROM models) are caddy drives, the later - ones are tray drives. */ - if (dev->drv->bus_type == CDROM_BUS_SCSI) - b[4] |= ((dev->drv->type == CDROM_TYPE_86BOX_100) ? 0x20 : 0x00); - else - b[4] |= ((dev->drv->type == CDROM_TYPE_NEC_260_100) || - ((dev->drv->type == CDROM_TYPE_NEC_260_101)) ? 0x00 : 0x20); + b[4] = 0x0d | (cdrom_is_caddy(dev->drv->type) ? 0x00 : 0x20); alloc_length += 8; b += 8; } if ((feature == 0x10) || ((cdb[1] & 3) < 2)) { b[1] = 0x10; - b[2] = (0 << 2) | 0x02 | 0x01; /* persistent and current */ + /* Persistent and current. */ + b[2] = (0 << 2) | 0x02 | 0x01; b[3] = 8; b[6] = 8; @@ -3115,7 +2832,8 @@ scsi_cdrom_command(scsi_common_t *sc, uint8_t *cdb) } if ((feature == 0x1d) || ((cdb[1] & 3) < 2)) { b[1] = 0x1d; - b[2] = (0 << 2) | 0x02 | 0x01; /* persistent and current */ + /* Persistent and current. */ + b[2] = (0 << 2) | 0x02 | 0x01; b[3] = 0; alloc_length += 4; @@ -3123,7 +2841,8 @@ scsi_cdrom_command(scsi_common_t *sc, uint8_t *cdb) } if ((feature == 0x1e) || ((cdb[1] & 3) < 2)) { b[1] = 0x1e; - b[2] = (2 << 2) | 0x02 | 0x01; /* persistent and current */ + /* Persistent and current. */ + b[2] = (2 << 2) | 0x02 | 0x01; b[3] = 4; b[4] = 0; @@ -3141,14 +2860,14 @@ scsi_cdrom_command(scsi_common_t *sc, uint8_t *cdb) if ((feature == 0x103) || ((cdb[1] & 3) < 2)) { b[0] = 1; b[1] = 3; - b[2] = (0 << 2) | 0x02 | 0x01; /* persistent and current */ + /* Persistent and current. */ + b[2] = (0 << 2) | 0x02 | 0x01; b[3] = 0; b[4] = 7; b[6] = 1; alloc_length += 8; - b += 8; } dev->buffer[0] = ((alloc_length - 4) >> 24) & 0xff; @@ -3160,7 +2879,8 @@ scsi_cdrom_command(scsi_common_t *sc, uint8_t *cdb) scsi_cdrom_set_buf_len(dev, BufLen, &alloc_length); - scsi_cdrom_data_command_finish(dev, alloc_length, alloc_length, alloc_length, 0); + scsi_cdrom_data_command_finish(dev, alloc_length, alloc_length, + alloc_length, 0); } break; @@ -3174,37 +2894,40 @@ scsi_cdrom_command(scsi_common_t *sc, uint8_t *cdb) if (gesn_cdb->polled & 0x01) { /* - * These are the supported events. - * - * We currently only support requests of the 'media' type. - * Notification class requests and supported event classes are bitmasks, - * but they are built from the same values as the "notification class" - * field. + These are the supported events. + + We currently only support requests of the 'media' type. + Notification class requests and supported event classes are bitmasks, + but they are built from the same values as the "notification class" + field. */ gesn_event_header->supported_events = 1 << GESN_MEDIA; /* - * We use |= below to set the class field; other bits in this byte - * are reserved now but this is useful to do if we have to use the - * reserved fields later. + We use |= below to set the class field; other bits in this byte + are reserved now but this is useful to do if we have to use the + reserved fields later. */ gesn_event_header->notification_class = 0; /* - * Responses to requests are to be based on request priority. The - * notification_class_request_type enum above specifies the - * priority: upper elements are higher prio than lower ones. + Responses to requests are to be based on request priority. The + notification_class_request_type enum above specifies the + priority: upper elements are higher prio than lower ones. */ if (gesn_cdb->class & (1 << GESN_MEDIA)) { gesn_event_header->notification_class |= GESN_MEDIA; - dev->buffer[4] = dev->media_status; /* Bits 7-4 = Reserved, Bits 4-1 = Media Status */ - dev->buffer[5] = 1; /* Power Status (1 = Active) */ + /* Bits 7-4 = Reserved, Bits 4-1 = Media Status. */ + dev->buffer[4] = dev->media_status; + /* Power Status (1 = Active). */ + dev->buffer[5] = 1; dev->buffer[6] = 0; dev->buffer[7] = 0; used_len = 8; } else { - gesn_event_header->notification_class = 0x80; /* No event available */ + /* No event available. */ + gesn_event_header->notification_class = 0x80; used_len = sizeof(*gesn_event_header); } gesn_event_header->len = used_len - sizeof(*gesn_event_header); @@ -3214,14 +2937,12 @@ scsi_cdrom_command(scsi_common_t *sc, uint8_t *cdb) scsi_cdrom_set_buf_len(dev, BufLen, &used_len); scsi_cdrom_data_command_finish(dev, used_len, used_len, used_len, 0); - } else { + } else /* Only polling is supported, asynchronous mode is not. It is fine by the MMC spec to not support async mode operations. */ - scsi_cdrom_invalid_field(dev); - scsi_cdrom_buf_free(dev); - } + scsi_cdrom_invalid_field(dev, gesn_cdb->polled); break; case GPCMD_READ_DISC_INFORMATION: @@ -3233,16 +2954,9 @@ scsi_cdrom_command(scsi_common_t *sc, uint8_t *cdb) scsi_cdrom_buf_alloc(dev, 65536); - memset(dev->buffer, 0, 34); - memset(dev->buffer, 1, 9); - dev->buffer[0] = 0; - dev->buffer[1] = 32; - dev->buffer[2] = 0xe; /* last session complete, disc finalized */ - dev->buffer[7] = 0x20; /* unrestricted use */ - dev->buffer[8] = 0x00; /* CD-ROM */ + cdrom_read_disc_information(dev->drv, dev->buffer); - len = 34; - len = MIN(len, max_len); + len = MIN(34, max_len); scsi_cdrom_set_buf_len(dev, BufLen, &len); @@ -3258,32 +2972,10 @@ scsi_cdrom_command(scsi_common_t *sc, uint8_t *cdb) scsi_cdrom_buf_alloc(dev, 65536); - track = ((uint32_t) cdb[2]) << 24; - track |= ((uint32_t) cdb[3]) << 16; - track |= ((uint32_t) cdb[4]) << 8; - track |= (uint32_t) cdb[5]; + ret = cdrom_read_track_information(dev->drv, cdb, dev->buffer); - if (((cdb[1] & 0x03) != 1) || (track != 1)) - scsi_cdrom_invalid_field(dev); - else { - len = 36; - - memset(dev->buffer, 0, 36); - dev->buffer[0] = 0; - dev->buffer[1] = 34; - dev->buffer[2] = 1; /* track number (LSB) */ - dev->buffer[3] = 1; /* session number (LSB) */ - dev->buffer[5] = (0 << 5) | (0 << 4) | (4 << 0); /* not damaged, primary copy, data track */ - dev->buffer[6] = (0 << 7) | (0 << 6) | (0 << 5) | /* not reserved track, not blank, */ - (0 << 6) | (1 << 0); /* not packet writing, not fixed packet, */ - /* data mode 1 */ - dev->buffer[7] = (0 << 1) | (0 << 0); /* last recorded address not valid, */ - /* next recordable address not valid */ - - dev->buffer[24] = ((dev->drv->cdrom_capacity - 1) >> 24) & 0xff; /* track size */ - dev->buffer[25] = ((dev->drv->cdrom_capacity - 1) >> 16) & 0xff; /* track size */ - dev->buffer[26] = ((dev->drv->cdrom_capacity - 1) >> 8) & 0xff; /* track size */ - dev->buffer[27] = (dev->drv->cdrom_capacity - 1) & 0xff; /* track size */ + if (ret > 0) { + len = ret; if (len > max_len) { len = max_len; @@ -3293,7 +2985,8 @@ scsi_cdrom_command(scsi_common_t *sc, uint8_t *cdb) scsi_cdrom_set_buf_len(dev, BufLen, &len); scsi_cdrom_data_command_finish(dev, len, len, max_len, 0); - } + } else + scsi_cdrom_invalid_field(dev, -ret); break; case GPCMD_PLAY_AUDIO_10: @@ -3345,7 +3038,8 @@ scsi_cdrom_command(scsi_common_t *sc, uint8_t *cdb) break; } - if (ret && (dev->drv->image_path[0] != 0x00) && (dev->drv->cd_status > CD_STATUS_DATA_ONLY)) + if (ret && (dev->drv->image_path[0] != 0x00) && + (dev->drv->cd_status > CD_STATUS_DVD)) ret = cdrom_audio_play(dev->drv, pos, len, msf); else ret = 0; @@ -3366,13 +3060,14 @@ scsi_cdrom_command(scsi_common_t *sc, uint8_t *cdb) scsi_cdrom_buf_alloc(dev, 32); - scsi_cdrom_log("CD-ROM %i: Getting page %i (%s)\n", dev->id, cdb[3], msf ? "MSF" : "LBA"); + scsi_cdrom_log(dev->log, "Getting page %i (%s)\n", cdb[3], + msf ? "MSF" : "LBA"); - if (cdb[3] > 3) { - /* scsi_cdrom_log("CD-ROM %i: Read subchannel check condition %02X\n", dev->id, - cdb[3]); */ - scsi_cdrom_invalid_field(dev); - } else if (max_len <= 0) { + if (cdb[3] > 3) + scsi_cdrom_invalid_field(dev, cdb[3]); + else if ((cdb[3] != 3) && (cdb[6] != 0)) + scsi_cdrom_invalid_field(dev, cdb[6]); + else if (max_len <= 0) { scsi_cdrom_set_phase(dev, SCSI_PHASE_STATUS); dev->packet_status = PHASE_COMPLETE; dev->callback = 20.0 * CDROM_TIME; @@ -3382,7 +3077,7 @@ scsi_cdrom_command(scsi_common_t *sc, uint8_t *cdb) alloc_length = 4; else switch (cdb[3]) { case 0: - /* SCSI-2: Q-type subchannel, ATAPI: reserved */ + /* SCSI-2: Q-type subchannel, ATAPI: reserved. */ alloc_length = (dev->drv->bus_type == CDROM_BUS_SCSI) ? 48 : 4; break; case 1: @@ -3404,32 +3099,14 @@ scsi_cdrom_command(scsi_common_t *sc, uint8_t *cdb) dev->buffer[pos++] = cdb[3]; /* Format code */ if (alloc_length != 4) { - dev->buffer[1] = cdrom_get_current_status(dev->drv); - cdrom_get_current_subchannel(dev->drv, &dev->buffer[4], msf); dev->buffer[2] = alloc_length - 4; } - switch (dev->drv->cd_status) { - case CD_STATUS_PLAYING: - dev->buffer[1] = 0x11; - break; - case CD_STATUS_PAUSED: - dev->buffer[1] = ((dev->drv->type == CDROM_TYPE_CHINON_CDS431_H42) || - (dev->drv->type == CDROM_TYPE_CHINON_CDX435_M62)) ? 0x15 : 0x12; - break; - case CD_STATUS_DATA_ONLY: - dev->buffer[1] = ((dev->drv->type == CDROM_TYPE_CHINON_CDS431_H42) || - (dev->drv->type == CDROM_TYPE_CHINON_CDX435_M62)) ? 0x00 : 0x15; - break; - default: - dev->buffer[1] = ((dev->drv->type == CDROM_TYPE_CHINON_CDS431_H42) || - (dev->drv->type == CDROM_TYPE_CHINON_CDX435_M62)) ? 0x00 : 0x13; - break; - } + dev->buffer[1] = cdrom_get_current_status(dev->drv); - scsi_cdrom_log("Audio Status = %02x\n", dev->buffer[1]); + scsi_cdrom_log(dev->log, "Audio Status = %02x\n", dev->buffer[1]); len = MIN(len, max_len); scsi_cdrom_set_buf_len(dev, BufLen, &len); @@ -3445,23 +3122,29 @@ scsi_cdrom_command(scsi_common_t *sc, uint8_t *cdb) scsi_cdrom_buf_alloc(dev, alloc_length); - if ((cdb[7] < 0xc0) && (dev->drv->cdrom_capacity <= CD_MAX_SECTORS)) - scsi_cdrom_incompatible_format(dev); + if ((cdb[7] < 0xc0) && (dev->drv->cd_status != CD_STATUS_DVD)) + scsi_cdrom_incompatible_format(dev, cdb[7]); else { memset(dev->buffer, 0, alloc_length); if ((cdb[7] <= 0x7f) || (cdb[7] == 0xff)) { + uint32_t info = 0x00000000; + if (cdb[1] == 0) { - format = cdb[7]; - ret = scsi_cdrom_read_dvd_structure(dev, format, cdb, dev->buffer); - dev->buffer[0] = (ret >> 8); - dev->buffer[1] = (ret & 0xff); - dev->buffer[2] = dev->buffer[3] = 0x00; - if (ret) { + ret = cdrom_read_dvd_structure(dev->drv, cdb[6], cdb[7], dev->buffer, &info); + if (ret > 0) { + dev->buffer[0] = (ret >> 8); + dev->buffer[1] = (ret & 0xff); + dev->buffer[2] = dev->buffer[3] = 0x00; + scsi_cdrom_set_buf_len(dev, BufLen, &alloc_length); - scsi_cdrom_data_command_finish(dev, alloc_length, alloc_length, + scsi_cdrom_data_command_finish(dev, alloc_length, + alloc_length, alloc_length, 0); - } else { + } else if (ret < 0) + scsi_cdrom_error_common(dev, (ret >> 16) & 0xff, + (ret >> 8) & 0xff, ret & 0xff, info); + else { scsi_cdrom_set_phase(dev, SCSI_PHASE_STATUS); dev->packet_status = PHASE_COMPLETE; dev->callback = 20.0 * CDROM_TIME; @@ -3469,7 +3152,7 @@ scsi_cdrom_command(scsi_common_t *sc, uint8_t *cdb) } } } else - scsi_cdrom_invalid_field(dev); + scsi_cdrom_invalid_field(dev, cdb[7]); } break; @@ -3481,8 +3164,10 @@ scsi_cdrom_command(scsi_common_t *sc, uint8_t *cdb) scsi_cdrom_stop(sc); break; case 1: /* Start the disc and read the TOC. */ - /* This makes no sense under emulation as this would do - absolutely nothing, so just break. */ + /* + This makes no sense under emulation as this would do + absolutely nothing, so just break. + */ break; case 2: /* Eject the disc if possible. */ scsi_cdrom_stop(sc); @@ -3512,11 +3197,15 @@ scsi_cdrom_command(scsi_common_t *sc, uint8_t *cdb) preamble_len = 4; size_idx = 3; - dev->buffer[idx++] = 5; - dev->buffer[idx++] = cdb[2]; - dev->buffer[idx++] = 0; + if ((cdb[1] & 0xe0) || ((dev->cur_lun > 0x00) && (dev->cur_lun < 0xff))) + dev->buffer[idx++] = 0x7f; /* No physical device on this LUN */ + else + dev->buffer[idx++] = 0x05; /* CD-ROM */ - idx++; + dev->buffer[idx++] = cdb[2]; + + dev->buffer[idx++] = 0x00; + dev->buffer[idx++] = 0x00; switch (cdb[2]) { case 0x00: @@ -3525,7 +3214,7 @@ scsi_cdrom_command(scsi_common_t *sc, uint8_t *cdb) break; case 0x83: if (idx + 24 > max_len) { - scsi_cdrom_data_phase_error(dev); + scsi_cdrom_data_phase_error(dev, idx + 24); scsi_cdrom_buf_free(dev); return; } @@ -3533,37 +3222,33 @@ scsi_cdrom_command(scsi_common_t *sc, uint8_t *cdb) dev->buffer[idx++] = 0x02; dev->buffer[idx++] = 0x00; dev->buffer[idx++] = 0x00; - dev->buffer[idx++] = 20; - ide_padstr8(dev->buffer + idx, 20, "53R141"); /* Serial */ + dev->buffer[idx++] = 0x14; + ide_padstr8(dev->buffer + idx, 20, "53R141"); /* Serial */ idx += 20; if (idx + 72 > cdb[4]) goto atapi_out; + dev->buffer[idx++] = 0x02; dev->buffer[idx++] = 0x01; dev->buffer[idx++] = 0x00; - dev->buffer[idx++] = 68; - - if (dev->drv->type == CDROM_TYPE_86BOX_100) - ide_padstr8(dev->buffer + idx, 8, EMU_NAME); /* Vendor */ - else - ide_padstr8(dev->buffer + idx, 8, cdrom_drive_types[dev->drv->type].vendor); /* Vendor */ + dev->buffer[idx++] = 34; + ide_padstr8(dev->buffer + idx, 8, + cdrom_get_vendor(dev->drv->type)); /* Vendor */ idx += 8; - if (dev->drv->type == CDROM_TYPE_86BOX_100) - ide_padstr8(dev->buffer + idx, 40, device_identify_ex); /* Product */ - else - ide_padstr8(dev->buffer + idx, 40, cdrom_drive_types[dev->drv->type].model); /* Product */ + cdrom_get_model(dev->drv->type, model, dev->id); + ide_padstr8(dev->buffer + idx, 16, model); /* Product */ + idx += 16; - idx += 40; - ide_padstr8(dev->buffer + idx, 20, "53R141"); /* Serial */ - idx += 20; + ide_padstr8(dev->buffer + idx, 10, "53R141"); /* Serial */ + idx += 10; break; default: - scsi_cdrom_log("INQUIRY: Invalid page: %02X\n", cdb[2]); - scsi_cdrom_invalid_field(dev); + scsi_cdrom_log(dev->log, "INQUIRY: Invalid page: %02X\n", cdb[2]); + scsi_cdrom_invalid_field(dev, cdb[2]); scsi_cdrom_buf_free(dev); return; } @@ -3575,99 +3260,44 @@ scsi_cdrom_command(scsi_common_t *sc, uint8_t *cdb) if ((cdb[1] & 0xe0) || ((dev->cur_lun > 0x00) && (dev->cur_lun < 0xff))) dev->buffer[0] = 0x7f; /* No physical device on this LUN */ else - dev->buffer[0] = 5; /* CD-ROM */ + dev->buffer[0] = 0x05; /* CD-ROM */ + dev->buffer[1] = 0x80; /* Removable */ if (dev->drv->bus_type == CDROM_BUS_SCSI) { - dev->buffer[3] = 0x02; - switch (dev->drv->type) { - case CDROM_TYPE_CHINON_CDS431_H42: - case CDROM_TYPE_CHINON_CDX435_M62: - case CDROM_TYPE_DEC_RRD45_0436: - case CDROM_TYPE_MATSHITA_501_10b: - case CDROM_TYPE_ShinaKen_DM3x1S_104: - case CDROM_TYPE_SONY_CDU541_10i: - case CDROM_TYPE_TEXEL_DM3024_100: - dev->buffer[2] = 0x00; - dev->buffer[3] = 0x01; /* SCSI-1 compliant */ - break; - case CDROM_TYPE_TEXEL_DM3028_106: - dev->buffer[2] = 0x02; - dev->buffer[3] = 0x01; /* SCSI-2 compliant */ - break; - case CDROM_TYPE_NEC_25_10a: - case CDROM_TYPE_NEC_75_103: - case CDROM_TYPE_NEC_77_106: - dev->buffer[3] = 0x00; /* SCSI unknown version per NEC manuals */ - break; - case CDROM_TYPE_TOSHIBA_XM3201B_3232: - dev->buffer[2] = 0x01; - dev->buffer[3] = 0x01; /* SCSI-1 compliant */ - break; - default: - dev->buffer[2] = 0x02; /* SCSI-2 compliant */ - break; - } + dev->buffer[3] = cdrom_get_scsi_std(dev->drv->type); + + if (!strcmp(cdrom_get_vendor(dev->drv->type), "TOSHIBA")) + /* Linked Command and Relative Addressing supported */ + dev->buffer[7] = 0x88; } else { dev->buffer[2] = 0x00; dev->buffer[3] = 0x21; } - dev->buffer[4] = 31; - if (dev->drv->bus_type == CDROM_BUS_SCSI) { - switch (dev->drv->type) { - case CDROM_TYPE_TOSHIBA_XM_3433 ... CDROM_TYPE_TOSHIBA_XM5701TA_3136: - dev->buffer[4] = 91; /* - Always 91 on Toshiba SCSI-1 (or SCSI-2) - CD-ROM drives from 1989-1990 - */ - dev->buffer[7] = 0x88; /* Linked Command and Relative Addressing supported */ - break; - case CDROM_TYPE_PIONEER_DRM604X_2403: - dev->buffer[4] = 42; - break; - case CDROM_TYPE_NEC_25_10a: - case CDROM_TYPE_NEC_38_103: - case CDROM_TYPE_NEC_75_103: - case CDROM_TYPE_NEC_77_106: - break; - default: - dev->buffer[6] = 0x01; /* 16-bit transfers supported */ - dev->buffer[7] = 0x20; /* Wide bus supported */ - break; - } + if (cdrom_is_generic(dev->drv->type)) { + dev->buffer[6] = 0x01; /* 16-bit transfers supported */ + dev->buffer[7] = 0x20; /* Wide bus supported */ } - if (dev->drv->type == CDROM_TYPE_86BOX_100) { - ide_padstr8(dev->buffer + 8, 8, EMU_NAME); /* Vendor */ - ide_padstr8(dev->buffer + 16, 16, device_identify); /* Product */ - ide_padstr8(dev->buffer + 32, 4, EMU_VERSION_EX); /* Revision */ - } else { - ide_padstr8(dev->buffer + 8, 8, cdrom_drive_types[dev->drv->type].vendor); /* Vendor */ - ide_padstr8(dev->buffer + 16, 16, cdrom_drive_types[dev->drv->type].model); /* Product */ - ide_padstr8(dev->buffer + 32, 4, cdrom_drive_types[dev->drv->type].revision); /* Revision */ - if (dev->drv->type == CDROM_TYPE_PIONEER_DRM604X_2403) { - dev->buffer[36] = 0x20; - ide_padstr8(dev->buffer + 37, 10, "1991/01/01"); /* Date */ - } + ide_padstr8(dev->buffer + 8, 8, + cdrom_get_vendor(dev->drv->type)); /* Vendor */ + cdrom_get_model(dev->drv->type, model, dev->id); + ide_padstr8(dev->buffer + 16, 16, model); /* Product */ + ide_padstr8(dev->buffer + 32, 4, + cdrom_get_revision(dev->drv->type)); /* Revision */ + + if (cdrom_has_date(dev->drv->type)) { + dev->buffer[36] = 0x20; + ide_padstr8(dev->buffer + 37, 10, "1991/01/01"); /* Date */ } - idx = 36; - if (dev->drv->type == CDROM_TYPE_PIONEER_DRM604X_2403) - idx = 47; - else { - switch (dev->drv->type) { - case CDROM_TYPE_TOSHIBA_XM_3433 ... CDROM_TYPE_TOSHIBA_XM5701TA_3136: - idx = 96; - break; - default: - if (max_len == 96) { - dev->buffer[4] = 91; - idx = 96; - } - break; - } - } + if (max_len == 96) + idx = 96; + else + idx = cdrom_get_inquiry_len(dev->drv->bus_type); + + dev->buffer[4] = idx - 5; } atapi_out: @@ -3677,7 +3307,8 @@ atapi_out: len = MIN(len, max_len); scsi_cdrom_set_buf_len(dev, BufLen, &max_len); - scsi_cdrom_log("Inquiry = %d, max = %d, BufLen = %d.\n", len, max_len, *BufLen); + scsi_cdrom_log(dev->log, "Inquiry = %d, max = %d, BufLen = %d.\n", len, + max_len, *BufLen); scsi_cdrom_data_command_finish(dev, len, len, max_len, 0); break; @@ -3712,17 +3343,12 @@ atapi_out: dev->drv->seek_diff = ABS((int) (pos - dev->drv->seek_pos)); - if (cdb[0] == GPCMD_SEEK_10) { - switch (dev->drv->type) { - case CDROM_TYPE_NEC_25_10a ... CDROM_TYPE_NEC_464_105: - case CDROM_TYPE_TOSHIBA_XM_3433 ... CDROM_TYPE_TOSHIBA_SDM1401_1008: - cdrom_seek(dev->drv, pos, cdb[9] & 0xc0); - break; - default: - cdrom_seek(dev->drv, pos, 0); - break; - } - } else + /* Stop the audio playing. */ + cdrom_stop(dev->drv); + + if (dev->use_cdb_9 && (cdb[0] == GPCMD_SEEK_10)) + cdrom_seek(dev->drv, pos, cdb[9] & 0xc0); + else cdrom_seek(dev->drv, pos, 0); scsi_cdrom_command_complete(dev); @@ -3742,7 +3368,8 @@ atapi_out: dev->buffer[6] = 8; len = 8; - scsi_cdrom_log("CD-ROM Capacity=%x.\n", dev->drv->cdrom_capacity - 1); + scsi_cdrom_log(dev->log, "CD-ROM Capacity: %08X\n", + dev->drv->cdrom_capacity - 1); scsi_cdrom_set_buf_len(dev, BufLen, &len); scsi_cdrom_data_command_finish(dev, len, len, len, 0); @@ -3751,7 +3378,7 @@ atapi_out: case GPCMD_STOP_PLAY_SCAN: scsi_cdrom_set_phase(dev, SCSI_PHASE_STATUS); - if (dev->drv->cd_status <= CD_STATUS_DATA_ONLY) { + if (dev->drv->cd_status <= CD_STATUS_DVD) { scsi_cdrom_illegal_mode(dev); break; } @@ -3761,11 +3388,11 @@ atapi_out: break; default: - scsi_cdrom_illegal_opcode(dev); + scsi_cdrom_illegal_opcode(dev, cdb[0]); break; } - /* scsi_cdrom_log("CD-ROM %i: Phase: %02X, request length: %i\n", dev->tf->phase, + /* scsi_cdrom_log(dev->log, "Phase: %02X, request length: %i\n", dev->tf->phase, dev->tf->request_length); */ if ((dev->packet_status == PHASE_COMPLETE) || (dev->packet_status == PHASE_ERROR)) @@ -3789,15 +3416,14 @@ scsi_cdrom_phase_data_out(scsi_common_t *sc) uint16_t block_desc_len; uint16_t pos; uint16_t param_list_len; - uint16_t i = 0; - - uint8_t error = 0; - uint8_t page; - uint8_t page_len; - uint8_t hdr_len; - uint8_t val; - uint8_t old_val; - uint8_t ch; + uint16_t i; + uint8_t error = 0; + uint8_t page; + uint8_t page_len; + uint8_t hdr_len; + uint8_t val; + uint8_t old_val; + uint8_t ch; switch (dev->current_cdb[0]) { case GPCMD_MODE_SELECT_6: @@ -3817,7 +3443,8 @@ scsi_cdrom_phase_data_out(scsi_common_t *sc) block_desc_len = dev->buffer[2]; block_desc_len <<= 8; block_desc_len |= dev->buffer[3]; - scsi_cdrom_log("BlockDescLen (6)=%d, ParamListLen (6)=%d.\n", block_desc_len, param_list_len); + scsi_cdrom_log(dev->log, "BlockDescLen (6): %d, " + "ParamListLen (6): %d\n", block_desc_len, param_list_len); } else { block_desc_len = dev->buffer[6]; block_desc_len <<= 8; @@ -3829,21 +3456,28 @@ scsi_cdrom_phase_data_out(scsi_common_t *sc) if (block_desc_len >= 8) { pos = hdr_len + 5; - dev->drv->sector_size = (dev->drv->sector_size & 0x0000ffff) | (dev->buffer[pos++] << 16); - dev->drv->sector_size = (dev->drv->sector_size & 0x00ff00ff) | (dev->buffer[pos++] << 8); - dev->drv->sector_size = (dev->drv->sector_size & 0x00ffff00) | (dev->buffer[pos++]); - scsi_cdrom_log("CD-ROM %i: Sector size now %i bytes\n", dev->id, dev->drv->sector_size); + dev->drv->sector_size = (dev->drv->sector_size & 0x0000ffff) | + (dev->buffer[pos++] << 16); + dev->drv->sector_size = (dev->drv->sector_size & 0x00ff00ff) | + (dev->buffer[pos++] << 8); + dev->drv->sector_size = (dev->drv->sector_size & 0x00ffff00) | + (dev->buffer[pos]); + scsi_cdrom_log(dev->log, "Sector size now %i bytes\n", + dev->drv->sector_size); + + error |= scsi_cdrom_update_sector_flags(dev); } pos = hdr_len + block_desc_len; #ifdef ENABLE_SCSI_CDROM_LOG for (uint16_t j = 0; j < pos; j++) - scsi_cdrom_log("Buffer Mode Select, pos=%d, data=%02x.\n", j, dev->buffer[j]); + scsi_cdrom_log(dev->log, "Buffer Mode Select, pos=%d, data=%02x.\n", + j, dev->buffer[j]); #endif - while (1) { + if (!error) while (1) { if (pos >= param_list_len) { - scsi_cdrom_log("CD-ROM %i: Buffer has only block descriptor\n", dev->id); + scsi_cdrom_log(dev->log, "Buffer has only block descriptor\n"); break; } @@ -3852,71 +3486,39 @@ scsi_cdrom_phase_data_out(scsi_common_t *sc) pos += 2; - switch (dev->drv->type) { - case CDROM_TYPE_DEC_RRD45_0436: - case CDROM_TYPE_ShinaKen_DM3x1S_104 ... CDROM_TYPE_SONY_CDU76S_100: - case CDROM_TYPE_TEXEL_DM3024_100 ... CDROM_TYPE_TEXEL_DM3028_106: - if ((page == 0x08) && (page_len == 0x02)) - dev->drv->sony_msf = dev->buffer[pos] & 0x01; + if (dev->is_sony && (page == 0x08) && (page_len == 0x02)) + dev->drv->sony_msf = dev->buffer[pos] & 0x01; - if (!(scsi_cdrom_mode_sense_page_flags_sony & (1LL << ((uint64_t) page)))) { - scsi_cdrom_log("CD-ROM %i: Unimplemented page %02X\n", dev->id, page); - error |= 1; - } else { - for (i = 0; i < page_len; i++) { - ch = scsi_cdrom_mode_sense_pages_changeable_sony.pages[page][i + 2]; - val = dev->buffer[pos + i]; - old_val = dev->ms_pages_saved_sony.pages[page][i + 2]; - if (val != old_val) { - if (ch) - dev->ms_pages_saved_sony.pages[page][i + 2] = val; - else { - scsi_cdrom_log("CD-ROM %i: Unchangeable value on position " - "%02X on page %02X\n", dev->id, i + 2, page); - error |= 1; - } - } + if (!(dev->ms_page_flags & (1LL << ((uint64_t) page)))) { + scsi_cdrom_log(dev->log, "Unimplemented page %02X\n", page); + error |= 1; + } else { + for (i = 0; i < page_len; i++) { + uint8_t pg = page; + + if (dev->is_sony && (page == GPMODE_CDROM_AUDIO_PAGE_SONY) && (i >= 6) && (i <= 13)) + pg = GPMODE_CDROM_AUDIO_PAGE; + + ch = dev->ms_pages_changeable.pages[pg][i + 2]; + val = dev->buffer[pos + i]; + old_val = dev->ms_pages_saved.pages[pg][i + 2]; + if (val != old_val) { + if (ch) + dev->ms_pages_saved.pages[pg][i + 2] = val; + else { + scsi_cdrom_log(dev->log, "Unchangeable value on position " + "%02X on page %02X\n", i + 2, page); + scsi_cdrom_invalid_field_pl(dev, val); + error |= 1; } } - break; - default: - if (!(scsi_cdrom_mode_sense_page_flags & (1LL << ((uint64_t) page)))) { - scsi_cdrom_log("CD-ROM %i: Unimplemented page %02X\n", dev->id, page); - error |= 1; - } else { - for (i = 0; i < page_len; i++) { - ch = scsi_cdrom_mode_sense_pages_changeable.pages[page][i + 2]; - val = dev->buffer[pos + i]; - old_val = dev->ms_pages_saved.pages[page][i + 2]; - if (val != old_val) { - if (ch) - dev->ms_pages_saved.pages[page][i + 2] = val; - else { - scsi_cdrom_log("CD-ROM %i: Unchangeable value on position " - "%02X on page %02X\n", dev->id, i + 2, page); - error |= 1; - } - } - } - } - break; + } } pos += page_len; - switch (dev->drv->type) { - case CDROM_TYPE_DEC_RRD45_0436: - case CDROM_TYPE_ShinaKen_DM3x1S_104 ... CDROM_TYPE_SONY_CDU76S_100: - case CDROM_TYPE_TEXEL_DM3024_100 ... CDROM_TYPE_TEXEL_DM3028_106: - val = scsi_cdrom_mode_sense_pages_default_sony_scsi.pages[page][0] & 0x80; - break; - default: - if (dev->drv->bus_type == CDROM_BUS_SCSI) - val = scsi_cdrom_mode_sense_pages_default_scsi.pages[page][0] & 0x80; - else - val = scsi_cdrom_mode_sense_pages_default.pages[page][0] & 0x80; - break; - } + val = dev->ms_pages_default.pages[page][0] & 0x80; + if (dev->do_page_save && val) scsi_cdrom_mode_sense_save(dev); @@ -3925,21 +3527,20 @@ scsi_cdrom_phase_data_out(scsi_common_t *sc) } if (error) { - scsi_cdrom_invalid_field_pl(dev); scsi_cdrom_buf_free(dev); return 0; } break; - case 0xC9: - switch (dev->drv->type) { - case CDROM_TYPE_DEC_RRD45_0436: - case CDROM_TYPE_ShinaKen_DM3x1S_104 ... CDROM_TYPE_SONY_CDU76S_100: - case CDROM_TYPE_TEXEL_DM3024_100 ... CDROM_TYPE_TEXEL_DM3028_106: - for (i = 0; i < 18; i++) - dev->ms_pages_saved_sony.pages[GPMODE_CDROM_AUDIO_PAGE_SONY][i] = dev->buffer[i]; - break; - default: - break; + case 0xc9: + if (dev->is_sony) { + for (i = 0; i < 18; i++) { + if ((i >= 8) && (i <= 15)) + dev->ms_pages_saved.pages[GPMODE_CDROM_AUDIO_PAGE][i] = + dev->buffer[i]; + else + dev->ms_pages_saved.pages[GPMODE_CDROM_AUDIO_PAGE_SONY][i] = + dev->buffer[i]; + } } break; @@ -3956,30 +3557,31 @@ scsi_cdrom_close(void *priv) { scsi_cdrom_t *dev = (scsi_cdrom_t *) priv; - if (dev->tf) - free(dev->tf); + if (dev != NULL) { + if (dev->tf != NULL) + free(dev->tf); + + if (dev->log != NULL) { + scsi_cdrom_log(dev->log, "Log closed\n"); + + log_close(dev->log); + dev->log = NULL; + } - if (dev) free(dev); + } } static int -scsi_cdrom_get_max(int ide_has_dma, int type) +scsi_cdrom_get_max(const ide_t *ide, UNUSED(const int ide_has_dma), const int type) { - int ret; + const scsi_cdrom_t *dev = (scsi_cdrom_t *) ide->sc; + int ret; switch (type) { - case TYPE_PIO: - ret = ide_has_dma ? 4 : 0; - break; - case TYPE_SDMA: - ret = ide_has_dma ? 2 : -1; - break; - case TYPE_MDMA: - ret = ide_has_dma ? 2 : -1; - break; - case TYPE_UDMA: - ret = ide_has_dma ? 5 : -1; + case TYPE_PIO: case TYPE_SDMA: + case TYPE_MDMA: case TYPE_UDMA: + ret = cdrom_get_transfer_max(dev->drv->type, type); break; default: ret = -1; @@ -3990,16 +3592,18 @@ scsi_cdrom_get_max(int ide_has_dma, int type) } static int -scsi_cdrom_get_timings(int ide_has_dma, int type) +scsi_cdrom_get_timings(const ide_t *ide, UNUSED(const int ide_has_dma), const int type) { - int ret; + const scsi_cdrom_t *dev = (scsi_cdrom_t *) ide->sc; + int has_dma = cdrom_has_dma(dev->drv->type); + int ret; switch (type) { case TIMINGS_DMA: - ret = ide_has_dma ? 120 : 0; + ret = has_dma ? 120 : 0; break; case TIMINGS_PIO: - ret = ide_has_dma ? 120 : 0; + ret = has_dma ? 120 : 0; break; case TIMINGS_PIO_FC: ret = 0; @@ -4016,194 +3620,29 @@ scsi_cdrom_get_timings(int ide_has_dma, int type) * Fill in ide->buffer with the output of the "IDENTIFY PACKET DEVICE" command */ static void -scsi_cdrom_identify(ide_t *ide, int ide_has_dma) +scsi_cdrom_identify(const ide_t *ide, UNUSED(const int ide_has_dma)) { - const scsi_cdrom_t *dev; - char device_identify[9] = { '8', '6', 'B', '_', 'C', 'D', '0', '0', 0 }; + const scsi_cdrom_t *dev = (scsi_cdrom_t *) ide->sc; + char model[2048] = { 0 }; + const int has_dma = cdrom_has_dma(dev->drv->type); - dev = (scsi_cdrom_t *) ide->sc; + cdrom_get_identify_model(dev->drv->type, model, dev->id); - device_identify[7] = dev->id + 0x30; - scsi_cdrom_log("ATAPI Identify: %s\n", device_identify); + scsi_cdrom_log(dev->log, "ATAPI Identify: %s\n", model); - if ((dev->drv->type == CDROM_TYPE_NEC_260_100) || (dev->drv->type == CDROM_TYPE_NEC_260_101)) /*NEC only*/ + if (dev->drv->is_early) ide->buffer[0] = 0x8000 | (5 << 8) | 0x80 | (1 << 5); /* ATAPI device, CD-ROM drive, removable media, interrupt DRQ */ else 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 */ + ide_padstr((char *) (ide->buffer + 10), "", 20); /* Serial Number */ - if (dev->drv->type == CDROM_TYPE_86BOX_100) { - ide_padstr((char *) (ide->buffer + 23), EMU_VERSION_EX, 8); /* Firmware */ - ide_padstr((char *) (ide->buffer + 27), device_identify, 40); /* Model */ - } else { - switch (dev->drv->type) { - case CDROM_TYPE_ASUS_CDS500_141: - ide_padstr((char *) (ide->buffer + 23), "1.41 ", 8); /* Firmware */ - ide_padstr((char *) (ide->buffer + 27), "ASUS CD-S500/A ", 40); /* Model */ - break; - case CDROM_TYPE_ASUS_CDS520_132: - ide_padstr((char *) (ide->buffer + 23), "1.32 ", 8); /* Firmware */ - ide_padstr((char *) (ide->buffer + 27), "ASUS CD-S520/A4 ", 40); /* Model */ - break; - case CDROM_TYPE_AZT_CDA46802I_115: - ide_padstr((char *) (ide->buffer + 23), "1.15 ", 8); /* Firmware */ - ide_padstr((char *) (ide->buffer + 27), "AZT CDA46802I ", 40); /* Model */ - break; - case CDROM_TYPE_BTC_BCD36XH_U10: - ide_padstr((char *) (ide->buffer + 23), "U1.0 ", 8); /* Firmware */ - ide_padstr((char *) (ide->buffer + 27), "BTC CD-ROM BCD36XH ", 40); /* Model */ - break; - case CDROM_TYPE_GOLDSTAR_CRD_8160B_314: - ide_padstr((char *) (ide->buffer + 23), "3.14 ", 8); /* Firmware */ - ide_padstr((char *) (ide->buffer + 27), "GOLDSTAR CRD-8160B ", 40); /* Model */ - break; - case CDROM_TYPE_HITACHI_CDR_8130_0020: - ide_padstr((char *) (ide->buffer + 23), "0020 ", 8); /* Firmware */ - ide_padstr((char *) (ide->buffer + 27), "HITACHI CDR-8130 ", 40); /* Model */ - break; - case CDROM_TYPE_HITACHI_GD7500_A1: - ide_padstr((char *) (ide->buffer + 23), "A1 ", 8); /* Firmware */ - ide_padstr((char *) (ide->buffer + 27), "HITACHI GD-7500 ", 40); /* Model */ - break; - case CDROM_TYPE_HLDTST_GCR8526B_101: - ide_padstr((char *) (ide->buffer + 23), "1.01 ", 8); /* Firmware */ - ide_padstr((char *) (ide->buffer + 27), "HL-DT-ST CD-ROM GCR-8526B ", 40); /* Model */ - break; - case CDROM_TYPE_HLDTST_GSA4160_A302: - ide_padstr((char *) (ide->buffer + 23), "A302 ", 8); /* Firmware */ - ide_padstr((char *) (ide->buffer + 27), "HL-DT-ST DVDRAM GSA-4160 ", 40); /* Model */ - break; - case CDROM_TYPE_KENWOOD_UCR_421_208E: - ide_padstr((char *) (ide->buffer + 23), "208E ", 8); /* Firmware */ - ide_padstr((char *) (ide->buffer + 27), "KENWOOD CD-ROM UCR-421 ", 40); /* Model */ - break; - case CDROM_TYPE_LG_CRN8245B_130: - ide_padstr((char *) (ide->buffer + 23), "1.30 ", 8); /* Firmware */ - ide_padstr((char *) (ide->buffer + 27), "LG CD-ROM CRN-8245B ", 40); /* Model */ - break; - case CDROM_TYPE_LG_CRD8322B_106: - ide_padstr((char *) (ide->buffer + 23), "1.06 ", 8); /* Firmware */ - ide_padstr((char *) (ide->buffer + 27), "LG CD-ROM CRD-8322B ", 40); /* Model */ - break; - case CDROM_TYPE_LTN48125S_1S07: - ide_padstr((char *) (ide->buffer + 23), "1S07 ", 8); /* Firmware */ - ide_padstr((char *) (ide->buffer + 27), "LTN48125S ", 40); /* Model */ - break; - case CDROM_TYPE_LTN526D_YSR5: - ide_padstr((char *) (ide->buffer + 23), "YSR5 ", 8); /* Firmware */ - ide_padstr((char *) (ide->buffer + 27), "LTN526D ", 40); /* Model */ - break; - case CDROM_TYPE_MATSHITA_583_107: - ide_padstr((char *) (ide->buffer + 23), "1.07 ", 8); /* Firmware */ - ide_padstr((char *) (ide->buffer + 27), "MATSHITA CD-ROM CR-583 ", 40); /* Model */ - break; - case CDROM_TYPE_MATSHITA_585_Z18P: - ide_padstr((char *) (ide->buffer + 23), "Z18P ", 8); /* Firmware */ - ide_padstr((char *) (ide->buffer + 27), "MATSHITA CD-ROM CR-585 ", 40); /* Model */ - break; - case CDROM_TYPE_MATSHITA_587_7S13: - ide_padstr((char *) (ide->buffer + 23), "7S13 ", 8); /* Firmware */ - ide_padstr((char *) (ide->buffer + 27), "MATSHITA CD-ROM CR-587 ", 40); /* Model */ - break; - case CDROM_TYPE_MATSHITA_588_LS15: - ide_padstr((char *) (ide->buffer + 23), "LS15 ", 8); /* Firmware */ - ide_padstr((char *) (ide->buffer + 27), "MATSHITA CD-ROM CR-588 ", 40); /* Model */ - break; - case CDROM_TYPE_MATSHITA_571_10e: - ide_padstr((char *) (ide->buffer + 23), "1.0e ", 8); /* Firmware */ - ide_padstr((char *) (ide->buffer + 27), "MATSHITA CR-571 ", 40); /* Model */ - break; - case CDROM_TYPE_MATSHITA_572_10j: - ide_padstr((char *) (ide->buffer + 23), "1.0j ", 8); /* Firmware */ - ide_padstr((char *) (ide->buffer + 27), "MATSHITA CR-572 ", 40); /* Model */ - break; - case CDROM_TYPE_MITSUMI_FX4820T_D02A: - ide_padstr((char *) (ide->buffer + 23), "D02A ", 8); /* Firmware */ - ide_padstr((char *) (ide->buffer + 27), "MITSUMI CRMC-FX4820T ", 40); /* Model */ - break; - case CDROM_TYPE_NEC_260_100: - ide_padstr((char *) (ide->buffer + 23), ".100 ", 8); /* Firmware */ - ide_padstr((char *) (ide->buffer + 27), "EN C DCR-MOD IREV2:06 ", 40); /* Model */ - break; - case CDROM_TYPE_NEC_260_101: - ide_padstr((char *) (ide->buffer + 23), ".110 ", 8); /* Firmware */ - ide_padstr((char *) (ide->buffer + 27), "EN C DCR-MOD IREV2:06 ", 40); /* Model */ - break; - case CDROM_TYPE_NEC_273_420: - ide_padstr((char *) (ide->buffer + 23), "4.20 ", 8); /* Firmware */ - ide_padstr((char *) (ide->buffer + 27), "NEC CD-ROM DRIVE:273 ", 40); /* Model */ - break; - case CDROM_TYPE_NEC_280_105: - ide_padstr((char *) (ide->buffer + 23), "1.05 ", 8); /* Firmware */ - ide_padstr((char *) (ide->buffer + 27), "NEC CD-ROM DRIVE:280 ", 40); /* Model */ - break; - case CDROM_TYPE_NEC_280_308: - ide_padstr((char *) (ide->buffer + 23), "3.08 ", 8); /* Firmware */ - ide_padstr((char *) (ide->buffer + 27), "NEC CD-ROM DRIVE:280 ", 40); /* Model */ - break; - case CDROM_TYPE_NEC_CDR_1900A_100: - ide_padstr((char *) (ide->buffer + 23), "1.00 ", 8); /* Firmware */ - ide_padstr((char *) (ide->buffer + 27), "NEC CDR-1900A ", 40); /* Model */ - break; - case CDROM_TYPE_PHILIPS_PCA403CD_U31P: - ide_padstr((char *) (ide->buffer + 23), "U31P ", 8); /* Firmware */ - ide_padstr((char *) (ide->buffer + 27), "PHILIPS CD-ROM PCA403CD ", 40); /* Model */ - break; - case CDROM_TYPE_SONY_CDU76_10i: - ide_padstr((char *) (ide->buffer + 23), "1.0i ", 8); /* Firmware */ - ide_padstr((char *) (ide->buffer + 27), "SONY CD-ROM CDU76 ", 40); /* Model */ - break; - case CDROM_TYPE_SONY_CDU311_30h: - ide_padstr((char *) (ide->buffer + 23), "3.0h ", 8); /* Firmware */ - ide_padstr((char *) (ide->buffer + 27), "SONY CD-ROM CDU311 ", 40); /* Model */ - break; - case CDROM_TYPE_SONY_CDU5225_NYS4: - ide_padstr((char *) (ide->buffer + 23), "NYS4 ", 8); /* Firmware */ - ide_padstr((char *) (ide->buffer + 27), "SONY CD-ROM CDU5225 ", 40); /* Model */ - break; - case CDROM_TYPE_TEAC_CD516E_10G: - ide_padstr((char *) (ide->buffer + 23), "1.0G ", 8); /* Firmware */ - ide_padstr((char *) (ide->buffer + 27), "TEAC CD-516E ", 40); /* Model */ - break; - case CDROM_TYPE_TEAC_CD524EA_30D: - ide_padstr((char *) (ide->buffer + 23), "3.0D ", 8); /* Firmware */ - ide_padstr((char *) (ide->buffer + 27), "TEAC CD-524EA ", 40); /* Model */ - break; - case CDROM_TYPE_TEAC_CD532E_20A: - ide_padstr((char *) (ide->buffer + 23), "2.0A ", 8); /* Firmware */ - ide_padstr((char *) (ide->buffer + 27), "TEAC CD-532E ", 40); /* Model */ - break; - case CDROM_TYPE_TOSHIBA_5302TA_0305: - ide_padstr((char *) (ide->buffer + 23), "0305 ", 8); /* Firmware */ - ide_padstr((char *) (ide->buffer + 27), "TOSHIBA CD-ROM XM-5302TA ", 40); /* Model */ - break; - case CDROM_TYPE_TOSHIBA_5702B_TA70: - ide_padstr((char *) (ide->buffer + 23), "TA70 ", 8); /* Firmware */ - ide_padstr((char *) (ide->buffer + 27), "TOSHIBA CD-ROM XM-5702B ", 40); /* Model */ - break; - case CDROM_TYPE_TOSHIBA_6202B_1512: - ide_padstr((char *) (ide->buffer + 23), "1512 ", 8); /* Firmware */ - ide_padstr((char *) (ide->buffer + 27), "TOSHIBA CD-ROM XM-6202B ", 40); /* Model */ - break; - case CDROM_TYPE_TOSHIBA_6402B_1008: - ide_padstr((char *) (ide->buffer + 23), "1008 ", 8); /* Firmware */ - ide_padstr((char *) (ide->buffer + 27), "TOSHIBA CD-ROM XM-6402B ", 40); /* Model */ - break; - case CDROM_TYPE_TOSHIBA_6702B_1007: - ide_padstr((char *) (ide->buffer + 23), "1007 ", 8); /* Firmware */ - ide_padstr((char *) (ide->buffer + 27), "TOSHIBA CD-ROM XM-6702B ", 40); /* Model */ - break; - case CDROM_TYPE_TOSHIBA_M1802_1051: - ide_padstr((char *) (ide->buffer + 23), "1051 ", 8); /* Firmware */ - ide_padstr((char *) (ide->buffer + 27), "TOSHIBA DVD-ROM SD-M1802 ", 40); /* Model */ - break; - } - } + ide_padstr((char *) (ide->buffer + 23), cdrom_get_revision(dev->drv->type), 8); /* Firmware */ + ide_padstr((char *) (ide->buffer + 27), model, 40); /* Model */ ide->buffer[49] = 0x200; /* LBA supported */ ide->buffer[126] = 0xfffe; /* Interpret zero byte count limit as maximum length */ - if (ide_has_dma) { + if (has_dma) { ide->buffer[71] = 30; ide->buffer[72] = 30; ide->buffer[80] = 0x7e; /*ATA-1 to ATA-6 supported*/ @@ -4212,14 +3651,11 @@ scsi_cdrom_identify(ide_t *ide, int ide_has_dma) } void -scsi_cdrom_drive_reset(int c) +scsi_cdrom_drive_reset(const int c) { cdrom_t *drv = &cdrom[c]; - scsi_cdrom_t *dev; - scsi_device_t *sd; - ide_t *id; - uint8_t scsi_bus = (drv->scsi_device_id >> 4) & 0x0f; - uint8_t scsi_id = drv->scsi_device_id & 0x0f; + const uint8_t scsi_bus = (drv->scsi_device_id >> 4) & 0x0f; + const uint8_t scsi_id = drv->scsi_device_id & 0x0f; uint8_t valid = 0; if (drv->bus_type == CDROM_BUS_SCSI) { @@ -4236,12 +3672,17 @@ scsi_cdrom_drive_reset(int c) if ((drv->bus_type == CDROM_BUS_ATAPI) && (drv->ide_channel > 7)) return; - if (!drv->priv) { - drv->priv = (scsi_cdrom_t *) malloc(sizeof(scsi_cdrom_t)); - memset(drv->priv, 0, sizeof(scsi_cdrom_t)); + if (drv->priv == NULL) { + drv->priv = (scsi_cdrom_t *) calloc(1, sizeof(scsi_cdrom_t)); + scsi_cdrom_t *dev = (scsi_cdrom_t *) drv->priv; + + char n[1024] = { 0 }; + + sprintf(n, "CD-ROM %i SCSI ", c + 1); + dev->log = log_open(n); } - dev = (scsi_cdrom_t *) drv->priv; + scsi_cdrom_t *dev = (scsi_cdrom_t *) drv->priv; dev->id = c; dev->drv = drv; @@ -4254,80 +3695,106 @@ scsi_cdrom_drive_reset(int c) drv->close = scsi_cdrom_close; drv->sector_size = 2048; + (void) scsi_cdrom_update_sector_flags(dev); if (drv->bus_type == CDROM_BUS_SCSI) { - valid = 1; + char *vendor = cdrom_get_vendor(dev->drv->type); - if (!dev->tf) - dev->tf = (ide_tf_t *) calloc(1, sizeof(ide_tf_t)); + dev->ven_cmd = NULL; + memset(dev->ven_cmd_is_data, 0x00, sizeof(dev->ven_cmd_is_data)); + dev->is_sony = 0; + dev->use_cdb_9 = 0; + dev->ms_page_flags = scsi_cdrom_ms_page_flags_scsi; + dev->ms_pages_default = scsi_cdrom_ms_pages_default_scsi; + dev->ms_pages_changeable = scsi_cdrom_ms_pages_changeable_scsi; + + if (!strcmp(vendor, "CHINON")) + dev->ven_cmd = scsi_cdrom_command_chinon; + else if (!strcmp(vendor, "DEC") || !strcmp(vendor, "ShinaKen") || + !strcmp(vendor, "SONY") || !strcmp(vendor, "TEXEL")) { + dev->ven_cmd = scsi_cdrom_command_dec_sony_texel; + dev->ven_cmd_is_data[0xc0] = 1; + dev->ven_cmd_is_data[0xc1] = 1; + dev->ven_cmd_is_data[0xc2] = 1; + dev->ven_cmd_is_data[0xc3] = 1; + dev->is_sony = 1; + dev->ms_page_flags = scsi_cdrom_ms_page_flags_sony_scsi; + dev->ms_pages_default = scsi_cdrom_ms_pages_default_sony_scsi; + dev->ms_pages_changeable = scsi_cdrom_ms_pages_changeable_sony_scsi; + } else if (!strcmp(vendor, "MATSHITA")) + dev->ven_cmd = scsi_cdrom_command_matsushita; + else if (!strcmp(vendor, "NEC")) { + dev->ven_cmd = scsi_cdrom_command_nec; + dev->ven_cmd_is_data[0xdd] = 1; + dev->ven_cmd_is_data[0xde] = 1; + } else if (!strcmp(vendor, "PIONEER")) { + dev->ven_cmd = scsi_cdrom_command_pioneer; + dev->ven_cmd_is_data[0xc1] = 1; + dev->ven_cmd_is_data[0xc2] = 1; + dev->ven_cmd_is_data[0xc3] = 1; + } else if (!strcmp(vendor, "TOSHIBA")) { + dev->ven_cmd = scsi_cdrom_command_toshiba; + dev->ven_cmd_is_data[0xc6] = 1; + dev->ven_cmd_is_data[0xc7] = 1; + dev->use_cdb_9 = 1; + } + + if (dev->tf == NULL) + dev->tf = (ide_tf_t *) calloc(1, sizeof(ide_tf_t)); /* SCSI CD-ROM, attach to the SCSI bus. */ - sd = &scsi_devices[scsi_bus][scsi_id]; + scsi_device_t *sd = &scsi_devices[scsi_bus][scsi_id]; - sd->sc = (scsi_common_t *) dev; - sd->command = scsi_cdrom_command; - sd->request_sense = scsi_cdrom_request_sense_for_scsi; - sd->reset = scsi_cdrom_reset; - sd->phase_data_out = scsi_cdrom_phase_data_out; - sd->command_stop = scsi_cdrom_command_stop; - sd->type = SCSI_REMOVABLE_CDROM; + sd->sc = (scsi_common_t *) dev; + sd->command = scsi_cdrom_command; + sd->request_sense = scsi_cdrom_request_sense_for_scsi; + sd->reset = scsi_cdrom_reset; + sd->phase_data_out = scsi_cdrom_phase_data_out; + sd->command_stop = scsi_cdrom_command_stop; + sd->type = SCSI_REMOVABLE_CDROM; - scsi_cdrom_log("SCSI CD-ROM drive %i attached to SCSI ID %i\n", c, cdrom[c].scsi_device_id); + valid = 1; + + scsi_cdrom_log(dev->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_get_drive(drv->ide_channel); - /* If the IDE channel is initialized, we attach to it, - otherwise, we do nothing - it's going to be a drive - that's not attached to anything. */ - if (id) { - valid = 1; + ide_t *id = ide_get_drive(drv->ide_channel); - id->sc = (scsi_common_t *) dev; - dev->tf = id->tf; - if ((dev->drv->type == CDROM_TYPE_NEC_260_100) || (dev->drv->type == CDROM_TYPE_NEC_260_101)) - IDE_ATAPI_IS_EARLY = 1; - id->get_max = scsi_cdrom_get_max; - id->get_timings = scsi_cdrom_get_timings; - id->identify = scsi_cdrom_identify; - id->stop = scsi_cdrom_stop; - id->packet_command = scsi_cdrom_command; - id->device_reset = scsi_cdrom_reset; - id->phase_data_out = scsi_cdrom_phase_data_out; - id->command_stop = scsi_cdrom_command_stop; - id->bus_master_error = scsi_cdrom_bus_master_error; - id->interrupt_drq = ((dev->drv->type == CDROM_TYPE_NEC_260_100) || - (dev->drv->type == CDROM_TYPE_NEC_260_101)); + /* + If the IDE channel is initialized, we attach to it, otherwise, we do + nothing - it's going to be a drive that's not attached to anything. + */ + if (id) { + dev->ven_cmd = NULL; + memset(dev->ven_cmd_is_data, 0x00, sizeof(dev->ven_cmd_is_data)); + dev->is_sony = 0; + dev->use_cdb_9 = 0; + dev->ms_page_flags = scsi_cdrom_ms_page_flags; + dev->ms_pages_default = scsi_cdrom_ms_pages_default; + dev->ms_pages_changeable = scsi_cdrom_ms_pages_changeable; + + id->sc = (scsi_common_t *) dev; + dev->tf = id->tf; + IDE_ATAPI_IS_EARLY = dev->drv->is_early; + id->get_max = scsi_cdrom_get_max; + id->get_timings = scsi_cdrom_get_timings; + id->identify = scsi_cdrom_identify; + id->stop = scsi_cdrom_stop; + id->packet_command = scsi_cdrom_command; + id->device_reset = scsi_cdrom_reset; + id->phase_data_out = scsi_cdrom_phase_data_out; + id->command_stop = scsi_cdrom_command_stop; + id->bus_master_error = scsi_cdrom_bus_master_error; + id->interrupt_drq = dev->drv->is_early; + + valid = 1; ide_atapi_attach(id); } - scsi_cdrom_log("ATAPI CD-ROM drive %i attached to IDE channel %i\n", c, cdrom[c].ide_channel); - } - - switch (dev->drv->type) { - case CDROM_TYPE_CHINON_CDS431_H42: - dev->ven_cmd = scsi_cdrom_command_chinon; - break; - case CDROM_TYPE_DEC_RRD45_0436: - case CDROM_TYPE_ShinaKen_DM3x1S_104 ... CDROM_TYPE_SONY_CDU76S_100: - case CDROM_TYPE_TEXEL_DM3024_100 ... CDROM_TYPE_TEXEL_DM3028_106: - dev->ven_cmd = scsi_cdrom_command_dec_sony_texel; - break; - case CDROM_TYPE_MATSHITA_501_10b: - dev->ven_cmd = scsi_cdrom_command_matsushita; - break; - case CDROM_TYPE_NEC_25_10a ... CDROM_TYPE_NEC_464_105: - dev->ven_cmd = scsi_cdrom_command_nec; - break; - case CDROM_TYPE_PIONEER_DRM604X_2403: - dev->ven_cmd = scsi_cdrom_command_pioneer; - break; - case CDROM_TYPE_TOSHIBA_XM_3433 ... CDROM_TYPE_TOSHIBA_SDM1401_1008: - dev->ven_cmd = scsi_cdrom_command_toshiba; - break; - default: - dev->ven_cmd = NULL; - break; + scsi_cdrom_log(dev->log, "ATAPI CD-ROM drive %i attached to IDE channel %i\n", + c, cdrom[c].ide_channel); } if (valid) diff --git a/src/scsi/scsi_device.c b/src/scsi/scsi_device.c index 4442b2680..33d3fa89a 100644 --- a/src/scsi/scsi_device.c +++ b/src/scsi/scsi_device.c @@ -16,10 +16,14 @@ * Copyright 2016-2018 Miran Grca. * Copyright 2017-2018 Fred N. van Kempen. */ +#include #include #include #include +#include +#include #include +#define HAVE_STDARG_H #include <86box/86box.h> #include <86box/device.h> #include <86box/hdd.h> @@ -29,9 +33,29 @@ #include <86box/plat_unused.h> scsi_device_t scsi_devices[SCSI_BUS_MAX][SCSI_ID_MAX]; - +int scsi_command_length[8] = { 6, 10, 10, 6, 16, 12, 10, 6 }; uint8_t scsi_null_device_sense[18] = { 0x70, 0, SENSE_ILLEGAL_REQUEST, 0, 0, 0, 0, 0, 0, 0, 0, 0, ASC_INV_LUN, 0, 0, 0, 0, 0 }; +#define SET_BUS_STATE(scsi_bus, state) scsi_bus->bus_out = (scsi_bus->bus_out & ~(SCSI_PHASE_MESSAGE_IN)) | (state & (SCSI_PHASE_MESSAGE_IN)) + +#ifdef ENABLE_SCSI_DEVICE_LOG +int scsi_device_do_log = ENABLE_SCSI_DEVICE_LOG; + +static void +scsi_device_log(const char *fmt, ...) +{ + va_list ap; + + if (scsi_device_do_log) { + va_start(ap, fmt); + pclog_ex(fmt, ap); + va_end(ap); + } +} +#else +# define scsi_device_log(fmt, ...) +#endif + static uint8_t scsi_device_target_command(scsi_device_t *dev, uint8_t *cdb) { @@ -189,3 +213,311 @@ scsi_device_init(void) } } } + +int +scsi_device_get_id(uint8_t data) +{ + for (uint8_t c = 0; c < SCSI_ID_MAX; c++) { + if (data & (1 << c)) + return c; + } + + return -1; +} + + +static int +scsi_device_get_msg(uint8_t *msgp, int len) +{ + uint8_t msg = msgp[0]; + if ((msg == 0) || ((msg >= 0x02) && (msg <= 0x1f)) || (msg >= 0x80)) + return 1; + + if ((msg >= 0x20) && (msg <= 0x2f)) + return 2; + + if (len < 2) + return 3; + + return msgp[1]; +} + +int +scsi_bus_read(scsi_bus_t *scsi_bus) +{ + scsi_device_t *dev; + int phase; + + /*Wait processes to handle bus requests*/ + if (scsi_bus->clear_req) { + scsi_bus->clear_req--; + if (!scsi_bus->clear_req) { + scsi_device_log("Prelude to command data\n"); + SET_BUS_STATE(scsi_bus, scsi_bus->bus_phase); + scsi_bus->bus_out |= BUS_REQ; + } + } + + if (scsi_bus->wait_data) { + scsi_bus->wait_data--; + if (!scsi_bus->wait_data) { + dev = &scsi_devices[scsi_bus->bus_device][scsi_bus->target_id]; + SET_BUS_STATE(scsi_bus, scsi_bus->bus_phase); + phase = scsi_bus->bus_out & SCSI_PHASE_MESSAGE_IN; + + switch (phase) { + case SCSI_PHASE_DATA_IN: + scsi_device_log("DataIn.\n"); + scsi_bus->state = STATE_DATAIN; + if ((dev->sc != NULL) && (dev->sc->temp_buffer != NULL)) + scsi_bus->data = dev->sc->temp_buffer[scsi_bus->data_pos++]; + + scsi_bus->bus_out = (scsi_bus->bus_out & ~BUS_DATAMASK) | BUS_SETDATA(scsi_bus->data) | BUS_DBP; + break; + case SCSI_PHASE_DATA_OUT: + if (scsi_bus->bus_phase & BUS_IDLE) { + scsi_device_log("Bus Idle.\n"); + scsi_bus->state = STATE_IDLE; + scsi_bus->bus_out &= ~BUS_BSY; + scsi_bus->timer(scsi_bus->priv, 0.0); + } else { + scsi_device_log("DataOut.\n"); + scsi_bus->state = STATE_DATAOUT; + } + break; + case SCSI_PHASE_STATUS: + scsi_device_log("Status.\n"); + scsi_bus->bus_out |= BUS_REQ; + scsi_bus->state = STATE_STATUS; + scsi_bus->bus_out = (scsi_bus->bus_out & ~BUS_DATAMASK) | BUS_SETDATA(dev->status) | BUS_DBP; + break; + case SCSI_PHASE_MESSAGE_IN: + scsi_device_log("Message In.\n"); + scsi_bus->state = STATE_MESSAGEIN; + scsi_bus->bus_out = (scsi_bus->bus_out & ~BUS_DATAMASK) | BUS_SETDATA(0) | BUS_DBP; + break; + case SCSI_PHASE_MESSAGE_OUT: + scsi_device_log("Message Out.\n"); + scsi_bus->bus_out |= BUS_REQ; + scsi_bus->state = STATE_MESSAGEOUT; + scsi_bus->bus_out = (scsi_bus->bus_out & ~BUS_DATAMASK) | BUS_SETDATA(scsi_bus->target_id >> 5) | BUS_DBP; + break; + default: + break; + } + } + } + + if (scsi_bus->wait_complete) { + scsi_bus->wait_complete--; + if (!scsi_bus->wait_complete) + scsi_bus->bus_out |= BUS_REQ; + } + + return scsi_bus->bus_out; +} + +void +scsi_bus_update(scsi_bus_t *scsi_bus, int bus) +{ + scsi_device_t *dev = &scsi_devices[scsi_bus->bus_device][scsi_bus->target_id]; + double p; + uint8_t sel_data; + int msglen; + + /*Start the SCSI command layer, which will also make the timings*/ + if (bus & BUS_ARB) + scsi_bus->state = STATE_IDLE; + + scsi_device_log("State = %i\n", scsi_bus->state); + + switch (scsi_bus->state) { + case STATE_IDLE: + scsi_bus->clear_req = scsi_bus->wait_data = scsi_bus->wait_complete = 0; + if ((bus & BUS_SEL) && !(bus & BUS_BSY)) { + sel_data = BUS_GETDATA(bus); + + scsi_bus->target_id = scsi_device_get_id(sel_data); + + /*Once the device has been found and selected, mark it as busy*/ + if ((scsi_bus->target_id != (uint8_t) -1) && scsi_device_present(&scsi_devices[scsi_bus->bus_device][scsi_bus->target_id])) { + scsi_bus->bus_out |= BUS_BSY; + scsi_bus->state = STATE_SELECT; + scsi_device_log("Select - target ID = %i, moving to state = %d.\n", scsi_bus->target_id, scsi_bus->state); + } else { + scsi_device_log("Device not found at ID %i, Current Bus BSY=%02x\n", scsi_bus->target_id, scsi_bus->bus_out); + scsi_bus->bus_out = 0; + } + } + break; + case STATE_SELECT: + if (!(bus & BUS_SEL)) { + if (!(bus & BUS_ATN)) { + if ((scsi_bus->target_id != (uint8_t) -1) && scsi_device_present(&scsi_devices[scsi_bus->bus_device][scsi_bus->target_id])) { + scsi_device_log("Device found at ID %i, Current Bus BSY=%02x\n", scsi_bus->target_id, scsi_bus->bus_out); + scsi_bus->state = STATE_COMMAND; + scsi_bus->bus_out = BUS_BSY | BUS_REQ; + scsi_bus->command_pos = 0; + SET_BUS_STATE(scsi_bus, SCSI_PHASE_COMMAND); + } else { + scsi_device_log("Device not found at ID %i again.\n", scsi_bus->target_id); + scsi_bus->state = STATE_IDLE; + scsi_bus->bus_out = 0; + } + } else { + scsi_device_log("Set to SCSI Message Out\n"); + scsi_bus->bus_phase = SCSI_PHASE_MESSAGE_OUT; + scsi_bus->wait_data = 4; + scsi_bus->msgout_pos = 0; + scsi_bus->is_msgout = 1; + } + } + break; + case STATE_COMMAND: + if ((bus & BUS_ACK) && !(scsi_bus->bus_in & BUS_ACK)) { + /*Write command byte to the output data register*/ + scsi_bus->command[scsi_bus->command_pos++] = BUS_GETDATA(bus); + scsi_bus->clear_req = 3; + scsi_bus->bus_phase = scsi_bus->bus_out & SCSI_PHASE_MESSAGE_IN; + scsi_bus->bus_out &= ~BUS_REQ; + + scsi_device_log("Command pos=%i, output data=%02x\n", scsi_bus->command_pos, BUS_GETDATA(bus)); + + if (scsi_bus->command_pos == scsi_command_length[(scsi_bus->command[0] >> 5) & 7]) { + if (scsi_bus->is_msgout) { + scsi_bus->is_msgout = 0; +#if 0 + scsi_bus->command[1] = (scsi_bus->command[1] & 0x1f) | (scsi_bus->msglun << 5); +#endif + } + + /*Reset data position to default*/ + scsi_bus->data_pos = 0; + + dev = &scsi_devices[scsi_bus->bus_device][scsi_bus->target_id]; + + scsi_device_log("SCSI Command 0x%02X for ID %d, status code=%02x\n", scsi_bus->command[0], scsi_bus->target_id, dev->status); + dev->buffer_length = -1; + scsi_device_command_phase0(dev, scsi_bus->command); + scsi_device_log("SCSI ID %i: Command %02X: Buffer Length %i, SCSI Phase %02X\n", scsi_bus->target_id, scsi_bus->command[0], dev->buffer_length, dev->phase); + + scsi_bus->period = 1.0; + scsi_bus->wait_data = 4; + scsi_bus->data_wait = 0; + scsi_bus->command_issued = 1; + + if (dev->status == SCSI_STATUS_OK) { + /*If the SCSI phase is Data In or Data Out, allocate the SCSI buffer based on the transfer length of the command*/ + if (dev->buffer_length && ((dev->phase == SCSI_PHASE_DATA_IN) || (dev->phase == SCSI_PHASE_DATA_OUT))) { + p = scsi_device_get_callback(dev); + scsi_bus->period = (p > 0.0) ? ((p / scsi_bus->divider) * scsi_bus->multi) : (((double) dev->buffer_length) * scsi_bus->speed); + scsi_device_log("SCSI ID %i: command 0x%02x for p = %lf, update = %lf, len = %i, dmamode = %x\n", scsi_bus->target_id, scsi_bus->command[0], scsi_device_get_callback(dev), scsi_bus->period, dev->buffer_length, scsi_bus->tx_mode); + } + } + scsi_bus->bus_phase = dev->phase; + } + } + break; + case STATE_DATAIN: + dev = &scsi_devices[scsi_bus->bus_device][scsi_bus->target_id]; + if ((bus & BUS_ACK) && !(scsi_bus->bus_in & BUS_ACK)) { + if (scsi_bus->data_pos >= dev->buffer_length) { + scsi_bus->bus_out &= ~BUS_REQ; + scsi_device_command_phase1(dev); + scsi_bus->bus_phase = SCSI_PHASE_STATUS; + scsi_bus->wait_data = 4; + scsi_bus->wait_complete = 8; + } else { + if ((dev->sc != NULL) && (dev->sc->temp_buffer != NULL)) + scsi_bus->data = dev->sc->temp_buffer[scsi_bus->data_pos++]; + + scsi_device_log("TXMode DataIn=%x, cmd=%02x.\n", scsi_bus->tx_mode, scsi_bus->command[0]); + scsi_bus->bus_out = (scsi_bus->bus_out & ~BUS_DATAMASK) | BUS_SETDATA(scsi_bus->data) | BUS_DBP | BUS_REQ; + if (scsi_bus->tx_mode == PIO_TX_BUS) { /*If a data in command that is not read 6/10 has been issued*/ + scsi_device_log("DMA mode idle IN=%d.\n", scsi_bus->data_pos); + scsi_bus->data_wait |= 1; + scsi_bus->timer(scsi_bus->priv, scsi_bus->period); + } else { + scsi_device_log("DMA mode IN=%d.\n", scsi_bus->data_pos); + scsi_bus->clear_req = 3; + } + scsi_bus->bus_out &= ~BUS_REQ; + scsi_bus->bus_phase = SCSI_PHASE_DATA_IN; + } + } + break; + case STATE_DATAOUT: + dev = &scsi_devices[scsi_bus->bus_device][scsi_bus->target_id]; + if ((bus & BUS_ACK) && !(scsi_bus->bus_in & BUS_ACK)) { + if ((dev->sc != NULL) && (dev->sc->temp_buffer != NULL)) + dev->sc->temp_buffer[scsi_bus->data_pos++] = BUS_GETDATA(bus); + + if (scsi_bus->data_pos >= dev->buffer_length) { + scsi_bus->bus_out &= ~BUS_REQ; + scsi_device_command_phase1(dev); + scsi_bus->bus_phase = SCSI_PHASE_STATUS; + scsi_bus->wait_data = 4; + scsi_bus->wait_complete = 8; + } else { + /*More data is to be transferred, place a request*/ + if (scsi_bus->tx_mode == PIO_TX_BUS) { /*If a data in command that is not write 6/10 has been issued*/ + scsi_device_log("DMA mode idle OUT=%d.\n", scsi_bus->data_pos); + scsi_bus->data_wait |= 1; + scsi_bus->timer(scsi_bus->priv, scsi_bus->period); + scsi_bus->bus_out &= ~BUS_REQ; + } else { + scsi_device_log("DMA mode OUT=%d.\n", scsi_bus->data_pos); + scsi_bus->bus_out |= BUS_REQ; + } + } + } + break; + case STATE_STATUS: + if ((bus & BUS_ACK) && !(scsi_bus->bus_in & BUS_ACK)) { + /*All transfers done, wait until next transfer*/ + scsi_device_identify(&scsi_devices[scsi_bus->bus_device][scsi_bus->target_id], SCSI_LUN_USE_CDB); + scsi_bus->bus_out &= ~BUS_REQ; + scsi_bus->bus_phase = SCSI_PHASE_MESSAGE_IN; + scsi_bus->wait_data = 4; + scsi_bus->wait_complete = 8; + scsi_bus->command_issued = 0; + } + break; + case STATE_MESSAGEIN: + if ((bus & BUS_ACK) && !(scsi_bus->bus_in & BUS_ACK)) { + scsi_bus->bus_out &= ~BUS_REQ; + scsi_bus->bus_phase = BUS_IDLE; + scsi_bus->wait_data = 4; + } + break; + case STATE_MESSAGEOUT: + if ((bus & BUS_ACK) && !(scsi_bus->bus_in & BUS_ACK)) { + scsi_bus->msgout[scsi_bus->msgout_pos++] = BUS_GETDATA(bus); + msglen = scsi_device_get_msg(scsi_bus->msgout, scsi_bus->msgout_pos); + if (scsi_bus->msgout_pos >= msglen) { + if ((scsi_bus->msgout[0] & (0x80 | 0x20)) == 0x80) + scsi_bus->msglun = scsi_bus->msgout[0] & 7; + + scsi_bus->bus_out &= ~BUS_REQ; + scsi_bus->state = STATE_MESSAGE_ID; + } + } + break; + case STATE_MESSAGE_ID: + if ((scsi_bus->target_id != (uint8_t) -1) && scsi_device_present(&scsi_devices[scsi_bus->bus_device][scsi_bus->target_id])) { + scsi_device_log("Device found at ID %i on MSGOUT, Current Bus BSY=%02x\n", scsi_bus->target_id, scsi_bus->bus_out); + scsi_device_identify(&scsi_devices[scsi_bus->bus_device][scsi_bus->target_id], scsi_bus->msglun); + scsi_bus->state = STATE_COMMAND; + scsi_bus->bus_out = BUS_BSY | BUS_REQ; + scsi_bus->command_pos = 0; + SET_BUS_STATE(scsi_bus, SCSI_PHASE_COMMAND); + } + break; + + default: + break; + } + + scsi_bus->bus_in = bus; +} + diff --git a/src/scsi/scsi_disk.c b/src/scsi/scsi_disk.c index 10fdf04a6..878259094 100644 --- a/src/scsi/scsi_disk.c +++ b/src/scsi/scsi_disk.c @@ -12,26 +12,24 @@ * * Copyright 2017-2018 Miran Grca. */ -#include #include #include -#include +#ifdef ENABLE_SCSI_DISK_LOG +#include +#endif #include +#include #include #include -#include -#define HAVE_STDARG_H #include <86box/86box.h> -#include <86box/config.h> #include <86box/timer.h> #include <86box/device.h> +#include <86box/log.h> #include <86box/scsi.h> #include <86box/scsi_device.h> #include <86box/machine.h> #include <86box/nvr.h> -#include <86box/hdc.h> #include <86box/hdc_ide.h> -#include <86box/sound.h> #include <86box/plat.h> #include <86box/ui.h> #include <86box/hdd.h> @@ -42,86 +40,71 @@ #define scsi_disk_sense_error dev->sense[0] #define scsi_disk_sense_key dev->sense[2] +#define scsi_disk_info *(uint32_t *) &(dev->sense[3]) #define scsi_disk_asc dev->sense[12] #define scsi_disk_ascq dev->sense[13] -/* Table of all SCSI commands and their flags, needed for the new disc change / not ready handler. */ +// clang-format off +/* + Table of all SCSI commands and their flags, needed for the new disc change / + not ready handler. + */ const uint8_t scsi_disk_command_flags[0x100] = { - IMPLEMENTED | CHECK_READY | NONDATA, /* 0x00 */ - IMPLEMENTED | ALLOW_UA | NONDATA | SCSI_ONLY, /* 0x01 */ - 0, - IMPLEMENTED | ALLOW_UA, /* 0x03 */ - IMPLEMENTED | CHECK_READY | ALLOW_UA | NONDATA | SCSI_ONLY, /* 0x04 */ - 0, 0, 0, - IMPLEMENTED | CHECK_READY, /* 0x08 */ - 0, - IMPLEMENTED | CHECK_READY, /* 0x0A */ - IMPLEMENTED | CHECK_READY | NONDATA, /* 0x0B */ - 0, 0, 0, 0, 0, 0, - IMPLEMENTED | ALLOW_UA, /* 0x12 */ - IMPLEMENTED | CHECK_READY | NONDATA | SCSI_ONLY, /* 0x13 */ - 0, - IMPLEMENTED, /* 0x15 */ - IMPLEMENTED | SCSI_ONLY, /* 0x16 */ - IMPLEMENTED | SCSI_ONLY, /* 0x17 */ - 0, 0, - IMPLEMENTED, /* 0x1A */ - 0, 0, - IMPLEMENTED, /* 0x1D */ - IMPLEMENTED | CHECK_READY, /* 0x1E */ - 0, 0, 0, 0, 0, 0, - IMPLEMENTED | CHECK_READY, /* 0x25 */ - 0, 0, - IMPLEMENTED | CHECK_READY, /* 0x28 */ - 0, - IMPLEMENTED | CHECK_READY, /* 0x2A */ - IMPLEMENTED | CHECK_READY | NONDATA, /* 0x2B */ - 0, 0, - IMPLEMENTED | CHECK_READY, /* 0x2E */ - IMPLEMENTED | CHECK_READY | NONDATA | SCSI_ONLY, /* 0x2F */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, - IMPLEMENTED | CHECK_READY, /* 0x41 */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, - IMPLEMENTED, /* 0x55 */ - 0, 0, 0, 0, - IMPLEMENTED, /* 0x5A */ - 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - IMPLEMENTED | CHECK_READY, /* 0xA8 */ - 0, - IMPLEMENTED | CHECK_READY, /* 0xAA */ - 0, 0, 0, - IMPLEMENTED | CHECK_READY, /* 0xAE */ - IMPLEMENTED | CHECK_READY | NONDATA | SCSI_ONLY, /* 0xAF */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - IMPLEMENTED, /* 0xBD */ - 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 + [0x00] = IMPLEMENTED | CHECK_READY, + [0x01] = IMPLEMENTED | ALLOW_UA | SCSI_ONLY, + [0x03] = IMPLEMENTED | ALLOW_UA, + [0x04] = IMPLEMENTED | CHECK_READY | ALLOW_UA | SCSI_ONLY, + [0x08] = IMPLEMENTED | CHECK_READY, + [0x0a ... 0x0b] = IMPLEMENTED | CHECK_READY, + [0x12] = IMPLEMENTED | ALLOW_UA, + [0x13] = IMPLEMENTED | CHECK_READY | SCSI_ONLY, + [0x15] = IMPLEMENTED, + [0x16 ... 0x17] = IMPLEMENTED | SCSI_ONLY, + [0x1a] = IMPLEMENTED, + [0x1d] = IMPLEMENTED, + [0x1e] = IMPLEMENTED | CHECK_READY, + [0x25] = IMPLEMENTED | CHECK_READY, + [0x28] = IMPLEMENTED | CHECK_READY, + [0x2a ... 0x2b] = IMPLEMENTED | CHECK_READY, + [0x2e] = IMPLEMENTED | CHECK_READY, + [0x2f] = IMPLEMENTED | CHECK_READY | SCSI_ONLY, + [0x41] = IMPLEMENTED | CHECK_READY, + [0x55] = IMPLEMENTED, + [0x5a] = IMPLEMENTED, + [0xa8] = IMPLEMENTED | CHECK_READY, + [0xaa] = IMPLEMENTED | CHECK_READY, + [0xae] = IMPLEMENTED | CHECK_READY, + [0xaf] = IMPLEMENTED | CHECK_READY | SCSI_ONLY, + [0xbd] = IMPLEMENTED }; -uint64_t scsi_disk_mode_sense_page_flags = (GPMODEP_FORMAT_DEVICE_PAGE | GPMODEP_RIGID_DISK_PAGE | GPMODEP_UNK_VENDOR_PAGE | GPMODEP_ALL_PAGES); +uint64_t scsi_disk_mode_sense_page_flags = (GPMODEP_FORMAT_DEVICE_PAGE | GPMODEP_RIGID_DISK_PAGE | + GPMODEP_UNK_VENDOR_PAGE | GPMODEP_ALL_PAGES); -/* This should be done in a better way but for time being, it's been done this way so it's not as huge and more readable. */ static const mode_sense_pages_t scsi_disk_mode_sense_pages_default = { - {[GPMODE_FORMAT_DEVICE_PAGE] = { GPMODE_FORMAT_DEVICE_PAGE, 0x16, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, - [GPMODE_RIGID_DISK_PAGE] = { GPMODE_RIGID_DISK_PAGE, 0x16, 0, 0x10, 0, 64, 0, 0, 0, 0, 0, 0, 0, 200, 0xff, 0xff, 0xff, 0, 0, 0, 0x15, 0x18, 0, 0 }, - [GPMODE_UNK_VENDOR_PAGE] = { 0xB0, 0x16, '8', '6', 'B', 'o', 'x', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' }} + { [0x03] = { GPMODE_FORMAT_DEVICE_PAGE, 0x16, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, + 0x00, 0x01, 0x01, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, + [0x04] = { GPMODE_RIGID_DISK_PAGE, 0x16, 0x00, 0x10, 0x00, 0x40, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0xc8, 0xff, 0xff, + 0xff, 0x00, 0x00, 0x00, 0x15, 0x18, 0x00, 0x00 }, + [0x30] = { GPMODE_UNK_VENDOR_PAGE | 0x80, 0x16, '8' , '6' , 'B' , 'o' , 'x' , ' ' , + ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , + ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' } } }; static const mode_sense_pages_t scsi_disk_mode_sense_pages_changeable = { - {[GPMODE_FORMAT_DEVICE_PAGE] = { GPMODE_FORMAT_DEVICE_PAGE, 0x16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, - [GPMODE_RIGID_DISK_PAGE] = { GPMODE_RIGID_DISK_PAGE, 0x16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, - [GPMODE_UNK_VENDOR_PAGE] = { 0xB0, 0x16, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }} + { [0x03] = { GPMODE_FORMAT_DEVICE_PAGE, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, + [0x04] = { GPMODE_RIGID_DISK_PAGE, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, + [0x30] = { GPMODE_UNK_VENDOR_PAGE | 0x80, 0x16, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff } } }; +// clang-format on static void scsi_disk_command_complete(scsi_disk_t *dev); @@ -133,116 +116,116 @@ static void scsi_disk_init(scsi_disk_t *dev); int scsi_disk_do_log = ENABLE_SCSI_DISK_LOG; static void -scsi_disk_log(const char *fmt, ...) +scsi_disk_log(void *priv, const char *fmt, ...) { va_list ap; if (scsi_disk_do_log) { va_start(ap, fmt); - pclog_ex(fmt, ap); + log_out(priv, fmt, ap); va_end(ap); } } #else -# define scsi_disk_log(fmt, ...) +# define scsi_disk_log(priv, fmt, ...) #endif static void -scsi_disk_set_callback(scsi_disk_t *dev) +scsi_disk_set_callback(const scsi_disk_t *dev) { - if (dev->drv->bus != HDD_BUS_SCSI) + if (dev->drv->bus_type != HDD_BUS_SCSI) ide_set_callback(ide_drives[dev->drv->ide_channel], dev->callback); } static void scsi_disk_init(scsi_disk_t *dev) { - if (!dev) - return; + if (dev != NULL) { + /* Do a reset (which will also rezero it). */ + scsi_disk_reset((scsi_common_t *) dev); - /* Do a reset (which will also rezero it). */ - scsi_disk_reset((scsi_common_t *) dev); + /* Configure the drive. */ + dev->requested_blocks = 1; - /* Configure the drive. */ - dev->requested_blocks = 1; + dev->drv->bus_mode = 0; + if (dev->drv->bus_type >= HDD_BUS_ATAPI) + dev->drv->bus_mode |= 2; + if (dev->drv->bus_type < HDD_BUS_SCSI) + dev->drv->bus_mode |= 1; + scsi_disk_log(dev->log, "Bus type %i, bus mode %i\n", + dev->drv->bus_type, dev->drv->bus_mode); - dev->drv->bus_mode = 0; - if (dev->drv->bus >= HDD_BUS_ATAPI) - dev->drv->bus_mode |= 2; - if (dev->drv->bus < HDD_BUS_SCSI) - dev->drv->bus_mode |= 1; - scsi_disk_log("SCSI HDD %i: Bus type %i, bus mode %i\n", - dev->id, dev->drv->bus, dev->drv->bus_mode); + dev->sense[0] = 0xf0; + dev->sense[7] = 10; - dev->sense[0] = 0xf0; - dev->sense[7] = 10; - /* NEC only */ - dev->tf->status = 0; - dev->tf->pos = 0; - dev->packet_status = PHASE_NONE; - scsi_disk_sense_key = scsi_disk_asc = scsi_disk_ascq = dev->unit_attention = 0; - scsi_disk_mode_sense_load(dev); + dev->tf->status = 0; + dev->tf->pos = 0; + dev->packet_status = PHASE_NONE; + scsi_disk_sense_key = scsi_disk_asc = scsi_disk_ascq = dev->unit_attention = 0; + scsi_disk_info = 0x00; + scsi_disk_mode_sense_load(dev); + } } /* Returns: 0 for none, 1 for PIO, 2 for DMA. */ static int -scsi_disk_current_mode(scsi_disk_t *dev) +scsi_disk_current_mode(const scsi_disk_t *dev) { - if (dev->drv->bus == HDD_BUS_SCSI) - return 2; - else if (dev->drv->bus == HDD_BUS_ATAPI) { - scsi_disk_log("SCSI DISK %i: ATAPI drive, setting to %s\n", dev->id, + int ret = 0; + + if (dev->drv->bus_type == HDD_BUS_SCSI) + ret = 2; + else if (dev->drv->bus_type == HDD_BUS_ATAPI) { + scsi_disk_log(dev->log, "ATAPI drive, setting to %s\n", (dev->tf->features & 1) ? "DMA" : "PIO", dev->id); - return (dev->tf->features & 1) ? 2 : 1; + ret = (dev->tf->features & 1) ? 2 : 1; } - return 0; + return ret; } -void +static void scsi_disk_mode_sense_load(scsi_disk_t *dev) { - FILE *fp; - char file_name[512]; + char file_name[512] = { 0 }; memset(&dev->ms_pages_saved, 0, sizeof(mode_sense_pages_t)); - memcpy(&dev->ms_pages_saved, &scsi_disk_mode_sense_pages_default, sizeof(mode_sense_pages_t)); + memcpy(&dev->ms_pages_saved, &scsi_disk_mode_sense_pages_default, + sizeof(mode_sense_pages_t)); - memset(file_name, 0, 512); sprintf(file_name, "scsi_disk_%02i_mode_sense.bin", dev->id); - fp = plat_fopen(nvr_path(file_name), "rb"); + FILE *fp = plat_fopen(nvr_path(file_name), "rb"); if (fp) { if (fread(dev->ms_pages_saved.pages[0x30], 1, 0x18, fp) != 0x18) - fatal("scsi_disk_mode_sense_load(): Error reading data\n"); + log_fatal(dev->log, "scsi_disk_mode_sense_load(): Error reading data\n"); fclose(fp); } } -void -scsi_disk_mode_sense_save(scsi_disk_t *dev) +static void +scsi_disk_mode_sense_save(const scsi_disk_t *dev) { - FILE *fp; - char file_name[512]; + char file_name[512] = { 0 }; - memset(file_name, 0, 512); sprintf(file_name, "scsi_disk_%02i_mode_sense.bin", dev->id); - fp = plat_fopen(nvr_path(file_name), "wb"); + FILE *fp = plat_fopen(nvr_path(file_name), "wb"); if (fp) { fwrite(dev->ms_pages_saved.pages[0x30], 1, 0x18, fp); fclose(fp); } } -/*SCSI Mode Sense 6/10*/ +/* SCSI Mode Sense 6/10 */ uint8_t -scsi_disk_mode_sense_read(scsi_disk_t *dev, uint8_t page_control, uint8_t page, uint8_t pos) +scsi_disk_mode_sense_read(const scsi_disk_t *dev, const uint8_t pgctl, + const uint8_t page, const uint8_t pos) { - if (page_control == 1) + if (pgctl == 1) return scsi_disk_mode_sense_pages_changeable.pages[page][pos]; if (page == GPMODE_RIGID_DISK_PAGE) - switch (page_control) { + switch (pgctl) { /* Rigid disk geometry page. */ case 0: case 2: @@ -272,7 +255,7 @@ scsi_disk_mode_sense_read(scsi_disk_t *dev, uint8_t page_control, uint8_t page, break; } else if (page == GPMODE_FORMAT_DEVICE_PAGE) - switch (page_control) { + switch (pgctl) { /* Format device page. */ case 0: case 2: @@ -293,7 +276,7 @@ scsi_disk_mode_sense_read(scsi_disk_t *dev, uint8_t page_control, uint8_t page, break; } else - switch (page_control) { + switch (pgctl) { case 0: case 3: return dev->ms_pages_saved.pages[page][pos]; @@ -308,16 +291,13 @@ scsi_disk_mode_sense_read(scsi_disk_t *dev, uint8_t page_control, uint8_t page, } uint32_t -scsi_disk_mode_sense(scsi_disk_t *dev, uint8_t *buf, uint32_t pos, uint8_t page, uint8_t block_descriptor_len) +scsi_disk_mode_sense(const scsi_disk_t *dev, uint8_t *buf, uint32_t pos, + uint8_t page, const uint8_t block_descriptor_len) { - uint8_t msplen; - uint8_t page_control = (page >> 6) & 3; - int size = 0; + int size = hdd_image_get_last_sector(dev->id); page &= 0x3f; - size = hdd_image_get_last_sector(dev->id); - if (block_descriptor_len) { buf[pos++] = 1; /* Density code. */ buf[pos++] = (size >> 16) & 0xff; /* Number of blocks (0 = all). */ @@ -332,12 +312,14 @@ scsi_disk_mode_sense(scsi_disk_t *dev, uint8_t *buf, uint32_t pos, uint8_t page, for (uint8_t i = 0; i < 0x40; i++) { if ((page == GPMODE_ALL_PAGES) || (page == i)) { if (scsi_disk_mode_sense_page_flags & (1LL << (uint64_t) page)) { - buf[pos++] = scsi_disk_mode_sense_read(dev, page_control, i, 0); - msplen = scsi_disk_mode_sense_read(dev, page_control, i, 1); - buf[pos++] = msplen; - scsi_disk_log("SCSI HDD %i: MODE SENSE: Page [%02X] length %i\n", dev->id, i, msplen); + const uint8_t pgctl = (page >> 6) & 3; + const uint8_t msplen = scsi_disk_mode_sense_read(dev, pgctl, i, 1); + buf[pos++] = scsi_disk_mode_sense_read(dev, pgctl, i, 0); + buf[pos++] = msplen; + scsi_disk_log(dev->log, "MODE SENSE: Page [%02X] length %i\n", + i, msplen); for (uint8_t j = 0; j < msplen; j++) - buf[pos++] = scsi_disk_mode_sense_read(dev, page_control, i, 2 + j); + buf[pos++] = scsi_disk_mode_sense_read(dev, pgctl, i, 2 + j); } } } @@ -346,7 +328,7 @@ scsi_disk_mode_sense(scsi_disk_t *dev, uint8_t *buf, uint32_t pos, uint8_t page, } static void -scsi_disk_update_request_length(scsi_disk_t *dev, int len, int block_len) +scsi_disk_update_request_length(scsi_disk_t *dev, int len, const int block_len) { int bt; int min_len = 0; @@ -407,7 +389,7 @@ scsi_disk_bus_speed(scsi_disk_t *dev) { double ret = -1.0; - if (dev && dev->drv && (dev->drv->bus == HDD_BUS_SCSI)) { + if (dev && dev->drv && (dev->drv->bus_type == HDD_BUS_SCSI)) { dev->callback = -1.0; /* Speed depends on SCSI controller */ return 0.0; } else { @@ -425,7 +407,7 @@ scsi_disk_bus_speed(scsi_disk_t *dev) void scsi_disk_command_common(scsi_disk_t *dev) { - double bytes_per_second = 0.0; + double bytes_per_second; double period; /* MAP: BUSY_STAT, no DRQ, phase 1. */ @@ -435,6 +417,7 @@ scsi_disk_command_common(scsi_disk_t *dev) dev->callback = 0; if (dev->packet_status == PHASE_COMPLETE) { + switch (dev->current_cdb[0]) { case GPCMD_VERIFY_6: case GPCMD_VERIFY_10: @@ -446,18 +429,19 @@ scsi_disk_command_common(scsi_disk_t *dev) case GPCMD_WRITE_AND_VERIFY_12: case GPCMD_WRITE_SAME_10: /* Seek time is in us. */ - period = hdd_timing_write(dev->drv, dev->drv->seek_pos, dev->drv->seek_len); - scsi_disk_log("SCSI HD %i: Seek period: %" PRIu64 " us\n", - dev->id, (uint64_t) period); + period = hdd_timing_write(dev->drv, dev->drv->seek_pos, + dev->drv->seek_len); + scsi_disk_log(dev->log, "Seek period: %" PRIu64 " us\n", + (uint64_t) period); dev->callback += period; /* Account for seek time. */ bytes_per_second = scsi_bus_get_speed(dev->drv->scsi_id >> 4); period = 1000000.0 / bytes_per_second; - scsi_disk_log("SCSI HD %i: Byte transfer period: %" PRIu64 " us\n", dev->id, + scsi_disk_log(dev->log, "Byte transfer period: %" PRIu64 " us\n", (uint64_t) period); period = period * (double) (dev->packet_len); - scsi_disk_log("CD-ROM %i: Sector transfer period: %" PRIu64 " us\n", dev->id, + scsi_disk_log(dev->log, "Sector transfer period: %" PRIu64 " us\n", (uint64_t) period); dev->callback += period; break; @@ -473,8 +457,8 @@ scsi_disk_command_common(scsi_disk_t *dev) /* Seek time is in us. */ period = hdd_seek_get_time(dev->drv, (dev->current_cdb[0] == GPCMD_REZERO_UNIT) ? 0 : dev->sector_pos, HDD_OP_SEEK, 0, 0.0); - scsi_disk_log("SCSI HD %i: Seek period: %" PRIu64 " us\n", - dev->id, (uint64_t) period); + scsi_disk_log(dev->log, "Seek period: %" PRIu64 " us\n", + (uint64_t) period); dev->callback += period; scsi_disk_set_callback(dev); return; @@ -482,9 +466,10 @@ scsi_disk_command_common(scsi_disk_t *dev) case 0x28: case 0xa8: /* Seek time is in us. */ - period = hdd_timing_read(dev->drv, dev->drv->seek_pos, dev->drv->seek_len); - scsi_disk_log("SCSI HD %i: Seek period: %" PRIu64 " us\n", - dev->id, (uint64_t) period); + period = hdd_timing_read(dev->drv, dev->drv->seek_pos, + dev->drv->seek_len); + scsi_disk_log(dev->log, "Seek period: %" PRIu64 " us\n", + (uint64_t) period); dev->callback += period; /* Account for seek time. */ bytes_per_second = scsi_bus_get_speed(dev->drv->scsi_id >> 4); @@ -500,9 +485,11 @@ scsi_disk_command_common(scsi_disk_t *dev) } period = 1000000.0 / bytes_per_second; - scsi_disk_log("SCSI HD %i: Byte transfer period: %" PRIu64 " us\n", dev->id, (uint64_t) period); + scsi_disk_log(dev->log, "Byte transfer period: %" PRIu64 " us\n", + (uint64_t) period); period = period * (double) (dev->packet_len); - scsi_disk_log("SCSI HD %i: Sector transfer period: %" PRIu64 " us\n", dev->id, (uint64_t) period); + scsi_disk_log(dev->log, "Sector transfer period: %" PRIu64 " us\n", + (uint64_t) period); dev->callback += period; } scsi_disk_set_callback(dev); @@ -543,16 +530,19 @@ scsi_disk_command_write_dma(scsi_disk_t *dev) scsi_disk_command_common(dev); } -/* id = Current ZIP device ID; +/* + dev = Pointer to current SCSI disk device; len = Total transfer length; block_len = Length of a single block (why does it matter?!); alloc_len = Allocated transfer length; - direction = Transfer direction (0 = read from host, 1 = write to host). */ + direction = Transfer direction (0 = read from host, 1 = write to host). + */ static void -scsi_disk_data_command_finish(scsi_disk_t *dev, int len, int block_len, int alloc_len, int direction) +scsi_disk_data_command_finish(scsi_disk_t *dev, int len, const int block_len, + const int alloc_len, const int direction) { - scsi_disk_log("SCSI HD %i: Finishing command (%02X): %i, %i, %i, %i, %i\n", - dev->id, dev->current_cdb[0], len, block_len, alloc_len, direction, + scsi_disk_log(dev->log, "Finishing command (%02X): %i, %i, %i, %i, %i\n", + dev->current_cdb[0], len, block_len, alloc_len, direction, dev->tf->request_length); dev->tf->pos = 0; if (alloc_len >= 0) { @@ -560,13 +550,13 @@ scsi_disk_data_command_finish(scsi_disk_t *dev, int len, int block_len, int allo len = alloc_len; } if ((len == 0) || (scsi_disk_current_mode(dev) == 0)) { - if (dev->drv->bus != HDD_BUS_SCSI) + if (dev->drv->bus_type != HDD_BUS_SCSI) dev->packet_len = 0; scsi_disk_command_complete(dev); } else { if (scsi_disk_current_mode(dev) == 2) { - if (dev->drv->bus != HDD_BUS_SCSI) + if (dev->drv->bus_type != HDD_BUS_SCSI) dev->packet_len = alloc_len; if (direction == 0) @@ -582,27 +572,27 @@ scsi_disk_data_command_finish(scsi_disk_t *dev, int len, int block_len, int allo } } - scsi_disk_log("SCSI HD %i: Status: %i, cylinder %i, packet length: %i, position: %i, phase: %i\n", - dev->id, dev->packet_status, dev->tf->request_length, dev->packet_len, dev->tf->pos, - dev->tf->phase); + scsi_disk_log(dev->log, "Status: %i, cylinder %i, packet length: %i, position: %i, " + "phase: %i\n", + dev->packet_status, dev->tf->request_length, dev->packet_len, + dev->tf->pos, dev->tf->phase); } static void scsi_disk_sense_clear(scsi_disk_t *dev, UNUSED(int command)) { scsi_disk_sense_key = scsi_disk_asc = scsi_disk_ascq = 0; + scsi_disk_info = 0x00000000; } static void -scsi_disk_set_phase(scsi_disk_t *dev, uint8_t phase) +scsi_disk_set_phase(const scsi_disk_t *dev, const uint8_t phase) { - uint8_t scsi_bus = (dev->drv->scsi_id >> 4) & 0x0f; - uint8_t scsi_id = dev->drv->scsi_id & 0x0f; + const uint8_t scsi_bus = (dev->drv->scsi_id >> 4) & 0x0f; + const uint8_t scsi_id = dev->drv->scsi_id & 0x0f; - if (dev->drv->bus != HDD_BUS_SCSI) - return; - - scsi_devices[scsi_bus][scsi_id].phase = phase; + if (dev->drv->bus_type == HDD_BUS_SCSI) + scsi_devices[scsi_bus][scsi_id].phase = phase; } static void @@ -615,15 +605,16 @@ scsi_disk_cmd_error(scsi_disk_t *dev) dev->packet_status = PHASE_ERROR; dev->callback = 50.0 * SCSI_TIME; scsi_disk_set_callback(dev); - ui_sb_update_icon(SB_HDD | dev->drv->bus, 0); - scsi_disk_log("SCSI HD %i: ERROR: %02X/%02X/%02X\n", dev->id, scsi_disk_sense_key, scsi_disk_asc, scsi_disk_ascq); + ui_sb_update_icon(SB_HDD | dev->drv->bus_type, 0); + scsi_disk_log(dev->log, "ERROR: %02X/%02X/%02X\n", scsi_disk_sense_key, + scsi_disk_asc, scsi_disk_ascq); } static void scsi_disk_buf_alloc(scsi_disk_t *dev, uint32_t len) { - scsi_disk_log("SCSI HD %i: Allocated buffer length: %i\n", dev->id, len); - if (!dev->temp_buffer) + scsi_disk_log(dev->log, "Allocated buffer length: %i\n", len); + if (dev->temp_buffer == NULL) dev->temp_buffer = (uint8_t *) malloc(len); } @@ -631,7 +622,7 @@ static void scsi_disk_buf_free(scsi_disk_t *dev) { if (dev->temp_buffer) { - scsi_disk_log("SCSI HD %i: Freeing buffer...\n", dev->id); + scsi_disk_log(dev->log, "Freeing buffer...\n"); free(dev->temp_buffer); dev->temp_buffer = NULL; } @@ -644,6 +635,10 @@ scsi_disk_bus_master_error(scsi_common_t *sc) scsi_disk_buf_free(dev); scsi_disk_sense_key = scsi_disk_asc = scsi_disk_ascq = 0; + scsi_disk_info = (dev->sector_pos >> 24) | + ((dev->sector_pos >> 16) << 8) | + ((dev->sector_pos >> 8) << 16) | + ( dev->sector_pos << 24); scsi_disk_cmd_error(dev); } @@ -653,6 +648,10 @@ scsi_disk_write_error(scsi_disk_t *dev) scsi_disk_sense_key = SENSE_MEDIUM_ERROR; scsi_disk_asc = ASC_WRITE_ERROR; scsi_disk_ascq = 0; + scsi_disk_info = (dev->sector_pos >> 24) | + ((dev->sector_pos >> 16) << 8) | + ((dev->sector_pos >> 8) << 16) | + ( dev->sector_pos << 24); scsi_disk_cmd_error(dev); } @@ -662,25 +661,31 @@ scsi_disk_read_error(scsi_disk_t *dev) scsi_disk_sense_key = SENSE_MEDIUM_ERROR; scsi_disk_asc = ASC_UNRECOVERED_READ_ERROR; scsi_disk_ascq = 0; + scsi_disk_info = (dev->sector_pos >> 24) | + ((dev->sector_pos >> 16) << 8) | + ((dev->sector_pos >> 8) << 16) | + ( dev->sector_pos << 24); scsi_disk_cmd_error(dev); } static void -scsi_disk_invalid_lun(scsi_disk_t *dev) +scsi_disk_invalid_lun(scsi_disk_t *dev, const uint8_t lun) { scsi_disk_sense_key = SENSE_ILLEGAL_REQUEST; scsi_disk_asc = ASC_INV_LUN; scsi_disk_ascq = 0; scsi_disk_set_phase(dev, SCSI_PHASE_STATUS); + scsi_disk_info = lun << 24; scsi_disk_cmd_error(dev); } static void -scsi_disk_illegal_opcode(scsi_disk_t *dev) +scsi_disk_illegal_opcode(scsi_disk_t *dev, const uint8_t opcode) { scsi_disk_sense_key = SENSE_ILLEGAL_REQUEST; scsi_disk_asc = ASC_ILLEGAL_OPCODE; scsi_disk_ascq = 0; + scsi_disk_info = opcode << 24; scsi_disk_cmd_error(dev); } @@ -690,54 +695,72 @@ scsi_disk_lba_out_of_range(scsi_disk_t *dev) scsi_disk_sense_key = SENSE_ILLEGAL_REQUEST; scsi_disk_asc = ASC_LBA_OUT_OF_RANGE; scsi_disk_ascq = 0; + scsi_disk_info = (dev->sector_pos >> 24) | + ((dev->sector_pos >> 16) << 8) | + ((dev->sector_pos >> 8) << 16) | + ( dev->sector_pos << 24); scsi_disk_cmd_error(dev); } static void -scsi_disk_invalid_field(scsi_disk_t *dev) +scsi_disk_invalid_field(scsi_disk_t *dev, const uint32_t field) { scsi_disk_sense_key = SENSE_ILLEGAL_REQUEST; scsi_disk_asc = ASC_INV_FIELD_IN_CMD_PACKET; scsi_disk_ascq = 0; + scsi_disk_info = (field >> 24) | + ((field >> 16) << 8) | + ((field >> 8) << 16) | + ( field << 24); scsi_disk_cmd_error(dev); dev->tf->status = 0x53; } static void -scsi_disk_invalid_field_pl(scsi_disk_t *dev) +scsi_disk_invalid_field_pl(scsi_disk_t *dev, const uint32_t field) { scsi_disk_sense_key = SENSE_ILLEGAL_REQUEST; scsi_disk_asc = ASC_INV_FIELD_IN_PARAMETER_LIST; scsi_disk_ascq = 0; + scsi_disk_info = (field >> 24) | + ((field >> 16) << 8) | + ((field >> 8) << 16) | + ( field << 24); scsi_disk_cmd_error(dev); dev->tf->status = 0x53; } static void -scsi_disk_data_phase_error(scsi_disk_t *dev) +scsi_disk_data_phase_error(scsi_disk_t *dev, const uint32_t info) { scsi_disk_sense_key = SENSE_ILLEGAL_REQUEST; scsi_disk_asc = ASC_DATA_PHASE_ERROR; scsi_disk_ascq = 0; + scsi_disk_info = (info >> 24) | + ((info >> 16) << 8) | + ((info >> 8) << 16) | + ( info << 24); scsi_disk_cmd_error(dev); } static int -scsi_disk_blocks(scsi_disk_t *dev, int32_t *len, UNUSED(int first_batch), int out) +scsi_disk_blocks(scsi_disk_t *dev, int32_t *len, UNUSED(int first_batch), const int out) { + const uint32_t medium_size = hdd_image_get_last_sector(dev->id) + 1; + *len = 0; - uint32_t medium_size = hdd_image_get_last_sector(dev->id) + 1; if (!dev->sector_len) { scsi_disk_command_complete(dev); return -1; } - scsi_disk_log("%sing %i blocks starting from %i...\n", out ? "Writ" : "Read", + scsi_disk_log(dev->log, "%sing %i blocks starting from %i...\n", out ? "Writ" : "Read", dev->requested_blocks, dev->sector_pos); if (dev->sector_pos >= medium_size) { - scsi_disk_log("SCSI HD %i: Trying to %s beyond the end of disk\n", dev->id, out ? "write" : "read"); + scsi_disk_log(dev->log, "Trying to %s beyond the end of disk\n", + out ? "write" : "read"); scsi_disk_lba_out_of_range(dev); return 0; } @@ -746,68 +769,90 @@ scsi_disk_blocks(scsi_disk_t *dev, int32_t *len, UNUSED(int first_batch), int ou for (int i = 0; i < dev->requested_blocks; i++) { if (out) { - if (hdd_image_write(dev->id, dev->sector_pos + i, 1, dev->temp_buffer + (i << 9)) < 0) { + if (hdd_image_write(dev->id, dev->sector_pos, 1, dev->temp_buffer + + (i << 9)) < 0) { scsi_disk_write_error(dev); return -1; } } else { - if (hdd_image_read(dev->id, dev->sector_pos + i, 1, dev->temp_buffer + (i << 9)) < 0) { + if (hdd_image_read(dev->id, dev->sector_pos, 1, dev->temp_buffer + + (i << 9)) < 0) { scsi_disk_read_error(dev); return -1; } } + dev->sector_pos++; } - scsi_disk_log("%s %i bytes of blocks...\n", out ? "Written" : "Read", *len); + scsi_disk_log(dev->log, "%s %i bytes of blocks...\n", out ? "Written" : "Read", *len); - dev->sector_pos += dev->requested_blocks; dev->sector_len -= dev->requested_blocks; return 1; } static int -scsi_disk_pre_execution_check(scsi_disk_t *dev, uint8_t *cdb) +scsi_disk_pre_execution_check(scsi_disk_t *dev, const uint8_t *cdb) { - if ((cdb[0] != GPCMD_REQUEST_SENSE) && (dev->cur_lun == SCSI_LUN_USE_CDB) && (cdb[1] & 0xe0)) { - scsi_disk_log("SCSI HD %i: Attempting to execute a unknown command targeted at SCSI LUN %i\n", - dev->id, ((dev->tf->request_length >> 5) & 7)); - scsi_disk_invalid_lun(dev); + if ((cdb[0] != GPCMD_REQUEST_SENSE) && (dev->cur_lun == SCSI_LUN_USE_CDB) && + (cdb[1] & 0xe0)) { + scsi_disk_log(dev->log, "Attempting to execute a unknown command " + "targeted at SCSI LUN %i\n", + ((dev->tf->request_length >> 5) & 7)); + scsi_disk_invalid_lun(dev, cdb[1] >> 5); return 0; } if (!(scsi_disk_command_flags[cdb[0]] & IMPLEMENTED)) { - scsi_disk_log("SCSI HD %i: Attempting to execute unknown command %02X over %s\n", dev->id, cdb[0], - (dev->drv->bus == HDD_BUS_SCSI) ? "SCSI" : "ATAPI"); - scsi_disk_illegal_opcode(dev); + scsi_disk_log(dev->log, "Attempting to execute unknown " + "command %02X over %s\n", cdb[0], + (dev->drv->bus_type == HDD_BUS_SCSI) ? "SCSI" : "ATAPI"); + scsi_disk_illegal_opcode(dev, cdb[0]); return 0; } - /* Unless the command is REQUEST SENSE, clear the sense. This will *NOT* - the UNIT ATTENTION condition if it's set. */ + if ((dev->drv->bus_type < HDD_BUS_SCSI) && + (scsi_disk_command_flags[cdb[0]] & SCSI_ONLY)) { + scsi_disk_log(dev->log, "Attempting to execute SCSI-only command %02X " + "over ATAPI\n", cdb[0]); + scsi_disk_illegal_opcode(dev, cdb[0]); + return 0; + } + + if ((dev->drv->bus_type == HDD_BUS_SCSI) && + (scsi_disk_command_flags[cdb[0]] & ATAPI_ONLY)) { + scsi_disk_log(dev->log, "Attempting to execute ATAPI-only command %02X " + "over SCSI\n", cdb[0]); + scsi_disk_illegal_opcode(dev, cdb[0]); + return 0; + } + + /* + Unless the command is REQUEST SENSE, clear the sense. This will *NOT* + the UNIT ATTENTION condition if it's set. + */ if (cdb[0] != GPCMD_REQUEST_SENSE) scsi_disk_sense_clear(dev, cdb[0]); - scsi_disk_log("SCSI HD %i: Continuing with command\n", dev->id); + scsi_disk_log(dev->log, "Continuing with command %02X\n", cdb[0]); return 1; } static void -scsi_disk_seek(scsi_disk_t *dev, uint32_t pos) +scsi_disk_seek(const scsi_disk_t *dev, const uint32_t pos) { - /* scsi_disk_log("SCSI HD %i: Seek %08X\n", dev->id, pos); */ + /* scsi_disk_log(dev->log, "Seek %08X\n", pos); */ hdd_image_seek(dev->id, pos); } static void scsi_disk_rezero(scsi_disk_t *dev) { - if (dev->id == 0xff) - return; - - dev->sector_pos = dev->sector_len = 0; - scsi_disk_seek(dev, 0); + if (dev->id != 0xff) { + dev->sector_pos = dev->sector_len = 0; + scsi_disk_seek(dev, 0); + } } void @@ -824,34 +869,38 @@ scsi_disk_reset(scsi_common_t *sc) dev->packet_status = PHASE_NONE; dev->unit_attention = 0; dev->cur_lun = SCSI_LUN_USE_CDB; + scsi_disk_sense_key = scsi_disk_asc = scsi_disk_ascq = dev->unit_attention = 0; + scsi_disk_info = 0x00; } void -scsi_disk_request_sense(scsi_disk_t *dev, uint8_t *buffer, uint8_t alloc_length, int desc) +scsi_disk_request_sense(scsi_disk_t *dev, uint8_t *buffer, + const uint8_t alloc_length, const int desc) { - /*Will return 18 bytes of 0*/ + /* Will return 18 bytes of 0. */ if (alloc_length != 0) { memset(buffer, 0, alloc_length); - if (!desc) - memcpy(buffer, dev->sense, alloc_length); - else { + if (desc) { buffer[1] = scsi_disk_sense_key; buffer[2] = scsi_disk_asc; buffer[3] = scsi_disk_ascq; - } - } else - return; + } else + memcpy(buffer, dev->sense, alloc_length); - buffer[0] = 0x70; + buffer[0] = desc ? 0x70 : 0xf0; + buffer[7] = 10; - scsi_disk_log("SCSI HD %i: Reporting sense: %02X %02X %02X\n", dev->id, buffer[2], buffer[12], buffer[13]); + scsi_disk_log(dev->log, "Reporting sense: %02X %02X %02X\n", + buffer[2], buffer[12], buffer[13]); - /* Clear the sense stuff as per the spec. */ - scsi_disk_sense_clear(dev, GPCMD_REQUEST_SENSE); + /* Clear the sense stuff as per the spec. */ + scsi_disk_sense_clear(dev, GPCMD_REQUEST_SENSE); + } } static void -scsi_disk_request_sense_for_scsi(scsi_common_t *sc, uint8_t *buffer, uint8_t alloc_length) +scsi_disk_request_sense_for_scsi(scsi_common_t *sc, uint8_t *buffer, + const uint8_t alloc_length) { scsi_disk_t *dev = (scsi_disk_t *) sc; @@ -859,41 +908,42 @@ scsi_disk_request_sense_for_scsi(scsi_common_t *sc, uint8_t *buffer, uint8_t all } static void -scsi_disk_set_buf_len(scsi_disk_t *dev, int32_t *BufLen, int32_t *src_len) +scsi_disk_set_buf_len(const scsi_disk_t *dev, int32_t *BufLen, int32_t *src_len) { - if (dev->drv->bus == HDD_BUS_SCSI) { + if (dev->drv->bus_type == HDD_BUS_SCSI) { if (*BufLen == -1) *BufLen = *src_len; else { *BufLen = MIN(*src_len, *BufLen); *src_len = *BufLen; } - scsi_disk_log("SCSI HD %i: Actual transfer length: %i\n", dev->id, *BufLen); + scsi_disk_log(dev->log, "Actual transfer length: %i\n", *BufLen); } } static void -scsi_disk_command(scsi_common_t *sc, uint8_t *cdb) +scsi_disk_command(scsi_common_t *sc, const uint8_t *cdb) { - scsi_disk_t *dev = (scsi_disk_t *) sc; - int ret; - int32_t blen = 0; - int32_t *BufLen; - int32_t len; - int32_t max_len; - int32_t alloc_length; - int pos = 0; - int idx = 0; - unsigned size_idx; - unsigned preamble_len; - uint32_t last_sector = 0; - char device_identify[9] = { '8', '6', 'B', '_', 'H', 'D', '0', '0', 0 }; - char device_identify_ex[15] = { '8', '6', 'B', '_', 'H', 'D', '0', '0', ' ', 'v', '1', '.', '0', '0', 0 }; - int block_desc = 0; - uint8_t scsi_bus = (dev->drv->scsi_id >> 4) & 0x0f; - uint8_t scsi_id = dev->drv->scsi_id & 0x0f; + char device_identify[9] = { '8', '6', 'B', '_', 'H', 'D', '0', '0', 0 }; + char device_identify_ex[15] = { '8', '6', 'B', '_', 'H', 'D', '0', '0', ' ', + 'v', '1', '.', '0', '0', 0 }; + scsi_disk_t * dev = (scsi_disk_t *) sc; + const uint32_t last_sector = hdd_image_get_last_sector(dev->id); + const uint8_t scsi_bus = (dev->drv->scsi_id >> 4) & 0x0f; + const uint8_t scsi_id = dev->drv->scsi_id & 0x0f; + int32_t blen = 0; + int pos = 0; + int idx = 0; + int block_desc; + int ret; + int32_t * BufLen; + int32_t len; + int32_t max_len; + int32_t alloc_length; + unsigned size_idx; + unsigned preamble_len; - if (dev->drv->bus == HDD_BUS_SCSI) { + if (dev->drv->bus_type == HDD_BUS_SCSI) { BufLen = &scsi_devices[scsi_bus][scsi_id].buffer_length; dev->tf->status &= ~ERR_STAT; } else { @@ -901,8 +951,6 @@ scsi_disk_command(scsi_common_t *sc, uint8_t *cdb) dev->tf->error = 0; } - last_sector = hdd_image_get_last_sector(dev->id); - dev->packet_len = 0; dev->request_pos = 0; @@ -918,11 +966,12 @@ scsi_disk_command(scsi_common_t *sc, uint8_t *cdb) memcpy(dev->current_cdb, cdb, 12); if (cdb[0] != 0) { - scsi_disk_log("SCSI HD %i: Command 0x%02X, Sense Key %02X, Asc %02X, Ascq %02X\n", - dev->id, cdb[0], scsi_disk_sense_key, scsi_disk_asc, scsi_disk_ascq); - scsi_disk_log("SCSI HD %i: Request length: %04X\n", dev->id, dev->tf->request_length); + scsi_disk_log(dev->log, "Command 0x%02X, Sense Key %02X, Asc %02X, Ascq %02X\n", + cdb[0], scsi_disk_sense_key, scsi_disk_asc, scsi_disk_ascq); + scsi_disk_log(dev->log, "Request length: %04X\n", dev->tf->request_length); - scsi_disk_log("SCSI HD %i: CDB: %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X\n", dev->id, + scsi_disk_log(dev->log, "CDB: %02X %02X %02X %02X %02X %02X %02X %02X " + "%02X %02X %02X %02X\n", cdb[0], cdb[1], cdb[2], cdb[3], cdb[4], cdb[5], cdb[6], cdb[7], cdb[8], cdb[9], cdb[10], cdb[11]); } @@ -931,14 +980,17 @@ scsi_disk_command(scsi_common_t *sc, uint8_t *cdb) scsi_disk_set_phase(dev, SCSI_PHASE_STATUS); - /* This handles the Not Ready/Unit Attention check if it has to be handled at this point. */ + /* + This handles the Not Ready/Unit Attention check if it has to be + handled at this point. + */ if (scsi_disk_pre_execution_check(dev, cdb) == 0) return; switch (cdb[0]) { case GPCMD_SEND_DIAGNOSTIC: if (!(cdb[1] & (1 << 2))) { - scsi_disk_invalid_field(dev); + scsi_disk_invalid_field(dev, cdb[1]); return; } fallthrough; @@ -961,9 +1013,6 @@ scsi_disk_command(scsi_common_t *sc, uint8_t *cdb) break; case GPCMD_REQUEST_SENSE: - /* If there's a unit attention condition and there's a buffered not - ready, a standalone REQUEST SENSE should forget about the not - ready, and report unit attention straight away. */ len = cdb[4]; if (!len) { @@ -977,14 +1026,11 @@ scsi_disk_command(scsi_common_t *sc, uint8_t *cdb) scsi_disk_buf_alloc(dev, 256); scsi_disk_set_buf_len(dev, BufLen, &len); - if (*BufLen < cdb[4]) - cdb[4] = *BufLen; - len = (cdb[1] & 1) ? 8 : 18; scsi_disk_request_sense(dev, dev->temp_buffer, *BufLen, cdb[1] & 1); scsi_disk_set_phase(dev, SCSI_PHASE_DATA_IN); - scsi_disk_data_command_finish(dev, len, len, cdb[4], 0); + scsi_disk_data_command_finish(dev, len, len, *BufLen, 0); break; case GPCMD_MECHANISM_STATUS: @@ -1020,12 +1066,15 @@ scsi_disk_command(scsi_common_t *sc, uint8_t *cdb) break; case GPCMD_READ_10: dev->sector_len = (cdb[7] << 8) | cdb[8]; - dev->sector_pos = (cdb[2] << 24) | (cdb[3] << 16) | (cdb[4] << 8) | cdb[5]; + dev->sector_pos = (cdb[2] << 24) | (cdb[3] << 16) | + (cdb[4] << 8) | cdb[5]; break; case GPCMD_READ_12: - dev->sector_len = (((uint32_t) cdb[6]) << 24) | (((uint32_t) cdb[7]) << 16) | + dev->sector_len = (((uint32_t) cdb[6]) << 24) | + (((uint32_t) cdb[7]) << 16) | (((uint32_t) cdb[8]) << 8) | ((uint32_t) cdb[9]); - dev->sector_pos = (((uint32_t) cdb[2]) << 24) | (((uint32_t) cdb[3]) << 16) | + dev->sector_pos = (((uint32_t) cdb[2]) << 24) | + (((uint32_t) cdb[3]) << 16) | (((uint32_t) cdb[4]) << 8) | ((uint32_t) cdb[5]); break; @@ -1033,54 +1082,45 @@ scsi_disk_command(scsi_common_t *sc, uint8_t *cdb) break; } - if (dev->sector_pos > last_sector) { + if (dev->sector_pos > last_sector) scsi_disk_lba_out_of_range(dev); - return; + else { + if (dev->sector_len) { + max_len = dev->sector_len; + dev->requested_blocks = max_len; + + dev->packet_len = max_len * alloc_length; + scsi_disk_buf_alloc(dev, dev->packet_len); + + dev->drv->seek_pos = dev->sector_pos; + dev->drv->seek_len = dev->sector_len; + + ret = scsi_disk_blocks(dev, &alloc_length, 1, 0); + if (ret > 0) { + dev->requested_blocks = max_len; + dev->packet_len = alloc_length; + + scsi_disk_set_buf_len(dev, BufLen, (int32_t *) &dev->packet_len); + + scsi_disk_data_command_finish(dev, alloc_length, 512, alloc_length, 0); + + ui_sb_update_icon(SB_HDD | dev->drv->bus_type, dev->packet_status != PHASE_COMPLETE); + } else { + scsi_disk_set_phase(dev, SCSI_PHASE_STATUS); + dev->packet_status = (ret < 0) ? PHASE_ERROR : PHASE_COMPLETE; + dev->callback = 20.0 * SCSI_TIME; + scsi_disk_set_callback(dev); + scsi_disk_buf_free(dev); + } + } else { + scsi_disk_set_phase(dev, SCSI_PHASE_STATUS); + scsi_disk_log(dev->log, "All done - callback set\n"); + dev->packet_status = PHASE_COMPLETE; + dev->callback = 20.0 * SCSI_TIME; + scsi_disk_set_callback(dev); + } } - - if (!dev->sector_len) { - scsi_disk_set_phase(dev, SCSI_PHASE_STATUS); - scsi_disk_log("SCSI HD %i: All done - callback set\n", dev->id); - dev->packet_status = PHASE_COMPLETE; - dev->callback = 20.0 * SCSI_TIME; - scsi_disk_set_callback(dev); - break; - } - - max_len = dev->sector_len; - /* - If we're reading all blocks in one go for DMA, why not also for - PIO, it should NOT matter anyway, this step should be identical - and only the way the read dat is transferred to the host should - be different. - */ - dev->requested_blocks = max_len; - - dev->packet_len = max_len * alloc_length; - scsi_disk_buf_alloc(dev, dev->packet_len); - - dev->drv->seek_pos = dev->sector_pos; - dev->drv->seek_len = dev->sector_len; - - ret = scsi_disk_blocks(dev, &alloc_length, 1, 0); - if (ret <= 0) { - scsi_disk_set_phase(dev, SCSI_PHASE_STATUS); - dev->packet_status = (ret < 0) ? PHASE_ERROR : PHASE_COMPLETE; - dev->callback = 20.0 * SCSI_TIME; - scsi_disk_set_callback(dev); - scsi_disk_buf_free(dev); - return; - } - - dev->requested_blocks = max_len; - dev->packet_len = alloc_length; - - scsi_disk_set_buf_len(dev, BufLen, (int32_t *) &dev->packet_len); - - scsi_disk_data_command_finish(dev, alloc_length, 512, alloc_length, 0); - - ui_sb_update_icon(SB_HDD | dev->drv->bus, dev->packet_status != PHASE_COMPLETE); - return; + break; case GPCMD_VERIFY_6: case GPCMD_VERIFY_10: @@ -1111,23 +1151,26 @@ scsi_disk_command(scsi_common_t *sc, uint8_t *cdb) dev->sector_len = 256; dev->sector_pos = ((((uint32_t) cdb[1]) & 0x1f) << 16) | (((uint32_t) cdb[2]) << 8) | ((uint32_t) cdb[3]); - scsi_disk_log("SCSI HD %i: Length: %i, LBA: %i\n", dev->id, + scsi_disk_log(dev->log, "Length: %i, LBA: %i\n", dev->sector_len, dev->sector_pos); break; case GPCMD_VERIFY_10: case GPCMD_WRITE_10: case GPCMD_WRITE_AND_VERIFY_10: dev->sector_len = (cdb[7] << 8) | cdb[8]; - dev->sector_pos = (cdb[2] << 24) | (cdb[3] << 16) | (cdb[4] << 8) | cdb[5]; - scsi_disk_log("SCSI HD %i: Length: %i, LBA: %i\n", dev->id, + dev->sector_pos = (cdb[2] << 24) | (cdb[3] << 16) | + (cdb[4] << 8) | cdb[5]; + scsi_disk_log(dev->log, "Length: %i, LBA: %i\n", dev->sector_len, dev->sector_pos); break; case GPCMD_VERIFY_12: case GPCMD_WRITE_12: case GPCMD_WRITE_AND_VERIFY_12: - dev->sector_len = (((uint32_t) cdb[6]) << 24) | (((uint32_t) cdb[7]) << 16) | + dev->sector_len = (((uint32_t) cdb[6]) << 24) | + (((uint32_t) cdb[7]) << 16) | (((uint32_t) cdb[8]) << 8) | ((uint32_t) cdb[9]); - dev->sector_pos = (((uint32_t) cdb[2]) << 24) | (((uint32_t) cdb[3]) << 16) | + dev->sector_pos = (((uint32_t) cdb[2]) << 24) | + (((uint32_t) cdb[3]) << 16) | (((uint32_t) cdb[4]) << 8) | ((uint32_t) cdb[5]); break; @@ -1135,90 +1178,79 @@ scsi_disk_command(scsi_common_t *sc, uint8_t *cdb) break; } - if (dev->sector_pos > last_sector) { + if (dev->sector_pos > last_sector) scsi_disk_lba_out_of_range(dev); - return; + else { + if (dev->sector_len) { + dev->drv->seek_pos = dev->sector_pos; + dev->drv->seek_len = dev->sector_len; + + max_len = dev->sector_len; + dev->requested_blocks = max_len; + + dev->packet_len = max_len * alloc_length; + scsi_disk_buf_alloc(dev, dev->packet_len); + + dev->requested_blocks = max_len; + dev->packet_len = max_len << 9; + + scsi_disk_set_buf_len(dev, BufLen, (int32_t *) &dev->packet_len); + + scsi_disk_data_command_finish(dev, dev->packet_len, 512, dev->packet_len, 1); + + ui_sb_update_icon(SB_HDD | dev->drv->bus_type, dev->packet_status != PHASE_COMPLETE); + } else { + scsi_disk_set_phase(dev, SCSI_PHASE_STATUS); + scsi_disk_log(dev->log, "All done - callback set\n"); + dev->packet_status = PHASE_COMPLETE; + dev->callback = 20.0 * SCSI_TIME; + scsi_disk_set_callback(dev); + } } - - if (!dev->sector_len) { - scsi_disk_set_phase(dev, SCSI_PHASE_STATUS); - scsi_disk_log("SCSI HD %i: All done - callback set\n", dev->id); - dev->packet_status = PHASE_COMPLETE; - dev->callback = 20.0 * SCSI_TIME; - scsi_disk_set_callback(dev); - break; - } - - dev->drv->seek_pos = dev->sector_pos; - dev->drv->seek_len = dev->sector_len; - - max_len = dev->sector_len; - /* - If we're writing all blocks in one go for DMA, why not also for - PIO, it should NOT matter anyway, this step should be identical - and only the way the read dat is transferred to the host should - be different. - */ - dev->requested_blocks = max_len; - - dev->packet_len = max_len * alloc_length; - scsi_disk_buf_alloc(dev, dev->packet_len); - - dev->requested_blocks = max_len; - dev->packet_len = max_len << 9; - - scsi_disk_set_buf_len(dev, BufLen, (int32_t *) &dev->packet_len); - - scsi_disk_data_command_finish(dev, dev->packet_len, 512, dev->packet_len, 1); - - ui_sb_update_icon(SB_HDD | dev->drv->bus, dev->packet_status != PHASE_COMPLETE); - return; + break; case GPCMD_WRITE_SAME_10: alloc_length = 512; - if ((cdb[1] & 6) == 6) { - scsi_disk_invalid_field(dev); - return; + if ((cdb[1] & 6) == 6) + scsi_disk_invalid_field(dev, cdb[1]); + else { + dev->sector_len = (cdb[7] << 8) | cdb[8]; + dev->sector_pos = (cdb[2] << 24) | (cdb[3] << 16) | (cdb[4] << 8) | cdb[5]; + + if (dev->sector_pos > last_sector) + scsi_disk_lba_out_of_range(dev); + else { + if (dev->sector_len) { + scsi_disk_buf_alloc(dev, alloc_length); + scsi_disk_set_buf_len(dev, BufLen, (int32_t *) &dev->packet_len); + + dev->requested_blocks = 1; + + dev->packet_len = alloc_length; + + scsi_disk_set_phase(dev, SCSI_PHASE_DATA_OUT); + + scsi_disk_data_command_finish(dev, 512, 512, alloc_length, 1); + + ui_sb_update_icon(SB_HDD | dev->drv->bus_type, + dev->packet_status != PHASE_COMPLETE); + } else { + scsi_disk_set_phase(dev, SCSI_PHASE_STATUS); + scsi_disk_log(dev->log, "All done - callback set\n"); + dev->packet_status = PHASE_COMPLETE; + dev->callback = 20.0 * SCSI_TIME; + scsi_disk_set_callback(dev); + } + } } - - dev->sector_len = (cdb[7] << 8) | cdb[8]; - dev->sector_pos = (cdb[2] << 24) | (cdb[3] << 16) | (cdb[4] << 8) | cdb[5]; - - if (dev->sector_pos > last_sector) { - scsi_disk_lba_out_of_range(dev); - return; - } - - if (!dev->sector_len) { - scsi_disk_set_phase(dev, SCSI_PHASE_STATUS); - scsi_disk_log("SCSI HD %i: All done - callback set\n", dev->id); - dev->packet_status = PHASE_COMPLETE; - dev->callback = 20.0 * SCSI_TIME; - scsi_disk_set_callback(dev); - break; - } - - scsi_disk_buf_alloc(dev, alloc_length); - scsi_disk_set_buf_len(dev, BufLen, (int32_t *) &dev->packet_len); - - max_len = 1; - dev->requested_blocks = 1; - - dev->packet_len = alloc_length; - - scsi_disk_set_phase(dev, SCSI_PHASE_DATA_OUT); - - scsi_disk_data_command_finish(dev, 512, 512, alloc_length, 1); - - ui_sb_update_icon(SB_HDD | dev->drv->bus, dev->packet_status != PHASE_COMPLETE); - return; + break; case GPCMD_MODE_SENSE_6: case GPCMD_MODE_SENSE_10: scsi_disk_set_phase(dev, SCSI_PHASE_DATA_IN); - if (dev->drv->bus == HDD_BUS_SCSI) + if (dev->drv->bus_type == HDD_BUS_SCSI) block_desc = ((cdb[1] >> 3) & 1) ? 0 : 1; else block_desc = 0; @@ -1235,7 +1267,8 @@ scsi_disk_command(scsi_common_t *sc, uint8_t *cdb) alloc_length = len; if (cdb[0] == GPCMD_MODE_SENSE_6) { - len = scsi_disk_mode_sense(dev, dev->temp_buffer, 4, cdb[2], block_desc); + len = scsi_disk_mode_sense(dev, dev->temp_buffer, 4, + cdb[2], block_desc); if (len > alloc_length) len = alloc_length; dev->temp_buffer[0] = len - 1; @@ -1261,10 +1294,10 @@ scsi_disk_command(scsi_common_t *sc, uint8_t *cdb) alloc_length = len; scsi_disk_set_buf_len(dev, BufLen, &alloc_length); - scsi_disk_log("SCSI HDD %i: Reading mode page: %02X...\n", dev->id, cdb[2]); + scsi_disk_log(dev->log, "Reading mode page: %02X...\n", cdb[2]); scsi_disk_data_command_finish(dev, len, len, alloc_length, 0); - return; + break; case GPCMD_MODE_SELECT_6: case GPCMD_MODE_SELECT_10: @@ -1282,7 +1315,7 @@ scsi_disk_command(scsi_common_t *sc, uint8_t *cdb) dev->total_length = len; dev->do_page_save = cdb[1] & 1; scsi_disk_data_command_finish(dev, len, len, len, 1); - return; + break; case GPCMD_INQUIRY: max_len = cdb[3]; @@ -1291,7 +1324,7 @@ scsi_disk_command(scsi_common_t *sc, uint8_t *cdb) if ((!max_len) || (*BufLen == 0)) { scsi_disk_set_phase(dev, SCSI_PHASE_STATUS); - /* scsi_disk_log("SCSI HD %i: All done - callback set\n", dev->id); */ + /* scsi_disk_log(dev->log, "All done - callback set\n"); */ dev->packet_status = PHASE_COMPLETE; dev->callback = 20.0 * SCSI_TIME; break; @@ -1317,7 +1350,7 @@ scsi_disk_command(scsi_common_t *sc, uint8_t *cdb) case 0x83: if (idx + 24 > max_len) { scsi_disk_buf_free(dev); - scsi_disk_data_phase_error(dev); + scsi_disk_data_phase_error(dev, idx + 24); return; } @@ -1325,7 +1358,8 @@ scsi_disk_command(scsi_common_t *sc, uint8_t *cdb) dev->temp_buffer[idx++] = 0x00; dev->temp_buffer[idx++] = 0x00; dev->temp_buffer[idx++] = 20; - ide_padstr8(dev->temp_buffer + idx, 20, "53R141"); /* Serial */ + /* Serial */ + ide_padstr8(dev->temp_buffer + idx, 20, "53R141"); idx += 20; if (idx + 72 > cdb[4]) @@ -1334,16 +1368,19 @@ scsi_disk_command(scsi_common_t *sc, uint8_t *cdb) dev->temp_buffer[idx++] = 0x01; dev->temp_buffer[idx++] = 0x00; dev->temp_buffer[idx++] = 68; - ide_padstr8(dev->temp_buffer + idx, 8, EMU_NAME); /* Vendor */ + /* Vendor */ + ide_padstr8(dev->temp_buffer + idx, 8, EMU_NAME); idx += 8; - ide_padstr8(dev->temp_buffer + idx, 40, device_identify_ex); /* Product */ + /* Product */ + ide_padstr8(dev->temp_buffer + idx, 40, device_identify_ex); idx += 40; - ide_padstr8(dev->temp_buffer + idx, 20, "53R141"); /* Product */ + /* Product */ + ide_padstr8(dev->temp_buffer + idx, 20, "53R141"); idx += 20; break; default: - scsi_disk_log("INQUIRY: Invalid page: %02X\n", cdb[2]); - scsi_disk_invalid_field(dev); + scsi_disk_log(dev->log, "INQUIRY: Invalid page: %02X\n", cdb[2]); + scsi_disk_invalid_field(dev, cdb[2]); scsi_disk_buf_free(dev); return; } @@ -1353,19 +1390,23 @@ scsi_disk_command(scsi_common_t *sc, uint8_t *cdb) memset(dev->temp_buffer, 0, 8); if ((cdb[1] & 0xe0) || ((dev->cur_lun > 0x00) && (dev->cur_lun < 0xff))) - dev->temp_buffer[0] = 0x7f; /*No physical device on this LUN*/ + dev->temp_buffer[0] = 0x7f; /* No physical device on this LUN */ else - dev->temp_buffer[0] = 0; /*SCSI HD*/ - dev->temp_buffer[1] = 0; /*Fixed*/ - dev->temp_buffer[2] = (dev->drv->bus == HDD_BUS_SCSI) ? 0x02 : 0x00; /*SCSI-2 compliant*/ - dev->temp_buffer[3] = (dev->drv->bus == HDD_BUS_SCSI) ? 0x02 : 0x21; + dev->temp_buffer[0] = 0; /* SCSI HD */ + dev->temp_buffer[1] = 0; /* Fixed */ + /* SCSI-2 compliant */ + dev->temp_buffer[2] = (dev->drv->bus_type == HDD_BUS_SCSI) ? 0x02 : 0x00; + dev->temp_buffer[3] = (dev->drv->bus_type == HDD_BUS_SCSI) ? 0x02 : 0x21; dev->temp_buffer[4] = 31; - dev->temp_buffer[6] = 1; /* 16-bit transfers supported */ - dev->temp_buffer[7] = 0x20; /* Wide bus supported */ + dev->temp_buffer[6] = 1; /* 16-bit transfers supported */ + dev->temp_buffer[7] = 0x20; /* Wide bus supported */ - ide_padstr8(dev->temp_buffer + 8, 8, EMU_NAME); /* Vendor */ - ide_padstr8(dev->temp_buffer + 16, 16, device_identify); /* Product */ - ide_padstr8(dev->temp_buffer + 32, 4, EMU_VERSION_EX); /* Revision */ + /* Vendor */ + ide_padstr8(dev->temp_buffer + 8, 8, EMU_NAME); + /* Product */ + ide_padstr8(dev->temp_buffer + 16, 16, device_identify); + /* Revision */ + ide_padstr8(dev->temp_buffer + 32, 4, EMU_VERSION_EX); idx = 36; if (max_len == 96) { @@ -1437,12 +1478,12 @@ atapi_out: break; default: - scsi_disk_illegal_opcode(dev); + scsi_disk_illegal_opcode(dev, cdb[0]); break; } - /* scsi_disk_log("SCSI HD %i: Phase: %02X, request length: %i\n", dev->id, dev->tf->phase, - dev->tf->request_length); */ + /* scsi_disk_log(dev->log, "Phase: %02X, request length: %i\n", + dev->tf->phase, dev->tf->request_length); */ if ((dev->packet_status == PHASE_COMPLETE) || (dev->packet_status == PHASE_ERROR)) scsi_disk_buf_free(dev); @@ -1460,35 +1501,30 @@ scsi_disk_command_stop(scsi_common_t *sc) static uint8_t scsi_disk_phase_data_out(scsi_common_t *sc) { - scsi_disk_t *dev = (scsi_disk_t *) sc; - uint8_t scsi_bus = (dev->drv->scsi_id >> 4) & 0x0f; - uint8_t scsi_id = dev->drv->scsi_id & 0x0f; + scsi_disk_t *dev = (scsi_disk_t *) sc; + const uint8_t scsi_bus = (dev->drv->scsi_id >> 4) & 0x0f; + const uint8_t scsi_id = dev->drv->scsi_id & 0x0f; + const int32_t *BufLen = &scsi_devices[scsi_bus][scsi_id].buffer_length; + const uint32_t last_sector = hdd_image_get_last_sector(dev->id); + int len = 0; + uint8_t error = 0; + int ret = 1; int i; - const int32_t *BufLen = &scsi_devices[scsi_bus][scsi_id].buffer_length; - uint32_t last_sector = hdd_image_get_last_sector(dev->id); - uint32_t c; - uint32_t h; - uint32_t s; - int len = 0; - uint32_t last_to_write = 0; + uint32_t last_to_write; uint16_t block_desc_len; uint16_t pos; uint16_t param_list_len; uint8_t hdr_len; uint8_t val; - uint8_t old_val; - uint8_t ch; - uint8_t error = 0; - uint8_t page; - uint8_t page_len; - if (!*BufLen) { + if (!*BufLen) scsi_disk_set_phase(dev, SCSI_PHASE_STATUS); + else switch (dev->current_cdb[0]) { + default: + log_fatal(dev->log, "Bad Command for phase 2 (%02X)\n", dev->current_cdb[0]); + ret = 0; + break; - return 1; - } - - switch (dev->current_cdb[0]) { case GPCMD_VERIFY_6: case GPCMD_VERIFY_10: case GPCMD_VERIFY_12: @@ -1514,9 +1550,9 @@ scsi_disk_phase_data_out(scsi_common_t *sc) dev->temp_buffer[2] = (i >> 8) & 0xff; dev->temp_buffer[3] = i & 0xff; } else if (dev->current_cdb[1] & 4) { - s = (i % dev->drv->spt); - h = ((i - s) / dev->drv->spt) % dev->drv->hpc; - c = ((i - s) / dev->drv->spt) / dev->drv->hpc; + uint32_t s = (i % dev->drv->spt); + uint32_t h = ((i - s) / dev->drv->spt) % dev->drv->hpc; + uint32_t c = ((i - s) / dev->drv->spt) / dev->drv->hpc; dev->temp_buffer[0] = (c >> 16) & 0xff; dev->temp_buffer[1] = (c >> 8) & 0xff; dev->temp_buffer[2] = c & 0xff; @@ -1542,7 +1578,7 @@ scsi_disk_phase_data_out(scsi_common_t *sc) param_list_len = dev->current_cdb[4]; } - if (dev->drv->bus == HDD_BUS_SCSI) { + if (dev->drv->bus_type == HDD_BUS_SCSI) { if (dev->current_cdb[0] == GPCMD_MODE_SELECT_6) { block_desc_len = dev->temp_buffer[2]; block_desc_len <<= 8; @@ -1559,27 +1595,29 @@ scsi_disk_phase_data_out(scsi_common_t *sc) while (1) { if (pos >= param_list_len) { - scsi_disk_log("SCSI HD %i: Buffer has only block descriptor\n", dev->id); + scsi_disk_log(dev->log, "Buffer has only block descriptor\n"); break; } - page = dev->temp_buffer[pos] & 0x3F; - page_len = dev->temp_buffer[pos + 1]; + const uint8_t page = dev->temp_buffer[pos] & 0x3f; + const uint8_t page_len = dev->temp_buffer[pos + 1]; pos += 2; if (!(scsi_disk_mode_sense_page_flags & (1LL << ((uint64_t) page)))) error |= 1; - else { - for (i = 0; i < page_len; i++) { - ch = scsi_disk_mode_sense_pages_changeable.pages[page][i + 2]; - val = dev->temp_buffer[pos + i]; - old_val = dev->ms_pages_saved.pages[page][i + 2]; - if (val != old_val) { - if (ch) - dev->ms_pages_saved.pages[page][i + 2] = val; - else - error |= 1; + else for (i = 0; i < page_len; i++) { + const uint8_t old = dev->ms_pages_saved.pages[page][i + 2]; + const uint8_t ch = scsi_disk_mode_sense_pages_changeable.pages[page][i + 2]; + + val = dev->temp_buffer[pos + i]; + + if (val != old) { + if (ch) + dev->ms_pages_saved.pages[page][i + 2] = val; + else { + scsi_disk_invalid_field_pl(dev, val); + error |= 1; } } } @@ -1594,22 +1632,17 @@ scsi_disk_phase_data_out(scsi_common_t *sc) break; } - if (error) { + if (error) scsi_disk_buf_free(dev); - scsi_disk_invalid_field_pl(dev); - } - break; - default: - fatal("SCSI HDD %i: Bad Command for phase 2 (%02X)\n", dev->id, dev->current_cdb[0]); break; } scsi_disk_command_stop((scsi_common_t *) dev); - return 1; + return ret; } static int -scsi_disk_get_max(int ide_has_dma, int type) +scsi_disk_get_max(UNUSED(const ide_t *ide), int ide_has_dma, const int type) { int ret; @@ -1635,7 +1668,7 @@ scsi_disk_get_max(int ide_has_dma, int type) } static int -scsi_disk_get_timings(int ide_has_dma, int type) +scsi_disk_get_timings(UNUSED(const ide_t *ide), const int ide_has_dma, const int type) { int ret; @@ -1657,29 +1690,28 @@ scsi_disk_get_timings(int ide_has_dma, int type) return ret; } -/** - * Fill in ide->buffer with the output of the "IDENTIFY PACKET DEVICE" command +/* + Fill in ide->buffer with the output of the "IDENTIFY PACKET DEVICE" command */ static void -scsi_disk_identify(ide_t *ide, int ide_has_dma) +scsi_disk_identify(const ide_t *ide, const int ide_has_dma) { - const scsi_disk_t *dev; - char device_identify[9] = { '8', '6', 'B', '_', 'H', 'D', '0', '0', 0 }; - - dev = (scsi_disk_t *) ide->sc; + const scsi_disk_t *dev = (scsi_disk_t *) ide->sc; + char device_identify[9] = { '8', '6', 'B', '_', 'H', 'D', '0', '0', 0 }; device_identify[7] = dev->id + 0x30; - scsi_disk_log("ATAPI Identify: %s\n", device_identify); + scsi_disk_log(dev->log, "ATAPI Identify: %s\n", device_identify); /* ATAPI device, direct-access device, non-removable media, accelerated DRQ */ ide->buffer[0] = 0x8000 | (0 << 8) | 0x00 | (2 << 5); - ide_padstr((char *) (ide->buffer + 10), "", 20); /* Serial Number */ + ide_padstr((char *) (ide->buffer + 10), "", 20); /* Serial Number */ - ide_padstr((char *) (ide->buffer + 23), EMU_VERSION_EX, 8); /* Firmware */ - ide_padstr((char *) (ide->buffer + 27), device_identify, 40); /* Model */ + ide_padstr((char *) (ide->buffer + 23), EMU_VERSION_EX, 8); /* Firmware */ + ide_padstr((char *) (ide->buffer + 27), device_identify, 40); /* Model */ - ide->buffer[49] = 0x200; /* LBA supported */ - ide->buffer[126] = 0xfffe; /* Interpret zero byte count limit as maximum length */ + ide->buffer[49] = 0x200; /* LBA supported */ + /* Interpret zero byte count limit as maximum length. */ + ide->buffer[126] = 0xfffe; if (ide_has_dma) { ide->buffer[71] = 30; @@ -1693,19 +1725,13 @@ void scsi_disk_hard_reset(void) { scsi_disk_t *dev; - scsi_device_t *sd; - ide_t *id; - uint8_t scsi_bus; - uint8_t scsi_id; - uint8_t valid = 0; for (uint8_t c = 0; c < HDD_NUM; c++) { - valid = 0; - if (hdd[c].bus == HDD_BUS_SCSI) { - scsi_disk_log("SCSI disk hard_reset drive=%d\n", c); + uint8_t valid = 0; - scsi_bus = (hdd[c].scsi_id >> 4) & 0x0f; - scsi_id = hdd[c].scsi_id & 0x0f; + if (hdd[c].bus_type == HDD_BUS_SCSI) { + const uint8_t scsi_bus = (hdd[c].scsi_id >> 4) & 0x0f; + const uint8_t scsi_id = hdd[c].scsi_id & 0x0f; /* Make sure to ignore any SCSI disk that has an out of range SCSI bus. */ if (scsi_bus >= SCSI_BUS_MAX) @@ -1727,16 +1753,25 @@ scsi_disk_hard_reset(void) hdd_preset_apply(c); - if (!hdd[c].priv) - hdd[c].priv = (scsi_disk_t *) calloc(1, sizeof(scsi_disk_t)); + if (hdd[c].priv == NULL) { + hdd[c].priv = (scsi_disk_t *) calloc(1, sizeof(scsi_disk_t)); + dev = (scsi_disk_t *) hdd[c].priv; + + char n[1024] = { 0 }; + + sprintf(n, "HDD %i SCSI ", c + 1); + dev->log = log_open(n); + } dev = (scsi_disk_t *) hdd[c].priv; - if (!dev->tf) + scsi_disk_log(dev->log, "SCSI disk hard_reset drive=%d\n", c); + + if (dev->tf == NULL) dev->tf = (ide_tf_t *) calloc(1, sizeof(ide_tf_t)); /* SCSI disk, attach to the SCSI bus. */ - sd = &scsi_devices[scsi_bus][scsi_id]; + scsi_device_t *sd = &scsi_devices[scsi_bus][scsi_id]; sd->sc = (scsi_common_t *) dev; sd->command = scsi_disk_command; @@ -1746,18 +1781,22 @@ scsi_disk_hard_reset(void) sd->command_stop = scsi_disk_command_stop; sd->type = SCSI_FIXED_DISK; - scsi_disk_log("SCSI disk %i attached to SCSI ID %i\n", c, hdd[c].scsi_id); - } else if (hdd[c].bus == HDD_BUS_ATAPI) { + scsi_disk_log(dev->log, "SCSI disk %i attached to SCSI ID %i\n", c, hdd[c].scsi_id); + } else if (hdd[c].bus_type == HDD_BUS_ATAPI) { /* Make sure to ignore any SCSI disk whose image file name is empty. */ if (strlen(hdd[c].fn) == 0) continue; /* Make sure to ignore any SCSI disk whose image fails to load. */ + /* ATAPI hard disk, attach to the IDE bus. */ - id = ide_get_drive(hdd[c].ide_channel); - /* If the IDE channel is initialized, we attach to it, + ide_t *id = ide_get_drive(hdd[c].ide_channel); + + /* + If the IDE channel is initialized, we attach to it, otherwise, we do nothing - it's going to be a drive - that's not attached to anything. */ + that's not attached to anything. + */ if (id) { if (!hdd_image_load(c)) continue; @@ -1766,7 +1805,7 @@ scsi_disk_hard_reset(void) hdd_preset_apply(c); - if (!hdd[c].priv) + if (hdd[c].priv == NULL) hdd[c].priv = (scsi_disk_t *) calloc(1, sizeof(scsi_disk_t)); dev = (scsi_disk_t *) hdd[c].priv; @@ -1786,12 +1825,15 @@ scsi_disk_hard_reset(void) id->interrupt_drq = 0; ide_atapi_attach(id); - } - scsi_disk_log("ATAPI hard disk drive %i attached to IDE channel %i\n", c, hdd[c].ide_channel); + scsi_disk_log(dev->log, "ATAPI hard disk drive %i attached to IDE channel %i\n", + c, hdd[c].ide_channel); + } } if (valid) { + dev = (scsi_disk_t *) hdd[c].priv; + dev->id = c; dev->drv = &hdd[c]; @@ -1807,28 +1849,32 @@ scsi_disk_hard_reset(void) void scsi_disk_close(void) { - scsi_disk_t *dev; - uint8_t scsi_bus; - uint8_t scsi_id; - for (uint8_t c = 0; c < HDD_NUM; c++) { - if ((hdd[c].bus == HDD_BUS_SCSI) || (hdd[c].bus == HDD_BUS_ATAPI)) { - if (hdd[c].bus == HDD_BUS_SCSI) { - scsi_bus = (hdd[c].scsi_id >> 4) & 0x0f; - scsi_id = hdd[c].scsi_id & 0x0f; + if ((hdd[c].bus_type == HDD_BUS_SCSI) || (hdd[c].bus_type == HDD_BUS_ATAPI)) { + if (hdd[c].bus_type == HDD_BUS_SCSI) { + const uint8_t scsi_bus = (hdd[c].scsi_id >> 4) & 0x0f; + const uint8_t scsi_id = hdd[c].scsi_id & 0x0f; memset(&scsi_devices[scsi_bus][scsi_id], 0x00, sizeof(scsi_device_t)); } hdd_image_close(c); - dev = hdd[c].priv; + scsi_disk_t *dev = hdd[c].priv; if (dev) { if (dev->tf) free(dev->tf); + if (dev->log != NULL) { + scsi_disk_log(dev->log, "Log closed\n"); + + log_close(dev->log); + dev->log = NULL; + } + free(dev); + hdd[c].priv = NULL; } } diff --git a/src/scsi/scsi_ncr5380.c b/src/scsi/scsi_ncr5380.c index e5dff88f8..048194a96 100644 --- a/src/scsi/scsi_ncr5380.c +++ b/src/scsi/scsi_ncr5380.c @@ -42,8 +42,6 @@ #include <86box/scsi_device.h> #include <86box/scsi_ncr5380.h> -int ncr5380_cmd_len[8] = { 6, 10, 10, 6, 16, 12, 10, 6 }; - #ifdef ENABLE_NCR5380_LOG int ncr5380_do_log = ENABLE_NCR5380_LOG; @@ -62,8 +60,6 @@ ncr5380_log(const char *fmt, ...) # define ncr5380_log(fmt, ...) #endif -#define SET_BUS_STATE(ncr, state) ncr->cur_bus = (ncr->cur_bus & ~(SCSI_PHASE_MESSAGE_IN)) | (state & (SCSI_PHASE_MESSAGE_IN)) - void ncr5380_irq(ncr_t *ncr, int set_irq) { @@ -86,45 +82,15 @@ ncr5380_set_irq(ncr_t *ncr, int irq) ncr->irq = irq; } -static int -ncr5380_get_dev_id(uint8_t data) -{ - for (uint8_t c = 0; c < SCSI_ID_MAX; c++) { - if (data & (1 << c)) - return c; - } - - return -1; -} - -static int -ncr5380_getmsglen(uint8_t *msgp, int len) -{ - uint8_t msg = msgp[0]; - if (msg == 0 || (msg >= 0x02 && msg <= 0x1f) || msg >= 0x80) - return 1; - if (msg >= 0x20 && msg <= 0x2f) - return 2; - if (len < 2) - return 3; - return msgp[1]; -} - static void ncr5380_reset(ncr_t *ncr) { - ncr->command_pos = 0; - ncr->data_pos = 0; - ncr->state = STATE_IDLE; - ncr->clear_req = 0; - ncr->cur_bus = 0; - ncr->tx_data = 0; + scsi_bus_t *scsi_bus = &ncr->scsibus; + ncr->output_data = 0; - ncr->data_wait = 0; ncr->mode = 0; ncr->tcr = 0; ncr->icr = 0; - ncr->dma_mode = DMA_IDLE; ncr5380_log("NCR Reset\n"); ncr->timer(ncr->priv, 0.0); @@ -132,6 +98,17 @@ ncr5380_reset(ncr_t *ncr) for (int i = 0; i < 8; i++) scsi_device_reset(&scsi_devices[ncr->bus][i]); + scsi_bus->state = STATE_IDLE; + scsi_bus->clear_req = 0; + scsi_bus->wait_complete = 0; + scsi_bus->wait_data = 0; + scsi_bus->bus_in = 0; + scsi_bus->bus_out = 0; + scsi_bus->command_pos = 0; + scsi_bus->data_wait = 0; + scsi_bus->data = 0; + scsi_bus->command_issued = 0; + ncr5380_irq(ncr, 0); } @@ -173,280 +150,10 @@ ncr5380_get_bus_host(ncr_t *ncr) return (bus_host | BUS_SETDATA(ncr->output_data)); } -void -ncr5380_bus_read(ncr_t *ncr) -{ - const scsi_device_t *dev; - int phase; - - /*Wait processes to handle bus requests*/ - if (ncr->clear_req) { - ncr->clear_req--; - if (!ncr->clear_req) { - ncr5380_log("Prelude to command data\n"); - SET_BUS_STATE(ncr, ncr->new_phase); - ncr->cur_bus |= BUS_REQ; - } - } - - if (ncr->wait_data) { - ncr->wait_data--; - if (!ncr->wait_data) { - dev = &scsi_devices[ncr->bus][ncr->target_id]; - SET_BUS_STATE(ncr, ncr->new_phase); - phase = (ncr->cur_bus & SCSI_PHASE_MESSAGE_IN); - - if (phase == SCSI_PHASE_DATA_IN) { - if ((ncr->dma_mode == DMA_IDLE) || ncr->dma_initiator_receive_ext || (ncr->wait_data_back == 1)) { - ncr5380_log("Phase Data In.\n"); - if ((dev->sc != NULL) && (dev->sc->temp_buffer != NULL)) - ncr->tx_data = dev->sc->temp_buffer[ncr->data_pos++]; - - ncr->state = STATE_DATAIN; - ncr->cur_bus = (ncr->cur_bus & ~BUS_DATAMASK) | BUS_SETDATA(ncr->tx_data) | BUS_DBP; - } - } else if (phase == SCSI_PHASE_DATA_OUT) { - if (ncr->new_phase & BUS_IDLE) { - ncr->state = STATE_IDLE; - ncr->cur_bus &= ~BUS_BSY; - } else { - if ((ncr->dma_mode == DMA_IDLE) || ncr->dma_send_ext || (ncr->wait_data_back == 1)) - ncr->state = STATE_DATAOUT; - } - } else if (phase == SCSI_PHASE_STATUS) { - ncr5380_log("Phase Status.\n"); - ncr->wait_data_back = 0; - ncr->cur_bus |= BUS_REQ; - ncr->state = STATE_STATUS; - ncr->cur_bus = (ncr->cur_bus & ~BUS_DATAMASK) | BUS_SETDATA(dev->status) | BUS_DBP; - } else if (phase == SCSI_PHASE_MESSAGE_IN) { - ncr5380_log("Phase Message In.\n"); - ncr->state = STATE_MESSAGEIN; - ncr->cur_bus = (ncr->cur_bus & ~BUS_DATAMASK) | BUS_SETDATA(0) | BUS_DBP; - } else if (phase == SCSI_PHASE_MESSAGE_OUT) { - ncr->cur_bus |= BUS_REQ; - ncr->state = STATE_MESSAGEOUT; - ncr->cur_bus = (ncr->cur_bus & ~BUS_DATAMASK) | BUS_SETDATA(ncr->target_id >> 5) | BUS_DBP; - } - } - } - - if (ncr->wait_complete) { - ncr->wait_complete--; - if (!ncr->wait_complete) - ncr->cur_bus |= BUS_REQ; - } -} - -void -ncr5380_bus_update(ncr_t *ncr, int bus) -{ - scsi_device_t *dev = &scsi_devices[ncr->bus][ncr->target_id]; - double p; - uint8_t sel_data; - int msglen; - - /*Start the SCSI command layer, which will also make the timings*/ - if (bus & BUS_ARB) - ncr->state = STATE_IDLE; - - ncr5380_log("State = %i\n", ncr->state); - - switch (ncr->state) { - case STATE_IDLE: - ncr->clear_req = ncr->wait_data = ncr->wait_complete = 0; - if ((bus & BUS_SEL) && !(bus & BUS_BSY)) { - ncr5380_log("Selection phase\n"); - sel_data = BUS_GETDATA(bus); - - ncr->target_id = ncr5380_get_dev_id(sel_data); - - ncr5380_log("Select - target ID = %i\n", ncr->target_id); - - /*Once the device has been found and selected, mark it as busy*/ - if ((ncr->target_id != (uint8_t) -1) && scsi_device_present(&scsi_devices[ncr->bus][ncr->target_id])) { - ncr->cur_bus |= BUS_BSY; - ncr->state = STATE_SELECT; - } else { - ncr5380_log("Device not found at ID %i, Current Bus BSY=%02x\n", ncr->target_id, ncr->cur_bus); - ncr->cur_bus = 0; - } - } - break; - case STATE_SELECT: - if (!(bus & BUS_SEL)) { - if (!(bus & BUS_ATN)) { - if ((ncr->target_id != (uint8_t) -1) && scsi_device_present(&scsi_devices[ncr->bus][ncr->target_id])) { - ncr5380_log("Device found at ID %i, Current Bus BSY=%02x\n", ncr->target_id, ncr->cur_bus); - ncr->state = STATE_COMMAND; - ncr->cur_bus = BUS_BSY | BUS_REQ; - ncr5380_log("CurBus BSY|REQ=%02x\n", ncr->cur_bus); - ncr->command_pos = 0; - SET_BUS_STATE(ncr, SCSI_PHASE_COMMAND); - } else { - ncr->state = STATE_IDLE; - ncr->cur_bus = 0; - } - } else { - ncr5380_log("Set to SCSI Message Out\n"); - ncr->new_phase = SCSI_PHASE_MESSAGE_OUT; - ncr->wait_data = 4; - ncr->msgout_pos = 0; - ncr->is_msgout = 1; - } - } - break; - case STATE_COMMAND: - if ((bus & BUS_ACK) && !(ncr->bus_in & BUS_ACK)) { - /*Write command byte to the output data register*/ - ncr->command[ncr->command_pos++] = BUS_GETDATA(bus); - ncr->clear_req = 3; - ncr->new_phase = ncr->cur_bus & SCSI_PHASE_MESSAGE_IN; - ncr->cur_bus &= ~BUS_REQ; - - ncr5380_log("Command pos=%i, output data=%02x\n", ncr->command_pos, BUS_GETDATA(bus)); - - if (ncr->command_pos == ncr5380_cmd_len[(ncr->command[0] >> 5) & 7]) { - if (ncr->is_msgout) { - ncr->is_msgout = 0; -#if 0 - ncr->command[1] = (ncr->command[1] & 0x1f) | (ncr->msglun << 5); -#endif - } - - /*Reset data position to default*/ - ncr->data_pos = 0; - - dev = &scsi_devices[ncr->bus][ncr->target_id]; - - ncr5380_log("SCSI Command 0x%02X for ID %d, status code=%02x\n", ncr->command[0], ncr->target_id, dev->status); - dev->buffer_length = -1; - scsi_device_command_phase0(dev, ncr->command); - ncr5380_log("SCSI ID %i: Command %02X: Buffer Length %i, SCSI Phase %02X\n", ncr->target_id, ncr->command[0], dev->buffer_length, dev->phase); - - ncr->period = 1.0; - ncr->wait_data = 4; - ncr->data_wait = 0; - - if (dev->status == SCSI_STATUS_OK) { - /*If the SCSI phase is Data In or Data Out, allocate the SCSI buffer based on the transfer length of the command*/ - if (dev->buffer_length && ((dev->phase == SCSI_PHASE_DATA_IN) || (dev->phase == SCSI_PHASE_DATA_OUT))) { - p = scsi_device_get_callback(dev); - ncr->period = (p > 0.0) ? p : (((double) dev->buffer_length) * 0.2); - ncr5380_log("SCSI ID %i: command 0x%02x for p = %lf, update = %lf, len = %i, dmamode = %x\n", ncr->target_id, ncr->command[0], scsi_device_get_callback(dev), ncr->period, dev->buffer_length, ncr->dma_mode); - } - } - ncr->new_phase = dev->phase; - } - } - break; - case STATE_DATAIN: - dev = &scsi_devices[ncr->bus][ncr->target_id]; - if ((bus & BUS_ACK) && !(ncr->bus_in & BUS_ACK)) { - if (ncr->data_pos >= dev->buffer_length) { - ncr->cur_bus &= ~BUS_REQ; - ncr5380_log("CMD Phase1 DataIn.\n"); - scsi_device_command_phase1(dev); - ncr->new_phase = SCSI_PHASE_STATUS; - ncr->wait_data = 4; - ncr->wait_complete = 8; - } else { - if ((dev->sc != NULL) && (dev->sc->temp_buffer != NULL)) - ncr->tx_data = dev->sc->temp_buffer[ncr->data_pos++]; - - ncr->cur_bus = (ncr->cur_bus & ~BUS_DATAMASK) | BUS_SETDATA(ncr->tx_data) | BUS_DBP | BUS_REQ; - if (ncr->dma_mode == DMA_IDLE) { /*If a data in command that is not read 6/10 has been issued*/ - ncr->data_wait |= 1; - ncr5380_log("DMA mode idle IN=%d.\n", ncr->data_pos); - ncr->timer(ncr->priv, ncr->period); - } else { - ncr5380_log("DMA mode IN=%d.\n", ncr->data_pos); - ncr->clear_req = 3; - } - - ncr->cur_bus &= ~BUS_REQ; - ncr->new_phase = SCSI_PHASE_DATA_IN; - } - } - break; - case STATE_DATAOUT: - dev = &scsi_devices[ncr->bus][ncr->target_id]; - if ((bus & BUS_ACK) && !(ncr->bus_in & BUS_ACK)) { - if ((dev->sc != NULL) && (dev->sc->temp_buffer != NULL)) - dev->sc->temp_buffer[ncr->data_pos++] = BUS_GETDATA(bus); - - if (ncr->data_pos >= dev->buffer_length) { - ncr->cur_bus &= ~BUS_REQ; - scsi_device_command_phase1(dev); - ncr->new_phase = SCSI_PHASE_STATUS; - ncr->wait_data = 4; - ncr->wait_complete = 8; - } else { - /*More data is to be transferred, place a request*/ - if (ncr->dma_mode == DMA_IDLE) { /*If a data out command that is not write 6/10 has been issued*/ - ncr->data_wait |= 1; - ncr5380_log("DMA mode idle out\n"); - ncr->timer(ncr->priv, ncr->period); - } else - ncr->clear_req = 3; - - ncr->cur_bus &= ~BUS_REQ; - ncr5380_log("CurBus ~REQ_DataOut=%02x\n", ncr->cur_bus); - } - } - break; - case STATE_STATUS: - if ((bus & BUS_ACK) && !(ncr->bus_in & BUS_ACK)) { - /*All transfers done, wait until next transfer*/ - scsi_device_identify(&scsi_devices[ncr->bus][ncr->target_id], SCSI_LUN_USE_CDB); - ncr->cur_bus &= ~BUS_REQ; - ncr->new_phase = SCSI_PHASE_MESSAGE_IN; - ncr->wait_data = 4; - ncr->wait_complete = 8; - } - break; - case STATE_MESSAGEIN: - if ((bus & BUS_ACK) && !(ncr->bus_in & BUS_ACK)) { - ncr->cur_bus &= ~BUS_REQ; - ncr->new_phase = BUS_IDLE; - ncr->wait_data = 4; - } - break; - case STATE_MESSAGEOUT: - ncr5380_log("Ack on MSGOUT = %02x\n", (bus & BUS_ACK)); - if ((bus & BUS_ACK) && !(ncr->bus_in & BUS_ACK)) { - ncr->msgout[ncr->msgout_pos++] = BUS_GETDATA(bus); - msglen = ncr5380_getmsglen(ncr->msgout, ncr->msgout_pos); - if (ncr->msgout_pos >= msglen) { - if ((ncr->msgout[0] & (0x80 | 0x20)) == 0x80) - ncr->msglun = ncr->msgout[0] & 7; - ncr->cur_bus &= ~BUS_REQ; - ncr->state = STATE_MESSAGE_ID; - } - } - break; - case STATE_MESSAGE_ID: - if ((ncr->target_id != (uint8_t) -1) && scsi_device_present(&scsi_devices[ncr->bus][ncr->target_id])) { - ncr5380_log("Device found at ID %i on MSGOUT, Current Bus BSY=%02x\n", ncr->target_id, ncr->cur_bus); - scsi_device_identify(&scsi_devices[ncr->bus][ncr->target_id], ncr->msglun); - ncr->state = STATE_COMMAND; - ncr->cur_bus = BUS_BSY | BUS_REQ; - ncr5380_log("CurBus BSY|REQ=%02x\n", ncr->cur_bus); - ncr->command_pos = 0; - SET_BUS_STATE(ncr, SCSI_PHASE_COMMAND); - } - break; - - default: - break; - } - - ncr->bus_in = bus; -} - void ncr5380_write(uint16_t port, uint8_t val, ncr_t *ncr) { + scsi_bus_t *scsi_bus = &ncr->scsibus; int bus_host = 0; ncr5380_log("NCR5380 write(%04x,%02x)\n", port & 7, val); @@ -462,8 +169,10 @@ ncr5380_write(uint16_t port, uint8_t val, ncr_t *ncr) if ((val & 0x80) && !(ncr->icr & 0x80)) { ncr5380_log("Resetting the 5380\n"); ncr5380_reset(ncr); + ncr5380_irq(ncr, 1); } ncr->icr = val; + ncr5380_log("ICR WaitData=%d, ClearReq=%d.\n", scsi_bus->wait_data, scsi_bus->clear_req); break; case 2: /* Mode register */ @@ -472,10 +181,8 @@ ncr5380_write(uint16_t port, uint8_t val, ncr_t *ncr) ncr->icr &= ~ICR_ARB_LOST; ncr->icr |= ICR_ARB_IN_PROGRESS; } - ncr->mode = val; - - ncr->dma_mode_ext(ncr, ncr->priv); + ncr->dma_mode_ext(ncr, ncr->priv, val); break; case 3: /* Target Command Register */ @@ -490,15 +197,15 @@ ncr5380_write(uint16_t port, uint8_t val, ncr_t *ncr) case 5: /* start DMA Send */ ncr5380_log("Write: start DMA send register\n"); /*a Write 6/10 has occurred, start the timer when the block count is loaded*/ - ncr->dma_mode = DMA_SEND; + scsi_bus->tx_mode = DMA_OUT_TX_BUS; if (ncr->dma_send_ext) ncr->dma_send_ext(ncr, ncr->priv); break; case 7: /* start DMA Initiator Receive */ - ncr5380_log("[%04X:%08X]: Write: start DMA initiator receive register, dma? = %02x\n", CS, cpu_state.pc, ncr->mode & MODE_DMA); + ncr5380_log("[%04X:%08X]: Write: start DMA initiator receive register, waitdata=%d, clearreq=%d.\n", CS, cpu_state.pc, scsi_bus->wait_data, scsi_bus->clear_req); /*a Read 6/10 has occurred, start the timer when the block count is loaded*/ - ncr->dma_mode = DMA_INITIATOR_RECEIVE; + scsi_bus->tx_mode = DMA_IN_TX_BUS; if (ncr->dma_initiator_receive_ext) ncr->dma_initiator_receive_ext(ncr, ncr->priv); break; @@ -509,12 +216,13 @@ ncr5380_write(uint16_t port, uint8_t val, ncr_t *ncr) } bus_host = ncr5380_get_bus_host(ncr); - ncr5380_bus_update(ncr, bus_host); + scsi_bus_update(scsi_bus, bus_host); } uint8_t ncr5380_read(uint16_t port, ncr_t *ncr) { + scsi_bus_t *scsi_bus = &ncr->scsibus; uint8_t ret = 0xff; int bus; int bus_state; @@ -524,12 +232,17 @@ ncr5380_read(uint16_t port, ncr_t *ncr) ncr5380_log("Read: Current SCSI data register\n"); if (ncr->icr & ICR_DBP) { /*Return the data from the output register if on data bus phase from ICR*/ - ret = ncr->output_data; - ncr5380_log("[%04X:%08X]: Data Bus Phase, ret=%02x, clearreq=%d, waitdata=%x.\n", CS, cpu_state.pc, ret, ncr->clear_req, ncr->wait_data); + if (scsi_bus->command_issued) { + bus = scsi_bus_read(scsi_bus); + ret = BUS_GETDATA(bus); + } else + ret = ncr->output_data; + + ncr5380_log("[%04X:%08X]: Data Bus Phase, CMDissued=%d, ret=%02x, clearreq=%d, waitdata=%x, txmode=%x.\n", CS, cpu_state.pc, scsi_bus->command_issued, ret, scsi_bus->clear_req, scsi_bus->wait_data, scsi_bus->tx_mode); } else { /*Return the data from the SCSI bus*/ - ncr5380_bus_read(ncr); - ret = BUS_GETDATA(ncr->cur_bus); + bus = scsi_bus_read(scsi_bus); + ret = BUS_GETDATA(bus); ncr5380_log("[%04X:%08X]: NCR Get SCSI bus data=%02x.\n", CS, cpu_state.pc, ret); } break; @@ -552,15 +265,12 @@ ncr5380_read(uint16_t port, ncr_t *ncr) case 4: /* Current SCSI Bus status */ ncr5380_log("Read: SCSI bus status register\n"); ret = 0; - ncr5380_bus_read(ncr); - ncr5380_log("NCR cur bus stat=%02x\n", ncr->cur_bus & 0xff); - ret |= (ncr->cur_bus & 0xff); + bus = scsi_bus_read(scsi_bus); + ret |= (bus & 0xff); if (ncr->icr & ICR_SEL) ret |= BUS_SEL; if (ncr->icr & ICR_BSY) ret |= BUS_BSY; - // if ((ret & SCSI_PHASE_MESSAGE_IN) == SCSI_PHASE_MESSAGE_IN) - // ret &= ~BUS_REQ; break; case 5: /* Bus and Status register */ @@ -571,13 +281,12 @@ ncr5380_read(uint16_t port, ncr_t *ncr) ncr5380_log("Get host from Interrupt\n"); /*Check if the phase in process matches with TCR's*/ - if ((bus & SCSI_PHASE_MESSAGE_IN) == (ncr->cur_bus & SCSI_PHASE_MESSAGE_IN)) { + if ((bus & SCSI_PHASE_MESSAGE_IN) == (scsi_bus->bus_out & SCSI_PHASE_MESSAGE_IN)) { ncr5380_log("Phase match\n"); ret |= STATUS_PHASE_MATCH; } - ncr5380_bus_read(ncr); - bus = ncr->cur_bus; + bus = scsi_bus_read(scsi_bus); if ((bus & BUS_ACK) || (ncr->icr & ICR_ACK)) ret |= STATUS_ACK; @@ -606,12 +315,13 @@ ncr5380_read(uint16_t port, ncr_t *ncr) ret |= STATUS_BUSY_ERROR; } ret |= (ncr->isr & (STATUS_INT | STATUS_END_OF_DMA)); + ncr->isr_reg = ret; break; case 6: ncr5380_log("Read: Input Data.\n"); - ncr5380_bus_read(ncr); - ret = BUS_GETDATA(ncr->cur_bus); + bus = scsi_bus_read(scsi_bus); + ret = BUS_GETDATA(bus); break; case 7: /* reset Parity/Interrupt */ diff --git a/src/scsi/scsi_ncr53c400.c b/src/scsi/scsi_ncr53c400.c index e028c7b42..d8008cf02 100644 --- a/src/scsi/scsi_ncr53c400.c +++ b/src/scsi/scsi_ncr53c400.c @@ -121,7 +121,8 @@ ncr53c400_write(uint32_t addr, uint8_t val, void *priv) { ncr53c400_t *ncr400 = (ncr53c400_t *) priv; ncr_t *ncr = &ncr400->ncr; - scsi_device_t *dev = &scsi_devices[ncr->bus][ncr->target_id]; + scsi_bus_t *scsi_bus = &ncr->scsibus; + scsi_device_t *dev = &scsi_devices[ncr->bus][scsi_bus->target_id]; addr &= 0x3fff; @@ -146,16 +147,9 @@ ncr53c400_write(uint32_t addr, uint8_t val, void *priv) if (ncr400->buffer_host_pos == MIN(128, dev->buffer_length)) { ncr400->status_ctrl |= STATUS_BUFFER_NOT_READY; ncr400->busy = 1; - if (!(ncr->mode & MODE_MONITOR_BUSY) && ((scsi_device_get_callback(dev) > 0.0))) - timer_on_auto(&ncr400->timer, ncr->period / 250.0); - else if ((ncr->mode & MODE_MONITOR_BUSY) && !ncr->wait_data) { - if (scsi_device_get_callback(dev) > 0.0) - timer_on_auto(&ncr400->timer, 100.0); - else - timer_on_auto(&ncr400->timer, 40.0); - } } - } + } else + ncr53c400_log("No Write.\n"); break; case 0x3980: @@ -173,7 +167,7 @@ ncr53c400_write(uint32_t addr, uint8_t val, void *priv) break; case 0x3981: /* block counter register */ - ncr53c400_log("Write block counter register: val=%d, dma mode=%x, period=%lf.\n", val, ncr->dma_mode, ncr->period); + ncr53c400_log("Write block counter register: val=%d, dma mode=%x, period=%lf.\n", val, scsi_bus->tx_mode, scsi_bus->period); ncr400->block_count = val; ncr400->block_count_loaded = 1; @@ -186,17 +180,14 @@ ncr53c400_write(uint32_t addr, uint8_t val, void *priv) } if ((ncr->mode & MODE_DMA) && (dev->buffer_length > 0)) { memset(ncr400->buffer, 0, MIN(128, dev->buffer_length)); - if (ncr->mode & MODE_MONITOR_BUSY) - timer_on_auto(&ncr400->timer, (ncr->period / 4.0) * 3.0); - else if (scsi_device_get_callback(dev) > 0.0) - timer_on_auto(&ncr400->timer, 40.0); + if (ncr400->type == ROM_T130B) + timer_on_auto(&ncr400->timer, 10.0); else - timer_on_auto(&ncr400->timer, ncr->period); - - ncr->wait_data_back = ncr->wait_data; - ncr53c400_log("DMA timer on=%02x, callback=%lf, scsi buflen=%d, waitdata=%d, waitcomplete=%d, clearreq=%d, datawait=%d, enabled=%d.\n", - ncr->mode & MODE_MONITOR_BUSY, scsi_device_get_callback(dev), dev->buffer_length, ncr->wait_data, ncr->wait_complete, ncr->clear_req, ncr->data_wait, timer_is_enabled(&ncr400->timer)); - } + timer_on_auto(&ncr400->timer, scsi_bus->period); + ncr53c400_log("DMA timer on=%02x, callback=%lf, scsi buflen=%d, waitdata=%d, waitcomplete=%d, clearreq=%d, p=%lf enabled=%d.\n", + ncr->mode & MODE_MONITOR_BUSY, scsi_device_get_callback(dev), dev->buffer_length, scsi_bus->wait_data, scsi_bus->wait_complete, scsi_bus->clear_req, scsi_bus->period, timer_is_enabled(&ncr400->timer)); + } else + ncr53c400_log("No Timer.\n"); break; default: @@ -216,7 +207,8 @@ ncr53c400_read(uint32_t addr, void *priv) { ncr53c400_t *ncr400 = (ncr53c400_t *) priv; ncr_t *ncr = &ncr400->ncr; - scsi_device_t *dev = &scsi_devices[ncr->bus][ncr->target_id]; + scsi_bus_t *scsi_bus = &ncr->scsibus; + scsi_device_t *dev = &scsi_devices[ncr->bus][scsi_bus->target_id]; uint8_t ret = 0xff; addr &= 0x3fff; @@ -240,7 +232,7 @@ ncr53c400_read(uint32_t addr, void *priv) break; case 0x3900: - if (ncr400->buffer_host_pos >= MIN(128, dev->buffer_length) || (!(ncr400->status_ctrl & CTRL_DATA_DIR))) { + if ((ncr400->buffer_host_pos >= MIN(128, dev->buffer_length)) || (!(ncr400->status_ctrl & CTRL_DATA_DIR))) { ret = 0xff; ncr53c400_log("No Read.\n"); } else { @@ -249,15 +241,6 @@ ncr53c400_read(uint32_t addr, void *priv) if (ncr400->buffer_host_pos == MIN(128, dev->buffer_length)) { ncr400->status_ctrl |= STATUS_BUFFER_NOT_READY; - ncr53c400_log("Transfer busy read, status = %02x.\n", ncr400->status_ctrl); - if (!(ncr->mode & MODE_MONITOR_BUSY) && (scsi_device_get_callback(dev) > 0.0)) - timer_on_auto(&ncr400->timer, ncr->period / 250.0); - else if ((ncr->mode & MODE_MONITOR_BUSY) && !ncr->wait_data) { - if (scsi_device_get_callback(dev) > 0.0) - timer_on_auto(&ncr400->timer, 100.0); - else - timer_on_auto(&ncr400->timer, 40.0); - } } } break; @@ -272,7 +255,7 @@ ncr53c400_read(uint32_t addr, void *priv) if (ncr->mode & 0x30) { /*Parity bits*/ if (!(ncr->mode & MODE_DMA)) { /*This is to avoid RTBios 8.10R BIOS problems with the hard disk and detection.*/ ret |= 0x01; /*If the parity bits are set, bit 0 of the 53c400 status port should be set as well.*/ - ncr->mode = 0; /*Required by RTASPI10.SYS otherwise it won't initialize.*/ + ncr->mode = 0x00; /*Required by RTASPI10.SYS otherwise it won't initialize.*/ } } ncr53c400_log("NCR 53c400 status=%02x.\n", ret); @@ -411,19 +394,19 @@ t130b_in(uint16_t port, void *priv) } static void -ncr53c400_dma_mode_ext(void *priv, void *ext_priv) +ncr53c400_dma_mode_ext(void *priv, void *ext_priv, uint8_t val) { ncr53c400_t *ncr400 = (ncr53c400_t *) ext_priv; ncr_t *ncr = (ncr_t *) priv; + scsi_bus_t *scsi_bus = &ncr->scsibus; /*When a pseudo-DMA transfer has completed (Send or Initiator Receive), mark it as complete and idle the status*/ - ncr53c400_log("BlockCountLoaded=%d.\n", ncr400->block_count_loaded); + ncr53c400_log("NCR 53c400: Loaded?=%d, DMA mode enabled=%02x, valDMA=%02x.\n", ncr400->block_count_loaded, ncr->mode & MODE_DMA, val & MODE_DMA); if (!ncr400->block_count_loaded) { - if (!(ncr->mode & MODE_DMA)) { - ncr53c400_log("No DMA mode\n"); + if (!(val & MODE_DMA)) { ncr->tcr &= ~TCR_LAST_BYTE_SENT; ncr->isr &= ~STATUS_END_OF_DMA; - ncr->dma_mode = DMA_IDLE; + scsi_bus->tx_mode = PIO_TX_BUS; } } } @@ -431,26 +414,35 @@ ncr53c400_dma_mode_ext(void *priv, void *ext_priv) static void ncr53c400_callback(void *priv) { - ncr53c400_t *ncr400 = (void *) priv; + ncr53c400_t *ncr400 = (ncr53c400_t *) priv; ncr_t *ncr = &ncr400->ncr; - scsi_device_t *dev = &scsi_devices[ncr->bus][ncr->target_id]; + scsi_bus_t *scsi_bus = &ncr->scsibus; + scsi_device_t *dev = &scsi_devices[ncr->bus][scsi_bus->target_id]; int bus; uint8_t c; uint8_t temp; + uint8_t status; - if (ncr->dma_mode != DMA_IDLE) - timer_on_auto(&ncr400->timer, 1.0); - - if (ncr->data_wait & 1) { - ncr->clear_req = 3; - ncr->data_wait &= ~1; + if (scsi_bus->tx_mode != PIO_TX_BUS) { + if (ncr400->type == ROM_T130B) { + ncr53c400_log("PERIOD T130B DMA=%lf.\n", scsi_bus->period / 200.0); + timer_on_auto(&ncr400->timer, scsi_bus->period / 200.0); + } else + timer_on_auto(&ncr400->timer, 1.0); } - if (ncr->dma_mode == DMA_IDLE) - return; + if (scsi_bus->data_wait & 1) { + scsi_bus->clear_req = 3; + scsi_bus->data_wait &= ~1; + } - switch (ncr->dma_mode) { - case DMA_SEND: + if (scsi_bus->tx_mode == PIO_TX_BUS) { + ncr53c400_log("Timer CMD=%02x.\n", scsi_bus->command[0]); + return; + } + + switch (scsi_bus->tx_mode) { + case DMA_OUT_TX_BUS: if (ncr400->status_ctrl & CTRL_DATA_DIR) { ncr53c400_log("DMA_SEND with DMA direction set wrong\n"); break; @@ -468,8 +460,8 @@ ncr53c400_callback(void *priv) while (1) { for (c = 0; c < 10; c++) { - ncr5380_bus_read(ncr); - if (ncr->cur_bus & BUS_REQ) + status = scsi_bus_read(scsi_bus); + if (status & BUS_REQ) break; } /* Data ready. */ @@ -478,8 +470,8 @@ ncr53c400_callback(void *priv) bus = ncr5380_get_bus_host(ncr) & ~BUS_DATAMASK; bus |= BUS_SETDATA(temp); - ncr5380_bus_update(ncr, bus | BUS_ACK); - ncr5380_bus_update(ncr, bus & ~BUS_ACK); + scsi_bus_update(scsi_bus, bus | BUS_ACK); + scsi_bus_update(scsi_bus, bus & ~BUS_ACK); ncr400->buffer_pos++; ncr53c400_log("NCR 53c400 Buffer pos for writing = %d\n", ncr400->buffer_pos); @@ -492,7 +484,7 @@ ncr53c400_callback(void *priv) ncr400->block_count = (ncr400->block_count - 1) & 0xff; ncr53c400_log("NCR 53c400 Remaining blocks to be written=%d\n", ncr400->block_count); if (!ncr400->block_count) { - ncr->dma_mode = DMA_IDLE; + scsi_bus->tx_mode = PIO_TX_BUS; ncr400->block_count_loaded = 0; ncr53c400_log("IO End of write transfer\n"); ncr->tcr |= TCR_LAST_BYTE_SENT; @@ -507,7 +499,7 @@ ncr53c400_callback(void *priv) } break; - case DMA_INITIATOR_RECEIVE: + case DMA_IN_TX_BUS: if (!(ncr400->status_ctrl & CTRL_DATA_DIR)) { ncr53c400_log("DMA_INITIATOR_RECEIVE with DMA direction set wrong\n"); break; @@ -523,18 +515,18 @@ ncr53c400_callback(void *priv) while (1) { for (c = 0; c < 10; c++) { - ncr5380_bus_read(ncr); - if (ncr->cur_bus & BUS_REQ) + status = scsi_bus_read(scsi_bus); + if (status & BUS_REQ) break; } /* Data ready. */ - ncr5380_bus_read(ncr); - temp = BUS_GETDATA(ncr->cur_bus); + bus = scsi_bus_read(scsi_bus); + temp = BUS_GETDATA(bus); bus = ncr5380_get_bus_host(ncr); - ncr5380_bus_update(ncr, bus | BUS_ACK); - ncr5380_bus_update(ncr, bus & ~BUS_ACK); + scsi_bus_update(scsi_bus, bus | BUS_ACK); + scsi_bus_update(scsi_bus, bus & ~BUS_ACK); ncr400->buffer[ncr400->buffer_pos++] = temp; ncr53c400_log("NCR 53c400 Buffer pos for reading = %d\n", ncr400->buffer_pos); @@ -546,7 +538,7 @@ ncr53c400_callback(void *priv) ncr400->block_count = (ncr400->block_count - 1) & 0xff; ncr53c400_log("NCR 53c400 Remaining blocks to be read=%d\n", ncr400->block_count); if (!ncr400->block_count) { - ncr->dma_mode = DMA_IDLE; + scsi_bus->tx_mode = PIO_TX_BUS; ncr400->block_count_loaded = 0; ncr53c400_log("IO End of read transfer\n"); ncr->isr |= STATUS_END_OF_DMA; @@ -564,13 +556,12 @@ ncr53c400_callback(void *priv) break; } - ncr53c400_log("Bus Read.\n"); - ncr5380_bus_read(ncr); + status = scsi_bus_read(scsi_bus); - if (!(ncr->cur_bus & BUS_BSY) && (ncr->mode & MODE_MONITOR_BUSY)) { + if (!(status & BUS_BSY) && (ncr->mode & MODE_MONITOR_BUSY)) { ncr53c400_log("Updating DMA\n"); ncr->mode &= ~MODE_DMA; - ncr->dma_mode = DMA_IDLE; + scsi_bus->tx_mode = PIO_TX_BUS; ncr400->block_count_loaded = 0; } } @@ -641,16 +632,14 @@ ncr53c400_init(const device_t *info) { const char *bios_ver = NULL; const char *fn; - ncr53c400_t *ncr400; - ncr_t *ncr; - - ncr400 = malloc(sizeof(ncr53c400_t)); - memset(ncr400, 0x00, sizeof(ncr53c400_t)); - ncr = &ncr400->ncr; + ncr53c400_t *ncr400 = calloc(1, sizeof(ncr53c400_t)); + ncr_t *ncr = &ncr400->ncr; + scsi_bus_t *scsi_bus; ncr400->type = info->local; ncr->bus = scsi_get_bus(); + scsi_bus = &ncr->scsibus; switch (ncr400->type) { case ROM_LCS6821N: /* Longshine LCS6821N */ @@ -734,12 +723,17 @@ ncr53c400_init(const device_t *info) ncr->dma_send_ext = NULL; ncr->dma_initiator_receive_ext = NULL; ncr->timer = ncr53c400_timer_on_auto; + scsi_bus->bus_device = ncr->bus; + scsi_bus->timer = ncr->timer; + scsi_bus->priv = ncr->priv; ncr400->status_ctrl = STATUS_BUFFER_NOT_READY; ncr400->buffer_host_pos = 128; timer_add(&ncr400->timer, ncr53c400_callback, ncr400, 0); scsi_bus_set_speed(ncr->bus, 5000000.0); - + scsi_bus->speed = 0.2; + scsi_bus->divider = 2.0; + scsi_bus->multi = 1.750; return ncr400; } @@ -956,7 +950,7 @@ const device_t scsi_lcs6821n_device = { .init = ncr53c400_init, .close = ncr53c400_close, .reset = NULL, - { .available = lcs6821n_available }, + .available = lcs6821n_available, .speed_changed = NULL, .force_redraw = NULL, .config = ncr53c400_mmio_config @@ -970,7 +964,7 @@ const device_t scsi_rt1000b_device = { .init = ncr53c400_init, .close = ncr53c400_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = rt1000b_config @@ -984,7 +978,7 @@ const device_t scsi_rt1000mc_device = { .init = ncr53c400_init, .close = ncr53c400_close, .reset = NULL, - { .available = rt1000b_mc_available }, + .available = rt1000b_mc_available, .speed_changed = NULL, .force_redraw = NULL, .config = rt1000b_mc_config @@ -998,7 +992,7 @@ const device_t scsi_t130b_device = { .init = ncr53c400_init, .close = ncr53c400_close, .reset = NULL, - { .available = t130b_available }, + .available = t130b_available, .speed_changed = NULL, .force_redraw = NULL, .config = t130b_config @@ -1012,7 +1006,7 @@ const device_t scsi_ls2000_device = { .init = ncr53c400_init, .close = ncr53c400_close, .reset = NULL, - { .available = corel_ls2000_available }, + .available = corel_ls2000_available, .speed_changed = NULL, .force_redraw = NULL, .config = ncr53c400_mmio_config diff --git a/src/scsi/scsi_ncr53c8xx.c b/src/scsi/scsi_ncr53c8xx.c index 1425f468b..d26da3bb3 100644 --- a/src/scsi/scsi_ncr53c8xx.c +++ b/src/scsi/scsi_ncr53c8xx.c @@ -2530,10 +2530,7 @@ ncr53c8xx_pci_write(UNUSED(int func), int addr, uint8_t val, void *priv) static void * ncr53c8xx_init(const device_t *info) { - ncr53c8xx_t *dev; - - dev = malloc(sizeof(ncr53c8xx_t)); - memset(dev, 0x00, sizeof(ncr53c8xx_t)); + ncr53c8xx_t *dev = calloc(1, sizeof(ncr53c8xx_t)); dev->bus = scsi_get_bus(); @@ -2692,7 +2689,7 @@ const device_t ncr53c810_pci_device = { .init = ncr53c8xx_init, .close = ncr53c8xx_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2706,7 +2703,7 @@ const device_t ncr53c810_onboard_pci_device = { .init = ncr53c8xx_init, .close = ncr53c8xx_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2720,7 +2717,7 @@ const device_t ncr53c815_pci_device = { .init = ncr53c8xx_init, .close = ncr53c8xx_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, ncr53c8xx_pci_config @@ -2734,7 +2731,7 @@ const device_t ncr53c820_pci_device = { .init = ncr53c8xx_init, .close = ncr53c8xx_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2748,7 +2745,7 @@ const device_t ncr53c825a_pci_device = { .init = ncr53c8xx_init, .close = ncr53c8xx_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = ncr53c8xx_pci_config @@ -2762,7 +2759,7 @@ const device_t ncr53c860_pci_device = { .init = ncr53c8xx_init, .close = ncr53c8xx_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = ncr53c8xx_pci_config @@ -2776,7 +2773,7 @@ const device_t ncr53c875_pci_device = { .init = ncr53c8xx_init, .close = ncr53c8xx_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = ncr53c8xx_pci_config diff --git a/src/scsi/scsi_pcscsi.c b/src/scsi/scsi_pcscsi.c index c2e5c9168..012d5524b 100644 --- a/src/scsi/scsi_pcscsi.c +++ b/src/scsi/scsi_pcscsi.c @@ -2204,10 +2204,7 @@ esp_pci_write(UNUSED(int func), int addr, uint8_t val, void *priv) static void * dc390_init(UNUSED(const device_t *info)) { - esp_t *dev; - - dev = malloc(sizeof(esp_t)); - memset(dev, 0x00, sizeof(esp_t)); + esp_t *dev = calloc(1, sizeof(esp_t)); dev->bus = scsi_get_bus(); @@ -2419,10 +2416,7 @@ ncr53c9x_mca_feedb(void *priv) static void * ncr53c9x_mca_init(const device_t *info) { - esp_t *dev; - - dev = malloc(sizeof(esp_t)); - memset(dev, 0x00, sizeof(esp_t)); + esp_t *dev = calloc(1, sizeof(esp_t)); dev->bus = scsi_get_bus(); @@ -2482,7 +2476,7 @@ const device_t dc390_pci_device = { .init = dc390_init, .close = esp_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = bios_enable_config @@ -2496,7 +2490,7 @@ const device_t am53c974_pci_device = { .init = dc390_init, .close = esp_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2510,7 +2504,7 @@ const device_t ncr53c90a_mca_device = { .init = ncr53c9x_mca_init, .close = esp_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/scsi/scsi_spock.c b/src/scsi/scsi_spock.c index e308d0788..cbf6ff205 100644 --- a/src/scsi/scsi_spock.c +++ b/src/scsi/scsi_spock.c @@ -1162,8 +1162,7 @@ spock_mca_reset(void *priv) static void * spock_init(const device_t *info) { - spock_t *scsi = malloc(sizeof(spock_t)); - memset(scsi, 0x00, sizeof(spock_t)); + spock_t *scsi = calloc(1, sizeof(spock_t)); scsi->bus = scsi_get_bus(); @@ -1257,7 +1256,7 @@ const device_t spock_device = { .init = spock_init, .close = spock_close, .reset = NULL, - { .available = spock_available }, + .available = spock_available, .speed_changed = NULL, .force_redraw = NULL, .config = spock_rom_config @@ -1271,7 +1270,7 @@ const device_t tribble_device = { .init = spock_init, .close = spock_close, .reset = NULL, - { .available = spock_available }, + .available = spock_available, .speed_changed = NULL, .force_redraw = NULL, .config = spock_rom_config diff --git a/src/scsi/scsi_t128.c b/src/scsi/scsi_t128.c index c878bbb91..ff5f584f1 100644 --- a/src/scsi/scsi_t128.c +++ b/src/scsi/scsi_t128.c @@ -69,7 +69,8 @@ t128_write(uint32_t addr, uint8_t val, void *priv) { t128_t *t128 = (t128_t *) priv; ncr_t *ncr = &t128->ncr; - const scsi_device_t *dev = &scsi_devices[ncr->bus][ncr->target_id]; + scsi_bus_t *scsi_bus = &ncr->scsibus; + const scsi_device_t *dev = &scsi_devices[ncr->bus][scsi_bus->target_id]; addr &= 0x3fff; if ((addr >= 0x1800) && (addr < 0x1880)) @@ -84,7 +85,7 @@ t128_write(uint32_t addr, uint8_t val, void *priv) ncr5380_write((addr - 0x1d00) >> 5, val, ncr); else if ((addr >= 0x1e00) && (addr < 0x2000)) { if ((t128->host_pos < MIN(512, dev->buffer_length)) && - (ncr->dma_mode == DMA_SEND)) { + (scsi_bus->tx_mode == DMA_OUT_TX_BUS)) { t128->buffer[t128->host_pos] = val; t128->host_pos++; @@ -106,7 +107,8 @@ t128_read(uint32_t addr, void *priv) { t128_t *t128 = (t128_t *) priv; ncr_t *ncr = &t128->ncr; - scsi_device_t *dev = &scsi_devices[ncr->bus][ncr->target_id]; + scsi_bus_t *scsi_bus = &ncr->scsibus; + scsi_device_t *dev = &scsi_devices[ncr->bus][scsi_bus->target_id]; uint8_t ret = 0xff; addr &= 0x3fff; @@ -124,7 +126,7 @@ t128_read(uint32_t addr, void *priv) ret = ncr5380_read((addr - 0x1d00) >> 5, ncr); else if (addr >= 0x1e00 && addr < 0x2000) { if ((t128->host_pos >= MIN(512, dev->buffer_length)) || - (ncr->dma_mode != DMA_INITIATOR_RECEIVE)) + (scsi_bus->tx_mode != DMA_IN_TX_BUS)) ret = 0xff; else { ret = t128->buffer[t128->host_pos++]; @@ -135,8 +137,8 @@ t128_read(uint32_t addr, void *priv) if (t128->host_pos == MIN(512, dev->buffer_length)) { t128->status &= ~0x04; t128_log("T128 Transfer busy read, status = %02x, period = %lf\n", - t128->status, ncr->period); - if ((ncr->period == 0.2) || (ncr->period == 0.02)) + t128->status, scsi_bus->period); + if ((scsi_bus->period == 0.2) || (scsi_bus->period == 0.02)) timer_on_auto(&t128->timer, 40.2); } else if ((t128->host_pos < MIN(512, dev->buffer_length)) && (scsi_device_get_callback(dev) > 100.0)) @@ -148,15 +150,16 @@ t128_read(uint32_t addr, void *priv) } static void -t128_dma_mode_ext(void *priv, void *ext_priv) +t128_dma_mode_ext(void *priv, void *ext_priv, UNUSED(uint8_t val)) { t128_t *t128 = (t128_t *) ext_priv; ncr_t *ncr = (ncr_t *) priv; + scsi_bus_t *scsi_bus = &ncr->scsibus; /*Don't stop the timer until it finishes the transfer*/ if (t128->block_loaded && (ncr->mode & MODE_DMA)) { t128_log("Continuing DMA mode\n"); - timer_on_auto(&t128->timer, ncr->period + 1.0); + timer_on_auto(&t128->timer, scsi_bus->period + 1.0); } /*When a pseudo-DMA transfer has completed (Send or Initiator Receive), mark it as complete and idle the status*/ @@ -164,7 +167,7 @@ t128_dma_mode_ext(void *priv, void *ext_priv) t128_log("No DMA mode\n"); ncr->tcr &= ~TCR_LAST_BYTE_SENT; ncr->isr &= ~STATUS_END_OF_DMA; - ncr->dma_mode = DMA_IDLE; + scsi_bus->tx_mode = PIO_TX_BUS; } } @@ -173,7 +176,8 @@ t128_dma_send_ext(void *priv, void *ext_priv) { t128_t *t128 = (t128_t *) ext_priv; ncr_t *ncr = (ncr_t *) priv; - scsi_device_t *dev = &scsi_devices[ncr->bus][ncr->target_id]; + scsi_bus_t *scsi_bus = &ncr->scsibus; + scsi_device_t *dev = &scsi_devices[ncr->bus][scsi_bus->target_id]; if ((ncr->mode & MODE_DMA) && !timer_is_on(&t128->timer) && (dev->buffer_length > 0)) { memset(t128->buffer, 0, MIN(512, dev->buffer_length)); @@ -194,7 +198,8 @@ t128_dma_initiator_receive_ext(void *priv, void *ext_priv) { t128_t *t128 = (t128_t *) ext_priv; ncr_t *ncr = (ncr_t *) priv; - scsi_device_t *dev = &scsi_devices[ncr->bus][ncr->target_id]; + scsi_bus_t *scsi_bus = &ncr->scsibus; + scsi_device_t *dev = &scsi_devices[ncr->bus][scsi_bus->target_id]; if ((ncr->mode & MODE_DMA) && !timer_is_on(&t128->timer) && (dev->buffer_length > 0)) { memset(t128->buffer, 0, MIN(512, dev->buffer_length)); @@ -227,27 +232,29 @@ t128_callback(void *priv) { t128_t *t128 = (void *) priv; ncr_t *ncr = &t128->ncr; - scsi_device_t *dev = &scsi_devices[ncr->bus][ncr->target_id]; - int bus; - uint8_t c; - uint8_t temp; + scsi_bus_t *scsi_bus = &ncr->scsibus; + scsi_device_t *dev = &scsi_devices[ncr->bus][scsi_bus->target_id]; + int bus; + uint8_t c; + uint8_t temp; + uint8_t status; - if ((ncr->dma_mode != DMA_IDLE) && (ncr->mode & MODE_DMA) && t128->block_loaded) { + if ((scsi_bus->tx_mode != PIO_TX_BUS) && (ncr->mode & MODE_DMA) && t128->block_loaded) { if ((t128->host_pos == MIN(512, dev->buffer_length)) && t128->block_count) t128->status |= 0x04; - timer_on_auto(&t128->timer, ncr->period / 55.0); + timer_on_auto(&t128->timer, scsi_bus->period / 55.0); } - if (ncr->data_wait & 1) { - ncr->clear_req = 3; - ncr->data_wait &= ~1; - if (ncr->dma_mode == DMA_IDLE) + if (scsi_bus->data_wait & 1) { + scsi_bus->clear_req = 3; + scsi_bus->data_wait &= ~1; + if (scsi_bus->tx_mode == PIO_TX_BUS) return; } - switch (ncr->dma_mode) { - case DMA_SEND: + switch (scsi_bus->tx_mode) { + case DMA_OUT_TX_BUS: if (!(t128->status & 0x04)) { t128_log("Write status busy, block count = %i, host pos = %i\n", t128->block_count, t128->host_pos); break; @@ -263,8 +270,8 @@ t128_callback(void *priv) write_again: for (c = 0; c < 10; c++) { - ncr5380_bus_read(ncr); - if (ncr->cur_bus & BUS_REQ) + status = scsi_bus_read(scsi_bus); + if (status & BUS_REQ) break; } @@ -274,8 +281,8 @@ write_again: bus = ncr5380_get_bus_host(ncr) & ~BUS_DATAMASK; bus |= BUS_SETDATA(temp); - ncr5380_bus_update(ncr, bus | BUS_ACK); - ncr5380_bus_update(ncr, bus & ~BUS_ACK); + scsi_bus_update(scsi_bus, bus | BUS_ACK); + scsi_bus_update(scsi_bus, bus & ~BUS_ACK); t128->pos++; t128_log("T128 Buffer pos for writing = %d\n", t128->pos); @@ -302,7 +309,7 @@ write_again: goto write_again; break; - case DMA_INITIATOR_RECEIVE: + case DMA_IN_TX_BUS: if (!(t128->status & 0x04)) { t128_log("Read status busy, block count = %i, host pos = %i\n", t128->block_count, t128->host_pos); break; @@ -318,19 +325,19 @@ write_again: read_again: for (c = 0; c < 10; c++) { - ncr5380_bus_read(ncr); - if (ncr->cur_bus & BUS_REQ) + status = scsi_bus_read(scsi_bus); + if (status & BUS_REQ) break; } /* Data ready. */ - ncr5380_bus_read(ncr); - temp = BUS_GETDATA(ncr->cur_bus); + bus = scsi_bus_read(scsi_bus); + temp = BUS_GETDATA(bus); bus = ncr5380_get_bus_host(ncr); - ncr5380_bus_update(ncr, bus | BUS_ACK); - ncr5380_bus_update(ncr, bus & ~BUS_ACK); + scsi_bus_update(scsi_bus, bus | BUS_ACK); + scsi_bus_update(scsi_bus, bus & ~BUS_ACK); t128->buffer[t128->pos++] = temp; t128_log("T128 Buffer pos for reading=%d, temp=%02x, len=%d.\n", t128->pos, temp, dev->buffer_length); @@ -360,12 +367,12 @@ read_again: break; } - ncr5380_bus_read(ncr); + status = scsi_bus_read(scsi_bus); - if (!(ncr->cur_bus & BUS_BSY) && (ncr->mode & MODE_MONITOR_BUSY)) { + if (!(status & BUS_BSY) && (ncr->mode & MODE_MONITOR_BUSY)) { t128_log("Updating DMA\n"); ncr->mode &= ~MODE_DMA; - ncr->dma_mode = DMA_IDLE; + scsi_bus->tx_mode = PIO_TX_BUS; timer_on_auto(&t128->timer, 10.0); } } @@ -465,14 +472,12 @@ t228_feedb(void *priv) static void * t128_init(const device_t *info) { - t128_t *t128; - ncr_t *ncr; - - t128 = malloc(sizeof(t128_t)); - memset(t128, 0x00, sizeof(t128_t)); - ncr = &t128->ncr; + t128_t *t128 = calloc(1, sizeof(t128_t)); + ncr_t *ncr = &t128->ncr; + scsi_bus_t *scsi_bus; ncr->bus = scsi_get_bus(); + scsi_bus = &ncr->scsibus; if (info->flags & DEVICE_MCA) { rom_init(&t128->bios_rom, T128_ROM, @@ -504,6 +509,9 @@ t128_init(const device_t *info) ncr->dma_send_ext = t128_dma_send_ext; ncr->dma_initiator_receive_ext = t128_dma_initiator_receive_ext; ncr->timer = t128_timer_on_auto; + scsi_bus->bus_device = ncr->bus; + scsi_bus->timer = ncr->timer; + scsi_bus->priv = ncr->priv; t128->status = 0x00 /*0x04*/; t128->host_pos = 512; if (!t128->bios_enabled && !(info->flags & DEVICE_MCA)) @@ -516,6 +524,9 @@ t128_init(const device_t *info) timer_add(&t128->timer, t128_callback, t128, 0); scsi_bus_set_speed(ncr->bus, 5000000.0); + scsi_bus->speed = 0.2; + scsi_bus->divider = 1.0; + scsi_bus->multi = 1.0; return t128; } @@ -593,7 +604,7 @@ const device_t scsi_t128_device = { .init = t128_init, .close = t128_close, .reset = NULL, - { .available = t128_available }, + .available = t128_available, .speed_changed = NULL, .force_redraw = NULL, .config = t128_config @@ -608,7 +619,7 @@ const device_t scsi_t228_device = { .init = t128_init, .close = t128_close, .reset = NULL, - { .available = t128_available }, + .available = t128_available, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -622,7 +633,7 @@ const device_t scsi_pas_device = { .init = t128_init, .close = t128_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/scsi/scsi_x54x.c b/src/scsi/scsi_x54x.c index 6876e4385..c248fbe92 100644 --- a/src/scsi/scsi_x54x.c +++ b/src/scsi/scsi_x54x.c @@ -287,10 +287,9 @@ x54x_bios_scsi_command(scsi_device_t *dev, uint8_t *cdb, uint8_t *buf, int len, static uint8_t x54x_bios_read_capacity(scsi_device_t *sd, uint8_t *buf, int transfer_size) { - uint8_t *cdb; + uint8_t *cdb = (uint8_t *) malloc(12);; uint8_t ret; - cdb = (uint8_t *) malloc(12); memset(cdb, 0, 12); cdb[0] = GPCMD_READ_CDROM_CAPACITY; @@ -305,10 +304,9 @@ x54x_bios_read_capacity(scsi_device_t *sd, uint8_t *buf, int transfer_size) static uint8_t x54x_bios_inquiry(scsi_device_t *sd, uint8_t *buf, int transfer_size) { - uint8_t *cdb; + uint8_t *cdb = (uint8_t *) malloc(12); uint8_t ret; - cdb = (uint8_t *) malloc(12); memset(cdb, 0, 12); cdb[0] = GPCMD_INQUIRY; cdb[4] = 36; @@ -324,14 +322,13 @@ x54x_bios_inquiry(scsi_device_t *sd, uint8_t *buf, int transfer_size) static uint8_t x54x_bios_command_08(scsi_device_t *sd, uint8_t *buffer, int transfer_size) { - uint8_t *rcbuf; + uint8_t *rcbuf = (uint8_t *) malloc(8); uint8_t ret; int i; memset(buffer, 0x00, 6); - rcbuf = (uint8_t *) malloc(8); - ret = x54x_bios_read_capacity(sd, rcbuf, transfer_size); + ret = x54x_bios_read_capacity(sd, rcbuf, transfer_size); if (ret) { free(rcbuf); return ret; @@ -353,13 +350,12 @@ x54x_bios_command_08(scsi_device_t *sd, uint8_t *buffer, int transfer_size) static int x54x_bios_command_15(scsi_device_t *sd, uint8_t *buffer, int transfer_size) { - uint8_t *inqbuf; + uint8_t *inqbuf = (uint8_t *) malloc(36); uint8_t *rcbuf; uint8_t ret; memset(buffer, 0x00, 6); - inqbuf = (uint8_t *) malloc(36); ret = x54x_bios_inquiry(sd, inqbuf, transfer_size); if (ret) { free(inqbuf); @@ -1896,13 +1892,11 @@ x54x_mem_disable(x54x_t *dev) void * x54x_init(const device_t *info) { - x54x_t *dev; + x54x_t *dev = calloc(1, sizeof(x54x_t)); /* Allocate control block and set up basic stuff. */ - dev = malloc(sizeof(x54x_t)); if (dev == NULL) return dev; - memset(dev, 0x00, sizeof(x54x_t)); dev->type = info->local; dev->card_bus = info->flags; diff --git a/src/sio/sio_82091aa.c b/src/sio/sio_82091aa.c index cbe89c682..76c7ba3f5 100644 --- a/src/sio/sio_82091aa.c +++ b/src/sio/sio_82091aa.c @@ -257,8 +257,7 @@ i82091aa_close(void *priv) static void * i82091aa_init(const device_t *info) { - i82091aa_t *dev = (i82091aa_t *) malloc(sizeof(i82091aa_t)); - memset(dev, 0, sizeof(i82091aa_t)); + i82091aa_t *dev = (i82091aa_t *) calloc(1, sizeof(i82091aa_t)); dev->fdc = device_add(&fdc_at_device); @@ -290,7 +289,7 @@ const device_t i82091aa_device = { .init = i82091aa_init, .close = i82091aa_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -304,7 +303,7 @@ const device_t i82091aa_398_device = { .init = i82091aa_init, .close = i82091aa_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -318,7 +317,7 @@ const device_t i82091aa_ide_pri_device = { .init = i82091aa_init, .close = i82091aa_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -332,7 +331,7 @@ const device_t i82091aa_ide_device = { .init = i82091aa_init, .close = i82091aa_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/sio/sio_acc3221.c b/src/sio/sio_acc3221.c index 275d9ae2e..d52949d46 100644 --- a/src/sio/sio_acc3221.c +++ b/src/sio/sio_acc3221.c @@ -454,8 +454,7 @@ acc3221_close(void *priv) static void * acc3221_init(UNUSED(const device_t *info)) { - acc3221_t *dev = (acc3221_t *) malloc(sizeof(acc3221_t)); - memset(dev, 0, sizeof(acc3221_t)); + acc3221_t *dev = (acc3221_t *) calloc(1, sizeof(acc3221_t)); dev->fdc = device_add(&fdc_at_device); @@ -477,7 +476,7 @@ const device_t acc3221_device = { .init = acc3221_init, .close = acc3221_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/sio/sio_ali5123.c b/src/sio/sio_ali5123.c index 78c585c11..5380e065a 100644 --- a/src/sio/sio_ali5123.c +++ b/src/sio/sio_ali5123.c @@ -463,8 +463,7 @@ ali5123_close(void *priv) static void * ali5123_init(const device_t *info) { - ali5123_t *dev = (ali5123_t *) malloc(sizeof(ali5123_t)); - memset(dev, 0, sizeof(ali5123_t)); + ali5123_t *dev = (ali5123_t *) calloc(1, sizeof(ali5123_t)); dev->fdc = device_add(&fdc_at_ali_device); @@ -492,7 +491,7 @@ const device_t ali5123_device = { .init = ali5123_init, .close = ali5123_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/sio/sio_detect.c b/src/sio/sio_detect.c index 38faf3c2c..ffa0ec9d0 100644 --- a/src/sio/sio_detect.c +++ b/src/sio/sio_detect.c @@ -65,8 +65,7 @@ sio_detect_close(void *priv) static void * sio_detect_init(UNUSED(const device_t *info)) { - sio_detect_t *dev = (sio_detect_t *) malloc(sizeof(sio_detect_t)); - memset(dev, 0, sizeof(sio_detect_t)); + sio_detect_t *dev = (sio_detect_t *) calloc(1, sizeof(sio_detect_t)); device_add(&fdc_at_smc_device); @@ -110,7 +109,7 @@ const device_t sio_detect_device = { .init = sio_detect_init, .close = sio_detect_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/sio/sio_f82c710.c b/src/sio/sio_f82c710.c index d4afb11da..8882f16e0 100644 --- a/src/sio/sio_f82c710.c +++ b/src/sio/sio_f82c710.c @@ -364,8 +364,7 @@ f82c710_close(void *priv) static void * f82c710_init(const device_t *info) { - upc_t *dev = (upc_t *) malloc(sizeof(upc_t)); - memset(dev, 0, sizeof(upc_t)); + upc_t *dev = (upc_t *) calloc(1, sizeof(upc_t)); dev->local = info->local; if (dev->local == 606) { @@ -393,7 +392,7 @@ const device_t f82c606_device = { .init = f82c710_init, .close = f82c710_close, .reset = f82c710_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -407,7 +406,7 @@ const device_t f82c710_device = { .init = f82c710_init, .close = f82c710_close, .reset = f82c710_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/sio/sio_fdc37c669.c b/src/sio/sio_fdc37c669.c index 0cd686991..7f97e79b0 100644 --- a/src/sio/sio_fdc37c669.c +++ b/src/sio/sio_fdc37c669.c @@ -335,8 +335,7 @@ fdc37c669_close(void *priv) static void * fdc37c669_init(const device_t *info) { - fdc37c669_t *dev = (fdc37c669_t *) malloc(sizeof(fdc37c669_t)); - memset(dev, 0, sizeof(fdc37c669_t)); + fdc37c669_t *dev = (fdc37c669_t *) calloc(1, sizeof(fdc37c669_t)); dev->id = next_id; @@ -364,7 +363,7 @@ const device_t fdc37c669_device = { .init = fdc37c669_init, .close = fdc37c669_close, .reset = fdc37c669_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -378,7 +377,7 @@ const device_t fdc37c669_370_device = { .init = fdc37c669_init, .close = fdc37c669_close, .reset = fdc37c669_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/sio/sio_fdc37c67x.c b/src/sio/sio_fdc37c67x.c index 871f3b1c8..f0fb8cd64 100644 --- a/src/sio/sio_fdc37c67x.c +++ b/src/sio/sio_fdc37c67x.c @@ -591,8 +591,7 @@ fdc37c67x_close(void *priv) static void * fdc37c67x_init(const device_t *info) { - fdc37c67x_t *dev = (fdc37c67x_t *) malloc(sizeof(fdc37c67x_t)); - memset(dev, 0, sizeof(fdc37c67x_t)); + fdc37c67x_t *dev = (fdc37c67x_t *) calloc(1, sizeof(fdc37c67x_t)); dev->fdc = device_add(&fdc_at_smc_device); @@ -625,7 +624,7 @@ const device_t fdc37c67x_device = { .init = fdc37c67x_init, .close = fdc37c67x_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/sio/sio_fdc37c6xx.c b/src/sio/sio_fdc37c6xx.c index c1fb2c1a5..530fff216 100644 --- a/src/sio/sio_fdc37c6xx.c +++ b/src/sio/sio_fdc37c6xx.c @@ -312,8 +312,7 @@ fdc37c6xx_close(void *priv) static void * fdc37c6xx_init(const device_t *info) { - fdc37c6xx_t *dev = (fdc37c6xx_t *) malloc(sizeof(fdc37c6xx_t)); - memset(dev, 0, sizeof(fdc37c6xx_t)); + fdc37c6xx_t *dev = (fdc37c6xx_t *) calloc(1, sizeof(fdc37c6xx_t)); dev->fdc = device_add(&fdc_at_smc_device); @@ -346,7 +345,7 @@ const device_t fdc37c651_device = { .init = fdc37c6xx_init, .close = fdc37c6xx_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -360,7 +359,7 @@ const device_t fdc37c651_ide_device = { .init = fdc37c6xx_init, .close = fdc37c6xx_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -374,7 +373,7 @@ const device_t fdc37c661_device = { .init = fdc37c6xx_init, .close = fdc37c6xx_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -388,7 +387,7 @@ const device_t fdc37c661_ide_device = { .init = fdc37c6xx_init, .close = fdc37c6xx_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -402,7 +401,7 @@ const device_t fdc37c661_ide_sec_device = { .init = fdc37c6xx_init, .close = fdc37c6xx_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -416,7 +415,7 @@ const device_t fdc37c663_device = { .init = fdc37c6xx_init, .close = fdc37c6xx_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -430,7 +429,7 @@ const device_t fdc37c663_ide_device = { .init = fdc37c6xx_init, .close = fdc37c6xx_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -444,7 +443,7 @@ const device_t fdc37c665_device = { .init = fdc37c6xx_init, .close = fdc37c6xx_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -458,7 +457,7 @@ const device_t fdc37c665_ide_device = { .init = fdc37c6xx_init, .close = fdc37c6xx_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -472,7 +471,7 @@ const device_t fdc37c665_ide_pri_device = { .init = fdc37c6xx_init, .close = fdc37c6xx_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -486,7 +485,7 @@ const device_t fdc37c665_ide_sec_device = { .init = fdc37c6xx_init, .close = fdc37c6xx_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -500,7 +499,7 @@ const device_t fdc37c666_device = { .init = fdc37c6xx_init, .close = fdc37c6xx_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/sio/sio_fdc37c93x.c b/src/sio/sio_fdc37c93x.c index a0152c34a..42908ecaf 100644 --- a/src/sio/sio_fdc37c93x.c +++ b/src/sio/sio_fdc37c93x.c @@ -918,8 +918,7 @@ access_bus_close(void *priv) static void * access_bus_init(UNUSED(const device_t *info)) { - access_bus_t *dev = (access_bus_t *) malloc(sizeof(access_bus_t)); - memset(dev, 0, sizeof(access_bus_t)); + access_bus_t *dev = (access_bus_t *) calloc(1, sizeof(access_bus_t)); return dev; } @@ -932,7 +931,7 @@ static const device_t access_bus_device = { .init = access_bus_init, .close = access_bus_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -950,8 +949,7 @@ static void * fdc37c93x_init(const device_t *info) { int is_compaq; - fdc37c93x_t *dev = (fdc37c93x_t *) malloc(sizeof(fdc37c93x_t)); - memset(dev, 0, sizeof(fdc37c93x_t)); + fdc37c93x_t *dev = (fdc37c93x_t *) calloc(1, sizeof(fdc37c93x_t)); dev->fdc = device_add(&fdc_at_smc_device); @@ -1014,7 +1012,7 @@ const device_t fdc37c931apm_device = { .init = fdc37c93x_init, .close = fdc37c93x_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -1028,7 +1026,7 @@ const device_t fdc37c931apm_compaq_device = { .init = fdc37c93x_init, .close = fdc37c93x_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -1042,7 +1040,7 @@ const device_t fdc37c932_device = { .init = fdc37c93x_init, .close = fdc37c93x_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -1056,7 +1054,7 @@ const device_t fdc37c932fr_device = { .init = fdc37c93x_init, .close = fdc37c93x_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -1070,7 +1068,7 @@ const device_t fdc37c932qf_device = { .init = fdc37c93x_init, .close = fdc37c93x_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -1084,7 +1082,7 @@ const device_t fdc37c935_device = { .init = fdc37c93x_init, .close = fdc37c93x_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -1098,7 +1096,7 @@ const device_t fdc37c935_370_device = { .init = fdc37c93x_init, .close = fdc37c93x_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -1112,7 +1110,7 @@ const device_t fdc37c935_no_nvr_device = { .init = fdc37c93x_init, .close = fdc37c93x_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/sio/sio_fdc37m60x.c b/src/sio/sio_fdc37m60x.c index 38a163538..671b3581b 100644 --- a/src/sio/sio_fdc37m60x.c +++ b/src/sio/sio_fdc37m60x.c @@ -306,8 +306,7 @@ fdc37m60x_close(void *priv) static void * fdc37m60x_init(const device_t *info) { - fdc37m60x_t *dev = (fdc37m60x_t *) malloc(sizeof(fdc37m60x_t)); - memset(dev, 0, sizeof(fdc37m60x_t)); + fdc37m60x_t *dev = (fdc37m60x_t *) calloc(1, sizeof(fdc37m60x_t)); SIO_INDEX_PORT = info->local; dev->fdc = device_add(&fdc_at_smc_device); @@ -329,7 +328,7 @@ const device_t fdc37m60x_device = { .init = fdc37m60x_init, .close = fdc37m60x_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -343,7 +342,7 @@ const device_t fdc37m60x_370_device = { .init = fdc37m60x_init, .close = fdc37m60x_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/sio/sio_it86x1f.c b/src/sio/sio_it86x1f.c index 00524863a..1cde8657e 100644 --- a/src/sio/sio_it86x1f.c +++ b/src/sio/sio_it86x1f.c @@ -602,7 +602,7 @@ it86x1f_pnp_write_vendor_reg(uint8_t ld, uint8_t reg, uint8_t val, void *priv) } static void -it86x1f_write_addr(uint16_t port, uint8_t val, void *priv) +it86x1f_write_addr(UNUSED(uint16_t port), uint8_t val, void *priv) { it86x1f_t *dev = (it86x1f_t *) priv; @@ -623,7 +623,7 @@ it86x1f_write_addr(uint16_t port, uint8_t val, void *priv) } static void -it86x1f_write_data(uint16_t port, uint8_t val, void *priv) +it86x1f_write_data(UNUSED(uint16_t port), uint8_t val, void *priv) { it86x1f_t *dev = (it86x1f_t *) priv; @@ -659,7 +659,7 @@ it86x1f_write_data(uint16_t port, uint8_t val, void *priv) } static uint8_t -it86x1f_read_addr(uint16_t port, void *priv) +it86x1f_read_addr(UNUSED(uint16_t port), void *priv) { it86x1f_t *dev = (it86x1f_t *) priv; uint8_t ret = dev->locked ? 0xff : dev->cur_reg; @@ -670,7 +670,7 @@ it86x1f_read_addr(uint16_t port, void *priv) } static uint8_t -it86x1f_read_data(uint16_t port, void *priv) +it86x1f_read_data(UNUSED(uint16_t port), void *priv) { it86x1f_t *dev = (it86x1f_t *) priv; uint8_t ret = 0xff; @@ -799,8 +799,7 @@ it86x1f_close(void *priv) static void * it86x1f_init(UNUSED(const device_t *info)) { - it86x1f_t *dev = (it86x1f_t *) malloc(sizeof(it86x1f_t)); - memset(dev, 0, sizeof(it86x1f_t)); + it86x1f_t *dev = (it86x1f_t *) calloc(1, sizeof(it86x1f_t)); uint8_t i; for (i = 0; i < (sizeof(it86x1f_models) / sizeof(it86x1f_models[0])); i++) { @@ -844,7 +843,7 @@ const device_t it8661f_device = { .init = it86x1f_init, .close = it86x1f_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -858,7 +857,7 @@ const device_t it8671f_device = { .init = it86x1f_init, .close = it86x1f_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/sio/sio_pc87306.c b/src/sio/sio_pc87306.c index ab7f8597e..33cb0d865 100644 --- a/src/sio/sio_pc87306.c +++ b/src/sio/sio_pc87306.c @@ -68,7 +68,7 @@ pc87306_gpio_write(uint16_t port, uint8_t val, void *priv) } uint8_t -pc87306_gpio_read(uint16_t port, void *priv) +pc87306_gpio_read(uint16_t port, UNUSED(void *priv)) { uint32_t ret = machine_handle_gpio(0, 0xffffffff); @@ -467,8 +467,7 @@ pc87306_close(void *priv) static void * pc87306_init(UNUSED(const device_t *info)) { - pc87306_t *dev = (pc87306_t *) malloc(sizeof(pc87306_t)); - memset(dev, 0, sizeof(pc87306_t)); + pc87306_t *dev = (pc87306_t *) calloc(1, sizeof(pc87306_t)); dev->fdc = device_add(&fdc_at_nsc_device); @@ -495,7 +494,7 @@ const device_t pc87306_device = { .init = pc87306_init, .close = pc87306_close, .reset = pc87306_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/sio/sio_pc87307.c b/src/sio/sio_pc87307.c index cb772aa5b..eba0748c9 100644 --- a/src/sio/sio_pc87307.c +++ b/src/sio/sio_pc87307.c @@ -593,8 +593,7 @@ pc87307_close(void *priv) static void * pc87307_init(const device_t *info) { - pc87307_t *dev = (pc87307_t *) malloc(sizeof(pc87307_t)); - memset(dev, 0, sizeof(pc87307_t)); + pc87307_t *dev = (pc87307_t *) calloc(1, sizeof(pc87307_t)); dev->id = info->local & 0xff; @@ -625,7 +624,7 @@ const device_t pc87307_device = { .init = pc87307_init, .close = pc87307_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -639,7 +638,7 @@ const device_t pc87307_15c_device = { .init = pc87307_init, .close = pc87307_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -653,7 +652,7 @@ const device_t pc87307_both_device = { .init = pc87307_init, .close = pc87307_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -667,7 +666,7 @@ const device_t pc97307_device = { .init = pc87307_init, .close = pc87307_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/sio/sio_pc87309.c b/src/sio/sio_pc87309.c index d10cb3e0b..1b790bc6b 100644 --- a/src/sio/sio_pc87309.c +++ b/src/sio/sio_pc87309.c @@ -466,8 +466,7 @@ pc87309_close(void *priv) static void * pc87309_init(const device_t *info) { - pc87309_t *dev = (pc87309_t *) malloc(sizeof(pc87309_t)); - memset(dev, 0, sizeof(pc87309_t)); + pc87309_t *dev = (pc87309_t *) calloc(1, sizeof(pc87309_t)); dev->id = info->local & 0xff; @@ -497,7 +496,7 @@ const device_t pc87309_device = { .init = pc87309_init, .close = pc87309_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -511,7 +510,7 @@ const device_t pc87309_15c_device = { .init = pc87309_init, .close = pc87309_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/sio/sio_pc87310.c b/src/sio/sio_pc87310.c index 075b819ff..674db6364 100644 --- a/src/sio/sio_pc87310.c +++ b/src/sio/sio_pc87310.c @@ -309,7 +309,7 @@ const device_t pc87310_device = { .init = pc87310_init, .close = pc87310_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -323,7 +323,7 @@ const device_t pc87310_ide_device = { .init = pc87310_init, .close = pc87310_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -337,7 +337,7 @@ const device_t ali5105_device = { .init = pc87310_init, .close = pc87310_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/sio/sio_pc87311.c b/src/sio/sio_pc87311.c index 9740753d1..1f38e6aa8 100644 --- a/src/sio/sio_pc87311.c +++ b/src/sio/sio_pc87311.c @@ -269,8 +269,7 @@ pc87311_close(void *priv) static void * pc87311_init(const device_t *info) { - pc87311_t *dev = (pc87311_t *) malloc(sizeof(pc87311_t)); - memset(dev, 0, sizeof(pc87311_t)); + pc87311_t *dev = (pc87311_t *) calloc(1, sizeof(pc87311_t)); /* Avoid conflicting with machines that make no use of the PC87311 Internal IDE */ HAS_IDE_FUNCTIONALITY = info->local; @@ -298,7 +297,7 @@ const device_t pc87311_device = { .init = pc87311_init, .close = pc87311_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -312,7 +311,7 @@ const device_t pc87311_ide_device = { .init = pc87311_init, .close = pc87311_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/sio/sio_pc87332.c b/src/sio/sio_pc87332.c index 5cbf9f694..f746306bd 100644 --- a/src/sio/sio_pc87332.c +++ b/src/sio/sio_pc87332.c @@ -323,8 +323,7 @@ pc87332_close(void *priv) static void * pc87332_init(const device_t *info) { - pc87332_t *dev = (pc87332_t *) malloc(sizeof(pc87332_t)); - memset(dev, 0, sizeof(pc87332_t)); + pc87332_t *dev = (pc87332_t *) calloc(1, sizeof(pc87332_t)); dev->fdc = device_add(&fdc_at_nsc_device); @@ -354,7 +353,7 @@ const device_t pc87332_device = { .init = pc87332_init, .close = pc87332_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -368,7 +367,7 @@ const device_t pc87332_398_device = { .init = pc87332_init, .close = pc87332_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -382,7 +381,7 @@ const device_t pc87332_398_ide_device = { .init = pc87332_init, .close = pc87332_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -396,7 +395,7 @@ const device_t pc87332_398_ide_sec_device = { .init = pc87332_init, .close = pc87332_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -410,7 +409,7 @@ const device_t pc87332_398_ide_fdcon_device = { .init = pc87332_init, .close = pc87332_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/sio/sio_prime3b.c b/src/sio/sio_prime3b.c index c93630516..2cadda2ab 100644 --- a/src/sio/sio_prime3b.c +++ b/src/sio/sio_prime3b.c @@ -257,8 +257,7 @@ prime3b_close(void *priv) static void * prime3b_init(const device_t *info) { - prime3b_t *dev = (prime3b_t *) malloc(sizeof(prime3b_t)); - memset(dev, 0, sizeof(prime3b_t)); + prime3b_t *dev = (prime3b_t *) calloc(1, sizeof(prime3b_t)); /* Avoid conflicting with machines that make no use of the Prime3B Internal IDE */ HAS_IDE_FUNCTIONALITY = info->local; @@ -290,7 +289,7 @@ const device_t prime3b_device = { .init = prime3b_init, .close = prime3b_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -304,7 +303,7 @@ const device_t prime3b_ide_device = { .init = prime3b_init, .close = prime3b_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/sio/sio_prime3c.c b/src/sio/sio_prime3c.c index b19f861bf..e646a3653 100644 --- a/src/sio/sio_prime3c.c +++ b/src/sio/sio_prime3c.c @@ -296,8 +296,7 @@ prime3c_close(void *priv) static void * prime3c_init(const device_t *info) { - prime3c_t *dev = (prime3c_t *) malloc(sizeof(prime3c_t)); - memset(dev, 0, sizeof(prime3c_t)); + prime3c_t *dev = (prime3c_t *) calloc(1, sizeof(prime3c_t)); /* Avoid conflicting with machines that make no use of the Prime3C Internal IDE */ HAS_IDE_FUNCTIONALITY = info->local; @@ -335,7 +334,7 @@ const device_t prime3c_device = { .init = prime3c_init, .close = prime3c_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -349,7 +348,7 @@ const device_t prime3c_ide_device = { .init = prime3c_init, .close = prime3c_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/sio/sio_um8663f.c b/src/sio/sio_um8663f.c index 7391b029f..79cb37da4 100644 --- a/src/sio/sio_um8663f.c +++ b/src/sio/sio_um8663f.c @@ -289,7 +289,7 @@ const device_t um8663af_device = { .init = um8663f_init, .close = um8663f_close, .reset = um8663f_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -303,7 +303,7 @@ const device_t um8663af_ide_device = { .init = um8663f_init, .close = um8663f_close, .reset = um8663f_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -317,7 +317,7 @@ const device_t um8663af_ide_sec_device = { .init = um8663f_init, .close = um8663f_close, .reset = um8663f_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -331,7 +331,7 @@ const device_t um8663bf_device = { .init = um8663f_init, .close = um8663f_close, .reset = um8663f_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -345,7 +345,7 @@ const device_t um8663bf_ide_device = { .init = um8663f_init, .close = um8663f_close, .reset = um8663f_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -359,7 +359,7 @@ const device_t um8663bf_ide_sec_device = { .init = um8663f_init, .close = um8663f_close, .reset = um8663f_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/sio/sio_um8669f.c b/src/sio/sio_um8669f.c index 136b1add6..b3d5259a2 100644 --- a/src/sio/sio_um8669f.c +++ b/src/sio/sio_um8669f.c @@ -328,8 +328,7 @@ um8669f_init(const device_t *info) { um8669f_log("UM8669F: init(%02X)\n", info->local); - um8669f_t *dev = (um8669f_t *) malloc(sizeof(um8669f_t)); - memset(dev, 0, sizeof(um8669f_t)); + um8669f_t *dev = (um8669f_t *) calloc(1, sizeof(um8669f_t)); dev->pnp_card = isapnp_add_card(um8669f_pnp_rom, sizeof(um8669f_pnp_rom), um8669f_pnp_config_changed, NULL, NULL, NULL, dev); for (uint8_t i = 0; i < (sizeof(um8669f_pnp_defaults) / sizeof(isapnp_device_config_t)); i++) @@ -362,7 +361,7 @@ const device_t um8669f_device = { .init = um8669f_init, .close = um8669f_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -376,7 +375,7 @@ const device_t um8669f_ide_device = { .init = um8669f_init, .close = um8669f_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -390,7 +389,7 @@ const device_t um8669f_ide_sec_device = { .init = um8669f_init, .close = um8669f_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/sio/sio_vl82c113.c b/src/sio/sio_vl82c113.c index 6a02ef359..ee18b1893 100644 --- a/src/sio/sio_vl82c113.c +++ b/src/sio/sio_vl82c113.c @@ -24,6 +24,7 @@ #include <86box/keyboard.h> #include <86box/nvr.h> #include <86box/sio.h> +#include <86box/plat_unused.h> typedef struct vl82c113_t { uint8_t index; @@ -128,7 +129,7 @@ vl82c113_close(void *priv) } static void * -vl82c113_init(const device_t *info) +vl82c113_init(UNUSED(const device_t *info)) { vl82c113_t *dev = (vl82c113_t *) calloc(1, sizeof(vl82c113_t)); @@ -155,7 +156,7 @@ const device_t vl82c113_device = { .init = vl82c113_init, .close = vl82c113_close, .reset = vl82c113_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/sio/sio_vt82c686.c b/src/sio/sio_vt82c686.c index f22af07df..fa0bf3c63 100644 --- a/src/sio/sio_vt82c686.c +++ b/src/sio/sio_vt82c686.c @@ -287,8 +287,7 @@ vt82c686_close(void *priv) static void * vt82c686_init(UNUSED(const device_t *info)) { - vt82c686_t *dev = (vt82c686_t *) malloc(sizeof(vt82c686_t)); - memset(dev, 0, sizeof(vt82c686_t)); + vt82c686_t *dev = (vt82c686_t *) calloc(1, sizeof(vt82c686_t)); dev->fdc = device_add(&fdc_at_smc_device); dev->fdc_dma = 2; @@ -311,7 +310,7 @@ const device_t via_vt82c686_sio_device = { .init = vt82c686_init, .close = vt82c686_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/sio/sio_w83787f.c b/src/sio/sio_w83787f.c index 2e4b82059..ea5169afc 100644 --- a/src/sio/sio_w83787f.c +++ b/src/sio/sio_w83787f.c @@ -443,8 +443,7 @@ w83787f_close(void *priv) static void * w83787f_init(const device_t *info) { - w83787f_t *dev = (w83787f_t *) malloc(sizeof(w83787f_t)); - memset(dev, 0, sizeof(w83787f_t)); + w83787f_t *dev = (w83787f_t *) calloc(1, sizeof(w83787f_t)); HAS_IDE_FUNCTIONALITY = (info->local & 0x30); @@ -474,7 +473,7 @@ const device_t w83787f_88h_device = { .init = w83787f_init, .close = w83787f_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -488,7 +487,7 @@ const device_t w83787f_device = { .init = w83787f_init, .close = w83787f_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -502,7 +501,7 @@ const device_t w83787f_ide_device = { .init = w83787f_init, .close = w83787f_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -516,7 +515,7 @@ const device_t w83787f_ide_en_device = { .init = w83787f_init, .close = w83787f_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -530,7 +529,7 @@ const device_t w83787f_ide_sec_device = { .init = w83787f_init, .close = w83787f_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/sio/sio_w83877f.c b/src/sio/sio_w83877f.c index c9a437630..90a3dba1b 100644 --- a/src/sio/sio_w83877f.c +++ b/src/sio/sio_w83877f.c @@ -444,8 +444,7 @@ w83877f_close(void *priv) static void * w83877f_init(const device_t *info) { - w83877f_t *dev = (w83877f_t *) malloc(sizeof(w83877f_t)); - memset(dev, 0, sizeof(w83877f_t)); + w83877f_t *dev = (w83877f_t *) calloc(1, sizeof(w83877f_t)); dev->fdc = device_add(&fdc_at_winbond_device); @@ -467,7 +466,7 @@ const device_t w83877f_device = { .init = w83877f_init, .close = w83877f_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -481,7 +480,7 @@ const device_t w83877f_president_device = { .init = w83877f_init, .close = w83877f_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -495,7 +494,7 @@ const device_t w83877tf_device = { .init = w83877f_init, .close = w83877f_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -509,7 +508,7 @@ const device_t w83877tf_acorp_device = { .init = w83877f_init, .close = w83877f_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/sio/sio_w83977f.c b/src/sio/sio_w83977f.c index 063f0ca69..1d743cc64 100644 --- a/src/sio/sio_w83977f.c +++ b/src/sio/sio_w83977f.c @@ -593,8 +593,7 @@ w83977f_close(void *priv) static void * w83977f_init(const device_t *info) { - w83977f_t *dev = (w83977f_t *) malloc(sizeof(w83977f_t)); - memset(dev, 0, sizeof(w83977f_t)); + w83977f_t *dev = (w83977f_t *) calloc(1, sizeof(w83977f_t)); dev->type = info->local & 0x0f; dev->hefras = info->local & 0x40; @@ -624,7 +623,7 @@ const device_t w83977f_device = { .init = w83977f_init, .close = w83977f_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -638,7 +637,7 @@ const device_t w83977f_370_device = { .init = w83977f_init, .close = w83977f_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -652,7 +651,7 @@ const device_t w83977tf_device = { .init = w83977f_init, .close = w83977f_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -666,7 +665,7 @@ const device_t w83977ef_device = { .init = w83977f_init, .close = w83977f_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -680,7 +679,7 @@ const device_t w83977ef_370_device = { .init = w83977f_init, .close = w83977f_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/sound/midi.c b/src/sound/midi.c index e9b4a82b6..9f83e88dc 100644 --- a/src/sound/midi.c +++ b/src/sound/midi.c @@ -157,8 +157,7 @@ midi_out_device_init(void) void midi_out_init(midi_device_t *device) { - midi_out = (midi_t *) malloc(sizeof(midi_t)); - memset(midi_out, 0, sizeof(midi_t)); + midi_out = (midi_t *) calloc(1, sizeof(midi_t)); midi_out->m_out_device = device; } @@ -166,8 +165,7 @@ midi_out_init(midi_device_t *device) void midi_in_init(midi_device_t *device, midi_t **mididev) { - *mididev = (midi_t *) malloc(sizeof(midi_t)); - memset(*mididev, 0, sizeof(midi_t)); + *mididev = (midi_t *) calloc(1, sizeof(midi_t)); (*mididev)->m_in_device = device; } @@ -394,8 +392,7 @@ midi_in_handler(int set, void (*msg)(void *priv, uint8_t *msg, uint32_t len), in if ((mih_first != NULL) && (mih_last == NULL)) fatal("First MIDI IN handler present with no last MIDI IN handler\n"); - temp = (midi_in_handler_t *) malloc(sizeof(midi_in_handler_t)); - memset(temp, 0, sizeof(midi_in_handler_t)); + temp = (midi_in_handler_t *) calloc(1, sizeof(midi_in_handler_t)); temp->msg = msg; temp->sysex = sysex; temp->priv = priv; diff --git a/src/sound/midi_fluidsynth.c b/src/sound/midi_fluidsynth.c index 51383bdcf..6ba017cd1 100644 --- a/src/sound/midi_fluidsynth.c +++ b/src/sound/midi_fluidsynth.c @@ -262,8 +262,7 @@ fluidsynth_init(UNUSED(const device_t *info)) al_set_midi(data->samplerate, data->buf_size); - dev = malloc(sizeof(midi_device_t)); - memset(dev, 0, sizeof(midi_device_t)); + dev = calloc(1, sizeof(midi_device_t)); dev->play_msg = fluidsynth_msg; dev->play_sysex = fluidsynth_sysex; diff --git a/src/sound/midi_mt32.c b/src/sound/midi_mt32.c index f95445540..ab2165c52 100644 --- a/src/sound/midi_mt32.c +++ b/src/sound/midi_mt32.c @@ -298,8 +298,7 @@ mt32emu_init(char *control_rom, char *pcm_rom) al_set_midi(samplerate, buf_size); - dev = malloc(sizeof(midi_device_t)); - memset(dev, 0, sizeof(midi_device_t)); + dev = calloc(1, sizeof(midi_device_t)); dev->play_msg = mt32_msg; dev->play_sysex = mt32_sysex; diff --git a/src/sound/midi_opl4.c b/src/sound/midi_opl4.c index cf99e092d..5ec15cc7c 100644 --- a/src/sound/midi_opl4.c +++ b/src/sound/midi_opl4.c @@ -557,7 +557,7 @@ program_change(uint8_t midi_channel, uint8_t program, opl4_midi_t *opl4_midi) } static void -opl4_midi_thread(void *arg) +opl4_midi_thread(UNUSED(void *arg)) { opl4_midi_t *opl4_midi = opl4_midi_cur; uint32_t i = 0; @@ -648,18 +648,18 @@ opl4_midi_msg(uint8_t *val) } void -opl4_midi_sysex(uint8_t *data, unsigned int len) +opl4_midi_sysex(UNUSED(uint8_t *data), UNUSED(unsigned int len)) { + // } void * -opl4_init(const device_t *info) +opl4_init(UNUSED(const device_t *info)) { midi_device_t *dev; extern void al_set_midi(int freq, int buf_size); - dev = malloc(sizeof(midi_device_t)); - memset(dev, 0, sizeof(midi_device_t)); + dev = calloc(1, sizeof(midi_device_t)); dev->play_msg = opl4_midi_msg; dev->play_sysex = opl4_midi_sysex; diff --git a/src/sound/midi_rtmidi.cpp b/src/sound/midi_rtmidi.cpp index e2458c9fe..9da3fdb91 100644 --- a/src/sound/midi_rtmidi.cpp +++ b/src/sound/midi_rtmidi.cpp @@ -73,8 +73,7 @@ rtmidi_play_sysex(uint8_t *sysex, unsigned int len) void * rtmidi_output_init(UNUSED(const device_t *info)) { - midi_device_t *dev = (midi_device_t *) malloc(sizeof(midi_device_t)); - memset(dev, 0, sizeof(midi_device_t)); + midi_device_t *dev = (midi_device_t *) calloc(1, sizeof(midi_device_t)); dev->play_msg = rtmidi_play_msg; dev->play_sysex = rtmidi_play_sysex; @@ -156,8 +155,7 @@ rtmidi_input_callback(UNUSED(double timeStamp), std::vector *mess void * rtmidi_input_init(UNUSED(const device_t *info)) { - midi_device_t *dev = (midi_device_t *) malloc(sizeof(midi_device_t)); - memset(dev, 0, sizeof(midi_device_t)); + midi_device_t *dev = (midi_device_t *) calloc(1, sizeof(midi_device_t)); try { if (!midiin) diff --git a/src/sound/snd_ac97_codec.c b/src/sound/snd_ac97_codec.c index f6c01c4ea..e92830f67 100644 --- a/src/sound/snd_ac97_codec.c +++ b/src/sound/snd_ac97_codec.c @@ -577,8 +577,7 @@ ac97_codec_getrate(void *priv, uint8_t reg) static void * ac97_codec_init(const device_t *info) { - ac97_codec_t *dev = malloc(sizeof(ac97_codec_t)); - memset(dev, 0, sizeof(ac97_codec_t)); + ac97_codec_t *dev = calloc(1, sizeof(ac97_codec_t)); for (; dev->model < (sizeof(ac97_codecs) / sizeof(ac97_codecs[0])); dev->model++) { if (ac97_codecs[dev->model].device->local == info->local) diff --git a/src/sound/snd_ac97_via.c b/src/sound/snd_ac97_via.c index e3fa9d2e4..8c1e45c40 100644 --- a/src/sound/snd_ac97_via.c +++ b/src/sound/snd_ac97_via.c @@ -787,8 +787,7 @@ ac97_via_speed_changed(void *priv) static void * ac97_via_init(UNUSED(const device_t *info)) { - ac97_via_t *dev = malloc(sizeof(ac97_via_t)); - memset(dev, 0, sizeof(ac97_via_t)); + ac97_via_t *dev = calloc(1, sizeof(ac97_via_t)); ac97_via_log("AC97 VIA: init()\n"); diff --git a/src/sound/snd_adlib.c b/src/sound/snd_adlib.c index 983ccf7d3..1f307596c 100644 --- a/src/sound/snd_adlib.c +++ b/src/sound/snd_adlib.c @@ -103,8 +103,7 @@ adlib_mca_feedb(void *priv) void * adlib_init(UNUSED(const device_t *info)) { - adlib_t *adlib = malloc(sizeof(adlib_t)); - memset(adlib, 0, sizeof(adlib_t)); + adlib_t *adlib = calloc(1, sizeof(adlib_t)); adlib_log("adlib_init\n"); fm_driver_get(FM_YM3812, &adlib->opl); diff --git a/src/sound/snd_adlibgold.c b/src/sound/snd_adlibgold.c index 7b5deaac5..8a809803d 100644 --- a/src/sound/snd_adlibgold.c +++ b/src/sound/snd_adlibgold.c @@ -1066,8 +1066,7 @@ adgold_init(UNUSED(const device_t *info)) FILE *fp; int c; double out; - adgold_t *adgold = malloc(sizeof(adgold_t)); - memset(adgold, 0, sizeof(adgold_t)); + adgold_t *adgold = calloc(1, sizeof(adgold_t)); adgold->dma = device_get_config_int("dma"); adgold->irq = device_get_config_int("irq"); diff --git a/src/sound/snd_audiopci.c b/src/sound/snd_audiopci.c index 07add5062..9e520bcf5 100644 --- a/src/sound/snd_audiopci.c +++ b/src/sound/snd_audiopci.c @@ -2645,8 +2645,7 @@ static void es137x_speed_changed(void *priv); static void * es1370_init(const device_t *info) { - es137x_t *dev = malloc(sizeof(es137x_t)); - memset(dev, 0x00, sizeof(es137x_t)); + es137x_t *dev = calloc(1, sizeof(es137x_t)); dev->type = info->local; if (device_get_config_int("receive_input")) @@ -2689,8 +2688,7 @@ es1370_init(const device_t *info) static void * es1371_init(const device_t *info) { - es137x_t *dev = malloc(sizeof(es137x_t)); - memset(dev, 0x00, sizeof(es137x_t)); + es137x_t *dev = calloc(1, sizeof(es137x_t)); dev->type = info->local & 0xffffff00; if (device_get_config_int("receive_input")) diff --git a/src/sound/snd_azt2316a.c b/src/sound/snd_azt2316a.c index cf05203f3..dfbab2bd3 100644 --- a/src/sound/snd_azt2316a.c +++ b/src/sound/snd_azt2316a.c @@ -974,8 +974,7 @@ azt_init(const device_t *info) int loaded_from_eeprom = 0; uint16_t addr_setting; uint8_t read_eeprom[AZTECH_EEPROM_SIZE]; - azt2316a_t *azt2316a = malloc(sizeof(azt2316a_t)); - memset(azt2316a, 0, sizeof(azt2316a_t)); + azt2316a_t *azt2316a = calloc(1, sizeof(azt2316a_t)); azt2316a->type = info->local; @@ -1226,8 +1225,7 @@ azt_init(const device_t *info) 2x4 to 2x5 -> Mixer interface 2x6, 2xA, 2xC, 2xE -> DSP chip 2x8, 2x9, 388 and 389 FM chip (9 voices).*/ - azt2316a->sb = malloc(sizeof(sb_t)); - memset(azt2316a->sb, 0, sizeof(sb_t)); + azt2316a->sb = calloc(1, sizeof(sb_t)); azt2316a->sb->opl_enabled = device_get_config_int("opl"); @@ -1259,8 +1257,7 @@ azt_init(const device_t *info) sound_set_cd_audio_filter(sbpro_filter_cd_audio, azt2316a->sb); if (azt2316a->cur_mpu401_enabled) { - azt2316a->mpu = (mpu_t *) malloc(sizeof(mpu_t)); - memset(azt2316a->mpu, 0, sizeof(mpu_t)); + azt2316a->mpu = (mpu_t *) calloc(1, sizeof(mpu_t)); mpu401_init(azt2316a->mpu, azt2316a->cur_mpu401_addr, azt2316a->cur_mpu401_irq, M_UART, device_get_config_int("receive_input401")); } else azt2316a->mpu = NULL; diff --git a/src/sound/snd_cmi8x38.c b/src/sound/snd_cmi8x38.c index 833124bb2..5f75d0dc3 100644 --- a/src/sound/snd_cmi8x38.c +++ b/src/sound/snd_cmi8x38.c @@ -1434,8 +1434,7 @@ cmi8x38_reset(void *priv) static void * cmi8x38_init(const device_t *info) { - cmi8x38_t *dev = malloc(sizeof(cmi8x38_t)); - memset(dev, 0, sizeof(cmi8x38_t)); + cmi8x38_t *dev = calloc(1, sizeof(cmi8x38_t)); /* Set the chip type. */ if ((info->local == CMEDIA_CMI8738_6CH) && !device_get_config_int("six_channel")) diff --git a/src/sound/snd_cms.c b/src/sound/snd_cms.c index 2ec81b53d..f8db04fed 100644 --- a/src/sound/snd_cms.c +++ b/src/sound/snd_cms.c @@ -181,8 +181,7 @@ cms_read(uint16_t addr, void *priv) void * cms_init(UNUSED(const device_t *info)) { - cms_t *cms = malloc(sizeof(cms_t)); - memset(cms, 0, sizeof(cms_t)); + cms_t *cms = calloc(1, sizeof(cms_t)); uint16_t addr = device_get_config_hex16("base"); io_sethandler(addr, 0x0010, cms_read, NULL, NULL, cms_write, NULL, NULL, cms); diff --git a/src/sound/snd_cs423x.c b/src/sound/snd_cs423x.c index 288314a13..a7aa04718 100644 --- a/src/sound/snd_cs423x.c +++ b/src/sound/snd_cs423x.c @@ -475,10 +475,9 @@ cs423x_slam_write(UNUSED(uint16_t addr), uint8_t val, void *priv) if (dev->slam_config) cs423x_pnp_config_changed(dev->slam_ld, dev->slam_config, dev); else - dev->slam_config = (isapnp_device_config_t *) malloc(sizeof(isapnp_device_config_t)); + dev->slam_config = (isapnp_device_config_t *) calloc(1, sizeof(isapnp_device_config_t)); /* Start new logical device. */ - memset(dev->slam_config, 0, sizeof(isapnp_device_config_t)); dev->slam_ld = val; break; @@ -853,8 +852,7 @@ cs423x_reset(void *priv) static void * cs423x_init(const device_t *info) { - cs423x_t *dev = malloc(sizeof(cs423x_t)); - memset(dev, 0, sizeof(cs423x_t)); + cs423x_t *dev = calloc(1, sizeof(cs423x_t)); /* Initialize model-specific data. */ dev->type = info->local & 0xff; diff --git a/src/sound/snd_emu8k.c b/src/sound/snd_emu8k.c index 5f13d2f8e..822abeeaa 100644 --- a/src/sound/snd_emu8k.c +++ b/src/sound/snd_emu8k.c @@ -328,7 +328,7 @@ emu8k_log(const char *fmt, ...) static inline int16_t EMU8K_READ(emu8k_t *emu8k, uint32_t addr) { - const register emu8k_mem_pointers_t addrmem = { { addr } }; + register const emu8k_mem_pointers_t addrmem = { { addr } }; return emu8k->ram_pointers[addrmem.hb_address][addrmem.lw_address]; } @@ -2171,8 +2171,7 @@ emu8k_init(emu8k_t *emu8k, uint16_t emu_addr, int onboard_ram) emu8k->rom[0x7ffff] = 0; } - emu8k->empty = malloc(2 * BLOCK_SIZE_WORDS); - memset(emu8k->empty, 0, 2 * BLOCK_SIZE_WORDS); + emu8k->empty = calloc(2, BLOCK_SIZE_WORDS); int j = 0; for (; j < 0x8; j++) { @@ -2186,8 +2185,7 @@ emu8k_init(emu8k_t *emu8k, uint16_t emu_addr, int onboard_ram) /*Clip to 28MB, since that's the max that we can address. */ if (onboard_ram > 0x7000) onboard_ram = 0x7000; - emu8k->ram = malloc(onboard_ram * 1024); - memset(emu8k->ram, 0, onboard_ram * 1024); + emu8k->ram = calloc(1024, onboard_ram); const int i_end = onboard_ram >> 7; int i = 0; for (; i < i_end; i++, j++) { diff --git a/src/sound/snd_gus.c b/src/sound/snd_gus.c index b39d77708..9dcf0f00b 100644 --- a/src/sound/snd_gus.c +++ b/src/sound/snd_gus.c @@ -1348,12 +1348,10 @@ gus_init(UNUSED(const device_t *info)) int c; double out = 1.0; uint8_t gus_ram = device_get_config_int("gus_ram"); - gus_t *gus = malloc(sizeof(gus_t)); - memset(gus, 0x00, sizeof(gus_t)); + gus_t *gus = calloc(1, sizeof(gus_t)); gus->gus_end_ram = 1 << (18 + gus_ram); - gus->ram = (uint8_t *) malloc(gus->gus_end_ram); - memset(gus->ram, 0x00, (gus->gus_end_ram)); + gus->ram = (uint8_t *) calloc(1, gus->gus_end_ram); for (c = 0; c < 32; c++) { gus->ctrl[c] = 1; diff --git a/src/sound/snd_lpt_dac.c b/src/sound/snd_lpt_dac.c index 8fb526f14..812a649a8 100644 --- a/src/sound/snd_lpt_dac.c +++ b/src/sound/snd_lpt_dac.c @@ -82,8 +82,7 @@ dac_get_buffer(int32_t *buffer, int len, void *priv) static void * dac_init(void *lpt) { - lpt_dac_t *lpt_dac = malloc(sizeof(lpt_dac_t)); - memset(lpt_dac, 0, sizeof(lpt_dac_t)); + lpt_dac_t *lpt_dac = calloc(1, sizeof(lpt_dac_t)); lpt_dac->lpt = lpt; diff --git a/src/sound/snd_lpt_dss.c b/src/sound/snd_lpt_dss.c index bd794fffb..06160ce4c 100644 --- a/src/sound/snd_lpt_dss.c +++ b/src/sound/snd_lpt_dss.c @@ -115,8 +115,7 @@ dss_callback(void *priv) static void * dss_init(void *lpt) { - dss_t *dss = malloc(sizeof(dss_t)); - memset(dss, 0, sizeof(dss_t)); + dss_t *dss = calloc(1, sizeof(dss_t)); dss->lpt = lpt; diff --git a/src/sound/snd_opl2board.c b/src/sound/snd_opl2board.c index f1bda3398..a76b6bf4d 100644 --- a/src/sound/snd_opl2board.c +++ b/src/sound/snd_opl2board.c @@ -124,8 +124,7 @@ opl2board_device_mca_feedb(void *priv) void * opl2board_device_init(UNUSED(const device_t *info)) { - opl2board_device_t *serial = malloc(sizeof(opl2board_device_t)); - memset(serial, 0, sizeof(opl2board_device_t)); + opl2board_device_t *serial = calloc(1, sizeof(opl2board_device_t)); opl2board_device_log("opl2board_device_init\n"); fm_driver_get(FM_OPL2BOARD, &serial->opl); diff --git a/src/sound/snd_opl_esfm.c b/src/sound/snd_opl_esfm.c index 993a0ec6b..bcd2a56e9 100644 --- a/src/sound/snd_opl_esfm.c +++ b/src/sound/snd_opl_esfm.c @@ -34,6 +34,7 @@ #include <86box/device.h> #include <86box/timer.h> #include <86box/snd_opl.h> +#include <86box/plat_unused.h> #define RSM_FRAC 10 @@ -175,7 +176,7 @@ esfm_drv_set_do_cycles(void *priv, int8_t do_cycles) } static void * -esfm_drv_init(const device_t *info) +esfm_drv_init(UNUSED(const device_t *info)) { esfm_drv_t *dev = (esfm_drv_t *) calloc(1, sizeof(esfm_drv_t)); dev->flags = FLAG_CYCLES | FLAG_OPL3; diff --git a/src/sound/snd_optimc.c b/src/sound/snd_optimc.c index d69986d98..7058d918c 100644 --- a/src/sound/snd_optimc.c +++ b/src/sound/snd_optimc.c @@ -419,8 +419,7 @@ optimc_init(const device_t *info) music_add_handler(sb_get_music_buffer_sbpro, optimc->sb); sound_set_cd_audio_filter(sbpro_filter_cd_audio, optimc->sb); /* CD audio filter for the default context */ - optimc->mpu = (mpu_t *) malloc(sizeof(mpu_t)); - memset(optimc->mpu, 0, sizeof(mpu_t)); + optimc->mpu = (mpu_t *) calloc(1, sizeof(mpu_t)); mpu401_init(optimc->mpu, optimc->cur_mpu401_addr, optimc->cur_mpu401_irq, M_UART, device_get_config_int("receive_input401")); if (device_get_config_int("receive_input")) diff --git a/src/sound/snd_pas16.c b/src/sound/snd_pas16.c index ed82afebf..05df32322 100644 --- a/src/sound/snd_pas16.c +++ b/src/sound/snd_pas16.c @@ -86,7 +86,7 @@ * Copyright 2008-2024 Sarah Walker. * Copyright 2024 Miran Grca. */ -#define _USE_MATH_DEFINES +#define _USE_MATH_DEFINES #include #include #include @@ -706,6 +706,7 @@ static uint8_t pas16_in(uint16_t port, void *priv) { pas16_t *pas16 = (pas16_t *) priv; + scsi_bus_t *scsi_bus = NULL; uint8_t ret = 0xff; port -= pas16->base; @@ -784,9 +785,11 @@ pas16_in(uint16_t port, void *priv) ret = t128_read(0x1e00, pas16->scsi); break; case 0x5c01: - if (pas16->has_scsi) + if (pas16->has_scsi) { + scsi_bus = &pas16->scsi->ncr.scsibus; /* Bits 0-6 must absolutely be set for SCSI hard disk drivers to work. */ - ret = (((pas16->scsi->ncr.dma_mode != DMA_IDLE) && (pas16->scsi->status & 0x04)) << 7) | 0x7f; + ret = (((scsi_bus->tx_mode != PIO_TX_BUS) && (pas16->scsi->status & 0x04)) << 7) | 0x7f; + } break; case 0x5c03: if (pas16->has_scsi) @@ -1183,10 +1186,11 @@ pas16_scsi_callback(void *priv) { pas16_t * pas16 = (pas16_t *) priv; t128_t * dev = pas16->scsi; + scsi_bus_t * scsi_bus = &dev->ncr.scsibus; t128_callback(pas16->scsi); - if ((dev->ncr.dma_mode != DMA_IDLE) && (dev->status & 0x04)) { + if ((scsi_bus->tx_mode != PIO_TX_BUS) && (dev->status & 0x04)) { timer_stop(&pas16->scsi_timer); pas16->timeout_status &= 0x7f; } @@ -1667,7 +1671,7 @@ pas16_out(uint16_t port, uint8_t val, void *priv) - A 16-bit sample always takes two ctr_clock() ticks. */ static uint16_t -pas16_dma_channel_read(pas16_t *pas16, int channel) +pas16_dma_channel_read(pas16_t *pas16, UNUSED(int channel)) { int status; uint16_t ret; @@ -2316,8 +2320,7 @@ pas16_init(const device_t *info) fm_driver_get(FM_YMF262, &pas16->opl); sb_dsp_set_real_opl(&pas16->dsp, 1); sb_dsp_init(&pas16->dsp, SB_DSP_201, SB_SUBTYPE_DEFAULT, pas16); - pas16->mpu = (mpu_t *) malloc(sizeof(mpu_t)); - memset(pas16->mpu, 0, sizeof(mpu_t)); + pas16->mpu = (mpu_t *) calloc(1, sizeof(mpu_t)); mpu401_init(pas16->mpu, 0, 0, M_UART, device_get_config_int("receive_input401")); sb_dsp_set_mpu(&pas16->dsp, pas16->mpu); diff --git a/src/sound/snd_ps1.c b/src/sound/snd_ps1.c index 531c2a369..15cad0051 100644 --- a/src/sound/snd_ps1.c +++ b/src/sound/snd_ps1.c @@ -166,8 +166,7 @@ ps1snd_get_buffer(int32_t *buffer, int len, void *priv) static void * ps1snd_init(UNUSED(const device_t *info)) { - ps1snd_t *ps1snd = malloc(sizeof(ps1snd_t)); - memset(ps1snd, 0x00, sizeof(ps1snd_t)); + ps1snd_t *ps1snd = calloc(1, sizeof(ps1snd_t)); sn76489_init(&ps1snd->sn76489, 0x0205, 0x0001, SN76496, 4000000); diff --git a/src/sound/snd_pssj.c b/src/sound/snd_pssj.c index 657f94b01..0b09a7b2e 100644 --- a/src/sound/snd_pssj.c +++ b/src/sound/snd_pssj.c @@ -193,8 +193,7 @@ pssj_get_buffer(int32_t *buffer, int len, void *priv) void * pssj_init(UNUSED(const device_t *info)) { - pssj_t *pssj = malloc(sizeof(pssj_t)); - memset(pssj, 0, sizeof(pssj_t)); + pssj_t *pssj = calloc(1, sizeof(pssj_t)); sn76489_init(&pssj->sn76489, 0x00c0, 0x0004, PSSJ, 3579545); @@ -208,8 +207,7 @@ pssj_init(UNUSED(const device_t *info)) void * pssj_1e0_init(UNUSED(const device_t *info)) { - pssj_t *pssj = malloc(sizeof(pssj_t)); - memset(pssj, 0, sizeof(pssj_t)); + pssj_t *pssj = calloc(1, sizeof(pssj_t)); sn76489_init(&pssj->sn76489, 0x01e0, 0x0004, PSSJ, 3579545); @@ -223,8 +221,7 @@ pssj_1e0_init(UNUSED(const device_t *info)) void * pssj_isa_init(UNUSED(const device_t *info)) { - pssj_t *pssj = malloc(sizeof(pssj_t)); - memset(pssj, 0, sizeof(pssj_t)); + pssj_t *pssj = calloc(1, sizeof(pssj_t)); uint16_t addr = device_get_config_hex16("base"); diff --git a/src/sound/snd_resid.cpp b/src/sound/snd_resid.cpp index b9895cf7e..b0503cac2 100644 --- a/src/sound/snd_resid.cpp +++ b/src/sound/snd_resid.cpp @@ -87,10 +87,10 @@ sid_write(uint16_t addr, uint8_t val, UNUSED(void *priv)) #define CLOCK_DELTA(n) (int) (((14318180.0 * n) / 16.0) / (float) RESID_FREQ) static void -fillbuf2(int &count, int16_t *buf, int len) +fillbuf2(int &count, int16_t *buf, UNUSED(int len)) { - int c; - c = psid->sid->clock(count, buf); + int c = psid->sid->clock(count, buf); + if (!c) *buf = psid->last_sample; psid->last_sample = *buf; diff --git a/src/sound/snd_sb.c b/src/sound/snd_sb.c index 016e50c40..ea961a6d3 100644 --- a/src/sound/snd_sb.c +++ b/src/sound/snd_sb.c @@ -1417,7 +1417,7 @@ sb_ct1745_mixer_reset(sb_t *sb) } static void -ess_base_write(uint16_t addr, uint8_t val, void *priv) +ess_base_write(uint16_t addr, UNUSED(uint8_t val), void *priv) { sb_t *ess = (sb_t *) priv; @@ -1463,7 +1463,7 @@ ess_base_read(uint16_t addr, void *priv) } static void -ess_fm_midi_write(uint16_t addr, uint8_t val, void *priv) +ess_fm_midi_write(UNUSED(uint16_t addr), UNUSED(uint8_t val), void *priv) { sb_t *ess = (sb_t *) priv; @@ -1471,7 +1471,7 @@ ess_fm_midi_write(uint16_t addr, uint8_t val, void *priv) } static uint8_t -ess_fm_midi_read(uint16_t addr, void *priv) +ess_fm_midi_read(UNUSED(uint16_t addr), void *priv) { sb_t *ess = (sb_t *) priv; @@ -5913,7 +5913,7 @@ const device_t sb_16_pnp_device = { .init = sb_16_pnp_init, .close = sb_close, .reset = NULL, - { .available = sb_16_pnp_noide_available }, + .available = sb_16_pnp_noide_available, .speed_changed = sb_speed_changed, .force_redraw = NULL, .config = sb_16_pnp_config @@ -6039,7 +6039,7 @@ const device_t sb_awe64_device = { .init = sb_awe32_pnp_init, .close = sb_awe32_close, .reset = NULL, - { .available = sb_awe64_noide_available }, + .available = sb_awe64_noide_available, .speed_changed = sb_speed_changed, .force_redraw = NULL, .config = sb_awe64_config diff --git a/src/sound/snd_sn76489.c b/src/sound/snd_sn76489.c index 8fb8db06e..89064bea4 100644 --- a/src/sound/snd_sn76489.c +++ b/src/sound/snd_sn76489.c @@ -228,8 +228,7 @@ sn76489_init(sn76489_t *sn76489, uint16_t base, uint16_t size, int type, int fre void * sn76489_device_init(UNUSED(const device_t *info)) { - sn76489_t *sn76489 = malloc(sizeof(sn76489_t)); - memset(sn76489, 0, sizeof(sn76489_t)); + sn76489_t *sn76489 = calloc(1, sizeof(sn76489_t)); sn76489_init(sn76489, 0x00c0, 0x0008, SN76496, 3579545); @@ -239,8 +238,7 @@ sn76489_device_init(UNUSED(const device_t *info)) void * ncr8496_device_init(UNUSED(const device_t *info)) { - sn76489_t *sn76489 = malloc(sizeof(sn76489_t)); - memset(sn76489, 0, sizeof(sn76489_t)); + sn76489_t *sn76489 = calloc(1, sizeof(sn76489_t)); sn76489_init(sn76489, 0x00c0, 0x0008, NCR8496, 3579545); @@ -250,8 +248,7 @@ ncr8496_device_init(UNUSED(const device_t *info)) void * tndy_device_init(UNUSED(const device_t *info)) { - sn76489_t *sn76489 = malloc(sizeof(sn76489_t)); - memset(sn76489, 0, sizeof(sn76489_t)); + sn76489_t *sn76489 = calloc(1, sizeof(sn76489_t)); uint16_t addr = device_get_config_hex16("base"); diff --git a/src/sound/snd_ssi2001.c b/src/sound/snd_ssi2001.c index e03be6b4c..0e1bbd96c 100644 --- a/src/sound/snd_ssi2001.c +++ b/src/sound/snd_ssi2001.c @@ -70,8 +70,7 @@ ssi2001_write(uint16_t addr, uint8_t val, void *priv) void * ssi2001_init(UNUSED(const device_t *info)) { - ssi2001_t *ssi2001 = malloc(sizeof(ssi2001_t)); - memset(ssi2001, 0, sizeof(ssi2001_t)); + ssi2001_t *ssi2001 = calloc(1, sizeof(ssi2001_t)); ssi2001->psid = sid_init(0); sid_reset(ssi2001->psid); @@ -95,13 +94,13 @@ ssi2001_close(void *priv) } static uint8_t -entertainer_read(uint16_t addr, void *priv) +entertainer_read(UNUSED(uint16_t addr), UNUSED(void *priv)) { return 0xa5; } static void -entertainer_write(uint16_t addr, uint8_t val, void *priv) +entertainer_write(UNUSED(uint16_t addr), uint8_t val, void *priv) { entertainer_t *entertainer = (entertainer_t *) priv; entertainer->regs = val; @@ -110,10 +109,8 @@ entertainer_write(uint16_t addr, uint8_t val, void *priv) void * entertainer_init(UNUSED(const device_t *info)) { - ssi2001_t *ssi2001 = malloc(sizeof(ssi2001_t)); - entertainer_t *entertainer = malloc(sizeof(entertainer_t)); - memset(ssi2001, 0, sizeof(ssi2001_t)); - memset(entertainer, 0, sizeof(entertainer_t)); + ssi2001_t *ssi2001 = calloc(1, sizeof(ssi2001_t)); + entertainer_t *entertainer = calloc(1, sizeof(entertainer_t)); ssi2001->psid = sid_init(0); sid_reset(ssi2001->psid); @@ -166,15 +163,27 @@ static const device_config_t ssi2001_config[] = { { .description = "" } } }, - { "gameport", "Enable Game port", CONFIG_BINARY, "", 1 }, - { "", "", -1 } + { + .name = "gameport", + .description = "Enable Game port", + .type = CONFIG_BINARY, + .default_string = "", + .default_int = 1 + }, + { .name = "", .description = "", .type = CONFIG_END } // clang-format off }; static const device_config_t entertainer_config[] = { // clang-format off - { "gameport", "Enable Game port", CONFIG_BINARY, "", 1 }, - { "", "", -1 } + { + .name = "gameport", + .description = "Enable Game port", + .type = CONFIG_BINARY, + .default_string = "", + .default_int = 1 + }, + { .name = "", .description = "", .type = CONFIG_END } // clang-format off }; diff --git a/src/sound/snd_wss.c b/src/sound/snd_wss.c index 833308280..0f37cbf27 100644 --- a/src/sound/snd_wss.c +++ b/src/sound/snd_wss.c @@ -107,8 +107,7 @@ wss_get_music_buffer(int32_t *buffer, int len, void *priv) void * wss_init(UNUSED(const device_t *info)) { - wss_t *wss = malloc(sizeof(wss_t)); - memset(wss, 0, sizeof(wss_t)); + wss_t *wss = calloc(1, sizeof(wss_t)); uint16_t addr = device_get_config_hex16("base"); wss->opl_enabled = device_get_config_int("opl"); @@ -209,8 +208,7 @@ ncr_audio_mca_feedb(void *priv) void * ncr_audio_init(UNUSED(const device_t *info)) { - wss_t *wss = malloc(sizeof(wss_t)); - memset(wss, 0, sizeof(wss_t)); + wss_t *wss = calloc(1, sizeof(wss_t)); fm_driver_get(FM_YMF262, &wss->opl); ad1848_init(&wss->ad1848, AD1848_TYPE_DEFAULT); diff --git a/src/timer.c b/src/timer.c index a3a7c9efb..9fed37511 100644 --- a/src/timer.c +++ b/src/timer.c @@ -31,7 +31,8 @@ timer_enable(pc_timer_t *timer) timer_disable(timer); if (timer->next || timer->prev) - fatal("timer_enable - timer->next\n"); + fatal("timer_disable(): Attempting to enable a non-isolated " + "timer incorrectly marked as disabled\n"); /*List currently empty - add to head*/ if (!timer_head) { @@ -92,7 +93,8 @@ timer_disable(pc_timer_t *timer) return; if (!timer->next && !timer->prev && timer != timer_head) - fatal("timer_disable - !timer->next\n"); + fatal("timer_disable(): Attempting to disable an isolated " + "non-head timer incorrectly marked as enabled\n"); timer->flags &= ~TIMER_ENABLED; timer->in_callback = 0; diff --git a/src/unix/dummy_cdrom_ioctl.c b/src/unix/dummy_cdrom_ioctl.c index fb0224bc6..bddfabb5b 100644 --- a/src/unix/dummy_cdrom_ioctl.c +++ b/src/unix/dummy_cdrom_ioctl.c @@ -17,241 +17,226 @@ * Copyright 2023 Miran Grca. */ #include +#ifdef ENABLE_IOCTL_LOG #include +#endif #include #include #include #include #include #define HAVE_STDARG_H -#include <86box/86box.h> #include <86box/scsi_device.h> #include <86box/cdrom.h> +#include <86box/log.h> #include <86box/plat_unused.h> -#include <86box/plat_cdrom.h> +#include <86box/plat_cdrom_ioctl.h> /* 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) -typedef struct dummy_cdrom_ioctl_t { - int toc_valid; -} dummy_cdrom_ioctl_t; +typedef struct ioctl_t { + cdrom_t *dev; + void *log; + void *handle; + char path[256]; +} ioctl_t; -#ifdef ENABLE_DUMMY_CDROM_IOCTL_LOG -int dummy_cdrom_ioctl_do_log = ENABLE_DUMMY_CDROM_IOCTL_LOG; +#ifdef ENABLE_IOCTL_LOG +int ioctl_do_log = ENABLE_IOCTL_LOG; void -dummy_cdrom_ioctl_log(const char *fmt, ...) +ioctl_log(void *priv, const char *fmt, ...) { - va_list ap; - - if (dummy_cdrom_ioctl_do_log) { + if (ioctl_do_log) { + va_list ap; va_start(ap, fmt); - pclog_ex(fmt, ap); + log_out(priv, fmt, ap); va_end(ap); } } #else -# define dummy_cdrom_ioctl_log(fmt, ...) +# define ioctl_log(priv, fmt, ...) #endif -static int -plat_cdrom_open(void *local) +/* Internal functions. */ +static void +ioctl_close_handle(UNUSED(const ioctl_t *ioctl)) { - return 0; } static int -plat_cdrom_load(void *local) +ioctl_open_handle(UNUSED(ioctl_t *ioctl)) { return 0; } static void -plat_cdrom_read_toc(void *local) +ioctl_read_toc(ioctl_t *ioctl) { - dummy_cdrom_ioctl_t *ioctl = (dummy_cdrom_ioctl_t *) local; - - if (!ioctl->toc_valid) - ioctl->toc_valid = 1; } -void -plat_cdrom_get_raw_track_info(UNUSED(void *local), int *num, raw_track_info_t *rti) +/* Shared functions. */ +static int +ioctl_get_track_info(UNUSED(const void *local), UNUSED(const uint32_t track), + UNUSED(int end), UNUSED(track_info_t *ti)) +{ + return 0; +} + +static void +ioctl_get_raw_track_info(UNUSED(const void *local), int *num, uint8_t *rti) { *num = 1; memset(rti, 0x00, 11); } -int -plat_cdrom_is_track_audio(void *local, uint32_t sector) +static int +ioctl_is_track_pre(const void *local, UNUSED(const uint32_t sector)) { - dummy_cdrom_ioctl_t *ioctl = (dummy_cdrom_ioctl_t *) local; + ioctl_t *ioctl = (ioctl_t *) local; - plat_cdrom_read_toc(ioctl); - - const int ret = 0; - - dummy_cdrom_ioctl_log("plat_cdrom_is_track_audio(%08X): %i\n", sector, ret); - - return ret; -} - -int -plat_cdrom_is_track_pre(void *local, uint32_t sector) -{ - dummy_cdrom_ioctl_t *ioctl = (dummy_cdrom_ioctl_t *) local; - - plat_cdrom_read_toc(ioctl); + ioctl_read_toc(ioctl); const int ret = 0; - dummy_cdrom_ioctl_log("plat_cdrom_is_track_audio(%08X): %i\n", sector, ret); + ioctl_log("ioctl_is_track_audio(%08X): %i\n", sector, ret); return ret; } -uint32_t -plat_cdrom_get_track_start(void *local, uint32_t sector, uint8_t *attr, uint8_t *track) +static int +ioctl_read_sector(const void *local, UNUSED(uint8_t *buffer), UNUSED(uint32_t const sector)) { - dummy_cdrom_ioctl_t *ioctl = (dummy_cdrom_ioctl_t *) local; + ioctl_t *ioctl = (ioctl_t *) local; - plat_cdrom_read_toc(ioctl); + ioctl_open_handle(ioctl); - return 0x00000000; -} + ioctl_close_handle(ioctl); -uint32_t -plat_cdrom_get_last_block(void *local) -{ - dummy_cdrom_ioctl_t *ioctl = (dummy_cdrom_ioctl_t *) local; - - plat_cdrom_read_toc(ioctl); - - return 0x00000000; -} - -int -plat_cdrom_ext_medium_changed(UNUSED(void *local)) -{ -#if 0 - dummy_cdrom_ioctl_t *ioctl = (dummy_cdrom_ioctl_t *) local; - - plat_cdrom_read_toc(ioctl); -#endif - - int ret = 0; - - dummy_cdrom_ioctl_log("plat_cdrom_ext_medium_changed(): %i\n", ret); - - return ret; -} - -/* This replaces both Info and EndInfo, they are specified by a variable. */ -int -plat_cdrom_get_audio_track_info(void *local, UNUSED(int end), int track, int *track_num, TMSF *start, uint8_t *attr) -{ - dummy_cdrom_ioctl_t *ioctl = (dummy_cdrom_ioctl_t *) local; - - plat_cdrom_read_toc(ioctl); - - if ((track < 1) || (track == 0xaa)) { - dummy_cdrom_ioctl_log("plat_cdrom_get_audio_track_info(%02i)\n", track); - return 0; - } - - start->min = 0; - start->sec = 0; - start->fr = 2; - - *track_num = 1; - *attr = 0x14; - - dummy_cdrom_ioctl_log("plat_cdrom_get_audio_track_info(%02i): %02i:%02i:%02i, %02i, %02X\n", - track, start->min, start->sec, start->fr, *track_num, *attr); - - return 1; -} - -/* TODO: See if track start is adjusted by 150 or not. */ -int -plat_cdrom_get_audio_sub(UNUSED(void *local), UNUSED(uint32_t sector), uint8_t *attr, uint8_t *track, uint8_t *index, - TMSF *rel_pos, TMSF *abs_pos) -{ - *track = 1; - *attr = 0x14; - *index = 1; - - rel_pos->min = 0; - rel_pos->sec = 0; - rel_pos->fr = 0; - abs_pos->min = 0; - abs_pos->sec = 0; - abs_pos->fr = 2; - - dummy_cdrom_ioctl_log("plat_cdrom_get_audio_sub(): %02i, %02X, %02i, %02i:%02i:%02i, %02i:%02i:%02i\n", - *track, *attr, *index, rel_pos->min, rel_pos->sec, rel_pos->fr, abs_pos->min, abs_pos->sec, abs_pos->fr); - - return 1; -} - -int -plat_cdrom_get_sector_size(UNUSED(void *local), UNUSED(uint32_t sector)) -{ - dummy_cdrom_ioctl_log("BytesPerSector=2048\n"); - - return 2048; -} - -int -plat_cdrom_read_sector(void *local, uint8_t *buffer, uint32_t sector) -{ - dummy_cdrom_ioctl_t *ioctl = (dummy_cdrom_ioctl_t *) local; - - plat_cdrom_open(ioctl); - - /* Raw */ - dummy_cdrom_ioctl_log("Raw\n"); - - plat_cdrom_close(ioctl); - - dummy_cdrom_ioctl_log("ReadSector sector=%d.\n", sector); + ioctl_log("ReadSector sector=%d.\n", sector); return 0; } -void -plat_cdrom_eject(void *local) +static uint8_t +ioctl_get_track_type(UNUSED(const void *local), UNUSED(const uint32_t sector)) { - dummy_cdrom_ioctl_t *ioctl = (dummy_cdrom_ioctl_t *) local; - - plat_cdrom_open(ioctl); - plat_cdrom_close(ioctl); + return 0x00; } -void -plat_cdrom_close(UNUSED(void *local)) +static uint32_t +ioctl_get_last_block(const void *local) { + ioctl_t *ioctl = (ioctl_t *) local; + + ioctl_read_toc(ioctl); + + return 0x00000000; } -int -plat_cdrom_set_drive(void *local, const char *drv) +static int +ioctl_read_dvd_structure(UNUSED(const void *local), UNUSED(const uint8_t layer), UNUSED(const uint8_t format), + UNUSED(uint8_t *buffer), UNUSED(uint32_t *info)) { - dummy_cdrom_ioctl_t *ioctl = (dummy_cdrom_ioctl_t *) local; + return -0x00052100; +} - plat_cdrom_close(ioctl); +static int +ioctl_is_dvd(UNUSED(const void *local)) +{ + return 0; +} - ioctl->toc_valid = 0; - - plat_cdrom_load(ioctl); +static int +ioctl_has_audio(UNUSED(const void *local)) +{ + return 0; +} +static int +ioctl_is_empty(const void *local) +{ return 1; } -int -plat_cdrom_get_local_size(void) +static int +ioctl_ext_medium_changed(UNUSED(void *local)) { - return sizeof(dummy_cdrom_ioctl_t); +#if 0 + ioctl_t *ioctl = (ioctl_t *) local; +#endif + int ret = 0; + + ioctl_log("ioctl_ext_medium_changed(): %i\n", ret); + + return ret; +} + +static void +ioctl_close(void *local) +{ + ioctl_t *ioctl = (ioctl_t *) local; + + ioctl_close_handle(ioctl); + ioctl->handle = NULL; + + ioctl_log(ioctl->log, "Log closed\n"); + + log_close(ioctl->log); + ioctl->log = NULL; +} + +static void +ioctl_load(const void *local) +{ + const ioctl_t *ioctl = (const ioctl_t *) local; + + if (ioctl_open_handle((ioctl_t *) ioctl)) { + ioctl_close_handle((ioctl_t *) ioctl); + + ioctl_read_toc((ioctl_t *) ioctl); + } +} + +static const cdrom_ops_t ioctl_ops = { + ioctl_get_track_info, + ioctl_get_raw_track_info, + ioctl_is_track_pre, + ioctl_read_sector, + ioctl_get_track_type, + ioctl_get_last_block, + ioctl_read_dvd_structure, + ioctl_is_dvd, + ioctl_has_audio, + ioctl_is_empty, + ioctl_close, + ioctl_load +}; + +/* Public functions. */ +void * +ioctl_open(cdrom_t *dev, const char *drv) +{ + ioctl_t *ioctl = (ioctl_t *) calloc(1, sizeof(ioctl_t)); + + if (ioctl != NULL) { + char n[1024] = { 0 }; + + sprintf(n, "CD-ROM %i IOCtl", dev->id + 1); + ioctl->log = log_open(n); + + memset(ioctl->path, 0x00, sizeof(ioctl->path)); + + sprintf(ioctl->path, "%s", drv); + ioctl_log(ioctl->log, "Path is %s\n", ioctl->path); + + ioctl->dev = dev; + + dev->ops = &ioctl_ops; + } + + return ioctl; } diff --git a/src/unix/unix.c b/src/unix/unix.c index 911905ef2..7f653b9b6 100644 --- a/src/unix/unix.c +++ b/src/unix/unix.c @@ -61,7 +61,7 @@ int fixed_size_y = 480; extern int title_set; extern wchar_t sdl_win_title[512]; plat_joystick_t plat_joystick_state[MAX_PLAT_JOYSTICKS]; -joystick_t joystick_state[MAX_JOYSTICKS]; +joystick_t joystick_state[GAMEPORT_MAX][MAX_JOYSTICKS]; int joysticks_present; SDL_mutex *blitmtx; SDL_threadID eventthread; @@ -301,7 +301,7 @@ path_abs(char *path) } void -path_normalize(char *path) +path_normalize(UNUSED(char *path)) { /* No-op. */ } @@ -459,13 +459,13 @@ plat_remove(char *path) } void -ui_sb_update_icon_state(int tag, int state) +ui_sb_update_icon_state(UNUSED(int tag), UNUSED(int state)) { /* No-op. */ } void -ui_sb_update_icon(int tag, int active) +ui_sb_update_icon(UNUSED(int tag), UNUSED(int active)) { /* No-op. */ } @@ -477,7 +477,7 @@ plat_delay_ms(uint32_t count) } void -ui_sb_update_tip(int arg) +ui_sb_update_tip(UNUSED(int arg)) { /* No-op. */ } @@ -514,8 +514,9 @@ path_get_dirname(char *dest, const char *path) *dest = '\0'; } volatile int cpu_thread_run = 1; + void -ui_sb_set_text_w(wchar_t *wstr) +ui_sb_set_text_w(UNUSED(wchar_t *wstr)) { /* No-op. */ } @@ -533,7 +534,7 @@ strnicmp(const char *s1, const char *s2, size_t n) } void -main_thread(void *param) +main_thread(UNUSED(void *param)) { uint32_t old_time; uint32_t new_time; @@ -707,7 +708,7 @@ plat_power_off(void) } void -ui_sb_bugui(char *str) +ui_sb_bugui(UNUSED(char *str)) { /* No-op. */ } @@ -726,7 +727,7 @@ int real_sdl_w; int real_sdl_h; void -ui_sb_set_ready(int ready) +ui_sb_set_ready(UNUSED(int ready)) { /* No-op. */ } @@ -912,14 +913,14 @@ void (*f_rl_callback_handler_remove)(void) = NULL; #endif uint32_t -timer_onesec(uint32_t interval, void *param) +timer_onesec(uint32_t interval, UNUSED(void *param)) { pc_onesec(); return interval; } void -monitor_thread(void *param) +monitor_thread(UNUSED(void *param)) { #ifndef USE_CLI if (isatty(fileno(stdin)) && isatty(fileno(stdout))) { @@ -1369,14 +1370,14 @@ main(int argc, char **argv) return 0; } char * -plat_vidapi_name(int i) +plat_vidapi_name(UNUSED(int i)) { return "default"; } /* Sets up the program language before initialization. */ uint32_t -plat_language_code(char *langcode) +plat_language_code(UNUSED(char *langcode)) { /* or maybe not */ return 0; @@ -1413,7 +1414,7 @@ plat_set_thread_name(void *thread, const char *name) /* Converts back the language code to LCID */ void -plat_language_code_r(uint32_t lcid, char *outbuf, int len) +plat_language_code_r(UNUSED(uint32_t lcid), UNUSED(char *outbuf), UNUSED(int len)) { /* or maybe not */ return; @@ -1451,7 +1452,7 @@ endblit(void) /* API */ void -ui_sb_mt32lcd(char *str) +ui_sb_mt32lcd(UNUSED(char *str)) { /* No-op. */ } diff --git a/src/unix/unix_cdrom.c b/src/unix/unix_cdrom.c index 186c7649b..b1096b0b4 100644 --- a/src/unix/unix_cdrom.c +++ b/src/unix/unix_cdrom.c @@ -32,6 +32,7 @@ #include <86box/hdd.h> #include <86box/scsi_device.h> #include <86box/cdrom.h> +#include <86box/cdrom_image.h> #include <86box/mo.h> #include <86box/zip.h> #include <86box/scsi_disk.h> @@ -69,7 +70,7 @@ cassette_eject(void) } void -cartridge_mount(uint8_t id, char *fn, uint8_t wp) +cartridge_mount(uint8_t id, char *fn, UNUSED(uint8_t wp)) { cart_close(id); cart_load(id, fn); @@ -120,7 +121,7 @@ floppy_eject(uint8_t id) } void -plat_cdrom_ui_update(uint8_t id, uint8_t reload) +plat_cdrom_ui_update(uint8_t id, UNUSED(uint8_t reload)) { cdrom_t *drv = &cdrom[id]; @@ -140,13 +141,13 @@ void cdrom_mount(uint8_t id, char *fn) { strcpy(cdrom[id].prev_image_path, cdrom[id].image_path); - if (cdrom[id].ops && cdrom[id].ops->exit) - cdrom[id].ops->exit(&(cdrom[id])); + if (cdrom[id].ops && cdrom[id].ops->close) + cdrom[id].ops->close(cdrom[id].local); cdrom[id].ops = NULL; memset(cdrom[id].image_path, 0, sizeof(cdrom[id].image_path)); if ((fn != NULL) && (strlen(fn) >= 1) && (fn[strlen(fn) - 1] == '\\')) fn[strlen(fn) - 1] = '/'; - cdrom_image_open(&(cdrom[id]), fn); + image_open(&(cdrom[id]), fn); /* Signal media change to the emulated machine. */ if (cdrom[id].insert) cdrom[id].insert(cdrom[id].priv); @@ -187,8 +188,7 @@ mo_mount(uint8_t id, char *fn, uint8_t wp) mo_disk_close(dev); mo_drives[id].read_only = wp; - mo_load(dev, fn); - mo_insert(dev); + mo_load(dev, fn, 0); ui_sb_update_icon_state(SB_MO | id, strlen(mo_drives[id].image_path) ? 0 : 1); #if 0 @@ -245,8 +245,7 @@ zip_mount(uint8_t id, char *fn, uint8_t wp) zip_disk_close(dev); zip_drives[id].read_only = wp; - zip_load(dev, fn); - zip_insert(dev); + zip_load(dev, fn, 0); ui_sb_update_icon_state(SB_ZIP | id, strlen(zip_drives[id].image_path) ? 0 : 1); #if 0 diff --git a/src/unix/unix_sdl.c b/src/unix/unix_sdl.c index 002e33fd6..651822335 100644 --- a/src/unix/unix_sdl.c +++ b/src/unix/unix_sdl.c @@ -533,19 +533,19 @@ ui_window_title(wchar_t *str) } void -ui_init_monitor(int monitor_index) +ui_init_monitor(UNUSED(int monitor_index)) { /* No-op. */ } void -ui_deinit_monitor(int monitor_index) +ui_deinit_monitor(UNUSED(int monitor_index)) { /* No-op. */ } void -plat_resize_request(int w, int h, int monitor_index) +plat_resize_request(UNUSED(int w), UNUSED(int h), int monitor_index) { atomic_store((&doresize_monitors[monitor_index]), 1); } diff --git a/src/usb.c b/src/usb.c index 6bdc8e6c0..222062f4f 100644 --- a/src/usb.c +++ b/src/usb.c @@ -433,7 +433,7 @@ const device_t usb_device = { .init = usb_init, .close = usb_close, .reset = usb_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/video/agpgart.c b/src/video/agpgart.c index b8ae2bdc8..bf1976b73 100644 --- a/src/video/agpgart.c +++ b/src/video/agpgart.c @@ -167,7 +167,7 @@ const device_t agpgart_device = { .init = agpgart_init, .close = agpgart_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/video/vid_8514a.c b/src/video/vid_8514a.c index 0e51feae4..1c81e8166 100644 --- a/src/video/vid_8514a.c +++ b/src/video/vid_8514a.c @@ -301,7 +301,7 @@ ibm8514_accel_out_pixtrans(svga_t *svga, UNUSED(uint16_t port), uint32_t val, in if ((cmd >= 2) && (dev->accel.cmd & 0x1000)) val = (val >> 8) | (val << 8); } - if ((cmd <= 2) || (cmd == 4) || ((cmd == 6))) { + if ((cmd <= 2) || (cmd == 4) || (cmd == 6)) { if ((dev->accel.cmd & 0x08) && (cmd >= 2)) monoxfer = val; else { @@ -432,6 +432,14 @@ ibm8514_accel_out_fifo(svga_t *svga, uint16_t port, uint32_t val, int len) if (len == 2) { dev->accel.short_stroke = val; + dev->accel.cx = dev->accel.cur_x; + if (dev->accel.cur_x >= 0x600) + dev->accel.cx |= ~0x5ff; + + dev->accel.cy = dev->accel.cur_y; + if (dev->accel.cur_y >= 0x600) + dev->accel.cy |= ~0x5ff; + if (dev->accel.cmd & 0x1000) { ibm8514_short_stroke_start(-1, 0, -1, 0, svga, dev->accel.short_stroke & 0xff, len); ibm8514_short_stroke_start(-1, 0, -1, 0, svga, dev->accel.short_stroke >> 8, len); @@ -1139,16 +1147,8 @@ ibm8514_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat the NOP command)*/ switch (cmd) { case 0: /*NOP (Short Stroke Vectors)*/ - if (dev->accel.ssv_state == 0) { - dev->accel.cx = dev->accel.cur_x; - if (dev->accel.cur_x >= 0x600) - dev->accel.cx |= ~0x5ff; - - dev->accel.cy = dev->accel.cur_y; - if (dev->accel.cur_y >= 0x600) - dev->accel.cy |= ~0x5ff; + if (dev->accel.ssv_state == 0) break; - } if (dev->accel.cmd & 0x08) { while (count-- && dev->accel.ssv_len >= 0) { @@ -3605,6 +3605,12 @@ ibm8514_render_overscan_right(ibm8514_t *dev, svga_t *svga) buffer32->line[dev->displine + svga->y_add][svga->x_add + dev->h_disp + i] = svga->overscan_color; } +void +ibm8514_set_poll(svga_t *svga) +{ + timer_set_callback(&svga->timer, ibm8514_poll); +} + void ibm8514_poll(void *priv) { @@ -3614,7 +3620,7 @@ ibm8514_poll(void *priv) int wx; int wy; - ibm8514_log("IBM 8514/A poll.\n"); + ibm8514_log("IBM 8514/A poll=%x.\n", dev->on); if (dev->on) { ibm8514_log("ON!\n"); if (!dev->linepos) { @@ -3857,7 +3863,7 @@ ibm8514_mca_reset(void *priv) else ibm8514_mca_write(0x102, 0, svga); - timer_set_callback(&svga->timer, svga_poll); + svga_set_poll(svga); } static void * @@ -4032,9 +4038,7 @@ static const device_config_t isa_ext8514_config[] = { { .description = "" } }, }, - { - .type = CONFIG_END - } + { .name = "", .description = "", .type = CONFIG_END } }; // clang-format off @@ -4077,9 +4081,7 @@ static const device_config_t mca_ext8514_config[] = { } } }, - { - .type = CONFIG_END - } + { .name = "", .description = "", .type = CONFIG_END } }; // clang-format off @@ -4091,7 +4093,7 @@ const device_t gen8514_isa_device = { .init = ibm8514_init, .close = ibm8514_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = ibm8514_speed_changed, .force_redraw = ibm8514_force_redraw, .config = isa_ext8514_config @@ -4105,7 +4107,7 @@ const device_t ibm8514_mca_device = { .init = ibm8514_init, .close = ibm8514_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = ibm8514_speed_changed, .force_redraw = ibm8514_force_redraw, .config = mca_ext8514_config diff --git a/src/video/vid_ati18800.c b/src/video/vid_ati18800.c index df41e5d3f..59688087f 100644 --- a/src/video/vid_ati18800.c +++ b/src/video/vid_ati18800.c @@ -347,9 +347,7 @@ static const device_config_t ati18800_wonder_config[] = { } } }, - { - .type = CONFIG_END - } + { .name = "", .description = "", .type = CONFIG_END } }; const device_t ati18800_wonder_device = { @@ -360,7 +358,7 @@ const device_t ati18800_wonder_device = { .init = ati18800_init, .close = ati18800_close, .reset = NULL, - { .available = ati18800_wonder_available }, + .available = ati18800_wonder_available, .speed_changed = ati18800_speed_changed, .force_redraw = ati18800_force_redraw, .config = ati18800_wonder_config @@ -374,7 +372,7 @@ const device_t ati18800_vga88_device = { .init = ati18800_init, .close = ati18800_close, .reset = NULL, - { .available = ati18800_vga88_available }, + .available = ati18800_vga88_available, .speed_changed = ati18800_speed_changed, .force_redraw = ati18800_force_redraw, .config = NULL @@ -388,7 +386,7 @@ const device_t ati18800_device = { .init = ati18800_init, .close = ati18800_close, .reset = NULL, - { .available = ati18800_available }, + .available = ati18800_available, .speed_changed = ati18800_speed_changed, .force_redraw = ati18800_force_redraw, .config = NULL diff --git a/src/video/vid_ati28800.c b/src/video/vid_ati28800.c index b3cf8aad1..4c039d9e6 100644 --- a/src/video/vid_ati28800.c +++ b/src/video/vid_ati28800.c @@ -766,9 +766,7 @@ static const device_config_t ati28800_config[] = { } } }, - { - .type = CONFIG_END - } + { .name = "", .description = "", .type = CONFIG_END } }; #ifdef USE_XL24 @@ -796,9 +794,7 @@ static const device_config_t ati28800_wonderxl_config[] = { } } }, - { - .type = CONFIG_END - } + { .name = "", .description = "", .type = CONFIG_END } }; #endif /* USE_XL24 */ // clang-format on @@ -811,7 +807,7 @@ const device_t ati28800_device = { .init = ati28800_init, .close = ati28800_close, .reset = NULL, - { .available = ati28800_available }, + .available = ati28800_available, .speed_changed = ati28800_speed_changed, .force_redraw = ati28800_force_redraw, .config = ati28800_config @@ -825,7 +821,7 @@ const device_t ati28800k_device = { .init = ati28800k_init, .close = ati28800_close, .reset = NULL, - { .available = ati28800k_available }, + .available = ati28800k_available, .speed_changed = ati28800_speed_changed, .force_redraw = ati28800_force_redraw, .config = ati28800_config @@ -839,7 +835,7 @@ const device_t ati28800k_spc4620p_device = { .init = ati28800k_init, .close = ati28800_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = ati28800_speed_changed, .force_redraw = ati28800_force_redraw, .config = NULL @@ -853,7 +849,7 @@ const device_t ati28800k_spc6033p_device = { .init = ati28800k_init, .close = ati28800_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = ati28800_speed_changed, .force_redraw = ati28800_force_redraw, .config = NULL @@ -867,7 +863,7 @@ const device_t compaq_ati28800_device = { .init = ati28800_init, .close = ati28800_close, .reset = NULL, - { .available = compaq_ati28800_available }, + .available = compaq_ati28800_available, .speed_changed = ati28800_speed_changed, .force_redraw = ati28800_force_redraw, .config = ati28800_config @@ -881,7 +877,7 @@ const device_t ati28800_wonder1024d_xl_plus_device = { .init = ati28800_init, .close = ati28800_close, .reset = NULL, - { .available = ati28800_wonder1024d_xl_plus_available }, + .available = ati28800_wonder1024d_xl_plus_available, .speed_changed = ati28800_speed_changed, .force_redraw = ati28800_force_redraw, .config = NULL @@ -896,7 +892,7 @@ const device_t ati28800_wonderxl24_device = { .init = ati28800_init, .close = ati28800_close, .reset = NULL, - { .available = ati28800_wonderxl24_available }, + .available = ati28800_wonderxl24_available, .speed_changed = ati28800_speed_changed, .force_redraw = ati28800_force_redraw, .config = ati28800_wonderxl_config diff --git a/src/video/vid_ati68860_ramdac.c b/src/video/vid_ati68860_ramdac.c index cb6de4353..bb5ccbf31 100644 --- a/src/video/vid_ati68860_ramdac.c +++ b/src/video/vid_ati68860_ramdac.c @@ -314,7 +314,7 @@ const device_t ati68860_ramdac_device = { .init = ati68860_ramdac_init, .close = ati68860_ramdac_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/video/vid_ati68875_ramdac.c b/src/video/vid_ati68875_ramdac.c index 447a8eca8..5d573a282 100644 --- a/src/video/vid_ati68875_ramdac.c +++ b/src/video/vid_ati68875_ramdac.c @@ -160,7 +160,7 @@ const device_t ati68875_ramdac_device = { .init = ati68875_ramdac_init, .close = ati68875_ramdac_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/video/vid_ati_mach64.c b/src/video/vid_ati_mach64.c index 1c79ae1d5..b3a544fc1 100644 --- a/src/video/vid_ati_mach64.c +++ b/src/video/vid_ati_mach64.c @@ -4733,9 +4733,7 @@ static const device_config_t mach64gx_config[] = { } } }, - { - .type = CONFIG_END - } + { .name = "", .description = "", .type = CONFIG_END } }; static const device_config_t mach64vt2_config[] = { @@ -4758,9 +4756,7 @@ static const device_config_t mach64vt2_config[] = { } } }, - { - .type = CONFIG_END - } + { .name = "", .description = "", .type = CONFIG_END } }; // clang-format on @@ -4772,7 +4768,7 @@ const device_t mach64gx_isa_device = { .init = mach64gx_init, .close = mach64_close, .reset = NULL, - { .available = mach64gx_isa_available }, + .available = mach64gx_isa_available, .speed_changed = mach64_speed_changed, .force_redraw = mach64_force_redraw, .config = mach64gx_config @@ -4786,7 +4782,7 @@ const device_t mach64gx_vlb_device = { .init = mach64gx_init, .close = mach64_close, .reset = NULL, - { .available = mach64gx_vlb_available }, + .available = mach64gx_vlb_available, .speed_changed = mach64_speed_changed, .force_redraw = mach64_force_redraw, .config = mach64gx_config @@ -4800,7 +4796,7 @@ const device_t mach64gx_pci_device = { .init = mach64gx_init, .close = mach64_close, .reset = NULL, - { .available = mach64gx_available }, + .available = mach64gx_available, .speed_changed = mach64_speed_changed, .force_redraw = mach64_force_redraw, .config = mach64gx_config @@ -4814,7 +4810,7 @@ const device_t mach64vt2_device = { .init = mach64vt2_init, .close = mach64_close, .reset = NULL, - { .available = mach64vt2_available }, + .available = mach64vt2_available, .speed_changed = mach64_speed_changed, .force_redraw = mach64_force_redraw, .config = mach64vt2_config diff --git a/src/video/vid_ati_mach8.c b/src/video/vid_ati_mach8.c index d294f61e9..a923ea7e2 100644 --- a/src/video/vid_ati_mach8.c +++ b/src/video/vid_ati_mach8.c @@ -291,7 +291,7 @@ mach_pixel_read(mach_t *mach) } static void -mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint32_t cpu_dat, svga_t *svga, mach_t *mach, ibm8514_t *dev) +mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint32_t cpu_dat, UNUSED(svga_t *svga), mach_t *mach, ibm8514_t *dev) { int compare_mode; uint16_t poly_src = 0; @@ -2503,6 +2503,96 @@ ati8514_in(uint16_t addr, void *priv) return temp; } +static void +ati_render_24bpp(svga_t *svga) +{ + mach_t *mach = (mach_t *) svga->priv; + ibm8514_t *dev = (ibm8514_t *) svga->dev8514; + uint32_t *p; + uint32_t dat; + + if ((dev->displine + svga->y_add) < 0) + return; + + if (dev->changedvram[dev->ma >> 12] || dev->changedvram[(dev->ma >> 12) + 1] || svga->fullchange) { + p = &buffer32->line[dev->displine + svga->y_add][svga->x_add]; + + if (dev->firstline_draw == 2000) + dev->firstline_draw = dev->displine; + dev->lastline_draw = dev->displine; + + if (mach->accel.ext_ge_config & 0x400) { /*BGR, Blue-(23:16), Green-(15:8), Red-(7:0)*/ + for (int x = 0; x <= dev->h_disp; x += 4) { + dat = *(uint32_t *) (&dev->vram[dev->ma & dev->vram_mask]); + p[x] = ((dat & 0xff0000) >> 16) | (dat & 0x00ff00) | ((dat & 0x0000ff) << 16); + + dat = *(uint32_t *) (&dev->vram[(dev->ma + 3) & dev->vram_mask]); + p[x + 1] = ((dat & 0xff0000) >> 16) | (dat & 0x00ff00) | ((dat & 0x0000ff) << 16); + + dat = *(uint32_t *) (&dev->vram[(dev->ma + 6) & dev->vram_mask]); + p[x + 2] = ((dat & 0xff0000) >> 16) | (dat & 0x00ff00) | ((dat & 0x0000ff) << 16); + + dat = *(uint32_t *) (&dev->vram[(dev->ma + 9) & dev->vram_mask]); + p[x + 3] = ((dat & 0xff0000) >> 16) | (dat & 0x00ff00) | ((dat & 0x0000ff) << 16); + + dev->ma += 12; + } + } else { /*RGB, Red-(23:16), Green-(15:8), Blue-(7:0)*/ + for (int x = 0; x <= dev->h_disp; x += 4) { + dat = *(uint32_t *) (&dev->vram[dev->ma & dev->vram_mask]); + p[x] = dat & 0xffffff; + + dat = *(uint32_t *) (&dev->vram[(dev->ma + 3) & dev->vram_mask]); + p[x + 1] = dat & 0xffffff; + + dat = *(uint32_t *) (&dev->vram[(dev->ma + 6) & dev->vram_mask]); + p[x + 2] = dat & 0xffffff; + + dat = *(uint32_t *) (&dev->vram[(dev->ma + 9) & dev->vram_mask]); + p[x + 3] = dat & 0xffffff; + + dev->ma += 12; + } + } + dev->ma &= dev->vram_mask; + } +} + +static void +ati_render_32bpp(svga_t *svga) +{ + mach_t *mach = (mach_t *) svga->priv; + ibm8514_t *dev = (ibm8514_t *) svga->dev8514; + int x; + uint32_t *p; + uint32_t dat; + + if ((dev->displine + svga->y_add) < 0) + return; + + if (dev->changedvram[dev->ma >> 12] || dev->changedvram[(dev->ma >> 12) + 1] || dev->changedvram[(dev->ma >> 12) + 2] || svga->fullchange) { + p = &buffer32->line[dev->displine + svga->y_add][svga->x_add]; + + if (dev->firstline_draw == 2000) + dev->firstline_draw = dev->displine; + dev->lastline_draw = dev->displine; + + if (mach->accel.ext_ge_config & 0x400) { /*BGR, Blue-(23:16), Green-(15:8), Red-(7:0)*/ + for (x = 0; x <= dev->h_disp; x++) { + dat = *(uint32_t *) (&dev->vram[(dev->ma + (x << 2)) & dev->vram_mask]); + *p++ = ((dat & 0x00ff0000) >> 16) | (dat & 0x0000ff00) | ((dat & 0x000000ff) << 16); + } + } else { /*RGB, Red-(31:24), Green-(23:16), Blue-(15:8)*/ + for (x = 0; x <= dev->h_disp; x++) { + dat = *(uint32_t *) (&dev->vram[(dev->ma + (x << 2)) & dev->vram_mask]); + *p++ = ((dat & 0xffffff00) >> 8); + } + } + dev->ma += (x * 4); + dev->ma &= dev->vram_mask; + } +} + void ati8514_recalctimings(svga_t *svga) { @@ -2711,17 +2801,11 @@ mach_recalctimings(svga_t *svga) break; case 24: mach_log("GEConfig24bpp: %03x.\n", mach->accel.ext_ge_config & 0x600); - if (mach->accel.ext_ge_config & 0x400) - svga->render8514 = ibm8514_render_BGR; - else - svga->render8514 = ibm8514_render_24bpp; + svga->render8514 = ati_render_24bpp; break; case 32: mach_log("GEConfig32bpp: %03x.\n", mach->accel.ext_ge_config & 0x600); - if (mach->accel.ext_ge_config & 0x400) - svga->render8514 = ibm8514_render_ABGR8888; - else - svga->render8514 = ibm8514_render_32bpp; + svga->render8514 = ati_render_32bpp; break; default: @@ -5776,7 +5860,7 @@ mach_mca_reset(void *priv) mach_log("MCA reset.\n"); dev->on = 0; mach_mca_write(0x102, 0, mach); - timer_set_callback(&svga->timer, svga_poll); + svga_set_poll(svga); } uint8_t @@ -6155,7 +6239,7 @@ ati8514_init(svga_t *svga, void *ext8514, void *dev8514) if (dev->vram_amount >= 1024) mach->config1 |= 0x20; - mach->config2 = 0x02; + mach->config2 = 0x01 | 0x02; } static int @@ -6245,12 +6329,9 @@ static const device_config_t mach8_config[] = { } } }, - { - .type = CONFIG_END - } + { .name = "", .description = "", .type = CONFIG_END } }; -// clang-format off static const device_config_t mach32_config[] = { { .name = "memory", @@ -6279,12 +6360,9 @@ static const device_config_t mach32_config[] = { } } }, - { - .type = CONFIG_END - } + { .name = "", .description = "", .type = CONFIG_END } }; -// clang-format off static const device_config_t mach32_pci_config[] = { { .name = "ramdac", @@ -6332,92 +6410,90 @@ static const device_config_t mach32_pci_config[] = { } } }, - { - .type = CONFIG_END - } + { .name = "", .description = "", .type = CONFIG_END } }; +// clang-format on const device_t mach8_vga_isa_device = { - .name = "ATI Mach8 (ATI Graphics Ultra) (ISA)", + .name = "ATI Mach8 (ATI Graphics Ultra) (ISA)", .internal_name = "mach8_vga_isa", - .flags = DEVICE_ISA, - .local = 1, - .init = mach8_init, - .close = mach_close, - .reset = NULL, - { .available = mach8_vga_available }, + .flags = DEVICE_ISA, + .local = 1, + .init = mach8_init, + .close = mach_close, + .reset = NULL, + .available = mach8_vga_available, .speed_changed = mach_speed_changed, - .force_redraw = mach_force_redraw, - .config = mach8_config + .force_redraw = mach_force_redraw, + .config = mach8_config }; const device_t mach32_isa_device = { - .name = "ATI Mach32 (ISA)", + .name = "ATI Mach32 (ISA)", .internal_name = "mach32_isa", - .flags = DEVICE_ISA, - .local = 2, - .init = mach8_init, - .close = mach_close, - .reset = NULL, - { .available = mach32_isa_available }, + .flags = DEVICE_ISA, + .local = 2, + .init = mach8_init, + .close = mach_close, + .reset = NULL, + .available = mach32_isa_available, .speed_changed = mach_speed_changed, - .force_redraw = mach_force_redraw, - .config = mach32_config + .force_redraw = mach_force_redraw, + .config = mach32_config }; const device_t mach32_vlb_device = { - .name = "ATI Mach32 (VLB)", + .name = "ATI Mach32 (VLB)", .internal_name = "mach32_vlb", - .flags = DEVICE_VLB, - .local = 2, - .init = mach8_init, - .close = mach_close, - .reset = NULL, - { .available = mach32_vlb_available }, + .flags = DEVICE_VLB, + .local = 2, + .init = mach8_init, + .close = mach_close, + .reset = NULL, + .available = mach32_vlb_available, .speed_changed = mach_speed_changed, - .force_redraw = mach_force_redraw, - .config = mach32_config + .force_redraw = mach_force_redraw, + .config = mach32_config }; const device_t mach32_mca_device = { - .name = "ATI Mach32 (MCA)", + .name = "ATI Mach32 (MCA)", .internal_name = "mach32_mca", - .flags = DEVICE_MCA, - .local = 2, - .init = mach8_init, - .close = mach_close, - .reset = NULL, - { .available = mach32_mca_available }, + .flags = DEVICE_MCA, + .local = 2, + .init = mach8_init, + .close = mach_close, + .reset = NULL, + .available = mach32_mca_available, .speed_changed = mach_speed_changed, - .force_redraw = mach_force_redraw, - .config = mach32_config + .force_redraw = mach_force_redraw, + .config = mach32_config }; const device_t mach32_pci_device = { - .name = "ATI Mach32 (PCI)", + .name = "ATI Mach32 (PCI)", .internal_name = "mach32_pci", - .flags = DEVICE_PCI, - .local = 2, - .init = mach8_init, - .close = mach_close, - .reset = NULL, - { .available = mach32_pci_available }, + .flags = DEVICE_PCI, + .local = 2, + .init = mach8_init, + .close = mach_close, + .reset = NULL, + .available = mach32_pci_available, .speed_changed = mach_speed_changed, - .force_redraw = mach_force_redraw, - .config = mach32_pci_config + .force_redraw = mach_force_redraw, + .config = mach32_pci_config }; const device_t mach32_onboard_pci_device = { - .name = "ATI Mach32 (PCI) On-Board", + .name = "ATI Mach32 (PCI) On-Board", .internal_name = "mach32_pci_onboard", - .flags = DEVICE_PCI, - .local = 2 | 0x100, - .init = mach8_init, - .close = mach_close, - .reset = NULL, - { .available = NULL }, + .flags = DEVICE_PCI, + .local = 2 | 0x100, + .init = mach8_init, + .close = mach_close, + .reset = NULL, + .available = NULL, .speed_changed = mach_speed_changed, - .force_redraw = mach_force_redraw, - .config = mach32_pci_config + .force_redraw = mach_force_redraw, + .config = mach32_pci_config }; - diff --git a/src/video/vid_att20c49x_ramdac.c b/src/video/vid_att20c49x_ramdac.c index f13740d34..7815f79be 100644 --- a/src/video/vid_att20c49x_ramdac.c +++ b/src/video/vid_att20c49x_ramdac.c @@ -182,7 +182,7 @@ const device_t att490_ramdac_device = { .init = att49x_ramdac_init, .close = att49x_ramdac_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -196,7 +196,7 @@ const device_t att491_ramdac_device = { .init = att49x_ramdac_init, .close = att49x_ramdac_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -210,7 +210,7 @@ const device_t att492_ramdac_device = { .init = att49x_ramdac_init, .close = att49x_ramdac_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/video/vid_att2xc498_ramdac.c b/src/video/vid_att2xc498_ramdac.c index 47eebccae..f52b1432f 100644 --- a/src/video/vid_att2xc498_ramdac.c +++ b/src/video/vid_att2xc498_ramdac.c @@ -183,7 +183,7 @@ const device_t att498_ramdac_device = { .init = att498_ramdac_init, .close = att498_ramdac_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/video/vid_av9194.c b/src/video/vid_av9194.c index e7cf75dee..951f3519c 100644 --- a/src/video/vid_av9194.c +++ b/src/video/vid_av9194.c @@ -103,7 +103,7 @@ const device_t av9194_device = { .init = av9194_init, .close = NULL, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/video/vid_bochs_vbe.c b/src/video/vid_bochs_vbe.c index a4459ce4c..473b10983 100644 --- a/src/video/vid_bochs_vbe.c +++ b/src/video/vid_bochs_vbe.c @@ -962,9 +962,7 @@ static const device_config_t bochs_vbe_config[] = { }, .default_int = 16 }, - { - .type = CONFIG_END - } + { .name = "", .description = "", .type = CONFIG_END } // clang-format on }; @@ -976,7 +974,7 @@ const device_t bochs_svga_device = { .init = bochs_vbe_init, .close = bochs_vbe_close, .reset = bochs_vbe_reset, - { .available = bochs_vbe_available }, + .available = bochs_vbe_available, .speed_changed = bochs_vbe_speed_changed, .force_redraw = bochs_vbe_force_redraw, .config = bochs_vbe_config diff --git a/src/video/vid_bt481_ramdac.c b/src/video/vid_bt481_ramdac.c index 6cf5f2b1b..1b81e2dc7 100644 --- a/src/video/vid_bt481_ramdac.c +++ b/src/video/vid_bt481_ramdac.c @@ -26,6 +26,7 @@ #include <86box/timer.h> #include <86box/video.h> #include <86box/vid_svga.h> +#include <86box/plat_unused.h> typedef struct bt481_ramdac_t { int state; @@ -128,7 +129,7 @@ bt481_ramdac_in(uint16_t addr, int rs2, void *priv, svga_t *svga) } static void * -bt481_ramdac_init(const device_t *info) +bt481_ramdac_init(UNUSED(const device_t *info)) { bt481_ramdac_t *ramdac = (bt481_ramdac_t *) malloc(sizeof(bt481_ramdac_t)); memset(ramdac, 0, sizeof(bt481_ramdac_t)); @@ -153,7 +154,7 @@ const device_t bt481_ramdac_device = { .init = bt481_ramdac_init, .close = bt481_ramdac_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/video/vid_bt48x_ramdac.c b/src/video/vid_bt48x_ramdac.c index 6b0ec300b..d608750e3 100644 --- a/src/video/vid_bt48x_ramdac.c +++ b/src/video/vid_bt48x_ramdac.c @@ -538,7 +538,7 @@ const device_t bt484_ramdac_device = { .init = bt48x_ramdac_init, .close = bt48x_ramdac_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -552,7 +552,7 @@ const device_t att20c504_ramdac_device = { .init = bt48x_ramdac_init, .close = bt48x_ramdac_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -566,7 +566,7 @@ const device_t bt485_ramdac_device = { .init = bt48x_ramdac_init, .close = bt48x_ramdac_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -580,7 +580,7 @@ const device_t att20c505_ramdac_device = { .init = bt48x_ramdac_init, .close = bt48x_ramdac_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -594,7 +594,7 @@ const device_t bt485a_ramdac_device = { .init = bt48x_ramdac_init, .close = bt48x_ramdac_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/video/vid_cga.c b/src/video/vid_cga.c index c58c319df..d324368ab 100644 --- a/src/video/vid_cga.c +++ b/src/video/vid_cga.c @@ -448,7 +448,7 @@ cga_interpolate_linear(uint8_t co1, uint8_t co2, double fraction) } static color_t -cga_interpolate_lookup(cga_t *cga, color_t color1, color_t color2, double fraction) +cga_interpolate_lookup(cga_t *cga, color_t color1, color_t color2, UNUSED(double fraction)) { color_t ret; uint8_t dt = cga->double_type - DOUBLE_INTERPOLATE_SRGB; @@ -914,9 +914,7 @@ const device_config_t cga_config[] = { .type = CONFIG_BINARY, .default_int = 1 }, - { - .type = CONFIG_END - } + { .name = "", .description = "", .type = CONFIG_END } }; // clang-format on @@ -928,7 +926,7 @@ const device_t cga_device = { .init = cga_standalone_init, .close = cga_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = cga_speed_changed, .force_redraw = NULL, .config = cga_config @@ -942,7 +940,7 @@ const device_t cga_pravetz_device = { .init = cga_pravetz_init, .close = cga_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = cga_speed_changed, .force_redraw = NULL, .config = cga_config diff --git a/src/video/vid_chips_69000.c b/src/video/vid_chips_69000.c index 5d41dc4a7..012a16348 100644 --- a/src/video/vid_chips_69000.c +++ b/src/video/vid_chips_69000.c @@ -166,12 +166,12 @@ static chips_69000_t *reset_state = NULL; /* TODO: Probe timings on real hardware. */ static video_timings_t timing_chips = { .type = VIDEO_PCI, .write_b = 2, .write_w = 2, .write_l = 1, .read_b = 10, .read_w = 10, .read_l = 10 }; -uint8_t chips_69000_readb_linear(uint32_t addr, void *p); -uint16_t chips_69000_readw_linear(uint32_t addr, void *p); -uint32_t chips_69000_readl_linear(uint32_t addr, void *p); -void chips_69000_writeb_linear(uint32_t addr, uint8_t val, void *p); -void chips_69000_writew_linear(uint32_t addr, uint16_t val, void *p); -void chips_69000_writel_linear(uint32_t addr, uint32_t val, void *p); +uint8_t chips_69000_readb_linear(uint32_t addr, void *priv); +uint16_t chips_69000_readw_linear(uint32_t addr, void *priv); +uint32_t chips_69000_readl_linear(uint32_t addr, void *priv); +void chips_69000_writeb_linear(uint32_t addr, uint8_t val, void *priv); +void chips_69000_writew_linear(uint32_t addr, uint16_t val, void *priv); +void chips_69000_writel_linear(uint32_t addr, uint32_t val, void *priv); /* Multimedia handling. */ uint8_t @@ -1643,9 +1643,9 @@ chips_69000_write_ext_reg(chips_69000_t* chips, uint8_t val) } void -chips_69000_out(uint16_t addr, uint8_t val, void *p) +chips_69000_out(uint16_t addr, uint8_t val, void *priv) { - chips_69000_t *chips = (chips_69000_t *) p; + chips_69000_t *chips = (chips_69000_t *) priv; svga_t *svga = &chips->svga; uint8_t old, index; @@ -1750,9 +1750,9 @@ chips_69000_out(uint16_t addr, uint8_t val, void *p) } uint8_t -chips_69000_in(uint16_t addr, void *p) +chips_69000_in(uint16_t addr, void *priv) { - chips_69000_t *chips = (chips_69000_t *) p; + chips_69000_t *chips = (chips_69000_t *) priv; svga_t *svga = &chips->svga; uint8_t temp = 0, index; @@ -1828,9 +1828,9 @@ chips_69000_in(uint16_t addr, void *p) } static uint8_t -chips_69000_pci_read(int func, int addr, void *p) +chips_69000_pci_read(UNUSED(int func), int addr, void *priv) { - chips_69000_t *chips = (chips_69000_t *) p; + chips_69000_t *chips = (chips_69000_t *) priv; { switch (addr) { @@ -1885,9 +1885,9 @@ chips_69000_pci_read(int func, int addr, void *p) } static void -chips_69000_pci_write(int func, int addr, uint8_t val, void *p) +chips_69000_pci_write(UNUSED(int func), int addr, uint8_t val, void *priv) { - chips_69000_t *chips = (chips_69000_t *) p; + chips_69000_t *chips = (chips_69000_t *) priv; { switch (addr) { @@ -2193,71 +2193,71 @@ chips_69000_writel_mmio(uint32_t addr, uint32_t val, chips_69000_t* chips) } uint8_t -chips_69000_readb_linear(uint32_t addr, void *p) +chips_69000_readb_linear(uint32_t addr, void *priv) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *) priv; chips_69000_t *chips = (chips_69000_t *) svga->priv; if (addr & 0x400000) return chips_69000_readb_mmio(addr, chips); - return svga_readb_linear(addr & 0x1FFFFF, p); + return svga_readb_linear(addr & 0x1FFFFF, priv); } uint16_t -chips_69000_readw_linear(uint32_t addr, void *p) +chips_69000_readw_linear(uint32_t addr, void *priv) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *) priv; chips_69000_t *chips = (chips_69000_t *) svga->priv; if (addr & 0x800000) { if (addr & 0x400000) return bswap16(chips_69000_readw_mmio(addr, chips)); - return bswap16(svga_readw_linear(addr & 0x1FFFFF, p)); + return bswap16(svga_readw_linear(addr & 0x1FFFFF, priv)); } if (addr & 0x400000) return chips_69000_readw_mmio(addr, chips); - return svga_readw_linear(addr & 0x1FFFFF, p); + return svga_readw_linear(addr & 0x1FFFFF, priv); } uint32_t -chips_69000_readl_linear(uint32_t addr, void *p) +chips_69000_readl_linear(uint32_t addr, void *priv) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *) priv; chips_69000_t *chips = (chips_69000_t *) svga->priv; if (addr & 0x800000) { if (addr & 0x400000) return bswap32(chips_69000_readl_mmio(addr, chips)); - return bswap32(svga_readl_linear(addr & 0x1FFFFF, p)); + return bswap32(svga_readl_linear(addr & 0x1FFFFF, priv)); } if (addr & 0x400000) return chips_69000_readl_mmio(addr, chips); - return svga_readl_linear(addr & 0x1FFFFF, p); + return svga_readl_linear(addr & 0x1FFFFF, priv); } void -chips_69000_writeb_linear(uint32_t addr, uint8_t val, void *p) +chips_69000_writeb_linear(uint32_t addr, uint8_t val, void *priv) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *) priv; chips_69000_t *chips = (chips_69000_t *) svga->priv; if (addr & 0x400000) return chips_69000_writeb_mmio(addr, val, chips); - svga_writeb_linear(addr & 0x1FFFFF, val, p); + svga_writeb_linear(addr & 0x1FFFFF, val, priv); } void -chips_69000_writew_linear(uint32_t addr, uint16_t val, void *p) +chips_69000_writew_linear(uint32_t addr, uint16_t val, void *priv) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *) priv; chips_69000_t *chips = (chips_69000_t *) svga->priv; if (addr & 0x800000) @@ -2266,13 +2266,13 @@ chips_69000_writew_linear(uint32_t addr, uint16_t val, void *p) if (addr & 0x400000) return chips_69000_writew_mmio(addr, val, chips); - svga_writew_linear(addr & 0x1FFFFF, val, p); + svga_writew_linear(addr & 0x1FFFFF, val, priv); } void -chips_69000_writel_linear(uint32_t addr, uint32_t val, void *p) +chips_69000_writel_linear(uint32_t addr, uint32_t val, void *priv) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *) priv; chips_69000_t *chips = (chips_69000_t *) svga->priv; if (addr & 0x800000) @@ -2281,7 +2281,7 @@ chips_69000_writel_linear(uint32_t addr, uint32_t val, void *p) if (addr & 0x400000) return chips_69000_writel_mmio(addr, val, chips); - svga_writel_linear(addr & 0x1FFFFF, val, p); + svga_writel_linear(addr & 0x1FFFFF, val, priv); } void @@ -2526,9 +2526,9 @@ chips_69000_available(void) } void -chips_69000_close(void *p) +chips_69000_close(void *priv) { - chips_69000_t *chips = (chips_69000_t *) p; + chips_69000_t *chips = (chips_69000_t *) priv; chips->quit = 1; // thread_set_event(chips->fifo_event); @@ -2544,17 +2544,17 @@ chips_69000_close(void *p) } void -chips_69000_speed_changed(void *p) +chips_69000_speed_changed(void *priv) { - chips_69000_t *chips = (chips_69000_t *) p; + chips_69000_t *chips = (chips_69000_t *) priv; svga_recalctimings(&chips->svga); } void -chips_69000_force_redraw(void *p) +chips_69000_force_redraw(void *priv) { - chips_69000_t *chips = (chips_69000_t *) p; + chips_69000_t *chips = (chips_69000_t *) priv; chips->svga.fullchange = chips->svga.monitor->mon_changeframecount; } @@ -2567,7 +2567,7 @@ const device_t chips_69000_device = { .init = chips_69000_init, .close = chips_69000_close, .reset = chips_69000_reset, - { .available = chips_69000_available }, + .available = chips_69000_available, .speed_changed = chips_69000_speed_changed, .force_redraw = chips_69000_force_redraw, .config = NULL @@ -2581,7 +2581,7 @@ const device_t chips_69000_onboard_device = { .init = chips_69000_init, .close = chips_69000_close, .reset = chips_69000_reset, - { .available = chips_69000_available }, + .available = chips_69000_available, .speed_changed = chips_69000_speed_changed, .force_redraw = chips_69000_force_redraw, .config = NULL diff --git a/src/video/vid_cl54xx.c b/src/video/vid_cl54xx.c index 08a8c7677..51e4ba335 100644 --- a/src/video/vid_cl54xx.c +++ b/src/video/vid_cl54xx.c @@ -4719,9 +4719,7 @@ static const device_config_t gd542x_config[] = { }, .default_int = 512 }, - { - .type = CONFIG_END - } + { .name = "", .description = "", .type = CONFIG_END } }; static const device_config_t gd5426_config[] = { @@ -4748,9 +4746,7 @@ static const device_config_t gd5426_config[] = { }, .default_int = 2048 }, - { - .type = CONFIG_END - } + { .name = "", .description = "", .type = CONFIG_END } }; static const device_config_t gd5428_onboard_config[] = { @@ -4777,9 +4773,7 @@ static const device_config_t gd5428_onboard_config[] = { }, .default_int = 2048 }, - { - .type = CONFIG_END - } + { .name = "", .description = "", .type = CONFIG_END } }; static const device_config_t gd5429_config[] = { @@ -4802,9 +4796,7 @@ static const device_config_t gd5429_config[] = { }, .default_int = 2 }, - { - .type = CONFIG_END - } + { .name = "", .description = "", .type = CONFIG_END } }; static const device_config_t gd5440_onboard_config[] = { @@ -4827,9 +4819,7 @@ static const device_config_t gd5440_onboard_config[] = { }, .default_int = 2 }, - { - .type = CONFIG_END - } + { .name = "", .description = "", .type = CONFIG_END } }; static const device_config_t gd5434_config[] = { @@ -4856,9 +4846,7 @@ static const device_config_t gd5434_config[] = { }, .default_int = 4 }, - { - .type = CONFIG_END - } + { .name = "", .description = "", .type = CONFIG_END } }; static const device_config_t gd5434_onboard_config[] = { @@ -4885,9 +4873,7 @@ static const device_config_t gd5434_onboard_config[] = { }, .default_int = 4 }, - { - .type = CONFIG_END - } + { .name = "", .description = "", .type = CONFIG_END } }; static const device_config_t gd5480_config[] = { @@ -4910,9 +4896,7 @@ static const device_config_t gd5480_config[] = { }, .default_int = 4 }, - { - .type = -1 - } + { .name = "", .description = "", .type = CONFIG_END } }; // clang-format on @@ -4924,7 +4908,7 @@ const device_t gd5401_isa_device = { .init = gd54xx_init, .close = gd54xx_close, .reset = gd54xx_reset, - { .available = gd5401_available }, + .available = gd5401_available, .speed_changed = gd54xx_speed_changed, .force_redraw = gd54xx_force_redraw, .config = NULL, @@ -4938,7 +4922,7 @@ const device_t gd5402_isa_device = { .init = gd54xx_init, .close = gd54xx_close, .reset = gd54xx_reset, - { .available = gd5402_available }, + .available = gd5402_available, .speed_changed = gd54xx_speed_changed, .force_redraw = gd54xx_force_redraw, .config = NULL, @@ -4952,7 +4936,7 @@ const device_t gd5402_onboard_device = { .init = gd54xx_init, .close = gd54xx_close, .reset = gd54xx_reset, - { .available = NULL }, + .available = NULL, .speed_changed = gd54xx_speed_changed, .force_redraw = gd54xx_force_redraw, .config = NULL, @@ -4966,7 +4950,7 @@ const device_t gd5420_isa_device = { .init = gd54xx_init, .close = gd54xx_close, .reset = gd54xx_reset, - { .available = gd5420_available }, + .available = gd5420_available, .speed_changed = gd54xx_speed_changed, .force_redraw = gd54xx_force_redraw, .config = gd542x_config, @@ -4980,7 +4964,7 @@ const device_t gd5422_isa_device = { .init = gd54xx_init, .close = gd54xx_close, .reset = gd54xx_reset, - { .available = gd5422_available }, /* Common BIOS between 5422 and 5424 */ + .available = gd5422_available, /* Common BIOS between 5422 and 5424 */ .speed_changed = gd54xx_speed_changed, .force_redraw = gd54xx_force_redraw, .config = gd542x_config, @@ -4994,7 +4978,7 @@ const device_t gd5424_vlb_device = { .init = gd54xx_init, .close = gd54xx_close, .reset = gd54xx_reset, - { .available = gd5422_available }, /* Common BIOS between 5422 and 5424 */ + .available = gd5422_available, /* Common BIOS between 5422 and 5424 */ .speed_changed = gd54xx_speed_changed, .force_redraw = gd54xx_force_redraw, .config = gd542x_config, @@ -5008,7 +4992,7 @@ const device_t gd5426_isa_device = { .init = gd54xx_init, .close = gd54xx_close, .reset = gd54xx_reset, - { .available = gd5428_isa_available }, + .available = gd5428_isa_available, .speed_changed = gd54xx_speed_changed, .force_redraw = gd54xx_force_redraw, .config = gd5426_config @@ -5023,7 +5007,7 @@ const device_t gd5426_diamond_speedstar_pro_a1_isa_device = { .init = gd54xx_init, .close = gd54xx_close, .reset = gd54xx_reset, - { .available = gd5426_diamond_a1_available }, + .available = gd5426_diamond_a1_available, .speed_changed = gd54xx_speed_changed, .force_redraw = gd54xx_force_redraw, .config = gd5426_config @@ -5037,7 +5021,7 @@ const device_t gd5426_vlb_device = { .init = gd54xx_init, .close = gd54xx_close, .reset = gd54xx_reset, - { .available = gd5428_available }, + .available = gd5428_available, .speed_changed = gd54xx_speed_changed, .force_redraw = gd54xx_force_redraw, .config = gd5426_config @@ -5051,7 +5035,7 @@ const device_t gd5426_onboard_device = { .init = gd54xx_init, .close = gd54xx_close, .reset = gd54xx_reset, - { .available = NULL }, + .available = NULL, .speed_changed = gd54xx_speed_changed, .force_redraw = gd54xx_force_redraw, .config = NULL @@ -5065,7 +5049,7 @@ const device_t gd5428_isa_device = { .init = gd54xx_init, .close = gd54xx_close, .reset = gd54xx_reset, - { .available = gd5428_isa_available }, + .available = gd5428_isa_available, .speed_changed = gd54xx_speed_changed, .force_redraw = gd54xx_force_redraw, .config = gd5426_config @@ -5079,7 +5063,7 @@ const device_t gd5428_vlb_device = { .init = gd54xx_init, .close = gd54xx_close, .reset = gd54xx_reset, - { .available = gd5428_available }, + .available = gd5428_available, .speed_changed = gd54xx_speed_changed, .force_redraw = gd54xx_force_redraw, .config = gd5426_config @@ -5094,7 +5078,7 @@ const device_t gd5428_diamond_speedstar_pro_b1_vlb_device = { .init = gd54xx_init, .close = gd54xx_close, .reset = gd54xx_reset, - { .available = gd5428_diamond_b1_available }, + .available = gd5428_diamond_b1_available, .speed_changed = gd54xx_speed_changed, .force_redraw = gd54xx_force_redraw, .config = gd5426_config @@ -5108,7 +5092,7 @@ const device_t gd5428_boca_isa_device = { .init = gd54xx_init, .close = gd54xx_close, .reset = gd54xx_reset, - { .available = gd5428_boca_isa_available }, + .available = gd5428_boca_isa_available, .speed_changed = gd54xx_speed_changed, .force_redraw = gd54xx_force_redraw, .config = gd5426_config @@ -5122,7 +5106,7 @@ const device_t gd5428_mca_device = { .init = gd54xx_init, .close = gd54xx_close, .reset = gd54xx_reset, - { .available = gd5428_mca_available }, + .available = gd5428_mca_available, .speed_changed = gd54xx_speed_changed, .force_redraw = gd54xx_force_redraw, .config = NULL @@ -5136,7 +5120,7 @@ const device_t gd5426_mca_device = { .init = gd54xx_init, .close = gd54xx_close, .reset = gd54xx_reset, - { .available = gd5426_mca_available }, + .available = gd5426_mca_available, .speed_changed = gd54xx_speed_changed, .force_redraw = gd54xx_force_redraw, .config = gd5426_config @@ -5150,7 +5134,7 @@ const device_t gd5428_onboard_device = { .init = gd54xx_init, .close = gd54xx_close, .reset = gd54xx_reset, - { .available = gd5428_isa_available }, + .available = gd5428_isa_available, .speed_changed = gd54xx_speed_changed, .force_redraw = gd54xx_force_redraw, .config = gd5428_onboard_config @@ -5164,7 +5148,7 @@ const device_t gd5428_vlb_onboard_device = { .init = gd54xx_init, .close = gd54xx_close, .reset = gd54xx_reset, - { .available = NULL }, + .available = NULL, .speed_changed = gd54xx_speed_changed, .force_redraw = gd54xx_force_redraw, .config = gd5428_onboard_config @@ -5178,7 +5162,7 @@ const device_t gd5429_isa_device = { .init = gd54xx_init, .close = gd54xx_close, .reset = gd54xx_reset, - { .available = gd5429_available }, + .available = gd5429_available, .speed_changed = gd54xx_speed_changed, .force_redraw = gd54xx_force_redraw, .config = gd5429_config @@ -5192,7 +5176,7 @@ const device_t gd5429_vlb_device = { .init = gd54xx_init, .close = gd54xx_close, .reset = gd54xx_reset, - { .available = gd5429_available }, + .available = gd5429_available, .speed_changed = gd54xx_speed_changed, .force_redraw = gd54xx_force_redraw, .config = gd5429_config @@ -5207,7 +5191,7 @@ const device_t gd5430_diamond_speedstar_pro_se_a8_vlb_device = { .init = gd54xx_init, .close = gd54xx_close, .reset = gd54xx_reset, - { .available = gd5430_diamond_a8_available }, + .available = gd5430_diamond_a8_available, .speed_changed = gd54xx_speed_changed, .force_redraw = gd54xx_force_redraw, .config = gd5429_config @@ -5221,7 +5205,7 @@ const device_t gd5430_vlb_device = { .init = gd54xx_init, .close = gd54xx_close, .reset = gd54xx_reset, - { .available = gd5430_orchid_vlb_available }, + .available = gd5430_orchid_vlb_available, .speed_changed = gd54xx_speed_changed, .force_redraw = gd54xx_force_redraw, .config = gd5429_config @@ -5235,7 +5219,7 @@ const device_t gd5430_onboard_vlb_device = { .init = gd54xx_init, .close = gd54xx_close, .reset = gd54xx_reset, - { .available = NULL }, + .available = NULL, .speed_changed = gd54xx_speed_changed, .force_redraw = gd54xx_force_redraw, .config = gd5429_config @@ -5249,7 +5233,7 @@ const device_t gd5430_pci_device = { .init = gd54xx_init, .close = gd54xx_close, .reset = gd54xx_reset, - { .available = gd5430_available }, + .available = gd5430_available, .speed_changed = gd54xx_speed_changed, .force_redraw = gd54xx_force_redraw, .config = gd5429_config @@ -5263,7 +5247,7 @@ const device_t gd5430_onboard_pci_device = { .init = gd54xx_init, .close = gd54xx_close, .reset = gd54xx_reset, - { .available = NULL }, + .available = NULL, .speed_changed = gd54xx_speed_changed, .force_redraw = gd54xx_force_redraw, .config = gd5429_config @@ -5277,7 +5261,7 @@ const device_t gd5434_isa_device = { .init = gd54xx_init, .close = gd54xx_close, .reset = gd54xx_reset, - { .available = gd5434_isa_available }, + .available = gd5434_isa_available, .speed_changed = gd54xx_speed_changed, .force_redraw = gd54xx_force_redraw, .config = gd5434_config @@ -5292,7 +5276,7 @@ const device_t gd5434_diamond_speedstar_64_a3_isa_device = { .init = gd54xx_init, .close = gd54xx_close, .reset = gd54xx_reset, - { .available = gd5434_diamond_a3_available }, + .available = gd5434_diamond_a3_available, .speed_changed = gd54xx_speed_changed, .force_redraw = gd54xx_force_redraw, .config = gd5429_config @@ -5306,7 +5290,7 @@ const device_t gd5434_onboard_pci_device = { .init = gd54xx_init, .close = gd54xx_close, .reset = gd54xx_reset, - { .available = NULL }, + .available = NULL, .speed_changed = gd54xx_speed_changed, .force_redraw = gd54xx_force_redraw, .config = gd5434_onboard_config @@ -5320,7 +5304,7 @@ const device_t gd5434_vlb_device = { .init = gd54xx_init, .close = gd54xx_close, .reset = gd54xx_reset, - { .available = gd5430_orchid_vlb_available }, + .available = gd5430_orchid_vlb_available, .speed_changed = gd54xx_speed_changed, .force_redraw = gd54xx_force_redraw, .config = gd5434_config @@ -5334,7 +5318,7 @@ const device_t gd5434_pci_device = { .init = gd54xx_init, .close = gd54xx_close, .reset = gd54xx_reset, - { .available = gd5434_available }, + .available = gd5434_available, .speed_changed = gd54xx_speed_changed, .force_redraw = gd54xx_force_redraw, .config = gd5434_config @@ -5348,7 +5332,7 @@ const device_t gd5436_onboard_pci_device = { .init = gd54xx_init, .close = gd54xx_close, .reset = gd54xx_reset, - { .available = NULL }, + .available = NULL, .speed_changed = gd54xx_speed_changed, .force_redraw = gd54xx_force_redraw, .config = gd5434_config @@ -5362,7 +5346,7 @@ const device_t gd5436_pci_device = { .init = gd54xx_init, .close = gd54xx_close, .reset = gd54xx_reset, - { .available = gd5436_available }, + .available = gd5436_available, .speed_changed = gd54xx_speed_changed, .force_redraw = gd54xx_force_redraw, .config = gd5434_config @@ -5376,7 +5360,7 @@ const device_t gd5440_onboard_pci_device = { .init = gd54xx_init, .close = gd54xx_close, .reset = gd54xx_reset, - { .available = NULL }, + .available = NULL, .speed_changed = gd54xx_speed_changed, .force_redraw = gd54xx_force_redraw, .config = gd5440_onboard_config @@ -5390,7 +5374,7 @@ const device_t gd5440_pci_device = { .init = gd54xx_init, .close = gd54xx_close, .reset = gd54xx_reset, - { .available = gd5440_available }, + .available = gd5440_available, .speed_changed = gd54xx_speed_changed, .force_redraw = gd54xx_force_redraw, .config = gd5429_config @@ -5404,7 +5388,7 @@ const device_t gd5446_pci_device = { .init = gd54xx_init, .close = gd54xx_close, .reset = gd54xx_reset, - { .available = gd5446_available }, + .available = gd5446_available, .speed_changed = gd54xx_speed_changed, .force_redraw = gd54xx_force_redraw, .config = gd5434_config @@ -5418,7 +5402,7 @@ const device_t gd5446_stb_pci_device = { .init = gd54xx_init, .close = gd54xx_close, .reset = gd54xx_reset, - { .available = gd5446_stb_available }, + .available = gd5446_stb_available, .speed_changed = gd54xx_speed_changed, .force_redraw = gd54xx_force_redraw, .config = gd5434_config @@ -5432,7 +5416,7 @@ const device_t gd5480_pci_device = { .init = gd54xx_init, .close = gd54xx_close, .reset = gd54xx_reset, - { .available = gd5480_available }, + .available = gd5480_available, .speed_changed = gd54xx_speed_changed, .force_redraw = gd54xx_force_redraw, .config = gd5480_config diff --git a/src/video/vid_colorplus.c b/src/video/vid_colorplus.c index dcc72a76b..98d6adea7 100644 --- a/src/video/vid_colorplus.c +++ b/src/video/vid_colorplus.c @@ -425,9 +425,7 @@ static const device_config_t colorplus_config[] = { .type = CONFIG_BINARY, .default_int = 1 }, - { - .type = CONFIG_END - } + { .name = "", .description = "", .type = CONFIG_END } // clang-format on }; @@ -439,7 +437,7 @@ const device_t colorplus_device = { .init = colorplus_standalone_init, .close = colorplus_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = colorplus_speed_changed, .force_redraw = NULL, .config = colorplus_config diff --git a/src/video/vid_compaq_cga.c b/src/video/vid_compaq_cga.c index 430c7a64d..13fc399eb 100644 --- a/src/video/vid_compaq_cga.c +++ b/src/video/vid_compaq_cga.c @@ -481,7 +481,7 @@ const device_t compaq_cga_device = { .init = compaq_cga_init, .close = compaq_cga_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = compaq_cga_speed_changed, .force_redraw = NULL, .config = cga_config @@ -495,7 +495,7 @@ const device_t compaq_cga_2_device = { .init = compaq_cga_init, .close = compaq_cga_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = compaq_cga_speed_changed, .force_redraw = NULL, .config = cga_config diff --git a/src/video/vid_ega.c b/src/video/vid_ega.c index fccd4f629..faf4b9066 100644 --- a/src/video/vid_ega.c +++ b/src/video/vid_ega.c @@ -1655,9 +1655,7 @@ static const device_config_t ega_config[] = { }, .default_int = 9 }, - { - .type = CONFIG_END - } + { .name = "", .description = "", .type = CONFIG_END } // clang-format on }; @@ -1669,7 +1667,7 @@ const device_t ega_device = { .init = ega_standalone_init, .close = ega_close, .reset = NULL, - { .available = ega_standalone_available }, + .available = ega_standalone_available, .speed_changed = ega_speed_changed, .force_redraw = NULL, .config = ega_config @@ -1683,7 +1681,7 @@ const device_t cpqega_device = { .init = ega_standalone_init, .close = ega_close, .reset = NULL, - { .available = cpqega_standalone_available }, + .available = cpqega_standalone_available, .speed_changed = ega_speed_changed, .force_redraw = NULL, .config = ega_config @@ -1697,7 +1695,7 @@ const device_t sega_device = { .init = ega_standalone_init, .close = ega_close, .reset = NULL, - { .available = sega_standalone_available }, + .available = sega_standalone_available, .speed_changed = ega_speed_changed, .force_redraw = NULL, .config = ega_config @@ -1711,7 +1709,7 @@ const device_t atiega800p_device = { .init = ega_standalone_init, .close = ega_close, .reset = NULL, - { .available = atiega800p_standalone_available }, + .available = atiega800p_standalone_available, .speed_changed = ega_speed_changed, .force_redraw = NULL, .config = ega_config @@ -1725,7 +1723,7 @@ const device_t iskra_ega_device = { .init = ega_standalone_init, .close = ega_close, .reset = NULL, - { .available = iskra_ega_standalone_available }, + .available = iskra_ega_standalone_available, .speed_changed = ega_speed_changed, .force_redraw = NULL, .config = ega_config @@ -1739,7 +1737,7 @@ const device_t et2000_device = { .init = ega_standalone_init, .close = ega_close, .reset = NULL, - { .available = et2000_standalone_available }, + .available = et2000_standalone_available, .speed_changed = ega_speed_changed, .force_redraw = NULL, .config = ega_config diff --git a/src/video/vid_et3000.c b/src/video/vid_et3000.c index 45a2fc199..8585fedff 100644 --- a/src/video/vid_et3000.c +++ b/src/video/vid_et3000.c @@ -560,7 +560,7 @@ static const device_config_t et3000_config[] = { { .description = "" } } }, - { .type = CONFIG_END } + { .name = "", .description = "", .type = CONFIG_END } // clang-format on }; @@ -572,7 +572,7 @@ const device_t et3000_isa_device = { .init = et3000_init, .close = et3000_close, .reset = NULL, - { .available = et3000_available }, + .available = et3000_available, .speed_changed = et3000_speed_changed, .force_redraw = et3000_force_redraw, .config = et3000_config diff --git a/src/video/vid_et4000.c b/src/video/vid_et4000.c index ad8cf5c46..169dc659b 100644 --- a/src/video/vid_et4000.c +++ b/src/video/vid_et4000.c @@ -981,9 +981,7 @@ static const device_config_t et4000_tc6058af_config[] = { { .files_no = 0 } }, }, - { - .type = CONFIG_END - } + { .name = "", .description = "", .type = CONFIG_END } // clang-format on }; @@ -1028,9 +1026,7 @@ static const device_config_t et4000_bios_config[] = { { .files_no = 0 } }, }, - { - .type = CONFIG_END - } + { .name = "", .description = "", .type = CONFIG_END } // clang-format on }; @@ -1059,9 +1055,7 @@ static const device_config_t et4000_config[] = { } } }, - { - .type = CONFIG_END - } + { .name = "", .description = "", .type = CONFIG_END } // clang-format on }; @@ -1073,7 +1067,7 @@ const device_t et4000_tc6058af_isa_device = { .init = et4000_init, .close = et4000_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = et4000_speed_changed, .force_redraw = et4000_force_redraw, .config = et4000_tc6058af_config @@ -1087,7 +1081,7 @@ const device_t et4000_isa_device = { .init = et4000_init, .close = et4000_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = et4000_speed_changed, .force_redraw = et4000_force_redraw, .config = et4000_bios_config @@ -1101,7 +1095,7 @@ const device_t et4000_mca_device = { .init = et4000_init, .close = et4000_close, .reset = NULL, - { .available = et4000_available }, + .available = et4000_available, .speed_changed = et4000_speed_changed, .force_redraw = et4000_force_redraw, .config = et4000_config @@ -1115,7 +1109,7 @@ const device_t et4000k_isa_device = { .init = et4000_init, .close = et4000_close, .reset = NULL, - { .available = et4000k_available }, + .available = et4000k_available, .speed_changed = et4000_speed_changed, .force_redraw = et4000_force_redraw, .config = et4000_config @@ -1129,7 +1123,7 @@ const device_t et4000k_tg286_isa_device = { .init = et4000_init, .close = et4000_close, .reset = NULL, - { .available = et4000k_available }, + .available = et4000k_available, .speed_changed = et4000_speed_changed, .force_redraw = et4000_force_redraw, .config = et4000_config @@ -1143,7 +1137,7 @@ const device_t et4000_kasan_isa_device = { .init = et4000_init, .close = et4000_close, .reset = NULL, - { .available = et4000_kasan_available }, + .available = et4000_kasan_available, .speed_changed = et4000_speed_changed, .force_redraw = et4000_force_redraw, .config = et4000_config diff --git a/src/video/vid_et4000w32.c b/src/video/vid_et4000w32.c index 2f086f3c7..351dfba5d 100644 --- a/src/video/vid_et4000w32.c +++ b/src/video/vid_et4000w32.c @@ -2961,9 +2961,7 @@ static const device_config_t et4000w32p_config[] = { } } }, - { - .type = CONFIG_END - } + { .name = "", .description = "", .type = CONFIG_END } // clang-format on }; @@ -2975,7 +2973,7 @@ const device_t et4000w32_device = { .init = et4000w32p_init, .close = et4000w32p_close, .reset = NULL, - { .available = et4000w32_available }, + .available = et4000w32_available, .speed_changed = et4000w32p_speed_changed, .force_redraw = et4000w32p_force_redraw, .config = NULL @@ -2989,7 +2987,7 @@ const device_t et4000w32_onboard_device = { .init = et4000w32p_init, .close = et4000w32p_close, .reset = NULL, - { .available = et4000w32_available }, + .available = et4000w32_available, .speed_changed = et4000w32p_speed_changed, .force_redraw = et4000w32p_force_redraw, .config = NULL @@ -3003,7 +3001,7 @@ const device_t et4000w32i_isa_device = { .init = et4000w32p_init, .close = et4000w32p_close, .reset = NULL, - { .available = et4000w32i_isa_available }, + .available = et4000w32i_isa_available, .speed_changed = et4000w32p_speed_changed, .force_redraw = et4000w32p_force_redraw, .config = NULL @@ -3017,7 +3015,7 @@ const device_t et4000w32i_vlb_device = { .init = et4000w32p_init, .close = et4000w32p_close, .reset = NULL, - { .available = et4000w32i_vlb_available }, + .available = et4000w32i_vlb_available, .speed_changed = et4000w32p_speed_changed, .force_redraw = et4000w32p_force_redraw, .config = et4000w32p_config @@ -3031,7 +3029,7 @@ const device_t et4000w32p_videomagic_revb_vlb_device = { .init = et4000w32p_init, .close = et4000w32p_close, .reset = NULL, - { .available = et4000w32p_videomagic_revb_vlb_available }, + .available = et4000w32p_videomagic_revb_vlb_available, .speed_changed = et4000w32p_speed_changed, .force_redraw = et4000w32p_force_redraw, .config = et4000w32p_config @@ -3045,7 +3043,7 @@ const device_t et4000w32p_videomagic_revb_pci_device = { .init = et4000w32p_init, .close = et4000w32p_close, .reset = NULL, - { .available = et4000w32p_videomagic_revb_vlb_available }, + .available = et4000w32p_videomagic_revb_vlb_available, .speed_changed = et4000w32p_speed_changed, .force_redraw = et4000w32p_force_redraw, .config = et4000w32p_config @@ -3059,7 +3057,7 @@ const device_t et4000w32p_revc_vlb_device = { .init = et4000w32p_init, .close = et4000w32p_close, .reset = NULL, - { .available = et4000w32p_revc_available }, + .available = et4000w32p_revc_available, .speed_changed = et4000w32p_speed_changed, .force_redraw = et4000w32p_force_redraw, .config = et4000w32p_config @@ -3073,7 +3071,7 @@ const device_t et4000w32p_revc_pci_device = { .init = et4000w32p_init, .close = et4000w32p_close, .reset = NULL, - { .available = et4000w32p_revc_available }, + .available = et4000w32p_revc_available, .speed_changed = et4000w32p_speed_changed, .force_redraw = et4000w32p_force_redraw, .config = et4000w32p_config @@ -3087,7 +3085,7 @@ const device_t et4000w32p_noncardex_vlb_device = { .init = et4000w32p_init, .close = et4000w32p_close, .reset = NULL, - { .available = et4000w32p_noncardex_available }, + .available = et4000w32p_noncardex_available, .speed_changed = et4000w32p_speed_changed, .force_redraw = et4000w32p_force_redraw, .config = et4000w32p_config @@ -3101,7 +3099,7 @@ const device_t et4000w32p_noncardex_pci_device = { .init = et4000w32p_init, .close = et4000w32p_close, .reset = NULL, - { .available = et4000w32p_noncardex_available }, + .available = et4000w32p_noncardex_available, .speed_changed = et4000w32p_speed_changed, .force_redraw = et4000w32p_force_redraw, .config = et4000w32p_config @@ -3115,7 +3113,7 @@ const device_t et4000w32p_cardex_vlb_device = { .init = et4000w32p_init, .close = et4000w32p_close, .reset = NULL, - { .available = et4000w32p_cardex_available }, + .available = et4000w32p_cardex_available, .speed_changed = et4000w32p_speed_changed, .force_redraw = et4000w32p_force_redraw, .config = et4000w32p_config @@ -3129,7 +3127,7 @@ const device_t et4000w32p_cardex_pci_device = { .init = et4000w32p_init, .close = et4000w32p_close, .reset = NULL, - { .available = et4000w32p_cardex_available }, + .available = et4000w32p_cardex_available, .speed_changed = et4000w32p_speed_changed, .force_redraw = et4000w32p_force_redraw, .config = et4000w32p_config @@ -3143,7 +3141,7 @@ const device_t et4000w32p_vlb_device = { .init = et4000w32p_init, .close = et4000w32p_close, .reset = NULL, - { .available = et4000w32p_available }, + .available = et4000w32p_available, .speed_changed = et4000w32p_speed_changed, .force_redraw = et4000w32p_force_redraw, .config = et4000w32p_config @@ -3157,7 +3155,7 @@ const device_t et4000w32p_pci_device = { .init = et4000w32p_init, .close = et4000w32p_close, .reset = NULL, - { .available = et4000w32p_available }, + .available = et4000w32p_available, .speed_changed = et4000w32p_speed_changed, .force_redraw = et4000w32p_force_redraw, .config = et4000w32p_config diff --git a/src/video/vid_f82c425.c b/src/video/vid_f82c425.c index 772926e1e..c607cda14 100644 --- a/src/video/vid_f82c425.c +++ b/src/video/vid_f82c425.c @@ -631,7 +631,7 @@ const device_t f82c425_video_device = { .init = f82c425_init, .close = f82c425_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = f82c425_speed_changed, .force_redraw = NULL, .config = NULL diff --git a/src/video/vid_genius.c b/src/video/vid_genius.c index 4ae8e6fd1..c7a91aac6 100644 --- a/src/video/vid_genius.c +++ b/src/video/vid_genius.c @@ -826,7 +826,7 @@ const device_t genius_device = { .init = genius_init, .close = genius_close, .reset = NULL, - { .available = genius_available }, + .available = genius_available, .speed_changed = genius_speed_changed, .force_redraw = NULL, .config = NULL diff --git a/src/video/vid_hercules.c b/src/video/vid_hercules.c index 2a725488d..8d99e9c7b 100644 --- a/src/video/vid_hercules.c +++ b/src/video/vid_hercules.c @@ -647,9 +647,7 @@ static const device_config_t hercules_config[] = { .type = CONFIG_BINARY, .default_int = 1 }, - { - .type = CONFIG_END - } + { .name = "", .description = "", .type = CONFIG_END } // clang-format on }; @@ -661,7 +659,7 @@ const device_t hercules_device = { .init = hercules_init, .close = hercules_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = speed_changed, .force_redraw = NULL, .config = hercules_config diff --git a/src/video/vid_herculesplus.c b/src/video/vid_herculesplus.c index 429632f19..1b6b74033 100644 --- a/src/video/vid_herculesplus.c +++ b/src/video/vid_herculesplus.c @@ -732,9 +732,7 @@ static const device_config_t herculesplus_config[] = { .type = CONFIG_BINARY, .default_int = 1 }, - { - .type = CONFIG_END - } + { .name = "", .description = "", .type = CONFIG_END } // clang-format on }; @@ -746,7 +744,7 @@ const device_t herculesplus_device = { .init = herculesplus_init, .close = herculesplus_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = speed_changed, .force_redraw = NULL, .config = herculesplus_config diff --git a/src/video/vid_ht216.c b/src/video/vid_ht216.c index f349864df..3ed9e2bce 100644 --- a/src/video/vid_ht216.c +++ b/src/video/vid_ht216.c @@ -1731,7 +1731,7 @@ static const device_config_t v7_vga_1024i_config[] = { { .description = "" } } }, - { .type = CONFIG_END } + { .name = "", .description = "", .type = CONFIG_END } }; static const device_config_t ht216_32_standalone_config[] = { @@ -1748,7 +1748,7 @@ static const device_config_t ht216_32_standalone_config[] = { { .description = "" } } }, - { .type = CONFIG_END } + { .name = "", .description = "", .type = CONFIG_END } }; // clang-format on @@ -1760,7 +1760,7 @@ const device_t g2_gc205_device = { .init = g2_gc205_init, .close = ht216_close, .reset = NULL, - { .available = g2_gc205_available }, + .available = g2_gc205_available, .speed_changed = ht216_speed_changed, .force_redraw = ht216_force_redraw, .config = NULL @@ -1774,7 +1774,7 @@ const device_t v7_vga_1024i_device = { .init = v7_vga_1024i_init, .close = ht216_close, .reset = NULL, - { .available = v7_vga_1024i_available }, + .available = v7_vga_1024i_available, .speed_changed = ht216_speed_changed, .force_redraw = ht216_force_redraw, .config = v7_vga_1024i_config @@ -1788,7 +1788,7 @@ const device_t ht216_32_pb410a_device = { .init = ht216_pb410a_init, .close = ht216_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = ht216_speed_changed, .force_redraw = ht216_force_redraw, .config = NULL @@ -1802,7 +1802,7 @@ const device_t ht216_32_standalone_device = { .init = ht216_standalone_init, .close = ht216_close, .reset = NULL, - { .available = ht216_standalone_available }, + .available = ht216_standalone_available, .speed_changed = ht216_speed_changed, .force_redraw = ht216_force_redraw, .config = ht216_32_standalone_config @@ -1816,7 +1816,7 @@ const device_t radius_svga_multiview_isa_device = { .init = radius_svga_multiview_init, .close = ht216_close, .reset = NULL, - { .available = radius_svga_multiview_available }, + .available = radius_svga_multiview_available, .speed_changed = ht216_speed_changed, .force_redraw = ht216_force_redraw, .config = NULL @@ -1830,7 +1830,7 @@ const device_t radius_svga_multiview_mca_device = { .init = radius_svga_multiview_init, .close = ht216_close, .reset = NULL, - { .available = radius_svga_multiview_available }, + .available = radius_svga_multiview_available, .speed_changed = ht216_speed_changed, .force_redraw = ht216_force_redraw, .config = NULL diff --git a/src/video/vid_ibm_rgb528_ramdac.c b/src/video/vid_ibm_rgb528_ramdac.c index 1b19a3a0f..dcdbbb25b 100644 --- a/src/video/vid_ibm_rgb528_ramdac.c +++ b/src/video/vid_ibm_rgb528_ramdac.c @@ -982,7 +982,7 @@ const device_t ibm_rgb528_ramdac_device = { .init = ibm_rgb528_ramdac_init, .close = ibm_rgb528_ramdac_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/video/vid_icd2061.c b/src/video/vid_icd2061.c index 4c23d6ec5..7b80a5484 100644 --- a/src/video/vid_icd2061.c +++ b/src/video/vid_icd2061.c @@ -179,7 +179,7 @@ const device_t icd2061_device = { .init = icd2061_init, .close = icd2061_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -193,7 +193,7 @@ const device_t ics9161_device = { .init = icd2061_init, .close = icd2061_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/video/vid_ics2494.c b/src/video/vid_ics2494.c index e85b4539e..350a490cc 100644 --- a/src/video/vid_ics2494.c +++ b/src/video/vid_ics2494.c @@ -168,7 +168,7 @@ const device_t ics2494an_305_device = { .init = ics2494_init, .close = ics2494_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -182,7 +182,7 @@ const device_t ati18810_device = { .init = ics2494_init, .close = ics2494_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -196,7 +196,7 @@ const device_t ati18811_0_device = { .init = ics2494_init, .close = ics2494_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -210,7 +210,7 @@ const device_t ati18811_1_device = { .init = ics2494_init, .close = ics2494_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/video/vid_ics2595.c b/src/video/vid_ics2595.c index ecb414f2b..b5da3d7e2 100644 --- a/src/video/vid_ics2595.c +++ b/src/video/vid_ics2595.c @@ -129,7 +129,7 @@ const device_t ics2595_device = { .init = ics2595_init, .close = ics2595_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/video/vid_im1024.c b/src/video/vid_im1024.c index c7602ffd0..a77ad09c3 100644 --- a/src/video/vid_im1024.c +++ b/src/video/vid_im1024.c @@ -1090,7 +1090,7 @@ const device_t im1024_device = { .init = im1024_init, .close = im1024_close, .reset = NULL, - { .available = im1024_available }, + .available = im1024_available, .speed_changed = im1024_speed_changed, .force_redraw = NULL, .config = NULL diff --git a/src/video/vid_incolor.c b/src/video/vid_incolor.c index e3f37ec65..0abb4a6c2 100644 --- a/src/video/vid_incolor.c +++ b/src/video/vid_incolor.c @@ -1053,7 +1053,7 @@ const device_t incolor_device = { .init = incolor_init, .close = incolor_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = speed_changed, .force_redraw = NULL, .config = NULL diff --git a/src/video/vid_mda.c b/src/video/vid_mda.c index 702fb7e32..edadb4e46 100644 --- a/src/video/vid_mda.c +++ b/src/video/vid_mda.c @@ -379,9 +379,7 @@ static const device_config_t mda_config[] = { } } }, - { - .type = CONFIG_END - } + { .name = "", .description = "", .type = CONFIG_END } // clang-format on }; @@ -393,7 +391,7 @@ const device_t mda_device = { .init = mda_standalone_init, .close = mda_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = mda_speed_changed, .force_redraw = NULL, .config = mda_config diff --git a/src/video/vid_mga.c b/src/video/vid_mga.c index 2b9e63af4..9ee74f512 100644 --- a/src/video/vid_mga.c +++ b/src/video/vid_mga.c @@ -5558,6 +5558,7 @@ blit_bitblt(mystique_t *mystique) mystique->dwgreg.ar[0] += mystique->dwgreg.ar[5]; mystique->dwgreg.ar[3] += mystique->dwgreg.ar[5]; src_addr = mystique->dwgreg.ar[3]; + break; } else src_addr += x_dir; @@ -5670,6 +5671,7 @@ blit_bitblt(mystique_t *mystique) mystique->dwgreg.ar[0] += mystique->dwgreg.ar[5]; mystique->dwgreg.ar[3] += mystique->dwgreg.ar[5]; src_addr = mystique->dwgreg.ar[3]; + break; } else src_addr += x_dir; @@ -5756,6 +5758,7 @@ blit_bitblt(mystique_t *mystique) mystique->dwgreg.ar[0] += mystique->dwgreg.ar[5]; mystique->dwgreg.ar[3] += mystique->dwgreg.ar[5]; src_addr = mystique->dwgreg.ar[3]; + break; } else src_addr += x_dir; @@ -5852,6 +5855,7 @@ blit_bitblt(mystique_t *mystique) mystique->dwgreg.ar[0] += mystique->dwgreg.ar[5]; mystique->dwgreg.ar[3] += mystique->dwgreg.ar[5]; src_addr = mystique->dwgreg.ar[3]; + break; } else src_addr += x_dir; @@ -6170,7 +6174,7 @@ mystique_hwcursor_draw(svga_t *svga, int displine) } static uint8_t -mystique_tvp3026_gpio_read(uint8_t cntl, void *priv) +mystique_tvp3026_gpio_read(UNUSED(uint8_t cntl), void *priv) { mystique_t *mystique = (mystique_t *) priv; @@ -6521,6 +6525,7 @@ mystique_pci_write(UNUSED(int func), int addr, uint8_t val, void *priv) mystique->pci_regs[addr] = val; if (addr == 0x30) mystique->pci_regs[addr] &= 1; + if (mystique->pci_regs[0x30] & 0x01) { uint32_t biosaddr = (mystique->pci_regs[0x32] << 16) | (mystique->pci_regs[0x33] << 24); mem_mapping_set_addr(&mystique->bios_rom.mapping, biosaddr, (mystique->type == MGA_G100) ? 0x10000 : 0x8000); @@ -6533,26 +6538,24 @@ mystique_pci_write(UNUSED(int func), int addr, uint8_t val, void *priv) return; case 0x40: - mystique->pci_regs[addr] = val & 0x3f; + mystique->pci_regs[0x40] = val & 0x3f; break; case 0x41: - mystique->pci_regs[addr] = val; + mystique->pci_regs[0x41] = val; break; case 0x42: - mystique->pci_regs[addr] = val & 0x1f; + mystique->pci_regs[0x42] = val & 0x1f; break; case 0x43: - mystique->pci_regs[addr] = val; - if (addr == 0x43) { - if (val & 0x40) { - if (mystique->pci_regs[0x30] & 0x01) { - uint32_t biosaddr = (mystique->pci_regs[0x32] << 16) | (mystique->pci_regs[0x33] << 24); - mem_mapping_set_addr(&mystique->bios_rom.mapping, biosaddr, (mystique->type == MGA_G100) ? 0x10000 : 0x8000); - } else - mem_mapping_disable(&mystique->bios_rom.mapping); + mystique->pci_regs[0x43] = val; + if (val & 0x40) { + if (mystique->pci_regs[0x30] & 0x01) { + uint32_t biosaddr = (mystique->pci_regs[0x32] << 16) | (mystique->pci_regs[0x33] << 24); + mem_mapping_set_addr(&mystique->bios_rom.mapping, biosaddr, (mystique->type == MGA_G100) ? 0x10000 : 0x8000); } else - mem_mapping_set_addr(&mystique->bios_rom.mapping, 0x000c0000, (mystique->type == MGA_G100) ? 0x10000 : 0x8000); - } + mem_mapping_disable(&mystique->bios_rom.mapping); + } else + mem_mapping_set_addr(&mystique->bios_rom.mapping, 0x000c0000, (mystique->type == MGA_G100) ? 0x10000 : 0x8000); break; case 0x4c: @@ -6580,17 +6583,17 @@ mystique_pci_write(UNUSED(int func), int addr, uint8_t val, void *priv) mystique_ctrl_write_b(addr, val, mystique); break; - case 0xf8: - mystique->pci_regs[0xf8] = val & 0x7; - break; + case 0xf8: + mystique->pci_regs[0xf8] = val & 0x7; + break; - case 0xf9: - mystique->pci_regs[0xf9] = val & 0x3; - break; + case 0xf9: + mystique->pci_regs[0xf9] = val & 0x3; + break; - case 0xfb: - mystique->pci_regs[0xfb] = val; - break; + case 0xfb: + mystique->pci_regs[0xfb] = val; + break; default: break; @@ -6677,6 +6680,7 @@ mystique_init(const device_t *info) mystique->svga.conv_16to32 = tvp3026_conv_16to32; if (mystique->type == MGA_2164W) mystique->svga.decode_mask = 0xffffff; + tvp3026_gpio(mystique_tvp3026_gpio_read, mystique_tvp3026_gpio_write, mystique, mystique->svga.ramdac); } else { video_inform(VIDEO_FLAG_TYPE_SPECIAL, &timing_matrox_mystique); @@ -6868,7 +6872,7 @@ static const device_config_t mystique_config[] = { }, .default_int = 8 }, - { .type = CONFIG_END } + { .name = "", .description = "", .type = CONFIG_END } // clang-format on }; @@ -6895,7 +6899,7 @@ static const device_config_t millennium_ii_config[] = { }, .default_int = 8 }, - { .type = CONFIG_END } + { .name = "", .description = "", .type = CONFIG_END } // clang-format on }; @@ -6907,7 +6911,7 @@ const device_t millennium_device = { .init = mystique_init, .close = mystique_close, .reset = NULL, - { .available = millennium_available }, + .available = millennium_available, .speed_changed = mystique_speed_changed, .force_redraw = mystique_force_redraw, .config = mystique_config @@ -6921,7 +6925,7 @@ const device_t mystique_device = { .init = mystique_init, .close = mystique_close, .reset = NULL, - { .available = mystique_available }, + .available = mystique_available, .speed_changed = mystique_speed_changed, .force_redraw = mystique_force_redraw, .config = mystique_config @@ -6935,7 +6939,7 @@ const device_t mystique_220_device = { .init = mystique_init, .close = mystique_close, .reset = NULL, - { .available = mystique_220_available }, + .available = mystique_220_available, .speed_changed = mystique_speed_changed, .force_redraw = mystique_force_redraw, .config = mystique_config @@ -6949,7 +6953,7 @@ const device_t millennium_ii_device = { .init = mystique_init, .close = mystique_close, .reset = NULL, - { .available = millennium_ii_available }, + .available = millennium_ii_available, .speed_changed = mystique_speed_changed, .force_redraw = mystique_force_redraw, .config = millennium_ii_config @@ -6964,7 +6968,7 @@ const device_t productiva_g100_device = { .init = mystique_init, .close = mystique_close, .reset = NULL, - { .available = matrox_g100_available }, + .available = matrox_g100_available, .speed_changed = mystique_speed_changed, .force_redraw = mystique_force_redraw, .config = millennium_ii_config diff --git a/src/video/vid_nga.c b/src/video/vid_nga.c index 32c103a8b..3cb7426b8 100644 --- a/src/video/vid_nga.c +++ b/src/video/vid_nga.c @@ -682,9 +682,7 @@ const device_config_t nga_config[] = { } } }, - { - .type = CONFIG_END - } + { .name = "", .description = "", .type = CONFIG_END } // clang-format on }; @@ -696,7 +694,7 @@ const device_t nga_device = { .init = nga_init, .close = nga_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = nga_speed_changed, .force_redraw = NULL, .config = nga_config diff --git a/src/video/vid_oak_oti.c b/src/video/vid_oak_oti.c index 715ba0df3..c7d42275d 100644 --- a/src/video/vid_oak_oti.c +++ b/src/video/vid_oak_oti.c @@ -589,9 +589,7 @@ static const device_config_t oti067_config[] = { } } }, - { - .type = CONFIG_END - } + { .name = "", .description = "", .type = CONFIG_END } }; static const device_config_t oti067_ama932j_config[] = { @@ -614,9 +612,7 @@ static const device_config_t oti067_ama932j_config[] = { } } }, - { - .type = CONFIG_END - } + { .name = "", .description = "", .type = CONFIG_END } }; static const device_config_t oti077_acer100t_config[] = { @@ -643,9 +639,7 @@ static const device_config_t oti077_acer100t_config[] = { } } }, - { - .type = CONFIG_END - } + { .name = "", .description = "", .type = CONFIG_END } }; static const device_config_t oti077_config[] = { @@ -672,9 +666,7 @@ static const device_config_t oti077_config[] = { } } }, - { - .type = CONFIG_END - } + { .name = "", .description = "", .type = CONFIG_END } }; // clang-format on @@ -686,7 +678,7 @@ const device_t oti037c_device = { .init = oti_init, .close = oti_close, .reset = NULL, - { .available = oti037c_available }, + .available = oti037c_available, .speed_changed = oti_speed_changed, .force_redraw = oti_force_redraw, .config = NULL @@ -700,7 +692,7 @@ const device_t oti067_device = { .init = oti_init, .close = oti_close, .reset = NULL, - { .available = oti067_077_available }, + .available = oti067_077_available, .speed_changed = oti_speed_changed, .force_redraw = oti_force_redraw, .config = oti067_config @@ -714,7 +706,7 @@ const device_t oti067_m300_device = { .init = oti_init, .close = oti_close, .reset = NULL, - { .available = oti067_m300_available }, + .available = oti067_m300_available, .speed_changed = oti_speed_changed, .force_redraw = oti_force_redraw, .config = oti067_config @@ -728,7 +720,7 @@ const device_t oti067_ama932j_device = { .init = oti_init, .close = oti_close, .reset = NULL, - { .available = oti067_ama932j_available }, + .available = oti067_ama932j_available, .speed_changed = oti_speed_changed, .force_redraw = oti_force_redraw, .config = oti067_ama932j_config @@ -742,7 +734,7 @@ const device_t oti077_acer100t_device = { .init = oti_init, .close = oti_close, .reset = NULL, - { .available = oti077_acer100t_available }, + .available = oti077_acer100t_available, .speed_changed = oti_speed_changed, .force_redraw = oti_force_redraw, .config = oti077_acer100t_config @@ -757,7 +749,7 @@ const device_t oti077_device = { .init = oti_init, .close = oti_close, .reset = NULL, - { .available = oti067_077_available }, + .available = oti067_077_available, .speed_changed = oti_speed_changed, .force_redraw = oti_force_redraw, .config = oti077_config diff --git a/src/video/vid_ogc.c b/src/video/vid_ogc.c index 9ac94169c..d430d2e14 100644 --- a/src/video/vid_ogc.c +++ b/src/video/vid_ogc.c @@ -666,9 +666,7 @@ const device_config_t ogc_m24_config[] = { .type = CONFIG_BINARY, .default_int = 1, }, - { - .type = CONFIG_END - } + { .name = "", .description = "", .type = CONFIG_END } // clang-format on }; @@ -680,7 +678,7 @@ const device_t ogc_m24_device = { .init = ogc_init, .close = ogc_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = ogc_speed_changed, .force_redraw = NULL, .config = ogc_m24_config @@ -694,7 +692,7 @@ const device_t ogc_device = { .init = ogc_init, .close = ogc_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = ogc_speed_changed, .force_redraw = NULL, .config = cga_config diff --git a/src/video/vid_paradise.c b/src/video/vid_paradise.c index 27e98d32d..8e3241efd 100644 --- a/src/video/vid_paradise.c +++ b/src/video/vid_paradise.c @@ -712,7 +712,7 @@ const device_t paradise_pvga1a_pc2086_device = { .init = paradise_pvga1a_pc2086_init, .close = paradise_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = paradise_speed_changed, .force_redraw = paradise_force_redraw, .config = NULL @@ -726,7 +726,7 @@ const device_t paradise_pvga1a_pc3086_device = { .init = paradise_pvga1a_pc3086_init, .close = paradise_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = paradise_speed_changed, .force_redraw = paradise_force_redraw, .config = NULL @@ -753,9 +753,7 @@ static const device_config_t paradise_pvga1a_config[] = { } } }, - { - .type = CONFIG_END - } + { .name = "", .description = "", .type = CONFIG_END } // clang-format on }; @@ -767,7 +765,7 @@ const device_t paradise_pvga1a_ncr3302_device = { .init = paradise_pvga1a_ncr3302_init, .close = paradise_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = paradise_speed_changed, .force_redraw = paradise_force_redraw, .config = paradise_pvga1a_config @@ -781,7 +779,7 @@ const device_t paradise_pvga1a_device = { .init = paradise_pvga1a_standalone_init, .close = paradise_close, .reset = NULL, - { .available = paradise_pvga1a_standalone_available }, + .available = paradise_pvga1a_standalone_available, .speed_changed = paradise_speed_changed, .force_redraw = paradise_force_redraw, .config = paradise_pvga1a_config @@ -795,7 +793,7 @@ const device_t paradise_wd90c11_megapc_device = { .init = paradise_wd90c11_megapc_init, .close = paradise_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = paradise_speed_changed, .force_redraw = paradise_force_redraw, .config = NULL @@ -809,7 +807,7 @@ const device_t paradise_wd90c11_device = { .init = paradise_wd90c11_standalone_init, .close = paradise_close, .reset = NULL, - { .available = paradise_wd90c11_standalone_available }, + .available = paradise_wd90c11_standalone_available, .speed_changed = paradise_speed_changed, .force_redraw = paradise_force_redraw, .config = NULL @@ -840,9 +838,7 @@ static const device_config_t paradise_wd90c30_config[] = { } } }, - { - .type = CONFIG_END - } + { .name = "", .description = "", .type = CONFIG_END } // clang-format on }; @@ -854,7 +850,7 @@ const device_t paradise_wd90c30_device = { .init = paradise_wd90c30_standalone_init, .close = paradise_close, .reset = NULL, - { .available = paradise_wd90c30_standalone_available }, + .available = paradise_wd90c30_standalone_available, .speed_changed = paradise_speed_changed, .force_redraw = paradise_force_redraw, .config = paradise_wd90c30_config diff --git a/src/video/vid_pgc.c b/src/video/vid_pgc.c index 354c7e265..5cb35dc4e 100644 --- a/src/video/vid_pgc.c +++ b/src/video/vid_pgc.c @@ -2743,7 +2743,7 @@ const device_t pgc_device = { .init = pgc_standalone_init, .close = pgc_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = pgc_speed_changed, .force_redraw = NULL, .config = NULL diff --git a/src/video/vid_rtg310x.c b/src/video/vid_rtg310x.c index e82763d15..b6e0085f8 100644 --- a/src/video/vid_rtg310x.c +++ b/src/video/vid_rtg310x.c @@ -405,9 +405,7 @@ static const device_config_t rtg3105_config[] = { } } }, - { - .type = CONFIG_END - } + { .name = "", .description = "", .type = CONFIG_END } // clang-format on }; @@ -436,9 +434,7 @@ static const device_config_t rtg3106_config[] = { } } }, - { - .type = CONFIG_END - } + { .name = "", .description = "", .type = CONFIG_END } // clang-format on }; @@ -450,7 +446,7 @@ const device_t realtek_rtg3105_device = { .init = rtg_init, .close = rtg_close, .reset = NULL, - { .available = rtg3105_available }, + .available = rtg3105_available, .speed_changed = rtg_speed_changed, .force_redraw = rtg_force_redraw, .config = rtg3105_config @@ -464,7 +460,7 @@ const device_t realtek_rtg3106_device = { .init = rtg_init, .close = rtg_close, .reset = NULL, - { .available = rtg3106_available }, + .available = rtg3106_available, .speed_changed = rtg_speed_changed, .force_redraw = rtg_force_redraw, .config = rtg3106_config diff --git a/src/video/vid_s3.c b/src/video/vid_s3.c index bb5c283ad..7e3b7a2ef 100644 --- a/src/video/vid_s3.c +++ b/src/video/vid_s3.c @@ -923,6 +923,9 @@ s3_accel_out_fifo(s3_t *s3, uint16_t port, uint8_t val) s3->accel.short_stroke = (s3->accel.short_stroke & 0xff) | (val << 8); s3->accel.ssv_state = 1; + s3->accel.cx = s3->accel.cur_x & 0xfff; + s3->accel.cy = s3->accel.cur_y & 0xfff; + if (s3->accel.cmd & 0x1000) { s3_short_stroke_start(s3, s3->accel.short_stroke & 0xff); s3_short_stroke_start(s3, s3->accel.short_stroke >> 8); @@ -1785,6 +1788,9 @@ s3_accel_out_fifo_w(s3_t *s3, uint16_t port, uint16_t val) s3->accel.short_stroke = val; s3->accel.ssv_state = 1; + s3->accel.cx = s3->accel.cur_x & 0xfff; + s3->accel.cy = s3->accel.cur_y & 0xfff; + if (s3->accel.cmd & 0x1000) { s3_short_stroke_start(s3, s3->accel.short_stroke & 0xff); s3_short_stroke_start(s3, s3->accel.short_stroke >> 8); @@ -7861,7 +7867,7 @@ s3_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat, voi uint32_t srcbase; uint32_t dstbase; - if ((s3->chip >= S3_TRIO64 || s3->chip == S3_VISION968 || s3->chip == S3_VISION868) && (s3->accel.cmd & (1 << 11))) + if (((s3->chip >= S3_TRIO64) || (s3->chip == S3_VISION968) || (s3->chip == S3_VISION868)) && (s3->accel.cmd & (1 << 11))) cmd |= 0x08; // SRC-BASE/DST-BASE @@ -7970,11 +7976,8 @@ s3_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat, voi switch (cmd) { case 0: /*NOP (Short Stroke Vectors)*/ - if (s3->accel.ssv_state == 0) { - s3->accel.cx = s3->accel.cur_x & 0xfff; - s3->accel.cy = s3->accel.cur_y & 0xfff; + if (s3->accel.ssv_state == 0) break; - } if (s3->accel.cmd & 0x08) { /*Radial*/ while (count-- && s3->accel.ssv_len >= 0) { @@ -10541,97 +10544,98 @@ s3_force_redraw(void *priv) } static const device_config_t s3_orchid_86c911_config[] = { - { .name = "memory", - .description = "Memory size", - .type = CONFIG_SELECTION, - .default_int = 1, - .selection = { - { .description = "512 KB", - .value = 0 }, - { .description = "1 MB", - .value = 1 }, - { .description = "" } } }, - { .type = CONFIG_END } + { + .name = "memory", + .description = "Memory size", + .type = CONFIG_SELECTION, + .default_int = 1, + .selection = { + { .description = "512 KB", .value = 0 }, + { .description = "1 MB", .value = 1 }, + { .description = "" } + } + }, + { .name = "", .description = "", .type = CONFIG_END } }; static const device_config_t s3_9fx_config[] = { - { .name = "memory", - .description = "Memory size", - .type = CONFIG_SELECTION, - .default_int = 2, - .selection = { - { .description = "1 MB", - .value = 1 }, - { .description = "2 MB", - .value = 2 }, - /*Trio64 also supports 4 MB, however the Number Nine BIOS does not*/ - { - .description = "" } } }, - { .type = CONFIG_END } + { + .name = "memory", + .description = "Memory size", + .type = CONFIG_SELECTION, + .default_int = 2, + .selection = { + { .description = "1 MB", .value = 1 }, + { .description = "2 MB", .value = 2 }, + /* Trio64 also supports 4 MB, however the Number Nine BIOS does not */ + { .description = "" } + } + }, + { .name = "", .description = "", .type = CONFIG_END } }; static const device_config_t s3_phoenix_trio32_config[] = { - { .name = "memory", - .description = "Memory size", - .type = CONFIG_SELECTION, - .default_int = 2, - .selection = { - { .description = "512 KB", - .value = 0 }, - { .description = "1 MB", - .value = 1 }, - { .description = "2 MB", - .value = 2 }, - { .description = "" } } }, - { .type = CONFIG_END } + { + .name = "memory", + .description = "Memory size", + .type = CONFIG_SELECTION, + .default_int = 2, + .selection = { + { .description = "512 KB", .value = 0 }, + { .description = "1 MB", .value = 1 }, + { .description = "2 MB", .value = 2 }, + { .description = "" } + } + }, + { .name = "", .description = "", .type = CONFIG_END } }; static const device_config_t s3_standard_config[] = { - { .name = "memory", - .description = "Memory size", - .type = CONFIG_SELECTION, - .default_int = 4, - .selection = { - { .description = "1 MB", - .value = 1 }, - { .description = "2 MB", - .value = 2 }, - { .description = "4 MB", - .value = 4 }, - { .description = "" } } }, - { .type = CONFIG_END } + { + .name = "memory", + .description = "Memory size", + .type = CONFIG_SELECTION, + .default_int = 4, + .selection = { + { .description = "1 MB", .value = 1 }, + { .description = "2 MB", .value = 2 }, + { .description = "4 MB", .value = 4 }, + { .description = "" } + } + }, + { .name = "", .description = "", .type = CONFIG_END } }; static const device_config_t s3_968_config[] = { - { .name = "memory", - .description = "Memory size", - .type = CONFIG_SELECTION, - .default_int = 4, - .selection = { - { .description = "1 MB", - .value = 1 }, - { .description = "2 MB", - .value = 2 }, - { .description = "4 MB", - .value = 4 }, - { .description = "8 MB", - .value = 8 }, - { .description = "" } } }, - { .type = CONFIG_END } + { + .name = "memory", + .description = "Memory size", + .type = CONFIG_SELECTION, + .default_int = 4, + .selection = { + { .description = "1 MB", .value = 1 }, + { .description = "2 MB", .value = 2 }, + { .description = "4 MB", .value = 4 }, + { .description = "8 MB", .value = 8 }, + { .description = "" } + } + }, + { .name = "", .description = "", .type = CONFIG_END } }; static const device_config_t s3_standard_config2[] = { - { .name = "memory", - .description = "Memory size", - .type = CONFIG_SELECTION, - .default_int = 4, - .selection = { - { .description = "2 MB", - .value = 2 }, - { .description = "4 MB", - .value = 4 }, - { .description = "" } } }, - { .type = CONFIG_END } + { + .name = "memory", + .description = "Memory size", + .type = CONFIG_SELECTION, + .default_int = 4, + .selection = { + { .description = "2 MB", .value = 2 }, + { .description = "4 MB", .value = 4 }, + { .description = "" } + } + }, + { .name = "", .description = "", .type = CONFIG_END } }; const device_t s3_orchid_86c911_isa_device = { @@ -10642,7 +10646,7 @@ const device_t s3_orchid_86c911_isa_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = s3_orchid_86c911_available }, + .available = s3_orchid_86c911_available, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_orchid_86c911_config @@ -10656,7 +10660,7 @@ const device_t s3_diamond_stealth_vram_isa_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = s3_diamond_stealth_vram_available }, + .available = s3_diamond_stealth_vram_available, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_orchid_86c911_config @@ -10670,7 +10674,7 @@ const device_t s3_ami_86c924_isa_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = s3_ami_86c924_available }, + .available = s3_ami_86c924_available, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_orchid_86c911_config @@ -10684,7 +10688,7 @@ const device_t s3_spea_mirage_86c801_isa_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = s3_spea_mirage_86c801_available }, + .available = s3_spea_mirage_86c801_available, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_9fx_config @@ -10698,7 +10702,7 @@ const device_t s3_86c805_onboard_vlb_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = NULL }, + .available = NULL, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_9fx_config @@ -10712,7 +10716,7 @@ const device_t s3_spea_mirage_86c805_vlb_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = s3_spea_mirage_86c805_available }, + .available = s3_spea_mirage_86c805_available, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_9fx_config @@ -10726,7 +10730,7 @@ const device_t s3_mirocrystal_8s_805_vlb_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = s3_mirocrystal_8s_805_available }, + .available = s3_mirocrystal_8s_805_available, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_9fx_config @@ -10740,7 +10744,7 @@ const device_t s3_mirocrystal_10sd_805_vlb_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = s3_mirocrystal_10sd_805_available }, + .available = s3_mirocrystal_10sd_805_available, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_9fx_config @@ -10754,7 +10758,7 @@ const device_t s3_phoenix_86c801_isa_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = s3_phoenix_86c80x_available }, + .available = s3_phoenix_86c80x_available, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_9fx_config @@ -10768,7 +10772,7 @@ const device_t s3_phoenix_86c805_vlb_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = s3_phoenix_86c80x_available }, + .available = s3_phoenix_86c80x_available, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_9fx_config @@ -10782,7 +10786,7 @@ const device_t s3_metheus_86c928_isa_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = s3_metheus_86c928_available }, + .available = s3_metheus_86c928_available, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_standard_config @@ -10796,7 +10800,7 @@ const device_t s3_metheus_86c928_vlb_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = s3_metheus_86c928_available }, + .available = s3_metheus_86c928_available, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_standard_config @@ -10810,7 +10814,7 @@ const device_t s3_spea_mercury_lite_86c928_pci_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = s3_spea_mercury_lite_pci_available }, + .available = s3_spea_mercury_lite_pci_available, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_orchid_86c911_config @@ -10824,7 +10828,7 @@ const device_t s3_mirocrystal_20sd_864_vlb_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = s3_mirocrystal_20sd_864_vlb_available }, + .available = s3_mirocrystal_20sd_864_vlb_available, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_9fx_config @@ -10838,7 +10842,7 @@ const device_t s3_bahamas64_vlb_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = s3_bahamas64_available }, + .available = s3_bahamas64_available, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_9fx_config @@ -10852,7 +10856,7 @@ const device_t s3_bahamas64_pci_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = s3_bahamas64_available }, + .available = s3_bahamas64_available, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_9fx_config @@ -10866,7 +10870,7 @@ const device_t s3_mirocrystal_20sv_964_vlb_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = s3_mirocrystal_20sv_964_vlb_available }, + .available = s3_mirocrystal_20sv_964_vlb_available, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_9fx_config @@ -10880,7 +10884,7 @@ const device_t s3_mirocrystal_20sv_964_pci_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = s3_mirocrystal_20sv_964_pci_available }, + .available = s3_mirocrystal_20sv_964_pci_available, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_9fx_config @@ -10894,7 +10898,7 @@ const device_t s3_diamond_stealth64_964_vlb_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = s3_diamond_stealth64_964_available }, + .available = s3_diamond_stealth64_964_available, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_standard_config @@ -10908,7 +10912,7 @@ const device_t s3_diamond_stealth64_964_pci_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = s3_diamond_stealth64_964_available }, + .available = s3_diamond_stealth64_964_available, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_standard_config @@ -10922,7 +10926,7 @@ const device_t s3_diamond_stealth64_968_vlb_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = s3_diamond_stealth64_968_available }, + .available = s3_diamond_stealth64_968_available, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_standard_config2 @@ -10936,7 +10940,7 @@ const device_t s3_diamond_stealth64_968_pci_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = s3_diamond_stealth64_968_available }, + .available = s3_diamond_stealth64_968_available, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_standard_config2 @@ -10950,7 +10954,7 @@ const device_t s3_9fx_771_pci_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = s3_9fx_771_available }, + .available = s3_9fx_771_available, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_968_config @@ -10964,7 +10968,7 @@ const device_t s3_phoenix_vision968_pci_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = s3_phoenix_vision968_available }, + .available = s3_phoenix_vision968_available, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_standard_config @@ -10978,7 +10982,7 @@ const device_t s3_mirovideo_40sv_ergo_968_pci_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = s3_mirovideo_40sv_ergo_968_pci_available }, + .available = s3_mirovideo_40sv_ergo_968_pci_available, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_standard_config @@ -10992,7 +10996,7 @@ const device_t s3_spea_mercury_p64v_pci_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = s3_spea_mercury_p64v_pci_available }, + .available = s3_spea_mercury_p64v_pci_available, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_standard_config @@ -11006,7 +11010,7 @@ const device_t s3_9fx_vlb_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = s3_9fx_available }, + .available = s3_9fx_available, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_9fx_config @@ -11020,7 +11024,7 @@ const device_t s3_9fx_pci_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = s3_9fx_available }, + .available = s3_9fx_available, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_9fx_config @@ -11034,7 +11038,7 @@ const device_t s3_phoenix_trio32_onboard_vlb_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = NULL }, + .available = NULL, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_phoenix_trio32_config @@ -11048,7 +11052,7 @@ const device_t s3_phoenix_trio32_vlb_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = s3_phoenix_trio32_available }, + .available = s3_phoenix_trio32_available, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_phoenix_trio32_config @@ -11062,7 +11066,7 @@ const device_t s3_phoenix_trio32_onboard_pci_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = NULL }, + .available = NULL, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_phoenix_trio32_config @@ -11076,7 +11080,7 @@ const device_t s3_phoenix_trio32_pci_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = s3_phoenix_trio32_available }, + .available = s3_phoenix_trio32_available, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_phoenix_trio32_config @@ -11090,7 +11094,7 @@ const device_t s3_diamond_stealth_se_vlb_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = s3_diamond_stealth_se_available }, + .available = s3_diamond_stealth_se_available, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_phoenix_trio32_config @@ -11104,7 +11108,7 @@ const device_t s3_diamond_stealth_se_pci_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = s3_diamond_stealth_se_available }, + .available = s3_diamond_stealth_se_available, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_phoenix_trio32_config @@ -11118,7 +11122,7 @@ const device_t s3_phoenix_trio64_vlb_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = s3_phoenix_trio64_available }, + .available = s3_phoenix_trio64_available, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_standard_config @@ -11132,7 +11136,7 @@ const device_t s3_phoenix_trio64_onboard_pci_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = NULL }, + .available = NULL, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_standard_config @@ -11146,7 +11150,7 @@ const device_t s3_phoenix_trio64_pci_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = s3_phoenix_trio64_available }, + .available = s3_phoenix_trio64_available, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_standard_config @@ -11160,7 +11164,7 @@ const device_t s3_stb_powergraph_64_video_vlb_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = s3_stb_powergraph_64_video_available }, + .available = s3_stb_powergraph_64_video_available, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_phoenix_trio32_config @@ -11174,7 +11178,7 @@ const device_t s3_phoenix_trio64vplus_onboard_pci_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = NULL }, + .available = NULL, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_standard_config @@ -11188,7 +11192,7 @@ const device_t s3_phoenix_trio64vplus_pci_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = s3_phoenix_trio64vplus_available }, + .available = s3_phoenix_trio64vplus_available, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_standard_config @@ -11202,7 +11206,7 @@ const device_t s3_cardex_trio64vplus_pci_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = s3_cardex_trio64vplus_available }, + .available = s3_cardex_trio64vplus_available, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_standard_config @@ -11216,7 +11220,7 @@ const device_t s3_phoenix_vision864_vlb_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = s3_phoenix_vision864_available }, + .available = s3_phoenix_vision864_available, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_standard_config @@ -11230,7 +11234,7 @@ const device_t s3_phoenix_vision864_pci_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = s3_phoenix_vision864_available }, + .available = s3_phoenix_vision864_available, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_standard_config @@ -11244,7 +11248,7 @@ const device_t s3_9fx_531_pci_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = s3_9fx_531_available }, + .available = s3_9fx_531_available, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_9fx_config @@ -11258,7 +11262,7 @@ const device_t s3_phoenix_vision868_pci_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = s3_phoenix_vision868_available }, + .available = s3_phoenix_vision868_available, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_standard_config @@ -11272,7 +11276,7 @@ const device_t s3_diamond_stealth64_vlb_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = s3_diamond_stealth64_764_available }, + .available = s3_diamond_stealth64_764_available, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_9fx_config @@ -11286,7 +11290,7 @@ const device_t s3_diamond_stealth64_pci_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = s3_diamond_stealth64_764_available }, + .available = s3_diamond_stealth64_764_available, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_9fx_config @@ -11300,7 +11304,7 @@ const device_t s3_spea_mirage_p64_vlb_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = s3_spea_mirage_p64_vlb_available }, + .available = s3_spea_mirage_p64_vlb_available, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_9fx_config @@ -11314,7 +11318,7 @@ const device_t s3_elsa_winner2000_pro_x_964_pci_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = s3_elsa_winner2000_pro_x_964_available }, + .available = s3_elsa_winner2000_pro_x_964_available, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_968_config @@ -11328,7 +11332,7 @@ const device_t s3_elsa_winner2000_pro_x_pci_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = s3_elsa_winner2000_pro_x_available }, + .available = s3_elsa_winner2000_pro_x_available, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_968_config @@ -11342,7 +11346,7 @@ const device_t s3_trio64v2_dx_pci_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = s3_trio64v2_dx_available }, + .available = s3_trio64v2_dx_available, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_standard_config @@ -11356,7 +11360,7 @@ const device_t s3_trio64v2_dx_onboard_pci_device = { .init = s3_init, .close = s3_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_standard_config diff --git a/src/video/vid_s3_virge.c b/src/video/vid_s3_virge.c index 08a01dbd6..3c61f3a57 100644 --- a/src/video/vid_s3_virge.c +++ b/src/video/vid_s3_virge.c @@ -4734,9 +4734,7 @@ static const device_config_t s3_virge_config[] = { .type = CONFIG_BINARY, .default_int = 1 }, - { - .type = CONFIG_END - } + { .name = "", .description = "", .type = CONFIG_END } // clang-format on }; @@ -4777,9 +4775,7 @@ static const device_config_t s3_virge_stb_config[] = { .type = CONFIG_BINARY, .default_int = 1 }, - { - .type = CONFIG_END - } + { .name = "", .description = "", .type = CONFIG_END } // clang-format on }; @@ -4797,9 +4793,7 @@ static const device_config_t s3_virge_357_config[] = { .type = CONFIG_BINARY, .default_int = 1 }, - { - .type = CONFIG_END - } + { .name = "", .description = "", .type = CONFIG_END } // clang-format on }; @@ -4836,9 +4830,7 @@ static const device_config_t s3_trio3d2x_config[] = { .type = CONFIG_BINARY, .default_int = 1 }, - { - .type = CONFIG_END - } + { .name = "", .description = "", .type = CONFIG_END } // clang-format on }; @@ -4850,7 +4842,7 @@ const device_t s3_virge_325_pci_device = { .init = s3_virge_init, .close = s3_virge_close, .reset = s3_virge_reset, - { .available = s3_virge_325_available }, + .available = s3_virge_325_available, .speed_changed = s3_virge_speed_changed, .force_redraw = s3_virge_force_redraw, .config = s3_virge_config @@ -4864,7 +4856,7 @@ const device_t s3_virge_325_onboard_pci_device = { .init = s3_virge_init, .close = s3_virge_close, .reset = s3_virge_reset, - { .available = NULL }, + .available = NULL, .speed_changed = s3_virge_speed_changed, .force_redraw = s3_virge_force_redraw, .config = s3_virge_config @@ -4878,7 +4870,7 @@ const device_t s3_diamond_stealth_2000_pci_device = { .init = s3_virge_init, .close = s3_virge_close, .reset = s3_virge_reset, - { .available = s3_virge_325_diamond_available }, + .available = s3_virge_325_diamond_available, .speed_changed = s3_virge_speed_changed, .force_redraw = s3_virge_force_redraw, .config = s3_virge_config @@ -4892,7 +4884,7 @@ const device_t s3_mirocrystal_3d_pci_device = { .init = s3_virge_init, .close = s3_virge_close, .reset = s3_virge_reset, - { .available = s3_mirocrystal_3d_available }, + .available = s3_mirocrystal_3d_available, .speed_changed = s3_virge_speed_changed, .force_redraw = s3_virge_force_redraw, .config = s3_virge_config @@ -4906,7 +4898,7 @@ const device_t s3_diamond_stealth_3000_pci_device = { .init = s3_virge_init, .close = s3_virge_close, .reset = s3_virge_reset, - { .available = s3_virge_988_diamond_available }, + .available = s3_virge_988_diamond_available, .speed_changed = s3_virge_speed_changed, .force_redraw = s3_virge_force_redraw, .config = s3_virge_stb_config @@ -4920,7 +4912,7 @@ const device_t s3_stb_velocity_3d_pci_device = { .init = s3_virge_init, .close = s3_virge_close, .reset = s3_virge_reset, - { .available = s3_virge_988_stb_available }, + .available = s3_virge_988_stb_available, .speed_changed = s3_virge_speed_changed, .force_redraw = s3_virge_force_redraw, .config = s3_virge_stb_config @@ -4934,7 +4926,7 @@ const device_t s3_virge_375_pci_device = { .init = s3_virge_init, .close = s3_virge_close, .reset = s3_virge_reset, - { .available = s3_virge_375_available }, + .available = s3_virge_375_available, .speed_changed = s3_virge_speed_changed, .force_redraw = s3_virge_force_redraw, .config = s3_virge_config @@ -4948,7 +4940,7 @@ const device_t s3_virge_375_onboard_pci_device = { .init = s3_virge_init, .close = s3_virge_close, .reset = s3_virge_reset, - { .available = NULL }, + .available = NULL, .speed_changed = s3_virge_speed_changed, .force_redraw = s3_virge_force_redraw, .config = s3_virge_config @@ -4962,7 +4954,7 @@ const device_t s3_diamond_stealth_2000pro_pci_device = { .init = s3_virge_init, .close = s3_virge_close, .reset = s3_virge_reset, - { .available = s3_virge_375_diamond_available }, + .available = s3_virge_375_diamond_available, .speed_changed = s3_virge_speed_changed, .force_redraw = s3_virge_force_redraw, .config = s3_virge_config @@ -4976,7 +4968,7 @@ const device_t s3_virge_385_pci_device = { .init = s3_virge_init, .close = s3_virge_close, .reset = s3_virge_reset, - { .available = s3_virge_385_available }, + .available = s3_virge_385_available, .speed_changed = s3_virge_speed_changed, .force_redraw = s3_virge_force_redraw, .config = s3_virge_config @@ -4990,7 +4982,7 @@ const device_t s3_virge_357_pci_device = { .init = s3_virge_init, .close = s3_virge_close, .reset = s3_virge_reset, - { .available = s3_virge_357_available }, + .available = s3_virge_357_available, .speed_changed = s3_virge_speed_changed, .force_redraw = s3_virge_force_redraw, .config = s3_virge_357_config @@ -5004,7 +4996,7 @@ const device_t s3_virge_357_agp_device = { .init = s3_virge_init, .close = s3_virge_close, .reset = s3_virge_reset, - { .available = s3_virge_357_available }, + .available = s3_virge_357_available, .speed_changed = s3_virge_speed_changed, .force_redraw = s3_virge_force_redraw, .config = s3_virge_357_config @@ -5018,7 +5010,7 @@ const device_t s3_diamond_stealth_4000_pci_device = { .init = s3_virge_init, .close = s3_virge_close, .reset = s3_virge_reset, - { .available = s3_virge_357_diamond_available }, + .available = s3_virge_357_diamond_available, .speed_changed = s3_virge_speed_changed, .force_redraw = s3_virge_force_redraw, .config = s3_virge_357_config @@ -5032,7 +5024,7 @@ const device_t s3_diamond_stealth_4000_agp_device = { .init = s3_virge_init, .close = s3_virge_close, .reset = s3_virge_reset, - { .available = s3_virge_357_diamond_available }, + .available = s3_virge_357_diamond_available, .speed_changed = s3_virge_speed_changed, .force_redraw = s3_virge_force_redraw, .config = s3_virge_357_config @@ -5046,7 +5038,7 @@ const device_t s3_trio3d2x_pci_device = { .init = s3_virge_init, .close = s3_virge_close, .reset = s3_virge_reset, - { .available = s3_trio3d2x_available }, + .available = s3_trio3d2x_available, .speed_changed = s3_virge_speed_changed, .force_redraw = s3_virge_force_redraw, .config = s3_trio3d2x_config @@ -5060,7 +5052,7 @@ const device_t s3_trio3d2x_agp_device = { .init = s3_virge_init, .close = s3_virge_close, .reset = s3_virge_reset, - { .available = s3_trio3d2x_available }, + .available = s3_trio3d2x_available, .speed_changed = s3_virge_speed_changed, .force_redraw = s3_virge_force_redraw, .config = s3_trio3d2x_config diff --git a/src/video/vid_sc1148x_ramdac.c b/src/video/vid_sc1148x_ramdac.c index 24ca4aeec..0ebcb49b6 100644 --- a/src/video/vid_sc1148x_ramdac.c +++ b/src/video/vid_sc1148x_ramdac.c @@ -156,7 +156,7 @@ const device_t sc11483_ramdac_device = { .init = sc1148x_ramdac_init, .close = sc1148x_ramdac_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -170,7 +170,7 @@ const device_t sc11487_ramdac_device = { .init = sc1148x_ramdac_init, .close = sc1148x_ramdac_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -184,7 +184,7 @@ const device_t sc11484_nors2_ramdac_device = { .init = sc1148x_ramdac_init, .close = sc1148x_ramdac_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -198,7 +198,7 @@ const device_t sc11486_ramdac_device = { .init = sc1148x_ramdac_init, .close = sc1148x_ramdac_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/video/vid_sc1502x_ramdac.c b/src/video/vid_sc1502x_ramdac.c index 7315c65ad..1c7d4014d 100644 --- a/src/video/vid_sc1502x_ramdac.c +++ b/src/video/vid_sc1502x_ramdac.c @@ -249,7 +249,7 @@ const device_t sc1502x_ramdac_device = { .init = sc1502x_ramdac_init, .close = sc1502x_ramdac_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/video/vid_sdac_ramdac.c b/src/video/vid_sdac_ramdac.c index 83796506e..4e6deacdc 100644 --- a/src/video/vid_sdac_ramdac.c +++ b/src/video/vid_sdac_ramdac.c @@ -313,7 +313,7 @@ const device_t gendac_ramdac_device = { .init = sdac_ramdac_init, .close = sdac_ramdac_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -327,7 +327,7 @@ const device_t tseng_ics5301_ramdac_device = { .init = sdac_ramdac_init, .close = sdac_ramdac_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -341,7 +341,7 @@ const device_t tseng_ics5341_ramdac_device = { .init = sdac_ramdac_init, .close = sdac_ramdac_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -355,7 +355,7 @@ const device_t sdac_ramdac_device = { .init = sdac_ramdac_init, .close = sdac_ramdac_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/video/vid_sigma.c b/src/video/vid_sigma.c index 56f8b99aa..161331918 100644 --- a/src/video/vid_sigma.c +++ b/src/video/vid_sigma.c @@ -951,9 +951,7 @@ device_config_t sigma_config[] = { } }, }, - { - .type = CONFIG_END - } + { .name = "", .description = "", .type = CONFIG_END } // clang-format on }; @@ -965,7 +963,7 @@ const device_t sigma_device = { .init = sigma_init, .close = sigma_close, .reset = NULL, - { .available = sigma_available }, + .available = sigma_available, .speed_changed = sigma_speed_changed, .force_redraw = NULL, .config = sigma_config diff --git a/src/video/vid_stg_ramdac.c b/src/video/vid_stg_ramdac.c index 187139b3b..85d492ce7 100644 --- a/src/video/vid_stg_ramdac.c +++ b/src/video/vid_stg_ramdac.c @@ -263,7 +263,7 @@ const device_t stg_ramdac_device = { .init = stg_ramdac_init, .close = stg_ramdac_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/video/vid_svga.c b/src/video/vid_svga.c index e6201e4bf..e68e4c1a0 100644 --- a/src/video/vid_svga.c +++ b/src/video/vid_svga.c @@ -83,26 +83,76 @@ svga_get_pri(void) return svga_pri; } +void +svga_set_poll(svga_t *svga) +{ + svga_log("SVGA Timer activated, enabled?=%x.\n", timer_is_enabled(&svga->timer)); + timer_set_callback(&svga->timer, svga_poll); + if (!timer_is_enabled(&svga->timer)) + timer_enable(&svga->timer); +} + void svga_set_override(svga_t *svga, int val) { ibm8514_t *dev = (ibm8514_t *) svga->dev8514; + xga_t *xga = (xga_t *) svga->xga; + uint8_t ret_poll = 0; if (svga->override && !val) svga->fullchange = svga->monitor->mon_changeframecount; + svga->override = val; svga_log("Override=%x.\n", val); - if (ibm8514_active && (svga->dev8514 != NULL)) { - if (dev->on) { - if (svga->override) - timer_set_callback(&svga->timer, svga_poll); - else - timer_set_callback(&svga->timer, ibm8514_poll); - } else - timer_set_callback(&svga->timer, svga_poll); - } else - timer_set_callback(&svga->timer, svga_poll); + if (ibm8514_active && (svga->dev8514 != NULL)) + ret_poll |= 1; + + if (xga_active && (svga->xga != NULL)) + ret_poll |= 2; + + if (svga->override) + svga_set_poll(svga); + else { + switch (ret_poll) { + case 0: + default: + svga_set_poll(svga); + break; + + case 1: + if (ibm8514_active && (svga->dev8514 != NULL)) { + if (dev->on) + ibm8514_set_poll(svga); + else + svga_set_poll(svga); + } else + svga_set_poll(svga); + break; + + case 2: + if (xga_active && (svga->xga != NULL)) { + if (xga->on) + xga_set_poll(svga); + else + svga_set_poll(svga); + } else + svga_set_poll(svga); + break; + + case 3: + if (ibm8514_active && (svga->dev8514 != NULL) && xga_active && (svga->xga != NULL)) { + if (dev->on) + ibm8514_set_poll(svga); + else if (xga->on) + xga_set_poll(svga); + else + svga_set_poll(svga); + } else + svga_set_poll(svga); + break; + } + } #ifdef OVERRIDE_OVERSCAN if (!val) { @@ -241,7 +291,7 @@ svga_out(uint16_t addr, uint8_t val, void *priv) if (ibm8514_active && dev) dev->on = (val & 0x01) ? 0 : 1; - svga_log("Write Port 3C3.\n"); + svga_log("Write Port 3C3=%x.\n", val & 0x01); svga_recalctimings(svga); break; case 0x3c4: @@ -612,6 +662,8 @@ void svga_recalctimings(svga_t *svga) { ibm8514_t *dev = (ibm8514_t *) svga->dev8514; + xga_t *xga = (xga_t *) svga->xga; + uint8_t set_timer = 0; double crtcconst; double _dispontime; double _dispofftime; @@ -620,6 +672,10 @@ svga_recalctimings(svga_t *svga) double _dispontime8514 = 0.0; double _dispofftime8514 = 0.0; double disptime8514 = 0.0; + double crtcconst_xga = 0.0; + double _dispontime_xga = 0.0; + double _dispofftime_xga = 0.0; + double disptime_xga = 0.0; #ifdef ENABLE_SVGA_LOG int vsyncend; int vblankend; @@ -709,6 +765,12 @@ svga_recalctimings(svga_t *svga) } else svga->render = svga_render_text_80; + if (xga_active && (svga->xga != NULL)) { + if (xga->on) { + if ((svga->mapping.base == 0xb8000) && (xga->aperture_cntl == 1)) /*Some operating systems reset themselves with ctrl-alt-del by going into text mode.*/ + xga->on = 0; + } + } svga->hdisp_old = svga->hdisp; } else { svga->hdisp_old = svga->hdisp; @@ -904,6 +966,10 @@ svga_recalctimings(svga_t *svga) if (dev->on) crtcconst8514 = svga->clock8514; } + if (xga_active && (svga->xga != NULL)) { + if (xga->on) + crtcconst_xga = svga->clock_xga; + } #ifdef ENABLE_SVGA_LOG vsyncend = (svga->vsyncstart & 0xfffffff0) | (svga->crtc[0x11] & 0x0f); @@ -952,6 +1018,13 @@ svga_recalctimings(svga_t *svga) } } + if (xga_active && (svga->xga != NULL)) { + if (xga->on) { + disptime_xga = xga->h_total ? xga->h_total : TIMER_USEC; + _dispontime_xga = xga->h_disp; + } + } + if (svga->seqregs[1] & 8) { disptime *= 2; _dispontime *= 2; @@ -968,25 +1041,84 @@ svga_recalctimings(svga_t *svga) if (svga->dispofftime < TIMER_USEC) svga->dispofftime = TIMER_USEC; - if (ibm8514_active && (svga->dev8514 != NULL)) { - if (dev->on) { - _dispofftime8514 = disptime8514 - _dispontime8514; - _dispontime8514 *= crtcconst8514; - _dispofftime8514 *= crtcconst8514; + if (ibm8514_active && (svga->dev8514 != NULL)) + set_timer |= 1; - dev->dispontime = (uint64_t) (_dispontime8514); - dev->dispofftime = (uint64_t) (_dispofftime8514); - if (dev->dispontime < TIMER_USEC) - dev->dispontime = TIMER_USEC; - if (dev->dispofftime < TIMER_USEC) - dev->dispofftime = TIMER_USEC; + if (xga_active && (svga->xga != NULL)) + set_timer |= 2; - svga_log("IBM 8514/A poll.\n"); - timer_set_callback(&svga->timer, ibm8514_poll); - } else { - svga_log("SVGA poll enabled.\n"); - timer_set_callback(&svga->timer, svga_poll); - } + switch (set_timer) { + default: + case 0: /*VGA only*/ + svga_set_poll(svga); + break; + + case 1: /*Plus 8514/A*/ + if (dev->on) { + _dispofftime8514 = disptime8514 - _dispontime8514; + _dispontime8514 *= crtcconst8514; + _dispofftime8514 *= crtcconst8514; + + dev->dispontime = (uint64_t) (_dispontime8514); + dev->dispofftime = (uint64_t) (_dispofftime8514); + if (dev->dispontime < TIMER_USEC) + dev->dispontime = TIMER_USEC; + if (dev->dispofftime < TIMER_USEC) + dev->dispofftime = TIMER_USEC; + + ibm8514_set_poll(svga); + } else + svga_set_poll(svga); + break; + + case 2: /*Plus XGA*/ + if (xga->on) { + _dispofftime_xga = disptime_xga - _dispontime_xga; + _dispontime_xga *= crtcconst_xga; + _dispofftime_xga *= crtcconst_xga; + + xga->dispontime = (uint64_t) (_dispontime_xga); + xga->dispofftime = (uint64_t) (_dispofftime_xga); + if (xga->dispontime < TIMER_USEC) + xga->dispontime = TIMER_USEC; + if (xga->dispofftime < TIMER_USEC) + xga->dispofftime = TIMER_USEC; + + xga_set_poll(svga); + } else + svga_set_poll(svga); + break; + + case 3: /*Plus 8514/A and XGA*/ + if (dev->on) { + _dispofftime8514 = disptime8514 - _dispontime8514; + _dispontime8514 *= crtcconst8514; + _dispofftime8514 *= crtcconst8514; + + dev->dispontime = (uint64_t) (_dispontime8514); + dev->dispofftime = (uint64_t) (_dispofftime8514); + if (dev->dispontime < TIMER_USEC) + dev->dispontime = TIMER_USEC; + if (dev->dispofftime < TIMER_USEC) + dev->dispofftime = TIMER_USEC; + + ibm8514_set_poll(svga); + } else if (xga->on) { + _dispofftime_xga = disptime_xga - _dispontime_xga; + _dispontime_xga *= crtcconst_xga; + _dispofftime_xga *= crtcconst_xga; + + xga->dispontime = (uint64_t) (_dispontime_xga); + xga->dispofftime = (uint64_t) (_dispofftime_xga); + if (xga->dispontime < TIMER_USEC) + xga->dispontime = TIMER_USEC; + if (xga->dispofftime < TIMER_USEC) + xga->dispofftime = TIMER_USEC; + + xga_set_poll(svga); + } else + svga_set_poll(svga); + break; } if (!svga->force_old_addr) @@ -1064,7 +1196,6 @@ void svga_poll(void *priv) { svga_t *svga = (svga_t *) priv; - xga_t *xga = (xga_t *) svga->xga; uint32_t x; uint32_t blink_delay; int wx; @@ -1072,15 +1203,6 @@ svga_poll(void *priv) int ret; int old_ma; - if (!svga->override) { - if (xga_active && xga && xga->on) { - if ((xga->disp_cntl_2 & 7) >= 2) { - xga_poll(svga); - return; - } - } - } - svga_log("SVGA Poll.\n"); if (!svga->linepos) { if (svga->displine == ((svga->hwcursor_latch.y < 0) ? 0 : svga->hwcursor_latch.y) && svga->hwcursor_latch.ena) { @@ -1345,7 +1467,7 @@ svga_poll(void *priv) } uint32_t -svga_conv_16to32(struct svga_t *svga, uint16_t color, uint8_t bpp) +svga_conv_16to32(UNUSED(struct svga_t *svga), uint16_t color, uint8_t bpp) { return (bpp == 15) ? video_15to32[color] : video_16to32[color]; } @@ -2070,6 +2192,8 @@ svga_readw_common(uint32_t addr, uint8_t linear, void *priv) cycles -= svga->monitor->mon_video_timing_read_w; if (!linear) { + (void) xga_read_test(addr, svga); + (void) xga_read_test(addr + 1, svga); addr = svga_decode_addr(svga, addr, 0); if (addr == 0xffffffff) return 0xffff; @@ -2116,6 +2240,10 @@ svga_readl_common(uint32_t addr, uint8_t linear, void *priv) cycles -= svga->monitor->mon_video_timing_read_l; if (!linear) { + (void) xga_read_test(addr, svga); + (void) xga_read_test(addr + 1, svga); + (void) xga_read_test(addr + 2, svga); + (void) xga_read_test(addr + 3, svga); addr = svga_decode_addr(svga, addr, 0); if (addr == 0xffffffff) return 0xffffffff; diff --git a/src/video/vid_table.c b/src/video/vid_table.c index 859712357..9ff092161 100644 --- a/src/video/vid_table.c +++ b/src/video/vid_table.c @@ -50,206 +50,206 @@ static int was_reset = 0; static const VIDEO_CARD video_cards[] = { // clang-format off - { &device_none }, - { &device_internal }, - { &atiega800p_device }, - { &mach8_vga_isa_device, VIDEO_FLAG_TYPE_8514 }, - { &mach32_isa_device, VIDEO_FLAG_TYPE_8514 }, - { &mach64gx_isa_device }, - { &ati28800k_device }, - { &ati18800_vga88_device }, - { &ati28800_device }, - { &compaq_ati28800_device }, - { &ati28800_wonder1024d_xl_plus_device }, + { .device = &device_none, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &device_internal, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &atiega800p_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &mach8_vga_isa_device, .flags = VIDEO_FLAG_TYPE_8514 }, + { .device = &mach32_isa_device, .flags = VIDEO_FLAG_TYPE_8514 }, + { .device = &mach64gx_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &ati28800k_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &ati18800_vga88_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &ati28800_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &compaq_ati28800_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &ati28800_wonder1024d_xl_plus_device, .flags = VIDEO_FLAG_TYPE_NONE }, #ifdef USE_XL24 - { &ati28800_wonderxl24_device }, + { .device = &ati28800_wonderxl24_device, .flags = VIDEO_FLAG_TYPE_NONE }, #endif /* USE_XL24 */ - { &ati18800_device }, - { &ati18800_wonder_device }, - { &cga_device }, - { &sega_device }, - { &gd5401_isa_device }, - { &gd5402_isa_device }, - { &gd5420_isa_device }, - { &gd5422_isa_device }, - { &gd5426_isa_device }, - { &gd5426_diamond_speedstar_pro_a1_isa_device }, - { &gd5428_boca_isa_device }, - { &gd5428_isa_device }, - { &gd5429_isa_device }, - { &gd5434_isa_device }, - { &gd5434_diamond_speedstar_64_a3_isa_device }, - { &compaq_cga_device }, - { &compaq_cga_2_device }, - { &cpqega_device }, - { &ega_device }, - { &g2_gc205_device }, - { &hercules_device, VIDEO_FLAG_TYPE_MDA }, - { &herculesplus_device, VIDEO_FLAG_TYPE_MDA }, - { &incolor_device }, - { &inmos_isa_device, VIDEO_FLAG_TYPE_XGA }, - { &im1024_device }, - { &iskra_ega_device }, - { &et4000_kasan_isa_device }, - { &mda_device, VIDEO_FLAG_TYPE_MDA }, - { &genius_device }, - { &nga_device }, - { &ogc_device }, - { &oti037c_device }, - { &oti067_device }, - { &oti077_device }, - { ¶dise_pvga1a_device }, - { ¶dise_wd90c11_device }, - { ¶dise_wd90c30_device }, - { &colorplus_device }, - { &pgc_device }, - { &cga_pravetz_device }, - { &radius_svga_multiview_isa_device }, - { &realtek_rtg3105_device }, - { &realtek_rtg3106_device }, - { &s3_diamond_stealth_vram_isa_device }, - { &s3_orchid_86c911_isa_device }, - { &s3_ami_86c924_isa_device }, - { &s3_metheus_86c928_isa_device }, - { &s3_phoenix_86c801_isa_device }, - { &s3_spea_mirage_86c801_isa_device }, - { &sigma_device }, - { &tvga8900b_device }, - { &tvga8900d_device }, - { &tvga8900dr_device }, - { &tvga9000b_device }, - { &nec_sv9000_device }, - { &et4000k_isa_device }, - { &et2000_device }, - { &et3000_isa_device }, - { &et4000_tc6058af_isa_device }, - { &et4000_isa_device }, - { &et4000w32_device }, - { &et4000w32i_isa_device }, - { &vga_device }, - { &v7_vga_1024i_device }, - { &wy700_device }, - { &mach32_mca_device, VIDEO_FLAG_TYPE_8514 }, - { &gd5426_mca_device }, - { &gd5428_mca_device }, - { &et4000_mca_device }, - { &radius_svga_multiview_mca_device }, - { &mach32_pci_device, VIDEO_FLAG_TYPE_8514 }, - { &mach64gx_pci_device }, - { &mach64vt2_device }, - { &bochs_svga_device }, - { &chips_69000_device }, - { &gd5430_pci_device, }, - { &gd5434_pci_device }, - { &gd5436_pci_device, VIDEO_FLAG_TYPE_SPECIAL }, - { &gd5440_pci_device }, - { &gd5446_pci_device, VIDEO_FLAG_TYPE_SPECIAL }, - { &gd5446_stb_pci_device, VIDEO_FLAG_TYPE_SPECIAL }, - { &gd5480_pci_device }, - { &et4000w32p_videomagic_revb_pci_device }, - { &et4000w32p_revc_pci_device }, - { &et4000w32p_cardex_pci_device }, - { &et4000w32p_noncardex_pci_device }, - { &et4000w32p_pci_device }, - { &s3_spea_mercury_lite_86c928_pci_device }, - { &s3_diamond_stealth64_964_pci_device }, - { &s3_elsa_winner2000_pro_x_964_pci_device }, - { &s3_mirocrystal_20sv_964_pci_device }, - { &s3_bahamas64_pci_device }, - { &s3_phoenix_vision864_pci_device }, - { &s3_diamond_stealth_se_pci_device }, - { &s3_phoenix_trio32_pci_device }, - { &s3_diamond_stealth64_pci_device }, - { &s3_9fx_pci_device }, - { &s3_phoenix_trio64_pci_device }, - { &s3_diamond_stealth64_968_pci_device }, - { &s3_elsa_winner2000_pro_x_pci_device }, - { &s3_mirovideo_40sv_ergo_968_pci_device }, - { &s3_9fx_771_pci_device }, - { &s3_phoenix_vision968_pci_device }, - { &s3_spea_mercury_p64v_pci_device }, - { &s3_9fx_531_pci_device }, - { &s3_phoenix_vision868_pci_device }, - { &s3_cardex_trio64vplus_pci_device }, - { &s3_phoenix_trio64vplus_pci_device }, - { &s3_trio64v2_dx_pci_device }, - { &s3_virge_325_pci_device }, - { &s3_diamond_stealth_2000_pci_device }, - { &s3_mirocrystal_3d_pci_device }, - { &s3_diamond_stealth_3000_pci_device }, - { &s3_stb_velocity_3d_pci_device }, - { &s3_virge_375_pci_device }, - { &s3_diamond_stealth_2000pro_pci_device }, - { &s3_virge_385_pci_device }, - { &s3_virge_357_pci_device }, - { &s3_diamond_stealth_4000_pci_device }, - { &s3_trio3d2x_pci_device }, - { &millennium_device }, - { &millennium_ii_device }, - { &mystique_device }, - { &mystique_220_device }, - { &tgui9440_pci_device }, - { &tgui9660_pci_device }, - { &tgui9680_pci_device }, - { &voodoo_banshee_device }, - { &creative_voodoo_banshee_device }, - { &voodoo_3_1000_device }, - { &voodoo_3_2000_device }, - { &voodoo_3_3000_device }, - { &mach32_vlb_device, VIDEO_FLAG_TYPE_8514 }, - { &mach64gx_vlb_device }, - { &et4000w32i_vlb_device }, - { &et4000w32p_videomagic_revb_vlb_device }, - { &et4000w32p_revc_vlb_device }, - { &et4000w32p_cardex_vlb_device }, - { &et4000w32p_vlb_device }, - { &et4000w32p_noncardex_vlb_device }, - { &gd5424_vlb_device }, - { &gd5426_vlb_device }, - { &gd5428_vlb_device }, - { &gd5428_diamond_speedstar_pro_b1_vlb_device }, - { &gd5429_vlb_device }, - { &gd5430_diamond_speedstar_pro_se_a8_vlb_device }, - { &gd5430_vlb_device }, - { &gd5434_vlb_device }, - { &s3_metheus_86c928_vlb_device }, - { &s3_mirocrystal_8s_805_vlb_device }, - { &s3_mirocrystal_10sd_805_vlb_device }, - { &s3_phoenix_86c805_vlb_device }, - { &s3_spea_mirage_86c805_vlb_device }, - { &s3_diamond_stealth64_964_vlb_device }, - { &s3_mirocrystal_20sv_964_vlb_device }, - { &s3_mirocrystal_20sd_864_vlb_device }, - { &s3_bahamas64_vlb_device }, - { &s3_phoenix_vision864_vlb_device }, - { &s3_diamond_stealth_se_vlb_device }, - { &s3_phoenix_trio32_vlb_device }, - { &s3_diamond_stealth64_vlb_device }, - { &s3_9fx_vlb_device }, - { &s3_phoenix_trio64_vlb_device }, - { &s3_spea_mirage_p64_vlb_device }, - { &s3_diamond_stealth64_968_vlb_device }, - { &s3_stb_powergraph_64_video_vlb_device }, - { &ht216_32_standalone_device }, - { &tgui9400cxi_device }, - { &tgui9440_vlb_device }, - { &s3_virge_357_agp_device }, - { &s3_diamond_stealth_4000_agp_device }, - { &s3_trio3d2x_agp_device }, + { .device = &ati18800_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &ati18800_wonder_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &cga_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &sega_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &gd5401_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &gd5402_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &gd5420_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &gd5422_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &gd5426_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &gd5426_diamond_speedstar_pro_a1_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &gd5428_boca_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &gd5428_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &gd5429_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &gd5434_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &gd5434_diamond_speedstar_64_a3_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &compaq_cga_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &compaq_cga_2_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &cpqega_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &ega_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &g2_gc205_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &hercules_device, .flags = VIDEO_FLAG_TYPE_MDA }, + { .device = &herculesplus_device, .flags = VIDEO_FLAG_TYPE_MDA }, + { .device = &incolor_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &inmos_isa_device, .flags = VIDEO_FLAG_TYPE_XGA }, + { .device = &im1024_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &iskra_ega_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &et4000_kasan_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &mda_device, .flags = VIDEO_FLAG_TYPE_MDA }, + { .device = &genius_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &nga_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &ogc_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &oti037c_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &oti067_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &oti077_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = ¶dise_pvga1a_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = ¶dise_wd90c11_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = ¶dise_wd90c30_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &colorplus_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &pgc_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &cga_pravetz_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &radius_svga_multiview_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &realtek_rtg3105_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &realtek_rtg3106_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_diamond_stealth_vram_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_orchid_86c911_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_ami_86c924_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_metheus_86c928_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_phoenix_86c801_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_spea_mirage_86c801_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &sigma_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &tvga8900b_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &tvga8900d_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &tvga8900dr_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &tvga9000b_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &nec_sv9000_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &et4000k_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &et2000_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &et3000_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &et4000_tc6058af_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &et4000_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &et4000w32_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &et4000w32i_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &vga_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &v7_vga_1024i_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &wy700_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &mach32_mca_device, .flags = VIDEO_FLAG_TYPE_8514 }, + { .device = &gd5426_mca_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &gd5428_mca_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &et4000_mca_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &radius_svga_multiview_mca_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &mach32_pci_device, .flags = VIDEO_FLAG_TYPE_8514 }, + { .device = &mach64gx_pci_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &mach64vt2_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &bochs_svga_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &chips_69000_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &gd5430_pci_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &gd5434_pci_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &gd5436_pci_device, .flags = VIDEO_FLAG_TYPE_SPECIAL }, + { .device = &gd5440_pci_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &gd5446_pci_device, .flags = VIDEO_FLAG_TYPE_SPECIAL }, + { .device = &gd5446_stb_pci_device, .flags = VIDEO_FLAG_TYPE_SPECIAL }, + { .device = &gd5480_pci_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &et4000w32p_videomagic_revb_pci_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &et4000w32p_revc_pci_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &et4000w32p_cardex_pci_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &et4000w32p_noncardex_pci_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &et4000w32p_pci_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_spea_mercury_lite_86c928_pci_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_diamond_stealth64_964_pci_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_elsa_winner2000_pro_x_964_pci_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_mirocrystal_20sv_964_pci_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_bahamas64_pci_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_phoenix_vision864_pci_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_diamond_stealth_se_pci_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_phoenix_trio32_pci_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_diamond_stealth64_pci_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_9fx_pci_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_phoenix_trio64_pci_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_diamond_stealth64_968_pci_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_elsa_winner2000_pro_x_pci_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_mirovideo_40sv_ergo_968_pci_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_9fx_771_pci_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_phoenix_vision968_pci_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_spea_mercury_p64v_pci_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_9fx_531_pci_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_phoenix_vision868_pci_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_cardex_trio64vplus_pci_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_phoenix_trio64vplus_pci_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_trio64v2_dx_pci_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_virge_325_pci_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_diamond_stealth_2000_pci_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_mirocrystal_3d_pci_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_diamond_stealth_3000_pci_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_stb_velocity_3d_pci_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_virge_375_pci_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_diamond_stealth_2000pro_pci_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_virge_385_pci_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_virge_357_pci_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_diamond_stealth_4000_pci_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_trio3d2x_pci_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &millennium_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &millennium_ii_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &mystique_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &mystique_220_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &tgui9440_pci_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &tgui9660_pci_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &tgui9680_pci_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &voodoo_banshee_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &creative_voodoo_banshee_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &voodoo_3_1000_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &voodoo_3_2000_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &voodoo_3_3000_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &mach32_vlb_device, .flags = VIDEO_FLAG_TYPE_8514 }, + { .device = &mach64gx_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &et4000w32i_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &et4000w32p_videomagic_revb_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &et4000w32p_revc_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &et4000w32p_cardex_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &et4000w32p_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &et4000w32p_noncardex_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &gd5424_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &gd5426_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &gd5428_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &gd5428_diamond_speedstar_pro_b1_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &gd5429_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &gd5430_diamond_speedstar_pro_se_a8_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &gd5430_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &gd5434_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_metheus_86c928_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_mirocrystal_8s_805_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_mirocrystal_10sd_805_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_phoenix_86c805_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_spea_mirage_86c805_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_diamond_stealth64_964_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_mirocrystal_20sv_964_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_mirocrystal_20sd_864_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_bahamas64_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_phoenix_vision864_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_diamond_stealth_se_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_phoenix_trio32_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_diamond_stealth64_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_9fx_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_phoenix_trio64_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_spea_mirage_p64_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_diamond_stealth64_968_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_stb_powergraph_64_video_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &ht216_32_standalone_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &tgui9400cxi_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &tgui9440_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_virge_357_agp_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_diamond_stealth_4000_agp_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_trio3d2x_agp_device, .flags = VIDEO_FLAG_TYPE_NONE }, #ifdef USE_G100 - { &productiva_g100_device, VIDEO_FLAG_TYPE_SPECIAL }, + { .device = &productiva_g100_device, .flags = VIDEO_FLAG_TYPE_SPECIAL }, #endif /*USE_G100 */ - { &velocity_100_agp_device }, - { &velocity_200_agp_device }, - { &voodoo_3_1000_agp_device }, - { &voodoo_3_2000_agp_device }, - { &voodoo_3_3000_agp_device }, - { &voodoo_3_3500_agp_ntsc_device }, - { &voodoo_3_3500_agp_pal_device }, - { &compaq_voodoo_3_3500_agp_device }, - { &voodoo_3_3500_se_agp_device }, - { &voodoo_3_3500_si_agp_device }, - { NULL } + { .device = &velocity_100_agp_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &velocity_200_agp_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &voodoo_3_1000_agp_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &voodoo_3_2000_agp_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &voodoo_3_3000_agp_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &voodoo_3_3500_agp_ntsc_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &voodoo_3_3500_agp_pal_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &compaq_voodoo_3_3500_agp_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &voodoo_3_3500_se_agp_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &voodoo_3_3500_si_agp_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = NULL, .flags = VIDEO_FLAG_TYPE_NONE } // clang-format on }; diff --git a/src/video/vid_tgui9440.c b/src/video/vid_tgui9440.c index 9ec7e6105..e9fbe57f2 100644 --- a/src/video/vid_tgui9440.c +++ b/src/video/vid_tgui9440.c @@ -210,7 +210,7 @@ static void tgui_ext_writel(uint32_t addr, uint32_t val, void *priv); /*Remap address for chain-4/doubleword style layout*/ static __inline uint32_t -dword_remap(svga_t *svga, uint32_t in_addr) +dword_remap(UNUSED(svga_t *svga), uint32_t in_addr) { return ((in_addr << 2) & 0x3fff0) | ((in_addr >> 14) & 0xc) | (in_addr & ~0x3fffc); } @@ -3382,9 +3382,7 @@ static const device_config_t tgui9440_config[] = { }, .default_int = 2 }, - { - .type = CONFIG_END - } + { .name = "", .description = "", .type = CONFIG_END } }; static const device_config_t tgui96xx_config[] = { @@ -3411,9 +3409,7 @@ static const device_config_t tgui96xx_config[] = { }, .default_int = 4 }, - { - .type = CONFIG_END - } + { .name = "", .description = "", .type = CONFIG_END } }; // clang-format on @@ -3425,7 +3421,7 @@ const device_t tgui9400cxi_device = { .init = tgui_init, .close = tgui_close, .reset = NULL, - { .available = tgui9400cxi_available }, + .available = tgui9400cxi_available, .speed_changed = tgui_speed_changed, .force_redraw = tgui_force_redraw, .config = tgui9440_config @@ -3439,7 +3435,7 @@ const device_t tgui9440_vlb_device = { .init = tgui_init, .close = tgui_close, .reset = NULL, - { .available = tgui9440_vlb_available }, + .available = tgui9440_vlb_available, .speed_changed = tgui_speed_changed, .force_redraw = tgui_force_redraw, .config = tgui9440_config @@ -3453,7 +3449,7 @@ const device_t tgui9440_pci_device = { .init = tgui_init, .close = tgui_close, .reset = NULL, - { .available = tgui9440_pci_available }, + .available = tgui9440_pci_available, .speed_changed = tgui_speed_changed, .force_redraw = tgui_force_redraw, .config = tgui9440_config @@ -3467,7 +3463,7 @@ const device_t tgui9440_onboard_pci_device = { .init = tgui_init, .close = tgui_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = tgui_speed_changed, .force_redraw = tgui_force_redraw, .config = tgui9440_config @@ -3481,7 +3477,7 @@ const device_t tgui9660_pci_device = { .init = tgui_init, .close = tgui_close, .reset = NULL, - { .available = tgui96xx_available }, + .available = tgui96xx_available, .speed_changed = tgui_speed_changed, .force_redraw = tgui_force_redraw, .config = tgui96xx_config @@ -3495,7 +3491,7 @@ const device_t tgui9660_onboard_pci_device = { .init = tgui_init, .close = tgui_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = tgui_speed_changed, .force_redraw = tgui_force_redraw, .config = tgui96xx_config @@ -3509,7 +3505,7 @@ const device_t tgui9680_pci_device = { .init = tgui_init, .close = tgui_close, .reset = NULL, - { .available = tgui96xx_available }, + .available = tgui96xx_available, .speed_changed = tgui_speed_changed, .force_redraw = tgui_force_redraw, .config = tgui96xx_config diff --git a/src/video/vid_ti_cf62011.c b/src/video/vid_ti_cf62011.c index f23cb7396..fcc046cb4 100644 --- a/src/video/vid_ti_cf62011.c +++ b/src/video/vid_ti_cf62011.c @@ -266,7 +266,7 @@ const device_t ibm_ps1_2121_device = { .init = vid_init, .close = vid_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = vid_speed_changed, .force_redraw = vid_force_redraw, .config = NULL diff --git a/src/video/vid_tkd8001_ramdac.c b/src/video/vid_tkd8001_ramdac.c index 4108b9a4e..c8ad1c421 100644 --- a/src/video/vid_tkd8001_ramdac.c +++ b/src/video/vid_tkd8001_ramdac.c @@ -129,7 +129,7 @@ const device_t tkd8001_ramdac_device = { .init = tkd8001_ramdac_init, .close = tkd8001_ramdac_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/video/vid_tvga.c b/src/video/vid_tvga.c index eb0d1a780..9f329a604 100644 --- a/src/video/vid_tvga.c +++ b/src/video/vid_tvga.c @@ -544,78 +544,76 @@ static const device_config_t tvga_config[] = { } } }, - { - .type = CONFIG_END - } + { .name = "", .description = "", .type = CONFIG_END } // clang-format off }; const device_t tvga8900b_device = { - .name = "Trident TVGA 8900B", + .name = "Trident TVGA 8900B", .internal_name = "tvga8900b", - .flags = DEVICE_ISA, - .local = TVGA8900B_ID, - .init = tvga_init, - .close = tvga_close, - .reset = NULL, - { .available = tvga8900b_available }, + .flags = DEVICE_ISA, + .local = TVGA8900B_ID, + .init = tvga_init, + .close = tvga_close, + .reset = NULL, + .available = tvga8900b_available, .speed_changed = tvga_speed_changed, - .force_redraw = tvga_force_redraw, - .config = tvga_config + .force_redraw = tvga_force_redraw, + .config = tvga_config }; const device_t tvga8900d_device = { - .name = "Trident TVGA 8900D", + .name = "Trident TVGA 8900D", .internal_name = "tvga8900d", - .flags = DEVICE_ISA, - .local = TVGA8900CLD_ID, - .init = tvga_init, - .close = tvga_close, - .reset = NULL, - { .available = tvga8900d_available }, + .flags = DEVICE_ISA, + .local = TVGA8900CLD_ID, + .init = tvga_init, + .close = tvga_close, + .reset = NULL, + .available = tvga8900d_available, .speed_changed = tvga_speed_changed, - .force_redraw = tvga_force_redraw, - .config = tvga_config + .force_redraw = tvga_force_redraw, + .config = tvga_config }; const device_t tvga8900dr_device = { - .name = "Trident TVGA 8900D-R", + .name = "Trident TVGA 8900D-R", .internal_name = "tvga8900dr", - .flags = DEVICE_ISA, - .local = TVGA8900CLD_ID | 0x0100, - .init = tvga_init, - .close = tvga_close, - .reset = NULL, - { .available = tvga8900dr_available }, + .flags = DEVICE_ISA, + .local = TVGA8900CLD_ID | 0x0100, + .init = tvga_init, + .close = tvga_close, + .reset = NULL, + .available = tvga8900dr_available, .speed_changed = tvga_speed_changed, - .force_redraw = tvga_force_redraw, - .config = tvga_config + .force_redraw = tvga_force_redraw, + .config = tvga_config }; const device_t tvga9000b_device = { - .name = "Trident TVGA 9000B", + .name = "Trident TVGA 9000B", .internal_name = "tvga9000b", - .flags = DEVICE_ISA, - .local = TVGA9000B_ID, - .init = tvga_init, - .close = tvga_close, - .reset = NULL, - { .available = tvga9000b_available }, + .flags = DEVICE_ISA, + .local = TVGA9000B_ID, + .init = tvga_init, + .close = tvga_close, + .reset = NULL, + .available = tvga9000b_available, .speed_changed = tvga_speed_changed, - .force_redraw = tvga_force_redraw, - .config = NULL + .force_redraw = tvga_force_redraw, + .config = NULL }; const device_t nec_sv9000_device = { - .name = "NEC SV9000 (Trident TVGA 9000B)", + .name = "NEC SV9000 (Trident TVGA 9000B)", .internal_name = "nec_sv9000", - .flags = DEVICE_ISA, - .local = TVGA9000B_ID | 0x100, - .init = tvga_init, - .close = tvga_close, - .reset = NULL, - { .available = tvga9000b_nec_sv9000_available }, + .flags = DEVICE_ISA, + .local = TVGA9000B_ID | 0x100, + .init = tvga_init, + .close = tvga_close, + .reset = NULL, + .available = tvga9000b_nec_sv9000_available, .speed_changed = tvga_speed_changed, - .force_redraw = tvga_force_redraw, - .config = NULL + .force_redraw = tvga_force_redraw, + .config = NULL }; diff --git a/src/video/vid_tvp3026_ramdac.c b/src/video/vid_tvp3026_ramdac.c index 6c001b461..bd5a83fd0 100644 --- a/src/video/vid_tvp3026_ramdac.c +++ b/src/video/vid_tvp3026_ramdac.c @@ -733,7 +733,7 @@ const device_t tvp3026_ramdac_device = { .init = tvp3026_ramdac_init, .close = tvp3026_ramdac_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/video/vid_vga.c b/src/video/vid_vga.c index 881a3c6fd..ad66192ac 100644 --- a/src/video/vid_vga.c +++ b/src/video/vid_vga.c @@ -194,7 +194,7 @@ const device_t vga_device = { .init = vga_init, .close = vga_close, .reset = NULL, - { .available = vga_available }, + .available = vga_available, .speed_changed = vga_speed_changed, .force_redraw = vga_force_redraw, .config = NULL @@ -208,7 +208,7 @@ const device_t ps1vga_device = { .init = ps1vga_init, .close = vga_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = vga_speed_changed, .force_redraw = vga_force_redraw, .config = NULL @@ -222,7 +222,7 @@ const device_t ps1vga_mca_device = { .init = ps1vga_init, .close = vga_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = vga_speed_changed, .force_redraw = vga_force_redraw, .config = NULL diff --git a/src/video/vid_voodoo.c b/src/video/vid_voodoo.c index a9981333b..bf3b63736 100644 --- a/src/video/vid_voodoo.c +++ b/src/video/vid_voodoo.c @@ -1423,9 +1423,7 @@ static const device_config_t voodoo_config[] = { .default_int = 1 }, #endif - { - .type = CONFIG_END - } + { .name = "", .description = "", .type = CONFIG_END } // clang-format on }; @@ -1437,7 +1435,7 @@ const device_t voodoo_device = { .init = voodoo_init, .close = voodoo_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = voodoo_speed_changed, .force_redraw = voodoo_force_blit, .config = voodoo_config diff --git a/src/video/vid_voodoo_banshee.c b/src/video/vid_voodoo_banshee.c index 4fa27e2e4..ebd92d983 100644 --- a/src/video/vid_voodoo_banshee.c +++ b/src/video/vid_voodoo_banshee.c @@ -480,7 +480,7 @@ banshee_updatemapping(banshee_t *banshee) } uint32_t -banshee_conv_16to32(svga_t* svga, uint16_t color, uint8_t bpp) +banshee_conv_16to32(svga_t* svga, uint16_t color, UNUSED(uint8_t bpp)) { banshee_t *banshee = (banshee_t *) svga->priv; uint32_t ret = 0x00000000; @@ -3228,9 +3228,7 @@ static const device_config_t banshee_sgram_config[] = { .default_int = 1 }, #endif - { - .type = CONFIG_END - } + { .name = "", .description = "", .type = CONFIG_END } }; static const device_config_t banshee_sgram_16mbonly_config[] = { @@ -3283,9 +3281,7 @@ static const device_config_t banshee_sgram_16mbonly_config[] = { .default_int = 1 }, #endif - { - .type = CONFIG_END - } + { .name = "", .description = "", .type = CONFIG_END } }; static const device_config_t banshee_sdram_config[] = { @@ -3338,9 +3334,7 @@ static const device_config_t banshee_sdram_config[] = { .default_int = 1 }, #endif - { - .type = CONFIG_END - } + { .name = "", .description = "", .type = CONFIG_END } }; // clang-format on @@ -3743,7 +3737,7 @@ const device_t voodoo_banshee_device = { .init = banshee_init, .close = banshee_close, .reset = NULL, - { .available = banshee_available }, + .available = banshee_available, .speed_changed = banshee_speed_changed, .force_redraw = banshee_force_redraw, .config = banshee_sgram_config @@ -3757,7 +3751,7 @@ const device_t creative_voodoo_banshee_device = { .init = creative_banshee_init, .close = banshee_close, .reset = NULL, - { .available = creative_banshee_available }, + .available = creative_banshee_available, .speed_changed = banshee_speed_changed, .force_redraw = banshee_force_redraw, .config = banshee_sdram_config @@ -3771,7 +3765,7 @@ const device_t voodoo_3_1000_device = { .init = v3_1000_init, .close = banshee_close, .reset = NULL, - { .available = v3_1000_available }, + .available = v3_1000_available, .speed_changed = banshee_speed_changed, .force_redraw = banshee_force_redraw, .config = banshee_sgram_config @@ -3785,7 +3779,7 @@ const device_t voodoo_3_1000_agp_device = { .init = v3_1000_agp_init, .close = banshee_close, .reset = NULL, - { .available = v3_1000_agp_available }, + .available = v3_1000_agp_available, .speed_changed = banshee_speed_changed, .force_redraw = banshee_force_redraw, .config = banshee_sgram_16mbonly_config @@ -3799,7 +3793,7 @@ const device_t voodoo_3_2000_device = { .init = v3_2000_init, .close = banshee_close, .reset = NULL, - { .available = v3_2000_available }, + .available = v3_2000_available, .speed_changed = banshee_speed_changed, .force_redraw = banshee_force_redraw, .config = banshee_sdram_config @@ -3813,7 +3807,7 @@ const device_t voodoo_3_2000_agp_device = { .init = v3_2000_agp_init, .close = banshee_close, .reset = NULL, - { .available = v3_2000_agp_available }, + .available = v3_2000_agp_available, .speed_changed = banshee_speed_changed, .force_redraw = banshee_force_redraw, .config = banshee_sdram_config @@ -3827,7 +3821,7 @@ const device_t voodoo_3_2000_agp_onboard_8m_device = { .init = v3_2000_agp_onboard_init, .close = banshee_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = banshee_speed_changed, .force_redraw = banshee_force_redraw, .config = banshee_sgram_config @@ -3841,7 +3835,7 @@ const device_t voodoo_3_3000_device = { .init = v3_3000_init, .close = banshee_close, .reset = NULL, - { .available = v3_3000_available }, + .available = v3_3000_available, .speed_changed = banshee_speed_changed, .force_redraw = banshee_force_redraw, .config = banshee_sdram_config @@ -3855,7 +3849,7 @@ const device_t voodoo_3_3000_agp_device = { .init = v3_3000_agp_init, .close = banshee_close, .reset = NULL, - { .available = v3_3000_agp_available }, + .available = v3_3000_agp_available, .speed_changed = banshee_speed_changed, .force_redraw = banshee_force_redraw, .config = banshee_sdram_config @@ -3869,7 +3863,7 @@ const device_t voodoo_3_3500_agp_ntsc_device = { .init = v3_3500_agp_ntsc_init, .close = banshee_close, .reset = NULL, - { .available = v3_3500_agp_ntsc_available }, + .available = v3_3500_agp_ntsc_available, .speed_changed = banshee_speed_changed, .force_redraw = banshee_force_redraw, .config = banshee_sdram_config @@ -3883,7 +3877,7 @@ const device_t voodoo_3_3500_agp_pal_device = { .init = v3_3500_agp_pal_init, .close = banshee_close, .reset = NULL, - { .available = v3_3500_agp_pal_available }, + .available = v3_3500_agp_pal_available, .speed_changed = banshee_speed_changed, .force_redraw = banshee_force_redraw, .config = banshee_sdram_config @@ -3897,7 +3891,7 @@ const device_t compaq_voodoo_3_3500_agp_device = { .init = compaq_v3_3500_agp_init, .close = banshee_close, .reset = NULL, - { .available = compaq_v3_3500_agp_available }, + .available = compaq_v3_3500_agp_available, .speed_changed = banshee_speed_changed, .force_redraw = banshee_force_redraw, .config = banshee_sdram_config @@ -3911,7 +3905,7 @@ const device_t voodoo_3_3500_se_agp_device = { .init = v3_3500_se_agp_init, .close = banshee_close, .reset = NULL, - { .available = v3_3500_se_agp_available }, + .available = v3_3500_se_agp_available, .speed_changed = banshee_speed_changed, .force_redraw = banshee_force_redraw, .config = banshee_sdram_config @@ -3925,7 +3919,7 @@ const device_t voodoo_3_3500_si_agp_device = { .init = v3_3500_si_agp_init, .close = banshee_close, .reset = NULL, - { .available = v3_3500_si_agp_available }, + .available = v3_3500_si_agp_available, .speed_changed = banshee_speed_changed, .force_redraw = banshee_force_redraw, .config = banshee_sdram_config @@ -3939,7 +3933,7 @@ const device_t velocity_100_agp_device = { .init = velocity_100_agp_init, .close = banshee_close, .reset = NULL, - { .available = velocity_100_available }, + .available = velocity_100_available, .speed_changed = banshee_speed_changed, .force_redraw = banshee_force_redraw, .config = banshee_sdram_config @@ -3953,7 +3947,7 @@ const device_t velocity_200_agp_device = { .init = velocity_200_agp_init, .close = banshee_close, .reset = NULL, - { .available = velocity_200_available }, + .available = velocity_200_available, .speed_changed = banshee_speed_changed, .force_redraw = banshee_force_redraw, .config = banshee_sgram_16mbonly_config diff --git a/src/video/vid_wy700.c b/src/video/vid_wy700.c index 600fa21a8..a52bad4ee 100644 --- a/src/video/vid_wy700.c +++ b/src/video/vid_wy700.c @@ -1004,7 +1004,7 @@ const device_t wy700_device = { .init = wy700_init, .close = wy700_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = wy700_speed_changed, .force_redraw = NULL, .config = NULL diff --git a/src/video/vid_xga.c b/src/video/vid_xga.c index 852ff6273..fb27b8b2c 100644 --- a/src/video/vid_xga.c +++ b/src/video/vid_xga.c @@ -19,7 +19,7 @@ #include #include #include -#include <86box/bswap.h> +//#include <86box/bswap.h> #include <86box/86box.h> #include <86box/io.h> #include <86box/machine.h> @@ -243,6 +243,26 @@ xga_updatemapping(svga_t *svga) } } +static void +xga_render_blank(svga_t *svga) +{ + xga_t *xga = (xga_t *) svga->xga; + + if ((xga->displine + svga->y_add) < 0) + return; + + if (xga->firstline_draw == 2000) + xga->firstline_draw = xga->displine; + + xga->lastline_draw = xga->displine; + + uint32_t *line_ptr = &svga->monitor->target_buffer->line[xga->displine + svga->y_add][svga->x_add]; + uint32_t line_width = (uint32_t)(xga->h_disp) * sizeof(uint32_t); + + if (xga->h_disp > 0) + memset(line_ptr, 0, line_width); +} + void xga_recalctimings(svga_t *svga) { @@ -272,26 +292,43 @@ xga_recalctimings(svga_t *svga) xga->ma_latch = xga->disp_start_addr; + xga_log("XGA ClkSel1 = %d, ClkSel2 = %02x, dispcntl2=%02x.\n", (xga->clk_sel_1 >> 2) & 3, xga->clk_sel_2 & 0x80, xga->disp_cntl_2 & 0xc0); switch ((xga->clk_sel_1 >> 2) & 3) { case 0: xga_log("HDISP VGA0 = %d, XGA = %d.\n", svga->hdisp, xga->h_disp); if (xga->clk_sel_2 & 0x80) - svga->clock = (cpuclock * (double) (1ULL << 32)) / 41539000.0; + svga->clock_xga = (cpuclock * (double) (1ULL << 32)) / 41539000.0; else - svga->clock = (cpuclock * (double) (1ULL << 32)) / 25175000.0; + svga->clock_xga = (cpuclock * (double) (1ULL << 32)) / 25175000.0; break; case 1: xga_log("HDISP VGA1 = %d, XGA = %d.\n", svga->hdisp, xga->h_disp); - svga->clock = (cpuclock * (double) (1ULL << 32)) / 28322000.0; + svga->clock_xga = (cpuclock * (double) (1ULL << 32)) / 28322000.0; break; case 3: - svga->clock = (cpuclock * (double) (1ULL << 32)) / 44900000.0; + svga->clock_xga = (cpuclock * (double) (1ULL << 32)) / 44900000.0; break; default: break; } + + switch (xga->disp_cntl_2 & 7) { + case 2: + svga->render_xga = xga_render_4bpp; + break; + case 3: + svga->render_xga = xga_render_8bpp; + break; + case 4: + svga->render_xga = xga_render_16bpp; + break; + + default: + svga->render_xga = xga_render_blank; + break; + } } } @@ -1467,7 +1504,7 @@ xga_bitblt(svga_t *svga) uint32_t old_dest_dat; uint32_t color_cmp = xga->accel.color_cmp; uint32_t plane_mask = xga->accel.plane_mask; - uint32_t patbase = xga->accel.px_map_base[xga->accel.pat_src]; + uint32_t patbase; uint32_t dstbase = xga->accel.px_map_base[xga->accel.dst_map]; uint32_t srcbase = xga->accel.px_map_base[xga->accel.src_map]; uint32_t patwidth = xga->accel.px_map_width[xga->accel.pat_src]; @@ -1595,6 +1632,8 @@ xga_bitblt(svga_t *svga) } } } else if (xga->accel.pat_src >= 1) { + patbase = xga->accel.px_map_base[xga->accel.pat_src]; + if (patheight == 7) { if (xga->accel.src_map != 1) xga->accel.pattern = 1; @@ -1704,6 +1743,8 @@ xga_bitblt(svga_t *svga) } } } else { + patbase = xga->accel.px_map_base[xga->accel.pat_src]; + while (xga->accel.y >= 0) { mix = xga_accel_read_pattern_map_pixel(svga, xga->accel.px, xga->accel.py, patbase, patwidth + 1); @@ -2717,8 +2758,10 @@ xga_write_test(uint32_t addr, uint8_t val, void *priv) xga->vram[addr & xga->vram_mask] = val; xga_log("XGA Linear endian reverse write, val = %02x, addr = %05x, banked mask = %04x, a5test=%d.\n", val, addr, svga->banked_mask, xga->a5_test); } - } else if (xga->aperture_cntl || (!xga->aperture_cntl && (svga->mapping.base == 0xa0000))) + } else if (xga->aperture_cntl || (!xga->aperture_cntl && (svga->mapping.base == 0xa0000))) { xga->on = 0; + xga_log("OFF XGA write.\n"); + } } } @@ -2824,8 +2867,10 @@ xga_read_test(uint32_t addr, void *priv) addr += xga->read_bank; return xga->vram[addr & xga->vram_mask]; } - } else if (xga->aperture_cntl || (!xga->aperture_cntl && (svga->mapping.base == 0xa0000))) + } else if (xga->aperture_cntl || (!xga->aperture_cntl && (svga->mapping.base == 0xa0000))) { xga->on = 0; + xga_log("OFF XGA read.\n"); + } } return ret; } @@ -3029,6 +3074,12 @@ xga_readl_linear(uint32_t addr, void *priv) return ret; } +void +xga_set_poll(svga_t *svga) +{ + timer_set_callback(&svga->timer, xga_poll); +} + void xga_poll(void *priv) { @@ -3038,166 +3089,158 @@ xga_poll(void *priv) int wx; int wy; - if (!xga->linepos) { - if (xga->displine == xga->hwcursor_latch.y && xga->hwcursor_latch.ena) { - xga->hwcursor_on = xga->hwcursor_latch.cur_ysize - ((xga->hwcursor_latch.yoff & 0x20) ? 32 : 0); - xga->hwcursor_oddeven = 0; - } - - if (xga->displine == (xga->hwcursor_latch.y + 1) && xga->hwcursor_latch.ena && xga->interlace) { - xga->hwcursor_on = xga->hwcursor_latch.cur_ysize - ((xga->hwcursor_latch.yoff & 0x20) ? 33 : 1); - xga->hwcursor_oddeven = 1; - } - - timer_advance_u64(&svga->timer, svga->dispofftime); - svga->cgastat |= 1; - xga->linepos = 1; - - if (xga->dispon) { - xga->h_disp_on = 1; - - xga->ma &= xga->vram_mask; - - if (xga->firstline == 2000) { - xga->firstline = xga->displine; - video_wait_for_buffer_monitor(svga->monitor_index); + xga_log("XGA Poll=%d.\n", xga->on); + if (xga->on) { + if (!xga->linepos) { + if (xga->displine == xga->hwcursor_latch.y && xga->hwcursor_latch.ena) { + xga->hwcursor_on = xga->hwcursor_latch.cur_ysize - ((xga->hwcursor_latch.yoff & 0x20) ? 32 : 0); + xga->hwcursor_oddeven = 0; } - if (xga->hwcursor_on) - xga->changedvram[xga->ma >> 12] = xga->changedvram[(xga->ma >> 12) + 1] = xga->interlace ? 3 : 2; - - switch (xga->disp_cntl_2 & 7) { - case 2: - xga_render_4bpp(svga); - break; - case 3: - xga_render_8bpp(svga); - break; - case 4: - xga_render_16bpp(svga); - break; - default: - break; + if (xga->displine == (xga->hwcursor_latch.y + 1) && xga->hwcursor_latch.ena && xga->interlace) { + xga->hwcursor_on = xga->hwcursor_latch.cur_ysize - ((xga->hwcursor_latch.yoff & 0x20) ? 33 : 1); + xga->hwcursor_oddeven = 1; } - svga->x_add = (overscan_x >> 1); - xga_render_overscan_left(xga, svga); - xga_render_overscan_right(xga, svga); - svga->x_add = (overscan_x >> 1); + timer_advance_u64(&svga->timer, xga->dispofftime); + svga->cgastat |= 1; + xga->linepos = 1; - if (xga->hwcursor_on) { - xga_hwcursor_draw(svga, xga->displine + svga->y_add); - xga->hwcursor_on--; - if (xga->hwcursor_on && xga->interlace) + if (xga->dispon) { + xga->h_disp_on = 1; + + xga->ma &= xga->vram_mask; + + if (xga->firstline == 2000) { + xga->firstline = xga->displine; + video_wait_for_buffer_monitor(svga->monitor_index); + } + + if (xga->hwcursor_on) + xga->changedvram[xga->ma >> 12] = xga->changedvram[(xga->ma >> 12) + 1] = xga->interlace ? 3 : 2; + + svga->render_xga(svga); + + svga->x_add = (overscan_x >> 1); + xga_render_overscan_left(xga, svga); + xga_render_overscan_right(xga, svga); + svga->x_add = (overscan_x >> 1); + + if (xga->hwcursor_on) { + xga_hwcursor_draw(svga, xga->displine + svga->y_add); xga->hwcursor_on--; + if (xga->hwcursor_on && xga->interlace) + xga->hwcursor_on--; + } + + if (xga->lastline < xga->displine) + xga->lastline = xga->displine; } - if (xga->lastline < xga->displine) - xga->lastline = xga->displine; - } - - xga->displine++; - if (xga->interlace) xga->displine++; - if ((svga->cgastat & 8) && ((xga->displine & 0x0f) == (svga->crtc[0x11] & 0x0f)) && svga->vslines) - svga->cgastat &= ~8; - if (xga->displine > 1500) - xga->displine = 0; - } else { - timer_advance_u64(&svga->timer, svga->dispontime); - if (xga->dispon) - svga->cgastat &= ~1; + if (xga->interlace) + xga->displine++; + if ((svga->cgastat & 8) && ((xga->displine & 0x0f) == (svga->crtc[0x11] & 0x0f)) && svga->vslines) + svga->cgastat &= ~8; + if (xga->displine > 1500) + xga->displine = 0; + } else { + timer_advance_u64(&svga->timer, xga->dispontime); + if (xga->dispon) + svga->cgastat &= ~1; - xga->h_disp_on = 0; + xga->h_disp_on = 0; - xga->linepos = 0; - if (xga->dispon) { - if (xga->sc == xga->rowcount) { - xga->sc = 0; + xga->linepos = 0; + if (xga->dispon) { + if (xga->sc == xga->rowcount) { + xga->sc = 0; - xga_log("MA=%08x, MALATCH=%x.\n", xga->ma, xga->ma_latch); - xga->maback += (xga->rowoffset << 3); - if (xga->interlace) + xga_log("MA=%08x, MALATCH=%x.\n", xga->ma, xga->ma_latch); xga->maback += (xga->rowoffset << 3); + if (xga->interlace) + xga->maback += (xga->rowoffset << 3); - xga->maback &= xga->vram_mask; - xga->ma = xga->maback; - } else { - xga->sc++; - xga->sc &= 0x1f; - xga->ma = xga->maback; + xga->maback &= xga->vram_mask; + xga->ma = xga->maback; + } else { + xga->sc++; + xga->sc &= 0x1f; + xga->ma = xga->maback; + } + } + + xga->vc++; + xga->vc &= 0x7ff; + + if (xga->vc == xga->split) { + if (xga->interlace && xga->oddeven) + xga->ma = xga->maback = (xga->rowoffset << 1); + else + xga->ma = xga->maback = 0; + + xga->ma = (xga->ma << 2); + xga->maback = (xga->maback << 2); + + xga->sc = 0; + } + if (xga->vc == xga->dispend) { + xga->dispon = 0; + + for (x = 0; x < ((xga->vram_mask + 1) >> 12); x++) { + if (xga->changedvram[x]) + xga->changedvram[x]--; + } + if (svga->fullchange) + svga->fullchange--; + } + if (xga->vc == xga->v_syncstart) { + xga->dispon = 0; + svga->cgastat |= 8; + x = xga->h_disp; + + if (xga->interlace && !xga->oddeven) + xga->lastline++; + if (xga->interlace && xga->oddeven) + xga->firstline--; + + wx = x; + + wy = xga->lastline - xga->firstline; + svga_doblit(wx, wy, svga); + + xga->firstline = 2000; + xga->lastline = 0; + + xga->firstline_draw = 2000; + xga->lastline_draw = 0; + + xga->oddeven ^= 1; + + svga->monitor->mon_changeframecount = xga->interlace ? 3 : 2; + + if (xga->interlace && xga->oddeven) + xga->ma = xga->maback = xga->ma_latch + (xga->rowoffset << 1); + else + xga->ma = xga->maback = xga->ma_latch; + + xga->ma = (xga->ma << 2); + xga->maback = (xga->maback << 2); + } + if (xga->vc == xga->v_total) { + xga->vc = 0; + xga->sc = 0; + xga->dispon = 1; + xga->displine = (xga->interlace && xga->oddeven) ? 1 : 0; + + svga->x_add = (overscan_x >> 1); + + xga->hwcursor_on = 0; + xga->hwcursor_latch = xga->hwcursor; } } - - xga->vc++; - xga->vc &= 0x7ff; - - if (xga->vc == xga->split) { - if (xga->interlace && xga->oddeven) - xga->ma = xga->maback = (xga->rowoffset << 1); - else - xga->ma = xga->maback = 0; - - xga->ma = (xga->ma << 2); - xga->maback = (xga->maback << 2); - - xga->sc = 0; - } - if (xga->vc == xga->dispend) { - xga->dispon = 0; - - for (x = 0; x < ((xga->vram_mask + 1) >> 12); x++) { - if (xga->changedvram[x]) - xga->changedvram[x]--; - } - if (svga->fullchange) - svga->fullchange--; - } - if (xga->vc == xga->v_syncstart) { - xga->dispon = 0; - svga->cgastat |= 8; - x = xga->h_disp; - - if (xga->interlace && !xga->oddeven) - xga->lastline++; - if (xga->interlace && xga->oddeven) - xga->firstline--; - - wx = x; - - wy = xga->lastline - xga->firstline; - svga_doblit(wx, wy, svga); - - xga->firstline = 2000; - xga->lastline = 0; - - xga->firstline_draw = 2000; - xga->lastline_draw = 0; - - xga->oddeven ^= 1; - - svga->monitor->mon_changeframecount = xga->interlace ? 3 : 2; - - if (xga->interlace && xga->oddeven) - xga->ma = xga->maback = xga->ma_latch + (xga->rowoffset << 1); - else - xga->ma = xga->maback = xga->ma_latch; - - xga->ma = (xga->ma << 2); - xga->maback = (xga->maback << 2); - } - if (xga->vc == xga->v_total) { - xga->vc = 0; - xga->sc = 0; - xga->dispon = 1; - xga->displine = (xga->interlace && xga->oddeven) ? 1 : 0; - - svga->x_add = (overscan_x >> 1); - - xga->hwcursor_on = 0; - xga->hwcursor_latch = xga->hwcursor; - } - } + } else + svga_recalctimings(svga); } static uint8_t @@ -3285,6 +3328,7 @@ xga_reset(void *priv) xga->on = 0; xga->a5_test = 0; mem_mapping_set_handler(&svga->mapping, svga->read, svga->readw, svga->readl, svga->write, svga->writew, svga->writel); + svga_set_poll(svga); } static uint8_t @@ -3773,7 +3817,7 @@ const device_t xga_device = { .init = xga_init, .close = xga_close, .reset = xga_reset, - { .available = xga_available }, + .available = xga_available, .speed_changed = xga_speed_changed, .force_redraw = xga_force_redraw, .config = xga_mca_configuration @@ -3787,7 +3831,7 @@ const device_t xga_isa_device = { .init = xga_init, .close = xga_close, .reset = xga_reset, - { .available = xga_available }, + .available = xga_available, .speed_changed = xga_speed_changed, .force_redraw = xga_force_redraw, .config = xga_isa_configuration @@ -3801,7 +3845,7 @@ const device_t inmos_isa_device = { .init = svga_xga_init, .close = xga_close, .reset = xga_reset, - { .available = inmos_xga_available }, + .available = inmos_xga_available, .speed_changed = xga_speed_changed, .force_redraw = xga_force_redraw, .config = xga_inmos_isa_configuration