diff --git a/src/86box.h b/src/86box.h index 42b516047..42d1f9133 100644 --- a/src/86box.h +++ b/src/86box.h @@ -6,9 +6,9 @@ * * This file is part of the 86Box distribution. * - * Main emulator include file. + * Main include file for the application. * - * Version: @(#)86box.h 1.0.3 2017/10/09 + * Version: @(#)86box.h 1.0.7 2017/10/21 * * Authors: Miran Grca, * Fred N. van Kempen, @@ -20,6 +20,24 @@ # define EMU_86BOX_H +/* Configuration values. */ +#define SERIAL_MAX 2 +#define PARALLEL_MAX 1 +#define SCREEN_RES_X 640 +#define SCREEN_RES_Y 480 + +/* Version info. */ +#define EMU_NAME "86Box" +#define EMU_NAME_W L"86Box" +#define EMU_VERSION "2.00" +#define EMU_VERSION_W L"2.00" + +/* Filename and pathname info. */ +#define CONFIG_FILE_W L"86box.cfg" +#define NVR_PATH L"nvr" +#define SCREENSHOT_PATH L"screenshots" + + #if defined(ENABLE_BUSLOGIC_LOG) || \ defined(ENABLE_CDROM_LOG) || \ defined(ENABLE_D86F_LOG) || \ @@ -33,16 +51,72 @@ # define ENABLE_LOG_COMMANDS 1 #endif -#define EMU_VERSION "2.00" -#define EMU_VERSION_W L"2.00" -#define EMU_NAME "86Box" -#define EMU_NAME_W L"86Box" +#ifdef __cplusplus +extern "C" { +#endif -#define CONFIG_FILE_W L"86box.cfg" +/* Global variables. */ +extern int dump_on_exit; /* (O) dump regs on exit*/ +extern int do_dump_config; /* (O) dump cfg after load */ +extern int start_in_fullscreen; /* (O) start in fullscreen */ -#define NVR_PATH L"nvr" -#define SCREENSHOT_PATH L"screenshots" +extern int window_w, window_h, /* (C) window size and */ + window_x, window_y, /* position info */ + window_remember, + vid_resize, /* (C) allow resizing */ + invert_display, /* (C) invert the display */ + suppress_overscan; /* (C) suppress overscans */ +extern int scale; /* (C) screen scale factor */ +extern int vid_api; /* (C) video renderer */ +extern int vid_cga_contrast, /* (C) video */ + video_fullscreen, /* (C) video */ + video_fullscreen_first, /* (C) video */ + video_fullscreen_scale, /* (C) video */ + enable_overscan, /* (C) video */ + force_43, /* (C) video */ + video_speed; /* (C) video */ + + +#ifdef ENABLE_LOG_TOGGLES +extern int buslogic_do_log; +extern int cdrom_do_log; +extern int d86f_do_log; +extern int fdc_do_log; +extern int ide_do_log; +extern int serial_do_log; +extern int nic_do_log; +#endif + +extern wchar_t exe_path[1024]; /* path (dir) of executable */ +extern wchar_t cfg_path[1024]; /* path (dir) of user data */ +extern int scrnsz_x, /* current screen size, X */ + scrnsz_y; /* current screen size, Y */ + + +/* Function prototypes. */ +extern void pclog(const char *format, ...); +extern void fatal(const char *format, ...); +extern void set_screen_size(int x, int y); +extern void set_screen_size_natural(void); +extern int pc_init_modules(void); +extern int pc_init(int argc, wchar_t *argv[]); +extern void pc_close(void *threadid); +extern void pc_reset_hard_close(void); +extern void pc_reset_hard_init(void); +extern void pc_reset_hard(void); +extern void pc_reset(int hard); +extern void pc_full_speed(void); +extern void pc_speed_changed(void); +extern void pc_send_cad(void); +extern void pc_send_cae(void); +extern void pc_thread(void *param); +extern void pc_start(void); +extern void pc_onesec(void); + +#ifdef __cplusplus +} +#endif #endif /*EMU_86BOX_H*/ diff --git a/src/Makefile.local b/src/Makefile.local index 6f0df2aa8..f33613ab6 100644 --- a/src/Makefile.local +++ b/src/Makefile.local @@ -10,7 +10,7 @@ # settings, so we can avoid changing the main one for all of # our local setups. # -# Version: @(#)Makefile.local 1.0.4 2017/10/14 +# Version: @(#)Makefile.local 1.0.5 2017/10/19 # # Author: Fred N. van Kempen, # @@ -27,10 +27,56 @@ COPTIM := -O1 # Name of the executable. PROG := yourexe -# Various compile-time options. -STUFF := #-DROM_TRACE=0xC800 -DIO_TRACE=0x70 -EXTRAS := #-DYOURNAME +# Various compile-time options. +# -DROM_TRACE=0xc800 traces ROM access from segment C800 +# -DIO_TRACE=0x66 traces I/O on port 0x66 +STUFF := + +# Add feature selections here. +# -DANSI_CFG forces the config file to ANSI encoding. +# -DENABLE_VRAM_DUMP enables Video Ram dumping. +# -DENABLE_LOG_BREAKPOINT enables extra logging. +# -DENABLE_KEYBOARD_AMSTRAD_LOG=N sets logging level at N. +# -DENABLE_KEYBOARD_AT_LOG=N sets logging level at N. +# -DENABLE_KEYBOARD_LOG=N sets logging level at N. +# -DENABLE_PCI_LOG=N sets logging level at N. +# -DENABLE_CDROM_LOG=N sets logging level at N. +# -DENABLE_HDD_LOG=N sets logging level at N. +# -DENABLE_IDE_LOG=N sets logging level at N. +# -DENABLE_FDC_LOG=N sets logging level at N. +# -DENABLE_D86F_LOG=N sets logging level at N. +# -DENABLE_NIC_LOG=N sets logging level at N. +# -DENABLE_SCSI_BUS_LOG=N sets logging level at N. +# -DENABLE_SCSI_DISK_LOG=N sets logging level at N. +# -DENABLE_X54X_LOG=N sets logging level at N. +# -DENABLE_AHA154X_LOG=N sets logging level at N. +# -DENABLE_BUSLOGIC_LOG=N sets logging level at N. +# -DENABLE_NCR5380_LOG=N sets logging level at N. +# -DENABLE_AUDIOPCI_LOG=N sets logging level at N. +# -DENABLE_EMU8K_LOG=N sets logging level at N. +# -DENABLE_VRAM_DUMP=N sets logging level at N. +# -DENABLE_SERIAL_LOG=N sets logging level at N. +EXTRAS := + + +AUTODEP := n +DEBUG := n +OPTIM := n +X64 := n +RELEASE := n +USB := n +VNC := n +RDP := n +DEV_BUILD := n +DEV_BRANCH := n +CIRRUS := n +NE1000 := n +NV_RIVA := n +FLUIDSYNTH := y +MUNT := y +PAS16 := n +DYNAREC := y ######################################################################### diff --git a/src/bugger.c b/src/bugger.c index 75d5c983c..5d6f77ce0 100644 --- a/src/bugger.c +++ b/src/bugger.c @@ -44,7 +44,7 @@ * configuration register (CTRL_SPCFG bit set) but have to * remember that stuff first... * - * Version: @(#)bugger.c 1.0.7 2017/10/09 + * Version: @(#)bugger.c 1.0.8 2017/10/16 * * Author: Fred N. van Kempen, * Copyright 1989-2017 Fred N. van Kempen. @@ -53,6 +53,7 @@ #include #include #include +#include "86box.h" #include "ibm.h" #include "io.h" #include "ui.h" diff --git a/src/cdrom/cdrom.c b/src/cdrom/cdrom.c index cd8bd3a2c..d0df04b98 100644 --- a/src/cdrom/cdrom.c +++ b/src/cdrom/cdrom.c @@ -9,7 +9,7 @@ * Implementation of the CD-ROM drive with SCSI(-like) * commands, for both ATAPI and SCSI usage. * - * Version: @(#)cdrom.c 1.0.18 2017/10/15 + * Version: @(#)cdrom.c 1.0.19 2017/10/22 * * Author: Miran Grca, * @@ -845,7 +845,7 @@ void cdrom_init(int id, int cdb_len_setting) cdrom[id].sense[0] = 0xf0; cdrom[id].sense[7] = 10; cdrom_drives[id].bus_mode = 0; - if (cdrom_drives[id].bus_type > CDROM_BUS_ATAPI_PIO_AND_DMA) + if (cdrom_drives[id].bus_type >= CDROM_BUS_ATAPI_PIO_AND_DMA) { cdrom_drives[id].bus_mode |= 2; } @@ -890,6 +890,7 @@ int cdrom_current_mode(int id) } if (cdrom_supports_pio(id) && !cdrom_supports_dma(id)) { + cdrom_log("CD-ROM %i: Drive does not support DMA, setting to PIO\n", id); return 1; } if (!cdrom_supports_pio(id) && cdrom_supports_dma(id)) @@ -898,6 +899,7 @@ int cdrom_current_mode(int id) } if (cdrom_supports_pio(id) && cdrom_supports_dma(id)) { + cdrom_log("CD-ROM %i: Drive supports both, setting to %s\n", id, (cdrom[id].features & 1) ? "DMA" : "PIO", id); return (cdrom[id].features & 1) ? 2 : 1; } @@ -1366,6 +1368,8 @@ uint32_t cdrom_mode_sense(uint8_t id, uint8_t *buf, uint32_t pos, uint8_t type, void cdrom_update_request_length(uint8_t id, int len, int block_len) { + uint32_t bt; + /* For media access commands, make sure the requested DRQ length matches the block length. */ switch (cdrom[id].current_cdb[0]) { @@ -1378,17 +1382,11 @@ void cdrom_update_request_length(uint8_t id, int len, int block_len) { cdrom[id].request_length = block_len; } - /* Make sure we respect the limit of how many blocks we can transfer at once. */ - if (cdrom[id].requested_blocks > cdrom_drives[id].max_blocks_at_once) + bt = (cdrom[id].requested_blocks * block_len); + if (len > bt) { - cdrom[id].requested_blocks = cdrom_drives[id].max_blocks_at_once; + len = bt; } - cdrom[id].block_total = (cdrom[id].requested_blocks * block_len); - if (len > cdrom[id].block_total) - { - len = cdrom[id].block_total; - } - break; default: cdrom[id].packet_len = len; break; @@ -1406,21 +1404,6 @@ void cdrom_update_request_length(uint8_t id, int len, int block_len) return; } -static int cdrom_is_media_access(uint8_t id) -{ - switch (cdrom[id].current_cdb[0]) - { - case 0x08: - case 0x28: - case 0xa8: - case 0xb9: - case 0xbe: - return 1; - default: - return 0; - } -} - static void cdrom_command_common(uint8_t id) { cdrom[id].status = BUSY_STAT; @@ -1489,6 +1472,11 @@ static int cdrom_request_length_is_zero(uint8_t id) return 0; } +/* id = Current CD-ROM device ID; + 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). */ static void cdrom_data_command_finish(uint8_t id, int len, int block_len, int alloc_len, int direction) { cdrom_log("CD-ROM %i: Finishing command (%02X): %i, %i, %i, %i, %i\n", id, cdrom[id].current_cdb[0], len, block_len, alloc_len, direction, cdrom[id].request_length); @@ -2547,15 +2535,9 @@ cdrom_readtoc_fallback: } max_len = cdrom[id].sector_len; - /* if (cdrom_drives[id].bus_type == CDROM_BUS_SCSI) */ - if (cdrom_current_mode(id) == 2) - { - cdrom[id].requested_blocks = max_len; - } - else - { - cdrom[id].requested_blocks = 1; - } + cdrom[id].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. */ cdrom[id].packet_len = max_len * alloc_length; cdrom_buf_alloc(id, cdrom[id].packet_len); @@ -2566,27 +2548,13 @@ cdrom_readtoc_fallback: return; } - if (cdrom_current_mode(id) == 2) - { - cdrom[id].requested_blocks = max_len; - cdrom[id].packet_len = alloc_length; - } - else - { - cdrom[id].requested_blocks = 1; - cdrom[id].packet_len = max_len * alloc_length; - } + cdrom[id].requested_blocks = max_len; + cdrom[id].packet_len = alloc_length; cdrom_set_buf_len(id, BufLen, &cdrom[id].packet_len); - if (cdrom[id].requested_blocks > 1) - { - cdrom_data_command_finish(id, alloc_length, alloc_length / cdrom[id].requested_blocks, alloc_length, 0); - } - else - { - cdrom_data_command_finish(id, alloc_length, alloc_length, alloc_length, 0); - } + cdrom_data_command_finish(id, alloc_length, alloc_length / cdrom[id].requested_blocks, alloc_length, 0); + cdrom[id].all_blocks_total = cdrom[id].block_total; if (cdrom[id].packet_status != CDROM_PHASE_COMPLETE) { @@ -3434,63 +3402,6 @@ atapi_out: /* cdrom_log("CD-ROM %i: Phase: %02X, request length: %i\n", cdrom[id].phase, cdrom[id].request_length); */ } -/* This is for block reads. */ -int cdrom_block_check(uint8_t id) -{ - uint32_t alloc_length = 0; - int ret = 0; - - /* If this is a media access command, and we hit the end of the block but not the entire length, - read the next block. */ - if (cdrom_is_media_access(id)) - { - /* We have finished the current block. */ - cdrom_log("CD-ROM %i: %i bytes total read, %i bytes all total\n", id, cdrom[id].total_read, cdrom[id].all_blocks_total); - if (cdrom[id].total_read >= cdrom[id].all_blocks_total) - { - cdrom_log("CD-ROM %i: %i bytes read, current block finished\n", id, cdrom[id].total_read); - /* Read the next block. */ - ret = cdrom_read_blocks(id, &alloc_length, 0); - if (ret == -1) - { - /* Return value is -1 - there are no further blocks to read. */ - cdrom_log("CD-ROM %i: %i bytes read, no further blocks to read\n", id, cdrom[id].total_read); - cdrom[id].status = BUSY_STAT; - cdrom_buf_free(id); - return 1; - } - else if (ret == 0) - { - /* Return value is 0 - an error has occurred. */ - cdrom_log("CD-ROM %i: %i bytes read, error while reading blocks\n", id, cdrom[id].total_read); - cdrom[id].status = BUSY_STAT | (cdrom[id].status & ERR_STAT); - cdrom_buf_free(id); - return 0; - } - else - { - /* Return value is 1 - sectors have been read successfully. */ - cdrom[id].pos = 0; - cdrom[id].all_blocks_total += cdrom[id].block_total; - cdrom_log("CD-ROM %i: %i bytes read, next block(s) read successfully, %i bytes are still left\n", id, cdrom[id].total_read, cdrom[id].all_blocks_total - cdrom[id].total_read); - return 1; - } - } - else - { - /* Blocks not exhausted, tell the host to check for buffer length. */ - cdrom_log("CD-ROM %i: Blocks not yet finished\n", id); - return 1; - } - } - else - { - /* Not a media access command, ALWAYS do the callback. */ - cdrom_log("CD-ROM %i: Not a media access command\n", id); - return 1; - } -} - /* This is the general ATAPI callback. */ void cdrom_callback(uint8_t id) /* Callback for non-Read CD commands */ { @@ -3831,7 +3742,6 @@ uint32_t cdrom_read(uint8_t channel, int length) uint8_t id = atapi_cdrom_drives[channel]; uint32_t temp = 0; - int ret = 0; if (id > CDROM_NUM) { @@ -3844,20 +3754,23 @@ uint32_t cdrom_read(uint8_t channel, int length) if (!cdbufferb) return 0; + /* Make sure we return a 0 and don't attempt to read from the buffer if we're transferring bytes beyond it, + which can happen when issuing media access commands with an allocated length below minimum request length + (which is 1 sector = 2048 bytes). */ switch(length) { case 1: - temp = cdbufferb[cdrom[id].pos]; + temp = (cdrom[id].pos < cdrom[id].packet_len) ? cdbufferb[cdrom[id].pos] : 0; cdrom[id].pos++; cdrom[id].request_pos++; break; case 2: - temp = cdbufferw[cdrom[id].pos >> 1]; + temp = (cdrom[id].pos < cdrom[id].packet_len) ? cdbufferw[cdrom[id].pos >> 1] : 0; cdrom[id].pos += 2; cdrom[id].request_pos += 2; break; case 4: - temp = cdbufferl[cdrom[id].pos >> 2]; + temp = (cdrom[id].pos < cdrom[id].packet_len) ? cdbufferl[cdrom[id].pos >> 2] : 0; cdrom[id].pos += 4; cdrom[id].request_pos += 4; break; @@ -3867,26 +3780,12 @@ uint32_t cdrom_read(uint8_t channel, int length) if (cdrom[id].packet_status == CDROM_PHASE_DATA_IN) { - cdrom[id].total_read += length; - ret = cdrom_block_check(id); - /* If the block check has returned 0, this means all the requested blocks have been read, therefore the command has finished. */ - if (ret) + if (cdrom[id].request_pos >= cdrom[id].request_length) { - cdrom_log("CD-ROM %i: Return value is 1 (request length: %i)\n", id, cdrom[id].request_length); - if (cdrom[id].request_pos >= cdrom[id].request_length) - { - /* Time for a DRQ. */ - cdrom_log("CD-ROM %i: Issuing read callback\n", id); - cdrom_callback(id); - } - else - { - cdrom_log("CD-ROM %i: Doing nothing\n", id); - } - } - else - { - cdrom_log("CD-ROM %i: Return value is 0\n", id); + /* Time for a DRQ. */ + cdrom_log("CD-ROM %i: Issuing read callback\n", id); + cdrom[id].total_read += cdrom[id].request_length; + cdrom_callback(id); } cdrom_log("CD-ROM %i: Returning: %02X (buffer position: %i, request position: %i, total: %i)\n", id, temp, cdrom[id].pos, cdrom[id].request_pos, cdrom[id].total_read); return temp; diff --git a/src/cdrom/cdrom_dosbox.cpp b/src/cdrom/cdrom_dosbox.cpp index a8b1ef389..0ccf4973a 100644 --- a/src/cdrom/cdrom_dosbox.cpp +++ b/src/cdrom/cdrom_dosbox.cpp @@ -100,6 +100,7 @@ void CDROM_Interface_Image::InitNewMedia() bool CDROM_Interface_Image::SetDevice(char* path, int forceCD) { + (void)forceCD; if (LoadCueSheet(path)) return true; if (LoadIsoFile(path)) return true; @@ -174,6 +175,7 @@ bool CDROM_Interface_Image::ReadSectors(PhysPt buffer, bool raw, unsigned long s bool CDROM_Interface_Image::LoadUnloadMedia(bool unload) { + (void)unload; return true; } diff --git a/src/cdrom/cdrom_image.cc b/src/cdrom/cdrom_image.cc index 6a22a9414..c9dc4670c 100644 --- a/src/cdrom/cdrom_image.cc +++ b/src/cdrom/cdrom_image.cc @@ -57,6 +57,8 @@ void cdrom_image_log(const char *format, ...) va_end(ap); fflush(stdout); } +#else + (void)format; #endif } @@ -211,7 +213,7 @@ static int image_ready(uint8_t id) return 1; } -static int image_get_last_block(uint8_t id, uint8_t starttrack, int msf, int maxlen, int single) +static int image_get_last_block(uint8_t id, UNUSED(uint8_t starttrack), UNUSED(int msf), UNUSED(int maxlen), UNUSED(int single)) { int c; uint32_t lb=0; @@ -321,12 +323,12 @@ static uint8_t image_getcurrentsubchannel(uint8_t id, uint8_t *b, int msf) return ret; } -static void image_eject(uint8_t id) +static void image_eject(UNUSED(uint8_t id)) { return; } -static void image_load(uint8_t id) +static void image_load(UNUSED(uint8_t id)) { return; } @@ -965,7 +967,7 @@ static int image_status(uint8_t id) return CD_STATUS_DATA_ONLY; } -void image_reset(uint8_t id) +void image_reset(UNUSED(uint8_t id)) { return; } @@ -998,7 +1000,7 @@ int image_open(uint8_t id, wchar_t *fn) swprintf(cdrom_image[id].image_path, sizeof(cdrom_image[id].image_path)/sizeof(wchar_t), L"%ls", fn); } - if (! wcscasecmp(get_extension_w(fn), L"ISO")) + if (! wcscasecmp(plat_get_extension(fn), L"ISO")) { cdrom_image[id].image_is_iso = 1; } diff --git a/src/cdrom/cdrom_null.c b/src/cdrom/cdrom_null.c index 28d383100..f0d6c19ea 100644 --- a/src/cdrom/cdrom_null.c +++ b/src/cdrom/cdrom_null.c @@ -9,7 +9,7 @@ * Implementation of the CD-ROM null interface for unmounted * guest CD-ROM drives. * - * Version: @(#)cdrom_null.c 1.0.4 2017/10/09 + * Version: @(#)cdrom_null.c 1.0.5 2017/10/16 * * Authors: Sarah Walker, * Miran Grca, @@ -21,6 +21,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "cdrom.h" diff --git a/src/config.c b/src/config.c index 3ba7b842e..0bd449d5c 100644 --- a/src/config.c +++ b/src/config.c @@ -8,7 +8,7 @@ * * Configuration file handler. * - * Version: @(#)config.c 1.0.21 2017/10/13 + * Version: @(#)config.c 1.0.25 2017/10/21 * * Authors: Sarah Walker, * Miran Grca, @@ -29,6 +29,7 @@ #include #include #include +#include "86box.h" #include "ibm.h" #include "cpu/cpu.h" #include "nvr.h" @@ -102,6 +103,7 @@ typedef struct { wchar_t config_file_default[256]; + static list_t config_head; @@ -326,8 +328,9 @@ config_read(wchar_t *fn) } (void)fclose(f); - - config_dump(); + + if (do_dump_config) + config_dump(); return(1); } @@ -415,23 +418,8 @@ load_general(void) vid_resize = !!config_get_int(cat, "vid_resize", 0); memset(temp, '\0', sizeof(temp)); - p = config_get_string(cat, "vid_renderer", "d3d9"); - if (p != NULL) - strcpy(temp, p); - if (! strcmp(temp, "ddraw")) - vid_api = 0; - else if (! strcmp(temp, "d3d9")) - vid_api = 1; -#ifdef USE_VNC - else if (! strcmp(temp, "vnc")) - vid_api = 2; -#endif -#ifdef USE_RDP - else if (! strcmp(temp, "rdp")) - vid_api = 3; -#endif - else - vid_api = 1; /* default to d3d9 on invalid values */ + p = config_get_string(cat, "vid_renderer", "default"); + vid_api = plat_vidapi(p); config_delete_var(cat, "vid_api"); video_fullscreen_scale = config_get_int(cat, "video_fullscreen_scale", 0); @@ -705,7 +693,10 @@ load_other_peripherals(void) else scsi_card_current = 0; - memset(hdc_name, '\0', sizeof(hdc_name)); + if (hdc_name) { + free(hdc_name); + hdc_name = NULL; + } p = config_get_string(cat, "hdc", NULL); if (p == NULL) { p = config_get_string(cat, "hdd_controller", NULL); @@ -713,12 +704,17 @@ load_other_peripherals(void) config_delete_var(cat, "hdd_controller"); } if (p == NULL) { - if (machines[machine].flags & MACHINE_HAS_HDC) + if (machines[machine].flags & MACHINE_HAS_HDC) { + hdc_name = (char *) malloc((strlen("internal") + 1) * sizeof(char)); strcpy(hdc_name, "internal"); - else + } else { + hdc_name = (char *) malloc((strlen("none") + 1) * sizeof(char)); strcpy(hdc_name, "none"); - } else + } + } else { + hdc_name = (char *) malloc((strlen(p) + 1) * sizeof(char)); strcpy(hdc_name, p); + } config_set_string(cat, "hdc", hdc_name); memset(temp, '\0', sizeof(temp)); @@ -1133,6 +1129,11 @@ config_load(wchar_t *fn) vid_api = 1; enable_sync = 1; joystick_type = 7; + if (hdc_name) { + free(hdc_name); + hdc_name = NULL; + } + hdc_name = (char *) malloc((strlen("none") + 1) * sizeof(char)); strcpy(hdc_name, "none"); serial_enabled[0] = 0; serial_enabled[1] = 0; @@ -1988,58 +1989,3 @@ config_set_wstring(char *head, char *name, wchar_t *val) memcpy(ent->wdata, val, sizeof_w(ent->wdata)); wcstombs(ent->data, ent->wdata, sizeof(ent->data)); } - - -/* FIXME: should be moved elsewhere. --FvK */ -wchar_t * -get_filename_w(wchar_t *s) -{ - int c = wcslen(s) - 1; - - while (c > 0) { - if (s[c] == L'/' || s[c] == L'\\') - return(&s[c+1]); - c--; - } - - return(s); -} - - -/* FIXME: should be moved elsewhere. --FvK */ -void -append_filename_w(wchar_t *dest, wchar_t *s1, wchar_t *s2, int size) -{ - wcscat(dest, s1); - wcscat(dest, s2); -} - - -/* FIXME: should be moved elsewhere. --FvK */ -void -put_backslash_w(wchar_t *s) -{ - int c = wcslen(s) - 1; - - if (s[c] != L'/' && s[c] != L'\\') - s[c] = L'/'; -} - - -/* FIXME: should be moved elsewhere. --FvK */ -wchar_t -*get_extension_w(wchar_t *s) -{ - int c = wcslen(s) - 1; - - if (c <= 0) - return(s); - - while (c && s[c] != L'.') - c--; - - if (!c) - return(&s[wcslen(s)]); - - return(&s[c+1]); -} diff --git a/src/config.h b/src/config.h index bca7591d2..2a6960b87 100644 --- a/src/config.h +++ b/src/config.h @@ -8,7 +8,7 @@ * * Configuration file handler header. * - * Version: @(#)config.h 1.0.3 2017/10/13 + * Version: @(#)config.h 1.0.5 2017/10/18 * * Authors: Sarah Walker, * Miran Grca, @@ -49,12 +49,6 @@ extern void config_set_mac(char *head, char *name, int val); extern void config_set_string(char *head, char *name, char *val); extern void config_set_wstring(char *head, char *name, wchar_t *val); -extern wchar_t *get_filename_w(wchar_t *s); -extern void append_filename_w(wchar_t *dest, wchar_t *s1, wchar_t *s2, int size); -extern void put_backslash_w(wchar_t *s); -extern wchar_t *get_extension_w(wchar_t *s); - - #ifdef __cplusplus } #endif diff --git a/src/cpu/386.c b/src/cpu/386.c index 4bbb87976..abdcf668e 100644 --- a/src/cpu/386.c +++ b/src/cpu/386.c @@ -7,6 +7,7 @@ #ifndef INFINITY # define INFINITY (__builtin_inff()) #endif +#include "../86box.h" #include "../ibm.h" #include "cpu.h" #include "x86.h" diff --git a/src/cpu/386_dynarec.c b/src/cpu/386_dynarec.c index 504a002be..88f97ae7f 100644 --- a/src/cpu/386_dynarec.c +++ b/src/cpu/386_dynarec.c @@ -7,6 +7,7 @@ #ifndef INFINITY # define INFINITY (__builtin_inff()) #endif +#include "../86box.h" #include "../ibm.h" #include "cpu.h" #include "x86.h" diff --git a/src/cpu/386_dynarec_ops.c b/src/cpu/386_dynarec_ops.c index 5e7a6692c..e0f8e345f 100644 --- a/src/cpu/386_dynarec_ops.c +++ b/src/cpu/386_dynarec_ops.c @@ -6,6 +6,7 @@ #ifndef INFINITY # define INFINITY (__builtin_inff()) #endif +#include "../86box.h" #include "../ibm.h" #include "cpu.h" #include "x86.h" diff --git a/src/cpu/808x.c b/src/cpu/808x.c index 3d77f2018..026908c4d 100644 --- a/src/cpu/808x.c +++ b/src/cpu/808x.c @@ -18,7 +18,7 @@ * 2 clocks - fetch opcode 1 2 clocks - execute * 2 clocks - fetch opcode 2 etc * - * Version: @(#)808x.c 1.0.4 2017/10/12 + * Version: @(#)808x.c 1.0.5 2017/10/16 * * Authors: Sarah Walker, * Miran Grca, @@ -30,6 +30,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "cpu.h" #include "x86.h" diff --git a/src/cpu/codegen.c b/src/cpu/codegen.c index e3773089b..b860ee96f 100644 --- a/src/cpu/codegen.c +++ b/src/cpu/codegen.c @@ -2,6 +2,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../mem.h" #include "x86_ops.h" diff --git a/src/cpu/codegen_ops.c b/src/cpu/codegen_ops.c index 309241c0e..b101222a6 100644 --- a/src/cpu/codegen_ops.c +++ b/src/cpu/codegen_ops.c @@ -2,6 +2,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../mem.h" #include "x86.h" diff --git a/src/cpu/codegen_timing_486.c b/src/cpu/codegen_timing_486.c index 56f654313..407dffb1c 100644 --- a/src/cpu/codegen_timing_486.c +++ b/src/cpu/codegen_timing_486.c @@ -2,6 +2,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../mem.h" #include "cpu.h" diff --git a/src/cpu/codegen_timing_686.c b/src/cpu/codegen_timing_686.c index 17ec4ab43..3b58c9a6c 100644 --- a/src/cpu/codegen_timing_686.c +++ b/src/cpu/codegen_timing_686.c @@ -12,6 +12,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../mem.h" #include "cpu.h" diff --git a/src/cpu/codegen_timing_common.c b/src/cpu/codegen_timing_common.c index d02ff2a42..e8a2375f2 100644 --- a/src/cpu/codegen_timing_common.c +++ b/src/cpu/codegen_timing_common.c @@ -2,6 +2,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "codegen_timing_common.h" diff --git a/src/cpu/codegen_timing_pentium.c b/src/cpu/codegen_timing_pentium.c index 95edbe1d6..11676c69d 100644 --- a/src/cpu/codegen_timing_pentium.c +++ b/src/cpu/codegen_timing_pentium.c @@ -13,6 +13,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../mem.h" #include "cpu.h" diff --git a/src/cpu/codegen_timing_winchip.c b/src/cpu/codegen_timing_winchip.c index 06644e90f..0bb47b024 100644 --- a/src/cpu/codegen_timing_winchip.c +++ b/src/cpu/codegen_timing_winchip.c @@ -2,6 +2,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "cpu.h" #include "x86.h" diff --git a/src/cpu/codegen_x86-64.c b/src/cpu/codegen_x86-64.c index ff2e25541..d44cda3d1 100644 --- a/src/cpu/codegen_x86-64.c +++ b/src/cpu/codegen_x86-64.c @@ -5,6 +5,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../mem.h" #include "cpu.h" diff --git a/src/cpu/codegen_x86.c b/src/cpu/codegen_x86.c index fb2ea44d3..a3932e55a 100644 --- a/src/cpu/codegen_x86.c +++ b/src/cpu/codegen_x86.c @@ -5,6 +5,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../mem.h" #include "cpu.h" diff --git a/src/cpu/cpu.c b/src/cpu/cpu.c index 2c2e79773..346373790 100644 --- a/src/cpu/cpu.c +++ b/src/cpu/cpu.c @@ -8,7 +8,7 @@ * * CPU type handler. * - * Version: @(#)cpu.c 1.0.4 2017/10/14 + * Version: @(#)cpu.c 1.0.5 2017/10/16 * * Authors: Sarah Walker, * leilei, @@ -22,6 +22,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "cpu.h" #include "../device.h" diff --git a/src/cpu/x86_ops.h b/src/cpu/x86_ops.h index e0b981807..4435587d4 100644 --- a/src/cpu/x86_ops.h +++ b/src/cpu/x86_ops.h @@ -5,7 +5,7 @@ #define _X86_OPS_H -#define UNUSED(x) (void)(x) +#define UN_USED(x) (void)(x) typedef int (*OpFn)(uint32_t fetchdat); diff --git a/src/cpu/x86_ops_call.h b/src/cpu/x86_ops_call.h index d1f61021c..30e60410c 100644 --- a/src/cpu/x86_ops_call.h +++ b/src/cpu/x86_ops_call.h @@ -61,7 +61,7 @@ static int opCALL_far_w(uint32_t fetchdat) { uint32_t old_cs, old_pc; uint16_t new_cs, new_pc; - int cycles_old = cycles; UNUSED(cycles_old); + int cycles_old = cycles; UN_USED(cycles_old); new_pc = getwordf(); new_cs = getword(); if (cpu_state.abrt) return 1; @@ -77,7 +77,7 @@ static int opCALL_far_l(uint32_t fetchdat) { uint32_t old_cs, old_pc; uint32_t new_cs, new_pc; - int cycles_old = cycles; UNUSED(cycles_old); + int cycles_old = cycles; UN_USED(cycles_old); new_pc = getlong(); new_cs = getword(); if (cpu_state.abrt) return 1; @@ -95,7 +95,7 @@ static int opFF_w_a16(uint32_t fetchdat) { uint16_t old_cs, new_cs; uint32_t old_pc, new_pc; - int cycles_old = cycles; UNUSED(cycles_old); + int cycles_old = cycles; UN_USED(cycles_old); uint16_t temp; @@ -172,7 +172,7 @@ static int opFF_w_a32(uint32_t fetchdat) { uint16_t old_cs, new_cs; uint32_t old_pc, new_pc; - int cycles_old = cycles; UNUSED(cycles_old); + int cycles_old = cycles; UN_USED(cycles_old); uint16_t temp; @@ -250,7 +250,7 @@ static int opFF_l_a16(uint32_t fetchdat) { uint16_t old_cs, new_cs; uint32_t old_pc, new_pc; - int cycles_old = cycles; UNUSED(cycles_old); + int cycles_old = cycles; UN_USED(cycles_old); uint32_t temp; @@ -327,7 +327,7 @@ static int opFF_l_a32(uint32_t fetchdat) { uint16_t old_cs, new_cs; uint32_t old_pc, new_pc; - int cycles_old = cycles; UNUSED(cycles_old); + int cycles_old = cycles; UN_USED(cycles_old); uint32_t temp; diff --git a/src/cpu/x86_ops_int.h b/src/cpu/x86_ops_int.h index 354bcd59b..5aa05fc11 100644 --- a/src/cpu/x86_ops_int.h +++ b/src/cpu/x86_ops_int.h @@ -1,6 +1,6 @@ static int opINT3(uint32_t fetchdat) { - int cycles_old = cycles; UNUSED(cycles_old); + int cycles_old = cycles; UN_USED(cycles_old); if ((cr0 & 1) && (eflags & VM_FLAG) && (IOPL != 3)) { x86gpf(NULL,0); @@ -14,7 +14,7 @@ static int opINT3(uint32_t fetchdat) static int opINT1(uint32_t fetchdat) { - int cycles_old = cycles; UNUSED(cycles_old); + int cycles_old = cycles; UN_USED(cycles_old); if ((cr0 & 1) && (eflags & VM_FLAG) && (IOPL != 3)) { x86gpf(NULL,0); @@ -28,7 +28,7 @@ static int opINT1(uint32_t fetchdat) static int opINT(uint32_t fetchdat) { - int cycles_old = cycles; UNUSED(cycles_old); + int cycles_old = cycles; UN_USED(cycles_old); uint8_t temp = getbytef(); if ((cr0 & 1) && (eflags & VM_FLAG) && (IOPL != 3)) @@ -70,7 +70,7 @@ static int opINT(uint32_t fetchdat) static int opINTO(uint32_t fetchdat) { - int cycles_old = cycles; UNUSED(cycles_old); + int cycles_old = cycles; UN_USED(cycles_old); if ((cr0 & 1) && (eflags & VM_FLAG) && (IOPL != 3)) { diff --git a/src/cpu/x86_ops_ret.h b/src/cpu/x86_ops_ret.h index 72998c0f6..95872588c 100644 --- a/src/cpu/x86_ops_ret.h +++ b/src/cpu/x86_ops_ret.h @@ -44,7 +44,7 @@ static int opRETF_a16(uint32_t fetchdat) { - int cycles_old = cycles; UNUSED(cycles_old); + int cycles_old = cycles; UN_USED(cycles_old); CPU_BLOCK_END(); RETF_a16(0); @@ -55,7 +55,7 @@ static int opRETF_a16(uint32_t fetchdat) } static int opRETF_a32(uint32_t fetchdat) { - int cycles_old = cycles; UNUSED(cycles_old); + int cycles_old = cycles; UN_USED(cycles_old); CPU_BLOCK_END(); RETF_a32(0); @@ -68,7 +68,7 @@ static int opRETF_a32(uint32_t fetchdat) static int opRETF_a16_imm(uint32_t fetchdat) { uint16_t offset = getwordf(); - int cycles_old = cycles; UNUSED(cycles_old); + int cycles_old = cycles; UN_USED(cycles_old); CPU_BLOCK_END(); RETF_a16(offset); @@ -80,7 +80,7 @@ static int opRETF_a16_imm(uint32_t fetchdat) static int opRETF_a32_imm(uint32_t fetchdat) { uint16_t offset = getwordf(); - int cycles_old = cycles; UNUSED(cycles_old); + int cycles_old = cycles; UN_USED(cycles_old); CPU_BLOCK_END(); RETF_a32(offset); @@ -92,7 +92,7 @@ static int opRETF_a32_imm(uint32_t fetchdat) static int opIRET_286(uint32_t fetchdat) { - int cycles_old = cycles; UNUSED(cycles_old); + int cycles_old = cycles; UN_USED(cycles_old); if ((cr0 & 1) && (eflags & VM_FLAG) && (IOPL != 3)) { @@ -137,7 +137,7 @@ static int opIRET_286(uint32_t fetchdat) static int opIRET(uint32_t fetchdat) { - int cycles_old = cycles; UNUSED(cycles_old); + int cycles_old = cycles; UN_USED(cycles_old); if ((cr0 & 1) && (eflags & VM_FLAG) && (IOPL != 3)) { @@ -214,7 +214,7 @@ static int opIRET(uint32_t fetchdat) static int opIRETD(uint32_t fetchdat) { - int cycles_old = cycles; UNUSED(cycles_old); + int cycles_old = cycles; UN_USED(cycles_old); if ((cr0 & 1) && (eflags & VM_FLAG) && (IOPL != 3)) { diff --git a/src/cpu/x86seg.c b/src/cpu/x86seg.c index e365488bc..babc40b1b 100644 --- a/src/cpu/x86seg.c +++ b/src/cpu/x86seg.c @@ -8,7 +8,7 @@ * * x86 CPU segment emulation. * - * Version: @(#)x86seg.c 1.0.3 2017/10/12 + * Version: @(#)x86seg.c 1.0.4 2017/10/16 * * Authors: Sarah Walker, * Miran Grca, @@ -22,6 +22,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../mem.h" #include "../nvr.h" diff --git a/src/cpu/x87.c b/src/cpu/x87.c index 362e288d7..5d95b6fa9 100644 --- a/src/cpu/x87.c +++ b/src/cpu/x87.c @@ -4,6 +4,7 @@ #include #define fplog 0 #include +#include "../86box.h" #include "../ibm.h" #include "../pic.h" #include "x86.h" diff --git a/src/device.c b/src/device.c index ef2904f1a..f3d59d06b 100644 --- a/src/device.c +++ b/src/device.c @@ -9,10 +9,11 @@ * Implementation of the generic device interface to handle * all devices attached to the emulator. * - * Version: @(#)device.c 1.0.4 2017/10/04 + * Version: @(#)device.c 1.0.5 2017/10/16 * * Authors: Sarah Walker, * Miran Grca, + * * Copyright 2008-2016 Sarah Walker. * Copyright 2016,2017 Miran Grca. */ @@ -20,6 +21,7 @@ #include #include #include +#include "86box.h" #include "ibm.h" #include "cpu/cpu.h" #include "config.h" @@ -43,7 +45,7 @@ device_init(void) } -void +void * device_add(device_t *d) { void *priv = NULL; @@ -63,7 +65,9 @@ device_add(device_t *d) } devices[c] = d; - device_priv[c] = priv; + device_priv[c] = priv; + + return priv; } diff --git a/src/device.h b/src/device.h index ae8db2308..0ae2b9d0d 100644 --- a/src/device.h +++ b/src/device.h @@ -98,7 +98,7 @@ extern "C" { #endif extern void device_init(void); -extern void device_add(device_t *d); +extern void *device_add(device_t *d); extern void device_close_all(void); extern void device_reset_all(void); extern void *device_get_priv(device_t *d); diff --git a/src/disk/hdc.c b/src/disk/hdc.c index 39b180599..88521befe 100644 --- a/src/disk/hdc.c +++ b/src/disk/hdc.c @@ -8,10 +8,11 @@ * * Common code to handle all sorts of disk controllers. * - * Version: @(#)hdc.c 1.0.3 2017/10/04 + * Version: @(#)hdc.c 1.0.4 2017/10/16 * * Authors: Miran Grca, * Fred N. van Kempen, + * * Copyright 2016,2017 Miran Grca. * Copyright 2017 Fred N. van Kempen. */ @@ -19,6 +20,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../cpu/cpu.h" #include "../device.h" @@ -26,7 +28,7 @@ #include "hdc.h" -char hdc_name[16]; /* configured HDC name */ +char *hdc_name; /* configured HDC name */ int hdc_current; @@ -71,8 +73,8 @@ static device_t inthdc_device = { static struct { - char name[50]; - char internal_name[16]; + char *name; + char *internal_name; device_t *device; int is_mfm; } controllers[] = { diff --git a/src/disk/hdc.h b/src/disk/hdc.h index 5d0e93657..7a1223a56 100644 --- a/src/disk/hdc.h +++ b/src/disk/hdc.h @@ -27,7 +27,7 @@ * least 7 devices, with each device being * able to support 8 units, but hey... */ -extern char hdc_name[16]; +extern char *hdc_name; extern int hdc_current; diff --git a/src/disk/hdc_esdi_at.c b/src/disk/hdc_esdi_at.c index 91d847c5a..183bc5b16 100644 --- a/src/disk/hdc_esdi_at.c +++ b/src/disk/hdc_esdi_at.c @@ -8,7 +8,7 @@ * * Driver for the ESDI controller (WD1007-vse1) for PC/AT. * - * Version: @(#)hdc_esdi_at.c 1.0.4 2017/10/09 + * Version: @(#)hdc_esdi_at.c 1.0.5 2017/10/16 * * Authors: Sarah Walker, * Miran Grca, @@ -26,6 +26,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../device.h" #include "../io.h" diff --git a/src/disk/hdc_esdi_mca.c b/src/disk/hdc_esdi_mca.c index 19868e488..92df525be 100644 --- a/src/disk/hdc_esdi_mca.c +++ b/src/disk/hdc_esdi_mca.c @@ -52,7 +52,7 @@ * however, are auto-configured by the system software as * shown above. * - * Version: @(#)hdc_esdi_mca.c 1.0.6 2017/10/09 + * Version: @(#)hdc_esdi_mca.c 1.0.7 2017/10/16 * * Authors: Sarah Walker, * Fred N. van Kempen, @@ -65,6 +65,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../device.h" #include "../dma.h" diff --git a/src/disk/hdc_mfm_at.c b/src/disk/hdc_mfm_at.c index 11d77373e..473999dcb 100644 --- a/src/disk/hdc_mfm_at.c +++ b/src/disk/hdc_mfm_at.c @@ -12,7 +12,7 @@ * based design. Most cards were WD1003-WA2 or -WAH, where the * -WA2 cards had a floppy controller as well (to save space.) * - * Version: @(#)hdd_mfm_at.c 1.0.8 2017/10/14 + * Version: @(#)hdd_mfm_at.c 1.0.9 2017/10/16 * * Authors: Sarah Walker, * Fred N. van Kempen, @@ -28,6 +28,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../device.h" #include "../io.h" diff --git a/src/disk/hdc_mfm_xt.c b/src/disk/hdc_mfm_xt.c index 0ff2c652a..7deae868b 100644 --- a/src/disk/hdc_mfm_xt.c +++ b/src/disk/hdc_mfm_xt.c @@ -41,7 +41,7 @@ * Since all controllers (including the ones made by DTC) use * (mostly) the same API, we keep them all in this module. * - * Version: @(#)hdd_mfm_xt.c 1.0.9 2017/10/11 + * Version: @(#)hdd_mfm_xt.c 1.0.10 2017/10/16 * * Authors: Sarah Walker, * Fred N. van Kempen, @@ -57,6 +57,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../device.h" #include "../dma.h" diff --git a/src/disk/hdc_xtide.c b/src/disk/hdc_xtide.c index d3e5789e1..9e81817d0 100644 --- a/src/disk/hdc_xtide.c +++ b/src/disk/hdc_xtide.c @@ -21,7 +21,7 @@ * already on their way out, the newer IDE standard based on the * PC/AT controller and 16b design became the IDE we now know. * - * Version: @(#)hdc_xtide.c 1.0.8 2017/10/09 + * Version: @(#)hdc_xtide.c 1.0.9 2017/10/16 * * Authors: Sarah Walker, * Miran Grca, @@ -36,6 +36,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../io.h" #include "../mem.h" diff --git a/src/disk/hdd.c b/src/disk/hdd.c index 90cb7a140..ade328272 100644 --- a/src/disk/hdd.c +++ b/src/disk/hdd.c @@ -8,7 +8,7 @@ * * Common code to handle all sorts of hard disk images. * - * Version: @(#)hdd.c 1.0.4 2017/10/09 + * Version: @(#)hdd.c 1.0.5 2017/10/16 * * Authors: Miran Grca, * Fred N. van Kempen, @@ -20,6 +20,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../ui.h" #include "hdd.h" diff --git a/src/disk/hdd_image.c b/src/disk/hdd_image.c index 956a6732a..0630cdc3c 100644 --- a/src/disk/hdd_image.c +++ b/src/disk/hdd_image.c @@ -8,7 +8,7 @@ * * Handling of hard disk image files. * - * Version: @(#)hdd_image.c 1.0.5 2017/11/13 + * Version: @(#)hdd_image.c 1.0.6 2017/10/19 * * Authors: Sarah Walker, * Miran Grca, @@ -28,6 +28,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../plat.h" #include "hdd.h" @@ -49,11 +50,13 @@ static char empty_sector[512]; static char *empty_sector_1mb; -int hdd_image_do_log = 0; +#ifdef ENABLE_HDD_LOG +int hdd_image_do_log = ENABLE_HDD_LOG; +#endif void hdd_image_log(const char *format, ...) { -#ifdef ENABLE_HDD_IMAGE_LOG +#ifdef ENABLE_HDD_LOG if (hdd_image_do_log) { va_list ap; diff --git a/src/disk/hdd_table.c b/src/disk/hdd_table.c index bf61beef9..98045f031 100644 --- a/src/disk/hdd_table.c +++ b/src/disk/hdd_table.c @@ -9,7 +9,7 @@ * Implementation of the IDE emulation for hard disks and ATAPI * CD-ROM devices. * - * Version: @(#)hdd_table.c 1.0.3 2017/09/30 + * Version: @(#)hdd_table.c 1.0.4 2017/10/16 * * Authors: Miran Grca, * Fred N. van Kempen, diff --git a/src/dma.c b/src/dma.c index f31bfe475..32efc672e 100644 --- a/src/dma.c +++ b/src/dma.c @@ -8,10 +8,11 @@ * * Implementation of the Intel DMA controllers. * - * Version: @(#)dma.c 1.0.3 2017/09/24 + * Version: @(#)dma.c 1.0.4 2017/10/16 * * Authors: Sarah Walker, * Miran Grca, + * * Copyright 2008-2017 Sarah Walker. * Copyright 2016,2017 Miran Grca. */ @@ -19,6 +20,7 @@ #include #include #include +#include "86box.h" #include "ibm.h" #include "cpu/x86.h" #include "mem.h" diff --git a/src/floppy/fdc.c b/src/floppy/fdc.c index e08d440db..a190126d9 100644 --- a/src/floppy/fdc.c +++ b/src/floppy/fdc.c @@ -9,10 +9,11 @@ * Implementation of the NEC uPD-765 and compatible floppy disk * controller. * - * Version: @(#)fdc.c 1.0.5 2017/10/09 + * Version: @(#)fdc.c 1.0.6 2017/10/16 * * Authors: Sarah Walker, * Miran Grca, + * * Copyright 2008-2017 Sarah Walker. * Copyright 2016,2017 Miran Grca. */ @@ -21,6 +22,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../io.h" #include "../mem.h" @@ -166,7 +168,9 @@ int floppyrate[4]; int floppyint; -int fdc_do_log = 0; +#ifdef ENABLE_FDC_LOG +int fdc_do_log = ENABLE_FDC_LOG; +#endif void fdc_log(const char *format, ...) { diff --git a/src/floppy/fdd.c b/src/floppy/fdd.c index 10a755dc8..d6ea4f0e5 100644 --- a/src/floppy/fdd.c +++ b/src/floppy/fdd.c @@ -8,10 +8,11 @@ * * Implementation of the floppy drive emulation. * - * Version: @(#)fdd.c 1.0.3 2017/09/24 + * Version: @(#)fdd.c 1.0.4 2017/10/16 * * Authors: Sarah Walker, * Miran Grca, + * * Copyright 2008-2017 Sarah Walker. * Copyright 2016,2017 Miran Grca. */ @@ -19,6 +20,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "floppy.h" #include "fdc.h" diff --git a/src/floppy/fdi2raw.c b/src/floppy/fdi2raw.c index 84e2c7388..3b80d888c 100644 --- a/src/floppy/fdi2raw.c +++ b/src/floppy/fdi2raw.c @@ -30,6 +30,7 @@ #include "zfile.h"*/ /* ELSE */ #define xmalloc malloc +#include "../86box.h" #include "../ibm.h" #include "fdi2raw.h" diff --git a/src/floppy/floppy.c b/src/floppy/floppy.c index 809de0a88..9118a85bb 100644 --- a/src/floppy/floppy.c +++ b/src/floppy/floppy.c @@ -9,7 +9,7 @@ * Generic floppy disk interface that communicates with the * other handlers. * - * Version: @(#)floppy.c 1.0.8 2017/10/12 + * Version: @(#)floppy.c 1.0.10 2017/10/16 * * Authors: Sarah Walker, * Miran Grca, @@ -21,6 +21,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../mem.h" #include "../rom.h" @@ -135,7 +136,7 @@ void floppy_load(int drive, wchar_t *fn) wchar_t *p; FILE *f; if (!fn) return; - p = get_extension_w(fn); + p = plat_get_extension(fn); if (!p) return; f = plat_fopen(fn, L"rb"); if (!f) return; diff --git a/src/floppy/floppy_86f.c b/src/floppy/floppy_86f.c index 9328d7d3d..5f122ed4b 100644 --- a/src/floppy/floppy_86f.c +++ b/src/floppy/floppy_86f.c @@ -10,7 +10,7 @@ * data in the form of FM/MFM-encoded transitions) which also * forms the core of the emulator's floppy disk emulation. * - * Version: @(#)floppy_86f.c 1.0.7 2017/10/12 + * Version: @(#)floppy_86f.c 1.0.9 2017/10/19 * * Author: Miran Grca, * Copyright 2016,2017 Miran Grca. @@ -23,6 +23,7 @@ #include #include #include "../lzf/lzf.h" +#include "../86box.h" #include "../ibm.h" #include "../config.h" #include "../dma.h" @@ -112,36 +113,24 @@ enum static uint16_t CRCTable[256]; -#ifdef __MSC__ -# pragma pack(push,1) +#pragma pack(push,1) typedef struct -#else -typedef struct __attribute__((__packed__)) -#endif { uint8_t buffer[10]; uint32_t pos; uint32_t len; } sliding_buffer_t; -#ifdef __MSC__ -# pragma pack(pop) -#endif +#pragma pack(pop) -#ifdef __MSC__ -# pragma pack(push,1) +#pragma pack(push,1) typedef struct -#else -typedef struct __attribute__((__packed__)) -#endif { uint32_t sync_marks; uint32_t bits_obtained; uint32_t bytes_obtained; uint32_t sync_pos; } find_t; -#ifdef __MSC__ -# pragma pack(pop) -#endif +#pragma pack(pop) uint8_t encoded_fm[64] = { 0xAA, 0xAB, 0xAE, 0xAF, 0xBA, 0xBB, 0xBE, 0xBF, 0xEA, 0xEB, 0xEE, 0xEF, 0xFA, 0xFB, 0xFE, 0xFF, 0xAA, 0xAB, 0xAE, 0xAF, 0xBA, 0xBB, 0xBE, 0xBF, 0xEA, 0xEB, 0xEE, 0xEF, 0xFA, 0xFB, 0xFE, 0xFF, @@ -175,19 +164,13 @@ enum FMT_POSTTRK_GAP4 }; -#ifdef __MSC__ -# pragma pack(push,1) +#pragma pack(push,1) typedef struct -#else -typedef struct __attribute__((__packed__)) -#endif { unsigned nibble0 :4; unsigned nibble1 :4; } split_byte_t; -#ifdef __MSC__ -# pragma pack(pop) -#endif +#pragma pack(pop) typedef union { uint8_t byte; @@ -205,12 +188,8 @@ typedef union { Bits 10, 9 Zone type (3 = Commodore 64 zoned, 2 = Apple zoned, 1 = Pre-Apple zoned #2, 0 = Pre-Apple zoned #1) Bit 11 Data and surface bits are stored in reverse byte endianness */ -#ifdef __MSC__ -# pragma pack(push,1) +#pragma pack(push,1) struct -#else -struct __attribute__((__packed__)) -#endif { FILE *f; uint16_t version; @@ -255,11 +234,11 @@ struct __attribute__((__packed__)) int turbo_pos; uint16_t sector_id_bit_field[2][256][256][256]; } d86f[FDD_NUM]; -#ifdef __MSC__ -# pragma pack(pop) -#endif +#pragma pack(pop) -int d86f_do_log = 0; +#ifdef ENABLE_D86F_LOG +int d86f_do_log = ENABLE_D86F_LOG; +#endif void d86f_log(const char *format, ...) { diff --git a/src/floppy/floppy_common.c b/src/floppy/floppy_common.c index 167dc6efb..d6d0b218c 100644 --- a/src/floppy/floppy_common.c +++ b/src/floppy/floppy_common.c @@ -8,7 +8,7 @@ * * Shared code for all the floppy modules. * - * Version: @(#)floppy_common.c 1.0.2 2017/09/24 + * Version: @(#)floppy_common.c 1.0.3 2017/10/16 * * Author: Fred N. van Kempen, * Copyright 2017 Fred N. van Kempen. @@ -18,6 +18,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../floppy/floppy.h" #include "floppy_common.h" diff --git a/src/floppy/floppy_fdi.c b/src/floppy/floppy_fdi.c index 1f65696b5..67c179aa4 100644 --- a/src/floppy/floppy_fdi.c +++ b/src/floppy/floppy_fdi.c @@ -9,7 +9,7 @@ * Implementation of the FDI floppy stream image format * interface to the FDI2RAW module. * - * Version: @(#)floppy_fdi.c 1.0.3 2017/10/12 + * Version: @(#)floppy_fdi.c 1.0.4 2017/10/16 * * Authors: Sarah Walker, * Miran Grca, @@ -21,6 +21,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../plat.h" #include "floppy.h" diff --git a/src/floppy/floppy_imd.c b/src/floppy/floppy_imd.c index f5de9700d..e109ec057 100644 --- a/src/floppy/floppy_imd.c +++ b/src/floppy/floppy_imd.c @@ -8,7 +8,7 @@ * * Implementation of the IMD floppy image format. * - * Version: @(#)floppy_imd.c 1.0.3 2017/10/12 + * Version: @(#)floppy_imd.c 1.0.4 2017/10/16 * * Author: Miran Grca, * Copyright 2016,2017 Miran Grca. @@ -18,6 +18,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../plat.h" #include "floppy.h" diff --git a/src/floppy/floppy_img.c b/src/floppy/floppy_img.c index 20f712981..9c5e4d9c1 100644 --- a/src/floppy/floppy_img.c +++ b/src/floppy/floppy_img.c @@ -9,7 +9,7 @@ * Implementation of the raw sector-based floppy image format, * as well as the Japanese FDI, CopyQM, and FDF formats. * - * Version: @(#)floppy_img.c 1.0.3 2017/10/12 + * Version: @(#)floppy_img.c 1.0.5 2017/10/16 * * Authors: Sarah Walker, * Miran Grca, @@ -22,6 +22,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../config.h" #include "../plat.h" @@ -346,7 +347,7 @@ void img_load(int drive, wchar_t *fn) uint8_t *literal; int guess = 0; - ext = get_extension_w(fn); + ext = plat_get_extension(fn); d86f_unregister(drive); diff --git a/src/floppy/floppy_json.c b/src/floppy/floppy_json.c index 495269799..c4822f095 100644 --- a/src/floppy/floppy_json.c +++ b/src/floppy/floppy_json.c @@ -8,7 +8,7 @@ * * Implementation of the PCjs JSON floppy image format. * - * Version: @(#)floppy_json.c 1.0.7 2017/10/14 + * Version: @(#)floppy_json.c 1.0.8 2017/10/16 * * Author: Fred N. van Kempen, * @@ -19,6 +19,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../plat.h" #include "floppy.h" diff --git a/src/floppy/floppy_td0.c b/src/floppy/floppy_td0.c index 0d16e3250..97e5e45a2 100644 --- a/src/floppy/floppy_td0.c +++ b/src/floppy/floppy_td0.c @@ -8,7 +8,7 @@ * * Implementation of the Teledisk floppy image format. * - * Version: @(#)floppy_td0.c 1.0.4 2017/10/12 + * Version: @(#)floppy_td0.c 1.0.5 2017/10/16 * * Authors: Milodrag Milanovic, * Haruhiko OKUMURA, @@ -42,6 +42,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../plat.h" #include "floppy.h" diff --git a/src/game/gameport.c b/src/game/gameport.c index 7410abdd9..9756facb8 100644 --- a/src/game/gameport.c +++ b/src/game/gameport.c @@ -6,6 +6,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../cpu/cpu.h" #include "../device.h" diff --git a/src/game/joystick_ch_flightstick_pro.c b/src/game/joystick_ch_flightstick_pro.c index ffec5e7bf..fe9917059 100644 --- a/src/game/joystick_ch_flightstick_pro.c +++ b/src/game/joystick_ch_flightstick_pro.c @@ -3,6 +3,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../device.h" #include "../timer.h" diff --git a/src/game/joystick_standard.c b/src/game/joystick_standard.c index 329355d0e..9eb632410 100644 --- a/src/game/joystick_standard.c +++ b/src/game/joystick_standard.c @@ -3,6 +3,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../device.h" #include "../timer.h" diff --git a/src/game/joystick_sw_pad.c b/src/game/joystick_sw_pad.c index f127d2f49..6713ffa63 100644 --- a/src/game/joystick_sw_pad.c +++ b/src/game/joystick_sw_pad.c @@ -24,6 +24,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../device.h" #include "../timer.h" diff --git a/src/game/joystick_tm_fcs.c b/src/game/joystick_tm_fcs.c index 2fcbe4920..13b3a38a5 100644 --- a/src/game/joystick_tm_fcs.c +++ b/src/game/joystick_tm_fcs.c @@ -3,6 +3,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../device.h" #include "../timer.h" diff --git a/src/ibm.h b/src/ibm.h index 288224314..2c7a2a9f7 100644 --- a/src/ibm.h +++ b/src/ibm.h @@ -10,7 +10,7 @@ * * !!!NOTE!!! The goal is to GET RID of this file. Do NOT add stuff !! * - * Version: @(#)ibm.h 1.0.9 2017/10/15 + * Version: @(#)ibm.h 1.0.10 2017/10/16 * * Authors: Sarah Walker, * Miran Grca, @@ -285,6 +285,7 @@ extern int CPUID; extern int cpl_override; + /*Timer*/ typedef struct PIT_nr { @@ -382,9 +383,8 @@ extern int driveempty[4]; #define MDA ((gfxcard==GFX_MDA || gfxcard==GFX_HERCULES || gfxcard==GFX_HERCULESPLUS || gfxcard==GFX_INCOLOR || gfxcard==GFX_GENIUS) && (romset=ROM_IBMAT)) #define VGA ((gfxcard>=GFX_TVGA) && gfxcard!=GFX_COLORPLUS && gfxcard!=GFX_INCOLOR && gfxcard!=GFX_WY700 && gfxcard!=GFX_GENIUS && gfxcard!=GFX_COMPAQ_EGA && gfxcard!=GFX_SUPER_EGA && gfxcard!=GFX_HERCULESPLUS && romset!=ROM_PC1640 && romset!=ROM_PC1512 && romset!=ROM_TANDY && romset!=ROM_PC200) -int GAMEBLASTER, GUS, SSI2001, voodoo_enabled, buslogic_enabled; +int GAMEBLASTER, GUS, SSI2001, voodoo_enabled; extern int AMSTRAD, AT, is286, is386, PCI, TANDY; - extern int hasfpu; enum @@ -462,9 +462,6 @@ int cpuspeed; /*Video*/ extern int egareads,egawrites; -extern int vid_resize; -extern int vid_api; -extern int winsizex,winsizey; extern int changeframecount; @@ -491,9 +488,6 @@ extern int gated,speakval,speakon; #define SND_WSS 9 /*Windows Sound System*/ #define SND_PAS16 10 /*Pro Audio Spectrum 16*/ -extern wchar_t exe_path[1024]; -extern wchar_t cfg_path[1024]; - /*Keyboard*/ extern int64_t keybsenddelay; @@ -531,18 +525,6 @@ extern int nmi_auto_clear; extern float isa_timing, bus_timing; - -extern uint64_t timer_read(void); -extern uint64_t timer_freq; - - -extern int infocus; - - -extern int dump_on_exit; -extern int start_in_fullscreen; -extern int window_w, window_h, window_x, window_y, window_remember; - extern uint64_t pmc[2]; extern uint16_t temp_seg_data[4]; @@ -560,18 +542,6 @@ extern uint64_t star; extern int mem_a20_state; -#ifdef ENABLE_LOG_TOGGLES -extern int buslogic_do_log; -extern int cdrom_do_log; -extern int d86f_do_log; -extern int fdc_do_log; -extern int ide_do_log; -extern int serial_do_log; -extern int nic_do_log; -#endif - -extern int suppress_overscan; - typedef struct PCI_RESET { void (*pci_master_reset)(void); @@ -589,35 +559,14 @@ extern int serial_enabled[2]; extern int lpt_enabled, bugger_enabled; extern int romset; -extern int invert_display; - uint32_t svga_color_transform(uint32_t color); -extern int scale; - /* Function prototypes. */ #ifdef __cplusplus extern "C" { #endif -extern void pclog(const char *format, ...); -extern void fatal(const char *format, ...); -extern wchar_t *pc_concat(wchar_t *str); -extern int pc_init_modules(void); -extern int pc_init(int argc, wchar_t *argv[]); -extern void pc_close(void); -extern void pc_reset_hard_close(void); -extern void pc_reset_hard_init(void); -extern void pc_reset_hard(void); -extern void pc_full_speed(void); -extern void pc_speed_changed(void); -extern void pc_send_cad(void); -extern void pc_send_cae(void); -extern void pc_run(void); -extern void onesec(void); - - extern int checkio(int port); extern void codegen_block_end(void); extern void codegen_reset(void); @@ -657,9 +606,4 @@ extern void x87_reset(void); #endif -/* Configuration values. */ -#define SERIAL_MAX 2 -#define PARALLEL_MAX 1 - - #endif /*EMU_IBM_H*/ diff --git a/src/intel_flash.c b/src/intel_flash.c index 7da82f2ac..7ad1268b2 100644 --- a/src/intel_flash.c +++ b/src/intel_flash.c @@ -8,7 +8,7 @@ * * Implementation of the Intel 2 Mbit 8-bit flash devices. * - * Version: @(#)intel_flash.c 1.0.8 2017/10/14 + * Version: @(#)intel_flash.c 1.0.9 2017/10/16 * * Authors: Sarah Walker, * Miran Grca, @@ -21,6 +21,7 @@ #include #include #include +#include "86box.h" #include "ibm.h" #include "cpu/cpu.h" #include "device.h" diff --git a/src/io.c b/src/io.c index 6983b47ad..5b6d04926 100644 --- a/src/io.c +++ b/src/io.c @@ -5,6 +5,7 @@ #include #include #include +#include "86box.h" #include "ibm.h" #include "io.h" diff --git a/src/keyboard.c b/src/keyboard.c index 8a4bbdf5b..716b0c015 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -8,7 +8,7 @@ * * Host to guest keyboard interface and keyboard scan code sets. * - * Version: @(#)keyboard.c 1.0.4 2017/10/10 + * Version: @(#)keyboard.c 1.0.5 2017/10/16 * * Authors: Sarah Walker, * Miran Grca, @@ -20,6 +20,7 @@ #include #include #include +#include "86box.h" #include "ibm.h" #include "plat_keyboard.h" #include "keyboard.h" diff --git a/src/keyboard_amstrad.c b/src/keyboard_amstrad.c index 6ebbaa0f3..022ecb4a1 100644 --- a/src/keyboard_amstrad.c +++ b/src/keyboard_amstrad.c @@ -5,6 +5,7 @@ #include #include #include +#include "86box.h" #include "ibm.h" #include "io.h" #include "mem.h" diff --git a/src/keyboard_at.c b/src/keyboard_at.c index 2b98f21f6..95192ea08 100644 --- a/src/keyboard_at.c +++ b/src/keyboard_at.c @@ -8,17 +8,21 @@ * * Intel 8042 (AT keyboard controller) emulation. * - * Version: @(#)keyboard_at.c 1.0.3 2017/09/24 + * Version: @(#)keyboard_at.c 1.0.5 2017/10/19 * * Authors: Sarah Walker, * Miran Grca, + * * Copyright 2008-2017 Sarah Walker. * Copyright 2016,2017 Miran Grca. */ #include #include +#include #include +#include #include +#include "86box.h" #include "ibm.h" #include "io.h" #include "pic.h" @@ -127,7 +131,9 @@ static uint8_t nont_to_t[256] = { 0xFF, 0x43, 0x41, 0x3F, 0x3D, 0x3B, 0x3C, 0x58 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF, 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF }; -int keyboard_at_do_log = 0; +#ifdef ENABLE_KEYBOARD_AT_LOG +int keyboard_at_do_log = ENABLE_KEYBOARD_AT_LOG; +#endif void keyboard_at_log(const char *format, ...) { diff --git a/src/keyboard_olim24.c b/src/keyboard_olim24.c index 371a104c3..9bd139087 100644 --- a/src/keyboard_olim24.c +++ b/src/keyboard_olim24.c @@ -3,6 +3,7 @@ #include #include #include +#include "86box.h" #include "ibm.h" #include "io.h" #include "mem.h" diff --git a/src/keyboard_pcjr.c b/src/keyboard_pcjr.c index ccd9986f2..87e3fc0b6 100644 --- a/src/keyboard_pcjr.c +++ b/src/keyboard_pcjr.c @@ -5,6 +5,7 @@ #include #include #include +#include "86box.h" #include "ibm.h" #include "io.h" #include "mem.h" diff --git a/src/keyboard_xt.c b/src/keyboard_xt.c index 3e93125c9..d413575b7 100644 --- a/src/keyboard_xt.c +++ b/src/keyboard_xt.c @@ -5,6 +5,7 @@ #include #include #include +#include "86box.h" #include "ibm.h" #include "io.h" #include "mem.h" diff --git a/src/machine/machine.c b/src/machine/machine.c index d164499dc..af328bed7 100644 --- a/src/machine/machine.c +++ b/src/machine/machine.c @@ -8,7 +8,7 @@ * * Handling of the emulated machines. * - * Version: @(#)machine.c 1.0.19 2017/10/12 + * Version: @(#)machine.c 1.0.20 2017/10/16 * * Authors: Sarah Walker, * Miran Grca, @@ -22,6 +22,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../cpu/cpu.h" #include "../mem.h" diff --git a/src/machine/machine_amstrad.c b/src/machine/machine_amstrad.c index d2eb674cf..ca63131c8 100644 --- a/src/machine/machine_amstrad.c +++ b/src/machine/machine_amstrad.c @@ -3,6 +3,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../io.h" #include "../nmi.h" diff --git a/src/machine/machine_at.c b/src/machine/machine_at.c index 0c6faab0c..71cde9e1b 100644 --- a/src/machine/machine_at.c +++ b/src/machine/machine_at.c @@ -2,6 +2,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../pic.h" #include "../pit.h" diff --git a/src/machine/machine_at_430fx.c b/src/machine/machine_at_430fx.c index e50ad18cf..030ed2099 100644 --- a/src/machine/machine_at_430fx.c +++ b/src/machine/machine_at_430fx.c @@ -8,7 +8,7 @@ * * Implementation of the Intel 430FX PCISet chip. * - * Version: @(#)machine_at_430fx.c 1.0.6 2017/10/07 + * Version: @(#)machine_at_430fx.c 1.0.7 2017/10/16 * * Authors: Sarah Walker, * Miran Grca, @@ -20,6 +20,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../mem.h" #include "../memregs.h" @@ -132,6 +133,10 @@ static void i430fx_write(int func, int addr, uint8_t val, void *priv) i430fx_map(0xec000, 0x04000, val >> 4); pclog("i430fx_write : PAM6 write %02X\n", val); break; + case 0x72: /*SMRAM*/ + if ((card_i430fx[0x72] ^ val) & 0x48) + i430fx_map(0xa0000, 0x20000, ((val & 0x48) == 0x48) ? 3 : 0); + break; } card_i430fx[addr] = val; @@ -184,6 +189,7 @@ static void i430fx_reset(void) static void i430fx_pci_reset(void) { i430fx_write(0, 0x59, 0x00, NULL); + i430fx_write(0, 0x72, 0x02, NULL); } diff --git a/src/machine/machine_at_430hx.c b/src/machine/machine_at_430hx.c index ca110dd60..cc42157f0 100644 --- a/src/machine/machine_at_430hx.c +++ b/src/machine/machine_at_430hx.c @@ -8,7 +8,7 @@ * * Implementation of the Intel 430HX PCISet chip. * - * Version: @(#)machine_at_430hx.c 1.0.6 2017/10/07 + * Version: @(#)machine_at_430hx.c 1.0.7 2017/10/16 * * Authors: Sarah Walker, * Miran Grca, @@ -20,6 +20,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../io.h" #include "../mem.h" @@ -130,6 +131,10 @@ static void i430hx_write(int func, int addr, uint8_t val, void *priv) if ((card_i430hx[0x5f] ^ val) & 0xf0) i430hx_map(0xec000, 0x04000, val >> 4); break; + case 0x72: /*SMRAM*/ + if ((card_i430hx[0x72] ^ val) & 0x48) + i430hx_map(0xa0000, 0x20000, ((val & 0x48) == 0x48) ? 3 : 0); + break; } card_i430hx[addr] = val; @@ -171,6 +176,7 @@ static void i430hx_reset(void) static void i430hx_pci_reset(void) { i430hx_write(0, 0x59, 0x00, NULL); + i430hx_write(0, 0x72, 0x02, NULL); } diff --git a/src/machine/machine_at_430lx_nx.c b/src/machine/machine_at_430lx_nx.c index 2f7530435..48e111f97 100644 --- a/src/machine/machine_at_430lx_nx.c +++ b/src/machine/machine_at_430lx_nx.c @@ -8,7 +8,7 @@ * * Implementation of the Intel 430LX and 430NX PCISet chips. * - * Version: @(#)machine_at_430lx_nx.c 1.0.6 2017/10/07 + * Version: @(#)machine_at_430lx_nx.c 1.0.7 2017/10/16 * * Authors: Sarah Walker, * Miran Grca, @@ -20,6 +20,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../mem.h" #include "../memregs.h" diff --git a/src/machine/machine_at_430vx.c b/src/machine/machine_at_430vx.c index 54171e2a4..aa670538d 100644 --- a/src/machine/machine_at_430vx.c +++ b/src/machine/machine_at_430vx.c @@ -8,7 +8,7 @@ * * Implementation of the Intel 430VX PCISet chip. * - * Version: @(#)machine_at_430vx.c 1.0.7 2017/10/07 + * Version: @(#)machine_at_430vx.c 1.0.8 2017/10/16 * * Authors: Sarah Walker, * Miran Grca, @@ -20,6 +20,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../io.h" #include "../pci.h" @@ -133,6 +134,10 @@ static void i430vx_write(int func, int addr, uint8_t val, void *priv) i430vx_map(0xec000, 0x04000, val >> 4); /* pclog("i430vx_write : PAM6 write %02X\n", val); */ break; + case 0x72: /*SMRAM*/ + if ((card_i430vx[0x72] ^ val) & 0x48) + i430vx_map(0xa0000, 0x20000, ((val & 0x48) == 0x48) ? 3 : 0); + break; } card_i430vx[addr] = val; @@ -174,6 +179,7 @@ static void i430vx_reset(void) static void i430vx_pci_reset(void) { i430vx_write(0, 0x59, 0x00, NULL); + i430vx_write(0, 0x72, 0x02, NULL); } diff --git a/src/machine/machine_at_440fx.c b/src/machine/machine_at_440fx.c index fcb579111..ce48b200d 100644 --- a/src/machine/machine_at_440fx.c +++ b/src/machine/machine_at_440fx.c @@ -8,7 +8,7 @@ * * Implementation of the Intel 440FX PCISet chip. * - * Version: @(#)machine_at_440fx.c 1.0.6 2017/10/07 + * Version: @(#)machine_at_440fx.c 1.0.7 2017/10/16 * * Authors: Sarah Walker, * Miran Grca, @@ -20,6 +20,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../io.h" #include "../pci.h" @@ -130,6 +131,10 @@ static void i440fx_write(int func, int addr, uint8_t val, void *priv) if ((card_i440fx[0x5f] ^ val) & 0xf0) i440fx_map(0xec000, 0x04000, val >> 4); break; + case 0x72: /*SMRAM*/ + if ((card_i440fx[0x72] ^ val) & 0x48) + i440fx_map(0xa0000, 0x20000, ((val & 0x48) == 0x48) ? 3 : 0); + break; } card_i440fx[addr] = val; @@ -175,6 +180,7 @@ static void i440fx_reset(void) static void i440fx_pci_reset(void) { i440fx_write(0, 0x59, 0x00, NULL); + i440fx_write(0, 0x72, 0x02, NULL); } diff --git a/src/machine/machine_at_ali1429.c b/src/machine/machine_at_ali1429.c index 36c689419..baaf1ad3e 100644 --- a/src/machine/machine_at_ali1429.c +++ b/src/machine/machine_at_ali1429.c @@ -5,6 +5,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../cpu/cpu.h" #include "../io.h" diff --git a/src/machine/machine_at_commodore.c b/src/machine/machine_at_commodore.c index 05bcbad86..820ba1cda 100644 --- a/src/machine/machine_at_commodore.c +++ b/src/machine/machine_at_commodore.c @@ -2,6 +2,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../io.h" #include "../lpt.h" diff --git a/src/machine/machine_at_compaq.c b/src/machine/machine_at_compaq.c index 9ed973abb..17ef88467 100644 --- a/src/machine/machine_at_compaq.c +++ b/src/machine/machine_at_compaq.c @@ -5,6 +5,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../cpu/cpu.h" #include "../mem.h" diff --git a/src/machine/machine_at_headland.c b/src/machine/machine_at_headland.c index 74778e83f..4ab6e711e 100644 --- a/src/machine/machine_at_headland.c +++ b/src/machine/machine_at_headland.c @@ -5,6 +5,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../cpu/cpu.h" #include "../io.h" diff --git a/src/machine/machine_at_neat.c b/src/machine/machine_at_neat.c index d43872a16..4c46015cb 100644 --- a/src/machine/machine_at_neat.c +++ b/src/machine/machine_at_neat.c @@ -6,6 +6,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../io.h" #include "machine.h" diff --git a/src/machine/machine_at_opti495.c b/src/machine/machine_at_opti495.c index 7570c7922..54ac72178 100644 --- a/src/machine/machine_at_opti495.c +++ b/src/machine/machine_at_opti495.c @@ -255,6 +255,7 @@ SeeAlso: #P0178,#P0187 #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../cpu/cpu.h" #include "../io.h" diff --git a/src/machine/machine_at_scat.c b/src/machine/machine_at_scat.c index 26ecdb6d5..17f4797c6 100644 --- a/src/machine/machine_at_scat.c +++ b/src/machine/machine_at_scat.c @@ -10,7 +10,7 @@ * * Re-worked version based on the 82C235 datasheet and errata. * - * Version: @(#)at_scat.c 1.0.2 2017/10/07 + * Version: @(#)at_scat.c 1.0.4 2017/10/18 * * Authors: Original by GreatPsycho for PCem. * Fred N. van Kempen, @@ -21,6 +21,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../cpu/cpu.h" #include "../cpu/x86.h" @@ -29,7 +30,7 @@ #include "machine.h" -#define SCAT_DEBUG 2 +#define SCAT_DEBUG 1 #define SCAT_DMA_WS_CTL 0x01 #define SCAT_VERSION 0x40 @@ -176,12 +177,10 @@ set_xms_bound(uint8_t val) 0x160000 - scat_xms_bound, MEM_READ_EXTERNAL | MEM_WRITE_EXTERNAL); } else { -#if 0 for (i=0; i<6; i++) mem_mapping_disable(&scat_shadowram_mapping[i]); if (mem_size > 1024) mem_mapping_enable(&ram_high_mapping); -#endif if (scat_xms_bound > max_xms) scat_xms_bound = max_xms; @@ -279,10 +278,8 @@ ems_state(int state) } else { mem_mapping_set_exec(&scat_mapping[i], ram+base_addr); mem_mapping_disable(&scat_mapping[i]); -#if 0 if (i < 24) mem_mapping_enable(&scat_top_mapping[i]); -#endif } } } @@ -490,7 +487,6 @@ ics_write(uint8_t idx, uint8_t val) break; case SCAT_EMS_CTL: -pclog("SCAT: EMSctrl(%02x)\n", val); if (val & 0x40) { if (val & 1) { io_sethandler(0x0218, 3, @@ -526,24 +522,18 @@ pclog("SCAT: EMSctrl(%02x)\n", val); case SCAT_DRAM_CONFIG: if ((scat_regs[SCAT_EXT_BOUNDARY] & 0x40) == 0) { -pclog("SCAT: 0\n"); if ((val & 0x0f) == 3) { -pclog("SCAT: 3\n"); if (mem_size > 1024) mem_mapping_disable(&ram_high_mapping); for (idx=0; idx<6; idx++) mem_mapping_enable(&scat_shadowram_mapping[idx]); } else { -pclog("SCAT: 0\n"); for (idx=0; idx<6; idx++) mem_mapping_disable(&scat_shadowram_mapping[idx]); -#if 0 if (mem_size > 1024) mem_mapping_enable(&ram_high_mapping); -#endif } } else { -pclog("SCAT: 1\n"); for (idx=0; idx<6; idx++) mem_mapping_disable(&scat_shadowram_mapping[idx]); if (mem_size > 1024) @@ -687,8 +677,6 @@ scat_init(void) */ pclog("SCAT: mem_size=%d\n", mem_size); - -#if 0 /* Create the 32 EMS page frame mappings for 256-640K. */ for (i=0; i<24; i++) { mem_mapping_add(&scat_top_mapping[i], @@ -697,12 +685,9 @@ scat_init(void) ems_pgwr, NULL, NULL, mem_size > 256+(i<<4) ? ram+0x40000+(i<<14) : NULL, MEM_MAPPING_INTERNAL, NULL); -// mem_mapping_enable(&scat_top_mapping[i]); - mem_mapping_disable(&scat_top_mapping[i]); + mem_mapping_enable(&scat_top_mapping[i]); } -#endif -#if 0 /* Re-map the 128K at A0000 (video BIOS) to above 16MB+top. */ mem_mapping_add(&scat_A000_mapping, 0xA0000, 0x20000, @@ -711,9 +696,7 @@ scat_init(void) ram+0xA0000, MEM_MAPPING_INTERNAL, NULL); mem_mapping_disable(&scat_A000_mapping); -#endif -#if 0 /* Create 32 page frames for EMS, each 16K. */ for (i=0; i<32; i++) { scat_ems[i].regs_2x8 = 0xff; @@ -726,9 +709,8 @@ scat_init(void) 0, &scat_ems[i]); mem_mapping_disable(&scat_mapping[i]); } -#endif -// for (i=4; i<10; i++) isram[i] = 0; + for (i=4; i<10; i++) isram[i] = 0; /* Re-map the BIOS ROM (C0000-FFFFF) area. */ for (i=12; i<16; i++) { @@ -740,7 +722,6 @@ scat_init(void) 0, NULL); } -#if 0 for (i=0; i<6; i++) { mem_mapping_add(&scat_shadowram_mapping[i], 0x100000 + (i<<16), 0x10000, @@ -749,7 +730,6 @@ scat_init(void) mem_size >= 1024 ? ram+get_addr(0x100000+(i<<16), NULL) : NULL, MEM_MAPPING_INTERNAL, NULL); } -#endif set_xms_bound(0); shadow_state_update(); diff --git a/src/machine/machine_at_sis_85c471.c b/src/machine/machine_at_sis_85c471.c index 68b9b5ab1..6e80fad31 100644 --- a/src/machine/machine_at_sis_85c471.c +++ b/src/machine/machine_at_sis_85c471.c @@ -9,7 +9,7 @@ * SiS sis85c471 Super I/O Chip * Used by DTK PKM-0038S E-2 * - * Version: @(#)sis85c471.c 1.0.6 2017/10/07 + * Version: @(#)sis85c471.c 1.0.7 2017/10/16 * * Author: Miran Grca, * @@ -19,6 +19,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../io.h" #include "../memregs.h" diff --git a/src/machine/machine_at_sis_85c496.c b/src/machine/machine_at_sis_85c496.c index 77a9c3580..287ef129e 100644 --- a/src/machine/machine_at_sis_85c496.c +++ b/src/machine/machine_at_sis_85c496.c @@ -6,6 +6,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../cpu/cpu.h" #include "../io.h" diff --git a/src/machine/machine_at_sis_85c50x.c b/src/machine/machine_at_sis_85c50x.c index c6aa5dfb6..23607f74a 100644 --- a/src/machine/machine_at_sis_85c50x.c +++ b/src/machine/machine_at_sis_85c50x.c @@ -6,7 +6,7 @@ * * Emulation of the SiS 50x PCI chips. * - * Version: @(#)machine_at_sis_85c50x.c 1.0.3 2017/10/07 + * Version: @(#)machine_at_sis_85c50x.c 1.0.4 2017/10/16 * * Author: Miran Grca, * @@ -17,6 +17,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../io.h" #include "../pci.h" diff --git a/src/machine/machine_at_wd76c10.c b/src/machine/machine_at_wd76c10.c index acdb47245..ca7efd07a 100644 --- a/src/machine/machine_at_wd76c10.c +++ b/src/machine/machine_at_wd76c10.c @@ -5,6 +5,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../io.h" #include "../mem.h" diff --git a/src/machine/machine_common.c b/src/machine/machine_common.c index bf22dca68..5a3ca1d1d 100644 --- a/src/machine/machine_common.c +++ b/src/machine/machine_common.c @@ -2,6 +2,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../dma.h" #include "../pic.h" diff --git a/src/machine/machine_europc.c b/src/machine/machine_europc.c index 9328293a3..ecc9c80bc 100644 --- a/src/machine/machine_europc.c +++ b/src/machine/machine_europc.c @@ -5,6 +5,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../io.h" #include "../nmi.h" diff --git a/src/machine/machine_olivetti_m24.c b/src/machine/machine_olivetti_m24.c index 36ca77f1f..52a5cc48f 100644 --- a/src/machine/machine_olivetti_m24.c +++ b/src/machine/machine_olivetti_m24.c @@ -5,6 +5,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../io.h" #include "../nmi.h" diff --git a/src/machine/machine_pcjr.c b/src/machine/machine_pcjr.c index aace2715e..f719fa325 100644 --- a/src/machine/machine_pcjr.c +++ b/src/machine/machine_pcjr.c @@ -2,6 +2,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../nmi.h" #include "../pic.h" diff --git a/src/machine/machine_ps1.c b/src/machine/machine_ps1.c index 3e2be3012..de10cd709 100644 --- a/src/machine/machine_ps1.c +++ b/src/machine/machine_ps1.c @@ -5,6 +5,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../cpu/cpu.h" #include "../io.h" diff --git a/src/machine/machine_ps2_isa.c b/src/machine/machine_ps2_isa.c index c3b71007a..97ba57477 100644 --- a/src/machine/machine_ps2_isa.c +++ b/src/machine/machine_ps2_isa.c @@ -2,6 +2,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../cpu/cpu.h" #include "../io.h" diff --git a/src/machine/machine_ps2_mca.c b/src/machine/machine_ps2_mca.c index c4ddc4ec9..6c7a6d75c 100644 --- a/src/machine/machine_ps2_mca.c +++ b/src/machine/machine_ps2_mca.c @@ -2,6 +2,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../cpu/cpu.h" #include "../cpu/x86.h" diff --git a/src/machine/machine_tandy.c b/src/machine/machine_tandy.c index 0698ad6f9..1565a80a5 100644 --- a/src/machine/machine_tandy.c +++ b/src/machine/machine_tandy.c @@ -2,6 +2,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../nmi.h" #include "../mem.h" diff --git a/src/machine/machine_xt.c b/src/machine/machine_xt.c index 183482fd5..2954390e1 100644 --- a/src/machine/machine_xt.c +++ b/src/machine/machine_xt.c @@ -2,6 +2,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../nmi.h" #include "../pit.h" diff --git a/src/machine/machine_xt_laserxt.c b/src/machine/machine_xt_laserxt.c index 6cbadf648..04b89709b 100644 --- a/src/machine/machine_xt_laserxt.c +++ b/src/machine/machine_xt_laserxt.c @@ -3,6 +3,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../cpu/cpu.h" #include "../io.h" diff --git a/src/mcr.c b/src/mcr.c index bdde8e27e..9f753639f 100644 --- a/src/mcr.c +++ b/src/mcr.c @@ -5,6 +5,7 @@ #include #include #include +#include "86box.h" #include "ibm.h" diff --git a/src/mem.c b/src/mem.c index b21f9939d..db519d6fa 100644 --- a/src/mem.c +++ b/src/mem.c @@ -6,6 +6,7 @@ #include #include #include +#include "86box.h" #include "ibm.h" #include "cpu/cpu.h" #include "cpu/x86_ops.h" diff --git a/src/memregs.c b/src/memregs.c index 018f07d84..103ab3582 100644 --- a/src/memregs.c +++ b/src/memregs.c @@ -9,7 +9,7 @@ * Emulation of the memory I/O scratch registers on ports 0xE1 * and 0xE2, used by just about any emulated machine. * - * Version: @(#)memregs.c 1.0.2 2017/09/24 + * Version: @(#)memregs.c 1.0.3 2017/10/16 * * Author: Miran Grca, * Copyright 2016-2017 Miran Grca. @@ -18,6 +18,7 @@ #include #include #include +#include "86box.h" #include "ibm.h" #include "io.h" #include "memregs.h" diff --git a/src/mouse.c b/src/mouse.c index 567fba71a..aee1dca46 100644 --- a/src/mouse.c +++ b/src/mouse.c @@ -8,7 +8,7 @@ * * Common driver module for MOUSE devices. * - * Version: @(#)mouse.c 1.0.9 2017/10/09 + * Version: @(#)mouse.c 1.0.10 2017/10/17 * * Authors: Sarah Walker, * Miran Grca, @@ -26,6 +26,7 @@ #include "device.h" #include "mouse.h" #include "machine/machine.h" +#include "plat_mouse.h" static mouse_t mouse_none = { @@ -81,6 +82,24 @@ mouse_emu_close(void) } +void +mouse_process(void) +{ + static int poll_delay = 2; + int x, y, z; + + if (--poll_delay) return; + + mouse_poll_host(); + + mouse_get_mickeys(&x, &y, &z); + + mouse_poll(x, y, z, mouse_buttons); + + poll_delay = 2; +} + + void mouse_poll(int x, int y, int z, int b) { diff --git a/src/mouse_bus.c b/src/mouse_bus.c index fa2225685..2b37aec0e 100644 --- a/src/mouse_bus.c +++ b/src/mouse_bus.c @@ -32,10 +32,11 @@ * Based on an early driver for MINIX 1.5. * Based on the 86Box PS/2 mouse driver as a framework. * - * Version: @(#)mouse_bus.c 1.0.9 2017/09/24 + * Version: @(#)mouse_bus.c 1.0.10 2017/10/16 * * Authors: Fred N. van Kempen, * TheCollector1995 + * * Copyright 1989-2017 Fred N. van Kempen. */ #include @@ -43,6 +44,7 @@ #include #include #include +#include "86box.h" #include "ibm.h" #include "io.h" #include "pic.h" diff --git a/src/network/net_ne2000.c b/src/network/net_ne2000.c index 449623715..c929171b3 100644 --- a/src/network/net_ne2000.c +++ b/src/network/net_ne2000.c @@ -10,7 +10,7 @@ * * NOTE: The file will also implement an NE1000 for 8-bit ISA systems. * - * Version: @(#)net_ne2000.c 1.0.18 2017/10/09 + * Version: @(#)net_ne2000.c 1.0.20 2017/10/19 * * Authors: Fred N. van Kempen, * Peter Grehan, grehan@iprg.nokia.com> @@ -27,6 +27,7 @@ #include #include #include +#include "../86box.h" #include "../config.h" #include "../ibm.h" #include "../io.h" @@ -1880,11 +1881,15 @@ nic_init(device_t *info) uint32_t mac; wchar_t *rom; nic_t *dev; +#ifdef ENABLE_NIC_LOG int i; +#endif /* Get the desired debug level. */ +#ifdef ENABLE_NIC_LOG i = device_get_config_int("debug"); if (i > 0) nic_do_log = i; +#endif dev = malloc(sizeof(nic_t)); memset(dev, 0x00, sizeof(nic_t)); diff --git a/src/network/net_pcap.c b/src/network/net_pcap.c index fe41e6281..f1bf76271 100644 --- a/src/network/net_pcap.c +++ b/src/network/net_pcap.c @@ -8,7 +8,7 @@ * * Handle WinPcap library processing. * - * Version: @(#)net_pcap.c 1.0.9 2017/10/11 + * Version: @(#)net_pcap.c 1.0.10 2017/10/16 * * Author: Fred N. van Kempen, * @@ -20,6 +20,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../config.h" #include "../device.h" @@ -28,11 +29,18 @@ #include "network.h" -static void *pcap_handle; /* handle to WinPcap DLL */ -static pcap_t *pcap; /* handle to WinPcap library */ -static thread_t *poll_tid; -static NETRXCB poll_rx; /* network RX function to call */ -static void *poll_arg; /* network RX function arg */ +static volatile + void *pcap_handle; /* handle to WinPcap DLL */ +static volatile + pcap_t *pcap; /* handle to WinPcap library */ +static volatile + thread_t *poll_tid; +static volatile + NETRXCB poll_rx; /* network RX function to call */ +static volatile + void *poll_arg; /* network RX function arg */ +static volatile + event_t *thread_started; /* Pointers to the real functions. */ @@ -71,6 +79,8 @@ poll_thread(void *arg) uint16_t mac_cmp16[2]; event_t *evt; + thread_set_event((event_t *) thread_started); + pclog("PCAP: polling thread started, arg %08lx\n", arg); /* Create a waitable event. */ @@ -78,12 +88,12 @@ poll_thread(void *arg) /* As long as the channel is open.. */ while (pcap != NULL) { - startnet(); + network_mutex_wait(1); network_wait_for_poll(); /* Wait for the next packet to arrive. */ - data = f_pcap_next(pcap, &h); + data = f_pcap_next((pcap_t *) pcap, &h); if (data != NULL) { /* Received MAC. */ mac_cmp32[0] = *(uint32_t *)(data+6); @@ -95,7 +105,7 @@ poll_thread(void *arg) if ((mac_cmp32[0] != mac_cmp32[1]) || (mac_cmp16[0] != mac_cmp16[1])) { if (poll_rx != NULL) - poll_rx(poll_arg, (uint8_t *)data, h.caplen); + poll_rx((void *) poll_arg, (uint8_t *)data, h.caplen); } else { /* Mark as invalid packet. */ data = NULL; @@ -106,13 +116,10 @@ poll_thread(void *arg) if (data == NULL) thread_wait_event(evt, 10); - endnet(); + network_mutex_wait(0); } thread_destroy_event(evt); - poll_tid = NULL; - - network_mutex_close(); pclog("PCAP: polling stopped.\n"); } @@ -225,15 +232,15 @@ network_pcap_setup(uint8_t *mac, NETRXCB func, void *arg) "( ((ether dst ff:ff:ff:ff:ff:ff) or (ether dst %02x:%02x:%02x:%02x:%02x:%02x)) and not (ether src %02x:%02x:%02x:%02x:%02x:%02x) )", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5], mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); - if (f_pcap_compile(pcap, &fp, filter_exp, 0, 0xffffffff) != -1) { - if (f_pcap_setfilter(pcap, &fp) == -1) { + if (f_pcap_compile((pcap_t *) pcap, &fp, filter_exp, 0, 0xffffffff) != -1) { + if (f_pcap_setfilter((pcap_t *) pcap, &fp) == -1) { pclog(" Error installing filter (%s) !\n", filter_exp); - f_pcap_close(pcap); + f_pcap_close((pcap_t *) pcap); return (-1); } } else { pclog(" Could not compile filter (%s) !\n", filter_exp); - f_pcap_close(pcap); + f_pcap_close((pcap_t *) pcap); return (-1); } @@ -246,6 +253,8 @@ network_pcap_setup(uint8_t *mac, NETRXCB func, void *arg) pclog(" Starting thread..\n"); poll_tid = thread_create(poll_thread, mac); + thread_wait_event((event_t *) thread_started, -1); + return(0); } @@ -254,13 +263,15 @@ network_pcap_setup(uint8_t *mac, NETRXCB func, void *arg) void network_pcap_close(void) { - pcap_t *pc; + volatile pcap_t *pc; if (pcap != NULL) { pclog("Closing WinPcap\n"); /* Tell the polling thread to shut down. */ pc = pcap; pcap = NULL; + +#if 0 #if 1 /* Terminate the polling thread. */ if (poll_tid != NULL) { @@ -271,17 +282,33 @@ network_pcap_close(void) /* Wait for the polling thread to shut down. */ while (poll_tid != NULL) ; +#endif #endif - network_mutex_close(); + /* Tell the thread to terminate. */ + if (poll_tid != NULL) { + network_busy(0); + + pclog("Waiting for network thread to end...\n"); + /* Wait for the end event. */ + network_wait_for_end((void *) poll_tid); + pclog("Network thread ended\n"); + + poll_tid = NULL; + } + + if (thread_started) { + thread_destroy_event((event_t *) thread_started); + thread_started = NULL; + } /* OK, now shut down WinPcap itself. */ - f_pcap_close(pc); + f_pcap_close((pcap_t *) pc); pc = pcap = NULL; /* Unload the DLL if possible. */ if (pcap_handle != NULL) { - dynld_close(pcap_handle); + dynld_close((void *) pcap_handle); pcap_handle = NULL; } } @@ -294,12 +321,12 @@ void network_pcap_stop(void) { /* OK, now shut down WinPcap itself. */ - f_pcap_close(pcap); + f_pcap_close((pcap_t *) pcap); pcap = NULL; /* Unload the DLL if possible. */ if (pcap_handle != NULL) { - dynld_close(pcap_handle); + dynld_close((void *) pcap_handle); pcap_handle = NULL; } } @@ -347,7 +374,7 @@ network_pcap_test(void) /* Unload the DLL if possible. */ if (pcap_handle != NULL) { - dynld_close(pcap_handle); + dynld_close((void *) pcap_handle); pcap_handle = NULL; } @@ -368,7 +395,7 @@ network_pcap_test(void) /* Unload the DLL if possible. */ if (pcap_handle != NULL) { - dynld_close(pcap_handle); + dynld_close((void *) pcap_handle); pcap_handle = NULL; } @@ -380,8 +407,8 @@ network_pcap_test(void) "( ((ether dst ff:ff:ff:ff:ff:ff) or (ether dst %02x:%02x:%02x:%02x:%02x:%02x)) and not (ether src %02x:%02x:%02x:%02x:%02x:%02x) )", 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5); - if (f_pcap_compile(pcap, &fp, filter_exp, 0, 0xffffffff) != -1) { - if (f_pcap_setfilter(pcap, &fp) == -1) { + if (f_pcap_compile((pcap_t *) pcap, &fp, filter_exp, 0, 0xffffffff) != -1) { + if (f_pcap_setfilter((pcap_t *) pcap, &fp) == -1) { pclog(" Error installing filter (%s) !\n", filter_exp); network_pcap_stop(); return 0; @@ -403,10 +430,10 @@ void network_pcap_in(uint8_t *bufp, int len) { if (pcap != NULL) { - network_busy_set(); + network_busy(1); - f_pcap_sendpacket(pcap, bufp, len); + f_pcap_sendpacket((pcap_t *) pcap, bufp, len); - network_busy_clear(); + network_busy(0); } } diff --git a/src/network/net_slirp.c b/src/network/net_slirp.c index 01987c47d..a72fe7180 100644 --- a/src/network/net_slirp.c +++ b/src/network/net_slirp.c @@ -8,7 +8,7 @@ * * Handle SLiRP library processing. * - * Version: @(#)net_slirp.c 1.0.9 2017/10/14 + * Version: @(#)net_slirp.c 1.0.10 2017/10/16 * * Author: Fred N. van Kempen, * @@ -21,6 +21,7 @@ #include #include "slirp/slirp.h" #include "slirp/queue.h" +#include "../86box.h" #include "../ibm.h" #include "../config.h" #include "../device.h" @@ -28,10 +29,16 @@ #include "network.h" -static queueADT slirpq; /* SLiRP library handle */ -static thread_t *poll_tid; -static NETRXCB poll_rx; /* network RX function to call */ -static void *poll_arg; /* network RX function arg */ +static volatile + queueADT slirpq; /* SLiRP library handle */ +static volatile + thread_t *poll_tid; +static volatile + NETRXCB poll_rx; /* network RX function to call */ +static volatile + void *poll_arg; /* network RX function arg */ +static volatile + event_t *thread_started; @@ -74,13 +81,15 @@ poll_thread(void *arg) struct queuepacket *qp; event_t *evt; + thread_set_event((event_t *) thread_started); + pclog("SLiRP: polling thread started, arg %08lx\n", arg); /* Create a waitable event. */ evt = thread_create_event(); while (slirpq != NULL) { - startnet(); + network_mutex_wait(1); network_wait_for_poll(); @@ -91,6 +100,8 @@ poll_thread(void *arg) if (QueuePeek(slirpq) == 0) { /* If we did not get anything, wait a while. */ thread_wait_event(evt, 10); + + network_mutex_wait(0); continue; } @@ -102,18 +113,15 @@ poll_thread(void *arg) #endif if (poll_rx != NULL) - poll_rx(poll_arg, (uint8_t *)&qp->data, qp->len); + poll_rx((void *) poll_arg, (uint8_t *)&qp->data, qp->len); /* Done with this one. */ free(qp); - endnet(); + network_mutex_wait(0); } thread_destroy_event(evt); - evt = poll_tid = NULL; - - network_mutex_close(); pclog("SLiRP: polling stopped.\n"); } @@ -142,6 +150,8 @@ network_slirp_setup(uint8_t *mac, NETRXCB func, void *arg) pclog("SLiRP: starting thread..\n"); poll_tid = thread_create(poll_thread, mac); + thread_wait_event((event_t *) thread_started, -1); + return(0); } @@ -156,6 +166,8 @@ network_slirp_close(void) /* Tell the polling thread to shut down. */ sl = slirpq; slirpq = NULL; + +#if 0 #if 1 /* Terminate the polling thread. */ if (poll_tid != NULL) { @@ -166,9 +178,25 @@ network_slirp_close(void) /* Wait for the polling thread to shut down. */ while (poll_tid != NULL) ; +#endif #endif - network_mutex_close(); + /* Tell the thread to terminate. */ + if (poll_tid != NULL) { + network_busy(0); + + pclog("Waiting for network thread to end...\n"); + /* Wait for the end event. */ + network_wait_for_end((void *) poll_tid); + pclog("Network thread ended\n"); + + poll_tid = NULL; + } + + if (thread_started) { + thread_destroy_event((event_t *) thread_started); + thread_started = NULL; + } /* OK, now shut down SLiRP itself. */ QueueDestroy(sl); @@ -201,11 +229,11 @@ void network_slirp_in(uint8_t *pkt, int pkt_len) { if (slirpq != NULL) { - network_busy_set(); + network_busy(1); slirp_input((const uint8_t *)pkt, pkt_len); - network_busy_clear(); + network_busy(0); } } diff --git a/src/network/network.c b/src/network/network.c index da68ec403..0bb9091bc 100644 --- a/src/network/network.c +++ b/src/network/network.c @@ -12,7 +12,7 @@ * it should be malloc'ed and then linked to the NETCARD def. * Will be done later. * - * Version: @(#)network.c 1.0.14 2017/10/15 + * Version: @(#)network.c 1.0.17 2017/10/19 * * Author: Fred N. van Kempen, * @@ -23,6 +23,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../device.h" #include "../plat.h" @@ -53,32 +54,32 @@ int network_ndev; int network_card; netdev_t network_devs[32]; char network_pcap[512]; -int nic_do_log; -static mutex_t *netMutex; +#ifdef ENABLE_NIC_LOG +int nic_do_log = ENABLE_NIC_LOG; +#endif +static volatile mutex_t *netMutex; static struct { - int busy; - int queue_in_use; + volatile int + busy, + queue_in_use; - event_t *wake_poll_thread; - event_t *poll_complete; - event_t *queue_not_in_use; + volatile event_t + *wake_poll_thread, + *poll_complete, + *queue_not_in_use; } poll_data; void -startnet(void) +network_mutex_wait(uint8_t wait) { - thread_wait_mutex(netMutex); -} - - -void -endnet(void) -{ - thread_release_mutex(netMutex); + if (wait) + thread_wait_mutex((mutex_t *) netMutex); + else + thread_release_mutex((mutex_t *) netMutex); } @@ -86,46 +87,48 @@ void network_wait_for_poll() { while (poll_data.busy) - thread_wait_event(poll_data.poll_complete, -1); - thread_reset_event(poll_data.poll_complete); + thread_wait_event((event_t *) poll_data.wake_poll_thread, -1); + thread_reset_event((event_t *) poll_data.wake_poll_thread); } void -network_mutex_init() +network_wait_for_end(void *handle) { - netMutex = thread_create_mutex(L"86Box.NetMutex"); + thread_wait((event_t *) handle, -1); + + if (poll_data.wake_poll_thread) { + thread_destroy_event((event_t *) poll_data.wake_poll_thread); + poll_data.wake_poll_thread = NULL; + } + + if (poll_data.poll_complete) { + thread_destroy_event((event_t *) poll_data.poll_complete); + poll_data.poll_complete = NULL; + } } void -network_mutex_close() +network_thread_init(void) { - thread_close_mutex(netMutex); -} - - -void -network_thread_init() -{ - network_mutex_init(); - poll_data.wake_poll_thread = thread_create_event(); poll_data.poll_complete = thread_create_event(); } void -network_busy_set() +network_busy(uint8_t set) { - poll_data.busy = 1; + poll_data.busy = !!set; + if (!set) + thread_set_event((event_t *) poll_data.wake_poll_thread); } void -network_busy_clear() +network_end(void) { - poll_data.busy = 0; - thread_set_event(poll_data.poll_complete); + thread_set_event((event_t *) poll_data.poll_complete); } @@ -141,12 +144,6 @@ network_init(void) { int i; -#if ENABLE_NIC_LOG - nic_do_log = ENABLE_NIC_LOG; -#else - nic_do_log = 0; -#endif - /* Initialize to a known state. */ network_type = NET_TYPE_NONE; network_card = 0; @@ -184,6 +181,8 @@ network_attach(void *dev, uint8_t *mac, NETRXCB rx) net_cards[network_card].priv = dev; net_cards[network_card].rx = rx; + netMutex = thread_create_mutex(L"86Box.NetMutex"); + /* Start the platform module. */ switch(network_type) { case NET_TYPE_PCAP: @@ -207,6 +206,8 @@ network_attach(void *dev, uint8_t *mac, NETRXCB rx) void network_close(void) { + thread_close_mutex((mutex_t *) netMutex); + switch(network_type) { case NET_TYPE_PCAP: network_pcap_close(); diff --git a/src/network/network.h b/src/network/network.h index d6602f6b2..2e668ec9b 100644 --- a/src/network/network.h +++ b/src/network/network.h @@ -56,14 +56,13 @@ extern char network_pcap[512]; /* Function prototypes. */ -extern void startnet(void); -extern void endnet(void); -extern void network_wait_for_poll(); -extern void network_mutex_init(); -extern void network_mutex_close(); -extern void network_thread_init(); -extern void network_busy_set(); -extern void network_busy_clear(); +extern void network_mutex_wait(uint8_t wait); +extern void network_wait_for_poll(void); +extern void network_wait_for_end(void *handle); +extern void network_mutex_init(void); +extern void network_thread_init(void); +extern void network_busy(uint8_t set); +extern void network_end(void); extern void network_init(void); extern int network_attach(void *, uint8_t *, NETRXCB); diff --git a/src/nvr.c b/src/nvr.c index dea2717ef..78ecd1698 100644 --- a/src/nvr.c +++ b/src/nvr.c @@ -186,7 +186,7 @@ * (DS12887A) which implemented a "century" register to be * compatible with Y2K. * - * Version: @(#)nvr.c 1.0.9 2017/10/14 + * Version: @(#)nvr.c 1.0.10 2017/10/16 * * Authors: Sarah Walker, * Miran Grca, @@ -756,8 +756,8 @@ nvr_path(wchar_t *str) wcscat(temp, NVR_PATH); /* Create the directory if needed. */ - if (! dir_check_exist(temp)) - dir_create(temp); + if (! plat_dir_check(temp)) + plat_dir_create(temp); /* Now append the actual filename. */ #ifdef WIN32 diff --git a/src/pc.c b/src/pc.c index ac0e4ba6c..470ae2803 100644 --- a/src/pc.c +++ b/src/pc.c @@ -6,9 +6,9 @@ * * This file is part of the 86Box distribution. * - * Emulation core dispatcher. + * Main emulator module where most things are controlled. * - * Version: @(#)pc.c 1.0.27 2017/10/14 + * Version: @(#)pc.c 1.0.31 2017/10/21 * * Authors: Sarah Walker, * Miran Grca, @@ -23,6 +23,7 @@ #include #include #include +#include #include #include "86box.h" #include "config.h" @@ -77,30 +78,66 @@ #include "plat_mouse.h" -int window_w, window_h, window_x, window_y, window_remember; -int dump_on_exit = 0; -int start_in_fullscreen = 0; +/* Commandline options. */ +int dump_on_exit = 0; /* (O) dump regs on exit */ +int do_dump_config = 0; /* (O) dump config on load */ +int start_in_fullscreen = 0; /* (O) start in fullscreen */ + +/* Configuration values. */ +int window_w, window_h, /* (C) window size and */ + window_x, window_y, /* position info */ + window_remember, + vid_resize, /* (C) allow resizing */ + invert_display, /* (C) invert the display */ + suppress_overscan = 0; /* (C) suppress overscans */ +int scale = 0; /* (C) screen scale factor */ +int vid_api = 0; /* (C) video renderer */ +int vid_cga_contrast = 0, /* (C) video */ + video_fullscreen = 0, /* (C) video */ + video_fullscreen_scale = 0, /* (C) video */ + video_fullscreen_first = 0, /* (C) video */ + enable_overscan = 0, /* (C) video */ + force_43 = 0, /* (C) video */ + video_speed = 0; /* (C) video */ + + +/* Statistics. */ +extern int + mmuflush, + readlnum, + writelnum; + +int sndcount = 0; +int sreadlnum, + swritelnum, + segareads, + segawrites, + scycles_lost; +float mips, flops; +int cycles_lost = 0; // video +int insc = 0; // cpu +int emu_fps = 0, fps; // video +int framecount; + int CPUID; -int vid_resize, vid_api; int output; int atfullspeed; -int cycles_lost = 0; -int clockrate; -int insc = 0; -float mips, flops; -int framecount, fps; -int win_title_update = 0; -int updatestatus = 0; -int pollmouse_delay = 2; -int mousecapture; -int suppress_overscan = 0; int cpuspeed2; -wchar_t exe_path[1024]; -wchar_t cfg_path[1024]; +int clockrate; + +int gfx_present[GFX_MAX]; // should not be here + +wchar_t exe_path[1024]; /* path (dir) of executable */ +wchar_t cfg_path[1024]; /* path (dir) of user data */ +int scrnsz_x = SCREEN_RES_X, /* current screen size, X */ + scrnsz_y = SCREEN_RES_Y; /* current screen size, Y */ +int title_update; +int mousecapture; +int64_t main_time; -extern int mmuflush; -extern int readlnum,writelnum; +static int unscaled_size_x = SCREEN_RES_X, /* current unscaled size X */ + unscaled_size_y = SCREEN_RES_Y; /* current unscaled size Y */ /* Log something to the logfile or stdout. */ @@ -149,32 +186,94 @@ fatal(const char *format, ...) } -/* - * This function returns the absolute pathname to a file (str) - * that is to be found in the user (formerly 'nvr_path' area. - */ -wchar_t * -pc_concat(wchar_t *str) +void +set_screen_size(int x, int y) { - static wchar_t temp[1024]; + int owsx = scrnsz_x; + int owsy = scrnsz_y; + int temp_overscan_x = overscan_x; + int temp_overscan_y = overscan_y; + double dx, dy, dtx, dty; + int efscrnsz_y; - /* Get the full prefix in place. */ - memset(temp, 0x00, sizeof(temp)); - wcscpy(temp, cfg_path); - - /* Create the directory if needed. */ - if (! dir_check_exist(temp)) - dir_create(temp); - - /* Now append the actual filename. */ -#ifdef WIN32 - wcscat(temp, L"\\"); -#else - wcscat(temp, L"/"); + /* Make sure we keep usable values. */ +#if 0 + pclog("SetScreenSize(%d, %d) resize=%d\n", x, y, vid_resize); #endif - wcscat(temp, str); + if (x < 320) x = 320; + if (y < 200) y = 200; + if (x > 2048) x = 2048; + if (y > 2048) y = 2048; - return(temp); + /* Save the new values as "real" (unscaled) resolution. */ + unscaled_size_x = x; + efscrnsz_y = y; + + if (suppress_overscan) + temp_overscan_x = temp_overscan_y = 0; + + if (force_43) { + dx = (double)x; + dtx = (double)temp_overscan_x; + + dy = (double)y; + dty = (double)temp_overscan_y; + + /* Account for possible overscan. */ + if (!(VGA) && (temp_overscan_y == 16)) { + /* CGA */ + dy = (((dx - dtx) / 4.0) * 3.0) + dty; + } else if (!(VGA) && (temp_overscan_y < 16)) { + /* MDA/Hercules */ + dy = (x / 4.0) * 3.0; + } else { + if (enable_overscan) { + /* EGA/(S)VGA with overscan */ + dy = (((dx - dtx) / 4.0) * 3.0) + dty; + } else { + /* EGA/(S)VGA without overscan */ + dy = (x / 4.0) * 3.0; + } + } + unscaled_size_y = (int)dy; + } else { + unscaled_size_y = efscrnsz_y; + } + + switch(scale) { + case 0: /* 50% */ + scrnsz_x = (unscaled_size_x>>1); + scrnsz_y = (unscaled_size_y>>1); + break; + + case 1: /* 100% */ + scrnsz_x = unscaled_size_x; + scrnsz_y = unscaled_size_y; + break; + + case 2: /* 150% */ + scrnsz_x = ((unscaled_size_x*3)>>1); + scrnsz_y = ((unscaled_size_y*3)>>1); + break; + + case 3: /* 200% */ + scrnsz_x = (unscaled_size_x<<1); + scrnsz_y = (unscaled_size_y<<1); + break; + } + + /* If the resolution has changed, let the main thread handle it. */ + if ((owsx != scrnsz_x) || (owsy != scrnsz_y)) + doresize = 1; + else + doresize = 0; +} + + +void +set_screen_size_natural(void) +{ + set_screen_size(unscaled_size_x, unscaled_size_y); } @@ -189,11 +288,14 @@ int pc_init(int argc, wchar_t *argv[]) { wchar_t *cfg = NULL, *p; + char temp[128]; + struct tm *info; + time_t now; int c; /* Grab the executable's full path. */ - get_executable_name(exe_path, sizeof(exe_path)-1); - p = get_filename_w(exe_path); + plat_get_exe_name(exe_path, sizeof(exe_path)-1); + p = plat_get_filename(exe_path); *p = L'\0'; /* @@ -213,11 +315,15 @@ usage: printf("\nUsage: 86box [options] [cfg-file]\n\n"); printf("Valid options are:\n\n"); printf("-? or --help - show this information\n"); + printf("-C or --dumpcfg - dump config file after loading\n"); printf("-D or --dump - dump memory on exit\n"); printf("-F or --fullscreen - start in fullscreen mode\n"); printf("-P or --vmpath path - set 'path' to be root for vm\n"); printf("\nA config file can be specified. If none is, the default file will be used.\n"); return(0); + } else if (!wcscasecmp(argv[c], L"--dumpcfg") || + !wcscasecmp(argv[c], L"-C")) { + do_dump_config = 1; } else if (!wcscasecmp(argv[c], L"--dump") || !wcscasecmp(argv[c], L"-D")) { dump_on_exit = 1; @@ -245,14 +351,7 @@ usage: cfg = argv[c++]; if (c != argc) goto usage; - /* - * This is where we start outputting to the log file, - * if there is one. Maybe we should log a header with - * application build info and such? --FvK - */ - /* Make sure cfg_path has a trailing backslash. */ - pclog("exe_path=%ls\n", exe_path); if ((cfg_path[wcslen(cfg_path)-1] != L'\\') && (cfg_path[wcslen(cfg_path)-1] != L'/')) { #ifdef WIN32 @@ -261,7 +360,6 @@ usage: wcscat(cfg_path, L"/"); #endif } - pclog("cfg_path=%ls\n", cfg_path); if (cfg != NULL) { /* @@ -280,13 +378,25 @@ usage: #endif wcscpy(config_file_default, cfg); else - append_filename_w(config_file_default, - cfg_path, cfg, 511); + plat_append_filename(config_file_default, cfg_path, cfg, 511); cfg = NULL; } else { - append_filename_w(config_file_default, cfg_path, CONFIG_FILE_W, 511); + plat_append_filename(config_file_default, cfg_path, CONFIG_FILE_W, 511); } + /* + * This is where we start outputting to the log file, + * if there is one. Create a little info header first. + */ + (void)time(&now); + info = localtime(&now); + strftime(temp, sizeof(temp), "%Y/%m/%d %H:%M:%S", info); + pclog("#\n# %ls v%ls logfile, created %s\n#\n", + EMU_NAME_W, EMU_VERSION_W, temp); + pclog("# Emulator path: %ls\n", exe_path); + pclog("# Userfiles path: %ls\n", cfg_path); + pclog("# Configuration file: %ls\n#\n\n", config_file_default); + /* * We are about to read the configuration file, which MAY * put data into global variables (the hard- and floppy @@ -342,8 +452,7 @@ pc_init_modules(void) int c, i; pclog("Scanning for ROM images:\n"); - c = 0; - for (i=0; iexit(i); @@ -650,134 +804,195 @@ pc_close(void) /* - * Run the actual configured PC. + * The main thread runs the actual emulator code. + * + * We basically run until the upper layers terminate us, by + * setting the variable 'quited' there to 1. We get a pointer + * to that variable as our function argument. */ -int framecountx=0; -int sndcount=0; -int sreadlnum,swritelnum,segareads,segawrites, scycles_lost; -int serial_fifo_read, serial_fifo_write; -int emu_fps = 0; - -static wchar_t wmachine[2048]; -static wchar_t wcpu[2048]; - - -static void -pollmouse(void) -{ - int x, y, z; - - if (--pollmouse_delay) return; - - pollmouse_delay = 2; - - mouse_poll_host(); - - mouse_get_mickeys(&x, &y, &z); - - mouse_poll(x, y, z, mouse_buttons); -} - - void -pc_run(void) +pc_thread(void *param) { - wchar_t temp[200]; - int done = 0; + wchar_t temp[200], wcpu[2048]; + wchar_t wmachine[2048]; + uint64_t start_time, end_time; + uint32_t old_time, new_time; + int status_update_needed; + int done, drawits, frames; + int *quitp = (int *)param; + int framecountx; - startblit(); - clockrate = machines[machine].cpu[cpu_manufacturer].cpus[cpu].rspeed; - - if (is386) { -#ifdef USE_DYNAREC - if (cpu_use_dynarec) - exec386_dynarec(machines[machine].cpu[cpu_manufacturer].cpus[cpu].rspeed / 100); - else + pclog("PC: starting main thread...\n"); + + main_time = 0; + framecountx = 0; + status_update_needed = title_update = 1; + old_time = plat_get_ticks(); + done = drawits = frames = 0; + while (! *quitp) { + /* Update the Stat(u)s window with the current info. */ + if (status_update_needed) { +#if 0 + pclog("Updating STATS window..\n"); +// ui_status_update(); #endif - exec386(machines[machine].cpu[cpu_manufacturer].cpus[cpu].rspeed / 100); - } else if (AT) { - exec386(machines[machine].cpu[cpu_manufacturer].cpus[cpu].rspeed / 100); - } else { - execx86(machines[machine].cpu[cpu_manufacturer].cpus[cpu].rspeed / 100); - } + status_update_needed = 0; + } - keyboard_process(); + /* See if it is time to run a frame of code. */ + new_time = plat_get_ticks(); + drawits += (new_time - old_time); + old_time = new_time; + if (drawits > 0 && !dopause) { + /* Yes, so do one frame now. */ + start_time = plat_timer_read(); + drawits -= 10; + if (drawits > 50) + drawits = 0; - pollmouse(); + /* Run a block of code. */ + startblit(); + clockrate = machines[machine].cpu[cpu_manufacturer].cpus[cpu].rspeed; - if (joystick_type != 7) - joystick_poll(); + if (is386) { +#ifdef USE_DYNAREC + if (cpu_use_dynarec) + exec386_dynarec(clockrate/100); + else +#endif + exec386(clockrate/100); + } else if (AT) { + exec386(clockrate/100); + } else { + execx86(clockrate/100); + } - endblit(); + keyboard_process(); - framecountx++; - framecount++; - if (framecountx >= 100) { - framecountx = 0; - mips = (float)insc/1000000.0f; - insc = 0; - flops = (float)fpucount/1000000.0f; - fpucount = 0; - sreadlnum = readlnum; - swritelnum = writelnum; - segareads = egareads; - segawrites = egawrites; - scycles_lost = cycles_lost; + mouse_process(); + + joystick_process(); + + endblit(); + + /* Done with this frame, update statistics. */ + framecount++; + if (++framecountx >= 100) { + framecountx = 0; + + /* FIXME: all this should go into a "stats" struct! */ + mips = (float)insc/1000000.0f; + insc = 0; + flops = (float)fpucount/1000000.0f; + fpucount = 0; + sreadlnum = readlnum; + swritelnum = writelnum; + segareads = egareads; + segawrites = egawrites; + scycles_lost = cycles_lost; #ifdef USE_DYNAREC - cpu_recomp_blocks_latched = cpu_recomp_blocks; - cpu_recomp_ins_latched = cpu_state.cpu_recomp_ins; - cpu_recomp_full_ins_latched = cpu_recomp_full_ins; - cpu_new_blocks_latched = cpu_new_blocks; - cpu_recomp_flushes_latched = cpu_recomp_flushes; - cpu_recomp_evicted_latched = cpu_recomp_evicted; - cpu_recomp_reuse_latched = cpu_recomp_reuse; - cpu_recomp_removed_latched = cpu_recomp_removed; - cpu_reps_latched = cpu_reps; - cpu_notreps_latched = cpu_notreps; + cpu_recomp_blocks_latched = cpu_recomp_blocks; + cpu_recomp_ins_latched = cpu_state.cpu_recomp_ins; + cpu_recomp_full_ins_latched = cpu_recomp_full_ins; + cpu_new_blocks_latched = cpu_new_blocks; + cpu_recomp_flushes_latched = cpu_recomp_flushes; + cpu_recomp_evicted_latched = cpu_recomp_evicted; + cpu_recomp_reuse_latched = cpu_recomp_reuse; + cpu_recomp_removed_latched = cpu_recomp_removed; + cpu_reps_latched = cpu_reps; + cpu_notreps_latched = cpu_notreps; - cpu_recomp_blocks = 0; - cpu_state.cpu_recomp_ins = 0; - cpu_recomp_full_ins = 0; - cpu_new_blocks = 0; - cpu_recomp_flushes = 0; - cpu_recomp_evicted = 0; - cpu_recomp_reuse = 0; - cpu_recomp_removed = 0; - cpu_reps = 0; - cpu_notreps = 0; + cpu_recomp_blocks = 0; + cpu_state.cpu_recomp_ins = 0; + cpu_recomp_full_ins = 0; + cpu_new_blocks = 0; + cpu_recomp_flushes = 0; + cpu_recomp_evicted = 0; + cpu_recomp_reuse = 0; + cpu_recomp_removed = 0; + cpu_reps = 0; + cpu_notreps = 0; #endif - updatestatus = 1; - readlnum = writelnum = 0; - egareads = egawrites = 0; - cycles_lost = 0; - mmuflush = 0; - emu_fps = frames; - frames = 0; - } + readlnum = writelnum = 0; + egareads = egawrites = 0; + cycles_lost = 0; + mmuflush = 0; + emu_fps = frames; + frames = 0; - if (win_title_update) { - mbstowcs(wmachine, machine_getname(), strlen(machine_getname())+1); - mbstowcs(wcpu, machines[machine].cpu[cpu_manufacturer].cpus[cpu].name, - strlen(machines[machine].cpu[cpu_manufacturer].cpus[cpu].name)+1); - swprintf(temp, sizeof_w(temp), L"%ls v%ls - %i%% - %ls - %ls - %ls", - EMU_NAME_W, EMU_VERSION_W, fps, wmachine, wcpu, - (!mousecapture) ? plat_get_string(IDS_2077) + /* We need a Status window update now. */ + status_update_needed = 1; + } + + if (title_update) { + mbstowcs(wmachine, machine_getname(), strlen(machine_getname())+1); + mbstowcs(wcpu, machines[machine].cpu[cpu_manufacturer].cpus[cpu].name, + strlen(machines[machine].cpu[cpu_manufacturer].cpus[cpu].name)+1); + swprintf(temp, sizeof_w(temp), + L"%ls v%ls - %i%% - %ls - %ls - %ls", + EMU_NAME_W,EMU_VERSION_W,fps,wmachine,wcpu, + (!mousecapture) ? plat_get_string(IDS_2077) : ((mouse_get_type(mouse_type) & MOUSE_TYPE_3BUTTON) ? plat_get_string(IDS_2078) : plat_get_string(IDS_2079))); - set_window_title(temp); - win_title_update = 0; + ui_window_title(temp); + + title_update = 0; + } + + /* One more frame done! */ + done++; + + /* Every 200 frames we save the machine status. */ + if (++frames >= 200 && nvr_dosave) { + nvr_save(); + nvr_dosave = 0; + frames = 0; + } + + end_time = plat_timer_read(); + main_time += (end_time - start_time); + } else { + /* Just so we dont overload the host OS. */ + plat_delay_ms(1); + } + + /* If needed, hand a screen resize. */ + if (!video_fullscreen && doresize && (scrnsz_x>0) && (scrnsz_y>0)) { + plat_resize(scrnsz_x, scrnsz_y); + + doresize = 0; + } + + /* If requested, leave full-screen mode. */ + if (leave_fullscreen_flag) { +#if 1 + pclog("Leaving full-screen mode..\n"); +// plat_fullscreen(0); +#else + SendMessage(hwndMain, WM_LEAVEFULLSCREEN, 0, 0); +#endif + leave_fullscreen_flag = 0; + } + +#if 0 + /* Do we really need this all the time? */ + if (video_fullscreen && infocus) + SetCursorPos(9999, 9999); +#endif } - done++; + pclog("PC: main thread done.\n"); } +/* Handler for the 1-second timer to refresh the window title. */ void -onesec(void) +pc_onesec(void) { fps = framecount; framecount = 0; - win_title_update = 1; + + title_update = 1; } diff --git a/src/pic.c b/src/pic.c index 797e16266..9c9639209 100644 --- a/src/pic.c +++ b/src/pic.c @@ -2,6 +2,7 @@ #include #include #include +#include "86box.h" #include "ibm.h" #include "io.h" #include "pci.h" diff --git a/src/piix.c b/src/piix.c index 4fbb059d1..c136dde1b 100644 --- a/src/piix.c +++ b/src/piix.c @@ -12,10 +12,11 @@ * word 0 - base address * word 1 - bits 1 - 15 = byte count, bit 31 = end of transfer * - * Version: @(#)piix.c 1.0.5 2017/10/01 + * Version: @(#)piix.c 1.0.6 2017/10/16 * * Authors: Sarah Walker, * Miran Grca, + * * Copyright 2008-2017 Sarah Walker. * Copyright 2016,2017 Miran Grca. */ @@ -23,6 +24,7 @@ #include #include #include +#include "86box.h" #include "ibm.h" #include "dma.h" #include "io.h" diff --git a/src/plat.h b/src/plat.h index ff5c9ed62..1aa76b2f5 100644 --- a/src/plat.h +++ b/src/plat.h @@ -8,7 +8,7 @@ * * Define the various platform support functions. * - * Version: @(#)plat.h 1.0.8 2017/10/15 + * Version: @(#)plat.h 1.0.12 2017/10/19 * * Authors: Miran Grca, * Fred N. van Kempen, @@ -19,13 +19,27 @@ #ifndef EMU_PLAT_H # define EMU_PLAT_H +#ifndef GLOBAL +# define GLOBAL extern +#endif + + +/* A hack (GCC-specific) to allow us to ignore unused parameters. */ +#define UNUSED(arg) __attribute__((unused))arg + #ifdef __cplusplus extern "C" { #endif /* Global variables residing in the platform module. */ -extern int dopause; +GLOBAL int dopause, /* system is paused */ + doresize, /* screen resize requested */ + quited, /* system exit requested */ + leave_fullscreen_flag; /* windowed-mode requested */ +GLOBAL uint64_t timer_freq; +GLOBAL int infocus; +GLOBAL int mousecapture; /* System-related functions. */ @@ -33,14 +47,21 @@ extern FILE *plat_fopen(wchar_t *path, wchar_t *mode); extern void plat_remove(wchar_t *path); extern int plat_getcwd(wchar_t *bufp, int max); extern int plat_chdir(wchar_t *path); -extern void get_executable_name(wchar_t *s, int size); -extern wchar_t *set_window_title(wchar_t *s); -extern int dir_check_exist(wchar_t *path); -extern int dir_create(wchar_t *path); - -extern void leave_fullscreen(void); -extern void plat_pc_reset(int hard); +extern void plat_get_exe_name(wchar_t *s, int size); +extern wchar_t *plat_get_filename(wchar_t *s); +extern wchar_t *plat_get_extension(wchar_t *s); +extern void plat_append_filename(wchar_t *dest, wchar_t *s1, wchar_t *s2, int size); +extern void plat_put_backslash(wchar_t *s); +extern int plat_dir_check(wchar_t *path); +extern int plat_dir_create(wchar_t *path); +extern uint64_t plat_timer_read(void); +extern uint32_t plat_get_ticks(void); +extern void plat_delay_ms(uint32_t count); extern void plat_pause(int p); +extern int plat_vidapi(char *name); +extern int plat_setvid(int api); +extern void plat_setfullscreen(int on); +extern void plat_resize(int max_x, int max_y); /* Return the size (in wchar's) of a wchar_t array. */ @@ -60,7 +81,6 @@ extern wchar_t *plat_get_string_from_string(char *str); /* Platform-specific device support. */ extern uint8_t host_cdrom_drive_available[26]; extern uint8_t host_cdrom_drive_available_num; -extern uint32_t cdrom_capacity; extern void cdrom_init_host_drives(void); extern void cdrom_eject(uint8_t id); @@ -78,20 +98,18 @@ typedef void thread_t; typedef void event_t; typedef void mutex_t; -extern thread_t *thread_create(void (*thread_rout)(void *param), void *param); -extern void thread_kill(thread_t *handle); - -extern void thread_sleep(int t); - +extern thread_t *thread_create(void (*thread_func)(void *param), void *param); +extern void thread_kill(thread_t *arg); +extern int thread_wait(thread_t *arg, int timeout); extern event_t *thread_create_event(void); -extern void thread_set_event(event_t *event); -extern void thread_reset_event(event_t *_event); -extern int thread_wait_event(event_t *event, int timeout); -extern void thread_destroy_event(event_t *_event); +extern void thread_set_event(event_t *arg); +extern void thread_reset_event(event_t *arg); +extern int thread_wait_event(event_t *arg, int timeout); +extern void thread_destroy_event(event_t *arg); extern mutex_t *thread_create_mutex(wchar_t *name); -extern void thread_close_mutex(mutex_t *mutex); -extern int thread_wait_mutex(mutex_t *mutex); +extern void thread_close_mutex(mutex_t *arg); +extern int thread_wait_mutex(mutex_t *arg); extern int thread_release_mutex(mutex_t *mutex); @@ -100,11 +118,6 @@ extern void startblit(void); extern void endblit(void); extern void take_screenshot(void); - -extern uint32_t get_ticks(void); -extern void delay_ms(uint32_t count); - - #ifdef __cplusplus } #endif diff --git a/src/plat_joystick.h b/src/plat_joystick.h index aecb3537c..ecb80168e 100644 --- a/src/plat_joystick.h +++ b/src/plat_joystick.h @@ -4,66 +4,66 @@ #ifdef __cplusplus extern "C" { #endif - void joystick_init(); - void joystick_close(); - void joystick_poll(); - - typedef struct plat_joystick_t - { - char name[64]; - - int a[8]; - int b[32]; - int p[4]; - - struct - { - char name[32]; - int id; - } axis[8]; - - struct - { - char name[32]; - int id; - } button[32]; - - struct - { - char name[32]; - int id; - } pov[4]; - - int nr_axes; - int nr_buttons; - int nr_povs; - } plat_joystick_t; +extern void joystick_init(void); +extern void joystick_close(void); +extern void joystick_process(void); - #define MAX_PLAT_JOYSTICKS 8 +typedef struct plat_joystick_t +{ + char name[64]; - extern plat_joystick_t plat_joystick_state[MAX_PLAT_JOYSTICKS]; - extern int joysticks_present; + int a[8]; + int b[32]; + int p[4]; - #define POV_X 0x80000000 - #define POV_Y 0x40000000 - - typedef struct joystick_t - { - int axis[8]; - int button[32]; - int pov[4]; - - int plat_joystick_nr; - int axis_mapping[8]; - int button_mapping[32]; - int pov_mapping[4][2]; - } joystick_t; + struct + { + char name[32]; + int id; + } axis[8]; - #define MAX_JOYSTICKS 4 - extern joystick_t joystick_state[MAX_JOYSTICKS]; + struct + { + char name[32]; + int id; + } button[32]; - #define JOYSTICK_PRESENT(n) (joystick_state[n].plat_joystick_nr != 0) + struct + { + char name[32]; + int id; + } pov[4]; + + int nr_axes; + int nr_buttons; + int nr_povs; +} plat_joystick_t; + +#define MAX_PLAT_JOYSTICKS 8 + +extern plat_joystick_t plat_joystick_state[MAX_PLAT_JOYSTICKS]; +extern int joysticks_present; + +#define POV_X 0x80000000 +#define POV_Y 0x40000000 + +typedef struct joystick_t +{ + int axis[8]; + int button[32]; + int pov[4]; + + int plat_joystick_nr; + int axis_mapping[8]; + int button_mapping[32]; + int pov_mapping[4][2]; +} joystick_t; + +#define MAX_JOYSTICKS 4 +extern joystick_t joystick_state[MAX_JOYSTICKS]; + +#define JOYSTICK_PRESENT(n) (joystick_state[n].plat_joystick_nr != 0) #ifdef __cplusplus } -#endif \ No newline at end of file +#endif diff --git a/src/plat_mouse.h b/src/plat_mouse.h index ff248f301..f5be1597c 100644 --- a/src/plat_mouse.h +++ b/src/plat_mouse.h @@ -1,16 +1,22 @@ /* Copyright holders: Sarah Walker see COPYING for more details */ + + +extern int mousecapture; +extern int mouse_buttons; + + #ifdef __cplusplus extern "C" { #endif - void mouse_init(); - void mouse_close(); - extern int mouse_buttons; - void mouse_poll_host(); - void mouse_get_mickeys(int *x, int *y, int *z); - extern int mousecapture; +extern void mouse_init(void); +extern void mouse_close(void); +extern void mouse_process(void); +extern void mouse_poll_host(void); +extern void mouse_get_mickeys(int *x, int *y, int *z); + #ifdef __cplusplus } #endif diff --git a/src/rom.c b/src/rom.c index cc7bf154a..ad27f969f 100644 --- a/src/rom.c +++ b/src/rom.c @@ -13,7 +13,7 @@ * - c386sx16 BIOS fails checksum * - the loadfont() calls should be done elsewhere * - * Version: @(#)rom.c 1.0.11 2017/10/14 + * Version: @(#)rom.c 1.0.14 2017/10/17 * * Authors: Sarah Walker, * Miran Grca, @@ -28,6 +28,7 @@ #include #include #include +#include "86box.h" #include "config.h" #include "ibm.h" #include "mem.h" @@ -45,7 +46,7 @@ rom_fopen(wchar_t *fn, wchar_t *mode) wchar_t temp[1024]; wcscpy(temp, exe_path); - put_backslash_w(temp); + plat_put_backslash(temp); wcscat(temp, fn); return(plat_fopen(temp, mode)); @@ -58,7 +59,7 @@ rom_getfile(wchar_t *fn, wchar_t *s, int size) FILE *f; wcscpy(s, exe_path); - put_backslash_w(s); + plat_put_backslash(s); wcscat(s, fn); f = plat_fopen(s, L"rb"); @@ -564,7 +565,7 @@ rom_load_bios(int rom_id) return(1); case ROM_DESKPRO_386: - if (rom_load_interleaved( + if (! rom_load_interleaved( L"roms/machines/deskpro386/109592-005.U11.bin", L"roms/machines/deskpro386/109591-005.U13.bin", 0x000000, 32768, 0, rom)) break; diff --git a/src/scsi/scsi.c b/src/scsi/scsi.c index 1701f88a3..3831d04dc 100644 --- a/src/scsi/scsi.c +++ b/src/scsi/scsi.c @@ -49,6 +49,7 @@ int scsi_card_current = 0; int scsi_card_last = 0; uint32_t SCSI_BufferLength; +static volatile mutex_t *scsiMutex; @@ -71,7 +72,9 @@ static SCSI_CARD scsi_cards[] = { { "[ISA] Ranco RT1000B", "rt1000b", &scsi_rt1000b_device, NULL }, { "[ISA] Trantor T130B", "t130b", &scsi_t130b_device, NULL }, { "[MCA] Adaptec AHA-1640", "aha1640", &aha1640_device, x54x_device_reset }, + { "[MCA] BusLogic BT-640A", "bt640a", &buslogic_640a_device,BuslogicDeviceReset }, { "[PCI] BusLogic BT-958D", "bt958d", &buslogic_pci_device, BuslogicDeviceReset }, + { "[VLB] BusLogic BT-445S", "bt445s", &buslogic_445s_device,BuslogicDeviceReset }, { "", "", NULL, NULL }, }; @@ -125,15 +128,12 @@ int scsi_card_get_from_internal_name(char *s) } -void scsi_mutex_init(void) +void scsi_mutex(uint8_t start) { - scsiMutex = thread_create_mutex(L"86Box.SCSIMutex"); -} - - -void scsi_mutex_close(void) -{ - thread_close_mutex(scsiMutex); + if (start) + scsiMutex = thread_create_mutex(L"86Box.SCSIMutex"); + else + thread_close_mutex((mutex_t *) scsiMutex); } @@ -207,14 +207,10 @@ void SCSIReset(uint8_t id, uint8_t lun) void -startscsi(void) +scsi_mutex_wait(uint8_t wait) { - thread_wait_mutex(scsiMutex); -} - - -void -endscsi(void) -{ - thread_release_mutex(scsiMutex); + if (wait) + thread_wait_mutex((mutex_t *) scsiMutex); + else + thread_release_mutex((mutex_t *) scsiMutex); } diff --git a/src/scsi/scsi.h b/src/scsi/scsi.h index 1f6bb1cde..092dd5650 100644 --- a/src/scsi/scsi.h +++ b/src/scsi/scsi.h @@ -294,8 +294,7 @@ extern device_t *scsi_card_getdevice(int card); extern int scsi_card_has_config(int card); extern char *scsi_card_get_internal_name(int card); extern int scsi_card_get_from_internal_name(char *s); -extern void scsi_mutex_init(void); -extern void scsi_mutex_close(void); +extern void scsi_mutex(uint8_t start); extern void scsi_card_init(void); extern void scsi_card_reset(void); @@ -354,5 +353,4 @@ typedef struct { #endif /*EMU_SCSI_H*/ -extern void startscsi(void); -extern void endscsi(void); +extern void scsi_mutex_wait(uint8_t wait); diff --git a/src/scsi/scsi_aha154x.c b/src/scsi/scsi_aha154x.c index 914709fc6..2300e67b3 100644 --- a/src/scsi/scsi_aha154x.c +++ b/src/scsi/scsi_aha154x.c @@ -10,7 +10,7 @@ * made by Adaptec, Inc. These controllers were designed for * the ISA bus. * - * Version: @(#)scsi_aha154x.c 1.0.30 2017/10/16 + * Version: @(#)scsi_aha154x.c 1.0.32 2017/10/22 * * Authors: Fred N. van Kempen, * Original Buslogic version by SA1988 and Miran Grca. @@ -23,6 +23,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../io.h" #include "../mca.h" @@ -66,6 +67,7 @@ uint16_t aha_ports[] = { }; +#pragma pack(push,1) typedef struct { uint8_t CustomerSignature[20]; uint8_t uAutoRetry; @@ -74,6 +76,7 @@ typedef struct { uint8_t uUnknown; addr24 BIOSMailboxAddress; } aha_setup_t; +#pragma pack(pop) #ifdef ENABLE_AHA154X_LOG @@ -84,7 +87,7 @@ int aha_do_log = ENABLE_AHA154X_LOG; static void aha_log(const char *fmt, ...) { -#if ENABLE_AHA154X_LOG +#ifdef ENABLE_AHA154X_LOG va_list ap; if (aha_do_log) { @@ -263,11 +266,10 @@ aha_fast_cmds(void *p, uint8_t cmd) x54x_t *dev = (x54x_t *)p; if (cmd == CMD_BIOS_SCSI) { - x54x_busy_set(); + x54x_busy(1); dev->BIOSMailboxReq++; - - x54x_thread_start(dev); - x54x_busy_clear(); + x54x_set_wait_event(); + x54x_busy(0); return 1; } @@ -359,7 +361,7 @@ aha_cmds(void *p) case CMD_BIOS_MBINIT: /* BIOS Mailbox Initialization */ /* Sent by CF BIOS. */ - x54x_busy_set(); + x54x_busy(1); dev->Mbx24bit = 1; mbi = (MailboxInit_t *)dev->CmdBuf; @@ -375,7 +377,7 @@ aha_cmds(void *p) dev->Status &= ~STAT_INIT; dev->DataReplyLeft = 0; - x54x_busy_clear(); + x54x_busy(0); break; case CMD_MEMORY_MAP_1: /* AHA memory mapper */ @@ -436,25 +438,15 @@ aha_setup_data(void *p) ReplyISI = (ReplyInquireSetupInformation *)dev->DataBuf; aha_setup = (aha_setup_t *)ReplyISI->VendorSpecificData; + ReplyISI->fSynchronousInitiationEnabled = dev->sync & 1; + ReplyISI->fParityCheckingEnabled = dev->parity & 1; + U32_TO_ADDR(aha_setup->BIOSMailboxAddress, dev->BIOSMailboxOutAddr); aha_setup->uChecksum = 0xA3; aha_setup->uUnknown = 0xC2; } -static void -aha_reset(void *p) -{ - x54x_t *dev = (x54x_t *)p; - - dev->Lock = 0; - dev->shram_mode = 0; - dev->MailboxIsBIOS = 0; - dev->BIOSMailboxCount = 0; - dev->BIOSMailboxOutPosCur = 0; -} - - static void aha_do_bios_mail(x54x_t *dev) { @@ -507,36 +499,13 @@ aha_mca_write(int port, uint8_t val, void *priv) /* Save the MCA register value. */ dev->pos_regs[port & 7] = val; - /* Get the new assigned I/O base address. */ - switch(dev->pos_regs[3] & 0xc7) { - case 0x01: /* [1]=00xx x001 */ - dev->Base = 0x0130; - break; - - case 0x02: /* [1]=00xx x010 */ - dev->Base = 0x0230; - break; - - case 0x03: /* [1]=00xx x011 */ - dev->Base = 0x0330; - break; - - case 0x41: - dev->Base = 0x0134; - break; - - case 0x42: /* [1]=01xx x010 */ - dev->Base = 0x0234; - break; - - case 0x43: /* [1]=01xx x011 */ - dev->Base = 0x0334; - break; - } - /* This is always necessary so that the old handler doesn't remain. */ x54x_io_remove(dev, dev->Base); + /* Get the new assigned I/O base address. */ + dev->Base = (dev->pos_regs[3] & 7) << 8; + dev->Base |= ((dev->pos_regs[3] & 0xc0) ? 4 : 0); + /* Save the new IRQ and DMA channel values. */ dev->Irq = (dev->pos_regs[4] & 0x07) + 8; dev->DmaChannel = dev->pos_regs[5] & 0x0f; @@ -585,6 +554,8 @@ aha_mca_write(int port, uint8_t val, void *priv) * * SCSI Parity is pos[2]=xxx1xxxx. */ + dev->sync = (dev->pos_regs[4] >> 3) & 1; + dev->parity = (dev->pos_regs[4] >> 4) & 1; /* * The PS/2 Model 80 BIOS always enables a card if it finds one, @@ -789,6 +760,7 @@ aha_init(device_t *info) dev->max_id = 7; dev->int_geom_writable = 0; dev->cdrom_boot = 0; + dev->bit32 = 0; dev->ven_thread = aha_thread; dev->ven_cmd_is_fast = aha_cmd_is_fast; @@ -796,7 +768,6 @@ aha_init(device_t *info) dev->get_ven_param_len = aha_param_len; dev->ven_cmds = aha_cmds; dev->get_ven_data = aha_setup_data; - dev->ven_reset = aha_reset; strcpy(dev->vendor, "Adaptec"); diff --git a/src/scsi/scsi_bus.c b/src/scsi/scsi_bus.c index 36b8e7e16..5cf516887 100644 --- a/src/scsi/scsi_bus.c +++ b/src/scsi/scsi_bus.c @@ -8,10 +8,10 @@ * * The generic SCSI bus operations handler. * - * Version: @(#)scsi_bus.c 1.0.1 2017/10/04 + * Version: @(#)scsi_bus.c 1.0.2 2017/10/16 * * NOTES: For now ported from PCem with some modifications - * but at least it's a start. + * but at least it's a start. * * Authors: TheCollector1995, */ @@ -21,10 +21,12 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "scsi.h" #include "scsi_device.h" + #define STATE_IDLE 0 #define STATE_COMMAND 1 #define STATE_COMMANDWAIT 2 diff --git a/src/scsi/scsi_buslogic.c b/src/scsi/scsi_buslogic.c index 206aa5590..d5a66965e 100644 --- a/src/scsi/scsi_buslogic.c +++ b/src/scsi/scsi_buslogic.c @@ -11,7 +11,7 @@ * 1 - BT-545S ISA; * 2 - BT-958D PCI * - * Version: @(#)scsi_buslogic.c 1.0.24 2017/10/16 + * Version: @(#)scsi_buslogic.c 1.0.25 2017/10/22 * * Authors: TheCollector1995, * Miran Grca, @@ -26,6 +26,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../io.h" #include "../mca.h" @@ -208,6 +209,7 @@ typedef struct { } MailboxInitExtended_t; #pragma pack(pop) +#pragma pack(push,1) typedef struct { rom_t bios; int ExtendedLUNCCBFormat; @@ -223,6 +225,7 @@ typedef struct { uint8_t AutoSCSIROM[32768]; uint8_t SCAMData[65536]; } buslogic_data_t; +#pragma pack(pop) enum { @@ -263,12 +266,10 @@ BuslogicGetNVRFileName(buslogic_data_t *bl) return L"bt542bh.nvr"; case CHIP_BUSLOGIC_ISA: return L"bt545s.nvr"; -#ifdef BUSLOGIC_NOT_WORKING case CHIP_BUSLOGIC_MCA: return L"bt640a.nvr"; case CHIP_BUSLOGIC_VLB: return L"bt445s.nvr"; -#endif case CHIP_BUSLOGIC_PCI: return L"bt958d.nvr"; default: @@ -300,14 +301,12 @@ BuslogicAutoSCSIRamSetDefaults(x54x_t *dev, uint8_t safe) case CHIP_BUSLOGIC_ISA: memcpy(&(HALR->structured.autoSCSIData.aHostAdaptertype[1]), "545S", 4); break; -#ifdef BUSLOGIC_NOT_WORKING - case CHIP_BUSLOGIC_VLB: - memcpy(&(HALR->structured.autoSCSIData.aHostAdaptertype[1]), "445S", 4); - break; case CHIP_BUSLOGIC_MCA: memcpy(&(HALR->structured.autoSCSIData.aHostAdaptertype[1]), "640A", 4); break; -#endif + case CHIP_BUSLOGIC_VLB: + memcpy(&(HALR->structured.autoSCSIData.aHostAdaptertype[1]), "445S", 4); + break; case CHIP_BUSLOGIC_PCI: memcpy(&(HALR->structured.autoSCSIData.aHostAdaptertype[1]), "958D", 4); break; @@ -361,7 +360,7 @@ BuslogicAutoSCSIRamSetDefaults(x54x_t *dev, uint8_t safe) } HALR->structured.autoSCSIData.fIrqAutoConfiguration = (bl->chip == CHIP_BUSLOGIC_PCI) ? 0 : 1; - HALR->structured.autoSCSIData.uDMATransferRate = ((bl->chip == CHIP_BUSLOGIC_ISA_542) || (bl->chip == CHIP_BUSLOGIC_ISA)) ? 1 : 0; + HALR->structured.autoSCSIData.uDMATransferRate = (bl->chip == CHIP_BUSLOGIC_PCI) ? 0 : 1; HALR->structured.autoSCSIData.uSCSIId = 7; HALR->structured.autoSCSIData.uSCSIConfiguration = 0x3F; @@ -477,7 +476,7 @@ buslogic_get_dma(void *p) HALocalRAM *HALR = &bl->LocalRAM; if (bl->chip == CHIP_BUSLOGIC_PCI) - return dev->DmaChannel; + return (dev->Base ? 7 : 0); else return bl_dma[HALR->structured.autoSCSIData.uDMAChannel]; } @@ -509,6 +508,8 @@ buslogic_param_len(void *p) return 2; case 0x94: return 3; + case 0x93: /* Valid only for VLB */ + return (bl->chip == CHIP_BUSLOGIC_VLB) ? 1 : 0; case 0x95: /* Valid only for PCI */ return (bl->chip == CHIP_BUSLOGIC_PCI) ? 1 : 0; case 0x97: /* Valid only for PCI */ @@ -694,7 +695,7 @@ buslogic_cmds(void *p) dev->IrqEnabled = 1; return 1; case 0x81: - x54x_busy_set(); + x54x_busy(1); dev->Mbx24bit = 0; MailboxInitE = (MailboxInitExtended_t *)dev->CmdBuf; @@ -711,7 +712,7 @@ buslogic_cmds(void *p) dev->Status &= ~STAT_INIT; dev->DataReplyLeft = 0; - x54x_busy_clear(); + x54x_busy(0); break; case 0x83: if (dev->CmdParam == 12) { @@ -807,7 +808,7 @@ buslogic_cmds(void *p) ReplyIESI->cMailbox = dev->MailboxCount; ReplyIESI->uMailboxAddressBase = dev->MailboxOutAddr; ReplyIESI->fHostWideSCSI = 1; /* This should be set for the BT-542B as well. */ - if (bl->chip != CHIP_BUSLOGIC_ISA_542) + if ((bl->chip != CHIP_BUSLOGIC_ISA_542) && (bl->chip != CHIP_BUSLOGIC_MCA)) ReplyIESI->fLevelSensitiveInterrupt = bl->LocalRAM.structured.autoSCSIData.fLevelSensitiveInterrupt; if (bl->chip == CHIP_BUSLOGIC_PCI) ReplyIESI->fHostUltraSCSI = 1; @@ -815,7 +816,7 @@ buslogic_cmds(void *p) buslogic_log("Return Extended Setup Information: %d\n", dev->CmdBuf[0]); break; case 0x8F: - if (bl->chip == CHIP_BUSLOGIC_ISA_542) + if ((bl->chip == CHIP_BUSLOGIC_ISA_542) || (bl->chip == CHIP_BUSLOGIC_MCA)) bl->fAggressiveRoundRobinMode = dev->CmdBuf[0] & 1; else bl->LocalRAM.structured.autoSCSIData.fAggressiveRoundRobinMode = dev->CmdBuf[0] & 1; @@ -838,8 +839,14 @@ buslogic_cmds(void *p) dev->DataReply = 0; break; + case 0x93: + if (bl->chip != CHIP_BUSLOGIC_VLB) { + dev->DataReplyLeft = 0; + dev->Status |= STAT_INVCMD; + break; + } case 0x92: - if (bl->chip == CHIP_BUSLOGIC_ISA_542) { + if ((bl->chip == CHIP_BUSLOGIC_ISA_542) || (bl->chip == CHIP_BUSLOGIC_MCA)) { dev->DataReplyLeft = 0; dev->Status |= STAT_INVCMD; break; @@ -869,7 +876,7 @@ buslogic_cmds(void *p) } break; case 0x94: - if (bl->chip == CHIP_BUSLOGIC_ISA_542) { + if ((bl->chip == CHIP_BUSLOGIC_ISA_542) || (bl->chip == CHIP_BUSLOGIC_MCA)) { dev->DataReplyLeft = 0; dev->Status |= STAT_INVCMD; break; @@ -955,6 +962,10 @@ buslogic_cmds(void *p) dev->DataReply = 0; break; + default: + dev->DataReplyLeft = 0; + dev->Status |= STAT_INVCMD; + break; } return 0; } @@ -967,10 +978,14 @@ buslogic_setup_data(void *p) ReplyInquireSetupInformation *ReplyISI; buslogic_setup_t *bl_setup; buslogic_data_t *bl = (buslogic_data_t *) dev->ven_data; + HALocalRAM *HALR = &bl->LocalRAM; ReplyISI = (ReplyInquireSetupInformation *)dev->DataBuf; bl_setup = (buslogic_setup_t *)ReplyISI->VendorSpecificData; + ReplyISI->fSynchronousInitiationEnabled = HALR->structured.autoSCSIData.u16SynchronousPermittedMask ? 1 : 0; + ReplyISI->fParityCheckingEnabled = (HALR->structured.autoSCSIData.uSCSIConfiguration & 2) ? 1 : 0; + bl_setup->uSignature = 'B'; /* The 'D' signature prevents Buslogic's OS/2 drivers from getting too * friendly with Adaptec hardware and upsetting the HBA state. @@ -982,14 +997,12 @@ buslogic_setup_data(void *p) case CHIP_BUSLOGIC_ISA: bl_setup->uHostBusType = 'A'; break; -#ifdef BUSLOGIC_NOT_WORKING case CHIP_BUSLOGIC_MCA: bl_setup->uHostBusType = 'B'; break; case CHIP_BUSLOGIC_VLB: bl_setup->uHostBusType = 'E'; break; -#endif case CHIP_BUSLOGIC_PCI: bl_setup->uHostBusType = 'F'; break; @@ -1004,7 +1017,7 @@ buslogic_is_aggressive_mode(void *p) buslogic_data_t *bl = (buslogic_data_t *) dev->ven_data; HALocalRAM *HALR = &bl->LocalRAM; - if (bl->chip == CHIP_BUSLOGIC_ISA_542) + if ((bl->chip == CHIP_BUSLOGIC_ISA_542) || (bl->chip == CHIP_BUSLOGIC_MCA)) return bl->fAggressiveRoundRobinMode; else return HALR->structured.autoSCSIData.fAggressiveRoundRobinMode; @@ -1017,7 +1030,7 @@ buslogic_interrupt_type(void *p) x54x_t *dev = (x54x_t *)p; buslogic_data_t *bl = (buslogic_data_t *) dev->ven_data; - if (bl->chip == CHIP_BUSLOGIC_ISA_542) + if ((bl->chip == CHIP_BUSLOGIC_ISA_542) || (bl->chip == CHIP_BUSLOGIC_MCA)) return 0; else return !!bl->LocalRAM.structured.autoSCSIData.fLevelSensitiveInterrupt; @@ -1228,7 +1241,8 @@ BuslogicPCIWrite(int func, int addr, uint8_t val, void *p) if (val != 0xFF) { buslogic_log("BusLogic IRQ now: %i\n", val); dev->Irq = val; - } + } else + dev->Irq = 0; return; } } @@ -1254,13 +1268,142 @@ BuslogicInitializeLocalRAM(buslogic_data_t *bl) } +static uint8_t +buslogic_mca_read(int port, void *priv) +{ + x54x_t *dev = (x54x_t *)priv; + + return(dev->pos_regs[port & 7]); +} + + +static void +buslogic_mca_write(int port, uint8_t val, void *priv) +{ + x54x_t *dev = (x54x_t *) priv; + buslogic_data_t *bl = (buslogic_data_t *) dev->ven_data; + + HALocalRAM *HALR = &bl->LocalRAM; + + /* MCA does not write registers below 0x0100. */ + if (port < 0x0102) return; + + /* Save the MCA register value. */ + dev->pos_regs[port & 7] = val; + + /* This is always necessary so that the old handler doesn't remain. */ + x54x_io_remove(dev, dev->Base); + + /* Get the new assigned I/O base address. */ + if (dev->pos_regs[3]) { + dev->Base = dev->pos_regs[3] << 8; + dev->Base |= ((dev->pos_regs[2] & 0x10) ? 4 : 0); + } else { + dev->Base = 0x0000; + } + + /* Save the new IRQ and DMA channel values. */ + dev->Irq = ((dev->pos_regs[2] >> 1) & 0x07) + 8; + dev->DmaChannel = dev->pos_regs[5] & 0x0f; + + /* Extract the BIOS ROM address info. */ + if (dev->pos_regs[0] & 0xe0) switch(dev->pos_regs[0] & 0xe0) { + case 0xe0: /* [0]=111x xxxx */ + bl->bios_addr = 0xDC000; + break; + + case 0x00: /* [0]=000x xxxx */ + bl->bios_addr = 0; + break; + + case 0xc0: /* [0]=110x xxxx */ + bl->bios_addr = 0xD8000; + break; + + case 0xa0: /* [0]=101x xxxx */ + bl->bios_addr = 0xD4000; + break; + + case 0x80: /* [0]=100x xxxx */ + bl->bios_addr = 0xD0000; + break; + + case 0x60: /* [0]=011x xxxx */ + bl->bios_addr = 0xCC000; + break; + + case 0x40: /* [0]=010x xxxx */ + bl->bios_addr = 0xC8000; + break; + + case 0x20: /* [0]=001x xxxx */ + bl->bios_addr = 0xC4000; + break; + } else { + /* Disabled. */ + bl->bios_addr = 0x000000; + } + + /* + * Get misc SCSI config stuff. For now, we are only + * interested in the configured HA target ID: + * + * pos[2]=111xxxxx = 7 + * pos[2]=000xxxxx = 0 + */ + dev->HostID = (dev->pos_regs[4] >> 5) & 0x07; + + /* + * SYNC mode is pos[2]=xxxxxx1x. + * + * SCSI Parity is pos[2]=xxx1xxxx. + * + * DOS Disk Space > 1GBytes is pos[2] = xxxx1xxx. + */ + /* Parity. */ + HALR->structured.autoSCSIData.uSCSIConfiguration &= ~2; + HALR->structured.autoSCSIData.uSCSIConfiguration |= (dev->pos_regs[4] & 2); + + /* Sync. */ + HALR->structured.autoSCSIData.u16SynchronousPermittedMask = (dev->pos_regs[4] & 0x10) ? 0xffff : 0x0000; + + /* DOS Disk Space > 1GBytes */ + HALR->structured.autoSCSIData.uBIOSConfiguration &= ~4; + HALR->structured.autoSCSIData.uBIOSConfiguration |= (dev->pos_regs[4] & 8) ? 4 : 0; + + /* + * The PS/2 Model 80 BIOS always enables a card if it finds one, + * even if no resources were assigned yet (because we only added + * the card, but have not run AutoConfig yet...) + * + * So, remove current address, if any. + */ + mem_mapping_disable(&dev->bios.mapping); + + /* Initialize the device if fully configured. */ + if (dev->pos_regs[2] & 0x01) { + /* Card enabled; register (new) I/O handler. */ + x54x_io_set(dev, dev->Base); + + /* Reset the device. */ + x54x_reset_ctrl(dev, CTRL_HRST); + + /* Enable or disable the BIOS ROM. */ + if (bl->has_bios && (bl->bios_addr != 0x000000)) { + mem_mapping_enable(&bl->bios.mapping); + mem_mapping_set_addr(&bl->bios.mapping, bl->bios_addr, ROM_SIZE); + } + } +} + + void BuslogicDeviceReset(void *p) { x54x_t *dev = (x54x_t *) p; buslogic_data_t *bl = (buslogic_data_t *) dev->ven_data; - x54x_reset_ctrl(dev, 1); + x54x_device_reset(dev); BuslogicInitializeLocalRAM(bl); BuslogicInitializeAutoSCSIRam(dev); @@ -1294,13 +1437,16 @@ buslogic_init(device_t *info) dev->bus = info->flags; dev->Base = device_get_config_hex16("base"); - dev->Irq = device_get_config_int("irq"); - dev->DmaChannel = device_get_config_int("dma"); + if ((info->flags != DEVICE_MCA) && (info->flags != DEVICE_PCI)) { + dev->Irq = device_get_config_int("irq"); + dev->DmaChannel = device_get_config_int("dma"); + } dev->HostID = 7; /* default HA ID */ dev->setup_info_len = sizeof(buslogic_setup_t); dev->max_id = 7; dev->int_geom_writable = 1; dev->cdrom_boot = 0; + dev->bit32 = 0; bl->chip = info->local; bl->PCIBase = 0; @@ -1308,6 +1454,9 @@ buslogic_init(device_t *info) if (info->flags & DEVICE_PCI) { bios_rom_addr = 0xd8000; bl->has_bios = device_get_config_int("bios"); + } else if (info->flags & DEVICE_MCA) { + bios_rom_addr = 0xd8000; + bl->has_bios = 1; } else { bios_rom_addr = device_get_config_hex20("bios_addr"); bl->has_bios = !!bios_rom_addr; @@ -1326,10 +1475,6 @@ buslogic_init(device_t *info) strcpy(dev->vendor, "BusLogic"); - if ((dev->Base != 0) && !(dev->bus & DEVICE_MCA)) { - x54x_io_set(dev, dev->Base); - } - switch(bl->chip) { case CHIP_BUSLOGIC_ISA_542: @@ -1354,19 +1499,32 @@ buslogic_init(device_t *info) has_scam_rom = 0; dev->fw_rev = "AA421E"; break; -#ifdef BUSLOGIC_NOT_WORKING case CHIP_BUSLOGIC_MCA: strcpy(dev->name, "BT-640A"); - bios_rom_name = L"roms/scsi/buslogic/BT-640_BIOS.rom"; + bios_rom_name = L"roms/scsi/buslogic/BT-640A_BIOS.rom"; + bios_rom_size = 0x4000; + bios_rom_mask = 0x3fff; + has_autoscsi_rom = 0; + has_scam_rom = 0; + dev->fw_rev = "BA150"; + dev->bit32 = 1; + bl->fAggressiveRoundRobinMode = 1; + dev->pos_regs[0] = 0x08; /* MCA board ID */ + dev->pos_regs[1] = 0x07; + mca_add(buslogic_mca_read, buslogic_mca_write, dev); + break; + case CHIP_BUSLOGIC_VLB: + strcpy(dev->name, "BT-445S"); + bios_rom_name = L"roms/scsi/buslogic/BT-445S_BIOS.rom"; bios_rom_size = 0x4000; bios_rom_mask = 0x3fff; has_autoscsi_rom = 1; - autoscsi_rom_name = L"roms/scsi/buslogic/BT-640_AutoSCSI.rom"; + autoscsi_rom_name = L"roms/scsi/buslogic/BT-445S_AutoSCSI.rom"; autoscsi_rom_size = 0x4000; has_scam_rom = 0; - dev->fw_rev = "BA421E"; + dev->fw_rev = "AA421E"; + dev->bit32 = 1; break; -#endif case CHIP_BUSLOGIC_PCI: strcpy(dev->name, "BT-958D"); bios_rom_name = L"roms/scsi/buslogic/BT-958D_BIOS.rom"; @@ -1380,9 +1538,14 @@ buslogic_init(device_t *info) scam_rom_size = 0x0200; dev->fw_rev = "AA507B"; dev->cdrom_boot = 1; + dev->bit32 = 1; break; } + if ((dev->Base != 0) && !(dev->bus & DEVICE_MCA)) { + x54x_io_set(dev, dev->Base); + } + memset(bl->AutoSCSIROM, 0xff, 32768); memset(bl->SCAMData, 0x00, 65536); @@ -1435,15 +1598,16 @@ buslogic_init(device_t *info) x54x_mem_init(dev, 0xfffd0000); x54x_mem_disable(dev); - - mem_mapping_disable(&bl->bios.mapping); } + + if ((bl->chip == CHIP_BUSLOGIC_MCA) || (bl->chip == CHIP_BUSLOGIC_PCI)) + mem_mapping_disable(&bl->bios.mapping); buslogic_log("Buslogic on port 0x%04X\n", dev->Base); x54x_device_reset(dev); - if (bl->chip != CHIP_BUSLOGIC_ISA_542) { + if ((bl->chip != CHIP_BUSLOGIC_ISA_542) && (bl->chip != CHIP_BUSLOGIC_MCA)) { BuslogicInitializeLocalRAM(bl); BuslogicInitializeAutoSCSIRam(dev); } @@ -1605,6 +1769,24 @@ device_t buslogic_545s_device = { BT_ISA_Config }; +device_t buslogic_640a_device = { + "Buslogic BT-640A MCA", + DEVICE_MCA, + CHIP_BUSLOGIC_MCA, + buslogic_init, x54x_close, NULL, + NULL, NULL, NULL, NULL, + NULL +}; + +device_t buslogic_445s_device = { + "Buslogic BT-445S ISA", + DEVICE_VLB, + CHIP_BUSLOGIC_VLB, + buslogic_init, x54x_close, NULL, + NULL, NULL, NULL, NULL, + BT_ISA_Config +}; + device_t buslogic_pci_device = { "Buslogic BT-958D PCI", DEVICE_PCI, diff --git a/src/scsi/scsi_buslogic.h b/src/scsi/scsi_buslogic.h index 398e3db25..4383ad640 100644 --- a/src/scsi/scsi_buslogic.h +++ b/src/scsi/scsi_buslogic.h @@ -22,6 +22,8 @@ extern device_t buslogic_device; extern device_t buslogic_545s_device; +extern device_t buslogic_640a_device; +extern device_t buslogic_445s_device; extern device_t buslogic_pci_device; extern void BuslogicDeviceReset(void *p); diff --git a/src/scsi/scsi_device.c b/src/scsi/scsi_device.c index 73e3e0789..214e0c74b 100644 --- a/src/scsi/scsi_device.c +++ b/src/scsi/scsi_device.c @@ -8,10 +8,11 @@ * * The generic SCSI device command handler. * - * Version: @(#)scsi_device.c 1.0.7 2017/10/10 + * Version: @(#)scsi_device.c 1.0.8 2017/10/17 * * Authors: Miran Grca, * Fred N. van Kempen, + * * Copyright 2016,2017 Miran Grca. * Copyright 2017 Fred N. van Kempen. */ @@ -19,6 +20,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../device.h" #include "../cdrom/cdrom.h" diff --git a/src/scsi/scsi_disk.c b/src/scsi/scsi_disk.c index 5b2390abc..a0d36861a 100644 --- a/src/scsi/scsi_disk.c +++ b/src/scsi/scsi_disk.c @@ -6,9 +6,10 @@ * * Emulation of SCSI fixed and removable disks. * - * Version: @(#)scsi_disk.c 1.0.16 2017/10/16 + * Version: @(#)scsi_disk.c 1.0.18 2017/10/19 * * Author: Miran Grca, + * * Copyright 2017 Miran Grca. */ #include @@ -446,13 +447,13 @@ uint8_t scsi_hd_mode_sense_pages_saved[HDD_NUM][0x40][0x40] = [0x30] = { 0xB0, 0x16, '8', '6', 'B', 'o', 'x', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' } } }; -#ifdef ENABLE_SCSI_HD_LOG -int scsi_hd_do_log = ENABLE_SCSI_HD_LOG; +#ifdef ENABLE_SCSI_DISK_LOG +int scsi_hd_do_log = ENABLE_SCSI_DISK_LOG; #endif void scsi_hd_log(const char *format, ...) { -#ifdef ENABLE_SCSI_HD_LOG +#ifdef ENABLE_SCSI_DISK_LOG if (scsi_hd_do_log) { va_list ap; diff --git a/src/scsi/scsi_ncr5380.c b/src/scsi/scsi_ncr5380.c index 5f2f24ee2..4fc1bef6e 100644 --- a/src/scsi/scsi_ncr5380.c +++ b/src/scsi/scsi_ncr5380.c @@ -9,7 +9,7 @@ * Implementation of the NCR 5380 series of SCSI Host Adapters * made by NCR. These controllers were designed for the ISA bus. * - * Version: @(#)scsi_ncr5380.c 1.0.3 2017/10/10 + * Version: @(#)scsi_ncr5380.c 1.0.5 2017/10/19 * * Authors: Sarah Walker, * TheCollector1995, @@ -20,26 +20,23 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../io.h" -#include "../mca.h" -#include "../mem.h" -#include "../mca.h" -#include "../rom.h" -#include "../nvr.h" #include "../dma.h" #include "../pic.h" -#include "../timer.h" +#include "../mca.h" +#include "../mem.h" +#include "../rom.h" +#include "../nvr.h" #include "../device.h" +#include "../timer.h" #include "../plat.h" #include "scsi.h" #include "scsi_device.h" #include "scsi_ncr5380.h" -//#define ENABLE_NCR5380_LOG 1 - - #define LCS6821N_ROM L"roms/scsi/ncr5380/Longshine LCS-6821N - BIOS version 1.04.bin" #define RT1000B_ROM L"roms/scsi/ncr5380/Rancho_RT1000_RTBios_version_8.10R.bin" #define T130B_ROM L"roms/scsi/ncr5380/trantor_t130b_bios_v2.14.bin" @@ -155,7 +152,7 @@ int ncr5380_do_log = ENABLE_NCR5380_LOG; static void ncr_log(const char *fmt, ...) { -#if ENABLE_NCR5380_LOG +#ifdef ENABLE_NCR5380_LOG va_list ap; if (ncr5380_do_log) { diff --git a/src/scsi/scsi_x54x.c b/src/scsi/scsi_x54x.c index cc2a982cc..417633e04 100644 --- a/src/scsi/scsi_x54x.c +++ b/src/scsi/scsi_x54x.c @@ -11,7 +11,7 @@ * series of SCSI Host Adapters made by Mylex. * These controllers were designed for various buses. * - * Version: @(#)scsi_x54x.c 1.0.2 2017/10/16 + * Version: @(#)scsi_x54x.c 1.0.3 2017/10/19 * * Authors: TheCollector1995, * Miran Grca, @@ -26,18 +26,18 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../io.h" +#include "../dma.h" +#include "../pic.h" +#include "../pci.h" #include "../mca.h" #include "../mem.h" -#include "../mca.h" #include "../rom.h" #include "../nvr.h" -#include "../dma.h" -#include "../pci.h" -#include "../pic.h" -#include "../timer.h" #include "../device.h" +#include "../timer.h" #include "../plat.h" #include "scsi.h" #include "scsi_device.h" @@ -50,12 +50,23 @@ static void x54x_cmd_thread(void *priv); -static thread_t *poll_tid; -static int busy; +static volatile +thread_t *poll_tid; +static volatile +int busy; -static event_t *evt; +static volatile +event_t *evt; +static volatile +event_t *wait_evt; -static event_t *poll_complete; +static volatile +event_t *wake_poll_thread; +static volatile +event_t *thread_started; + +static volatile +x54x_t *x54x_dev; #ifdef ENABLE_X54X_LOG @@ -66,7 +77,7 @@ int x54x_do_log = ENABLE_X54X_LOG; static void x54x_log(const char *fmt, ...) { -#if ENABLE_X54X_LOG +#ifdef ENABLE_X54X_LOG va_list ap; if (x54x_do_log) { @@ -1053,7 +1064,7 @@ x54x_scsi_cmd(x54x_t *dev) x54x_log("SCSIStatus = %02X\n", SCSIStatus); if (temp_cdb[0] == 0x42) { - thread_wait_event(evt, 10); + thread_wait_event((event_t *) evt, 10); } } @@ -1233,7 +1244,10 @@ x54x_mbo_process(x54x_t *dev) } } - dev->MailboxReq--; + if (dev->MailboxIsBIOS) + dev->BIOSMailboxReq--; + else + dev->MailboxReq--; return 1; } @@ -1284,31 +1298,35 @@ x54x_cmd_done(x54x_t *dev, int suppress); void x54x_wait_for_poll(void) { - if (x54x_busy()) { - thread_wait_event(poll_complete, -1); + if (x54x_is_busy()) { + thread_wait_event((event_t *) wake_poll_thread, -1); } - thread_reset_event(poll_complete); + thread_reset_event((event_t *) wake_poll_thread); } static void x54x_cmd_thread(void *priv) { - x54x_t *dev = (x54x_t *)priv; + x54x_t *dev = (x54x_t *) x54x_dev; + + thread_set_event((event_t *) thread_started); x54x_log("Polling thread started\n"); - while (1) + while (x54x_dev) { + scsi_mutex_wait(1); + if ((dev->Status & STAT_INIT) || (!dev->MailboxInit && !dev->BIOSMailboxInit) || (!dev->MailboxReq && !dev->BIOSMailboxReq)) { /* If we did not get anything, wait a while. */ - thread_wait_event(evt, 10); + thread_wait_event((event_t *) wait_evt, 10); + + scsi_mutex_wait(0); continue; } - startscsi(); - - if (!(dev->Status & STAT_INIT) && dev->MailboxInit && dev->MailboxReq) + if (!(x54x_dev->Status & STAT_INIT) && x54x_dev->MailboxInit && dev->MailboxReq) { x54x_wait_for_poll(); @@ -1319,34 +1337,19 @@ x54x_cmd_thread(void *priv) dev->ven_thread(dev); } - endscsi(); + scsi_mutex_wait(0); } - if (poll_tid) { - thread_kill(poll_tid); - poll_tid = NULL; - } - - if (poll_complete) { - thread_destroy_event(poll_complete); - poll_complete = NULL; - } - - if (evt) { - thread_destroy_event(evt); - evt = NULL; - } - - scsi_mutex_close(); - x54x_log("%s: Callback: polling stopped.\n", dev->name); } void -x54x_busy_set(void) +x54x_busy(uint8_t set) { - busy = 1; + busy = !!set; + if (!set) + thread_set_event((event_t *) wake_poll_thread); } @@ -1360,21 +1363,20 @@ x54x_thread_start(x54x_t *dev) } -void -x54x_busy_clear(void) -{ - busy = 0; - x54x_log("Thread set event - poll complete\n"); - thread_set_event(poll_complete); -} - uint8_t -x54x_busy(void) +x54x_is_busy(void) { return !!busy; } +void +x54x_set_wait_event(void) +{ + thread_set_event((event_t *) wait_evt); +} + + static uint8_t x54x_in(uint16_t port, void *priv) { @@ -1406,6 +1408,9 @@ x54x_in(uint16_t port, void *priv) break; } +#if 0 + x54x_log("%s: Read Port 0x%02X, Value %02X\n", dev->name, port, ret); +#endif return(ret); } @@ -1450,8 +1455,7 @@ x54x_reset_poll(void *priv) { x54x_t *dev = (x54x_t *)priv; - dev->Status &= ~STAT_STST; - dev->Status |= STAT_IDLE; + dev->Status = STAT_INIT | STAT_IDLE; dev->ResetCB = 0LL; } @@ -1460,22 +1464,22 @@ x54x_reset_poll(void *priv) static void x54x_reset(x54x_t *dev) { + clear_irq(dev); dev->Geometry = 0x80; dev->Command = 0xFF; dev->CmdParam = 0; dev->CmdParamLeft = 0; - dev->IrqEnabled = 1; - dev->MailboxCount = 0; - dev->MailboxOutPosCur = 0; + dev->Mbx24bit = 1; dev->MailboxInPosCur = 0; dev->MailboxOutInterrupts = 0; dev->PendingInterrupt = 0; + dev->IrqEnabled = 1; + dev->MailboxCount = 0; + dev->MailboxOutPosCur = 0; if (dev->ven_reset) { dev->ven_reset(dev); } - - clear_irq(dev); } @@ -1520,32 +1524,31 @@ x54x_out(uint16_t port, uint8_t val, void *priv) switch (port & 3) { case 0: if ((val & CTRL_HRST) || (val & CTRL_SRST)) { - x54x_busy_set(); + x54x_busy(1); reset = (val & CTRL_HRST); x54x_log("Reset completed = %x\n", reset); x54x_reset_ctrl(dev, reset); x54x_log("Controller reset: "); - x54x_busy_clear(); + x54x_busy(0); break; } if (val & CTRL_IRST) { - x54x_busy_set(); + x54x_busy(1); clear_irq(dev); x54x_log("Interrupt reset: "); - x54x_busy_clear(); + x54x_busy(0); } break; case 1: /* Fast path for the mailbox execution command. */ if ((val == CMD_START_SCSI) && (dev->Command == 0xff)) { - x54x_busy_set(); + x54x_busy(1); dev->MailboxReq++; - - x54x_thread_start(dev); + x54x_set_wait_event(); x54x_log("Start SCSI command: "); - x54x_busy_clear(); + x54x_busy(0); return; } if (dev->ven_fast_cmds) { @@ -1612,7 +1615,7 @@ x54x_out(uint16_t port, uint8_t val, void *priv) break; case CMD_MBINIT: /* mailbox initialization */ - x54x_busy_set(); + x54x_busy(1); dev->Mbx24bit = 1; mbi = (MailboxInit_t *)dev->CmdBuf; @@ -1631,7 +1634,7 @@ x54x_out(uint16_t port, uint8_t val, void *priv) dev->Status &= ~STAT_INIT; dev->DataReplyLeft = 0; x54x_log("Mailbox init: "); - x54x_busy_clear(); + x54x_busy(0); break; case CMD_BIOSCMD: /* execute BIOS */ @@ -1661,6 +1664,7 @@ x54x_out(uint16_t port, uint8_t val, void *priv) case CMD_INQUIRY: /* Inquiry */ memcpy(dev->DataBuf, dev->fw_rev, 4); + x54x_log("Adapter inquiry: %c %c %c %c\n", dev->fw_rev[0], dev->fw_rev[1], dev->fw_rev[2], dev->fw_rev[3]); dev->DataReplyLeft = 4; break; @@ -1699,13 +1703,14 @@ x54x_out(uint16_t port, uint8_t val, void *priv) case CMD_RETDEVS: /* return Installed Devices */ memset(dev->DataBuf, 0x00, 8); + + if (dev->ven_get_host_id) + host_id = dev->ven_get_host_id(dev); + for (i=0; iDataBuf[i] = 0x00; /* Skip the HA .. */ - if (dev->ven_get_host_id) - host_id = dev->ven_get_host_id(dev); - if (i == host_id) continue; for (j=0; jDataBuf[2] = dev->ven_get_host_id(dev); else dev->DataBuf[2] = dev->HostID; + x54x_log("Configuration data: %02X %02X %02X\n", dev->DataBuf[0], dev->DataBuf[1], dev->DataBuf[2]); dev->DataReplyLeft = 3; break; @@ -1857,7 +1863,14 @@ x54x_writel(uint32_t port, uint32_t val, void *priv) void x54x_io_set(x54x_t *dev, uint32_t base) { - if (dev->bus & DEVICE_PCI) { + int bit32 = 0; + + if (dev->bus & DEVICE_PCI) + bit32 = 1; + else if ((dev->bus & DEVICE_MCA) && dev->bit32) + bit32 = 1; + + if (bit32) { x54x_log("x54x: [PCI] Setting I/O handler at %04X\n", base); io_sethandler(base, 4, x54x_in, x54x_inw, x54x_inl, @@ -1874,9 +1887,16 @@ x54x_io_set(x54x_t *dev, uint32_t base) void x54x_io_remove(x54x_t *dev, uint32_t base) { + int bit32 = 0; + + if (dev->bus & DEVICE_PCI) + bit32 = 1; + else if ((dev->bus & DEVICE_MCA) && dev->bit32) + bit32 = 1; + x54x_log("x54x: Removing I/O handler at %04X\n", base); - if (dev->bus & DEVICE_PCI) { + if (bit32) { io_removehandler(base, 4, x54x_in, x54x_inw, x54x_inl, x54x_out, x54x_outw, x54x_outl, dev); @@ -1891,7 +1911,14 @@ x54x_io_remove(x54x_t *dev, uint32_t base) void x54x_mem_init(x54x_t *dev, uint32_t addr) { - if (dev->bus & DEVICE_PCI) { + int bit32 = 0; + + if (dev->bus & DEVICE_PCI) + bit32 = 1; + else if ((dev->bus & DEVICE_MCA) && dev->bit32) + bit32 = 1; + + if (bit32) { mem_mapping_add(&dev->mmio_mapping, addr, 0x20, x54x_read, x54x_readw, x54x_readl, x54x_write, x54x_writew, x54x_writel, @@ -1943,12 +1970,19 @@ x54x_init(device_t *info) timer_add(x54x_reset_poll, &dev->ResetCB, &dev->ResetCB, dev); - scsi_mutex_init(); + x54x_dev = dev; - poll_complete = thread_create_event(); + scsi_mutex(1); + + wake_poll_thread = thread_create_event(); + thread_started = thread_create_event(); /* Create a waitable event. */ evt = thread_create_event(); + wait_evt = thread_create_event(); + + x54x_thread_start(dev); + thread_wait_event((event_t *) thread_started, -1); return(dev); } @@ -1961,6 +1995,20 @@ x54x_close(void *priv) if (dev) { + x54x_dev = NULL; + + /* Tell the thread to terminate. */ + if (poll_tid != NULL) { + x54x_busy(0); + + x54x_log("Waiting for SCSI thread to end...\n"); + /* Wait for the end event. */ + thread_wait((event_t *) poll_tid, -1); + x54x_log("SCSI thread ended\n"); + + poll_tid = NULL; + } + dev->MailboxInit = dev->BIOSMailboxInit = 0; dev->MailboxCount = dev->BIOSMailboxCount = 0; dev->MailboxReq = dev->BIOSMailboxReq = 0; @@ -1968,22 +2016,27 @@ x54x_close(void *priv) if (dev->ven_data) free(dev->ven_data); - if (poll_tid) { - thread_kill(poll_tid); - poll_tid = NULL; - } - - if (poll_complete) { - thread_destroy_event(poll_complete); - poll_complete = NULL; - } - - if (evt) { - thread_destroy_event(evt); + if (wait_evt) { + thread_destroy_event((event_t *) evt); evt = NULL; } - scsi_mutex_close(); + if (evt) { + thread_destroy_event((event_t *) evt); + evt = NULL; + } + + if (thread_started) { + thread_destroy_event((event_t *) thread_started); + thread_started = NULL; + } + + if (wake_poll_thread) { + thread_destroy_event((event_t *) wake_poll_thread); + wake_poll_thread = NULL; + } + + scsi_mutex(0); if (dev->nvr != NULL) free(dev->nvr); diff --git a/src/scsi/scsi_x54x.h b/src/scsi/scsi_x54x.h index 86cad8256..9f850f162 100644 --- a/src/scsi/scsi_x54x.h +++ b/src/scsi/scsi_x54x.h @@ -399,6 +399,9 @@ typedef struct { uint8_t shram_mode; + uint8_t sync; + uint8_t parity; + volatile uint8_t dma_buffer[128]; @@ -420,6 +423,7 @@ typedef struct { uint8_t setup_info_len; uint8_t max_id; uint8_t pci_slot; + uint8_t bit32; mem_mapping_t mmio_mapping; @@ -488,10 +492,10 @@ typedef struct extern void x54x_reset_ctrl(x54x_t *dev, uint8_t Reset); -extern void x54x_busy_set(void); +extern void x54x_busy(uint8_t set); extern void x54x_thread_start(x54x_t *dev); -extern void x54x_busy_clear(void); -extern uint8_t x54x_busy(void); +extern void x54x_set_wait_event(void); +extern uint8_t x54x_is_busy(void); extern void x54x_buf_alloc(uint8_t id, uint8_t lun, int length); extern void x54x_buf_free(uint8_t id, uint8_t lun); extern uint8_t x54x_mbo_process(x54x_t *dev); diff --git a/src/serial.c b/src/serial.c index 8470f7428..431a89bb5 100644 --- a/src/serial.c +++ b/src/serial.c @@ -3,6 +3,7 @@ #include #include #include +#include "86box.h" #include "ibm.h" #include "io.h" #include "pic.h" diff --git a/src/sio_detect.c b/src/sio_detect.c index a51fd9006..ffa6507bd 100644 --- a/src/sio_detect.c +++ b/src/sio_detect.c @@ -2,6 +2,7 @@ #include #include #include +#include "86box.h" #include "ibm.h" #include "io.h" #include "floppy/floppy.h" diff --git a/src/sio_fdc37c665.c b/src/sio_fdc37c665.c index c9cef0759..d140da5e2 100644 --- a/src/sio_fdc37c665.c +++ b/src/sio_fdc37c665.c @@ -8,10 +8,11 @@ * * Implementation of the SMC FDC37C665 Super I/O Chip. * - * Version: @(#)sio_fdc37c665.c 1.0.6 2017/09/30 + * Version: @(#)sio_fdc37c665.c 1.0.7 2017/10/16 * * Authors: Sarah Walker, * Miran Grca, + * * Copyright 2008-2017 Sarah Walker. * Copyright 2016,2017 Miran Grca. */ @@ -19,6 +20,7 @@ #include #include #include +#include "86box.h" #include "ibm.h" #include "io.h" #include "device.h" @@ -175,6 +177,8 @@ void fdc37c665_write(uint16_t port, uint8_t val, void *priv) if (val == 0xaa) write_lock(val); else + fdc37c665_curreg = val; +#if 0 if (fdc37c665_curreg != 0) { fdc37c665_curreg = val & 0xf; @@ -184,9 +188,13 @@ void fdc37c665_write(uint16_t port, uint8_t val, void *priv) /* Hardcode the IDE to AT type. */ fdc37c665_curreg = (val & 0xf) | 2; } +#endif } else { + if (fdc37c665_curreg > 15) + return; + valxor = val ^ fdc37c665_regs[fdc37c665_curreg]; fdc37c665_regs[fdc37c665_curreg] = val; diff --git a/src/sio_fdc37c669.c b/src/sio_fdc37c669.c index bfff245b0..6ac8762cb 100644 --- a/src/sio_fdc37c669.c +++ b/src/sio_fdc37c669.c @@ -8,7 +8,7 @@ * * Implementation of the SMC FDC37C669 Super I/O Chip. * - * Version: @(#)sio_fdc37c669.c 1.0.4 2017/09/30 + * Version: @(#)sio_fdc37c669.c 1.0.5 2017/10/16 * * Author: Miran Grca, * Copyright 2016,2017 Miran Grca. @@ -17,6 +17,7 @@ #include #include #include +#include "86box.h" #include "ibm.h" #include "io.h" #include "device.h" diff --git a/src/sio_fdc37c932fr.c b/src/sio_fdc37c932fr.c index 205cfde23..bb165d72a 100644 --- a/src/sio_fdc37c932fr.c +++ b/src/sio_fdc37c932fr.c @@ -8,7 +8,7 @@ * * Implementation of the SMC FDC37C932FR Super I/O Chip. * - * Version: @(#)sio_fdc37c932fr.c 1.0.5 2017/09/30 + * Version: @(#)sio_fdc37c932fr.c 1.0.6 2017/10/16 * * Author: Miran Grca, * Copyright 2016,2017 Miran Grca. @@ -17,6 +17,7 @@ #include #include #include +#include "86box.h" #include "ibm.h" #include "io.h" #include "device.h" diff --git a/src/sio_pc87306.c b/src/sio_pc87306.c index c955c372e..9a6c8a7d4 100644 --- a/src/sio_pc87306.c +++ b/src/sio_pc87306.c @@ -8,7 +8,7 @@ * * Emulation of the NatSemi PC87306 Super I/O chip. * - * Version: @(#)sio_pc87306.c 1.0.5 2017/09/30 + * Version: @(#)sio_pc87306.c 1.0.6 2017/10/16 * * Author: Miran Grca, * Copyright 2016,2017 Miran Grca. @@ -17,6 +17,7 @@ #include #include #include +#include "86box.h" #include "ibm.h" #include "io.h" #include "device.h" @@ -178,7 +179,7 @@ void pc87306_write(uint16_t port, uint8_t val, void *priv) { val = 0x4b; } - if (pc87306_curreg <= 28) valxor = val ^ pc87306_regs[pc87306_curreg]; + valxor = val ^ pc87306_regs[pc87306_curreg]; tries = 0; if ((pc87306_curreg == 0x19) && !(pc87306_regs[0x1B] & 0x40)) { diff --git a/src/sio_um8669f.c b/src/sio_um8669f.c index f94d3c92e..9f27fd97b 100644 --- a/src/sio_um8669f.c +++ b/src/sio_um8669f.c @@ -25,6 +25,7 @@ PnP registers : #include #include #include +#include "86box.h" #include "ibm.h" #include "io.h" #include "lpt.h" diff --git a/src/sio_w83877f.c b/src/sio_w83877f.c index d63414cc6..65cc05c74 100644 --- a/src/sio_w83877f.c +++ b/src/sio_w83877f.c @@ -11,7 +11,7 @@ * Winbond W83877F Super I/O Chip * Used by the Award 430HX * - * Version: @(#)sio_w83877f.c 1.0.3 2017/09/24 + * Version: @(#)sio_w83877f.c 1.0.4 2017/10/16 * * Author: Miran Grca, * Copyright 2016,2017 Miran Grca. @@ -20,6 +20,7 @@ #include #include #include +#include "86box.h" #include "ibm.h" #include "io.h" #include "mem.h" diff --git a/src/sound/midi.c b/src/sound/midi.c index 1c70b252d..9d07f3b1b 100644 --- a/src/sound/midi.c +++ b/src/sound/midi.c @@ -3,8 +3,9 @@ #include #include #include -#include "../device.h" +#include "../86box.h" #include "../ibm.h" +#include "../device.h" #include "../plat.h" #include "../plat_midi.h" #include "midi.h" @@ -177,10 +178,10 @@ void midi_write(uint8_t val) if (midi_sysex_start) { - passed_ticks = get_ticks() - midi_sysex_start; + passed_ticks = plat_get_ticks() - midi_sysex_start; if (passed_ticks < midi_sysex_delay) { - delay_ms(midi_sysex_delay - passed_ticks); + plat_delay_ms(midi_sysex_delay - passed_ticks); } } @@ -229,7 +230,7 @@ void midi_write(uint8_t val) else midi_sysex_delay = (unsigned int) (((float) (midi_pos) * 1.25f) * 1000.0f / 3125.0f) + 2; - midi_sysex_start = get_ticks(); + midi_sysex_start = plat_get_ticks(); } } } diff --git a/src/sound/midi_fluidsynth.c b/src/sound/midi_fluidsynth.c index cce894675..2e63823a5 100644 --- a/src/sound/midi_fluidsynth.c +++ b/src/sound/midi_fluidsynth.c @@ -6,6 +6,7 @@ #include #include #include +#include "../86box.h" #include "../config.h" #include "../device.h" #include "../plat.h" diff --git a/src/sound/midi_mt32.c b/src/sound/midi_mt32.c index eab3e7dab..d1ddb78bf 100644 --- a/src/sound/midi_mt32.c +++ b/src/sound/midi_mt32.c @@ -4,6 +4,7 @@ #include #include #include "munt/c_interface/c_interface.h" +#include "../86box.h" #include "../ibm.h" #include "../device.h" #include "../mem.h" diff --git a/src/sound/midi_system.c b/src/sound/midi_system.c index 982049bdc..209889401 100644 --- a/src/sound/midi_system.c +++ b/src/sound/midi_system.c @@ -3,6 +3,7 @@ #include #include #include +#include "../86box.h" #include "../device.h" #include "../plat.h" #include "../plat_midi.h" diff --git a/src/sound/munt/SampleRateConverter_dummy.cpp b/src/sound/munt/SampleRateConverter_dummy.cpp index 84d51e736..9094f1514 100644 --- a/src/sound/munt/SampleRateConverter_dummy.cpp +++ b/src/sound/munt/SampleRateConverter_dummy.cpp @@ -14,17 +14,20 @@ * along with this program. If not, see . */ +#include +#include +#include "../../plat.h" #include "SampleRateConverter.h" #include "Synth.h" using namespace MT32Emu; -static inline void *createDelegate(Synth &synth, double targetSampleRate, SamplerateConversionQuality quality) { +static inline void *createDelegate(UNUSED(Synth &synth), UNUSED(double targetSampleRate), UNUSED(SamplerateConversionQuality quality)) { return 0; } -AnalogOutputMode SampleRateConverter::getBestAnalogOutputMode(double targetSampleRate) { +AnalogOutputMode SampleRateConverter::getBestAnalogOutputMode(UNUSED(double targetSampleRate)) { return AnalogOutputMode_COARSE; } diff --git a/src/sound/munt/config.h b/src/sound/munt/config.h index 9cbdf2bc6..5f5b6c9fb 100644 --- a/src/sound/munt/config.h +++ b/src/sound/munt/config.h @@ -35,4 +35,6 @@ */ #define MT32EMU_EXPORTS_TYPE 3 +#define MT32EMU_API_TYPE 0 + #endif diff --git a/src/sound/openal.c b/src/sound/openal.c index 1c80de8fd..1a0c1a311 100644 --- a/src/sound/openal.c +++ b/src/sound/openal.c @@ -13,6 +13,7 @@ # include # include #endif +#include "../86box.h" #include "../ibm.h" #include "sound.h" diff --git a/src/sound/snd_ad1848.c b/src/sound/snd_ad1848.c index 4a22e4c76..f670b7095 100644 --- a/src/sound/snd_ad1848.c +++ b/src/sound/snd_ad1848.c @@ -7,6 +7,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../dma.h" #include "../pic.h" diff --git a/src/sound/snd_adlib.c b/src/sound/snd_adlib.c index 964d6e475..e297dabaa 100644 --- a/src/sound/snd_adlib.c +++ b/src/sound/snd_adlib.c @@ -3,6 +3,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../io.h" #include "../mca.h" diff --git a/src/sound/snd_adlibgold.c b/src/sound/snd_adlibgold.c index 3c8a76c19..6b015ff0e 100644 --- a/src/sound/snd_adlibgold.c +++ b/src/sound/snd_adlibgold.c @@ -3,6 +3,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../io.h" #include "../dma.h" diff --git a/src/sound/snd_audiopci.c b/src/sound/snd_audiopci.c index a5eeb752f..331246225 100644 --- a/src/sound/snd_audiopci.c +++ b/src/sound/snd_audiopci.c @@ -1,7 +1,9 @@ -#include +#include #include #include #include +#include +#include "../86box.h" #include "../ibm.h" #include "../device.h" #include "../io.h" @@ -11,7 +13,8 @@ #include "sound.h" #include "snd_audiopci.h" -typedef struct es1371_t + +typedef struct { uint8_t pci_command, pci_serr; @@ -128,10 +131,10 @@ static void update_legacy(es1371_t *es1371); int audiopci_do_log = ENABLE_AUDIOPCI_LOG; #endif -void audiopci_log(const char *format, ...) +static void audiopci_log(const char *format, ...) { #ifdef ENABLE_AUDIOPCI_LOG - if (emu8k_audiopci_log) + if (audiopci_do_log) { va_list ap; va_start(ap, format); diff --git a/src/sound/snd_cms.c b/src/sound/snd_cms.c index 9f148a57f..7ddf04825 100644 --- a/src/sound/snd_cms.c +++ b/src/sound/snd_cms.c @@ -3,6 +3,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../io.h" #include "../device.h" @@ -26,6 +27,8 @@ typedef struct cms_t uint16_t noisefreq[2][2]; int noisecount[2][2]; int noisetype[2][2]; + + uint8_t latched_data; int16_t buffer[SOUNDBUFLEN * 2]; @@ -110,12 +113,16 @@ void cms_write(uint16_t addr, uint8_t val, void *p) int voice; int chip = (addr & 2) >> 1; - pclog("cms_write : addr %04X val %02X\n", addr, val); - - if (addr & 1) - cms->addrs[chip] = val & 31; - else + switch (addr & 0xf) { + case 1: + cms->addrs[0] = val & 31; + break; + case 3: + cms->addrs[1] = val & 31; + break; + + case 0: case 2: cms_update(cms); cms->regs[chip][cms->addrs[chip] & 31] = val; switch (cms->addrs[chip] & 31) @@ -144,18 +151,29 @@ void cms_write(uint16_t addr, uint8_t val, void *p) cms->noisetype[chip][1] = (val >> 4) & 3; break; } + break; + case 0x6: case 0x7: + cms->latched_data = val; + break; } } uint8_t cms_read(uint16_t addr, void *p) { cms_t *cms = (cms_t *)p; - int chip = (addr & 2) >> 1; - - if (addr & 1) - return cms->addrs[chip]; - - return cms->regs[chip][cms->addrs[chip] & 31]; + + switch (addr & 0xf) + { + case 0x1: + return cms->addrs[0]; + case 0x3: + return cms->addrs[1]; + case 0x4: + return 0x7f; + case 0xa: case 0xb: + return cms->latched_data; + } + return 0xff; } void *cms_init(device_t *info) @@ -164,7 +182,7 @@ void *cms_init(device_t *info) memset(cms, 0, sizeof(cms_t)); pclog("cms_init\n"); - io_sethandler(0x0220, 0x0004, cms_read, NULL, NULL, cms_write, NULL, NULL, cms); + io_sethandler(0x0220, 0x0010, cms_read, NULL, NULL, cms_write, NULL, NULL, cms); sound_add_handler(cms_get_buffer, cms); return cms; } diff --git a/src/sound/snd_emu8k.c b/src/sound/snd_emu8k.c index 0bd4e3122..2c2f61edd 100644 --- a/src/sound/snd_emu8k.c +++ b/src/sound/snd_emu8k.c @@ -6,6 +6,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../device.h" #include "../io.h" diff --git a/src/sound/snd_gus.c b/src/sound/snd_gus.c index 860c93e77..9c0a84ffb 100644 --- a/src/sound/snd_gus.c +++ b/src/sound/snd_gus.c @@ -3,6 +3,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../io.h" #include "../pic.h" diff --git a/src/sound/snd_lpt_dac.c b/src/sound/snd_lpt_dac.c index ed424250d..8730c2c8e 100644 --- a/src/sound/snd_lpt_dac.c +++ b/src/sound/snd_lpt_dac.c @@ -3,6 +3,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../cpu/cpu.h" #include "../lpt.h" diff --git a/src/sound/snd_lpt_dss.c b/src/sound/snd_lpt_dss.c index 8dfb1ddab..a3c914709 100644 --- a/src/sound/snd_lpt_dss.c +++ b/src/sound/snd_lpt_dss.c @@ -3,6 +3,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../cpu/cpu.h" #include "../timer.h" diff --git a/src/sound/snd_mpu401.c b/src/sound/snd_mpu401.c index 3506764e3..68d29a195 100644 --- a/src/sound/snd_mpu401.c +++ b/src/sound/snd_mpu401.c @@ -8,12 +8,13 @@ * * Roland MPU-401 emulation. * - * Version: @(#)snd_mpu401.c 1.0.3 2017/10/04 + * Version: @(#)snd_mpu401.c 1.0.5 2017/10/19 * * Authors: Sarah Walker, * DOSBox Team, * Miran Grca, * TheCollector1995, + * * Copyright 2008-2017 Sarah Walker. * Copyright 2008-2017 DOSBox Team. * Copyright 2016,2017 Miran Grca. @@ -24,6 +25,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../device.h" #include "../io.h" @@ -50,7 +52,7 @@ static int64_t mpu401_eoi_callback = 0LL; static int64_t mpu401_reset_callback = 0LL; #ifdef ENABLE_MPU401_LOG -static int mpu401_do_log = 1; +static int mpu401_do_log = ENABLE_MPU401_LOG; static char logfmt[512]; #endif diff --git a/src/sound/snd_opl.c b/src/sound/snd_opl.c index 990769d58..e65a73d52 100644 --- a/src/sound/snd_opl.c +++ b/src/sound/snd_opl.c @@ -6,6 +6,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../io.h" #include "../timer.h" diff --git a/src/sound/snd_pas16.c b/src/sound/snd_pas16.c index 6a39568dc..234bb7751 100644 --- a/src/sound/snd_pas16.c +++ b/src/sound/snd_pas16.c @@ -3,6 +3,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../io.h" #include "../pic.h" diff --git a/src/sound/snd_ps1.c b/src/sound/snd_ps1.c index 60a836995..9b62db6bf 100644 --- a/src/sound/snd_ps1.c +++ b/src/sound/snd_ps1.c @@ -3,6 +3,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../io.h" #include "../pic.h" diff --git a/src/sound/snd_pssj.c b/src/sound/snd_pssj.c index 395717350..763122850 100644 --- a/src/sound/snd_pssj.c +++ b/src/sound/snd_pssj.c @@ -3,6 +3,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../io.h" #include "../dma.h" diff --git a/src/sound/snd_resid.cc b/src/sound/snd_resid.cc index ef1d32854..a984323bd 100644 --- a/src/sound/snd_resid.cc +++ b/src/sound/snd_resid.cc @@ -3,6 +3,7 @@ #include #include #include "resid-fp/sid.h" +#include "../plat.h" #include "snd_resid.h" @@ -58,14 +59,14 @@ void *sid_init(void) return (void *)psid; } -void sid_close(void *p) +void sid_close(UNUSED(void *p)) { // psid_t *psid = (psid_t *)p; delete psid->sid; // free(psid); } -void sid_reset(void *p) +void sid_reset(UNUSED(void *p)) { // psid_t *psid = (psid_t *)p; int c; @@ -77,7 +78,7 @@ void sid_reset(void *p) } -uint8_t sid_read(uint16_t addr, void *p) +uint8_t sid_read(uint16_t addr, UNUSED(void *p)) { // psid_t *psid = (psid_t *)p; @@ -85,7 +86,7 @@ uint8_t sid_read(uint16_t addr, void *p) // return 0xFF; } -void sid_write(uint16_t addr, uint8_t val, void *p) +void sid_write(uint16_t addr, uint8_t val, UNUSED(void *p)) { // psid_t *psid = (psid_t *)p; @@ -102,7 +103,7 @@ static void fillbuf2(int& count, int16_t *buf, int len) *buf = psid->last_sample; psid->last_sample = *buf; } -void sid_fillbuf(int16_t *buf, int len, void *p) +void sid_fillbuf(int16_t *buf, int len, UNUSED(void *p)) { // psid_t *psid = (psid_t *)p; int x = CLOCK_DELTA(len); diff --git a/src/sound/snd_sb.c b/src/sound/snd_sb.c index 05d5e179e..d7d4ad5fe 100644 --- a/src/sound/snd_sb.c +++ b/src/sound/snd_sb.c @@ -8,11 +8,12 @@ * * Sound Blaster emulation. * - * Version: @(#)sound_sb.c 1.0.2 2017/10/04 + * Version: @(#)sound_sb.c 1.0.3 2017/10/16 * * Authors: Sarah Walker, * Miran Grca, * TheCollector1995, + * * Copyright 2008-2017 Sarah Walker. * Copyright 2016,2017 Miran Grca. */ @@ -21,6 +22,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../io.h" #include "../mca.h" @@ -790,8 +792,22 @@ uint8_t sb_ct1745_mixer_read(uint16_t addr, void *p) } switch (mixer->index) { - case 0x00: case 0x04: case 0x0A: case 0x22: case 0x26: case 0x28: case 0x2E: + case 0x00: return mixer->regs[mixer->index]; + + /*SB Pro compatibility*/ + case 0x04: + return ((mixer->regs[0x33] >> 4) & 0x0f) | (mixer->regs[0x32] & 0xf0); + case 0x0a: + return (mixer->regs[0x2a] - 10) / 3; + case 0x22: + return ((mixer->regs[0x31] >> 4) & 0x0f) | (mixer->regs[0x30] & 0xf0); + case 0x26: + return ((mixer->regs[0x35] >> 4) & 0x0f) | (mixer->regs[0x34] & 0xf0); + case 0x28: + return ((mixer->regs[0x37] >> 4) & 0x0f) | (mixer->regs[0x36] & 0xf0); + case 0x2e: + return ((mixer->regs[0x39] >> 4) & 0x0f) | (mixer->regs[0x38] & 0xf0); case 0x48: // Undocumented. The Creative Windows Mixer calls this after calling 3C (input selector). even when writing. diff --git a/src/sound/snd_sb_dsp.c b/src/sound/snd_sb_dsp.c index e26c93f78..e1216769d 100644 --- a/src/sound/snd_sb_dsp.c +++ b/src/sound/snd_sb_dsp.c @@ -9,6 +9,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../io.h" #include "../pic.h" diff --git a/src/sound/snd_sn76489.c b/src/sound/snd_sn76489.c index 7f7d02f2f..09cbe28e4 100644 --- a/src/sound/snd_sn76489.c +++ b/src/sound/snd_sn76489.c @@ -4,6 +4,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../io.h" #include "../device.h" diff --git a/src/sound/snd_speaker.c b/src/sound/snd_speaker.c index 44d576941..3109d66e8 100644 --- a/src/sound/snd_speaker.c +++ b/src/sound/snd_speaker.c @@ -2,6 +2,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "sound.h" #include "snd_speaker.h" diff --git a/src/sound/snd_ssi2001.c b/src/sound/snd_ssi2001.c index cba259422..8161b4153 100644 --- a/src/sound/snd_ssi2001.c +++ b/src/sound/snd_ssi2001.c @@ -3,6 +3,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../io.h" #include "../device.h" diff --git a/src/sound/snd_wss.c b/src/sound/snd_wss.c index 7c47f38e4..c247c9903 100644 --- a/src/sound/snd_wss.c +++ b/src/sound/snd_wss.c @@ -8,6 +8,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../io.h" #include "../pic.h" diff --git a/src/sound/snd_ym7128.c b/src/sound/snd_ym7128.c index 354b8b3b0..7a74eac01 100644 --- a/src/sound/snd_ym7128.c +++ b/src/sound/snd_ym7128.c @@ -2,6 +2,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "snd_ym7128.h" diff --git a/src/sound/sound.c b/src/sound/sound.c index 2d3afd6d0..57da46ecf 100644 --- a/src/sound/sound.c +++ b/src/sound/sound.c @@ -8,7 +8,7 @@ * * Sound emulation core. * - * Version: @(#)sound.c 1.0.5 2017/10/10 + * Version: @(#)sound.c 1.0.6 2017/10/16 * * Authors: Sarah Walker, * Miran Grca, @@ -21,6 +21,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../device.h" #include "../timer.h" @@ -426,6 +427,22 @@ void sound_reset(void) } } +void sound_cd_thread_end(void) +{ + if (sound_cd_thread_h) { + pclog("Waiting for CD Audio thread to terminate...\n"); + thread_wait(sound_cd_thread_h, -1); + pclog("CD Audio thread terminated...\n"); + + if (sound_cd_event) { + thread_destroy_event(sound_cd_event); + sound_cd_event = NULL; + } + + sound_cd_thread_h = NULL; + } +} + void sound_cd_thread_reset(void) { int i = 0; @@ -446,9 +463,7 @@ void sound_cd_thread_reset(void) } else if (!available_cdrom_drives && cd_thread_enable) { - thread_destroy_event(sound_cd_event); - thread_kill(sound_cd_thread_h); - sound_cd_thread_h = NULL; + sound_cd_thread_end(); } cd_thread_enable = available_cdrom_drives ? 1 : 0; diff --git a/src/sound/sound.h b/src/sound/sound.h index 53e043cb6..5933e2b71 100644 --- a/src/sound/sound.h +++ b/src/sound/sound.h @@ -46,6 +46,7 @@ void sound_realloc_buffers(void); void sound_init(); void sound_reset(); +void sound_cd_thread_end(); void sound_cd_thread_reset(); void closeal(void); diff --git a/src/timer.c b/src/timer.c index 8313ebed6..6a7128f61 100644 --- a/src/timer.c +++ b/src/timer.c @@ -2,6 +2,7 @@ #include #include #include +#include "86box.h" #include "ibm.h" #include "timer.h" diff --git a/src/ui.h b/src/ui.h index 6b32fd7d4..54823da29 100644 --- a/src/ui.h +++ b/src/ui.h @@ -8,7 +8,7 @@ * * Define the various UI functions. * - * Version: @(#)ui.h 1.0.3 2017/10/14 + * Version: @(#)ui.h 1.0.5 2017/10/16 * * Authors: Miran Grca, * Fred N. van Kempen, @@ -41,6 +41,7 @@ extern "C" { extern int ui_msgbox(int type, void *arg); +extern void ui_check_menu_item(int id, int checked); /* Status Bar functions. */ #define SB_ICON_WIDTH 24 @@ -51,6 +52,7 @@ extern int ui_msgbox(int type, void *arg); #define SB_NETWORK 0x50 #define SB_TEXT 0x60 +extern wchar_t *ui_window_title(wchar_t *s); extern int ui_sb_find_part(int tag); extern void ui_sb_update_panes(void); extern void ui_sb_update_tip(int meaning); diff --git a/src/video/vid_ati18800.c b/src/video/vid_ati18800.c index 8794af217..ae1cec1d0 100644 --- a/src/video/vid_ati18800.c +++ b/src/video/vid_ati18800.c @@ -8,7 +8,7 @@ * * ATI 18800 emulation (VGA Edge-16) * - * Version: @(#)vid_ati18800.c 1.0.1 2017/10/10 + * Version: @(#)vid_ati18800.c 1.0.1 2017/10/16 * * Authors: Sarah Walker, * Miran Grca, @@ -21,6 +21,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../io.h" #include "../mem.h" diff --git a/src/video/vid_ati28800.c b/src/video/vid_ati28800.c index 99709def8..e2a99e0d8 100644 --- a/src/video/vid_ati28800.c +++ b/src/video/vid_ati28800.c @@ -8,7 +8,7 @@ * * ATI 28800 emulation (VGA Charger) * - * Version: @(#)vid_ati28800.c 1.0.1 2017/10/10 + * Version: @(#)vid_ati28800.c 1.0.1 2017/10/16 * * Authors: Sarah Walker, * Miran Grca, @@ -21,6 +21,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../io.h" #include "../mem.h" diff --git a/src/video/vid_ati68860_ramdac.c b/src/video/vid_ati68860_ramdac.c index c82dbc4bc..a304cd0d2 100644 --- a/src/video/vid_ati68860_ramdac.c +++ b/src/video/vid_ati68860_ramdac.c @@ -28,7 +28,7 @@ * 7 If set can remove "snow" in some cases * (A860_Delay_L ?) ?? * - * Version: @(#)vid_ati68860.c 1.0.1 2017/10/10 + * Version: @(#)vid_ati68860.c 1.0.1 2017/10/16 * * Authors: Sarah Walker, * Miran Grca, @@ -40,6 +40,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../mem.h" #include "video.h" diff --git a/src/video/vid_ati_eeprom.c b/src/video/vid_ati_eeprom.c index b2d5ae6c8..8ecb25e8e 100644 --- a/src/video/vid_ati_eeprom.c +++ b/src/video/vid_ati_eeprom.c @@ -8,7 +8,7 @@ * * Emulation of the EEPROM on select ATI cards. * - * Version: @(#)vid_ati_eeprom.c 1.0.1 2017/10/10 + * Version: @(#)vid_ati_eeprom.c 1.0.1 2017/10/16 * * Authors: Sarah Walker, * Miran Grca, @@ -20,6 +20,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../mem.h" #include "../nvr.h" diff --git a/src/video/vid_ati_mach64.c b/src/video/vid_ati_mach64.c index 3f707d8cf..a4d2f8ef1 100644 --- a/src/video/vid_ati_mach64.c +++ b/src/video/vid_ati_mach64.c @@ -8,7 +8,7 @@ * * ATi Mach64 graphics card emulation. * - * Version: @(#)vid_ati_mach64.c 1.0.4 2017/10/10 + * Version: @(#)vid_ati_mach64.c 1.0.5 2017/10/16 * * Authors: Sarah Walker, * Miran Grca, @@ -21,6 +21,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../device.h" #include "../io.h" @@ -879,7 +880,7 @@ static void fifo_thread(void *param) mach64->blitter_busy = 1; while (!FIFO_EMPTY) { - uint64_t start_time = timer_read(); + uint64_t start_time = plat_timer_read(); uint64_t end_time; fifo_entry_t *fifo = &mach64->fifo[mach64->fifo_read_idx & FIFO_MASK]; @@ -902,7 +903,7 @@ static void fifo_thread(void *param) if (FIFO_ENTRIES > 0xe000) thread_set_event(mach64->fifo_not_full_event); - end_time = timer_read(); + end_time = plat_timer_read(); mach64->blitter_time += end_time - start_time; } mach64->blitter_busy = 0; @@ -3422,7 +3423,7 @@ void mach64_add_status_info(char *s, int max_len, void *p) { mach64_t *mach64 = (mach64_t *)p; char temps[256]; - uint64_t new_time = timer_read(); + uint64_t new_time = plat_timer_read(); uint64_t status_diff = new_time - mach64->status_time; mach64->status_time = new_time; diff --git a/src/video/vid_bt485_ramdac.c b/src/video/vid_bt485_ramdac.c index ee97b6d60..1957d05b9 100644 --- a/src/video/vid_bt485_ramdac.c +++ b/src/video/vid_bt485_ramdac.c @@ -11,7 +11,7 @@ * Currently only a dummy stub for logging and passing output * to the generic SVGA handler. * - * Version: @(#)vid_bt485_ramdac.c 1.0.1 2017/10/10 + * Version: @(#)vid_bt485_ramdac.c 1.0.1 2017/10/16 * * Authors: Sarah Walker, * Miran Grca, @@ -23,6 +23,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../mem.h" #include "video.h" diff --git a/src/video/vid_cga.c b/src/video/vid_cga.c index 384a0a5c5..d6742e337 100644 --- a/src/video/vid_cga.c +++ b/src/video/vid_cga.c @@ -8,7 +8,7 @@ * * Emulation of the old and new IBM CGA graphics cards. * - * Version: @(#)vid_cga.c 1.0.5 2017/10/13 + * Version: @(#)vid_cga.c 1.0.8 2017/10/22 * * Authors: Sarah Walker, * Miran Grca, @@ -22,6 +22,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../io.h" #include "../mem.h" @@ -107,9 +108,6 @@ uint8_t cga_in(uint16_t addr, void *p) void cga_write(uint32_t addr, uint8_t val, void *p) { cga_t *cga = (cga_t *)p; - /* Horrible hack, I know, but it's the only way to fix the 440FX BIOS filling the VRAM with garbage until Tom fixes the memory emulation. */ - if ((cs == 0xE0000) && (cpu_state.pc == 0xBF2F) && (romset == ROM_440FX)) return; - if ((cs == 0xE0000) && (cpu_state.pc == 0xBF77) && (romset == ROM_440FX)) return; cga->vram[addr & 0x3fff] = val; if (cga->snow_enabled) @@ -398,19 +396,22 @@ void cga_poll(void *p) if (cga->cgamode & 1) x = (cga->crtc[1] << 3) + 16; else x = (cga->crtc[1] << 4) + 16; cga->lastline++; - if (x != xsize || (cga->lastline - cga->firstline) != ysize) + if ((x != xsize) || ((cga->lastline - cga->firstline) != ysize) || video_force_resize_get()) { xsize = x; ysize = cga->lastline - cga->firstline; if (xsize < 64) xsize = 656; if (ysize < 32) ysize = 200; - updatewindowsize(xsize, (ysize << 1) + 16); + set_screen_size(xsize, (ysize << 1) + 16); + + if (video_force_resize_get()) + video_force_resize_set(0); } if (cga->composite) video_blit_memtoscreen(0, cga->firstline - 4, 0, (cga->lastline - cga->firstline) + 8, xsize, (cga->lastline - cga->firstline) + 8); else - video_blit_memtoscreen_8(0, cga->firstline - 4, xsize, (cga->lastline - cga->firstline) + 8); + video_blit_memtoscreen_8(0, cga->firstline - 4, 0, (cga->lastline - cga->firstline) + 8, xsize, (cga->lastline - cga->firstline) + 8); frames++; video_res_x = xsize - 16; diff --git a/src/video/vid_cga_comp.c b/src/video/vid_cga_comp.c index 407e38726..da99a2442 100644 --- a/src/video/vid_cga_comp.c +++ b/src/video/vid_cga_comp.c @@ -9,7 +9,7 @@ * IBM CGA composite filter, borrowed from reenigne's DOSBox * patch and ported to C. * - * Version: @(#)vid_cga_comp.c 1.0.2 2017/10/10 + * Version: @(#)vid_cga_comp.c 1.0.2 2017/10/16 * * Authors: reenigne, * Miran Grca, @@ -23,6 +23,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../device.h" #include "../mem.h" diff --git a/src/video/vid_cl_gd.c b/src/video/vid_cl_gd.c index ffb58f4b3..0627301b5 100644 --- a/src/video/vid_cl_gd.c +++ b/src/video/vid_cl_gd.c @@ -8,7 +8,7 @@ * * Emulation of select Cirrus Logic cards. * - * Version: @(#)vid_cl_gd.c 1.0.1 2017/10/10 + * Version: @(#)vid_cl_gd.c 1.0.1 2017/10/16 * * Authors: Sarah Walker, * Miran Grca, @@ -21,6 +21,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../io.h" #include "../mem.h" diff --git a/src/video/vid_cl_gd_blit.c b/src/video/vid_cl_gd_blit.c index 28c58b692..2e4706f20 100644 --- a/src/video/vid_cl_gd_blit.c +++ b/src/video/vid_cl_gd_blit.c @@ -8,7 +8,7 @@ * * This is the CL-GD 5446 blitter, directly from QEMU. * - * Version: @(#)vid_cl_gd_blit.c 1.0.1 2017/10/10 + * Version: @(#)vid_cl_gd_blit.c 1.0.1 2017/10/16 * * Author: Miran Grca, * @@ -19,6 +19,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../io.h" #include "../mem.h" diff --git a/src/video/vid_cl_ramdac.c b/src/video/vid_cl_ramdac.c index d33d0a7eb..4a9644ff6 100644 --- a/src/video/vid_cl_ramdac.c +++ b/src/video/vid_cl_ramdac.c @@ -8,7 +8,7 @@ * * Emulation of the Cirrus Logic RAMDAC. * - * Version: @(#)vid_cl_ramdac.c 1.0.1 2017/10/10 + * Version: @(#)vid_cl_ramdac.c 1.0.1 2017/10/16 * * Author: Miran Grca, * @@ -18,6 +18,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../mem.h" #include "../rom.h" diff --git a/src/video/vid_colorplus.c b/src/video/vid_colorplus.c index df85e2f9e..337058c8a 100644 --- a/src/video/vid_colorplus.c +++ b/src/video/vid_colorplus.c @@ -8,7 +8,7 @@ * * Plantronics ColorPlus emulation. * - * Version: @(#)vid_colorplus.c 1.0.1 2017/10/10 + * Version: @(#)vid_colorplus.c 1.0.4 2017/10/22 * * Authors: Sarah Walker, * Miran Grca, @@ -22,6 +22,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../io.h" #include "../mem.h" @@ -320,13 +321,13 @@ void colorplus_poll(void *p) ysize = colorplus->cga.lastline - colorplus->cga.firstline; if (xsize < 64) xsize = 656; if (ysize < 32) ysize = 200; - updatewindowsize(xsize, (ysize << 1) + 16); + set_screen_size(xsize, (ysize << 1) + 16); } if (colorplus->cga.composite) video_blit_memtoscreen(0, colorplus->cga.firstline - 4, 0, (colorplus->cga.lastline - colorplus->cga.firstline) + 8, xsize, (colorplus->cga.lastline - colorplus->cga.firstline) + 8); else - video_blit_memtoscreen_8(0, colorplus->cga.firstline - 4, xsize, (colorplus->cga.lastline - colorplus->cga.firstline) + 8); + video_blit_memtoscreen_8(0, colorplus->cga.firstline - 4, 0, (colorplus->cga.lastline - colorplus->cga.firstline) + 8, xsize, (colorplus->cga.lastline - colorplus->cga.firstline) + 8); frames++; video_res_x = xsize - 16; diff --git a/src/video/vid_ega.c b/src/video/vid_ega.c index b199431f1..06fa96fa6 100644 --- a/src/video/vid_ega.c +++ b/src/video/vid_ega.c @@ -9,7 +9,7 @@ * Emulation of the EGA, Chips & Technologies SuperEGA, and * AX JEGA graphics cards. * - * Version: @(#)vid_ega.c 1.0.6 2017/10/10 + * Version: @(#)vid_ega.c 1.0.8 2017/10/18 * * Authors: Sarah Walker, * Miran Grca, @@ -23,6 +23,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../io.h" #include "../mem.h" @@ -663,7 +664,7 @@ void ega_poll(void *p) if (ega->interlace && !ega->oddeven) ega->lastline++; if (ega->interlace && ega->oddeven) ega->firstline--; - if ((x != xsize || (ega->lastline - ega->firstline + 1) != ysize) || update_overscan) + if ((x != xsize || (ega->lastline - ega->firstline + 1) != ysize) || update_overscan || video_force_resize_get()) { xsize = x; ysize = ega->lastline - ega->firstline + 1; @@ -686,9 +687,12 @@ void ega_poll(void *p) } if (ega->vres) - updatewindowsize(xsize + x_add_ex, (ysize << 1) + y_add_ex); + set_screen_size(xsize + x_add_ex, (ysize << 1) + y_add_ex); else - updatewindowsize(xsize + x_add_ex, ysize + y_add_ex); + set_screen_size(xsize + x_add_ex, ysize + y_add_ex); + + if (video_force_resize_get()) + video_force_resize_set(0); } if (enable_overscan) diff --git a/src/video/vid_ega_render.c b/src/video/vid_ega_render.c index 2e6ca4357..be7429a72 100644 --- a/src/video/vid_ega_render.c +++ b/src/video/vid_ega_render.c @@ -8,7 +8,7 @@ * * EGA renderers. * - * Version: @(#)vid_ega_render.c 1.0.3 2017/10/10 + * Version: @(#)vid_ega_render.c 1.0.3 2017/10/16 * * Author: Sarah Walker, * Miran Grca, @@ -20,6 +20,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../device.h" #include "../mem.h" diff --git a/src/video/vid_et4000.c b/src/video/vid_et4000.c index 3b809da20..23ba00c7a 100644 --- a/src/video/vid_et4000.c +++ b/src/video/vid_et4000.c @@ -8,7 +8,7 @@ * * Emulation of the Tseng Labs ET4000. * - * Version: @(#)vid_et4000.c 1.0.1 2017/10/10 + * Version: @(#)vid_et4000.c 1.0.1 2017/10/16 * * Authors: Sarah Walker, * Miran Grca, @@ -21,6 +21,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../io.h" #include "../mem.h" diff --git a/src/video/vid_et4000w32.c b/src/video/vid_et4000w32.c index fda5e2ff1..edec65dff 100644 --- a/src/video/vid_et4000w32.c +++ b/src/video/vid_et4000w32.c @@ -10,7 +10,7 @@ * * Known bugs: Accelerator doesn't work in planar modes * - * Version: @(#)vid_et4000w32.c 1.0.1 2017/10/10 + * Version: @(#)vid_et4000w32.c 1.0.2 2017/10/16 * * Authors: Sarah Walker, * Miran Grca, @@ -23,6 +23,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../io.h" #include "../mem.h" @@ -470,7 +471,7 @@ static void fifo_thread(void *param) et4000->blitter_busy = 1; while (!FIFO_EMPTY) { - start_time = timer_read(); + start_time = plat_timer_read(); fifo = &et4000->fifo[et4000->fifo_read_idx & FIFO_MASK]; switch (fifo->addr_type & FIFO_TYPE) @@ -489,7 +490,7 @@ static void fifo_thread(void *param) if (FIFO_ENTRIES > 0xe000) thread_set_event(et4000->fifo_not_full_event); - end_time = timer_read(); + end_time = plat_timer_read(); et4000->blitter_time += end_time - start_time; } et4000->blitter_busy = 0; @@ -1243,7 +1244,7 @@ void et4000w32p_add_status_info(char *s, int max_len, void *p) { et4000w32p_t *et4000 = (et4000w32p_t *)p; char temps[256]; - uint64_t new_time = timer_read(); + uint64_t new_time = plat_timer_read(); uint64_t status_diff = new_time - et4000->status_time; et4000->status_time = new_time; diff --git a/src/video/vid_et4000w32i.c b/src/video/vid_et4000w32i.c index d4208eaa2..7e382d819 100644 --- a/src/video/vid_et4000w32i.c +++ b/src/video/vid_et4000w32i.c @@ -26,6 +26,7 @@ #include #include #include +#include "../86box.h" #include "ibm.h" int et4k_b8000; diff --git a/src/video/vid_genius.c b/src/video/vid_genius.c index de2ac599c..a6524fb09 100644 --- a/src/video/vid_genius.c +++ b/src/video/vid_genius.c @@ -8,7 +8,7 @@ * * MDSI Genius VHR emulation. * - * Version: @(#)vid_genius.c 1.0.1 2017/10/10 + * Version: @(#)vid_genius.c 1.0.4 2017/10/22 * * Authors: Sarah Walker, * Miran Grca, @@ -21,6 +21,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../io.h" #include "../mem.h" @@ -550,15 +551,18 @@ void genius_poll(void *p) if (genius->displine == 1008) { /* Hardcode GENIUS_XSIZE * GENIUS_YSIZE window size */ - if (GENIUS_XSIZE != xsize || GENIUS_YSIZE != ysize) + if ((GENIUS_XSIZE != xsize) || (GENIUS_YSIZE != ysize) || video_force_resize_get()) { xsize = GENIUS_XSIZE; ysize = GENIUS_YSIZE; if (xsize < 64) xsize = 656; if (ysize < 32) ysize = 200; - updatewindowsize(xsize, ysize); + set_screen_size(xsize, ysize); + + if (video_force_resize_get()) + video_force_resize_set(0); } - video_blit_memtoscreen_8(0, 0, xsize, ysize); + video_blit_memtoscreen_8(0, 0, 0, ysize, xsize, ysize); frames++; /* Fixed 728x1008 resolution */ diff --git a/src/video/vid_hercules.c b/src/video/vid_hercules.c index 0329c9b7a..b97399b04 100644 --- a/src/video/vid_hercules.c +++ b/src/video/vid_hercules.c @@ -8,7 +8,7 @@ * * Hercules emulation. * - * Version: @(#)vid_hercules.c 1.0.2 2017/10/13 + * Version: @(#)vid_hercules.c 1.0.5 2017/10/22 * * Authors: Sarah Walker, * Miran Grca, @@ -21,6 +21,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../mem.h" #include "../rom.h" @@ -114,9 +115,6 @@ void hercules_write(uint32_t addr, uint8_t val, void *p) { hercules_t *hercules = (hercules_t *)p; egawrites++; - /* Horrible hack, I know, but it's the only way to fix the 440FX BIOS filling the VRAM with garbage until Tom fixes the memory emulation. */ - if ((cs == 0xE0000) && (cpu_state.pc == 0xBF2F) && (romset == ROM_440FX)) return; - if ((cs == 0xE0000) && (cpu_state.pc == 0xBF77) && (romset == ROM_440FX)) return; // pclog("Herc write %08X %02X\n",addr,val); hercules->vram[addr & 0xffff] = val; } @@ -285,16 +283,19 @@ void hercules_poll(void *p) if ((hercules->ctrl & 2) && (hercules->ctrl2 & 1)) x = hercules->crtc[1] << 4; else x = hercules->crtc[1] * 9; hercules->lastline++; - if (x != xsize || (hercules->lastline - hercules->firstline) != ysize) + if ((x != xsize) || ((hercules->lastline - hercules->firstline) != ysize) || video_force_resize_get()) { xsize = x; ysize = hercules->lastline - hercules->firstline; // printf("Resize to %i,%i - R1 %i\n",xsize,ysize,crtcm[1]); if (xsize < 64) xsize = 656; if (ysize < 32) ysize = 200; - updatewindowsize(xsize, ysize); + set_screen_size(xsize, ysize); + + if (video_force_resize_get()) + video_force_resize_set(0); } - video_blit_memtoscreen_8(0, hercules->firstline, xsize, ysize); + video_blit_memtoscreen_8(0, hercules->firstline, 0, ysize, xsize, ysize); frames++; if ((hercules->ctrl & 2) && (hercules->ctrl2 & 1)) { diff --git a/src/video/vid_herculesplus.c b/src/video/vid_herculesplus.c index c9ef61bd9..918686339 100644 --- a/src/video/vid_herculesplus.c +++ b/src/video/vid_herculesplus.c @@ -8,7 +8,7 @@ * * Hercules InColor emulation. * - * Version: @(#)vid_herculesplus.c 1.0.1 2017/10/10 + * Version: @(#)vid_herculesplus.c 1.0.3 2017/10/18 * * Authors: Sarah Walker, * Miran Grca, @@ -21,6 +21,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../io.h" #include "../mem.h" @@ -148,10 +149,6 @@ void herculesplus_write(uint32_t addr, uint8_t val, void *p) egawrites++; - /* Horrible hack, I know, but it's the only way to fix the 440FX BIOS filling the VRAM with garbage until Tom fixes the memory emulation. */ - if ((cs == 0xE0000) && (cpu_state.pc == 0xBF2F) && (romset == ROM_440FX)) return; - if ((cs == 0xE0000) && (cpu_state.pc == 0xBF77) && (romset == ROM_440FX)) return; - addr &= 0xFFFF; herculesplus->vram[addr] = val; @@ -636,13 +633,16 @@ void herculesplus_poll(void *p) x = herculesplus->crtc[1] * 9; } herculesplus->lastline++; - if (x != xsize || (herculesplus->lastline - herculesplus->firstline) != ysize) + if ((x != xsize) || ((herculesplus->lastline - herculesplus->firstline) != ysize) || video_force_resize_get()) { xsize = x; ysize = herculesplus->lastline - herculesplus->firstline; if (xsize < 64) xsize = 656; if (ysize < 32) ysize = 200; - updatewindowsize(xsize, ysize); + set_screen_size(xsize, ysize); + + if (video_force_resize_get()) + video_force_resize_set(0); } video_blit_memtoscreen(0, herculesplus->firstline, 0, herculesplus->lastline - herculesplus->firstline, xsize, herculesplus->lastline - herculesplus->firstline); frames++; diff --git a/src/video/vid_icd2061.c b/src/video/vid_icd2061.c index 1292752b0..644534ed4 100644 --- a/src/video/vid_icd2061.c +++ b/src/video/vid_icd2061.c @@ -10,7 +10,7 @@ * * Used by ET4000w32/p (Diamond Stealth 32) * - * Version: @(#)vid_icd2061.c 1.0.1 2017/10/10 + * Version: @(#)vid_icd2061.c 1.0.1 2017/10/16 * * Authors: Sarah Walker, * Miran Grca, @@ -22,6 +22,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "vid_icd2061.h" diff --git a/src/video/vid_ics2595.c b/src/video/vid_ics2595.c index eb2aaf4a1..f4b36ef4e 100644 --- a/src/video/vid_ics2595.c +++ b/src/video/vid_ics2595.c @@ -8,7 +8,7 @@ * * ICS2595 clock chip emulation. Used by ATI Mach64. * - * Version: @(#)vid_ics2595.c 1.0.1 2017/10/10 + * Version: @(#)vid_ics2595.c 1.0.1 2017/10/16 * * Authors: Sarah Walker, * Miran Grca, @@ -20,6 +20,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "vid_ics2595.h" diff --git a/src/video/vid_incolor.c b/src/video/vid_incolor.c index 6fdee5417..fbcdd1b52 100644 --- a/src/video/vid_incolor.c +++ b/src/video/vid_incolor.c @@ -8,7 +8,7 @@ * * Hercules InColor emulation. * - * Version: @(#)vid_incolor.c 1.0.1 2017/10/10 + * Version: @(#)vid_incolor.c 1.0.3 2017/10/18 * * Authors: Sarah Walker, * Miran Grca, @@ -21,6 +21,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../io.h" #include "../mem.h" @@ -266,10 +267,6 @@ void incolor_write(uint32_t addr, uint8_t val, void *p) egawrites++; - /* Horrible hack, I know, but it's the only way to fix the 440FX BIOS filling the VRAM with garbage until Tom fixes the memory emulation. */ - if ((cs == 0xE0000) && (cpu_state.pc == 0xBF2F) && (romset == ROM_440FX)) return; - if ((cs == 0xE0000) && (cpu_state.pc == 0xBF77) && (romset == ROM_440FX)) return; - addr &= 0xFFFF; /* In text mode, writes to the bottom 16k always touch all 4 planes */ @@ -983,13 +980,16 @@ void incolor_poll(void *p) x = incolor->crtc[1] * 9; } incolor->lastline++; - if (x != xsize || (incolor->lastline - incolor->firstline) != ysize) + if ((x != xsize) || ((incolor->lastline - incolor->firstline) != ysize) || video_force_resize_get()) { xsize = x; ysize = incolor->lastline - incolor->firstline; if (xsize < 64) xsize = 656; if (ysize < 32) ysize = 200; - updatewindowsize(xsize, ysize); + set_screen_size(xsize, ysize); + + if (video_force_resize_get()) + video_force_resize_set(0); } video_blit_memtoscreen(0, incolor->firstline, 0, incolor->lastline - incolor->firstline, xsize, incolor->lastline - incolor->firstline); frames++; diff --git a/src/video/vid_mda.c b/src/video/vid_mda.c index 942425cda..eb729cd77 100644 --- a/src/video/vid_mda.c +++ b/src/video/vid_mda.c @@ -8,7 +8,7 @@ * * MDA emulation. * - * Version: @(#)vid_mda.c 1.0.2 2017/10/13 + * Version: @(#)vid_mda.c 1.0.5 2017/10/22 * * Authors: Sarah Walker, * Miran Grca, @@ -21,6 +21,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../io.h" #include "../mem.h" @@ -102,9 +103,6 @@ void mda_write(uint32_t addr, uint8_t val, void *p) { mda_t *mda = (mda_t *)p; egawrites++; - /* Horrible hack, I know, but it's the only way to fix the 440FX BIOS filling the VRAM with garbage until Tom fixes the memory emulation. */ - if ((cs == 0xE0000) && (cpu_state.pc == 0xBF2F) && (romset == ROM_440FX)) return; - if ((cs == 0xE0000) && (cpu_state.pc == 0xBF77) && (romset == ROM_440FX)) return; mda->vram[addr & 0xfff] = val; } @@ -245,15 +243,18 @@ void mda_poll(void *p) { x = mda->crtc[1] * 9; mda->lastline++; - if (x != xsize || (mda->lastline - mda->firstline) != ysize) + if ((x != xsize) || ((mda->lastline - mda->firstline) != ysize) || video_force_resize_get()) { xsize = x; ysize = mda->lastline - mda->firstline; if (xsize < 64) xsize = 656; if (ysize < 32) ysize = 200; - updatewindowsize(xsize, ysize); + set_screen_size(xsize, ysize); + + if (video_force_resize_get()) + video_force_resize_set(0); } - video_blit_memtoscreen_8(0, mda->firstline, xsize, mda->lastline - mda->firstline); + video_blit_memtoscreen_8(0, mda->firstline, 0, ysize, xsize, ysize); frames++; video_res_x = mda->crtc[1]; video_res_y = mda->crtc[6]; diff --git a/src/video/vid_nv_riva128.c b/src/video/vid_nv_riva128.c index 4a86beaa8..2926c5535 100644 --- a/src/video/vid_nv_riva128.c +++ b/src/video/vid_nv_riva128.c @@ -8,7 +8,7 @@ * * nVidia RIVA 128 emulation. * - * Version: @(#)vid_nv_riva128.c 1.0.1 2017/10/10 + * Version: @(#)vid_nv_riva128.c 1.0.1 2017/10/16 * * Author: Melissa Goad * Miran Grca, @@ -21,6 +21,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../io.h" #include "../mem.h" diff --git a/src/video/vid_olivetti_m24.c b/src/video/vid_olivetti_m24.c index 5db33a6d2..6e936c343 100644 --- a/src/video/vid_olivetti_m24.c +++ b/src/video/vid_olivetti_m24.c @@ -8,7 +8,7 @@ * * Olivetti M24 video emulation- essentially double-res CGA. * - * Version: @(#)vid_olivetti_m24.c 1.0.1 2017/10/10 + * Version: @(#)vid_olivetti_m24.c 1.0.4 2017/10/22 * * Authors: Sarah Walker, * Miran Grca, @@ -21,6 +21,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../io.h" #include "../mem.h" @@ -403,16 +404,19 @@ void m24_poll(void *p) if (m24->cgamode & 1) x = (m24->crtc[1] << 3) + 16; else x = (m24->crtc[1] << 4) + 16; m24->lastline++; - if (x != xsize || (m24->lastline - m24->firstline) != ysize) + if ((x != xsize) || ((m24->lastline - m24->firstline) != ysize) || video_force_resize_get()) { xsize = x; ysize = m24->lastline - m24->firstline; if (xsize < 64) xsize = 656; if (ysize < 32) ysize = 200; - updatewindowsize(xsize, ysize + 16); + set_screen_size(xsize, ysize + 16); + + if (video_force_resize_get()) + video_force_resize_set(0); } - video_blit_memtoscreen_8(0, m24->firstline - 8, xsize, (m24->lastline - m24->firstline) + 16); + video_blit_memtoscreen_8(0, m24->firstline - 8, 0, (m24->lastline - m24->firstline) + 16, xsize, (m24->lastline - m24->firstline) + 16); frames++; video_res_x = xsize - 16; diff --git a/src/video/vid_oti067.c b/src/video/vid_oti067.c index 4b0c45135..aaea70e4e 100644 --- a/src/video/vid_oti067.c +++ b/src/video/vid_oti067.c @@ -8,7 +8,7 @@ * * Oak OTI067/077 emulation. * - * Version: @(#)vid_oti067.c 1.0.1 2017/10/10 + * Version: @(#)vid_oti067.c 1.0.1 2017/10/16 * * Authors: Sarah Walker, * Miran Grca, @@ -21,6 +21,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../io.h" #include "../mem.h" diff --git a/src/video/vid_paradise.c b/src/video/vid_paradise.c index 744341afc..f8afafcda 100644 --- a/src/video/vid_paradise.c +++ b/src/video/vid_paradise.c @@ -10,7 +10,7 @@ * PC2086, PC3086 use PVGA1A * MegaPC uses W90C11A * - * Version: @(#)vid_paradise.c 1.0.1 2017/10/10 + * Version: @(#)vid_paradise.c 1.0.1 2017/10/16 * * Authors: Sarah Walker, * Miran Grca, @@ -23,6 +23,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../io.h" #include "../mem.h" @@ -253,9 +254,6 @@ void paradise_write(uint32_t addr, uint8_t val, void *p) paradise_t *paradise = (paradise_t *)p; addr = (addr & 0x7fff) + paradise->write_bank[(addr >> 15) & 3]; - /* Horrible hack, I know, but it's the only way to fix the 440FX BIOS filling the VRAM with garbage until Tom fixes the memory emulation. */ - if ((cs == 0xE0000) && (cpu_state.pc == 0xBF2F) && (romset == ROM_440FX)) return; - if ((cs == 0xE0000) && (cpu_state.pc == 0xBF77) && (romset == ROM_440FX)) return; svga_write_linear(addr, val, ¶dise->svga); } diff --git a/src/video/vid_pc1512.c b/src/video/vid_pc1512.c index 5bfce6251..d0ca4ca85 100644 --- a/src/video/vid_pc1512.c +++ b/src/video/vid_pc1512.c @@ -15,7 +15,7 @@ * time as between 12 and 46 cycles. We currently always use * the lower number. * - * Version: @(#)vid_pc1512.c 1.0.1 2017/10/10 + * Version: @(#)vid_pc1512.c 1.0.4 2017/10/22 * * Authors: Sarah Walker, * Miran Grca, @@ -28,6 +28,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../io.h" #include "../mem.h" @@ -412,16 +413,19 @@ static void pc1512_poll(void *p) x = 640 + 16; pc1512->lastline++; - if (x != xsize || (pc1512->lastline - pc1512->firstline) != ysize) + if ((x != xsize) || ((pc1512->lastline - pc1512->firstline) != ysize) || video_force_resize_get()) { xsize = x; ysize = pc1512->lastline - pc1512->firstline; if (xsize < 64) xsize = 656; if (ysize < 32) ysize = 200; - updatewindowsize(xsize, (ysize << 1) + 16); + set_screen_size(xsize, (ysize << 1) + 16); + + if (video_force_resize_get()) + video_force_resize_set(0); } - video_blit_memtoscreen_8(0, pc1512->firstline - 4, xsize, (pc1512->lastline - pc1512->firstline) + 8); + video_blit_memtoscreen_8(0, pc1512->firstline - 4, 0, (pc1512->lastline - pc1512->firstline) + 8, xsize, (pc1512->lastline - pc1512->firstline) + 8); video_res_x = xsize - 16; video_res_y = ysize; diff --git a/src/video/vid_pc1640.c b/src/video/vid_pc1640.c index 77e4d0940..970f35e06 100644 --- a/src/video/vid_pc1640.c +++ b/src/video/vid_pc1640.c @@ -9,7 +9,7 @@ * PC1640 video emulation. * Mostly standard EGA, but with CGA & Hercules emulation. * - * Version: @(#)vid_pc1640.c 1.0.1 2017/10/10 + * Version: @(#)vid_pc1640.c 1.0.1 2017/10/16 * * Authors: Sarah Walker, * Miran Grca, @@ -22,6 +22,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../io.h" #include "../mem.h" diff --git a/src/video/vid_pc200.c b/src/video/vid_pc200.c index 32811e8ea..179926b7e 100644 --- a/src/video/vid_pc200.c +++ b/src/video/vid_pc200.c @@ -10,7 +10,7 @@ * CGA with some NMI stuff. But we don't need that as it's only * used for TV and LCD displays, and we're emulating a CRT. * - * Version: @(#)vid_pc200.c 1.0.1 2017/10/10 + * Version: @(#)vid_pc200.c 1.0.1 2017/10/16 * * Authors: Sarah Walker, * Miran Grca, @@ -23,6 +23,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../io.h" #include "../mem.h" diff --git a/src/video/vid_pcjr.c b/src/video/vid_pcjr.c index 7610a5db7..6e810533a 100644 --- a/src/video/vid_pcjr.c +++ b/src/video/vid_pcjr.c @@ -8,7 +8,7 @@ * * Video emulation for IBM PCjr. * - * Version: @(#)vid_pcjr.c 1.0.1 2017/10/10 + * Version: @(#)vid_pcjr.c 1.0.4 2017/10/22 * * Authors: Sarah Walker, * Miran Grca, @@ -22,6 +22,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../io.h" #include "../mem.h" @@ -502,19 +503,22 @@ void pcjr_poll(void *p) if (pcjr->array[0] & 1) x = (pcjr->crtc[1] << 3) + 16; else x = (pcjr->crtc[1] << 4) + 16; pcjr->lastline++; - if (x != xsize || (pcjr->lastline - pcjr->firstline) != ysize) + if ((x != xsize) || ((pcjr->lastline - pcjr->firstline) != ysize) || video_force_resize_get()) { xsize = x; ysize = pcjr->lastline - pcjr->firstline; if (xsize < 64) xsize = 656; if (ysize < 32) ysize = 200; - updatewindowsize(xsize, (ysize << 1) + 16); + set_screen_size(xsize, (ysize << 1) + 16); + + if (video_force_resize_get()) + video_force_resize_set(0); } if (pcjr->composite) video_blit_memtoscreen(0, pcjr->firstline-4, 0, (pcjr->lastline - pcjr->firstline) + 8, xsize, (pcjr->lastline - pcjr->firstline) + 8); else - video_blit_memtoscreen_8(0, pcjr->firstline-4, xsize, (pcjr->lastline - pcjr->firstline) + 8); + video_blit_memtoscreen_8(0, pcjr->firstline-4, 0, (pcjr->lastline - pcjr->firstline) + 8, xsize, (pcjr->lastline - pcjr->firstline) + 8); frames++; video_res_x = xsize - 16; diff --git a/src/video/vid_ps1_svga.c b/src/video/vid_ps1_svga.c index 93aff8732..54bc2426d 100644 --- a/src/video/vid_ps1_svga.c +++ b/src/video/vid_ps1_svga.c @@ -16,7 +16,7 @@ * drivers for any operating system and there is no VBE * implementation, so it's just a VGA for now. * - * Version: @(#)vid_ps1_svga.c 1.0.1 2017/10/10 + * Version: @(#)vid_ps1_svga.c 1.0.1 2017/10/16 * * Authors: Sarah Walker, * Miran Grca, @@ -29,6 +29,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../io.h" #include "../mem.h" diff --git a/src/video/vid_s3.c b/src/video/vid_s3.c index 11c0221a1..232257038 100644 --- a/src/video/vid_s3.c +++ b/src/video/vid_s3.c @@ -8,7 +8,7 @@ * * S3 emulation. * - * Version: @(#)vid_s3.c 1.0.1 2017/10/10 + * Version: @(#)vid_s3.c 1.0.2 2017/10/16 * * Authors: Sarah Walker, * Miran Grca, @@ -21,6 +21,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../device.h" #include "../io.h" @@ -711,7 +712,7 @@ static void fifo_thread(void *param) s3->blitter_busy = 1; while (!FIFO_EMPTY) { - uint64_t start_time = timer_read(); + uint64_t start_time = plat_timer_read(); uint64_t end_time; fifo_entry_t *fifo = &s3->fifo[s3->fifo_read_idx & FIFO_MASK]; @@ -743,7 +744,7 @@ static void fifo_thread(void *param) if (FIFO_ENTRIES > 0xe000) thread_set_event(s3->fifo_not_full_event); - end_time = timer_read(); + end_time = plat_timer_read(); s3->blitter_time += end_time - start_time; } s3->blitter_busy = 0; @@ -2357,7 +2358,7 @@ static void s3_add_status_info(char *s, int max_len, void *p) { s3_t *s3 = (s3_t *)p; char temps[256]; - uint64_t new_time = timer_read(); + uint64_t new_time = plat_timer_read(); uint64_t status_diff = new_time - s3->status_time; s3->status_time = new_time; diff --git a/src/video/vid_s3_virge.c b/src/video/vid_s3_virge.c index b8937a349..180e93af7 100644 --- a/src/video/vid_s3_virge.c +++ b/src/video/vid_s3_virge.c @@ -8,7 +8,7 @@ * * S3 ViRGE emulation. * - * Version: @(#)vid_s3_virge.c 1.0.1 2017/10/10 + * Version: @(#)vid_s3_virge.c 1.0.2 2017/10/16 * * Authors: Sarah Walker, * Miran Grca, @@ -21,6 +21,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../io.h" #include "../mem.h" @@ -956,7 +957,7 @@ static void fifo_thread(void *param) virge->virge_busy = 1; while (!FIFO_EMPTY) { - uint64_t start_time = timer_read(); + uint64_t start_time = plat_timer_read(); uint64_t end_time; fifo_entry_t *fifo = &virge->fifo[virge->fifo_read_idx & FIFO_MASK]; uint32_t val = fifo->val; @@ -1287,7 +1288,7 @@ static void fifo_thread(void *param) if (FIFO_ENTRIES > 0xe000) thread_set_event(virge->fifo_not_full_event); - end_time = timer_read(); + end_time = plat_timer_read(); virge_time += end_time - start_time; } virge->virge_busy = 0; @@ -3168,7 +3169,7 @@ static void s3_virge_triangle(virge_t *virge, s3d_t *s3d_tri) uint32_t tex_base; int c; - uint64_t start_time = timer_read(); + uint64_t start_time = plat_timer_read(); uint64_t end_time; state.tbu = s3d_tri->tbu << 11; @@ -3296,7 +3297,7 @@ static void s3_virge_triangle(virge_t *virge, s3d_t *s3d_tri) virge->tri_count++; - end_time = timer_read(); + end_time = plat_timer_read(); virge_time += end_time - start_time; } @@ -4136,7 +4137,7 @@ static void s3_virge_add_status_info(char *s, int max_len, void *p) { virge_t *virge = (virge_t *)p; char temps[256]; - uint64_t new_time = timer_read(); + uint64_t new_time = plat_timer_read(); uint64_t status_diff = new_time - status_time; status_time = new_time; diff --git a/src/video/vid_sc1502x_ramdac.c b/src/video/vid_sc1502x_ramdac.c index 3ef8830ac..afb1a6a1d 100644 --- a/src/video/vid_sc1502x_ramdac.c +++ b/src/video/vid_sc1502x_ramdac.c @@ -10,7 +10,7 @@ * * Used by the TLIVESA1 driver for ET4000. * - * Version: @(#)vid_sc1502x_ramdac.c 1.0.1 2017/10/10 + * Version: @(#)vid_sc1502x_ramdac.c 1.0.1 2017/10/16 * * Authors: Sarah Walker, * Miran Grca, @@ -22,6 +22,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../mem.h" #include "video.h" diff --git a/src/video/vid_sdac_ramdac.c b/src/video/vid_sdac_ramdac.c index 2dbcdabbf..9d78e8815 100644 --- a/src/video/vid_sdac_ramdac.c +++ b/src/video/vid_sdac_ramdac.c @@ -10,7 +10,7 @@ * * Misidentifies as AT&T 21C504. * - * Version: @(#)vid_sdac_ramdac.c 1.0.1 2017/10/10 + * Version: @(#)vid_sdac_ramdac.c 1.0.1 2017/10/16 * * Authors: Sarah Walker, * Miran Grca, @@ -22,6 +22,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../mem.h" #include "video.h" diff --git a/src/video/vid_stg_ramdac.c b/src/video/vid_stg_ramdac.c index a2200163a..8029b4ad2 100644 --- a/src/video/vid_stg_ramdac.c +++ b/src/video/vid_stg_ramdac.c @@ -8,7 +8,7 @@ * * STG1702 true colour RAMDAC emulation. * - * Version: @(#)vid_stg_ramdac.c 1.0.1 2017/10/10 + * Version: @(#)vid_stg_ramdac.c 1.0.1 2017/10/16 * * Authors: Sarah Walker, * Miran Grca, @@ -20,6 +20,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../mem.h" #include "video.h" diff --git a/src/video/vid_svga.c b/src/video/vid_svga.c index 27e61cbc4..bcc703065 100644 --- a/src/video/vid_svga.c +++ b/src/video/vid_svga.c @@ -11,7 +11,7 @@ * This is intended to be used by another SVGA driver, * and not as a card in it's own right. * - * Version: @(#)vid_svga.c 1.0.5 2017/10/10 + * Version: @(#)vid_svga.c 1.0.7 2017/10/18 * * Authors: Sarah Walker, * Miran Grca, @@ -24,6 +24,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../io.h" #include "../mem.h" @@ -1044,10 +1045,6 @@ void svga_write(uint32_t addr, uint8_t val, void *p) uint8_t vala, valb, valc, vald, wm = svga->writemask; int writemask2 = svga->writemask; - /* Horrible hack, I know, but it's the only way to fix the 440FX BIOS filling the VRAM with garbage until Tom fixes the memory emulation. */ - if ((cs == 0xE0000) && (cpu_state.pc == 0xBF2F) && (romset == ROM_440FX)) return; - if ((cs == 0xE0000) && (cpu_state.pc == 0xBF77) && (romset == ROM_440FX)) return; - egawrites++; cycles -= video_timing_b; @@ -1620,40 +1617,20 @@ void svga_doblit(int y1, int y2, int wx, int wy, svga_t *svga) return; } - if (((wx!=xsize) || ((wy + 1)!=ysize)) && !vid_resize) - { - xsize=wx; - ysize=wy+1; - if (xsize<64) xsize=640; - if (ysize<32) ysize=200; - - if ((xsize > 2032) || (ysize > 2032)) - { - x_add = 0; - y_add = 0; - suppress_overscan = 1; - } - else - { - suppress_overscan = 0; - } - - updatewindowsize(xsize + x_add,ysize + y_add); - } - if (vid_resize) + if ((wx != xsize) || ((wy + 1) != ysize) || video_force_resize_get()) { + /* Screen res has changed.. fix up, and let them know. */ xsize = wx; - ysize = wy + 1; + ysize = wy+1; + if (xsize<64) xsize = 640; + if (ysize<32) ysize = 200; - if ((xsize > 2032) || (ysize > 2032)) + set_screen_size(xsize+x_add,ysize+y_add); + + if (video_force_resize_get()) { - x_add = 0; - y_add = 0; - suppress_overscan = 1; - } - else - { - suppress_overscan = 0; + pclog("Scroll: %02X (%i, %i, %i, %i, %i, %i)\n", (svga->crtc[8] & 0x1f), enable_overscan, suppress_overscan, wx, wy + 1, x_add, y_add); + video_force_resize_set(0); } } diff --git a/src/video/vid_svga_render.c b/src/video/vid_svga_render.c index 145e26a26..1b08ecceb 100644 --- a/src/video/vid_svga_render.c +++ b/src/video/vid_svga_render.c @@ -8,7 +8,7 @@ * * SVGA renderers. * - * Version: @(#)vid_svga_render.c 1.0.2 2017/10/10 + * Version: @(#)vid_svga_render.c 1.0.2 2017/10/16 * * Authors: Sarah Walker, * Miran Grca, @@ -20,6 +20,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../mem.h" #include "video.h" @@ -133,7 +134,7 @@ uint32_t svga_color_transform(uint32_t color) int svga_display_line(svga_t *svga) { - int y_add = (enable_overscan) ? 16 : 0; + int y_add = enable_overscan ? (overscan_y >> 1) : 0; unsigned int dl = svga->displine; if (svga->crtc[9] & 0x1f) { @@ -146,75 +147,9 @@ int svga_display_line(svga_t *svga) void svga_render_blank(svga_t *svga) { -#if 0 int x, xx; - int y_add = (enable_overscan) ? 16 : 0; - int x_add = y_add >> 1; - int dl = svga_display_line(svga); - uint32_t *p; - - if (svga->firstline_draw == 2000) - svga->firstline_draw = svga->displine; - svga->lastline_draw = svga->displine; - - if (dl >= 2046) - { - return; - } - - for (x = 0; x < svga->hdisp; x++) - { - switch (svga->seqregs[1] & 9) - { - case 0: - for (xx = 0; xx < 9; xx++) - { - p = ((uint32_t *)buffer32->line[dl]); - if (&(p[(x * 9) + xx + 32 + x_add]) != NULL) - { - p[(x * 9) + xx + 32 + x_add] = svga_color_transform(0); - } - } - break; - - case 1: - for (xx = 0; xx < 8; xx++) - { - p = ((uint32_t *)buffer32->line[dl]); - if (&(p[(x * 8) + xx + 32 + x_add]) != NULL) - { - p[(x * 8) + xx + 32 + x_add] = svga_color_transform(0); - } - } - break; - - case 8: - for (xx = 0; xx < 18; xx++) - { - p = ((uint32_t *)buffer32->line[dl]); - if (&(p[(x * 18) + xx + 32 + x_add]) != NULL) - { - p[(x * 18) + xx + 32 + x_add] = svga_color_transform(0); - } - } - break; - - case 9: - for (xx = 0; xx < 16; xx++) - { - p = ((uint32_t *)buffer32->line[dl]); - if (&(p[(x * 16) + xx + 32 + x_add]) != NULL) - { - p[(x * 16) + xx + 32 + x_add] = svga_color_transform(0); - } - } - break; - } - } -#endif - int x, xx; - int y_add = (enable_overscan) ? 16 : 0; - int x_add = y_add >> 1; + int y_add = enable_overscan ? (overscan_y >> 1) : 0; + int x_add = enable_overscan ? 8 : 0; if (svga->firstline_draw == 2000) svga->firstline_draw = svga->displine; @@ -242,8 +177,7 @@ void svga_render_blank(svga_t *svga) void svga_render_text_40(svga_t *svga) { - int y_add = (enable_overscan) ? 16 : 0; - int x_add = y_add >> 1; + int x_add = enable_overscan ? 8 : 0; int dl = svga_display_line(svga); if (svga->firstline_draw == 2000) @@ -310,8 +244,7 @@ void svga_render_text_40(svga_t *svga) #if 0 void svga_render_text_40_12(svga_t *svga) { - int y_add = (enable_overscan) ? 16 : 0; - int x_add = (enable_overscan) ? 12 : 0; + int x_add = enable_overscan ? 12 : 0; int dl = svga_display_line(svga); if (svga->firstline_draw == 2000) @@ -367,8 +300,7 @@ void svga_render_text_40_12(svga_t *svga) void svga_render_text_80(svga_t *svga) { - int y_add = (enable_overscan) ? 16 : 0; - int x_add = y_add >> 1; + int x_add = enable_overscan ? 8 : 0; int dl = svga_display_line(svga); if (svga->firstline_draw == 2000) @@ -435,8 +367,7 @@ void svga_render_text_80(svga_t *svga) #if 0 void svga_render_text_80_12(svga_t *svga) { - int y_add = (enable_overscan) ? 16 : 0; - int x_add = (enable_overscan) ? 12 : 0; + int x_add = enable_overscan ? 12 : 0; int dl = svga_display_line(svga); if (svga->firstline_draw == 2000) @@ -494,8 +425,7 @@ void svga_render_text_80_12(svga_t *svga) void svga_render_2bpp_lowres(svga_t *svga) { int changed_offset; - int y_add = (enable_overscan) ? 16 : 0; - int x_add = y_add >> 1; + int x_add = enable_overscan ? 8 : 0; int dl = svga_display_line(svga); if (svga->sc & 1 && !(svga->crtc[0x17] & 1)) @@ -547,8 +477,7 @@ void svga_render_2bpp_lowres(svga_t *svga) void svga_render_2bpp_highres(svga_t *svga) { int changed_offset; - int y_add = (enable_overscan) ? 16 : 0; - int x_add = y_add >> 1; + int x_add = enable_overscan ? 8 : 0; int dl = svga_display_line(svga); if (svga->sc & 1 && !(svga->crtc[0x17] & 1)) @@ -600,8 +529,7 @@ void svga_render_2bpp_highres(svga_t *svga) void svga_render_4bpp_lowres(svga_t *svga) { int x; - int y_add = (enable_overscan) ? 16 : 0; - int x_add = y_add >> 1; + int x_add = enable_overscan ? 8 : 0; int dl = svga_display_line(svga); int offset; uint32_t *p; @@ -648,8 +576,7 @@ void svga_render_4bpp_highres(svga_t *svga) { int changed_offset; int changed_offset2; - int y_add = (enable_overscan) ? 16 : 0; - int x_add = y_add >> 1; + int x_add = enable_overscan ? 8 : 0; int dl = svga_display_line(svga); int x; int offset; @@ -708,8 +635,7 @@ void svga_render_4bpp_highres(svga_t *svga) void svga_render_8bpp_lowres(svga_t *svga) { - int y_add = (enable_overscan) ? 16 : 0; - int x_add = y_add >> 1; + int x_add = enable_overscan ? 8 : 0; int dl = svga_display_line(svga); if (svga->changedvram[svga->ma >> 12] || svga->changedvram[svga_mask_changedaddr((svga->ma >> 12) + 1, svga)] || svga->fullchange) @@ -740,8 +666,7 @@ void svga_render_8bpp_lowres(svga_t *svga) void svga_render_8bpp_highres(svga_t *svga) { - int y_add = (enable_overscan) ? 16 : 0; - int x_add = y_add >> 1; + int x_add = enable_overscan ? 8 : 0; int dl = svga_display_line(svga); if (svga->changedvram[svga->ma >> 12] || svga->changedvram[svga_mask_changedaddr((svga->ma >> 12) + 1, svga)] || svga->fullchange) @@ -778,8 +703,7 @@ void svga_render_8bpp_highres(svga_t *svga) void svga_render_15bpp_lowres(svga_t *svga) { - int y_add = (enable_overscan) ? 16 : 0; - int x_add = y_add >> 1; + int x_add = enable_overscan ? 8 : 0; int dl = svga_display_line(svga); if (svga->changedvram[svga->ma >> 12] || svga->changedvram[svga_mask_changedaddr((svga->ma >> 12) + 1, svga)] || svga->fullchange) @@ -825,8 +749,7 @@ void svga_render_15bpp_lowres(svga_t *svga) void svga_render_15bpp_highres(svga_t *svga) { - int y_add = (enable_overscan) ? 16 : 0; - int x_add = y_add >> 1; + int x_add = enable_overscan ? 8 : 0; int dl = svga_display_line(svga); if (svga->changedvram[svga->ma >> 12] || svga->changedvram[svga_mask_changedaddr((svga->ma >> 12) + 1, svga)] || svga->fullchange) @@ -864,8 +787,7 @@ void svga_render_15bpp_highres(svga_t *svga) void svga_render_16bpp_lowres(svga_t *svga) { - int y_add = (enable_overscan) ? 16 : 0; - int x_add = y_add >> 1; + int x_add = enable_overscan ? 8 : 0; int dl = svga_display_line(svga); if (svga->changedvram[svga->ma >> 12] || svga->changedvram[svga_mask_changedaddr((svga->ma >> 12) + 1, svga)] || svga->fullchange) @@ -911,8 +833,7 @@ void svga_render_16bpp_lowres(svga_t *svga) void svga_render_16bpp_highres(svga_t *svga) { - int y_add = (enable_overscan) ? 16 : 0; - int x_add = y_add >> 1; + int x_add = enable_overscan ? 8 : 0; int dl = svga_display_line(svga); if (svga->changedvram[svga->ma >> 12] || svga->changedvram[svga_mask_changedaddr((svga->ma >> 12) + 1, svga)] || svga->fullchange) @@ -952,8 +873,7 @@ void svga_render_24bpp_lowres(svga_t *svga) { int x, offset; uint32_t fg; - int y_add = (enable_overscan) ? 16 : 0; - int x_add = y_add >> 1; + int x_add = enable_overscan ? 8 : 0; int dl = svga_display_line(svga); if (svga->changedvram[svga->ma >> 12] || svga->changedvram[svga_mask_changedaddr((svga->ma >> 12) + 1, svga)] || svga->fullchange) @@ -976,8 +896,7 @@ void svga_render_24bpp_lowres(svga_t *svga) void svga_render_24bpp_highres(svga_t *svga) { - int y_add = (enable_overscan) ? 16 : 0; - int x_add = y_add >> 1; + int x_add = enable_overscan ? 8 : 0; int dl = svga_display_line(svga); if (svga->changedvram[svga->ma >> 12] || svga->changedvram[svga_mask_changedaddr((svga->ma >> 12) + 1, svga)] || svga->fullchange) @@ -1014,8 +933,7 @@ void svga_render_32bpp_lowres(svga_t *svga) { int x, offset; uint32_t fg; - int y_add = (enable_overscan) ? 16 : 0; - int x_add = y_add >> 1; + int x_add = enable_overscan ? 8 : 0; int dl = svga_display_line(svga); if (svga->changedvram[svga->ma >> 12] || svga->changedvram[svga_mask_changedaddr((svga->ma >> 12) + 1, svga)] || svga->fullchange) @@ -1040,8 +958,7 @@ void svga_render_32bpp_lowres(svga_t *svga) 91%*/ void svga_render_32bpp_highres(svga_t *svga) { - int y_add = (enable_overscan) ? 16 : 0; - int x_add = y_add >> 1; + int x_add = enable_overscan ? 8 : 0; int dl = svga_display_line(svga); if (svga->changedvram[svga->ma >> 12] || svga->changedvram[svga_mask_changedaddr((svga->ma >> 12) + 1, svga)] || svga->changedvram[svga_mask_changedaddr((svga->ma >> 12) + 2, svga)] || svga->fullchange) @@ -1066,8 +983,7 @@ void svga_render_32bpp_highres(svga_t *svga) void svga_render_ABGR8888_lowres(svga_t *svga) { - int y_add = (enable_overscan) ? 16 : 0; - int x_add = y_add >> 1; + int x_add = enable_overscan ? 8 : 0; int dl = svga_display_line(svga); if (svga->changedvram[svga->ma >> 12] || svga->changedvram[svga_mask_changedaddr((svga->ma >> 12) + 1, svga)] || svga->changedvram[svga_mask_changedaddr((svga->ma >> 12) + 2, svga)] || svga->fullchange) @@ -1092,8 +1008,7 @@ void svga_render_ABGR8888_lowres(svga_t *svga) void svga_render_ABGR8888_highres(svga_t *svga) { - int y_add = (enable_overscan) ? 16 : 0; - int x_add = y_add >> 1; + int x_add = enable_overscan ? 8 : 0; int dl = svga_display_line(svga); if (svga->changedvram[svga->ma >> 12] || svga->changedvram[svga_mask_changedaddr((svga->ma >> 12) + 1, svga)] || svga->changedvram[svga_mask_changedaddr((svga->ma >> 12) + 2, svga)] || svga->fullchange) @@ -1118,8 +1033,7 @@ void svga_render_ABGR8888_highres(svga_t *svga) void svga_render_RGBA8888_lowres(svga_t *svga) { - int y_add = (enable_overscan) ? 16 : 0; - int x_add = y_add >> 1; + int x_add = enable_overscan ? 8 : 0; int dl = svga_display_line(svga); if (svga->changedvram[svga->ma >> 12] || svga->changedvram[svga_mask_changedaddr((svga->ma >> 12) + 1, svga)] || svga->changedvram[svga_mask_changedaddr((svga->ma >> 12) + 2, svga)] || svga->fullchange) @@ -1144,8 +1058,7 @@ void svga_render_RGBA8888_lowres(svga_t *svga) void svga_render_RGBA8888_highres(svga_t *svga) { - int y_add = (enable_overscan) ? 16 : 0; - int x_add = y_add >> 1; + int x_add = enable_overscan ? 8 : 0; int dl = svga_display_line(svga); if (svga->changedvram[svga->ma >> 12] || svga->changedvram[svga_mask_changedaddr((svga->ma >> 12) + 1, svga)] || svga->changedvram[svga_mask_changedaddr((svga->ma >> 12) + 2, svga)] || svga->fullchange) diff --git a/src/video/vid_table.c b/src/video/vid_table.c index 2e3d69b37..efd714747 100644 --- a/src/video/vid_table.c +++ b/src/video/vid_table.c @@ -8,7 +8,7 @@ * * Define all known video cards. * - * Version: @(#)vid_table.c 1.0.2 2017/10/14 + * Version: @(#)vid_table.c 1.0.2 2017/10/16 * * Authors: Miran Grca, * Fred N. van Kempen, @@ -21,6 +21,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../mem.h" #include "../rom.h" @@ -103,19 +104,6 @@ video_cards[] = { {"[ISA] Tseng ET4000AX", "et4000ax", &et4000_device, GFX_ET4000 }, {"[ISA] VGA", "vga", &vga_device, GFX_VGA }, {"[ISA] Wyse 700", "wy700", &wy700_device, GFX_WY700 }, - {"[VLB] ATI Graphics Pro Turbo (Mach64 GX)", "mach64x_vlb", &mach64gx_vlb_device, GFX_MACH64GX_VLB }, - {"[VLB] Diamond Stealth 32 (Tseng ET4000/w32p)","stealth32_vlb", &et4000w32p_vlb_device, GFX_ET4000W32_VLB }, - {"[VLB] Diamond Stealth 3D 2000 (S3 ViRGE)", "stealth3d_2000_vlb", &s3_virge_vlb_device, GFX_VIRGE_VLB }, - {"[VLB] Diamond Stealth 3D 3000 (S3 ViRGE/VX)", "stealth3d_3000_vlb", &s3_virge_988_vlb_device, GFX_VIRGEVX_VLB }, - {"[VLB] Diamond Stealth 64 DRAM (S3 Trio64)", "stealth64d_vlb", &s3_diamond_stealth64_vlb_device, GFX_STEALTH64_VLB }, - {"[VLB] Number Nine 9FX (S3 Trio64)", "n9_9fx_vlb", &s3_9fx_vlb_device, GFX_N9_9FX_VLB }, - {"[VLB] Paradise Bahamas 64 (S3 Vision864)", "bahamas64_vlb", &s3_bahamas64_vlb_device, GFX_BAHAMAS64_VLB }, - {"[VLB] Phoenix S3 Vision864", "px_vision864_vlb", &s3_phoenix_vision864_vlb_device, GFX_PHOENIX_VISION864_VLB }, - {"[VLB] Phoenix S3 Trio32", "px_trio32_vlb", &s3_phoenix_trio32_vlb_device, GFX_PHOENIX_TRIO32_VLB }, - {"[VLB] Phoenix S3 Trio64", "px_trio64_vlb", &s3_phoenix_trio64_vlb_device, GFX_PHOENIX_TRIO64_VLB }, - {"[VLB] S3 ViRGE/DX", "virge375_vlb", &s3_virge_375_vlb_device, GFX_VIRGEDX_VLB }, - {"[VLB] S3 ViRGE/DX (VBE 2.0)", "virge375_vbe20_vlb", &s3_virge_375_4_vlb_device, GFX_VIRGEDX4_VLB }, - {"[VLB] Trident TGUI9440", "tgui9440_vlb", &tgui9440_vlb_device, GFX_TGUI9440_VLB }, {"[PCI] ATI Graphics Pro Turbo (Mach64 GX)", "mach64x_pci", &mach64gx_pci_device, GFX_MACH64GX_PCI }, {"[PCI] ATI Video Xpression (Mach64 VT2)", "mach64vt2", &mach64vt2_device, GFX_MACH64VT2 }, {"[PCI] Diamond Stealth 32 (Tseng ET4000/w32p)","stealth32_pci", &et4000w32p_pci_device, GFX_ET4000W32_PCI }, @@ -135,6 +123,19 @@ video_cards[] = { {"[PCI] S3 ViRGE/DX", "virge375_pci", &s3_virge_375_pci_device, GFX_VIRGEDX_PCI }, {"[PCI] S3 ViRGE/DX (VBE 2.0)", "virge375_vbe20_pci", &s3_virge_375_4_pci_device, GFX_VIRGEDX4_PCI }, {"[PCI] Trident TGUI9440", "tgui9440_pci", &tgui9440_pci_device, GFX_TGUI9440_PCI }, + {"[VLB] ATI Graphics Pro Turbo (Mach64 GX)", "mach64x_vlb", &mach64gx_vlb_device, GFX_MACH64GX_VLB }, + {"[VLB] Diamond Stealth 32 (Tseng ET4000/w32p)","stealth32_vlb", &et4000w32p_vlb_device, GFX_ET4000W32_VLB }, + {"[VLB] Diamond Stealth 3D 2000 (S3 ViRGE)", "stealth3d_2000_vlb", &s3_virge_vlb_device, GFX_VIRGE_VLB }, + {"[VLB] Diamond Stealth 3D 3000 (S3 ViRGE/VX)", "stealth3d_3000_vlb", &s3_virge_988_vlb_device, GFX_VIRGEVX_VLB }, + {"[VLB] Diamond Stealth 64 DRAM (S3 Trio64)", "stealth64d_vlb", &s3_diamond_stealth64_vlb_device, GFX_STEALTH64_VLB }, + {"[VLB] Number Nine 9FX (S3 Trio64)", "n9_9fx_vlb", &s3_9fx_vlb_device, GFX_N9_9FX_VLB }, + {"[VLB] Paradise Bahamas 64 (S3 Vision864)", "bahamas64_vlb", &s3_bahamas64_vlb_device, GFX_BAHAMAS64_VLB }, + {"[VLB] Phoenix S3 Vision864", "px_vision864_vlb", &s3_phoenix_vision864_vlb_device, GFX_PHOENIX_VISION864_VLB }, + {"[VLB] Phoenix S3 Trio32", "px_trio32_vlb", &s3_phoenix_trio32_vlb_device, GFX_PHOENIX_TRIO32_VLB }, + {"[VLB] Phoenix S3 Trio64", "px_trio64_vlb", &s3_phoenix_trio64_vlb_device, GFX_PHOENIX_TRIO64_VLB }, + {"[VLB] S3 ViRGE/DX", "virge375_vlb", &s3_virge_375_vlb_device, GFX_VIRGEDX_VLB }, + {"[VLB] S3 ViRGE/DX (VBE 2.0)", "virge375_vbe20_vlb", &s3_virge_375_4_vlb_device, GFX_VIRGEDX4_VLB }, + {"[VLB] Trident TGUI9440", "tgui9440_vlb", &tgui9440_vlb_device, GFX_TGUI9440_VLB }, {"", "", NULL, -1 } }; diff --git a/src/video/vid_tandy.c b/src/video/vid_tandy.c index a83e32377..6a09822d7 100644 --- a/src/video/vid_tandy.c +++ b/src/video/vid_tandy.c @@ -8,7 +8,7 @@ * * Emulation of the Tandy Model 1000 video. * - * Version: @(#)vid_tandy.c 1.0.1 2017/10/10 + * Version: @(#)vid_tandy.c 1.0.3 2017/10/22 * * Authors: Sarah Walker, * Miran Grca, @@ -22,6 +22,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../io.h" #include "../mem.h" @@ -539,19 +540,22 @@ void tandy_poll(void *p) if (tandy->mode & 1) x = (tandy->crtc[1] << 3) + 16; else x = (tandy->crtc[1] << 4) + 16; tandy->lastline++; - if (x != xsize || (tandy->lastline - tandy->firstline) != ysize) + if ((x != xsize) || ((tandy->lastline - tandy->firstline) != ysize) || video_force_resize_get()) { xsize = x; ysize = tandy->lastline - tandy->firstline; if (xsize < 64) xsize = 656; if (ysize < 32) ysize = 200; - updatewindowsize(xsize, (ysize << 1) + 16); + set_screen_size(xsize, (ysize << 1) + 16); + + if (video_force_resize_get()) + video_force_resize_set(0); } if (tandy->composite) video_blit_memtoscreen(0, tandy->firstline-4, 0, (tandy->lastline - tandy->firstline) + 8, xsize, (tandy->lastline - tandy->firstline) + 8); else - video_blit_memtoscreen_8(0, tandy->firstline-4, xsize, (tandy->lastline - tandy->firstline) + 8); + video_blit_memtoscreen_8(0, tandy->firstline-4, 0, (tandy->lastline - tandy->firstline) + 8, xsize, (tandy->lastline - tandy->firstline) + 8); frames++; video_res_x = xsize - 16; diff --git a/src/video/vid_tandysl.c b/src/video/vid_tandysl.c index 84d21a3f7..6ae2ded61 100644 --- a/src/video/vid_tandysl.c +++ b/src/video/vid_tandysl.c @@ -8,7 +8,7 @@ * * Emulation of the Tandy Model 1000/SL video. * - * Version: @(#)vid_tandysl.c 1.0.1 2017/10/10 + * Version: @(#)vid_tandysl.c 1.0.4 2017/10/22 * * Authors: Sarah Walker, * Miran Grca, @@ -22,6 +22,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../io.h" #include "../mem.h" @@ -608,16 +609,19 @@ static void tandysl_poll(void *p) if (tandy->mode & 1) x = (tandy->crtc[1] << 3) + 16; else x = (tandy->crtc[1] << 4) + 16; tandy->lastline++; - if (x != xsize || (tandy->lastline - tandy->firstline) != ysize) + if ((x != xsize) || ((tandy->lastline - tandy->firstline) != ysize) || video_force_resize_get()) { xsize = x; ysize = tandy->lastline - tandy->firstline; if (xsize < 64) xsize = 656; if (ysize < 32) ysize = 200; - updatewindowsize(xsize, (ysize << 1) + 16); + set_screen_size(xsize, (ysize << 1) + 16); + + if (video_force_resize_get()) + video_force_resize_set(0); } - video_blit_memtoscreen_8(0, tandy->firstline-4, xsize, (tandy->lastline - tandy->firstline) + 8); + video_blit_memtoscreen_8(0, tandy->firstline-4, 0, (tandy->lastline - tandy->firstline) + 8, xsize, (tandy->lastline - tandy->firstline) + 8); frames++; video_res_x = xsize - 16; diff --git a/src/video/vid_tgui9440.c b/src/video/vid_tgui9440.c index a51922a28..c88d32eb5 100644 --- a/src/video/vid_tgui9440.c +++ b/src/video/vid_tgui9440.c @@ -8,7 +8,7 @@ * * Trident TGUI9440 emulation. * - * Version: @(#)vid_tgui9440.c 1.0.1 2017/10/10 + * Version: @(#)vid_tgui9440.c 1.0.2 2017/10/16 * * Authors: Sarah Walker, * Miran Grca, @@ -21,6 +21,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../io.h" #include "../mem.h" @@ -117,6 +118,8 @@ typedef struct tgui_t int blitter_busy; uint64_t blitter_time; uint64_t status_time; + + volatile int write_blitter; } tgui_t; void tgui_recalcmapping(tgui_t *tgui); @@ -131,7 +134,8 @@ void tgui_accel_write(uint32_t addr, uint8_t val, void *priv); void tgui_accel_write_w(uint32_t addr, uint16_t val, void *priv); void tgui_accel_write_l(uint32_t addr, uint32_t val, void *priv); - +void tgui_accel_write_fb_b(uint32_t addr, uint8_t val, void *priv); +void tgui_accel_write_fb_w(uint32_t addr, uint16_t val, void *priv); void tgui_accel_write_fb_l(uint32_t addr, uint32_t val, void *priv); void tgui_out(uint16_t addr, uint8_t val, void *p) @@ -540,7 +544,7 @@ void *tgui9440_init(device_t *info) tgui_hwcursor_draw, NULL); - mem_mapping_add(&tgui->linear_mapping, 0, 0, svga_read_linear, svga_readw_linear, svga_readl_linear, svga_write_linear, svga_writew_linear, svga_writel_linear, NULL, 0, &tgui->svga); + mem_mapping_add(&tgui->linear_mapping, 0, 0, svga_read_linear, svga_readw_linear, svga_readl_linear, tgui_accel_write_fb_b, tgui_accel_write_fb_w, tgui_accel_write_fb_l, NULL, 0, &tgui->svga); mem_mapping_add(&tgui->accel_mapping, 0xbc000, 0x4000, tgui_accel_read, tgui_accel_read_w, tgui_accel_read_l, tgui_accel_write, tgui_accel_write_w, tgui_accel_write_l, NULL, 0, tgui); mem_mapping_disable(&tgui->accel_mapping); @@ -634,9 +638,6 @@ enum svga->changedvram[((addr) & 0xfffff) >> 11] = changeframecount; \ } -void tgui_accel_write_fb_b(uint32_t addr, uint8_t val, void *priv); -void tgui_accel_write_fb_w(uint32_t addr, uint16_t val, void *priv); - void tgui_accel_command(int count, uint32_t cpu_dat, tgui_t *tgui) { svga_t *svga = &tgui->svga; @@ -721,7 +722,9 @@ void tgui_accel_command(int count, uint32_t cpu_dat, tgui_t *tgui) if (count == -1) { if (svga->crtc[0x21] & 0x20) - mem_mapping_set_handler(&tgui->linear_mapping, svga_read_linear, svga_readw_linear, svga_readl_linear, tgui_accel_write_fb_b, tgui_accel_write_fb_w, tgui_accel_write_fb_l); + { + tgui->write_blitter = 1; + } if (tgui->accel.use_src) return; @@ -771,7 +774,7 @@ void tgui_accel_command(int count, uint32_t cpu_dat, tgui_t *tgui) { if (svga->crtc[0x21] & 0x20) { - mem_mapping_set_handler(&tgui->linear_mapping, svga_read_linear, svga_readw_linear, svga_readl_linear, svga_write_linear, svga_writew_linear, svga_writel_linear); + tgui->write_blitter = 0; } return; } @@ -786,7 +789,9 @@ void tgui_accel_command(int count, uint32_t cpu_dat, tgui_t *tgui) if (count == -1) { if (svga->crtc[0x21] & 0x20) - mem_mapping_set_handler(&tgui->linear_mapping, svga_read_linear, svga_readw_linear, svga_readl_linear, tgui_accel_write_fb_b, tgui_accel_write_fb_w, tgui_accel_write_fb_l); + { + tgui->write_blitter = 1; + } if (tgui->accel.use_src) return; @@ -827,7 +832,7 @@ void tgui_accel_command(int count, uint32_t cpu_dat, tgui_t *tgui) { if (svga->crtc[0x21] & 0x20) { - mem_mapping_set_handler(&tgui->linear_mapping, svga_read_linear, svga_readw_linear, svga_readl_linear, svga_write_linear, svga_writew_linear, svga_writel_linear); + tgui->write_blitter = 0; } return; } @@ -1029,7 +1034,7 @@ static void fifo_thread(void *param) tgui->blitter_busy = 1; while (!FIFO_EMPTY) { - start_time = timer_read(); + start_time = plat_timer_read(); fifo = &tgui->fifo[tgui->fifo_read_idx & FIFO_MASK]; switch (fifo->addr_type & FIFO_TYPE) @@ -1054,7 +1059,7 @@ static void fifo_thread(void *param) if (FIFO_ENTRIES > 0xe000) thread_set_event(tgui->fifo_not_full_event); - end_time = timer_read(); + end_time = plat_timer_read(); tgui->blitter_time += end_time - start_time; } tgui->blitter_busy = 0; @@ -1237,28 +1242,40 @@ void tgui_accel_write_fb_b(uint32_t addr, uint8_t val, void *p) { svga_t *svga = (svga_t *)p; tgui_t *tgui = (tgui_t *)svga->p; - tgui_queue(tgui, addr, val, FIFO_WRITE_FB_BYTE); + + if (tgui->write_blitter) + tgui_queue(tgui, addr, val, FIFO_WRITE_FB_BYTE); + else + svga_write_linear(addr, val, svga); } void tgui_accel_write_fb_w(uint32_t addr, uint16_t val, void *p) { svga_t *svga = (svga_t *)p; tgui_t *tgui = (tgui_t *)svga->p; - tgui_queue(tgui, addr, val, FIFO_WRITE_FB_WORD); + + if (tgui->write_blitter) + tgui_queue(tgui, addr, val, FIFO_WRITE_FB_WORD); + else + svga_writew_linear(addr, val, svga); } void tgui_accel_write_fb_l(uint32_t addr, uint32_t val, void *p) { svga_t *svga = (svga_t *)p; tgui_t *tgui = (tgui_t *)svga->p; - tgui_queue(tgui, addr, val, FIFO_WRITE_FB_LONG); + + if (tgui->write_blitter) + tgui_queue(tgui, addr, val, FIFO_WRITE_FB_LONG); + else + svga_writel_linear(addr, val, svga); } void tgui_add_status_info(char *s, int max_len, void *p) { tgui_t *tgui = (tgui_t *)p; char temps[256]; - uint64_t new_time = timer_read(); + uint64_t new_time = plat_timer_read(); uint64_t status_diff = new_time - tgui->status_time; tgui->status_time = new_time; diff --git a/src/video/vid_tkd8001_ramdac.c b/src/video/vid_tkd8001_ramdac.c index 123c9e118..f4429e216 100644 --- a/src/video/vid_tkd8001_ramdac.c +++ b/src/video/vid_tkd8001_ramdac.c @@ -8,7 +8,7 @@ * * Trident TKD8001 RAMDAC emulation. * - * Version: @(#)vid_tkd8001_ramdac.c 1.0.1 2017/10/10 + * Version: @(#)vid_tkd8001_ramdac.c 1.0.1 2017/10/16 * * Authors: Sarah Walker, * Miran Grca, @@ -20,6 +20,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../mem.h" #include "video.h" diff --git a/src/video/vid_tvga.c b/src/video/vid_tvga.c index 1112fd3fb..b7c525989 100644 --- a/src/video/vid_tvga.c +++ b/src/video/vid_tvga.c @@ -8,7 +8,7 @@ * * Trident TVGA (8900D) emulation. * - * Version: @(#)vid_tvga.c 1.0.1 2017/10/10 + * Version: @(#)vid_tvga.c 1.0.1 2017/10/16 * * Authors: Sarah Walker, * Miran Grca, @@ -21,6 +21,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../io.h" #include "../mem.h" diff --git a/src/video/vid_vga.c b/src/video/vid_vga.c index f11a4a81a..e0598f7b8 100644 --- a/src/video/vid_vga.c +++ b/src/video/vid_vga.c @@ -8,7 +8,7 @@ * * IBM VGA emulation. * - * Version: @(#)vid_vga.c 1.0.1 2017/10/10 + * Version: @(#)vid_vga.c 1.0.1 2017/10/16 * * Authors: Sarah Walker, * Miran Grca, @@ -21,6 +21,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../io.h" #include "../mem.h" diff --git a/src/video/vid_voodoo.c b/src/video/vid_voodoo.c index 1fd3e7ab2..cf9b74062 100644 --- a/src/video/vid_voodoo.c +++ b/src/video/vid_voodoo.c @@ -8,7 +8,7 @@ * * Emulation of the 3DFX Voodoo Graphics controller. * - * Version: @(#)vid_voodoo.c 1.0.2 2017/10/11 + * Version: @(#)vid_voodoo.c 1.0.3 2017/10/16 * * Authors: Sarah Walker, * leilei @@ -22,6 +22,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../cpu/cpu.h" #include "../device.h" @@ -3489,7 +3490,7 @@ static void render_thread(void *param, int odd_even) while (!(odd_even ? PARAM_EMPTY_2 : PARAM_EMPTY_1)) { - uint64_t start_time = timer_read(); + uint64_t start_time = plat_timer_read(); uint64_t end_time; voodoo_params_t *params = &voodoo->params_buffer[voodoo->params_read_idx[odd_even] & PARAM_MASK]; @@ -3500,7 +3501,7 @@ static void render_thread(void *param, int odd_even) if ((odd_even ? PARAM_ENTRIES_2 : PARAM_ENTRIES_1) > (PARAM_SIZE - 10)) thread_set_event(voodoo->render_not_full_event[odd_even]); - end_time = timer_read(); + end_time = plat_timer_read(); voodoo->render_time[odd_even] += end_time - start_time; } @@ -6494,7 +6495,7 @@ static void fifo_thread(void *param) voodoo->voodoo_busy = 1; while (!FIFO_EMPTY) { - uint64_t start_time = timer_read(); + uint64_t start_time = plat_timer_read(); uint64_t end_time; fifo_entry_t *fifo = &voodoo->fifo[voodoo->fifo_read_idx & FIFO_MASK]; @@ -6522,13 +6523,13 @@ static void fifo_thread(void *param) if (FIFO_ENTRIES > 0xe000) thread_set_event(voodoo->fifo_not_full_event); - end_time = timer_read(); + end_time = plat_timer_read(); voodoo->time += end_time - start_time; } while (voodoo->cmdfifo_depth_rd != voodoo->cmdfifo_depth_wr) { - uint64_t start_time = timer_read(); + uint64_t start_time = plat_timer_read(); uint64_t end_time; uint32_t header = cmdfifo_get(voodoo); uint32_t addr; @@ -6698,7 +6699,7 @@ static void fifo_thread(void *param) pclog("Bad CMDFIFO packet %08x %08x\n", header, voodoo->cmdfifo_rp); } - end_time = timer_read(); + end_time = plat_timer_read(); voodoo->time += end_time - start_time; } voodoo->voodoo_busy = 0; @@ -7388,7 +7389,7 @@ static void voodoo_add_status_info(char *s, int max_len, void *p) int texel_count_current[2]; int texel_count_total; int render_time[2]; - uint64_t new_time = timer_read(); + uint64_t new_time = plat_timer_read(); uint64_t status_diff = new_time - status_time; status_time = new_time; diff --git a/src/video/vid_wy700.c b/src/video/vid_wy700.c index 1cf02cb6c..f8887f4e4 100644 --- a/src/video/vid_wy700.c +++ b/src/video/vid_wy700.c @@ -8,7 +8,7 @@ * * Wyse-700 emulation. * - * Version: @(#)vid_wy700.c 1.0.1 2017/10/10 + * Version: @(#)vid_wy700.c 1.0.4 2017/10/22 * * Authors: Sarah Walker, * Miran Grca, @@ -21,6 +21,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../io.h" #include "../mem.h" @@ -859,15 +860,18 @@ void wy700_poll(void *p) if (wy700->displine == 800) { /* Hardcode 1280x800 window size */ - if (WY700_XSIZE != xsize || WY700_YSIZE != ysize) + if ((WY700_XSIZE != xsize) || (WY700_YSIZE != ysize) || video_force_resize_get()) { xsize = WY700_XSIZE; ysize = WY700_YSIZE; if (xsize < 64) xsize = 656; if (ysize < 32) ysize = 200; - updatewindowsize(xsize, ysize); + set_screen_size(xsize, ysize); + + if (video_force_resize_get()) + video_force_resize_set(0); } - video_blit_memtoscreen_8(0, 0, xsize, ysize); + video_blit_memtoscreen_8(0, 0, 0, ysize, xsize, ysize); frames++; /* Fixed 1280x800 resolution */ diff --git a/src/video/video.c b/src/video/video.c index bf745f7b7..9a666aba0 100644 --- a/src/video/video.c +++ b/src/video/video.c @@ -40,7 +40,7 @@ * W = 3 bus clocks * L = 4 bus clocks * - * Version: @(#)video.c 1.0.2 2017/10/13 + * Version: @(#)video.c 1.0.5 2017/10/22 * * Authors: Sarah Walker, * Miran Grca, @@ -73,33 +73,35 @@ enum { }; -int vid_cga_contrast = 0; +BITMAP *screen = NULL; +BITMAP *buffer= NULL, + *buffer32= NULL; +uint8_t fontdat[256][8]; /* IBM CGA font */ +uint8_t fontdatm[256][16]; /* IBM MDA font */ +uint8_t fontdatw[512][32]; /* Wyse700 font */ +uint8_t fontdat8x12[256][16]; /* MDSI Genius font */ +uint32_t pal_lookup[256]; +int xsize = 1, + ysize = 1; int cga_palette = 0; -int video_fullscreen = 0, - video_fullscreen_scale, - video_fullscreen_first; -uint32_t *video_6to8, - *video_15to32, - *video_16to32; -BITMAP *screen; +uint32_t *video_6to8 = NULL, + *video_15to32 = NULL, + *video_16to32 = NULL; int egareads = 0, egawrites = 0, changeframecount = 2; uint8_t rotatevga[8][256]; int frames = 0; -int fullchange; +int fullchange = 0; uint8_t edatlookup[4][4]; -int enable_overscan; -int overscan_x, - overscan_y; -int force_43; -int video_timing_b, - video_timing_w, - video_timing_l; -int video_res_x, - video_res_y, - video_bpp; -int video_speed = 0; +int overscan_x = 0, + overscan_y = 0; +int video_timing_b = 0, + video_timing_w = 0, + video_timing_l = 0; +int video_res_x = 0, + video_res_y = 0, + video_bpp = 0; int video_timing[6][4] = { { VIDEO_ISA, 8, 16, 32 }, { VIDEO_ISA, 6, 8, 16 }, @@ -108,14 +110,7 @@ int video_timing[6][4] = { { VIDEO_BUS, 4, 5, 10 }, { VIDEO_BUS, 3, 3, 4 } }; -BITMAP *buffer, - *buffer32; -uint8_t fontdat[256][8]; -uint8_t fontdatm[256][16]; -uint8_t fontdatw[512][32]; /* Wyse700 font */ -uint8_t fontdat8x12[256][16]; /* MDSI Genius font */ -int xsize=1, - ysize=1; +static int video_force_resize; PALETTE cgapal = { {0,0,0}, {0,42,0}, {42,0,0}, {42,21,0}, {0,0,0}, {0,42,42}, {42,0,42}, {42,42,42}, @@ -181,11 +176,10 @@ PALETTE cgapal_mono[6] = { {0x34,0x35,0x33},{0x37,0x37,0x34},{0x3e,0x3e,0x3a},{0x3f,0x3f,0x3b}, } }; -uint32_t pal_lookup[256]; static struct { - int x, y, y1, y2, w, h, blit8; + int x, y, y1, y2, w, h; int busy; int buffer_in_use; @@ -193,11 +187,10 @@ static struct { event_t *wake_blit_thread; event_t *blit_complete; event_t *buffer_not_in_use; -} blit_data; +} blit_data; -static void (*memtoscreen_func)(int x, int y, int y1, int y2, int w, int h); -static void (*memtoscreen_8_func)(int x, int y, int w, int h); +static void (*blit_func)(int x, int y, int y1, int y2, int w, int h); static @@ -207,10 +200,7 @@ void blit_thread(void *param) thread_wait_event(blit_data.wake_blit_thread, -1); thread_reset_event(blit_data.wake_blit_thread); - if (blit_data.blit8) - memtoscreen_8_func(blit_data.x, blit_data.y, blit_data.w, blit_data.h); - else - memtoscreen_func(blit_data.x, blit_data.y, blit_data.y1, blit_data.y2, blit_data.w, blit_data.h); + blit_func(blit_data.x, blit_data.y, blit_data.y1, blit_data.y2, blit_data.w, blit_data.h); blit_data.busy = 0; thread_set_event(blit_data.blit_complete); @@ -219,10 +209,9 @@ void blit_thread(void *param) void -video_setblit(void(*blit8)(int,int,int,int),void(*blit)(int,int,int,int,int,int)) +video_setblit(void(*blit)(int,int,int,int,int,int)) { - memtoscreen_func = blit; - memtoscreen_8_func = blit8; + blit_func = blit; } @@ -268,27 +257,28 @@ video_blit_memtoscreen(int x, int y, int y1, int y2, int w, int h) blit_data.y2 = y2; blit_data.w = w; blit_data.h = h; - blit_data.blit8 = 0; thread_set_event(blit_data.wake_blit_thread); } void -video_blit_memtoscreen_8(int x, int y, int w, int h) +video_blit_memtoscreen_8(int x, int y, int y1, int y2, int w, int h) { + int yy, xx; + if (h <= 0) return; - video_wait_for_blit(); + for (yy = 0; yy < h; yy++) + { + if ((y + yy) >= 0 && (y + yy) < buffer->h) + { + for (xx = 0; xx < w; xx++) + *(uint32_t *) &(buffer32->line[y + yy][(x + xx) << 2]) = pal_lookup[buffer->line[y + yy][x + xx]]; + } + } - blit_data.busy = 1; - blit_data.x = x; - blit_data.y = y; - blit_data.w = w; - blit_data.h = h; - blit_data.blit8 = 1; - - thread_set_event(blit_data.wake_blit_thread); + video_blit_memtoscreen(x, y, y1, y2, w, h); } @@ -297,6 +287,9 @@ cgapal_rebuild(void) { int c; + /* We cannot do this (yet) if we have not been enabled yet. */ + if (video_6to8 == NULL) return; + for (c=0; c<256; c++) { pal_lookup[c] = makecol(video_6to8[cgapal[c].r], video_6to8[cgapal[c].g], @@ -482,6 +475,8 @@ video_init(void) { int c, d, e; + pclog("VIDEO: initializing..\n"); + /* Account for overscan. */ buffer32 = create_bitmap(2048, 2048); @@ -576,6 +571,20 @@ video_reset(void) } +uint8_t +video_force_resize_get(void) +{ + return video_force_resize; +} + + +void +video_force_resize_set(uint8_t res) +{ + video_force_resize = res; +} + + void loadfont(wchar_t *s, int format) { @@ -583,7 +592,10 @@ loadfont(wchar_t *s, int format) int c,d; f = rom_fopen(s, L"rb"); - if (f == NULL) return; + if (f == NULL) { + pclog("VIDEO: cannot load font '%ls', fmt=%d\n", s, format); + return; + } switch (format) { case 0: /* MDA */ diff --git a/src/video/video.h b/src/video/video.h index 1aaf09e84..13fa9bb5c 100644 --- a/src/video/video.h +++ b/src/video/video.h @@ -57,8 +57,6 @@ extern int video_res_x, video_res_y, video_bpp; extern int vid_resize; -extern int winsizex, - winsizey; extern int cga_palette; extern int vid_cga_contrast; extern int video_grayscale; @@ -92,10 +90,9 @@ extern char *video_get_internal_name(int card); extern int video_get_video_from_internal_name(char *s); -extern void video_setblit(void(*blit8)(int,int,int,int), - void(*blit)(int,int,int,int,int,int)); +extern void video_setblit(void(*blit)(int,int,int,int,int,int)); extern void video_blit_memtoscreen(int x, int y, int y1, int y2, int w, int h); -extern void video_blit_memtoscreen_8(int x, int y, int w, int h); +extern void video_blit_memtoscreen_8(int x, int y, int y1, int y2, int w, int h); extern void video_blit_complete(void); extern void video_wait_for_blit(void); extern void video_wait_for_buffer(void); @@ -109,6 +106,8 @@ extern void updatewindowsize(int x, int y); extern void video_init(void); extern void video_close(void); extern void video_reset(void); +extern uint8_t video_force_resize_get(void); +extern void video_force_resize_set(uint8_t res); extern void video_reset_device(int, int); extern void video_update_timing(void); diff --git a/src/win/win_vnc.c b/src/vnc.c similarity index 83% rename from src/win/win_vnc.c rename to src/vnc.c index 3ef79e3ce..55c6ae925 100644 --- a/src/win/win_vnc.c +++ b/src/vnc.c @@ -6,9 +6,9 @@ * * This file is part of the 86Box distribution. * - * Implement the VNC renderer with LibVNCServer. + * Implement the VNC remote renderer with LibVNCServer. * - * Version: @(#)win_vnc.c 1.0.2 2017/10/14 + * Version: @(#)lnx_vnc.c 1.0.4 2017/10/18 * * Authors: Fred N. van Kempen, * Based on raw code by RichardG, @@ -17,17 +17,26 @@ */ #include #include -#include "../ibm.h" -#include "../device.h" -#include "../video/video.h" -#include "../plat.h" -#include "../plat_keyboard.h" -#include "../ui.h" +#include +#include +#include +#include "86box.h" +#include "device.h" +#include "video/video.h" +#include "plat.h" +#include "plat_keyboard.h" +#include "plat_mouse.h" +#include "ui.h" #define BITMAP MY_BITMAP #include #undef BITMAP -#include "win.h" -#include "win_vnc.h" +#include "vnc.h" + + +#define VNC_MIN_X 320 +#define VNC_MAX_X 2048 +#define VNC_MIN_Y 200 +#define VNC_MAX_Y 2048 static rfbScreenInfoPtr rfb = NULL; @@ -107,53 +116,6 @@ static int keysyms_ff[] = { }; -static void -vnc_clientgone(rfbClientPtr cl) -{ - pclog("VNC: client disconnected: %s\n", cl->host); - - if (clients > 0) - clients--; - if (clients == 0) { - /* No more clients, pause the emulator. */ - pclog("VNC: no clients, pausing..\n"); - plat_pause(1); - } -} - - -static enum rfbNewClientAction -vnc_newclient(rfbClientPtr cl) -{ - /* Hook the ClientGone function so we know when they're gone. */ - cl->clientGoneHook = vnc_clientgone; - - pclog("VNC: new client: %s\n", cl->host); - if (++clients == 1) { - /* We now have clients, un-pause the emulator. */ - pclog("VNC: unpausing..\n"); - plat_pause(0); - } - - return(RFB_CLIENT_ACCEPT); -} - - -static void -vnc_display(rfbClientPtr cl) -{ - /* Avoid race condition between resize and update. */ - if (!updatingSize && cl->newFBSizePending) { - updatingSize = 1; - } else if (updatingSize && !cl->newFBSizePending) { - updatingSize = 0; - - allowedX = rfb->width; - allowedY = rfb->height; - } -} - - static void vnc_kbdevent(rfbBool down, rfbKeySym k, rfbClientPtr cl) { @@ -177,18 +139,79 @@ vnc_kbdevent(rfbBool down, rfbKeySym k, rfbClientPtr cl) (will_press >> 8) & 0xff, will_press & 0xff); #endif - // first key + /* First key. */ key = (will_press >> 8) & 0xff; if (key > 0) recv_key[key] = down; - // second key + /* Second key. */ key = will_press & 0xff; if (key > 0) recv_key[key] = down; } +static void +vnc_ptrevent(int but, int x, int y, rfbClientPtr cl) +{ + if (x>=0 && x=0 && yhost); + + if (clients > 0) + clients--; + if (clients == 0) { + /* No more clients, pause the emulator. */ + pclog("VNC: no clients, pausing..\n"); + plat_pause(1); + } +} + + +static enum rfbNewClientAction +vnc_newclient(rfbClientPtr cl) +{ + /* Hook the ClientGone function so we know when they're gone. */ + cl->clientGoneHook = vnc_clientgone; + + pclog("VNC: new client: %s\n", cl->host); + if (++clients == 1) { + /* We now have clients, un-pause the emulator if needed. */ + pclog("VNC: unpausing..\n"); + plat_pause(0); + } + + /* For now, we always accept clients. */ + return(RFB_CLIENT_ACCEPT); +} + + +static void +vnc_display(rfbClientPtr cl) +{ + /* Avoid race condition between resize and update. */ + if (!updatingSize && cl->newFBSizePending) { + updatingSize = 1; + } else if (updatingSize && !cl->newFBSizePending) { + updatingSize = 0; + + allowedX = rfb->width; + allowedY = rfb->height; + } +} + + static void vnc_blit(int x, int y, int y1, int y2, int w, int h) { @@ -196,9 +219,9 @@ vnc_blit(int x, int y, int y1, int y2, int w, int h) int yy; for (yy=y1; yyframeBuffer)[yy*2048]); + p = (uint32_t *)&(((uint32_t *)rfb->frameBuffer)[yy*VNC_MAX_X]); - if ((y+yy) >= 0 && (y+yy) < 2048) + if ((y+yy) >= 0 && (y+yy) < VNC_MAX_Y) memcpy(p, &(((uint32_t *)buffer32->line[y+yy])[x]), w*4); } @@ -209,30 +232,9 @@ vnc_blit(int x, int y, int y1, int y2, int w, int h) } -static void -vnc_blit8(int x, int y, int w, int h) -{ - uint32_t *p; - int xx, yy; - - for (yy = 0; yy < h; yy++) { - p = (uint32_t *)&(((uint32_t *)rfb->frameBuffer)[yy*2048]); - - if ((y+yy) >= 0 && (y+yy) < buffer->h) { - for (xx=0; xxline[y+yy][x+xx]]; - } - } - - video_blit_complete(); - - if (! updatingSize) - rfbMarkRectAsModified(rfb, 0,0, x+w,y+h); -} - - +/* Initialize VNC for operation. */ int -vnc_init(HWND h) +vnc_init(UNUSED(void *arg)) { static char title[128]; rfbPixelFormat rpf = { @@ -249,32 +251,38 @@ vnc_init(HWND h) }; if (rfb == NULL) { - wcstombs(title, set_window_title(NULL), sizeof(title)); + wcstombs(title, ui_window_title(NULL), sizeof(title)); updatingSize = 0; - allowedX = allowedY = 2048; + allowedX = scrnsz_x; + allowedY = scrnsz_y; - rfb = rfbGetScreen(0, NULL, 2048, 2048, 8, 3, 4); + rfb = rfbGetScreen(0, NULL, VNC_MAX_X, VNC_MAX_Y, 8, 3, 4); rfb->desktopName = title; - rfb->frameBuffer = (char *)malloc(2048 * 2048 * 4); + rfb->frameBuffer = (char *)malloc(VNC_MAX_X*VNC_MAX_Y*4); rfb->serverFormat = rpf; rfb->alwaysShared = TRUE; rfb->displayHook = vnc_display; + rfb->ptrAddEvent = vnc_ptrevent; rfb->kbdAddEvent = vnc_kbdevent; rfb->newClientHook = vnc_newclient; + /* Set up our current resolution. */ + rfb->width = allowedX; + rfb->height = allowedY; + rfbInitServer(rfb); rfbRunEventLoop(rfb, -1, TRUE); } /* Set up our BLIT handlers. */ - video_setblit(vnc_blit8, vnc_blit); - - pclog("VNC: init complete.\n"); + video_setblit(vnc_blit); clients = 0; + pclog("VNC: init complete.\n"); + return(1); } @@ -282,7 +290,13 @@ vnc_init(HWND h) void vnc_close(void) { - pclog("VNC: closed.\n"); + if (rfb != NULL) { + free(rfb->frameBuffer); + + rfbScreenCleanup(rfb); + + rfb = NULL; + } } @@ -294,6 +308,12 @@ vnc_resize(int x, int y) if (rfb == NULL) return; + /* TightVNC doesn't like certain sizes.. */ + if (x < VNC_MIN_X || x > VNC_MAX_X || y < VNC_MIN_Y || y > VNC_MAX_Y) { + pclog("VNC: invalid resoltion %dx%d requested!\n", x, y); + return; + } + if ((x != rfb->width || y != rfb->height) && x > 160 && y > 0) { pclog("VNC: updating resolution: %dx%d\n", x, y); @@ -313,6 +333,7 @@ vnc_resize(int x, int y) } +/* Tell them to pause if we have no clients. */ int vnc_pause(void) { diff --git a/src/win/win_vnc.h b/src/vnc.h similarity index 76% rename from src/win/win_vnc.h rename to src/vnc.h index ba3d793e9..96330284d 100644 --- a/src/win/win_vnc.h +++ b/src/vnc.h @@ -8,23 +8,31 @@ * * Definitions for the VNC renderer. * - * Version: @(#)win_vnc.h 1.0.1 2017/10/13 + * Version: @(#)vnc.h 1.0.3 2017/10/18 * * Authors: RichardG, * Fred N. van Kempen, * * Copyright 2017 Fred N. van Kempen. */ -#ifndef WIN_VNC_H -# define WIN_VNC_H +#ifndef EMU_VNC_H +# define EMU_VNC_H -extern int vnc_init(HWND h); +#ifdef __cplusplus +extern "C" { +#endif + +extern int vnc_init(void *); extern void vnc_close(void); extern void vnc_resize(int x, int y); extern int vnc_pause(void); extern void vnc_take_screenshot(wchar_t *fn); +#ifdef __cplusplus +} +#endif -#endif /*WIN_VNC_H*/ + +#endif /*EMU_VNC_H*/ diff --git a/src/win/Makefile.mingw b/src/win/Makefile.mingw index 95a3c5beb..513297dd6 100644 --- a/src/win/Makefile.mingw +++ b/src/win/Makefile.mingw @@ -8,7 +8,7 @@ # # Makefile for Win32 (MinGW32) environment. # -# Version: @(#)Makefile.mingw 1.0.63 2017/10/14 +# Version: @(#)Makefile.mingw 1.0.65 2017/10/19 # # Authors: Miran Grca, # Fred N. van Kempen, @@ -20,25 +20,11 @@ PROG := 86Box endif # Various compile-time options. -# -DROM_TRACE=0xc800 traces ROM access from segment C800 -# -DIO_TRACE=0x66 traces I/O on port 0x66 +ifndef STUFF STUFF := +endif # Add feature selections here. -# -DANSI_CFG forces the config file to ANSI encoding. -# -DENABLE_VRAM_DUMP enables Video Ram dumping. -# -DENABLE_LOG_BREAKPOINT enables extra logging. -# -DENABLE_SCSI_BIOS_COMMAND_LOG=n enables extra logging. -# -DENABLE_AHA154X_LOG=n enables extra logging. -# -DENABLE_BUSLOGIC_LOG=n enables extra logging. -# -DENABLE_CDROM_LOG enables extra logging. -# -DENABLE_D86F_LOG enables extra logging. -# -DENABLE_FDC_LOG enables extra logging. -# -DENABLE_HDD_IMAGE_LOG enables extra logging. -# -DENABLE_IDE_LOG enables extra logging. -# -DENABLE_SERIAL_LOG enables extra logging. -# -DENABLE_NIC_LOG enables extra logging. -# -DENABLE_KEYBOARD_LOG enables extra logging. ifndef EXTRAS EXTRAS := endif @@ -224,7 +210,7 @@ RFLAGS += -DUSE_VNC VNCLIB := -L$(VNC_PATH)\LIB endif VNCLIB += -lvncserver -VNCOBJ := win_vnc.o +VNCOBJ := vnc.o endif ifeq ($(RDP), y) @@ -235,7 +221,7 @@ RFLAGS += -DUSE_RDP RDPLIB := -L$(RDP_PATH)\LIB endif RDPLIB += -lrdp -RDPOBJ := win_rdp.o +RDPOBJ := rdp.o endif # Options for the DEV branch. @@ -276,7 +262,7 @@ endif MAINOBJ := pc.o config.o random.o timer.o io.o dma.o nmi.o pic.o \ pit.o ppi.o pci.o mca.o mcr.o mem.o memregs.o rom.o \ - device.o nvr.o nvr_at.o nvr_ps2.o \ + device.o nvr.o nvr_at.o nvr_ps2.o $(VNCOBJ) $(RDPOBJ) \ intel.o intel_flash.o intel_sio.o CPUOBJ := cpu.o 386.o 386_dynarec.o 808x.o \ @@ -400,12 +386,11 @@ VIDOBJ := video.o \ PLATOBJ := win.o \ win_ddraw.o win_ddraw_fs.o win_d3d.o win_d3d_fs.o \ - $(VNCOBJ) $(RDPOBJ) \ - win_dynld.o win_thread.o $(WSERIAL) win_cdrom.o win_cdrom_ioctl.o \ - win_keyboard.o win_mouse.o win_joystick.o win_midi.o \ + win_dynld.o win_thread.o $(WSERIAL) win_video.o \ + win_cdrom.o win_cdrom_ioctl.o win_keyboard.o win_mouse.o \ + win_joystick.o win_midi.o \ win_dialog.o win_about.o win_status.o win_stbar.o \ - win_settings.o win_deviceconfig.o win_joystickconfig.o \ - $(OPENDIR) + win_settings.o win_deviceconfig.o win_joystickconfig.o OBJ := $(MAINOBJ) $(CPUOBJ) $(MCHOBJ) $(DEVOBJ) \ $(FDDOBJ) $(CDROMOBJ) $(HDDOBJ) \ @@ -513,7 +498,7 @@ ifneq ($(AUTODEP), y) depclean: @-rm -f $(DEPFILE) 2>NUL @echo Creating dependencies.. - @echo # Run "make depends" to re-create this file. $(DEPFILE) + @echo # Run "make depends" to re-create this file. >$(DEPFILE) depends: DEPOBJ=$(OBJ:%.o=%.d) depends: depclean $(OBJ:%.o=%.d) diff --git a/src/win/win.c b/src/win/win.c index ab12e005d..78a5374cb 100644 --- a/src/win/win.c +++ b/src/win/win.c @@ -8,7 +8,7 @@ * * The Emulator's Windows core. * - * Version: @(#)win.c 1.0.24 2017/10/14 + * Version: @(#)win.c 1.0.27 2017/10/18 * * Authors: Sarah Walker, * Miran Grca, @@ -38,8 +38,8 @@ #include "../86box.h" #include "../config.h" #include "../ibm.h" -#include "../mem.h" -#include "../rom.h" +#include "../mem.h" // because of load_config +#include "../rom.h" // because of load_config #include "../device.h" #include "../nvr.h" #include "../mouse.h" @@ -50,20 +50,16 @@ #include "../scsi/scsi.h" #include "../network/network.h" #include "../video/video.h" -#include "../video/vid_ega.h" +#include "../video/vid_ega.h" // for update_overscan #include "../sound/sound.h" -#include "../sound/snd_dbopl.h" +#define GLOBAL #include "../plat.h" #include "../plat_keyboard.h" #include "../plat_mouse.h" #include "../plat_midi.h" #include "../ui.h" #include "win.h" -#include "win_ddraw.h" #include "win_d3d.h" -#ifdef USE_VNC -# include "win_vnc.h" -#endif #define TIMER_1SEC 1 @@ -74,33 +70,18 @@ typedef struct { } rc_str_t; -extern int updatestatus; - - -/* Public data, more or less non-specific to platform. */ -int scale = 0; -uint64_t timer_freq; -int winsizex = 640, - winsizey = 480; -int efwinsizey = 480; -int gfx_present[GFX_MAX]; -int infocus = 1; -int drawits = 0; -int quited = 0; -int mousecapture = 0; -uint64_t main_time; - -/* Public data, specific to platform. */ -HWND hwndMain; -HMENU menuMain; +/* Platform Public data, specific (defined in lnx.h.) */ +HINSTANCE hinstance; /* application instance */ +HWND hwndMain, /* application main window */ + hwndRender; /* machine render window */ +HMENU menuMain; /* application main menu */ HANDLE ghMutex; -HINSTANCE hinstance; -HICON hIcon[512]; -RECT oldclip; -LCID dwLanguage; -int recv_key[272]; -uint32_t dwLangID, - dwSubLangID; +HICON hIcon[512]; /* icon data loaded from resources */ +LCID lang_id; /* current language ID used */ +DWORD dwSubLangID; +RECT oldclip; /* mouse rect */ +int infocus = 1; +int recv_key[272]; /* keyboard input buffer */ char openfilestring[260]; WCHAR wopenfilestring[260]; @@ -108,19 +89,11 @@ WCHAR wopenfilestring[260]; /* Local data. */ static HANDLE thMain; -static HWND hwndRender; /* machine render window */ static wchar_t wTitle[512]; static RAWINPUTDEVICE device; static HHOOK hKeyboardHook; static int hook_enabled = 0; static int save_window_pos = 0; -static int win_doresize = 0; -static int leave_fullscreen_flag = 0; -static int unscaled_size_x = 0; -static int unscaled_size_y = 0; -static int pause; -static uint64_t start_time; -static uint64_t end_time; static wchar_t **argv; static int argc; static wchar_t *argbuf; @@ -133,42 +106,6 @@ static rc_str_t *lpRCstr2048, *lpRCstr5376, *lpRCstr5632, *lpRCstr6144; -static struct { - int local; - int (*init)(HWND h); - void (*close)(void); - void (*resize)(int x, int y); - int (*pause)(void); -} vid_apis[2][4] = { - { - { 1, ddraw_init, ddraw_close, NULL, ddraw_pause }, - { 1, d3d_init, d3d_close, d3d_resize, d3d_pause }, -#ifdef USE_VNC - { 0, vnc_init, vnc_close, vnc_resize, vnc_pause }, -#else - { 0, NULL, NULL, NULL, NULL }, -#endif -#ifdef USE_RDP - { 0, rdp_init, rdp_close, rdp_resize, rdp_pause } -#else - { 0, NULL, NULL, NULL, NULL } -#endif - }, - { - { 1, ddraw_fs_init, ddraw_fs_close, NULL, ddraw_fs_pause }, - { 1, d3d_fs_init, d3d_fs_close, NULL, d3d_fs_pause }, -#ifdef USE_VNC - { 0, vnc_init, vnc_close, vnc_resize, vnc_pause }, -#else - { 0, NULL, NULL, NULL, NULL }, -#endif -#ifdef USE_RDP - { 0, rdp_init, rdp_close, rdp_resize, rdp_pause } -#else - { 0, NULL, NULL, NULL, NULL } -#endif - } -}; HICON @@ -207,26 +144,6 @@ releasemouse(void) } -static void -win_pc_reset(int hard) -{ - plat_pause(1); - - Sleep(100); - - nvr_save(); - - config_save(); - - if (hard) - pc_reset_hard(); - else - pc_send_cad(); - - plat_pause(vid_apis[video_fullscreen][vid_api].pause()); -} - - static void video_toggle_option(HMENU h, int *val, int id) { @@ -240,80 +157,6 @@ video_toggle_option(HMENU h, int *val, int id) } -/* The main thread runs the actual emulator code. */ -static void -MainThread(LPVOID param) -{ - int sb_borders[3]; - DWORD old_time, new_time; - int frames = 0; - RECT r; - - drawits = 0; - old_time = GetTickCount(); - while (! quited) { - if (updatestatus) { - if (hwndStatus != NULL) - SendMessage(hwndStatus, WM_USER, 0, 0); - updatestatus = 0; - } - - new_time = GetTickCount(); - drawits += new_time - old_time; - old_time = new_time; - if (drawits > 0 && !pause) { - start_time = timer_read(); - drawits -= 10; - if (drawits > 50) drawits = 0; - pc_run(); - - if (++frames >= 200 && nvr_dosave) { - frames = 0; - nvr_save(); - nvr_dosave = 0; - } - - end_time = timer_read(); - main_time += end_time - start_time; - } else - Sleep(1); - - if (!video_fullscreen && vid_apis[0][vid_api].local && - win_doresize && (winsizex>0) && (winsizey>0)) { - SendMessage(hwndSBAR, SB_GETBORDERS, 0, (LPARAM) sb_borders); - GetWindowRect(hwndMain, &r); - MoveWindow(hwndRender, 0, 0, winsizex, winsizey, TRUE); - GetWindowRect(hwndRender, &r); - MoveWindow(hwndSBAR, - 0, r.bottom + GetSystemMetrics(SM_CYEDGE), - winsizex, 17, TRUE); - GetWindowRect(hwndMain, &r); - - MoveWindow(hwndMain, r.left, r.top, - winsizex + (GetSystemMetrics(vid_resize ? SM_CXSIZEFRAME : SM_CXFIXEDFRAME) * 2), - winsizey + (GetSystemMetrics(SM_CYEDGE) * 2) + (GetSystemMetrics(vid_resize ? SM_CYSIZEFRAME : SM_CYFIXEDFRAME) * 2) + GetSystemMetrics(SM_CYMENUSIZE) + GetSystemMetrics(SM_CYCAPTION) + 17 + sb_borders[1] + 1, - TRUE); - - if (mousecapture) { - GetWindowRect(hwndRender, &r); - ClipCursor(&r); - } - - win_doresize = 0; - } - - if (leave_fullscreen_flag) { - leave_fullscreen_flag = 0; - - SendMessage(hwndMain, WM_LEAVEFULLSCREEN, 0, 0); - } - - if (video_fullscreen && infocus) - SetCursorPos(9999, 9999); - } -} - - static void ResetAllMenus(void) { @@ -420,7 +263,7 @@ static LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam) { BOOL bControlKeyDown; - KBDLLHOOKSTRUCT* p; + KBDLLHOOKSTRUCT *p; if (nCode < 0 || nCode != HC_ACTION) return(CallNextHookEx(hKeyboardHook, nCode, wParam, lParam)); @@ -473,11 +316,11 @@ MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) break; case IDM_ACTION_HRESET: - win_pc_reset(1); + pc_reset(1); break; case IDM_ACTION_RESET_CAD: - win_pc_reset(0); + pc_reset(0); break; case IDM_ACTION_EXIT: @@ -489,7 +332,7 @@ MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) break; case IDM_ACTION_PAUSE: - plat_pause(pause ^ 1); + plat_pause(dopause ^ 1); break; case IDM_CONFIG: @@ -524,7 +367,7 @@ MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) EnableMenuItem(hmenu, IDM_VID_SCALE_2X, vid_resize ? MF_GRAYED : MF_ENABLED); EnableMenuItem(hmenu, IDM_VID_SCALE_3X, vid_resize ? MF_GRAYED : MF_ENABLED); EnableMenuItem(hmenu, IDM_VID_SCALE_4X, vid_resize ? MF_GRAYED : MF_ENABLED); - win_doresize = 1; + doresize = 1; config_save(); break; @@ -549,43 +392,13 @@ MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) #ifdef USE_RDP case IDM_VID_RDP: #endif - startblit(); - video_wait_for_blit(); - CheckMenuItem(hmenu, IDM_VID_DDRAW+vid_api, MF_UNCHECKED); - vid_apis[0][vid_api].close(); - vid_api = LOWORD(wParam) - IDM_VID_DDRAW; - if (vid_apis[0][vid_api].local) - ShowWindow(hwndRender, SW_SHOW); - else - ShowWindow(hwndRender, SW_HIDE); - CheckMenuItem(hmenu, IDM_VID_DDRAW+vid_api, MF_CHECKED); - vid_apis[0][vid_api].init(hwndRender); - endblit(); + plat_setvid(LOWORD(wParam) - IDM_VID_DDRAW); config_save(); - device_force_redraw(); - cgapal_rebuild(); break; case IDM_VID_FULLSCREEN: - if (video_fullscreen == 1) break; - - if (video_fullscreen_first) { - video_fullscreen_first = 0; - ui_msgbox(MBX_INFO, (wchar_t *)IDS_2074); - } - - startblit(); - video_wait_for_blit(); - mouse_close(); - vid_apis[0][vid_api].close(); - video_fullscreen = 1; - vid_apis[1][vid_api].init(hwndMain); - mouse_init(); - leave_fullscreen_flag = 0; - endblit(); + plat_setfullscreen(1); config_save(); - device_force_redraw(); - cgapal_rebuild(); break; case IDM_VID_FS_FULL: @@ -595,8 +408,8 @@ MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) CheckMenuItem(hmenu, IDM_VID_FS_FULL + video_fullscreen_scale, MF_UNCHECKED); video_fullscreen_scale = LOWORD(wParam) - IDM_VID_FS_FULL; CheckMenuItem(hmenu, IDM_VID_FS_FULL + video_fullscreen_scale, MF_CHECKED); - config_save(); device_force_redraw(); + config_save(); break; case IDM_VID_SCALE_1X: @@ -606,12 +419,14 @@ MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) CheckMenuItem(hmenu, IDM_VID_SCALE_1X + scale, MF_UNCHECKED); scale = LOWORD(wParam) - IDM_VID_SCALE_1X; CheckMenuItem(hmenu, IDM_VID_SCALE_1X + scale, MF_CHECKED); - config_save(); device_force_redraw(); + video_force_resize_set(1); + config_save(); break; case IDM_VID_FORCE43: video_toggle_option(hmenu, &force_43, IDM_VID_FORCE43); + video_force_resize_set(1); break; case IDM_VID_INVERT: @@ -621,6 +436,7 @@ MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) case IDM_VID_OVERSCAN: update_overscan = 1; video_toggle_option(hmenu, &enable_overscan, IDM_VID_OVERSCAN); + video_force_resize_set(1); break; case IDM_VID_CGACON: @@ -636,8 +452,8 @@ MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) CheckMenuItem(hmenu, IDM_VID_GRAYCT_601 + video_graytype, MF_UNCHECKED); video_graytype = LOWORD(wParam) - IDM_VID_GRAYCT_601; CheckMenuItem(hmenu, IDM_VID_GRAYCT_601 + video_graytype, MF_CHECKED); - config_save(); device_force_redraw(); + config_save(); break; case IDM_VID_GRAY_RGB: @@ -648,8 +464,8 @@ MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) CheckMenuItem(hmenu, IDM_VID_GRAY_RGB + video_grayscale, MF_UNCHECKED); video_grayscale = LOWORD(wParam) - IDM_VID_GRAY_RGB; CheckMenuItem(hmenu, IDM_VID_GRAY_RGB + video_grayscale, MF_CHECKED); - config_save(); device_force_redraw(); + config_save(); break; #ifdef ENABLE_LOG_TOGGLES @@ -697,7 +513,6 @@ MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) # ifdef ENABLE_NIC_LOG case IDM_LOG_NIC: - /*FIXME: should be network_setlog() */ nic_do_log ^= 1; CheckMenuItem(hmenu, IDM_LOG_NIC, nic_do_log ? MF_CHECKED : MF_UNCHECKED); break; @@ -722,46 +537,30 @@ MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) if (ui_msgbox(MBX_QUESTION, (wchar_t *)IDS_2051) == IDYES) { config_write(config_file_default); for (i = 0; i < FDD_NUM; i++) - { floppy_close(i); - } for (i = 0; i < CDROM_NUM; i++) { cdrom_drives[i].handler->exit(i); if (cdrom_drives[i].host_drive == 200) - { image_close(i); - } else if ((cdrom_drives[i].host_drive >= 'A') && (cdrom_drives[i].host_drive <= 'Z')) - { ioctl_close(i); - } else - { null_close(i); - } } pc_reset_hard_close(); config_load(wopenfilestring); for (i = 0; i < CDROM_NUM; i++) { if (cdrom_drives[i].bus_type) - { SCSIReset(cdrom_drives[i].scsi_device_id, cdrom_drives[i].scsi_device_lun); - } if (cdrom_drives[i].host_drive == 200) - { image_open(i, cdrom_image[i].image_path); - } else if ((cdrom_drives[i].host_drive >= 'A') && (cdrom_drives[i].host_drive <= 'Z')) - { ioctl_open(i, cdrom_drives[i].host_drive); - } else - { cdrom_null_open(i, cdrom_drives[i].host_drive); - } } floppy_load(0, floppyfns[0]); @@ -840,28 +639,17 @@ MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) break; case WM_SIZE: - winsizex = (lParam & 0xFFFF); - winsizey = (lParam >> 16) - (17 + 6); - if (winsizey < 0) - winsizey = 0; + scrnsz_x = (lParam & 0xFFFF); + scrnsz_y = (lParam >> 16) - (17 + 6); + if (scrnsz_y < 0) + scrnsz_y = 0; - MoveWindow(hwndSBAR, 0, winsizey + 6, winsizex, 17, TRUE); + plat_resize(scrnsz_x, scrnsz_y); - if (vid_apis[0][vid_api].local && (hwndRender != NULL)) { - MoveWindow(hwndRender, 0, 0, winsizex, winsizey, TRUE); + if (mousecapture) { + GetWindowRect(hwndRender, &rect); - if (vid_apis[video_fullscreen][vid_api].resize) { - startblit(); - video_wait_for_blit(); - vid_apis[video_fullscreen][vid_api].resize(winsizex, winsizey); - endblit(); - } - - if (mousecapture) { - GetWindowRect(hwndRender, &rect); - - ClipCursor(&rect); - } + ClipCursor(&rect); } if (window_remember) { @@ -889,7 +677,7 @@ MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) case WM_TIMER: if (wParam == TIMER_1SEC) { - onesec(); + pc_onesec(); } break; @@ -903,15 +691,8 @@ MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) break; case WM_LEAVEFULLSCREEN: - startblit(); - mouse_close(); - vid_apis[1][vid_api].close(); - video_fullscreen = 0; + plat_setfullscreen(0); config_save(); - vid_apis[0][vid_api].init(hwndRender); - mouse_init(); - endblit(); - device_force_redraw(); cgapal_rebuild(); break; @@ -1118,7 +899,15 @@ WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpszArg, int nFunsterStil) HWND hwnd; /* handle for our window */ HACCEL haccel; /* handle to accelerator table */ int bRet; - LARGE_INTEGER qpc_freq; + + /* We need this later. */ + hinstance = hInst; + + /* First, set our (default) language. */ + set_language(0x0409); + + /* Load common strings from the resource file. */ + LoadCommonStrings(); #ifdef USE_CONSOLE /* Create console window. */ @@ -1137,20 +926,14 @@ WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpszArg, int nFunsterStil) return(1); } - /* We need this later. */ - hinstance = hInst; - - /* Load common strings from the resource file. */ - LoadCommonStrings(); - /* Create our main window's class and register it. */ - wincl.hInstance = hInst; + wincl.hInstance = hinstance; wincl.lpszClassName = CLASS_NAME; wincl.lpfnWndProc = MainWindowProcedure; wincl.style = CS_DBLCLKS; /* Catch double-clicks */ wincl.cbSize = sizeof(WNDCLASSEX); - wincl.hIcon = LoadIcon(hInst, (LPCTSTR)100); - wincl.hIconSm = LoadIcon(hInst, (LPCTSTR)100); + wincl.hIcon = LoadIcon(hinstance, (LPCTSTR)100); + wincl.hIconSm = LoadIcon(hinstance, (LPCTSTR)100); wincl.hCursor = NULL; wincl.lpszMenuName = NULL; wincl.cbClsExtra = 0; @@ -1164,11 +947,10 @@ WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpszArg, int nFunsterStil) return(2); /* Load the Window Menu(s) from the resources. */ - menuMain = LoadMenu(hInst, MENU_NAME); + menuMain = LoadMenu(hinstance, MENU_NAME); /* Set the initial title for the program's main window. */ _swprintf(title, L"%s v%s", EMU_NAME_W, EMU_VERSION_W); - set_window_title(title); /* Now create our main window. */ hwnd = CreateWindowEx ( @@ -1178,15 +960,17 @@ WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpszArg, int nFunsterStil) (WS_OVERLAPPEDWINDOW & ~WS_SIZEBOX) | DS_3DLOOK, CW_USEDEFAULT, /* Windows decides the position */ CW_USEDEFAULT, /* where window ends up on the screen */ - 640+(GetSystemMetrics(SM_CXFIXEDFRAME)*2), /* width */ - 480+(GetSystemMetrics(SM_CYFIXEDFRAME)*2)+GetSystemMetrics(SM_CYMENUSIZE)+GetSystemMetrics(SM_CYCAPTION)+1, /* and height in pixels */ + scrnsz_x+(GetSystemMetrics(SM_CXFIXEDFRAME)*2), /* width */ + scrnsz_y+(GetSystemMetrics(SM_CYFIXEDFRAME)*2)+GetSystemMetrics(SM_CYMENUSIZE)+GetSystemMetrics(SM_CYCAPTION)+1, /* and height in pixels */ HWND_DESKTOP, /* window is a child to desktop */ menuMain, /* menu */ - hInst, /* Program Instance handler */ + hinstance, /* Program Instance handler */ NULL); /* no Window Creation data */ hwndMain = hwnd; - /* Resize the window if needed. */ + ui_window_title(title); + + /* Set up main window for resizing if configured. */ if (vid_resize) SetWindowLongPtr(hwnd, GWL_STYLE, (WS_OVERLAPPEDWINDOW&~WS_MINIMIZEBOX)); @@ -1194,6 +978,7 @@ WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpszArg, int nFunsterStil) SetWindowLongPtr(hwnd, GWL_STYLE, (WS_OVERLAPPEDWINDOW&~WS_SIZEBOX&~WS_THICKFRAME&~WS_MAXIMIZEBOX&~WS_MINIMIZEBOX)); + /* Move to the last-saved position if needed. */ if (window_remember) MoveWindow(hwnd, window_x, window_y, window_w, window_h, TRUE); @@ -1204,7 +989,7 @@ WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpszArg, int nFunsterStil) ShowWindow(hwnd, nFunsterStil); /* Load the accelerator table */ - haccel = LoadAccelerators(hInst, ACCEL_NAME); + haccel = LoadAccelerators(hinstance, ACCEL_NAME); if (haccel == NULL) { MessageBox(hwndMain, plat_get_string(IDS_2053), @@ -1229,7 +1014,7 @@ WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpszArg, int nFunsterStil) get_registry_key_map(); /* Create the status bar window. */ - StatusBarCreate(hwndMain, IDC_STATUS, hInst); + StatusBarCreate(hwndMain, IDC_STATUS, hinstance); /* * Before we can create the Render window, we first have @@ -1240,24 +1025,18 @@ WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpszArg, int nFunsterStil) /* Create the Machine Rendering window. */ hwndRender = CreateWindow(L"STATIC", NULL, WS_CHILD|SS_BITMAP, 0, 0, 1, 1, hwnd, NULL, hInst, NULL); - MoveWindow(hwndRender, 0, 0, winsizex, winsizey, TRUE); + MoveWindow(hwndRender, 0, 0, scrnsz_x, scrnsz_y, TRUE); - /* If this is a local renderer, enable it. */ - if (vid_apis[0][vid_api].local) - ShowWindow(hwndRender, SW_SHOW); - - /* Select the best system renderer available. */ - if (! vid_apis[0][vid_api].init(hwndRender)) { - vid_api ^= 1; - if (! vid_apis[0][vid_api].init(hwndRender)) { - MessageBox(hwnd, - plat_get_string(IDS_2095), - plat_get_string(IDS_2050), - MB_OK | MB_ICONERROR); - return(5); - } + /* Initialize the configured Video API. */ + if (! plat_setvid(vid_api)) { + MessageBox(hwnd, + plat_get_string(IDS_2095), + plat_get_string(IDS_2050), + MB_OK | MB_ICONERROR); + return(5); } +#if 0 /* Initialize the rendering window, or fullscreen. */ if (start_in_fullscreen) { startblit(); @@ -1268,11 +1047,10 @@ WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpszArg, int nFunsterStil) endblit(); device_force_redraw(); } - if (vid_apis[video_fullscreen][vid_api].resize) { - startblit(); - vid_apis[video_fullscreen][vid_api].resize(winsizex, winsizey); - endblit(); - } +#endif + + /* Set up the current window size. */ + plat_resize(scrnsz_x, scrnsz_y); /* All done, fire up the actual emulated machine. */ if (! pc_init_modules()) { @@ -1290,21 +1068,16 @@ WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpszArg, int nFunsterStil) /* Set the PAUSE mode depending on the renderer. */ plat_pause(0); + /* Initialize raw keyboard input buffer. */ + memset(recv_key, 0x00, sizeof(recv_key)); + /* * Everything has been configured, and all seems to work, * so now it is time to start the main thread to do some * real work, and we will hang in here, dealing with the * UI until we're done. */ - timeBeginPeriod(1); - - atexit(releasemouse); - - thMain = (HANDLE)_beginthread(MainThread, 0, NULL); - SetThreadPriority(thMain, THREAD_PRIORITY_HIGHEST); - - QueryPerformanceFrequency(&qpc_freq); - timer_freq = qpc_freq.QuadPart; + do_start(); /* Run the message loop. It will run until GetMessage() returns 0 */ while (! quited) { @@ -1325,33 +1098,21 @@ WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpszArg, int nFunsterStil) DispatchMessage(&messages); } - if (recv_key[0x58] && recv_key[0x42] && mousecapture) { + if (mousecapture && recv_key[0x58] && recv_key[0x42]) { ClipCursor(&oldclip); ShowCursor(TRUE); mousecapture = 0; } - if ((recv_key[0x1D] || recv_key[0x9D]) && + if (video_fullscreen && + (recv_key[0x1D] || recv_key[0x9D]) && (recv_key[0x38] || recv_key[0xB8]) && - (recv_key[0x51] || recv_key[0xD1]) && video_fullscreen) { - leave_fullscreen(); + (recv_key[0x51] || recv_key[0xD1])) { + /* Signal "exit fullscreen mode". */ + plat_setfullscreen(0); } } - /* Why start??? --FvK */ - startblit(); - - Sleep(200); - TerminateThread(thMain, 0); - - nvr_save(); - - config_save(); - - pc_close(); - - vid_apis[video_fullscreen][vid_api].close(); - timeEndPeriod(1); if (mousecapture) { @@ -1359,24 +1120,100 @@ WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpszArg, int nFunsterStil) ShowCursor(TRUE); } - UnregisterClass(SUB_CLASS_NAME, hInst); - UnregisterClass(CLASS_NAME, hInst); + UnregisterClass(SUB_CLASS_NAME, hinstance); + UnregisterClass(CLASS_NAME, hinstance); + + /* Close down the emulator. */ + do_stop(); return(messages.wParam); } -FILE * -plat_fopen(wchar_t *path, wchar_t *mode) +wchar_t * +ui_window_title(wchar_t *s) { - return(_wfopen(path, mode)); + if (! video_fullscreen) { + if (s != NULL) + wcscpy(wTitle, s); + else + s = wTitle; + + SetWindowText(hwndMain, s); + } + + return(s); +} + + +/* Set (or re-set) the language for the application. */ +void +set_language(int id) +{ + LCID lcidNew = MAKELCID(id, dwSubLangID); + + if (lang_id != lcidNew) { + /* Set our new language ID. */ + lang_id = lcidNew; + + SetThreadLocale(lang_id); + + /* Load the strings table for this ID. */ + LoadCommonStrings(); + +#if 0 + /* Update the menus for this ID. */ + MenuUpdate(); +#endif + } +} + + +/* + * We do this here since there is platform-specific stuff + * going on here, and we do it in a function separate from + * main() so we can call it from the UI module as well. + */ +void +do_start(void) +{ + LARGE_INTEGER qpc; + + /* We have not stopped yet. */ + quited = 0; + + /* Initialize the high-precision timer. */ + timeBeginPeriod(1); + QueryPerformanceFrequency(&qpc); + timer_freq = qpc.QuadPart; + pclog("Main timer precision: %llu\n", timer_freq); + + atexit(releasemouse); + + /* Start the emulator, really. */ + thMain = thread_create(pc_thread, &quited); + SetThreadPriority(thMain, THREAD_PRIORITY_HIGHEST); +} + + +/* Cleanly stop the emulator. */ +void +do_stop(void) +{ + quited = 1; + + plat_delay_ms(100); + + pc_close(thMain); + + thMain = NULL; } void -plat_remove(wchar_t *path) +plat_get_exe_name(wchar_t *s, int size) { - _wremove(path); + GetModuleFileName(hinstance, s, size); } @@ -1396,31 +1233,73 @@ plat_chdir(wchar_t *path) } -void -get_executable_name(wchar_t *s, int size) +FILE * +plat_fopen(wchar_t *path, wchar_t *mode) { - GetModuleFileName(hinstance, s, size); + return(_wfopen(path, mode)); +} + + +void +plat_remove(wchar_t *path) +{ + _wremove(path); } wchar_t * -set_window_title(wchar_t *s) +plat_get_filename(wchar_t *s) { - if (! video_fullscreen) { - if (s != NULL) - wcscpy(wTitle, s); - else - s = wTitle; + int c = wcslen(s) - 1; - SetWindowText(hwndMain, s); + while (c > 0) { + if (s[c] == L'/' || s[c] == L'\\') + return(&s[c+1]); + c--; } return(s); } +wchar_t * +plat_get_extension(wchar_t *s) +{ + int c = wcslen(s) - 1; + + if (c <= 0) + return(s); + + while (c && s[c] != L'.') + c--; + + if (!c) + return(&s[wcslen(s)]); + + return(&s[c+1]); +} + + +void +plat_append_filename(wchar_t *dest, wchar_t *s1, wchar_t *s2, int size) +{ + wcscat(dest, s1); + wcscat(dest, s2); +} + + +void +plat_put_backslash(wchar_t *s) +{ + int c = wcslen(s) - 1; + + if (s[c] != L'/' && s[c] != L'\\') + s[c] = L'/'; +} + + int -dir_check_exist(wchar_t *path) +plat_dir_check(wchar_t *path) { DWORD dwAttrib = GetFileAttributes(path); @@ -1430,14 +1309,14 @@ dir_check_exist(wchar_t *path) int -dir_create(wchar_t *path) +plat_dir_create(wchar_t *path) { return((int)CreateDirectory(path, NULL)); } uint64_t -timer_read(void) +plat_timer_read(void) { LARGE_INTEGER li; @@ -1448,76 +1327,47 @@ timer_read(void) uint32_t -get_ticks(void) +plat_get_ticks(void) { return(GetTickCount()); } void -delay_ms(uint32_t count) +plat_delay_ms(uint32_t count) { Sleep(count); } /* We should have the language ID as a parameter. */ -void -win_set_language(void) -{ - SetThreadLocale(dwLanguage); -} - - -/* Update the global language used. This needs a parameter.. */ -void -win_language_update(void) -{ - win_set_language(); -#if 0 - MenuUpdate(); -#endif - LoadCommonStrings(); -} - - -void -win_language_check(void) -{ - LCID dwLanguageNew = MAKELCID(dwLangID, dwSubLangID); - - if (dwLanguageNew != dwLanguage) { - dwLanguage = dwLanguageNew; - - win_language_update(); - } -} - - void plat_pause(int p) { - static wchar_t oldtitle[512]; + static wchar_t oldtitle[128]; + wchar_t title[128]; /* If un-pausing, as the renderer if that's OK. */ if (p == 0) - p = vid_apis[video_fullscreen][vid_api].pause(); + p = get_vidpause(); /* If already so, done. */ - if (pause == p) return; + if (dopause == p) return; if (p) { - wcscpy(oldtitle, wTitle); - wcscat(wTitle, L" - PAUSED -"); - set_window_title(NULL); + wcscpy(oldtitle, ui_window_title(NULL)); + wcscpy(title, oldtitle); + wcscat(title, L" - PAUSED -"); + ui_window_title(title); } else { - set_window_title(oldtitle); + ui_window_title(oldtitle); } - pause = p; + dopause = p; /* Update the actual menu. */ - CheckMenuItem(menuMain, IDM_ACTION_PAUSE, (pause)?MF_CHECKED:MF_UNCHECKED); + CheckMenuItem(menuMain, IDM_ACTION_PAUSE, + (dopause) ? MF_CHECKED : MF_UNCHECKED); } @@ -1555,169 +1405,3 @@ plat_get_string_from_string(char *str) { return(plat_get_string(atoi(str))); } - - -void -take_screenshot(void) -{ - wchar_t path[1024], fn[128]; - struct tm *info; - time_t now; - - pclog("Screenshot: video API is: %i\n", vid_api); - if ((vid_api < 0) || (vid_api > 1)) return; - - memset(fn, 0, sizeof(fn)); - memset(path, 0, sizeof(path)); - - (void)time(&now); - info = localtime(&now); - - append_filename_w(path, cfg_path, SCREENSHOT_PATH, sizeof(path)-2); - - if (! dir_check_exist(path)) - dir_create(path); - -#ifdef WIN32 - wcscat(path, L"\\"); -#else - wcscat(path, L"/"); -#endif - - switch(vid_api) { - case 0: /* ddraw */ - wcsftime(path, 128, L"%Y%m%d_%H%M%S.bmp", info); - append_filename_w(path, cfg_path, fn, 1024); - if (video_fullscreen) - ddraw_fs_take_screenshot(path); - else - ddraw_take_screenshot(path); - pclog("Screenshot: fn='%ls'\n", path); - break; - - case 1: /* d3d9 */ - wcsftime(fn, 128, L"%Y%m%d_%H%M%S.png", info); - append_filename_w(path, cfg_path, fn, 1024); - if (video_fullscreen) - d3d_fs_take_screenshot(path); - else - d3d_take_screenshot(path); - pclog("Screenshot: fn='%ls'\n", path); - break; - -#ifdef USE_VNC - case 2: /* vnc */ - wcsftime(fn, 128, L"%Y%m%d_%H%M%S.png", info); - append_filename_w(path, cfg_path, fn, 1024); - vnc_take_screenshot(path); - pclog("Screenshot: fn='%ls'\n", path); - break; -#endif - } -} - - -void -startblit(void) -{ - WaitForSingleObject(ghMutex, INFINITE); -} - - -void -endblit(void) -{ - ReleaseMutex(ghMutex); -} - - -void -updatewindowsize(int x, int y) -{ - int owsx = winsizex; - int owsy = winsizey; - int temp_overscan_x = overscan_x; - int temp_overscan_y = overscan_y; - double dx, dy, dtx, dty; - - if (vid_resize) return; - - if (x < 160) x = 160; - if (y < 100) y = 100; - if (x > 2048) x = 2048; - if (y > 2048) y = 2048; - - if (suppress_overscan) - temp_overscan_x = temp_overscan_y = 0; - - unscaled_size_x=x; efwinsizey=y; - - if (force_43) { - dx = (double) x; - dtx = (double) temp_overscan_x; - - dy = (double) y; - dty = (double) temp_overscan_y; - - /* Account for possible overscan. */ - if (temp_overscan_y == 16) { - /* CGA */ - dy = (((dx - dtx) / 4.0) * 3.0) + dty; - } else if (temp_overscan_y < 16) { - /* MDA/Hercules */ - dy = (x / 4.0) * 3.0; - } else { - if (enable_overscan) { - /* EGA/(S)VGA with overscan */ - dy = (((dx - dtx) / 4.0) * 3.0) + dty; - } else { - /* EGA/(S)VGA without overscan */ - dy = (x / 4.0) * 3.0; - } - } - unscaled_size_y = (int) dy; - } else { - unscaled_size_y = efwinsizey; - } - - switch(scale) { - case 0: - winsizex = unscaled_size_x >> 1; - winsizey = unscaled_size_y >> 1; - break; - - case 1: - winsizex = unscaled_size_x; - winsizey = unscaled_size_y; - break; - - case 2: - winsizex = (unscaled_size_x * 3) >> 1; - winsizey = (unscaled_size_y * 3) >> 1; - break; - - case 3: - winsizex = unscaled_size_x << 1; - winsizey = unscaled_size_y << 1; - break; - } - - if ((owsx != winsizex) || (owsy != winsizey)) - win_doresize = 1; - else - win_doresize = 0; -} - - -void -uws_natural(void) -{ - updatewindowsize(unscaled_size_x, efwinsizey); -} - - -void -leave_fullscreen(void) -{ - leave_fullscreen_flag = 1; -} diff --git a/src/win/win.h b/src/win/win.h index 916087de9..9ff3e03cc 100644 --- a/src/win/win.h +++ b/src/win/win.h @@ -6,11 +6,9 @@ * * This file is part of the 86Box distribution. * - * This file should contain things only used by the platform - * support modules for Windows. Generic definitions for UI and - * platform go into ../plat*.h. + * Platform support defintions for Win32. * - * Version: @(#)win.h 1.0.5 2017/10/13 + * Version: @(#)win.h 1.0.7 2017/10/19 * * Authors: Sarah Walker, * Miran Grca, @@ -20,12 +18,10 @@ * Copyright 2016,2017 Miran Grca. * Copyright 2017 Fred N. van Kempen. */ -#ifndef BOX_WIN_H -# define BOX_WIN_H +#ifndef PLAT_WIN_H +# define PLAT_WIN_H -# ifndef NO_UNICODE -# define UNICODE -# endif +# define UNICODE # define BITMAP WINDOWS_BITMAP # if 0 # ifdef _WIN32_WINNT @@ -52,13 +48,16 @@ #define WM_SAVESETTINGS 0x8888 +extern HINSTANCE hinstance; +extern HWND hwndMain, + hwndRender; +extern HANDLE ghMutex; +extern LCID lang_id; +extern HICON hIcon[512]; + extern int status_is_open; extern int mousecapture; -extern LCID dwLanguage; - -extern HINSTANCE hinstance; -extern HWND hwndMain; -extern HICON hIcon[512]; +extern int recv_key[272]; extern char openfilestring[260]; extern WCHAR wopenfilestring[260]; @@ -70,12 +69,16 @@ extern "C" { extern HICON LoadIconEx(PCTSTR pszIconName); -extern void win_language_set(void); -extern void win_language_update(void); -extern void win_language_check(void); +/* Emulator start/stop support functions. */ +extern void do_start(void); +extern void do_stop(void); + +/* Internal platform support functions. */ +extern void set_language(int id); +extern int get_vidpause(void); #ifdef EMU_DEVICE_H -extern void deviceconfig_open(HWND hwnd, device_t *device); +extern uint8_t deviceconfig_open(HWND hwnd, device_t *device); #endif extern void joystickconfig_open(HWND hwnd, int joy_nr, int type); @@ -122,4 +125,4 @@ extern wchar_t *BrowseFolder(wchar_t *saved_path, wchar_t *title); #endif -#endif /*BOX_WIN_H*/ +#endif /*PLAT_WIN_H*/ diff --git a/src/win/win_about.c b/src/win/win_about.c index c8b46d86a..f9e5dfad4 100644 --- a/src/win/win_about.c +++ b/src/win/win_about.c @@ -8,7 +8,7 @@ * * Handle the About dialog. * - * Version: @(#)win_about.c 1.0.3 2017/10/13 + * Version: @(#)win_about.c 1.0.4 2017/10/16 * * Authors: Sarah Walker, * Miran Grca, diff --git a/src/win/win_cdrom.c b/src/win/win_cdrom.c index 19e0f454e..7695e451c 100644 --- a/src/win/win_cdrom.c +++ b/src/win/win_cdrom.c @@ -8,7 +8,7 @@ * * Handle the platform-side of CDROM drives. * - * Version: @(#)win_cdrom.c 1.0.3 2017/10/09 + * Version: @(#)win_cdrom.c 1.0.4 2017/10/16 * * Authors: Sarah Walker, * Miran Grca, diff --git a/src/win/win_cdrom_ioctl.c b/src/win/win_cdrom_ioctl.c index e99b372d1..def543d6f 100644 --- a/src/win/win_cdrom_ioctl.c +++ b/src/win/win_cdrom_ioctl.c @@ -9,7 +9,7 @@ * Implementation of the CD-ROM host drive IOCTL interface for * Windows using SCSI Passthrough Direct. * - * Version: @(#)cdrom_ioctl.c 1.0.6 2017/10/09 + * Version: @(#)cdrom_ioctl.c 1.0.6 2017/10/16 * * Authors: Sarah Walker, * Miran Grca, @@ -26,6 +26,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../device.h" #include "../scsi/scsi.h" diff --git a/src/win/win_d3d.cc b/src/win/win_d3d.cc index 91f6897cb..964485962 100644 --- a/src/win/win_d3d.cc +++ b/src/win/win_d3d.cc @@ -8,7 +8,7 @@ * * Direct3D 9 rendererer and screenshots taking. * - * Version: @(#)win_d3d.cc 1.0.4 2017/10/13 + * Version: @(#)win_d3d.cc 1.0.5 2017/10/22 * * Authors: Sarah Walker, * Miran Grca, @@ -33,7 +33,6 @@ void d3d_init_objects(void); void d3d_close_objects(void); static void blit_memtoscreen(int x, int y, int y1, int y2, int w, int h); -static void blit_memtoscreen_8(int x, int y, int w, int h); static LPDIRECT3D9 d3d = NULL; static LPDIRECT3DDEVICE9 d3ddev = NULL; @@ -101,7 +100,7 @@ int d3d_init(HWND h) d3d_init_objects(); - video_setblit(blit_memtoscreen_8, blit_memtoscreen); + video_setblit(blit_memtoscreen); return 1; } @@ -327,101 +326,6 @@ static void blit_memtoscreen(int x, int y, int y1, int y2, int w, int h) PostMessage(d3d_hwnd, WM_RESETD3D, 0, 0); } -static void blit_memtoscreen_8(int x, int y, int w, int h) -{ - VOID* pVoid; - D3DLOCKED_RECT dr; - RECT r; - int yy, xx; - HRESULT hr = D3D_OK; - - if (h == 0) - { - video_blit_complete(); - return; /*Nothing to do*/ - } - - r.top = 0; - r.left = 0; - r.bottom = h; - r.right = 2047; - - hr = d3dTexture->LockRect(0, &dr, &r, 0); - if (hr == D3D_OK) - { - for (yy = 0; yy < h; yy++) - { - uint32_t *p = (uint32_t *)((uintptr_t)dr.pBits + (yy * dr.Pitch)); - if ((y + yy) >= 0 && (y + yy) < buffer->h) - { - for (xx = 0; xx < w; xx++) - p[xx] = pal_lookup[buffer->line[y + yy][x + xx]]; - } - } - video_blit_complete(); - - d3dTexture->UnlockRect(0); - } - else - video_blit_complete(); - - d3d_verts[0].tu = d3d_verts[2].tu = d3d_verts[3].tu = 0;//0.5 / 2048.0; - d3d_verts[0].tv = d3d_verts[3].tv = d3d_verts[4].tv = 0;//0.5 / 2048.0; - d3d_verts[1].tu = d3d_verts[4].tu = d3d_verts[5].tu = (float)w / 2048.0; - d3d_verts[1].tv = d3d_verts[2].tv = d3d_verts[5].tv = (float)h / 2048.0; - d3d_verts[0].color = d3d_verts[1].color = d3d_verts[2].color = - d3d_verts[3].color = d3d_verts[4].color = d3d_verts[5].color = - d3d_verts[6].color = d3d_verts[7].color = d3d_verts[8].color = - d3d_verts[9].color = d3d_verts[10].color = d3d_verts[11].color = 0xffffff; - - GetClientRect(d3d_hwnd, &r); - d3d_verts[0].x = d3d_verts[2].x = d3d_verts[3].x = -0.5; - d3d_verts[0].y = d3d_verts[3].y = d3d_verts[4].y = -0.5; - d3d_verts[1].x = d3d_verts[4].x = d3d_verts[5].x = (r.right - r.left) - 0.5; - d3d_verts[1].y = d3d_verts[2].y = d3d_verts[5].y = (r.bottom - r.top) - 0.5; - d3d_verts[6].x = d3d_verts[8].x = d3d_verts[9].x = (r.right - r.left) - 40.5; - d3d_verts[6].y = d3d_verts[9].y = d3d_verts[10].y = 8.5; - d3d_verts[7].x = d3d_verts[10].x = d3d_verts[11].x = (r.right - r.left) - 8.5; - d3d_verts[7].y = d3d_verts[8].y = d3d_verts[11].y = 14.5; - - if (hr == D3D_OK) - hr = v_buffer->Lock(0, 0, (void**)&pVoid, 0); // lock the vertex buffer - if (hr == D3D_OK) - memcpy(pVoid, d3d_verts, sizeof(d3d_verts)); // copy the vertices to the locked buffer - if (hr == D3D_OK) - hr = v_buffer->Unlock(); // unlock the vertex buffer - - if (hr == D3D_OK) - hr = d3ddev->BeginScene(); - - if (hr == D3D_OK) - { - if (hr == D3D_OK) - hr = d3ddev->SetTexture(0, d3dTexture); - - if (hr == D3D_OK) - hr = d3ddev->SetFVF(D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1); - - if (hr == D3D_OK) - hr = d3ddev->SetStreamSource(0, v_buffer, 0, sizeof(CUSTOMVERTEX)); - - if (hr == D3D_OK) - hr = d3ddev->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 2); - - if (hr == D3D_OK) - hr = d3ddev->SetTexture(0, NULL); - - if (hr == D3D_OK) - hr = d3ddev->EndScene(); - } - - if (hr == D3D_OK) - hr = d3ddev->Present(NULL, NULL, d3d_hwnd, NULL); - - if (hr == D3DERR_DEVICELOST || hr == D3DERR_INVALIDCALL) - PostMessage(d3d_hwnd, WM_RESETD3D, 0, 0); -} - void d3d_take_screenshot(wchar_t *fn) { LPDIRECT3DSURFACE9 d3dSurface = NULL; diff --git a/src/win/win_d3d_fs.cc b/src/win/win_d3d_fs.cc index 7e10b4fc5..dd3b1d958 100644 --- a/src/win/win_d3d_fs.cc +++ b/src/win/win_d3d_fs.cc @@ -8,7 +8,7 @@ * * Direct3D 9 full-screen rendererer. * - * Version: @(#)win_d3d_fs.cc 1.0.6 2017/10/13 + * Version: @(#)win_d3d_fs.cc 1.0.7 2017/10/22 * * Authors: Sarah Walker, * Miran Grca, @@ -36,7 +36,6 @@ extern "C" void d3d_fs_take_screenshot(wchar_t *fn); static void d3d_fs_init_objects(void); static void d3d_fs_close_objects(void); static void blit_memtoscreen(int x, int y, int y1, int y2, int w, int h); -static void blit_memtoscreen_8(int x, int y, int w, int h); static LPDIRECT3D9 d3d = NULL; @@ -130,7 +129,7 @@ int d3d_fs_init(HWND h) d3d_fs_init_objects(); - video_setblit(blit_memtoscreen_8, blit_memtoscreen); + video_setblit(blit_memtoscreen); return 1; } @@ -416,124 +415,6 @@ static void blit_memtoscreen(int x, int y, int y1, int y2, int w, int h) PostMessage(hwndMain, WM_RESETD3D, 0, 0); } -static void blit_memtoscreen_8(int x, int y, int w, int h) -{ - HRESULT hr = D3D_OK; - VOID* pVoid; - D3DLOCKED_RECT dr; - RECT window_rect; - int xx, yy; - double l = 0, t = 0, r = 0, b = 0; - - if (!h) - { - video_blit_complete(); - return; /*Nothing to do*/ - } - - if (hr == D3D_OK) - { - RECT lock_rect; - - lock_rect.top = 0; - lock_rect.left = 0; - lock_rect.bottom = 2047; - lock_rect.right = 2047; - - hr = d3dTexture->LockRect(0, &dr, &lock_rect, 0); - if (hr == D3D_OK) - { - for (yy = 0; yy < h; yy++) - { - uint32_t *p = (uint32_t *)((uintptr_t)dr.pBits + (yy * dr.Pitch)); - if ((y + yy) >= 0 && (y + yy) < buffer->h) - { - for (xx = 0; xx < w; xx++) - p[xx] = pal_lookup[buffer->line[y + yy][x + xx]]; - } - } - video_blit_complete(); - d3dTexture->UnlockRect(0); - } - else - { - video_blit_complete(); - return; - } - } - else - video_blit_complete(); - - d3d_verts[0].tu = d3d_verts[2].tu = d3d_verts[3].tu = 0; - d3d_verts[0].tv = d3d_verts[3].tv = d3d_verts[4].tv = 0; - d3d_verts[1].tu = d3d_verts[4].tu = d3d_verts[5].tu = (float)w / 2048.0; - d3d_verts[1].tv = d3d_verts[2].tv = d3d_verts[5].tv = (float)h / 2048.0; - d3d_verts[0].color = d3d_verts[1].color = d3d_verts[2].color = - d3d_verts[3].color = d3d_verts[4].color = d3d_verts[5].color = - d3d_verts[6].color = d3d_verts[7].color = d3d_verts[8].color = - d3d_verts[9].color = d3d_verts[10].color = d3d_verts[11].color = 0xffffff; - - GetClientRect(d3d_device_window, &window_rect); - d3d_fs_size(window_rect, &l, &t, &r, &b, w, h); - - d3d_verts[0].x = l; - d3d_verts[0].y = t; - d3d_verts[1].x = r; - d3d_verts[1].y = b; - d3d_verts[2].x = l; - d3d_verts[2].y = b; - d3d_verts[3].x = l; - d3d_verts[3].y = t; - d3d_verts[4].x = r; - d3d_verts[4].y = t; - d3d_verts[5].x = r; - d3d_verts[5].y = b; - d3d_verts[6].x = d3d_verts[8].x = d3d_verts[9].x = r - 40.5; - d3d_verts[6].y = d3d_verts[9].y = d3d_verts[10].y = t + 8.5; - d3d_verts[7].x = d3d_verts[10].x = d3d_verts[11].x = r - 8.5; - d3d_verts[7].y = d3d_verts[8].y = d3d_verts[11].y = t + 14.5; - - if (hr == D3D_OK) - hr = v_buffer->Lock(0, 0, (void**)&pVoid, 0); - if (hr == D3D_OK) - memcpy(pVoid, d3d_verts, sizeof(d3d_verts)); - if (hr == D3D_OK) - hr = v_buffer->Unlock(); - - if (hr == D3D_OK) - hr = d3ddev->BeginScene(); - - if (hr == D3D_OK) - { - if (hr == D3D_OK) - d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0, 0); - - if (hr == D3D_OK) - hr = d3ddev->SetTexture(0, d3dTexture); - - if (hr == D3D_OK) - hr = d3ddev->SetFVF(D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1); - - if (hr == D3D_OK) - hr = d3ddev->SetStreamSource(0, v_buffer, 0, sizeof(CUSTOMVERTEX)); - - if (hr == D3D_OK) - hr = d3ddev->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 2); - - if (hr == D3D_OK) - hr = d3ddev->SetTexture(0, NULL); - - if (hr == D3D_OK) - hr = d3ddev->EndScene(); - } - - if (hr == D3D_OK) - hr = d3ddev->Present(NULL, NULL, d3d_device_window, NULL); - - if (hr == D3DERR_DEVICELOST || hr == D3DERR_INVALIDCALL) - PostMessage(hwndMain, WM_RESETD3D, 0, 0); -} - void d3d_fs_take_screenshot(wchar_t *fn) { diff --git a/src/win/win_ddraw.cc b/src/win/win_ddraw.cc index ce02b4fa4..5b1fdfe5b 100644 --- a/src/win/win_ddraw.cc +++ b/src/win/win_ddraw.cc @@ -236,70 +236,6 @@ blit_memtoscreen(int x, int y, int y1, int y2, int w, int h) } -static void -blit_memtoscreen_8(int x, int y, int w, int h) -{ - RECT r_src; - RECT r_dest; - int xx, yy; - POINT po; - uint32_t *p; - HRESULT hr; - - if (lpdds_back == NULL) { - video_blit_complete(); - return; /*Nothing to do*/ - } - - memset(&ddsd, 0, sizeof(ddsd)); - ddsd.dwSize = sizeof(ddsd); - - hr = lpdds_back->Lock(NULL, &ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL); - if (hr == DDERR_SURFACELOST) { - lpdds_back->Restore(); - lpdds_back->Lock(NULL, &ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL); - device_force_redraw(); - } - if (!ddsd.lpSurface) { - video_blit_complete(); - return; - } - - for (yy = 0; yy < h; yy++) { - if ((y + yy) >= 0 && (y + yy) < buffer->h) { - p = (uint32_t *) &(((uint8_t *) ddsd.lpSurface)[yy * ddsd.lPitch]); - for (xx = 0; xx < w; xx++) - p[xx] = pal_lookup[buffer->line[y + yy][x + xx]]; - } - } - p = &(((uint32_t *) ddsd.lpSurface)[4 * ddsd.lPitch]); - lpdds_back->Unlock(NULL); - video_blit_complete(); - - po.x = po.y = 0; - ClientToScreen(ddraw_hwnd, &po); - GetClientRect(ddraw_hwnd, &r_dest); - OffsetRect(&r_dest, po.x, po.y); - - r_src.left = 0; - r_src.top = 0; - r_src.right = w; - r_src.bottom = h; - - hr = lpdds_back2->Blt(&r_src, lpdds_back, &r_src, DDBLT_WAIT, NULL); - if (hr == DDERR_SURFACELOST) { - lpdds_back2->Restore(); - lpdds_back2->Blt(&r_src, lpdds_back, &r_src, DDBLT_WAIT, NULL); - } - - hr = lpdds_pri->Blt(&r_dest, lpdds_back2, &r_src, DDBLT_WAIT, NULL); - if (hr == DDERR_SURFACELOST) { - lpdds_pri->Restore(); - hr = lpdds_pri->Blt(&r_dest, lpdds_back2, &r_src, DDBLT_WAIT, NULL); - } -} - - int ddraw_init(HWND h) { @@ -361,7 +297,7 @@ ddraw_init(HWND h) ddraw_hwnd = h; - video_setblit(blit_memtoscreen_8, blit_memtoscreen); + video_setblit(blit_memtoscreen); return(1); } diff --git a/src/win/win_ddraw_fs.cc b/src/win/win_ddraw_fs.cc index 5604def7b..f2804ee8c 100644 --- a/src/win/win_ddraw_fs.cc +++ b/src/win/win_ddraw_fs.cc @@ -31,7 +31,6 @@ extern void ddraw_common_take_screenshot(wchar_t *fn, IDirectDrawSurface7 *pDDSu static void blit_memtoscreen(int, int, int, int, int, int); -static void blit_memtoscreen_8(int, int, int, int); int ddraw_fs_init(HWND h) @@ -92,7 +91,7 @@ int ddraw_fs_init(HWND h) pclog("DDRAW_INIT complete\n"); ddraw_hwnd = h; - video_setblit(blit_memtoscreen_8, blit_memtoscreen); + video_setblit(blit_memtoscreen); return 1; } @@ -244,77 +243,6 @@ static void blit_memtoscreen(int x, int y, int y1, int y2, int w, int h) } } -static void blit_memtoscreen_8(int x, int y, int w, int h) -{ - RECT r_src; - RECT r_dest; - RECT window_rect; - int xx, yy; - HRESULT hr; - DDBLTFX ddbltfx; - - if (lpdds_back == NULL) - { - video_blit_complete(); - return; /*Nothing to do*/ - } - - memset(&ddsd, 0, sizeof(ddsd)); - ddsd.dwSize = sizeof(ddsd); - - hr = lpdds_back->Lock(NULL, &ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL); - - if (hr == DDERR_SURFACELOST) - { - lpdds_back->Restore(); - lpdds_back->Lock(NULL, &ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL); - device_force_redraw(); - } - if (!ddsd.lpSurface) - { - video_blit_complete(); - return; - } - for (yy = 0; yy < h; yy++) - { - if ((y + yy) >= 0 && (y + yy) < buffer->h) - { - uint32_t *p = (uint32_t *) &(((uint8_t *) ddsd.lpSurface)[yy * ddsd.lPitch]); - for (xx = 0; xx < w; xx++) - { - p[xx] = pal_lookup[buffer->line[y + yy][x + xx]]; - } - } - } - video_blit_complete(); - lpdds_back->Unlock(NULL); - - window_rect.left = 0; - window_rect.top = 0; - window_rect.right = ddraw_w; - window_rect.bottom = ddraw_h; - ddraw_fs_size(window_rect, &r_dest, w, h); - - r_src.left = 0; - r_src.top = 0; - r_src.right = w; - r_src.bottom = h; - - ddbltfx.dwSize = sizeof(ddbltfx); - ddbltfx.dwFillColor = 0; - - lpdds_back2->Blt(&window_rect, NULL, NULL, DDBLT_WAIT | DDBLT_COLORFILL, &ddbltfx); - - hr = lpdds_back2->Blt(&r_dest, lpdds_back, &r_src, DDBLT_WAIT, NULL); - if (hr == DDERR_SURFACELOST) - { - lpdds_back2->Restore(); - lpdds_back2->Blt(&r_dest, lpdds_back, &r_src, DDBLT_WAIT, NULL); - } - - lpdds_pri->Flip(NULL, DDFLIP_NOVSYNC); -} - int ddraw_fs_pause(void) diff --git a/src/win/win_deviceconfig.c b/src/win/win_deviceconfig.c index 531a2867d..46355f0c0 100644 --- a/src/win/win_deviceconfig.c +++ b/src/win/win_deviceconfig.c @@ -8,7 +8,7 @@ * * Windows device configuration dialog implementation. * - * Version: @(#)win_deviceconfig.c 1.0.7 2017/10/10 + * Version: @(#)win_deviceconfig.c 1.0.8 2017/10/16 * * Authors: Sarah Walker, * Miran Grca, @@ -20,7 +20,7 @@ #include #include #include -#include "../ibm.h" +#include "../86box.h" #include "../config.h" #include "../device.h" #include "../plat.h" @@ -32,6 +32,8 @@ static device_t *config_device; +static uint8_t deviceconfig_changed = 0; + static BOOL CALLBACK deviceconfig_dlgproc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) @@ -39,7 +41,6 @@ deviceconfig_dlgproc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) HWND h; int val_int; - int ret; int id; int c; int num; @@ -278,21 +279,12 @@ deviceconfig_dlgproc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) if (!changed) { + deviceconfig_changed = 0; EndDialog(hdlg, 0); return TRUE; } - ret = ui_msgbox(MBX_QUESTION, (wchar_t *)IDS_2051); - switch(ret) - { - case 1: - EndDialog(hdlg, 0); - return TRUE; - case -1: - return FALSE; - default: - break; - } + deviceconfig_changed = 1; id = IDC_CONFIG_BASE; config = config_device->config; @@ -367,15 +359,12 @@ deviceconfig_dlgproc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) config++; } - config_save(); - - pc_reset_hard(); - EndDialog(hdlg, 0); return TRUE; } else if (cid == IDCANCEL) { + deviceconfig_changed = 0; EndDialog(hdlg, 0); return TRUE; } @@ -462,7 +451,7 @@ deviceconfig_dlgproc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) return FALSE; } -void deviceconfig_open(HWND hwnd, device_t *device) +uint8_t deviceconfig_open(HWND hwnd, device_t *device) { device_config_t *config = device->config; uint16_t *data_block = malloc(16384); @@ -472,6 +461,8 @@ void deviceconfig_open(HWND hwnd, device_t *device) int y = 10; int id = IDC_CONFIG_BASE; + deviceconfig_changed = 0; + memset(data_block, 0, 4096); dlg->style = DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU; @@ -731,4 +722,6 @@ void deviceconfig_open(HWND hwnd, device_t *device) DialogBoxIndirect(hinstance, dlg, hwnd, deviceconfig_dlgproc); free(data_block); + + return deviceconfig_changed; } diff --git a/src/win/win_dialog.c b/src/win/win_dialog.c index a92bf8c02..9621a8e4e 100644 --- a/src/win/win_dialog.c +++ b/src/win/win_dialog.c @@ -8,7 +8,7 @@ * * Several dialogs for the application. * - * Version: @(#)win_dialog.c 1.0.3 2017/10/10 + * Version: @(#)win_dialog.c 1.0.4 2017/10/16 * * Author: Miran Grca, * Fred N. van Kempen, @@ -27,7 +27,7 @@ #include #include #include -#include "../ibm.h" +#include "../86box.h" #include "../device.h" #include "../plat.h" #include "../ui.h" diff --git a/src/win/win_dynld.c b/src/win/win_dynld.c index 1065867e8..06a308365 100644 --- a/src/win/win_dynld.c +++ b/src/win/win_dynld.c @@ -8,7 +8,7 @@ * * Try to load a support DLL. * - * Version: @(#)win_dynld.c 1.0.5 2017/10/11 + * Version: @(#)win_dynld.c 1.0.6 2017/10/16 * * Author: Fred N. van Kempen, * @@ -20,7 +20,7 @@ #include #include #include -#include "../ibm.h" +#include "../86box.h" #include "../plat_dynld.h" diff --git a/src/win/win_joystick.cc b/src/win/win_joystick.cc index 695638ee8..56d2627e8 100644 --- a/src/win/win_joystick.cc +++ b/src/win/win_joystick.cc @@ -8,7 +8,7 @@ * * Joystick interface to host device. * - * Version: @(#)win_joystick.cc 1.0.4 2017/10/12 + * Version: @(#)win_joystick.cc 1.0.5 2017/10/17 * * Authors: Sarah Walker, * Miran Grca, @@ -220,10 +220,12 @@ static int joystick_get_axis(int joystick_nr, int mapping) return plat_joystick_state[joystick_nr].a[plat_joystick_state[joystick_nr].axis[mapping].id]; } -void joystick_poll() +void joystick_process(void) { int c, d; + if (joystick_type != 7) return; + for (c = 0; c < joysticks_present; c++) { DIJOYSTATE joystate; diff --git a/src/win/win_joystickconfig.c b/src/win/win_joystickconfig.c index 28c300629..cd5304805 100644 --- a/src/win/win_joystickconfig.c +++ b/src/win/win_joystickconfig.c @@ -9,7 +9,7 @@ #include #include #include -#include "../ibm.h" +#include "../86box.h" #include "../config.h" #include "../device.h" #include "../game/gameport.h" diff --git a/src/win/win_keyboard.c b/src/win/win_keyboard.c index 75bc80e6a..3f10e3a8c 100644 --- a/src/win/win_keyboard.c +++ b/src/win/win_keyboard.c @@ -8,7 +8,7 @@ * * Windows raw keyboard input handler. * - * Version: @(#)win_keyboard.c 1.0.2 2017/10/10 + * Version: @(#)win_keyboard.c 1.0.3 2017/10/16 * * Author: Miran Grca, * @@ -20,12 +20,11 @@ #include #include #undef BITMAP -//#include -//#include #include #include #include #include +#include "../86box.h" #include "../device.h" #include "../plat.h" #include "../plat_keyboard.h" diff --git a/src/win/win_midi.c b/src/win/win_midi.c index 0d49bf81e..d9d92eeb6 100644 --- a/src/win/win_midi.c +++ b/src/win/win_midi.c @@ -4,7 +4,7 @@ #include #include #include -#include "../ibm.h" +#include "../86box.h" #include "../config.h" #include "../sound/midi.h" #include "../plat.h" diff --git a/src/win/win_opendir.c b/src/win/win_opendir.c index ba8430a86..af0c6e768 100644 --- a/src/win/win_opendir.c +++ b/src/win/win_opendir.c @@ -10,7 +10,7 @@ * * Based on old original code @(#)dir_win32.c 1.2.0 2007/04/19 * - * Version: @(#)win_opendir.c 1.0.3 2017/10/10 + * Version: @(#)win_opendir.c 1.0.3 2017/10/16 * * Author: Fred N. van Kempen, * @@ -25,7 +25,7 @@ #include #include #include -#include "../ibm.h" +#include "../86box.h" #include "../plat.h" #include "../plat_dir.h" diff --git a/src/win/win_serial.c b/src/win/win_serial.c index df5823171..21dc7443d 100644 --- a/src/win/win_serial.c +++ b/src/win/win_serial.c @@ -12,7 +12,7 @@ * Windows and UNIX systems, with support for FTDI and Prolific * USB ports. Support for these has been removed. * - * Version: @(#)win_serial.c 1.0.6 2017/10/10 + * Version: @(#)win_serial.c 1.0.6 2017/10/16 * * Author: Fred N. van Kempen, * @@ -23,7 +23,7 @@ #include #include #define PLAT_SERIAL_C -#include "../ibm.h" +#include "../86box.h" #include "../plat.h" #include "../plat_serial.h" diff --git a/src/win/win_settings.c b/src/win/win_settings.c index 15b774d5e..574ec4ba5 100644 --- a/src/win/win_settings.c +++ b/src/win/win_settings.c @@ -8,7 +8,7 @@ * * Windows 86Box Settings dialog handler. * - * Version: @(#)win_settings.c 1.0.21 2017/10/13 + * Version: @(#)win_settings.c 1.0.21 2017/10/16 * * Author: Miran Grca, * @@ -25,6 +25,7 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../config.h" #include "../cpu/cpu.h" @@ -86,6 +87,8 @@ static char temp_hdc_name[16]; static char *hdc_names[16]; static int temp_bugger; +static uint8_t temp_deviceconfig; + /* Hard disks category */ static hard_disk_t temp_hdd[HDD_NUM]; @@ -195,6 +198,8 @@ static void win_settings_init(void) temp_fdd_check_bpb[i] = fdd_get_check_bpb(i); } memcpy(temp_cdrom_drives, cdrom_drives, CDROM_NUM * sizeof(cdrom_drive_t)); + + temp_deviceconfig = 0; } @@ -267,6 +272,8 @@ static int win_settings_changed(void) } i = i || memcmp(cdrom_drives, temp_cdrom_drives, CDROM_NUM * sizeof(cdrom_drive_t)); + i = i || !!temp_deviceconfig; + return i; } @@ -346,6 +353,11 @@ static void win_settings_save(void) /* Peripherals category */ scsi_card_current = temp_scsi_card; + if (hdc_name) { + free(hdc_name); + hdc_name = NULL; + } + hdc_name = (char *) malloc(sizeof(temp_hdc_name)); strncpy(hdc_name, temp_hdc_name, sizeof(temp_hdc_name) - 1); hdc_init(hdc_name); ide_enable[2] = temp_ide_ter; @@ -659,7 +671,7 @@ static BOOL CALLBACK win_settings_machine_proc(HWND hdlg, UINT message, WPARAM w h = GetDlgItem(hdlg, IDC_COMBO_MACHINE); temp_machine = listtomachine[SendMessage(h, CB_GETCURSEL, 0, 0)]; - deviceconfig_open(hdlg, (void *)machine_getdevice(temp_machine)); + temp_deviceconfig |= deviceconfig_open(hdlg, (void *)machine_getdevice(temp_machine)); break; } @@ -841,7 +853,7 @@ static BOOL CALLBACK win_settings_video_proc(HWND hdlg, UINT message, WPARAM wPa break; case IDC_BUTTON_VOODOO: - deviceconfig_open(hdlg, (void *)&voodoo_device); + temp_deviceconfig |= deviceconfig_open(hdlg, (void *)&voodoo_device); break; case IDC_CONFIGURE_VID: @@ -851,7 +863,7 @@ static BOOL CALLBACK win_settings_video_proc(HWND hdlg, UINT message, WPARAM wPa h = GetDlgItem(hdlg, IDC_COMBO_VIDEO); SendMessage(h, CB_GETLBTEXT, SendMessage(h, CB_GETCURSEL, 0, 0), (LPARAM) lptsTemp); wcstombs(stransi, lptsTemp, 512); - deviceconfig_open(hdlg, (void *)video_card_getdevice(video_card_getid(stransi))); + temp_deviceconfig |= deviceconfig_open(hdlg, (void *)video_card_getdevice(video_card_getid(stransi))); free(stransi); free(lptsTemp); @@ -1217,7 +1229,7 @@ static BOOL CALLBACK win_settings_sound_proc(HWND hdlg, UINT message, WPARAM wPa h = GetDlgItem(hdlg, IDC_COMBO_SOUND); temp_sound_card = settings_list_to_sound[SendMessage(h, CB_GETCURSEL, 0, 0)]; - deviceconfig_open(hdlg, (void *)sound_card_getdevice(temp_sound_card)); + temp_deviceconfig |= deviceconfig_open(hdlg, (void *)sound_card_getdevice(temp_sound_card)); break; case IDC_COMBO_MIDI: @@ -1246,7 +1258,7 @@ static BOOL CALLBACK win_settings_sound_proc(HWND hdlg, UINT message, WPARAM wPa h = GetDlgItem(hdlg, IDC_COMBO_MIDI); temp_midi_device = settings_list_to_midi[SendMessage(h, CB_GETCURSEL, 0, 0)]; - deviceconfig_open(hdlg, (void *)midi_device_getdevice(temp_midi_device)); + temp_deviceconfig |= deviceconfig_open(hdlg, (void *)midi_device_getdevice(temp_midi_device)); break; case IDC_CHECK_MPU401: @@ -1258,7 +1270,7 @@ static BOOL CALLBACK win_settings_sound_proc(HWND hdlg, UINT message, WPARAM wPa break; case IDC_CONFIGURE_MPU401: - deviceconfig_open(hdlg, (void *)&mpu401_device); + temp_deviceconfig |= deviceconfig_open(hdlg, (void *)&mpu401_device); break; } return FALSE; @@ -1586,7 +1598,7 @@ static BOOL CALLBACK win_settings_peripherals_proc(HWND hdlg, UINT message, WPAR h = GetDlgItem(hdlg, IDC_COMBO_SCSI); temp_scsi_card = settings_list_to_scsi[SendMessage(h, CB_GETCURSEL, 0, 0)]; - deviceconfig_open(hdlg, (void *)scsi_card_getdevice(temp_scsi_card)); + temp_deviceconfig |= deviceconfig_open(hdlg, (void *)scsi_card_getdevice(temp_scsi_card)); break; case IDC_COMBO_SCSI: @@ -1826,7 +1838,7 @@ static BOOL CALLBACK win_settings_network_proc(HWND hdlg, UINT message, WPARAM w h = GetDlgItem(hdlg, IDC_COMBO_NET); temp_net_card = settings_list_to_network[SendMessage(h, CB_GETCURSEL, 0, 0)]; - deviceconfig_open(hdlg, (void *)network_card_getdevice(temp_net_card)); + temp_deviceconfig |= deviceconfig_open(hdlg, (void *)network_card_getdevice(temp_net_card)); break; } return FALSE; diff --git a/src/win/win_status.c b/src/win/win_status.c index 86565f865..b32e02d42 100644 --- a/src/win/win_status.c +++ b/src/win/win_status.c @@ -9,13 +9,15 @@ #include #include #include +#include "../86box.h" #include "../ibm.h" #include "../mem.h" #include "../cpu/x86_ops.h" #ifdef USE_DYNAREC -#include "../cpu/codegen.h" +# include "../cpu/codegen.h" #endif #include "../device.h" +#include "../plat.h" #include "win.h" @@ -41,7 +43,7 @@ StatusWindowProcedure(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) /*FALLTHROUGH*/ case WM_USER: - new_time = timer_read(); + new_time = plat_timer_read(); status_diff = new_time - status_time; status_time = new_time; sprintf(temp, diff --git a/src/win/win_stbar.c b/src/win/win_stbar.c index 3651eabeb..b3fd18887 100644 --- a/src/win/win_stbar.c +++ b/src/win/win_stbar.c @@ -8,7 +8,7 @@ * * Implement the application's Status Bar. * - * Version: @(#)win_stbar.c 1.0.3 2017/10/09 + * Version: @(#)win_stbar.c 1.0.3 2017/10/16 * * Authors: Miran Grca, * Fred N. van Kempen, @@ -28,6 +28,7 @@ #include #include #include +#include "../86box.h" #include "../config.h" #include "../ibm.h" #include "../cpu/cpu.h" diff --git a/src/win/win_thread.c b/src/win/win_thread.c index db8afc75e..e5ecdb074 100644 --- a/src/win/win_thread.c +++ b/src/win/win_thread.c @@ -8,7 +8,7 @@ * * Implement threads and mutexes for the Win32 platform. * - * Version: @(#)win_thread.c 1.0.3 2017/10/14 + * Version: @(#)win_thread.c 1.0.5 2017/10/19 * * Authors: Sarah Walker, * Fred N. van Kempen, @@ -27,7 +27,7 @@ #include #include #include -#include "../ibm.h" +#include "../86box.h" #include "../plat.h" @@ -36,26 +36,33 @@ typedef struct { } win_event_t; -void * -thread_create(void (*thread_rout)(void *param), void *param) +thread_t * +thread_create(void (*func)(void *param), void *param) { - return((void *)_beginthread(thread_rout, 0, param)); + return((thread_t *)_beginthread(func, 0, param)); } void -thread_kill(void *handle) +thread_kill(void *arg) { - if (handle == NULL) return; + if (arg == NULL) return; - TerminateThread(handle, 0); + TerminateThread(arg, 0); } -void -thread_sleep(int t) +int +thread_wait(thread_t *arg, int timeout) { - Sleep(t); + if (arg == NULL) return(0); + + if (timeout == -1) + timeout = INFINITE; + + if (WaitForSingleObject(arg, timeout)) return(1); + + return(0); } @@ -99,6 +106,8 @@ thread_wait_event(event_t *arg, int timeout) if (arg == NULL) return(0); + if (ev->handle == NULL) return(0); + if (timeout == -1) timeout = INFINITE; diff --git a/src/win/win_video.c b/src/win/win_video.c new file mode 100644 index 000000000..e2bdc2114 --- /dev/null +++ b/src/win/win_video.c @@ -0,0 +1,315 @@ +/* + * 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. + * + * Platform video API support for Win32. + * + * Version: @(#)win_video.c 1.0.1 2017/10/18 + * + * Author: Fred N. van Kempen, + * + * Copyright 2017 Fred N. van Kempen. + */ +#define UNICODE +#define BITMAP WINDOWS_BITMAP +#include +#include +#include +#undef BITMAP +#include +#include +#include +#include +#include +#include +#include "../86box.h" +#include "../config.h" +#include "../device.h" +#include "../video/video.h" +#include "../plat.h" +#include "../plat_mouse.h" +#include "../ui.h" +#ifdef USE_VNC +# include "../vnc.h" +#endif +#ifdef USE_RDP +# include "../rdp.h" +#endif +#include "win.h" +#include "win_ddraw.h" +#include "win_d3d.h" + + +static struct { + char *name; + int local; + int (*init)(void *); + void (*close)(void); + void (*resize)(int x, int y); + int (*pause)(void); +} vid_apis[2][4] = { + { + { "DDraw", 1, (int(*)(void*))ddraw_init, ddraw_close, NULL, ddraw_pause }, + { "D3D", 1, (int(*)(void*))d3d_init, d3d_close, d3d_resize, d3d_pause }, +#ifdef USE_VNC + { "VNC", 0, vnc_init, vnc_close, vnc_resize, vnc_pause }, +#else + { NULL, 0, NULL, NULL, NULL, NULL }, +#endif +#ifdef USE_RDP + { "RDP", 0, rdp_init, rdp_close, rdp_resize, rdp_pause } +#else + { NULL, 0, NULL, NULL, NULL, NULL } +#endif + }, + { + { "DDraw", 1, (int(*)(void*))ddraw_fs_init, ddraw_fs_close, NULL, ddraw_fs_pause }, + { "D3D", 1, (int(*)(void*))d3d_fs_init, d3d_fs_close, NULL, d3d_fs_pause }, +#ifdef USE_VNC + { "VNC", 0, vnc_init, vnc_close, vnc_resize, vnc_pause }, +#else + { NULL, 0, NULL, NULL, NULL, NULL }, +#endif +#ifdef USE_RDP + { "RDP", 0, rdp_init, rdp_close, rdp_resize, rdp_pause } +#else + { NULL, 0, NULL, NULL, NULL, NULL } +#endif + }, +}; + + +#if 0 + /* Initialize the rendering window, or fullscreen. */ + if (start_in_fullscreen) { + startblit(); + vid_apis[0][vid_api].close(); + video_fullscreen = 1; + vid_apis[1][vid_api].init(hwndRender); + leave_fullscreen_flag = 0; + endblit(); + device_force_redraw(); + } +#endif + + +/* Return the VIDAPI number for the given name. */ +int +plat_vidapi(char *name) +{ + int i; + + if (!strcasecmp(name, "default") || !strcasecmp(name, "system")) return(0); + + for (i=0; i<4; i++) { + if (vid_apis[0][i].name && + !strcasecmp(vid_apis[0][i].name, name)) return(i); + } + + /* Default value. */ + return(0); +} + + +int +plat_setvid(int api) +{ + int i; + + pclog("Initializing VIDAPI: api=%d\n", api); + startblit(); + video_wait_for_blit(); + + /* Close the (old) API. */ + vid_apis[0][vid_api].close(); +#ifdef USE_WX + ui_check_menu_item(IDM_View_WX+vid_api, 0); +#endif + vid_api = api; + + if (vid_apis[0][vid_api].local) + ShowWindow(hwndRender, SW_SHOW); + else + ShowWindow(hwndRender, SW_HIDE); + + /* Initialize the (new) API. */ +#ifdef USE_WX + ui_check_menu_item(IDM_View_WX+vid_api, 1); +#endif + i = vid_apis[0][vid_api].init((void *)hwndRender); + endblit(); + if (! i) return(0); + + device_force_redraw(); + + return(1); +} + + +int +get_vidpause(void) +{ + return(vid_apis[video_fullscreen][vid_api].pause()); +} + + +void +plat_setfullscreen(int on) +{ + static int flag = 0; + + /* Want off and already off? */ + if (!on && !video_fullscreen) return; + + /* Want on and already on? */ + if (on && video_fullscreen) return; + + if (!on && !flag) { + /* We want to leave FS mode. */ + flag = 1; + + return; + } + + if (video_fullscreen_first) { + video_fullscreen_first = 0; + ui_msgbox(MBX_INFO, (wchar_t *)IDS_2074); + } + + /* OK, claim the video. */ + startblit(); + video_wait_for_blit(); + + mouse_close(); + + /* Close the current mode, and open the new one. */ + vid_apis[video_fullscreen][vid_api].close(); + video_fullscreen = on; + vid_apis[video_fullscreen][vid_api].init(NULL); + flag = 0; + + mouse_init(); + + /* Release video and make it redraw the screen. */ + endblit(); + device_force_redraw(); +} + + +void +take_screenshot(void) +{ + wchar_t path[1024], fn[128]; + struct tm *info; + time_t now; + + pclog("Screenshot: video API is: %i\n", vid_api); + if ((vid_api < 0) || (vid_api > 1)) return; + + memset(fn, 0, sizeof(fn)); + memset(path, 0, sizeof(path)); + + (void)time(&now); + info = localtime(&now); + + plat_append_filename(path, cfg_path, SCREENSHOT_PATH, sizeof(path)-2); + + if (! plat_dir_check(path)) + plat_dir_create(path); + +#ifdef WIN32 + wcscat(path, L"\\"); +#else + wcscat(path, L"/"); +#endif + + switch(vid_api) { + case 0: /* ddraw */ + wcsftime(path, 128, L"%Y%m%d_%H%M%S.bmp", info); + plat_append_filename(path, cfg_path, fn, 1024); + if (video_fullscreen) + ddraw_fs_take_screenshot(path); + else + ddraw_take_screenshot(path); + pclog("Screenshot: fn='%ls'\n", path); + break; + + case 1: /* d3d9 */ + wcsftime(fn, 128, L"%Y%m%d_%H%M%S.png", info); + plat_append_filename(path, cfg_path, fn, 1024); + if (video_fullscreen) + d3d_fs_take_screenshot(path); + else + d3d_take_screenshot(path); + pclog("Screenshot: fn='%ls'\n", path); + break; + +#ifdef USE_VNC + case 2: /* vnc */ + wcsftime(fn, 128, L"%Y%m%d_%H%M%S.png", info); + plat_append_filename(path, cfg_path, fn, 1024); + vnc_take_screenshot(path); + pclog("Screenshot: fn='%ls'\n", path); + break; +#endif + } +} + + +void /* plat_ */ +startblit(void) +{ + WaitForSingleObject(ghMutex, INFINITE); +} + + +void /* plat_ */ +endblit(void) +{ + ReleaseMutex(ghMutex); +} + + +/* Tell the UI and/or renderers about a new screen resolution. */ +void +plat_resize(int x, int y) +{ + int sb_borders[3]; + RECT r; + +#if 0 +pclog("PLAT: VID[%d,%d] resizing to %dx%d\n", video_fullscreen, vid_api, x, y); +#endif + /* First, see if we should resize the UI window. */ + if (!vid_resize) { + SendMessage(hwndSBAR, SB_GETBORDERS, 0, (LPARAM) sb_borders); + GetWindowRect(hwndMain, &r); + MoveWindow(hwndRender, 0, 0, x, y, TRUE); + GetWindowRect(hwndRender, &r); + MoveWindow(hwndSBAR, + 0, r.bottom + GetSystemMetrics(SM_CYEDGE), + x, 17, TRUE); + GetWindowRect(hwndMain, &r); + + MoveWindow(hwndMain, r.left, r.top, + x + (GetSystemMetrics(vid_resize ? SM_CXSIZEFRAME : SM_CXFIXEDFRAME) * 2), + y + (GetSystemMetrics(SM_CYEDGE) * 2) + (GetSystemMetrics(vid_resize ? SM_CYSIZEFRAME : SM_CYFIXEDFRAME) * 2) + GetSystemMetrics(SM_CYMENUSIZE) + GetSystemMetrics(SM_CYCAPTION) + 17 + sb_borders[1] + 1, + TRUE); + + if (mousecapture) { + GetWindowRect(hwndRender, &r); + ClipCursor(&r); + } + } + + /* Now, tell the renderer about the new screen size we want. */ + if (vid_apis[video_fullscreen][vid_api].resize) { + startblit(); + vid_apis[video_fullscreen][vid_api].resize(x, y); + endblit(); + } +}