diff --git a/src/86box.c b/src/86box.c index 5fba2cadc..fbd389ff0 100644 --- a/src/86box.c +++ b/src/86box.c @@ -32,6 +32,7 @@ #include #include #include +#include #ifndef _WIN32 # include @@ -233,6 +234,8 @@ extern int CPUID; extern int output; int atfullspeed; +extern double exp_pow_table[0x800]; + char exe_path[2048]; /* path (dir) of executable */ char usr_path[1024]; /* path (dir) of user data */ char cfg_path[1024]; /* full path of config file */ @@ -437,6 +440,75 @@ fatal_ex(const char *fmt, va_list ap) fflush(stdlog); } +/* Log a warning error, and display a UI message without exiting. */ +void +warning(const char *fmt, ...) +{ + char temp[1024]; + va_list ap; + char *sp; + + va_start(ap, fmt); + + if (stdlog == NULL) { + if (log_path[0] != '\0') { + stdlog = plat_fopen(log_path, "w"); + if (stdlog == NULL) + stdlog = stdout; + } else + stdlog = stdout; + } + + vsprintf(temp, fmt, ap); + fprintf(stdlog, "%s", temp); + fflush(stdlog); + va_end(ap); + + /* Make sure the message does not have a trailing newline. */ + if ((sp = strchr(temp, '\n')) != NULL) + *sp = '\0'; + + do_pause(2); + + ui_msgbox(MBX_ERROR | MBX_ANSI, temp); + + fflush(stdlog); + + do_pause(0); +} + +void +warning_ex(const char *fmt, va_list ap) +{ + char temp[1024]; + char *sp; + + if (stdlog == NULL) { + if (log_path[0] != '\0') { + stdlog = plat_fopen(log_path, "w"); + if (stdlog == NULL) + stdlog = stdout; + } else + stdlog = stdout; + } + + vsprintf(temp, fmt, ap); + fprintf(stdlog, "%s", temp); + fflush(stdlog); + + /* Make sure the message does not have a trailing newline. */ + if ((sp = strchr(temp, '\n')) != NULL) + *sp = '\0'; + + do_pause(2); + + ui_msgbox(MBX_ERROR | MBX_ANSI, temp); + + fflush(stdlog); + + do_pause(0); +} + #ifdef ENABLE_PC_LOG int pc_do_log = ENABLE_PC_LOG; @@ -1086,6 +1158,11 @@ pc_init_modules(void) machine_status_init(); + for (c = 0; c <= 0x7ff; c++) { + int64_t exp = c - 1023; /* 1023 = BIAS64 */ + exp_pow_table[c] = pow(2.0, (double) exp); + } + if (do_nothing) { do_nothing = 0; exit(-1); diff --git a/src/config.c b/src/config.c index 3bb9fb59a..2e6a5460f 100644 --- a/src/config.c +++ b/src/config.c @@ -3011,6 +3011,19 @@ save_other_removable_devices(void) else ini_section_set_string(cat, temp, zip_drives[c].image_path); } + + for (int i = 0; i < MAX_PREV_IMAGES; i++) { + sprintf(temp, "zip_%02i_image_history_%02i", c + 1, i + 1); + if ((zip_drives[c].image_history[i] == 0) || strlen(zip_drives[c].image_history[i]) == 0) + ini_section_delete_var(cat, temp); + else { + path_normalize(zip_drives[c].image_history[i]); + if (!strnicmp(zip_drives[c].image_history[i], usr_path, strlen(usr_path))) + ini_section_set_string(cat, temp, &zip_drives[c].image_history[i][strlen(usr_path)]); + else + ini_section_set_string(cat, temp, zip_drives[c].image_history[i]); + } + } } for (c = 0; c < MO_NUM; c++) { @@ -3054,6 +3067,19 @@ save_other_removable_devices(void) else ini_section_set_string(cat, temp, mo_drives[c].image_path); } + + for (int i = 0; i < MAX_PREV_IMAGES; i++) { + sprintf(temp, "mo_%02i_image_history_%02i", c + 1, i + 1); + if ((mo_drives[c].image_history[i] == 0) || strlen(mo_drives[c].image_history[i]) == 0) + ini_section_delete_var(cat, temp); + else { + path_normalize(mo_drives[c].image_history[i]); + if (!strnicmp(mo_drives[c].image_history[i], usr_path, strlen(usr_path))) + ini_section_set_string(cat, temp, &mo_drives[c].image_history[i][strlen(usr_path)]); + else + ini_section_set_string(cat, temp, mo_drives[c].image_history[i]); + } + } } ini_delete_section_if_empty(config, cat); diff --git a/src/cpu/cpu.c b/src/cpu/cpu.c index 41ca6932d..910d40765 100644 --- a/src/cpu/cpu.c +++ b/src/cpu/cpu.c @@ -287,6 +287,9 @@ uint8_t reg_30 = 0x00; uint8_t arr[24] = { 0 }; uint8_t rcr[8] = { 0 }; +/* Table for FXTRACT. */ +double exp_pow_table[0x800]; + static int cyrix_addr; static void cpu_write(uint16_t addr, uint8_t val, void *priv); diff --git a/src/cpu/x87_ops.h b/src/cpu/x87_ops.h index 6a51a2c7f..0bd8209e1 100644 --- a/src/cpu/x87_ops.h +++ b/src/cpu/x87_ops.h @@ -36,6 +36,8 @@ extern void fpu_log(const char *fmt, ...); # endif #endif +extern double exp_pow_table[0x800]; + static int rounding_modes[4] = { FE_TONEAREST, FE_DOWNWARD, FE_UPWARD, FE_TOWARDZERO }; #define ST(x) cpu_state.ST[((cpu_state.TOP + (x)) & 7)] diff --git a/src/cpu/x87_ops_misc.h b/src/cpu/x87_ops_misc.h index 4009eadd6..9a01f7496 100644 --- a/src/cpu/x87_ops_misc.h +++ b/src/cpu/x87_ops_misc.h @@ -46,7 +46,7 @@ opFXTRACT(UNUSED(uint32_t fetchdat)) test.eind.d = ST(0); exp80 = test.eind.ll & 0x7ff0000000000000LL; exp80final = (exp80 >> 52) - BIAS64; - mant = test.eind.d / (pow(2.0, (double) exp80final)); + mant = test.eind.d / exp_pow_table[exp80 >> 52]; ST(0) = (double) exp80final; FP_TAG_VALID; x87_push(mant); diff --git a/src/disk/mo.c b/src/disk/mo.c index e5cbd9140..f1cd3b983 100644 --- a/src/disk/mo.c +++ b/src/disk/mo.c @@ -486,19 +486,16 @@ mo_bus_speed(mo_t *dev) { double ret = -1.0; - if (dev && dev->drv && (dev->drv->bus_type == MO_BUS_SCSI)) { - dev->callback = -1.0; /* Speed depends on SCSI controller */ - return 0.0; - } else { - if (dev && dev->drv) - ret = ide_atapi_get_period(dev->drv->ide_channel); - if (ret == -1.0) { - if (dev) - dev->callback = -1.0; - return 0.0; - } else - return ret * 1000000.0; + if (dev && dev->drv) + ret = ide_atapi_get_period(dev->drv->ide_channel); + + if (ret == -1.0) { + if (dev) + dev->callback = -1.0; + ret = 0.0; } + + return ret; } static void @@ -509,18 +506,10 @@ mo_command_common(mo_t *dev) 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); - - const double period = 1000000.0 / bytes_per_second; - dev->callback = period * (double) (dev->packet_len); - } + else if (dev->drv->bus_type == MO_BUS_SCSI) + dev->callback = -1.0; /* Speed depends on SCSI controller */ + else + dev->callback = mo_bus_speed(dev) * (double) (dev->packet_len); mo_set_callback(dev); } @@ -1363,6 +1352,7 @@ mo_command(scsi_common_t *sc, const uint8_t *cdb) mo_buf_alloc(dev, dev->packet_len); const int ret = mo_blocks(dev, &alloc_length, 0); + alloc_length = dev->requested_blocks * dev->drv->sector_size; if (ret > 0) { dev->requested_blocks = max_len; diff --git a/src/disk/zip.c b/src/disk/zip.c index ae3319b40..eecafb802 100644 --- a/src/disk/zip.c +++ b/src/disk/zip.c @@ -567,19 +567,16 @@ zip_bus_speed(zip_t *dev) { double ret = -1.0; - if (dev && dev->drv && (dev->drv->bus_type == ZIP_BUS_SCSI)) { - dev->callback = -1.0; /* Speed depends on SCSI controller */ - return 0.0; - } else { - if (dev && dev->drv) - ret = ide_atapi_get_period(dev->drv->ide_channel); - if (ret == -1.0) { - if (dev) - dev->callback = -1.0; - return 0.0; - } else - return ret * 1000000.0; + if (dev && dev->drv) + ret = ide_atapi_get_period(dev->drv->ide_channel); + + if (ret == -1.0) { + if (dev) + dev->callback = -1.0; + ret = 0.0; } + + return ret; } static void @@ -590,18 +587,10 @@ zip_command_common(zip_t *dev) 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); - - double period = 1000000.0 / bytes_per_second; - dev->callback = period * (double) (dev->packet_len); - } + else if (dev->drv->bus_type == ZIP_BUS_SCSI) + dev->callback = -1.0; /* Speed depends on SCSI controller */ + else + dev->callback = zip_bus_speed(dev) * (double) (dev->packet_len); zip_set_callback(dev); } @@ -1386,10 +1375,8 @@ zip_command(scsi_common_t *sc, const uint8_t *cdb) 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); + const int ret = zip_blocks(dev, &alloc_length, 0); + alloc_length = dev->requested_blocks * 512; if (ret > 0) { dev->requested_blocks = max_len; diff --git a/src/include/86box/86box.h b/src/include/86box/86box.h index 40e1f7927..174685c34 100644 --- a/src/include/86box/86box.h +++ b/src/include/86box/86box.h @@ -194,15 +194,12 @@ extern __thread int is_cpu_thread; /* Is this the CPU thread? */ #ifdef HAVE_STDARG_H extern void pclog_ex(const char *fmt, va_list ap); extern void fatal_ex(const char *fmt, va_list ap); +extern void warning_ex(const char *fmt, va_list ap); #endif extern void pclog_toggle_suppr(void); -#ifdef _MSC_VER -extern void pclog(const char *fmt, ...); -extern void fatal(const char *fmt, ...); -#else extern void pclog(const char *fmt, ...) __attribute__ ((format (printf, 1, 2))); extern void fatal(const char *fmt, ...) __attribute__ ((format (printf, 1, 2))); -#endif +extern void warning(const char *fmt, ...) __attribute__ ((format (printf, 1, 2))); extern void set_screen_size(int x, int y); extern void set_screen_size_monitor(int x, int y, int monitor_index); extern void reset_screen_size(void); diff --git a/src/include/86box/log.h b/src/include/86box/log.h index a37bdec4f..e247ef9c5 100644 --- a/src/include/86box/log.h +++ b/src/include/86box/log.h @@ -36,6 +36,7 @@ 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, ...); +extern void log_warning(void *priv, const char *fmt, ...); extern void *log_open(const char *dev_name); extern void *log_open_cyclic(const char *dev_name); extern void log_close(void *priv); diff --git a/src/include/86box/plat.h b/src/include/86box/plat.h index 81874685e..7ed6e80d4 100644 --- a/src/include/86box/plat.h +++ b/src/include/86box/plat.h @@ -164,6 +164,7 @@ extern uint32_t plat_language_code(char *langcode); extern void plat_language_code_r(uint32_t lcid, char *outbuf, int len); extern void plat_get_cpu_string(char *outbuf, uint8_t len); extern void plat_set_thread_name(void *thread, const char *name); +extern void plat_break(void); /* Resource management. */ extern wchar_t *plat_get_string(int id); diff --git a/src/mem/mem.c b/src/mem/mem.c index d1c6de49d..d85b20581 100644 --- a/src/mem/mem.c +++ b/src/mem/mem.c @@ -2370,7 +2370,7 @@ mem_mapping_recalc(uint64_t base, uint64_t size) for (i_c = i_s; i_c <= i_e; i_c += i_a) { for (c = (start + i_c); c < (end + i_c); c += MEM_GRANULARITY_SIZE) { /* CPU */ - n = !!in_smm; + n = (!!in_smm) || (is_cxsmm && (ccr1 & CCR1_SMAC)); wp = _mem_wp[c >> MEM_GRANULARITY_BITS]; if (map->exec && mem_mapping_access_allowed(map->flags, diff --git a/src/qt/qt_platform.cpp b/src/qt/qt_platform.cpp index ebd6dc30c..1364750b1 100644 --- a/src/qt/qt_platform.cpp +++ b/src/qt/qt_platform.cpp @@ -842,3 +842,13 @@ plat_set_thread_name(void *thread, const char *name) # endif #endif } + +void +plat_break(void) +{ +#ifdef Q_OS_WINDOWS + DebugBreak(); +#else + raise(SIGTRAP); +#endif +} diff --git a/src/scsi/scsi_cdrom.c b/src/scsi/scsi_cdrom.c index b35662eeb..9ae65be74 100644 --- a/src/scsi/scsi_cdrom.c +++ b/src/scsi/scsi_cdrom.c @@ -656,7 +656,7 @@ scsi_cdrom_bus_speed(scsi_cdrom_t *dev) dev->callback = -1.0; return 0.0; } else - return ret * 1000000.0; + return 1000000.0 / ret; } } @@ -1069,8 +1069,9 @@ scsi_cdrom_read_data(scsi_cdrom_t *dev, const int msf, const int type, const int dev->block_len = temp_len; if ((dev->drv->bus_type != CDROM_BUS_SCSI) && - (scsi_cdrom_current_mode(dev) != 2)) + (scsi_cdrom_current_mode(dev) != 2)) { num = (dev->packet_len / dev->block_len); + } } dev->sector_pos++; @@ -1126,7 +1127,7 @@ scsi_cdrom_read_blocks(scsi_cdrom_t *dev) } if (ret) { - if (!dev->sector_len) { + if (dev->sector_len == 0) { scsi_cdrom_command_complete(dev); return -1; } diff --git a/src/scsi/scsi_disk.c b/src/scsi/scsi_disk.c index 878259094..8528db1fb 100644 --- a/src/scsi/scsi_disk.c +++ b/src/scsi/scsi_disk.c @@ -400,7 +400,8 @@ scsi_disk_bus_speed(scsi_disk_t *dev) dev->callback = -1.0; return 0.0; } else - return ret * 1000000.0; + /* We get bytes per µs, so divide 1000000.0 by it. */ + return 1000000.0 / ret; } } @@ -484,6 +485,10 @@ scsi_disk_command_common(scsi_disk_t *dev) break; } + /* + For ATAPI, this will be 1000000.0 / µs_per_byte, and this will + convert it back to µs_per_byte. + */ period = 1000000.0 / bytes_per_second; scsi_disk_log(dev->log, "Byte transfer period: %" PRIu64 " us\n", (uint64_t) period); @@ -1095,7 +1100,9 @@ scsi_disk_command(scsi_common_t *sc, const uint8_t *cdb) dev->drv->seek_pos = dev->sector_pos; dev->drv->seek_len = dev->sector_len; - ret = scsi_disk_blocks(dev, &alloc_length, 1, 0); + ret = scsi_disk_blocks(dev, &alloc_length, 1, 0); + alloc_length = dev->requested_blocks * 512; + if (ret > 0) { dev->requested_blocks = max_len; dev->packet_len = alloc_length; diff --git a/src/utils/log.c b/src/utils/log.c index fa39a6897..9c4a17f84 100644 --- a/src/utils/log.c +++ b/src/utils/log.c @@ -307,6 +307,31 @@ log_fatal(void *priv, const char *fmt, ...) exit(-1); } +void +log_warning(void *priv, const char *fmt, ...) +{ + log_t *log = (log_t *) priv; + char temp[1024]; + char fmt2[1024]; + va_list ap; + + 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); + warning_ex(fmt2, ap); + va_end(ap); +} + static void * log_open_common(const char *dev_name, const int cyclic) {