diff --git a/src/config.c b/src/config.c index dc9d979..9a564d4 100644 --- a/src/config.c +++ b/src/config.c @@ -12,7 +12,7 @@ * it on Windows XP, and possibly also Vista. Use the * -DANSI_CFG for use on these systems. * - * Version: @(#)config.c 1.0.9 2018/03/31 + * Version: @(#)config.c 1.0.10 2018/04/05 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -53,7 +53,8 @@ #include "machine/machine.h" #include "nvr.h" #include "device.h" -#include "lpt.h" +#include "serial.h" +#include "parallel.h" #include "mouse.h" #include "game/gameport.h" #include "floppy/fdd.h" @@ -700,30 +701,25 @@ load_network(void) static void load_ports(void) { + char temp[128]; char *cat = "Ports (COM & LPT)"; char *p; + int i; - serial_enabled[0] = !!config_get_int(cat, "serial1_enabled", 0); - serial_enabled[1] = !!config_get_int(cat, "serial2_enabled", 0); - lpt_enabled = !!config_get_int(cat, "lpt_enabled", 0); + for (i = 0; i < SERIAL_MAX; i++) { + sprintf(temp, "serial%i_enabled", i); + serial_enabled[i] = !!config_get_int(cat, temp, 0); + } + for (i = 0; i < PARALLEL_MAX; i++) { + sprintf(temp, "parallel%i_enabled", i); + parallel_enabled[i] = !!config_get_int(cat, temp, 0); - p = (char *)config_get_string(cat, "lpt1_device", NULL); - if (p != NULL) - strcpy(lpt_device_names[0], p); - else - strcpy(lpt_device_names[0], "none"); - - p = (char *)config_get_string(cat, "lpt2_device", NULL); - if (p != NULL) - strcpy(lpt_device_names[1], p); - else - strcpy(lpt_device_names[1], "none"); - - p = (char *)config_get_string(cat, "lpt3_device", NULL); - if (p != NULL) - strcpy(lpt_device_names[2], p); - else - strcpy(lpt_device_names[2], "none"); + sprintf(temp, "parallel%i_device", i); + p = (char *)config_get_string(cat, temp, NULL); + if (p == NULL) + p = "none"; + strcpy(parallel_device[i], p); + } } @@ -749,24 +745,14 @@ load_other_peripherals(void) else scsi_card_current = 0; - if (hdc_name) { - free(hdc_name); - hdc_name = NULL; - } p = config_get_string(cat, "hdc", NULL); if (p == NULL) { - if (machines[machine].flags & MACHINE_HDC) { - hdc_name = (char *) malloc((strlen("internal") + 1) * sizeof(char)); - strcpy(hdc_name, "internal"); - } else { - hdc_name = (char *) malloc((strlen("none") + 1) * sizeof(char)); - strcpy(hdc_name, "none"); - } - } else { - hdc_name = (char *) malloc((strlen(p) + 1) * sizeof(char)); - strcpy(hdc_name, p); + if (machines[machine].flags & MACHINE_HDC) + p = "internal"; + else + p = "none"; } - config_set_string(cat, "hdc", hdc_name); + hdc_type = hdc_get_from_internal_name(p); memset(temp, '\0', sizeof(temp)); for (c=2; c<4; c++) { @@ -1345,8 +1331,9 @@ load_other_removable_devices(void) void config_load(void) { - pclog("Loading config file '%ls'..\n", cfg_path); + int i; + pclog("CONFIG: loading file '%ls'..\n", cfg_path); if (! config_read(cfg_path)) { cpu = 0; #ifdef USE_LANGUAGE @@ -1357,20 +1344,18 @@ config_load(void) vid_api = plat_vidapi("default");; enable_sync = 1; joystick_type = 0; - 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; - lpt_enabled = 0; + hdc_type = 0; + for (i = 0; i < SERIAL_MAX; i++) + serial_enabled[i] = 0; + for (i = 0; i < PARALLEL_MAX; i++) + parallel_enabled[i] = 0; fdd_set_type(0, 2); + fdd_set_check_bpb(0, 1); fdd_set_type(1, 2); + fdd_set_check_bpb(1, 1); mem_size = 640; - pclog("Config file not present or invalid!\n"); + pclog("CONFIG: file not present or invalid, using defaults!\n"); return; } @@ -1390,7 +1375,7 @@ config_load(void) /* Mark the configuration as changed. */ config_changed = 1; - pclog("Config loaded.\n\n"); + pclog("CONFIG: file loaded.\n\n"); } @@ -1701,37 +1686,31 @@ save_network(void) static void save_ports(void) { + char temp[128]; char *cat = "Ports (COM & LPT)"; + int i; - if (serial_enabled[0]) - config_set_int(cat, "serial1_enabled", serial_enabled[0]); - else - config_delete_var(cat, "serial1_enabled"); + for (i = 0; i < SERIAL_MAX; i++) { + if (serial_enabled[i]) { + sprintf(temp, "serial%i_enabled", i); + config_set_int(cat, temp, 1); + } else + config_delete_var(cat, temp); + } - if (serial_enabled[1]) - config_set_int(cat, "serial2_enabled", serial_enabled[1]); - else - config_delete_var(cat, "serial2_enabled"); + for (i = 0; i < PARALLEL_MAX; i++) { + if (parallel_enabled[i]) { + sprintf(temp, "parallel%i_enabled", i); + config_set_int(cat, temp, 1); + } else + config_delete_var(cat, temp); - if (lpt_enabled) - config_set_int(cat, "lpt_enabled", lpt_enabled); - else - config_delete_var(cat, "lpt_enabled"); - - if (strcmp(lpt_device_names[0], "none")) - config_set_string(cat, "lpt1_device", lpt_device_names[0]); - else - config_delete_var(cat, "lpt1_device"); - - if (strcmp(lpt_device_names[1], "none")) - config_set_string(cat, "lpt2_device", lpt_device_names[1]); - else - config_delete_var(cat, "lpt2_device"); - - if (strcmp(lpt_device_names[2], "none")) - config_set_string(cat, "lpt3_device", lpt_device_names[2]); - else - config_delete_var(cat, "lpt3_device"); + sprintf(temp, "parallel%i_device", i); + if (strcmp(parallel_device[i], "none")) + config_set_string(cat, temp, parallel_device[i]); + else + config_delete_var(cat, temp); + } delete_section_if_empty(cat); } @@ -1751,7 +1730,7 @@ save_other_peripherals(void) config_set_string(cat, "scsi_card", scsi_card_get_internal_name(scsi_card_current)); - config_set_string(cat, "hdc", hdc_name); + config_set_string(cat, "hdc", hdc_get_internal_name(hdc_type)); memset(temp, '\0', sizeof(temp)); for (c=2; c<4; c++) { diff --git a/src/disk/hdc.c b/src/disk/hdc.c index c95b585..2556a26 100644 --- a/src/disk/hdc.c +++ b/src/disk/hdc.c @@ -8,7 +8,7 @@ * * Common code to handle all sorts of disk controllers. * - * Version: @(#)hdc.c 1.0.4 2018/04/02 + * Version: @(#)hdc.c 1.0.5 2018/04/05 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -46,8 +46,6 @@ #include "hdc_ide.h" -char *hdc_name; /* configured HDC name */ -int hdc_current; #ifdef ENABLE_HDC_LOG int hdc_do_log = ENABLE_HDC_LOG; #endif @@ -99,7 +97,7 @@ static const struct { const device_t *device; int is_mfm; } controllers[] = { - { "None", "none", + { "Disabled", "none", &null_device, 0 }, { "Internal Controller", "internal", @@ -150,7 +148,7 @@ static const struct { { "[VLB] [IDE] PC/AT IDE Adapter (Dual-Channel)", "vlb_isa_2ch", &ide_vlb_2ch_device, 0 }, - { "", "", NULL, 0 } + { NULL, NULL, NULL, 0 } }; @@ -169,37 +167,18 @@ hdc_log(const char *fmt, ...) } -/* Initialize the 'hdc_current' value based on configured HDC name. */ -void -hdc_init(char *name) -{ - int c; - -#ifdef ENABLE_HDC_LOG - hdc_log("HDC: initializing..\n"); -#endif - - for (c=0; controllers[c].device; c++) { - if (! strcmp(name, (char *)controllers[c].internal_name)) { - hdc_current = c; - break; - } - } -} - - /* Reset the HDC, whichever one that is. */ void hdc_reset(void) { #ifdef ENABLE_HDC_LOG hdc_log("HDC: reset(current=%d, internal=%d)\n", - hdc_current, (machines[machine].flags & MACHINE_HDC)?1:0); + hdc_type, (machines[machine].flags & MACHINE_HDC)?1:0); #endif /* If we have a valid controller, add its device. */ - if (hdc_current > 1) - device_add(controllers[hdc_current].device); + if (hdc_type > 1) + device_add(controllers[hdc_type].device); /* Reconfire and reset the IDE layer. */ ide_ter_disable(); @@ -245,3 +224,18 @@ hdc_available(int hdc) { return(device_available(controllers[hdc].device)); } + + +int +hdc_get_from_internal_name(char *s) +{ + int c = 0; + + while (controllers[c].internal_name != NULL) { + if (! strcmp((char *)controllers[c].internal_name, s)) + return(c); + c++; + } + + return(-1); +} diff --git a/src/disk/hdc.h b/src/disk/hdc.h index 4a0b650..1309297 100644 --- a/src/disk/hdc.h +++ b/src/disk/hdc.h @@ -8,7 +8,7 @@ * * Definitions for the common disk controller handler. * - * Version: @(#)hdc.h 1.0.3 2018/04/02 + * Version: @(#)hdc.h 1.0.4 2018/04/05 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -46,10 +46,6 @@ * least 7 devices, with each device being * able to support 8 units, but hey... */ -extern char *hdc_name; -extern int hdc_current; -extern int hdc_do_log; - #ifdef EMU_DEVICE_H extern const device_t mfm_xt_xebec_device; /* mfm_xt_xebec */ extern const device_t mfm_xt_dtc5150x_device; /* mfm_xt_dtc */ @@ -82,6 +78,7 @@ extern char *hdc_get_internal_name(int hdc); extern const device_t *hdc_get_device(int hdc); extern int hdc_get_flags(int hdc); extern int hdc_available(int hdc); +extern int hdc_get_from_internal_name(char *s); #endif /*EMU_HDC_H*/ diff --git a/src/emu.h b/src/emu.h index d77f7bb..7d64760 100644 --- a/src/emu.h +++ b/src/emu.h @@ -8,7 +8,7 @@ * * Main include file for the application. * - * Version: @(#)emu.h 1.0.13 2018/04/02 + * Version: @(#)emu.h 1.0.14 2018/04/05 * * Author: Fred N. van Kempen, * @@ -49,8 +49,6 @@ /* Configuration values. */ -#define SERIAL_MAX 2 -#define PARALLEL_MAX 1 #define SCREEN_RES_X 640 #define SCREEN_RES_Y 480 @@ -107,13 +105,15 @@ extern int vid_cga_contrast, /* (C) video */ vid_card, /* (C) graphics/video card */ video_speed; /* (C) video */ extern int serial_enabled[], /* (C) enable serial ports */ - lpt_enabled, /* (C) enable LPT ports */ + parallel_enabled[], /* (C) enable LPT ports */ bugger_enabled; /* (C) enable ISAbugger */ +extern char parallel_device[3][16]; /* (C) set up LPT devices */ extern int rctrl_is_lalt; /* (C) set R-CTRL as L-ALT */ extern int update_icons; /* (C) enable icons updates */ #ifdef WALTJE extern int romdos_enabled; /* (C) enable ROM DOS */ #endif +extern int hdc_type; /* (C) HDC type */ extern int sound_is_float, /* (C) sound uses FP values */ GAMEBLASTER, /* (C) sound option */ GUS, /* (C) sound option */ diff --git a/src/game/gameport.c b/src/game/gameport.c index df93e79..7b7ded0 100644 --- a/src/game/gameport.c +++ b/src/game/gameport.c @@ -8,7 +8,7 @@ * * Implementation of a generic Game Port. * - * Version: @(#)gameport.c 1.0.6 2018/03/28 + * Version: @(#)gameport.c 1.0.7 2018/04/05 * * Authors: Miran Grca, * Sarah Walker, @@ -69,7 +69,7 @@ typedef struct _gameport_ { static const joystick_if_t joystick_none = { - "No joystick", + "Disabled", NULL, NULL, NULL, diff --git a/src/lang/language.h b/src/lang/language.h index 0716614..b6f4bb7 100644 --- a/src/lang/language.h +++ b/src/lang/language.h @@ -10,7 +10,7 @@ * * NOTE: FIXME: Strings 2176 and 2193 are same. * - * Version: @(#)language.h 1.0.5 2018/03/28 + * Version: @(#)language.h 1.0.6 2018/04/05 * * Author: Fred N. van Kempen, * @@ -147,14 +147,7 @@ #define IDS_2141 2141 // "Invalid PCap device" #define IDS_2142 2142 // "&Notify disk change" #define IDS_2143 2143 // "Type" -#define IDS_2144 2144 // "Disabled" -#define IDS_2145 2145 // "Standard 2-button joystick(s)" -#define IDS_2146 2146 // "Standard 4-button joystick" -#define IDS_2147 2147 // "Standard 6-button joystick" -#define IDS_2148 2148 // "Standard 8-button joystick" -#define IDS_2149 2149 // "CH Flightstick Pro" -#define IDS_2150 2150 // "Microsoft SideWinder Pad" -#define IDS_2151 2151 // "Thrustmaster Flight Cont.." +/* IDS_2144-51 available */ #define IDS_2152 2152 // "None" #define IDS_2153 2153 // "Unable to load Accelerators" #define IDS_2154 2154 // "Unable to register Raw Input" diff --git a/src/lpt.c b/src/lpt.c deleted file mode 100644 index 69972ae..0000000 --- a/src/lpt.c +++ /dev/null @@ -1,300 +0,0 @@ -/* - * VARCem Virtual ARchaeological Computer EMulator. - * An emulator of (mostly) x86-based PC systems and devices, - * using the ISA,EISA,VLB,MCA and PCI system buses, roughly - * spanning the era between 1981 and 1995. - * - * This file is part of the VARCem Project. - * - * Implementation of the LPT style parallel ports. - * - * Version: @(#)lpt.c 1.0.3 2018/03/28 - * - * Authors: Fred N. van Kempen, - * Miran Grca, - * Sarah Walker, - * - * Copyright 2017,2018 Fred N. van Kempen. - * Copyright 2016-2018 Miran Grca. - * Copyright 2008-2018 Sarah Walker. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the: - * - * Free Software Foundation, Inc. - * 59 Temple Place - Suite 330 - * Boston, MA 02111-1307 - * USA. - */ -#include -#include -#include -#include -#include "emu.h" -#include "io.h" -#include "lpt.h" -#include "sound/snd_lpt_dac.h" -#include "sound/snd_lpt_dss.h" - - -char lpt_device_names[3][16]; - - -static const struct { - const char *name; - const char *internal_name; - const lpt_device_t *device; -} lpt_devices[] = { - { "None", "none", NULL }, - { "Disney Sound Source", "dss", &dss_device }, - { "LPT DAC / Covox Speech Thing", "lpt_dac", &lpt_dac_device }, - { "Stereo LPT DAC", "lpt_dac_stereo", &lpt_dac_stereo_device }, - { "", "", NULL } -}; - - -static const lpt_device_t *lpt_device_ts[3]; -static void *lpt_device_ps[3]; -static uint8_t lpt_dats[3], lpt_ctrls[3]; -static uint16_t lpt_addr[3] = { - 0x0378, 0x0278, 0x03bc -}; - - -static void -lpt_write(int i, uint16_t port, uint8_t val, void *priv) -{ - switch (port & 3) { - case 0: - if (lpt_device_ts[i]) - lpt_device_ts[i]->write_data(val, lpt_device_ps[i]); - lpt_dats[i] = val; - break; - - case 2: - if (lpt_device_ts[i]) - lpt_device_ts[i]->write_ctrl(val, lpt_device_ps[i]); - lpt_ctrls[i] = val; - break; - } -} - - -static uint8_t -lpt_read(int i, uint16_t port, void *priv) -{ - uint8_t ret = 0xff; - - switch (port & 3) { - case 0: - ret = lpt_dats[i]; - break; - - case 1: - if (lpt_device_ts[i]) - ret = lpt_device_ts[i]->read_status(lpt_device_ps[i]); - else ret = 0x00; - break; - - case 2: - ret = lpt_ctrls[i]; - break; - } - - return(ret); -} - - -static void -lpt1_write(uint16_t port, uint8_t val, void *priv) -{ - lpt_write(0, port, val, priv); -} - - -static uint8_t -lpt1_read(uint16_t port, void *priv) -{ - return(lpt_read(0, port, priv)); -} - - -static void -lpt2_write(uint16_t port, uint8_t val, void *priv) -{ - lpt_write(1, port, val, priv); -} - - -static uint8_t -lpt2_read(uint16_t port, void *priv) -{ - return(lpt_read(1, port, priv)); -} - - -static void -lpt3_write(uint16_t port, uint8_t val, void *priv) -{ - lpt_write(2, port, val, priv); -} - - -static uint8_t -lpt3_read(uint16_t port, void *priv) -{ - return(lpt_read(2, port, priv)); -} - - -void -lpt_init(void) -{ - if (lpt_enabled) { - lpt_addr[0] = 0x378; - io_sethandler(lpt_addr[0], 3, - lpt1_read,NULL,NULL, lpt1_write,NULL,NULL, NULL); - - lpt_addr[1] = 0x278; - io_sethandler(lpt_addr[1], 3, - lpt2_read,NULL,NULL, lpt2_write,NULL,NULL, NULL); - } -} - - -void -lpt_devices_close(void) -{ - int i; - - for (i = 0; i < 3; i++) { - if (lpt_device_ts[i]) - lpt_device_ts[i]->close(lpt_device_ps[i]); - lpt_device_ts[i] = NULL; - } -} - - -void -lpt1_init(uint16_t port) -{ - if (lpt_enabled) { - lpt_addr[0] = port; - io_sethandler(lpt_addr[0], 3, - lpt1_read,NULL,NULL, lpt1_write,NULL,NULL, NULL); - } -} - - -void -lpt1_remove(void) -{ - if (lpt_enabled) { - io_removehandler(lpt_addr[0], 3, - lpt1_read,NULL,NULL, lpt1_write,NULL,NULL, NULL); - } -} - - -void -lpt2_init(uint16_t port) -{ - if (lpt_enabled) { - lpt_addr[1] = port; - io_sethandler(lpt_addr[1], 3, - lpt2_read,NULL,NULL, lpt2_write,NULL,NULL, NULL); - } -} - - -void -lpt2_remove(void) -{ - if (lpt_enabled) { - io_removehandler(lpt_addr[1], 3, - lpt2_read,NULL,NULL, lpt2_write,NULL,NULL, NULL); - } -} - - -void -lpt2_remove_ams(void) -{ - if (lpt_enabled) { - io_removehandler(0x0379, 2, - lpt2_read,NULL,NULL, lpt2_write,NULL,NULL, NULL); - } -} - - -void -lpt3_init(uint16_t port) -{ - if (lpt_enabled) { - lpt_addr[2] = port; - io_sethandler(lpt_addr[2], 3, - lpt3_read,NULL,NULL, lpt3_write,NULL,NULL, NULL); - } -} - - -void -lpt3_remove(void) -{ - if (lpt_enabled) { - io_removehandler(lpt_addr[2], 3, - lpt3_read,NULL,NULL, lpt3_write,NULL,NULL, NULL); - } -} - - -void -lpt_devices_init(void) -{ - int c, i; - - for (i = 0; i < 3; i++) { - c = 0; - - while ((char *)strcmp(lpt_devices[c].internal_name, lpt_device_names[i]) && strlen((char *)lpt_devices[c].internal_name) != 0) - c++; - - if (strlen((char *)lpt_devices[c].internal_name) == 0) - lpt_device_ts[i] = NULL; - else { - lpt_device_ts[i] = lpt_devices[c].device; - if (lpt_device_ts[i]) - lpt_device_ps[i] = lpt_device_ts[i]->init(lpt_devices[c].device); - } - } -} - - -const char * -lpt_device_get_name(int id) -{ - if (strlen((char *)lpt_devices[id].name) == 0) - return(NULL); - - return((char *)lpt_devices[id].name); -} - - -char * -lpt_device_get_internal_name(int id) -{ - if (strlen((char *)lpt_devices[id].internal_name) == 0) - return(NULL); - - return((char *)lpt_devices[id].internal_name); -} diff --git a/src/machine/m_amstrad.c b/src/machine/m_amstrad.c index 5e7cfd7..42b4c21 100644 --- a/src/machine/m_amstrad.c +++ b/src/machine/m_amstrad.c @@ -32,7 +32,7 @@ * BIOSES: I need to re-do the bios.txt format so we can load non-BIOS * ROM files for a given machine, such as font roms here.. * - * Version: @(#)m_amstrad.c 1.0.8 2018/03/27 + * Version: @(#)m_amstrad.c 1.0.9 2018/04/05 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -80,7 +80,7 @@ #include "../keyboard.h" #include "../mouse.h" #include "../game/gameport.h" -#include "../lpt.h" +#include "../parallel.h" #include "../floppy/fdd.h" #include "../floppy/fdc.h" #include "../sound/sound.h" @@ -1230,13 +1230,7 @@ machine_amstrad_init(const machine_t *model, void *arg) device_add(&amstrad_nvr_device); - lpt2_remove_ams(); - - io_sethandler(0x0379, 2, - ams_read, NULL, NULL, NULL, NULL, NULL, ams); - - io_sethandler(0xdead, 1, - ams_read, NULL, NULL, ams_write, NULL, NULL, ams); + parallel_remove_amstrad(); io_sethandler(0x0078, 1, ms_read, NULL, NULL, ms_write, NULL, NULL, ams); @@ -1244,6 +1238,12 @@ machine_amstrad_init(const machine_t *model, void *arg) io_sethandler(0x007a, 1, ms_read, NULL, NULL, ms_write, NULL, NULL, ams); + io_sethandler(0x0379, 2, + ams_read, NULL, NULL, NULL, NULL, NULL, ams); + + io_sethandler(0xdead, 1, + ams_read, NULL, NULL, ams_write, NULL, NULL, ams); + switch(model->id) { case ROM_PC1512: device_add(&fdc_xt_device); diff --git a/src/machine/m_at.c b/src/machine/m_at.c index b418e3c..7e751d3 100644 --- a/src/machine/m_at.c +++ b/src/machine/m_at.c @@ -8,7 +8,7 @@ * * Standard PC/AT implementation. * - * Version: @(#)m_at.c 1.0.4 2018/03/21 + * Version: @(#)m_at.c 1.0.5 2018/04/05 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -47,7 +47,6 @@ #include "../mem.h" #include "../device.h" #include "../nvr.h" -#include "../lpt.h" #include "../keyboard.h" #include "../game/gameport.h" #include "../floppy/fdd.h" @@ -65,9 +64,6 @@ machine_at_common_init(const machine_t *model, void *arg) pic2_init(); dma16_init(); - if (lpt_enabled) - lpt2_remove(); - device_add(&at_nvr_device); if (joystick_type != JOYSTICK_TYPE_NONE) diff --git a/src/machine/m_at_commodore.c b/src/machine/m_at_commodore.c index baf75e7..87958be 100644 --- a/src/machine/m_at_commodore.c +++ b/src/machine/m_at_commodore.c @@ -8,7 +8,7 @@ * * Implementation of the Commodore PC3 system. * - * Version: @(#)m_at_commodore.c 1.0.3 2018/03/21 + * Version: @(#)m_at_commodore.c 1.0.4 2018/04/05 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -43,8 +43,8 @@ #include "../emu.h" #include "../device.h" #include "../io.h" -#include "../lpt.h" #include "../serial.h" +#include "../parallel.h" #include "../floppy/fdd.h" #include "../floppy/fdc.h" #include "machine.h" @@ -53,30 +53,30 @@ static void pc3_write(uint16_t port, uint8_t val, void *priv) { - lpt1_remove(); - lpt2_remove(); + parallel_remove(1); + parallel_remove(2); switch (val & 3) { case 1: - lpt1_init(0x3bc); + parallel_setup(1, 0x03bc); break; case 2: - lpt1_init(0x378); + parallel_setup(1, 0x0378); break; case 3: - lpt1_init(0x278); + parallel_setup(1, 0x0278); break; } switch (val & 0xc) { case 0x4: - serial_setup(1, 0x2f8, 3); + serial_setup(1, 0x02f8, 3); break; case 0x8: - serial_setup(1, 0x3f8, 4); + serial_setup(1, 0x03f8, 4); break; } } diff --git a/src/machine/m_at_compaq.c b/src/machine/m_at_compaq.c index 53006ef..71f98e8 100644 --- a/src/machine/m_at_compaq.c +++ b/src/machine/m_at_compaq.c @@ -8,7 +8,7 @@ * * Emulation of various Compaq PC's. * - * Version: @(#)m_at_compaq.c 1.0.4 2018/03/21 + * Version: @(#)m_at_compaq.c 1.0.5 2018/04/05 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -142,13 +142,13 @@ machine_at_compaq_init(const machine_t *model, void *arg) case ROM_PORTABLEIII386: machine_olim24_video_init(); - if (hdc_current == 1) + if (hdc_type == 1) device_add(&ide_isa_device); break; #endif #if defined(DEV_BRANCH) && defined(USE_DESKPRO386) case ROM_DESKPRO_386: - if (hdc_current == 1) + if (hdc_type == 1) device_add(&ide_isa_device); break; #endif diff --git a/src/machine/m_at_sis_85c471.c b/src/machine/m_at_sis_85c471.c index be5480d..0571882 100644 --- a/src/machine/m_at_sis_85c471.c +++ b/src/machine/m_at_sis_85c471.c @@ -12,7 +12,7 @@ * * Used by DTK PKM-0038S E-2 * - * Version: @(#)m_at_sis85c471.c 1.0.4 2018/03/21 + * Version: @(#)m_at_sis85c471.c 1.0.5 2018/04/05 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -46,8 +46,8 @@ #include "../io.h" #include "../memregs.h" #include "../device.h" -#include "../lpt.h" #include "../serial.h" +#include "../parallel.h" #include "../disk/hdc.h" #include "../disk/hdc_ide.h" #include "../floppy/fdd.h" @@ -100,9 +100,9 @@ sis_write(uint16_t port, uint8_t val, void *priv) if (x & 0x10) { if (val & 0x10) - lpt1_init(0x378); + parallel_setup(1, 0x378); else - lpt1_remove(); + parallel_remove(1); } break; @@ -136,7 +136,7 @@ sis_init(void) { int i = 0; - lpt2_remove(); + parallel_remove(2); sis_curreg = 0; for (i = 0; i < 0x27; i++) diff --git a/src/machine/m_europc.c b/src/machine/m_europc.c index 67b5f08..669fe32 100644 --- a/src/machine/m_europc.c +++ b/src/machine/m_europc.c @@ -40,7 +40,7 @@ * 100 joystick port enabled * f000:e1e2-dc0c CPU speed is 4.77 mhz * f000:e1e5-f9c0 keyboard processor error - * f000:e1eb-c617 external lpt1 at 0x3bc + * f000:e1eb-c617 external LPT1 at 0x3bc * f000:e1ee-e8ee external coms at * * Routines: @@ -66,7 +66,7 @@ * bit 1: b8000 memory available * 0000:046a: 00 jim 250 01 jim 350 * - * Version: @(#)m_europc.c 1.0.5 2018/03/21 + * Version: @(#)m_europc.c 1.0.6 2018/04/05 * * Author: Fred N. van Kempen, * @@ -120,6 +120,7 @@ #include "../rom.h" #include "../nvr.h" #include "../device.h" +#include "../parallel.h" #include "../keyboard.h" #include "../mouse.h" #include "../game/gameport.h" @@ -655,7 +656,7 @@ europc_boot(const device_t *info) * * We only do this if we have not configured another one. */ - if (hdc_current == 1) + if (hdc_type == 1) (void)device_add(&europc_hdc_device); return(sys); diff --git a/src/machine/m_ps1.c b/src/machine/m_ps1.c index e454417..a7cc086 100644 --- a/src/machine/m_ps1.c +++ b/src/machine/m_ps1.c @@ -28,7 +28,7 @@ * boot. Sometimes, they do, and then it shows an "Incorrect * DOS" error message?? --FvK * - * Version: @(#)m_ps1.c 1.0.8 2018/03/31 + * Version: @(#)m_ps1.c 1.0.9 2018/04/05 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -74,7 +74,7 @@ #include "../device.h" #include "../nvr.h" #include "../game/gameport.h" -#include "../lpt.h" +#include "../parallel.h" #include "../serial.h" #include "../keyboard.h" #include "../disk/hdc.h" @@ -350,7 +350,7 @@ ps1_write(uint16_t port, uint8_t val, void *priv) break; case 0x0102: - lpt1_remove(); + parallel_remove(1); if (val & 0x04) serial_setup(1, SERIAL1_ADDR, SERIAL1_IRQ); else @@ -358,13 +358,13 @@ ps1_write(uint16_t port, uint8_t val, void *priv) if (val & 0x10) { switch ((val >> 5) & 3) { case 0: - lpt1_init(0x03bc); + parallel_setup(1, 0x03bc); break; case 1: - lpt1_init(0x0378); + parallel_setup(1, 0x0378); break; case 2: - lpt1_init(0x0278); + parallel_setup(1, 0x0278); break; } } @@ -512,9 +512,9 @@ ps1_setup(int model) 0xf80000, 0x80000, 0x7ffff, 0, MEM_MAPPING_EXTERNAL); #endif - lpt1_remove(); - lpt2_remove(); - lpt1_init(0x03bc); + parallel_remove(1); + parallel_remove(2); + parallel_setup(1, 0x03bc); serial_remove(1); serial_remove(2); @@ -540,7 +540,7 @@ ps1_setup(int model) 0xfc0000, 0x40000, 0x3ffff, 0, MEM_MAPPING_EXTERNAL); #endif - lpt1_init(0x03bc); + parallel_setup(1, 0x03bc); /* Initialize the video controller. */ if (vid_card == VID_INTERNAL) @@ -548,7 +548,7 @@ ps1_setup(int model) } if (model == 2133) { - lpt1_init(0x03bc); + parallel_setup(1, 0x03bc); } } diff --git a/src/machine/m_ps2_isa.c b/src/machine/m_ps2_isa.c index 8a36ed6..1e6a1dd 100644 --- a/src/machine/m_ps2_isa.c +++ b/src/machine/m_ps2_isa.c @@ -8,7 +8,7 @@ * * Implementation of ISA-based PS/2 machines. * - * Version: @(#)m_ps2_isa.c 1.0.4 2018/03/21 + * Version: @(#)m_ps2_isa.c 1.0.5 2018/04/05 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -51,7 +51,7 @@ #include "../device.h" #include "../nvr.h" #include "../keyboard.h" -#include "../lpt.h" +#include "../parallel.h" #include "../serial.h" #include "../floppy/fdd.h" #include "../floppy/fdc.h" @@ -114,24 +114,23 @@ static void ps2_write(uint16_t port, uint8_t val, void *p) ps2_94 = val; break; case 0x102: - lpt1_remove(); + parallel_remove(1); if (val & 0x04) serial_setup(1, SERIAL1_ADDR, SERIAL1_IRQ); else serial_remove(1); if (val & 0x10) { - switch ((val >> 5) & 3) - { + switch ((val >> 5) & 3) { case 0: - lpt1_init(0x3bc); - break; + parallel_setup(1, 0x3bc); + break; case 1: - lpt1_init(0x378); - break; + parallel_setup(1, 0x378); + break; case 2: - lpt1_init(0x278); - break; + parallel_setup(1, 0x278); + break; } } ps2_102 = val; @@ -179,7 +178,7 @@ static void ps2board_init(void) ps2_190 = 0; - lpt1_init(0x3bc); + parallel_setup(1, 0x3bc); memset(&ps2_hd, 0, sizeof(ps2_hd)); } diff --git a/src/machine/m_ps2_mca.c b/src/machine/m_ps2_mca.c index fbc9659..8e17c65 100644 --- a/src/machine/m_ps2_mca.c +++ b/src/machine/m_ps2_mca.c @@ -8,7 +8,7 @@ * * Implementation of MCA-based PS/2 machines. * - * Version: @(#)m_ps2_mca.c 1.0.7 2018/03/22 + * Version: @(#)m_ps2_mca.c 1.0.8 2018/04/05 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -57,7 +57,7 @@ #include "../nvr.h" #include "../nvr_ps2.h" #include "../keyboard.h" -#include "../lpt.h" +#include "../parallel.h" #include "../mouse.h" #include "../serial.h" #include "../video/vid_vga.h" @@ -357,7 +357,7 @@ static void model_50_write(uint16_t port, uint8_t val) case 0x101: break; case 0x102: - lpt1_remove(); + parallel_remove(1); serial_remove(1); if (val & 0x04) { @@ -373,14 +373,14 @@ static void model_50_write(uint16_t port, uint8_t val) switch ((val >> 5) & 3) { case 0: - lpt1_init(0x3bc); - break; + parallel_setup(1, 0x3bc); + break; case 1: - lpt1_init(0x378); - break; + parallel_setup(1, 0x378); + break; case 2: - lpt1_init(0x278); - break; + parallel_setup(1, 0x278); + break; } } ps2.option[0] = val; @@ -413,7 +413,7 @@ static void model_55sx_write(uint16_t port, uint8_t val) case 0x101: break; case 0x102: - lpt1_remove(); + parallel_remove(1); serial_remove(1); if (val & 0x04) { @@ -429,14 +429,14 @@ static void model_55sx_write(uint16_t port, uint8_t val) switch ((val >> 5) & 3) { case 0: - lpt1_init(0x3bc); - break; + parallel_setup(1, 0x3bc); + break; case 1: - lpt1_init(0x378); - break; + parallel_setup(1, 0x378); + break; case 2: - lpt1_init(0x278); - break; + parallel_setup(1, 0x278); + break; } } ps2.option[0] = val; @@ -489,7 +489,7 @@ static void model_70_type3_write(uint16_t port, uint8_t val) case 0x101: break; case 0x102: - lpt1_remove(); + parallel_remove(1); serial_remove(1); if (val & 0x04) { @@ -505,14 +505,14 @@ static void model_70_type3_write(uint16_t port, uint8_t val) switch ((val >> 5) & 3) { case 0: - lpt1_init(0x3bc); - break; + parallel_setup(1, 0x3bc); + break; case 1: - lpt1_init(0x378); - break; + parallel_setup(1, 0x378); + break; case 2: - lpt1_init(0x278); - break; + parallel_setup(1, 0x278); + break; } } ps2.option[0] = val; @@ -539,7 +539,7 @@ static void model_80_write(uint16_t port, uint8_t val) case 0x101: break; case 0x102: - lpt1_remove(); + parallel_remove(1); serial_remove(1); if (val & 0x04) { @@ -555,14 +555,14 @@ static void model_80_write(uint16_t port, uint8_t val) switch ((val >> 5) & 3) { case 0: - lpt1_init(0x3bc); - break; + parallel_setup(1, 0x3bc); + break; case 1: - lpt1_init(0x378); - break; + parallel_setup(1, 0x378); + break; case 2: - lpt1_init(0x278); - break; + parallel_setup(1, 0x278); + break; } } ps2.option[0] = val; @@ -759,7 +759,7 @@ static void ps2_mca_board_common_init() ps2.setup = 0xff; - lpt1_init(0x3bc); + parallel_setup(1, 0x3bc); } static uint8_t ps2_mem_expansion_read(int port, void *p) diff --git a/src/machine/m_xt_compaq.c b/src/machine/m_xt_compaq.c index dcc4312..7aa1aaf 100644 --- a/src/machine/m_xt_compaq.c +++ b/src/machine/m_xt_compaq.c @@ -8,7 +8,7 @@ * * Emulation of various Compaq XT-class PC's. * - * Version: @(#)m_xt_compaq.c 1.0.5 2018/03/21 + * Version: @(#)m_xt_compaq.c 1.0.6 2018/04/05 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -52,7 +52,7 @@ #include "../floppy/fdc.h" #include "../game/gameport.h" #include "../keyboard.h" -#include "../lpt.h" +#include "../parallel.h" #include "machine.h" @@ -74,8 +74,8 @@ machine_xt_compaq_init(const machine_t *model, void *arg) switch(model->id) { case ROM_PORTABLE: - lpt1_remove(); - lpt1_init(0x03bc); + parallel_remove(1); + parallel_setup(1, 0x03bc); break; } } diff --git a/src/machine/m_xt_t1000.c b/src/machine/m_xt_t1000.c index 69317da..50b8feb 100644 --- a/src/machine/m_xt_t1000.c +++ b/src/machine/m_xt_t1000.c @@ -50,7 +50,7 @@ * * FIXME: The ROM drive should be re-done using the "option file". * - * Version: @(#)m_xt_t1000.c 1.0.8 2018/04/03 + * Version: @(#)m_xt_t1000.c 1.0.9 2018/04/05 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -94,7 +94,7 @@ #include "../nvr.h" #include "../device.h" #include "../keyboard.h" -#include "../lpt.h" +#include "../parallel.h" #include "../floppy/fdd.h" #include "../floppy/fdc.h" #include "../game/gameport.h" diff --git a/src/machine/m_xt_xi8088.c b/src/machine/m_xt_xi8088.c index 392a5b4..f11f0d5 100644 --- a/src/machine/m_xt_xi8088.c +++ b/src/machine/m_xt_xi8088.c @@ -8,7 +8,7 @@ * * Implementation of the Xi8088 open-source machine. * - * Version: @(#)m_xt_xi8088.c 1.0.5 2018/04/03 + * Version: @(#)m_xt_xi8088.c 1.0.6 2018/04/05 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -50,7 +50,7 @@ #include "../device.h" #include "../nvr.h" #include "../keyboard.h" -#include "../lpt.h" +#include "../parallel.h" #include "../game/gameport.h" #include "../floppy/fdd.h" #include "../floppy/fdc.h" diff --git a/src/machine/machine.c b/src/machine/machine.c index d86e2dd..6f7b9e5 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.10 2018/03/21 + * Version: @(#)machine.c 1.0.11 2018/04/05 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -47,8 +47,8 @@ #include "../pit.h" #include "../mem.h" #include "../rom.h" -#include "../lpt.h" #include "../serial.h" +#include "../parallel.h" #include "../disk/hdc.h" #include "../disk/hdc_ide.h" #include "../plat.h" @@ -153,8 +153,17 @@ machine_common_init(const machine_t *model, UNUSED(void *arg)) pic_init(); pit_init(); - if (lpt_enabled) - lpt_init(); + /* Disable all LPT ports. */ + parallel_init(); + + if (parallel_enabled[0]) + parallel_setup(1, PARALLEL1_ADDR); + + if (parallel_enabled[1]) + parallel_setup(2, PARALLEL2_ADDR); + + if (parallel_enabled[2]) + parallel_setup(3, PARALLEL3_ADDR); if (serial_enabled[0]) serial_setup(1, SERIAL1_ADDR, SERIAL1_IRQ); diff --git a/src/mouse.c b/src/mouse.c index 4ce6fa4..5e0a78e 100644 --- a/src/mouse.c +++ b/src/mouse.c @@ -11,7 +11,7 @@ * TODO: Add the Genius bus- and serial mouse. * Remove the '3-button' flag from mouse types. * - * Version: @(#)mouse.c 1.0.4 2018/03/29 + * Version: @(#)mouse.c 1.0.5 2018/04/05 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -72,7 +72,7 @@ int mouse_x, static const device_t mouse_none_device = { - "None", + "Disabled", 0, MOUSE_TYPE_NONE, NULL, NULL, NULL, NULL, NULL, NULL, NULL, diff --git a/src/network/network.c b/src/network/network.c index 78ba03d..16295ff 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.3 2018/03/15 + * Version: @(#)network.c 1.0.4 2018/04/05 * * Author: Fred N. van Kempen, * @@ -65,18 +65,12 @@ static netcard_t net_cards[] = { - { "None", "none", NULL, - NULL }, - { "[ISA] Novell NE1000", "ne1k", &ne1000_device, - NULL }, - { "[ISA] Novell NE2000", "ne2k", &ne2000_device, - NULL }, - { "[ISA] Realtek RTL8019AS", "ne2kpnp", &rtl8019as_device, - NULL }, - { "[PCI] Realtek RTL8029AS", "ne2kpci", &rtl8029as_device, - NULL }, - { "", "", NULL, - NULL } + {"Disabled", "none", NULL, NULL}, + {"[ISA] Novell NE1000", "ne1k", &ne1000_device, NULL}, + {"[ISA] Novell NE2000", "ne2k", &ne2000_device, NULL}, + {"[ISA] Realtek RTL8019AS", "ne2kpnp", &rtl8019as_device, NULL}, + {"[PCI] Realtek RTL8029AS", "ne2kpci", &rtl8029as_device, NULL}, + {NULL, NULL, NULL, NULL} }; @@ -488,7 +482,7 @@ network_card_get_from_internal_name(char *s) { int c = 0; - while (strlen((char *)net_cards[c].internal_name)) { + while (net_cards[c].internal_name != NULL) { if (! strcmp((char *)net_cards[c].internal_name, s)) return(c); c++; diff --git a/src/parallel.c b/src/parallel.c new file mode 100644 index 0000000..9c7d69c --- /dev/null +++ b/src/parallel.c @@ -0,0 +1,274 @@ +/* + * VARCem Virtual ARchaeological Computer EMulator. + * An emulator of (mostly) x86-based PC systems and devices, + * using the ISA,EISA,VLB,MCA and PCI system buses, roughly + * spanning the era between 1981 and 1995. + * + * This file is part of the VARCem Project. + * + * Implementation of the "LPT" style parallel ports. + * + * NOTE: Have to re-do the "attach" and "detach" stuff for the + * "device" that use the ports. --FvK + * + * Version: @(#)parallel.c 1.0.4 2018/04/05 + * + * Authors: Fred N. van Kempen, + * Miran Grca, + * Sarah Walker, + * + * Copyright 2017,2018 Fred N. van Kempen. + * Copyright 2016-2018 Miran Grca. + * Copyright 2008-2018 Sarah Walker. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the: + * + * Free Software Foundation, Inc. + * 59 Temple Place - Suite 330 + * Boston, MA 02111-1307 + * USA. + */ +#include +#include +#include +#include +#include "emu.h" +#include "io.h" +#include "parallel.h" +#include "sound/snd_lpt_dac.h" +#include "sound/snd_lpt_dss.h" + + +static const struct { + const char *name; + const char *internal_name; + const lpt_device_t *device; +} parallel_devices[] = { + { "None", "none", NULL }, + { "Disney Sound Source", "dss", &dss_device }, + { "LPT DAC / Covox Speech Thing", "lpt_dac", &lpt_dac_device }, + { "Stereo LPT DAC", "lpt_dac_stereo", &lpt_dac_stereo_device }, + { "", "", NULL } +}; + +static const uint16_t addr_list[] = { /* valid port addresses */ + 0x0378, 0x0278, 0x03bc +}; + + +typedef struct { + /* Standard port stuff. */ + uint16_t base; /* port base address */ + + uint8_t dat, /* port data register */ + ctrl; /* port control register */ + + /* Device stuff. */ + char device_name[16]; /* name of attached device */ + const lpt_device_t *device_ts; + void *device_ps; +} parallel_t; + + + +static parallel_t ports[PARALLEL_MAX]; /* the ports */ + + +/* Write a value to a port (and/or its attached device.) */ +static void +parallel_write(uint16_t port, uint8_t val, void *priv) +{ + parallel_t *dev = (parallel_t *)priv; + + switch (port & 3) { + case 0: + if (dev->device_ts != NULL) + dev->device_ts->write_data(val, dev->device_ps); + dev->dat = val; + break; + + case 2: + if (dev->device_ts != NULL) + dev->device_ts->write_ctrl(val, dev->device_ps); + dev->ctrl = val; + break; + } +} + + +/* Read a value from a port (and/or its attached device.) */ +static uint8_t +parallel_read(uint16_t port, void *priv) +{ + parallel_t *dev = (parallel_t *)priv; + uint8_t ret = 0xff; + + switch (port & 3) { + case 0: + ret = dev->dat; + break; + + case 1: + if (dev->device_ts != NULL) + ret = dev->device_ts->read_status(dev->device_ps); + else ret = 0x00; + break; + + case 2: + ret = dev->ctrl; + break; + } + + return(ret); +} + + +/* Initialize (all) the parallel ports. */ +void +parallel_init(void) +{ + parallel_t *dev; + int i; + + pclog("LPT: initializing ports..."); + + for (i = 0; i < PARALLEL_MAX; i++) { + dev = &ports[i]; + + memset(dev, 0x00, sizeof(parallel_t)); + + dev->base = addr_list[i]; + + if (parallel_enabled[i]) { + io_sethandler(dev->base, 3, + parallel_read,NULL,NULL, + parallel_write,NULL,NULL, dev); + + pclog(" [%i=%04x]", i, dev->base); + } + } + + pclog("\n"); +} + + +/* Disable one of the parallel ports. */ +void +parallel_remove(int id) +{ + parallel_t *dev = &ports[id-1]; + + if (! parallel_enabled[id-1]) return; + + io_removehandler(dev->base, 3, + parallel_read,NULL,NULL, + parallel_write,NULL,NULL, dev); + + dev->base = addr_list[id-1]; +} + + +void +parallel_remove_amstrad(void) +{ + parallel_t *dev = &ports[1]; + + if (parallel_enabled[1]) { + io_removehandler(dev->base+1, 2, + parallel_read,NULL,NULL, + parallel_write,NULL,NULL, dev); + } +} + + +/* Set up (the address of) one of the parallel ports. */ +void +parallel_setup(int id, uint16_t port) +{ + parallel_t *dev = &ports[id-1]; + + if (! parallel_enabled[id-1]) return; + + dev->base = port; + io_sethandler(dev->base, 3, + parallel_read,NULL,NULL, + parallel_write,NULL,NULL, dev); +} + + +const char * +parallel_device_get_name(int id) +{ + if (strlen((char *)parallel_devices[id].name) == 0) + return(NULL); + + return((char *)parallel_devices[id].name); +} + + +char * +parallel_device_get_internal_name(int id) +{ + if (strlen((char *)parallel_devices[id].internal_name) == 0) + return(NULL); + + return((char *)parallel_devices[id].internal_name); +} + + +/* Attach the configured "LPT" devices. */ +void +parallel_devices_init(void) +{ + parallel_t *dev; + int c, i; + + for (i = 0; i < PARALLEL_MAX; i++) { + dev = &ports[i]; + + c = 0; + +#if 0 + /* FIXME: Gotta re-think this junk... --FvK */ + while (! strmpdev->device_name, (char *)strcmp(lpt_devices[c].internal_name, lpt_device_names[i]) && strlen((char *)lpt_devices[c].internal_name) != 0) + c++; + + if (strlen((char *)lpt_devices[c].internal_name) == 0) + lpt_device_ts[i] = NULL; + else { + lpt_device_ts[i] = lpt_devices[c].device; + if (lpt_device_ts[i]) + lpt_device_ps[i] = lpt_device_ts[i]->init(lpt_devices[c].device); + } +#endif + } +} + + +void +parallel_devices_close(void) +{ + parallel_t *dev; + int i; + + for (i = 0; i < PARALLEL_MAX; i++) { + dev = &ports[i]; + + if (dev->device_ts != NULL) { + dev->device_ts->close(dev->device_ps); + dev->device_ts = NULL; + dev->device_ps = NULL; + } + } +} diff --git a/src/lpt.h b/src/parallel.h similarity index 69% rename from src/lpt.h rename to src/parallel.h index e9ddacd..67a8819 100644 --- a/src/lpt.h +++ b/src/parallel.h @@ -6,9 +6,9 @@ * * This file is part of the VARCem Project. * - * Definitions for the LPT parallel port handlerss. + * Definitions for the "LPT" parallel port handlerss. * - * Version: @(#)lpt.h 1.0.2 2018/03/28 + * Version: @(#)parallel.h 1.0.3 2018/04/05 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -36,8 +36,15 @@ * Boston, MA 02111-1307 * USA. */ -#ifndef EMU_LPT_H -# define EMU_LPT_H +#ifndef EMU_PARALLEL_H +# define EMU_PARALLEL_H + + +#define PARALLEL_MAX 3 /* three ports supported */ + +#define PARALLEL1_ADDR 0x0378 +#define PARALLEL2_ADDR 0x0278 +#define PARALLEL3_ADDR 0x03BC /* part of the MDA */ typedef struct _lpt_device_ { @@ -51,23 +58,15 @@ typedef struct _lpt_device_ { } lpt_device_t; -extern char lpt_device_names[3][16]; +extern void parallel_init(void); +extern void parallel_setup(int id, uint16_t port); +extern void parallel_remove(int id); +extern void parallel_remove_amstrad(void); + +extern const char *parallel_device_get_name(int id); +extern char *parallel_device_get_internal_name(int id); +extern void parallel_devices_init(void); +extern void parallel_devices_close(void); -extern void lpt_init(void); -extern void lpt1_init(uint16_t port); -extern void lpt1_remove(void); -extern void lpt2_init(uint16_t port); -extern void lpt2_remove(void); -extern void lpt2_remove_ams(void); -extern void lpt3_init(uint16_t port); -extern void lpt3_remove(void); - -extern void lpt_devices_init(void); -extern void lpt_devices_close(void); - -extern const char *lpt_device_get_name(int id); -extern char *lpt_device_get_internal_name(int id); - - -#endif /*EMU_LPT_H*/ +#endif /*EMU_PARALLEL_H*/ diff --git a/src/pc.c b/src/pc.c index b9b5d99..68587d8 100644 --- a/src/pc.c +++ b/src/pc.c @@ -8,7 +8,7 @@ * * Main emulator module where most things are controlled. * - * Version: @(#)pc.c 1.0.19 2018/04/03 + * Version: @(#)pc.c 1.0.20 2018/04/05 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -65,8 +65,8 @@ #include "device.h" #include "nvr.h" #include "bugger.h" -#include "lpt.h" #include "serial.h" +#include "parallel.h" #include "keyboard.h" #include "mouse.h" #include "game/gameport.h" @@ -128,13 +128,15 @@ int vid_cga_contrast = 0, /* (C) video */ vid_card = 0, /* (C) graphics/video card */ video_speed = 0; /* (C) video */ int serial_enabled[SERIAL_MAX] = {0,0}, /* (C) enable serial ports */ - lpt_enabled = 0, /* (C) enable LPT ports */ + parallel_enabled[PARALLEL_MAX] = {0,0,0},/* (C) enable LPT ports */ bugger_enabled = 0; /* (C) enable ISAbugger */ +char parallel_device[PARALLEL_MAX][16]; /* (C) set up LPT devices */ int rctrl_is_lalt; /* (C) set R-CTRL as L-ALT */ int update_icons; /* (C) enable icons updates */ #ifdef WALTJE int romdos_enabled = 0; /* (C) enable ROM DOS */ #endif +int hdc_type = 0; /* (C) HDC type */ int sound_is_float = 1, /* (C) sound uses FP values */ GAMEBLASTER = 0, /* (C) sound option */ GUS = 0, /* (C) sound option */ @@ -764,12 +766,12 @@ pc_init_modules(void) sound_init(); - /* FIXME: should be disk_init(). */ - hdc_init(hdc_name); + /* FIXME: should be disk_init() */ cdrom_hard_reset(); zip_hard_reset(); ide_reset_hard(); + /* FIXME: should be scsi_init() */ scsi_card_init(); pc_full_speed(); @@ -790,7 +792,7 @@ pc_reset_hard_close(void) mouse_close(); - lpt_devices_close(); + parallel_devices_close(); device_close_all(); @@ -850,7 +852,7 @@ pc_reset_hard_init(void) /* Reset some basic devices. */ speaker_init(); serial_reset(); - lpt_devices_init(); + parallel_devices_init(); shadowbios = 0; @@ -976,7 +978,7 @@ pc_close(thread_t *ptr) plat_mouse_capture(0); - lpt_devices_close(); + parallel_devices_close(); for (i=0; i * @@ -48,7 +48,8 @@ # define EMU_SERIAL_H -#ifdef WALTJE_SERIAL +#define SERIAL_MAX 2 /* two ports supported */ + /* Default settings for the standard ports. */ #define SERIAL1_ADDR 0x03f8 #define SERIAL1_IRQ 4 @@ -56,6 +57,8 @@ #define SERIAL2_IRQ 3 +#ifdef WALTJE_SERIAL + /* Supported UART types. */ #define UART_TYPE_8250 0 /* standard NS8250 */ #define UART_TYPE_8250A 1 /* updated NS8250(A) */ @@ -138,12 +141,6 @@ void serial_clear_fifo(SERIAL *); void serial_write_fifo(SERIAL *serial, uint8_t dat); extern SERIAL serial1, serial2; - -/* Default settings for the standard ports. */ -#define SERIAL1_ADDR 0x03f8 -#define SERIAL1_IRQ 4 -#define SERIAL2_ADDR 0x02f8 -#define SERIAL2_IRQ 3 #endif diff --git a/src/sio/sio_fdc37c669.c b/src/sio/sio_fdc37c669.c index b261635..78f41d5 100644 --- a/src/sio/sio_fdc37c669.c +++ b/src/sio/sio_fdc37c669.c @@ -8,7 +8,7 @@ * * Implementation of the SMC FDC37C669 Super I/O Chip. * - * Version: @(#)sio_fdc37c669.c 1.0.2 2018/03/07 + * Version: @(#)sio_fdc37c669.c 1.0.3 2018/04/05 * * Author: Miran Grca, * @@ -40,7 +40,7 @@ #include "../io.h" #include "../device.h" #include "../pci.h" -#include "../lpt.h" +#include "../parallel.h" #include "../serial.h" #include "../floppy/fdd.h" #include "../floppy/fdc.h" @@ -158,11 +158,11 @@ process_value: if (valxor & 4) { /* pclog("Removing LPT1\n"); */ - lpt1_remove(); + parallel_remove(1); if ((fdc37c669_regs[1] & 4) && (fdc37c669_regs[0x23] >= 0x40)) { /* pclog("LPT1 init (%02X)\n", make_port(0x23)); */ - lpt1_init(make_port(0x23)); + parallel_setup(1, make_port(0x23)); } } if (valxor & 7) @@ -233,11 +233,11 @@ process_value: if (valxor) { /* pclog("Removing LPT1\n"); */ - lpt1_remove(); + parallel_remove(1); if ((fdc37c669_regs[1] & 4) && (fdc37c669_regs[0x23] >= 0x40)) { /* pclog("LPT1 init (%02X)\n", make_port(0x23)); */ - lpt1_init(make_port(0x23)); + parallel_setup(1, make_port(0x23)); } } break; @@ -321,10 +321,9 @@ void fdc37c669_reset(void) serial_remove(2); serial_setup(2, SERIAL2_ADDR, SERIAL2_IRQ); - lpt2_remove(); - - lpt1_remove(); - lpt1_init(0x378); + parallel_remove(1); + parallel_remove(2); + parallel_setup(1, 0x378); memset(fdc37c669_regs, 0, 42); fdc37c669_regs[0] = 0x28; diff --git a/src/sio/sio_fdc37c66x.c b/src/sio/sio_fdc37c66x.c index c50a7c5..40a7e64 100644 --- a/src/sio/sio_fdc37c66x.c +++ b/src/sio/sio_fdc37c66x.c @@ -9,7 +9,7 @@ * Implementation of the SMC FDC37C663 and FDC37C665 Super * I/O Chips. * - * Version: @(#)sio_fdc37c66x.c 1.0.2 2018/03/07 + * Version: @(#)sio_fdc37c66x.c 1.0.3 2018/04/05 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -45,7 +45,7 @@ #include "../io.h" #include "../device.h" #include "../pci.h" -#include "../lpt.h" +#include "../parallel.h" #include "../serial.h" #include "../floppy/fdd.h" #include "../floppy/fdc.h" @@ -173,17 +173,17 @@ static void set_serial2_addr() static void lpt1_handler() { - lpt1_remove(); + parallel_remove(1); switch (fdc37c66x_regs[1] & 3) { case 1: - lpt1_init(0x3bc); + parallel_setup(1, 0x3bc); break; case 2: - lpt1_init(0x378); + parallel_setup(1, 0x378); break; case 3: - lpt1_init(0x278); + parallel_setup(1, 0x278); break; } } @@ -303,10 +303,9 @@ static void fdc37c66x_reset(void) serial_remove(2); serial_setup(2, SERIAL2_ADDR, SERIAL2_IRQ); - lpt2_remove(); - - lpt1_remove(); - lpt1_init(0x378); + parallel_remove(1); + parallel_remove(2); + parallel_setup(1, 0x378); fdc_reset(fdc37c66x_fdc); diff --git a/src/sio/sio_fdc37c93x.c b/src/sio/sio_fdc37c93x.c index 106db01..0bb83c2 100644 --- a/src/sio/sio_fdc37c93x.c +++ b/src/sio/sio_fdc37c93x.c @@ -9,7 +9,7 @@ * Implementation of the SMC FDC37C932FR and FDC37C935 Super * I/O Chips. * - * Version: @(#)sio_fdc37c93x.c 1.0.4 2018/03/13 + * Version: @(#)sio_fdc37c93x.c 1.0.5 2018/04/05 * * Author: Miran Grca, * @@ -41,7 +41,7 @@ #include "../io.h" #include "../device.h" #include "../pci.h" -#include "../lpt.h" +#include "../parallel.h" #include "../serial.h" #include "../floppy/fdd.h" #include "../floppy/fdc.h" @@ -108,13 +108,13 @@ static void fdc37c93x_lpt_handler(void) uint8_t global_enable = !!(fdc37c93x_regs[0x22] & (1 << 3)); uint8_t local_enable = !!fdc37c93x_ld_regs[3][0x30]; - lpt1_remove(); + parallel_remove(1); if (global_enable && local_enable) { ld_port = make_port(3); /* pclog("fdc37c93x: Setting LPT1 port to %04X\n", ld_port); */ if ((ld_port >= 0x0100) && (ld_port <= 0x0FFC)) - lpt1_init(ld_port); + parallel_setup(1, ld_port); } } @@ -572,7 +572,7 @@ static void fdc37c935_reset(void) static void fdc37c93x_init(void) { - lpt2_remove(); + parallel_remove(2); fdc37c93x_fdc = device_add(&fdc_at_smc_device); diff --git a/src/sio/sio_pc87306.c b/src/sio/sio_pc87306.c index b12f226..be6c9f8 100644 --- a/src/sio/sio_pc87306.c +++ b/src/sio/sio_pc87306.c @@ -8,7 +8,7 @@ * * Emulation of the NatSemi PC87306 Super I/O chip. * - * Version: @(#)sio_pc87306.c 1.0.2 2018/03/07 + * Version: @(#)sio_pc87306.c 1.0.3 2018/04/05 * * Author: Miran Grca, * @@ -40,7 +40,7 @@ #include "../io.h" #include "../device.h" #include "../pci.h" -#include "../lpt.h" +#include "../parallel.h" #include "../serial.h" #include "../floppy/fdd.h" #include "../floppy/fdc.h" @@ -84,6 +84,7 @@ void lpt1_handler() { int temp; uint16_t lptba; + temp = pc87306_regs[0x01] & 3; lptba = ((uint16_t) pc87306_regs[0x19]) << 2; if (pc87306_regs[0x1B] & 0x10) { @@ -109,7 +110,7 @@ void lpt1_handler() } } if (lpt_port) - lpt1_init(lpt_port); + parallel_setup(1, lpt_port); } void serial1_handler() @@ -228,7 +229,7 @@ process_value: case 0: if (valxor & 1) { - lpt1_remove(); + parallel_remove(1); if (val & 1) { lpt1_handler(); @@ -284,7 +285,7 @@ process_value: case 1: if (valxor & 3) { - lpt1_remove(); + parallel_remove(1); if (pc87306_regs[0] & 1) { lpt1_handler(); @@ -320,7 +321,7 @@ process_value: { if (val & 1) { - lpt1_remove(); + parallel_remove(1); serial_remove(1); serial_remove(2); fdc_remove(pc87306_fdc); @@ -368,7 +369,7 @@ process_value: case 0x19: if (valxor) { - lpt1_remove(); + parallel_remove(1); if (pc87306_regs[0] & 1) { lpt1_handler(); @@ -378,7 +379,7 @@ process_value: case 0x1B: if (valxor & 0x70) { - lpt1_remove(); + parallel_remove(1); if (!(val & 0x40)) { pc87306_regs[0x19] = 0xEF; @@ -475,8 +476,8 @@ void pc87306_reset(void) 0 = 360 rpm @ 500 kbps for 3.5" 1 = Default, 300 rpm @ 500,300,250,1000 kbps for 3.5" */ - lpt1_remove(); - lpt2_remove(); + parallel_remove(1); + parallel_remove(2); lpt1_handler(); serial_remove(1); serial_remove(2); @@ -490,7 +491,7 @@ void pc87306_init() { pc87306_fdc = device_add(&fdc_at_nsc_device); - lpt2_remove(); + parallel_remove(2); pc87306_reset(); diff --git a/src/sio/sio_um8669f.c b/src/sio/sio_um8669f.c index 401d57b..51e5fbe 100644 --- a/src/sio/sio_um8669f.c +++ b/src/sio/sio_um8669f.c @@ -29,7 +29,7 @@ * 70 - IRQ * 74 - DMA * - * Version: @(#)sio_um8669f.c 1.0.2 2018/03/07 + * Version: @(#)sio_um8669f.c 1.0.3 2018/04/05 * * Author: Miran Grca, * Sarah Walker, @@ -63,7 +63,7 @@ #include "../device.h" #include "../io.h" #include "../pci.h" -#include "../lpt.h" +#include "../parallel.h" #include "../serial.h" #include "../floppy/fdd.h" #include "../floppy/fdc.h" @@ -181,9 +181,9 @@ void um8669f_pnp_write(uint16_t port, uint8_t val, void *p) case DEV_LPT1: if ((um8669f->cur_reg == REG_ENABLE) && valxor) { - lpt1_remove(); + parallel_remove(1); if (um8669f->dev[DEV_LPT1].enable & 1) - lpt1_init(um8669f->dev[DEV_LPT1].addr); + parallel_setup(1, um8669f->dev[DEV_LPT1].addr); } break; } @@ -289,10 +289,9 @@ void um8669f_reset(void) serial_remove(2); serial_setup(2, SERIAL2_ADDR, SERIAL2_IRQ); - lpt2_remove(); - - lpt1_remove(); - lpt1_init(0x378); + parallel_remove(1); + parallel_remove(2); + parallel_setup(1, 0x378); if (um8669f_global.pnp_active) { io_removehandler(0x0279, 0x0001, NULL, NULL, NULL, um8669f_pnp_write, NULL, NULL, &um8669f_global); diff --git a/src/sio/sio_w83877f.c b/src/sio/sio_w83877f.c index 21fc383..52a1720 100644 --- a/src/sio/sio_w83877f.c +++ b/src/sio/sio_w83877f.c @@ -11,7 +11,7 @@ * Winbond W83877F Super I/O Chip * Used by the Award 430HX * - * Version: @(#)sio_w83877f.c 1.0.2 2018/03/07 + * Version: @(#)sio_w83877f.c 1.0.3 2018/04/05 * * Author: Miran Grca, * @@ -46,7 +46,7 @@ #include "../pci.h" #include "../mem.h" #include "../rom.h" -#include "../lpt.h" +#include "../parallel.h" #include "../serial.h" #include "../floppy/fdd.h" #include "../floppy/fdc.h" @@ -412,8 +412,8 @@ process_value: } if (valxor & 0x80) { - lpt1_remove(); - if (!(w83877f_regs[4] & 0x80)) lpt1_init(make_port(0x23)); + parallel_remove(1); + if (!(w83877f_regs[4] & 0x80)) parallel_setup(1, make_port(0x23)); } break; case 6: @@ -457,8 +457,8 @@ process_value: case 0x23: if (valxor) { - lpt1_remove(); - if (!(w83877f_regs[4] & 0x80)) lpt1_init(make_port(0x23)); + parallel_remove(1); + if (!(w83877f_regs[4] & 0x80)) parallel_setup(1, make_port(0x23)); } break; case 0x24: @@ -517,8 +517,8 @@ uint8_t w83877f_read(uint16_t port, void *priv) void w83877f_reset(void) { - lpt1_remove(); - lpt1_init(0x378); + parallel_remove(1); + parallel_setup(1, 0x378); fdc_reset(w83877f_fdc); @@ -554,7 +554,7 @@ void w83877f_init(void) { w83877f_fdc = device_add(&fdc_at_winbond_device); - lpt2_remove(); + parallel_remove(2); w83877f_reset(); diff --git a/src/sound/midi.c b/src/sound/midi.c index 41f56ff..3d4aae2 100644 --- a/src/sound/midi.c +++ b/src/sound/midi.c @@ -8,7 +8,7 @@ * * MIDI support module, main file. * - * Version: @(#)midi.c 1.0.3 2018/03/15 + * Version: @(#)midi.c 1.0.4 2018/04/05 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -54,243 +54,246 @@ #endif -int midi_device_current = 0; -static int midi_device_last = 0; +#define SYSEX_SIZE 1024 +#define RAWBUF 1024 + + +int midi_device_current = 0; typedef struct { - const char *name; - const char *internal_name; - const device_t *device; -} MIDI_DEVICE; + const char *name; + const char *internal_name; + const device_t *device; +} midi_t; -static const MIDI_DEVICE devices[] = { - {"None", "none", NULL}, +static const midi_t devices[] = { + {"Disabled", "none", NULL }, #ifdef USE_FLUIDSYNTH - {"FluidSynth", "fluidsynth", &fluidsynth_device}, + {"FluidSynth", "fluidsynth", &fluidsynth_device}, #endif #ifdef USE_MUNT - {"Roland MT-32 Emulation", "mt32", &mt32_device}, - {"Roland CM-32L Emulation", "cm32l", &cm32l_device}, + {"Roland MT-32 Emulation", "mt32", &mt32_device }, + {"Roland CM-32L Emulation", "cm32l", &cm32l_device }, #endif - {SYSTEM_MIDI_NAME, SYSTEM_MIDI_INTERNAL_NAME, &system_midi_device}, - {"", "", NULL} + {SYSTEM_MIDI_NAME, SYSTEM_MIDI_INT, &system_midi_device}, + {NULL, NULL, NULL } }; -static midi_device_t* m_device = NULL; -int midi_device_available(int card) +static midi_device_t *m_device = NULL; +static int midi_device_last = 0; +static uint8_t midi_rt_buf[1024]; +static uint8_t midi_cmd_buf[1024]; +static int midi_cmd_pos = 0; +static int midi_cmd_len = 0; +static uint8_t midi_status = 0; +static unsigned int midi_pos; +static unsigned int midi_sysex_start = 0; +static unsigned int midi_sysex_delay = 0; +static uint8_t midi_sysex_data[1024+2]; +static const uint8_t MIDI_evt_len[256] = { + 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, // 0x00 + 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, // 0x10 + 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, // 0x20 + 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, // 0x30 + 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, // 0x40 + 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, // 0x50 + 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, // 0x60 + 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, // 0x70 + + 3,3,3,3, 3,3,3,3, 3,3,3,3, 3,3,3,3, // 0x80 + 3,3,3,3, 3,3,3,3, 3,3,3,3, 3,3,3,3, // 0x90 + 3,3,3,3, 3,3,3,3, 3,3,3,3, 3,3,3,3, // 0xa0 + 3,3,3,3, 3,3,3,3, 3,3,3,3, 3,3,3,3, // 0xb0 + + 2,2,2,2, 2,2,2,2, 2,2,2,2, 2,2,2,2, // 0xc0 + 2,2,2,2, 2,2,2,2, 2,2,2,2, 2,2,2,2, // 0xd0 + + 3,3,3,3, 3,3,3,3, 3,3,3,3, 3,3,3,3, // 0xe0 + + 0,2,3,2, 0,0,1,0, 1,0,1,1, 1,0,1,0 // 0xf0 +}; + + +int +midi_device_available(int card) { - if (devices[card].device) - return device_available(devices[card].device); + if (devices[card].device != NULL) + return(device_available(devices[card].device)); - return 1; + return(1); } -char *midi_device_getname(int card) + +char * +midi_device_getname(int card) { - return (char *) devices[card].name; + return((char *)devices[card].name); } -const device_t *midi_device_getdevice(int card) + +const device_t * +midi_device_getdevice(int card) { - return devices[card].device; + return(devices[card].device); } -int midi_device_has_config(int card) + +int +midi_device_has_config(int card) { - if (!devices[card].device) - return 0; - return devices[card].device->config ? 1 : 0; + if (devices[card].device == NULL) return(0); + + return(devices[card].device->config ? 1 : 0); } -char *midi_device_get_internal_name(int card) + +char * +midi_device_get_internal_name(int card) { - return (char *) devices[card].internal_name; + return((char *)devices[card].internal_name); } -int midi_device_get_from_internal_name(char *s) + +int +midi_device_get_from_internal_name(char *s) { - int c = 0; + int c = 0; - while (strlen(devices[c].internal_name)) - { - if (!strcmp(devices[c].internal_name, s)) - return c; - c++; + while (devices[c].internal_name != NULL) { + if (!strcmp(devices[c].internal_name, s)) + return(c); + c++; + } + + return(0); +} + + +void +midi_device_init(void) +{ + if (devices[midi_device_current].device != NULL) + device_add(devices[midi_device_current].device); + + midi_device_last = midi_device_current; +} + + +void +midi_init(midi_device_t* device) +{ + memset(midi_rt_buf, 0, sizeof(midi_rt_buf)); + memset(midi_cmd_buf, 0, sizeof(midi_cmd_buf)); + + midi_cmd_pos = midi_cmd_len = 0; + midi_status = 0; + + midi_sysex_start = midi_sysex_delay = 0; + + m_device = device; +} + + +void +midi_close(void) +{ + m_device = NULL; +} + + +void +midi_poll(void) +{ + if (m_device && m_device->poll) + m_device->poll(); +} + + +void +play_msg(uint8_t *msg) +{ + if (m_device->play_msg) + m_device->play_msg(msg); +} + + +void +play_sysex(uint8_t *sysex, unsigned int len) +{ + if (m_device->play_sysex) + m_device->play_sysex(sysex, len); +} + + +void +midi_write(uint8_t val) +{ + uint32_t passed_ticks; + + if (m_device == NULL) return; + + if (m_device->write && m_device->write(val)) return; + + if (midi_sysex_start) { + passed_ticks = plat_get_ticks() - midi_sysex_start; + if (passed_ticks < midi_sysex_delay) + plat_delay_ms(midi_sysex_delay - passed_ticks); + } + + /* Test for a realtime MIDI message */ + if (val >= 0xf8) { + midi_rt_buf[0] = val; + play_msg(midi_rt_buf); + return; + } + + /* Test for a active sysex transfer */ + if (midi_status == 0xf0) { + if (! (val & 0x80)) { + if (midi_pos < (SYSEX_SIZE-1)) midi_sysex_data[midi_pos++] = val; + return; + } else { + midi_sysex_data[midi_pos++] = 0xf7; + + if ((midi_sysex_start) && (midi_pos >= 4) && (midi_pos <= 9) && (midi_sysex_data[1] == 0x41) && (midi_sysex_data[3] == 0x16)) { + /* pclog("MIDI: Skipping invalid MT-32 SysEx MIDI message\n"); */ + } else { + play_sysex(midi_sysex_data, midi_pos); + if (midi_sysex_start) { + if (midi_sysex_data[5] == 0x7f) { + midi_sysex_delay = 290; /* All parameters reset */ + } else if ((midi_sysex_data[5] == 0x10) && (midi_sysex_data[6] == 0x00) && (midi_sysex_data[7] == 0x04)) { + midi_sysex_delay = 145; /* Viking Child */ + } else if ((midi_sysex_data[5] == 0x10) && (midi_sysex_data[6] == 0x00) && (midi_sysex_data[7] == 0x01)) { + midi_sysex_delay = 30; /* Dark Sun 1 */ + } else + midi_sysex_delay = (unsigned int) (((float) (midi_pos) * 1.25f) * 1000.0f / 3125.0f) + 2; + + midi_sysex_start = plat_get_ticks(); + } + } } - - return 0; -} - -void midi_device_init() -{ - if (devices[midi_device_current].device) - device_add(devices[midi_device_current].device); - midi_device_last = midi_device_current; -} - -static uint8_t midi_rt_buf[1024]; -static uint8_t midi_cmd_buf[1024]; -static int midi_cmd_pos = 0; -static int midi_cmd_len = 0; -static uint8_t midi_status = 0; -static unsigned int midi_sysex_start = 0; -static unsigned int midi_sysex_delay = 0; - -uint8_t MIDI_evt_len[256] = { - 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, // 0x00 - 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, // 0x10 - 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, // 0x20 - 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, // 0x30 - 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, // 0x40 - 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, // 0x50 - 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, // 0x60 - 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, // 0x70 - - 3,3,3,3, 3,3,3,3, 3,3,3,3, 3,3,3,3, // 0x80 - 3,3,3,3, 3,3,3,3, 3,3,3,3, 3,3,3,3, // 0x90 - 3,3,3,3, 3,3,3,3, 3,3,3,3, 3,3,3,3, // 0xa0 - 3,3,3,3, 3,3,3,3, 3,3,3,3, 3,3,3,3, // 0xb0 - - 2,2,2,2, 2,2,2,2, 2,2,2,2, 2,2,2,2, // 0xc0 - 2,2,2,2, 2,2,2,2, 2,2,2,2, 2,2,2,2, // 0xd0 - - 3,3,3,3, 3,3,3,3, 3,3,3,3, 3,3,3,3, // 0xe0 - - 0,2,3,2, 0,0,1,0, 1,0,1,1, 1,0,1,0 // 0xf0 -}; - -static unsigned int midi_pos; -static uint8_t midi_sysex_data[1024+2]; - -void midi_init(midi_device_t* device) -{ - memset(midi_rt_buf, 0, sizeof(midi_rt_buf)); - memset(midi_cmd_buf, 0, sizeof(midi_cmd_buf)); - - midi_cmd_pos = midi_cmd_len = 0; - midi_status = 0; - - midi_sysex_start = midi_sysex_delay = 0; - - m_device = device; - -} - -void midi_close() -{ - m_device = NULL; -} - -void midi_poll() -{ - if (m_device && m_device->poll) m_device->poll(); -} - -void play_msg(uint8_t *msg) -{ - if (m_device->play_msg) m_device->play_msg(msg); -} - - -void play_sysex(uint8_t *sysex, unsigned int len) -{ - if (m_device->play_sysex) m_device->play_sysex(sysex, len); -} - -#define SYSEX_SIZE 1024 -#define RAWBUF 1024 - -void midi_write(uint8_t val) -{ - if (!m_device) return; - - if (m_device->write && m_device->write(val)) return; - - uint32_t passed_ticks; - - if (midi_sysex_start) - { - passed_ticks = plat_get_ticks() - midi_sysex_start; - if (passed_ticks < midi_sysex_delay) - { - plat_delay_ms(midi_sysex_delay - passed_ticks); - } - } - - /* Test for a realtime MIDI message */ - if (val >= 0xf8) - { - midi_rt_buf[0] = val; - play_msg(midi_rt_buf); - return; - } - - /* Test for a active sysex transfer */ - - if (midi_status == 0xf0) - { - if (!(val & 0x80)) - { - if (midi_pos < (SYSEX_SIZE-1)) midi_sysex_data[midi_pos++] = val; - return; - } - else - { - midi_sysex_data[midi_pos++] = 0xf7; - - if ((midi_sysex_start) && (midi_pos >= 4) && (midi_pos <= 9) && (midi_sysex_data[1] == 0x41) && (midi_sysex_data[3] == 0x16)) - { - /* pclog("MIDI: Skipping invalid MT-32 SysEx MIDI message\n"); */ - } - else - { - play_sysex(midi_sysex_data, midi_pos); - if (midi_sysex_start) - { - if (midi_sysex_data[5] == 0x7f) - { - midi_sysex_delay = 290; /* All parameters reset */ - } - else if ((midi_sysex_data[5] == 0x10) && (midi_sysex_data[6] == 0x00) && (midi_sysex_data[7] == 0x04)) - { - midi_sysex_delay = 145; /* Viking Child */ - } - else if ((midi_sysex_data[5] == 0x10) && (midi_sysex_data[6] == 0x00) && (midi_sysex_data[7] == 0x01)) - { - midi_sysex_delay = 30; /* Dark Sun 1 */ - } - else - midi_sysex_delay = (unsigned int) (((float) (midi_pos) * 1.25f) * 1000.0f / 3125.0f) + 2; - - midi_sysex_start = plat_get_ticks(); - } - } - } - } - - - if (val & 0x80) - { - midi_status = val; - midi_cmd_pos = 0; - midi_cmd_len = MIDI_evt_len[val]; - if (midi_status == 0xf0) - { - midi_sysex_data[0] = 0xf0; - midi_pos = 1; - } - } - - if (midi_cmd_len) - { - midi_cmd_buf[midi_cmd_pos++] = val; - if (midi_cmd_pos >= midi_cmd_len) - { - play_msg(midi_cmd_buf); - midi_cmd_pos = 1; - } - } + } + + if (val & 0x80) { + midi_status = val; + midi_cmd_pos = 0; + midi_cmd_len = MIDI_evt_len[val]; + + if (midi_status == 0xf0) { + midi_sysex_data[0] = 0xf0; + midi_pos = 1; + } + } + + if (midi_cmd_len) { + midi_cmd_buf[midi_cmd_pos++] = val; + if (midi_cmd_pos >= midi_cmd_len) { + play_msg(midi_cmd_buf); + midi_cmd_pos = 1; + } + } } diff --git a/src/sound/midi.h b/src/sound/midi.h index 806df87..6df1a32 100644 --- a/src/sound/midi.h +++ b/src/sound/midi.h @@ -8,7 +8,7 @@ * * Definitions for the MIDI module. * - * Version: @(#)midi.h 1.0.2 2018/03/15 + * Version: @(#)midi.h 1.0.3 2018/04/05 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -66,17 +66,12 @@ void midi_close(); void midi_write(uint8_t val); void midi_poll(); -#if 0 #ifdef _WIN32 -#define SYSTEM_MIDI_NAME "Windows MIDI" -#define SYSTEM_MIDI_INTERNAL_NAME "windows_midi" +# define SYSTEM_MIDI_NAME "Windows MIDI" +# define SYSTEM_MIDI_INT "system_midi" #else -#define SYSTEM_MIDI_NAME "System MIDI" -#define SYSTEM_MIDI_INTERNAL_NAME "system_midi" -#endif -#else -#define SYSTEM_MIDI_NAME "System MIDI" -#define SYSTEM_MIDI_INTERNAL_NAME "system_midi" +# define SYSTEM_MIDI_NAME "System MIDI" +# define SYSTEM_MIDI_INT "system_midi" #endif diff --git a/src/sound/openal.c b/src/sound/openal.c index 28f8b37..0b56bef 100644 --- a/src/sound/openal.c +++ b/src/sound/openal.c @@ -8,7 +8,7 @@ * * Interface to the OpenAL sound processing library. * - * Version: @(#)openal.c 1.0.5 2018/03/28 + * Version: @(#)openal.c 1.0.6 2018/04/05 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -209,8 +209,7 @@ initalmain(int argc, char *argv[]) * initialize the MIDI buffer and source, otherwise, do not. */ str = midi_device_get_internal_name(midi_device_current); - if (!strcmp(str, "none") || - !strcmp(str, SYSTEM_MIDI_INTERNAL_NAME)) return; + if (!strcmp(str, "none") || !strcmp(str, SYSTEM_MIDI_INT)) return; /* Try loading the DLL. */ openal_handle = dynld_module(PATH_AL_DLL, openal_imports); diff --git a/src/sound/snd_lpt_dac.c b/src/sound/snd_lpt_dac.c index 7b408e3..820ad39 100644 --- a/src/sound/snd_lpt_dac.c +++ b/src/sound/snd_lpt_dac.c @@ -8,7 +8,7 @@ * * Implemantation of LPT-based sound devices. * - * Version: @(#)snd_lpt_dac.c 1.0.3 2018/03/28 + * Version: @(#)snd_lpt_dac.c 1.0.4 2018/04/05 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -44,7 +44,7 @@ #include "../emu.h" #include "../cpu/cpu.h" #include "../machine/machine.h" -#include "../lpt.h" +#include "../parallel.h" #include "../timer.h" #include "sound.h" #include "filters.h" diff --git a/src/sound/snd_lpt_dss.c b/src/sound/snd_lpt_dss.c index 9bec116..ab3c42c 100644 --- a/src/sound/snd_lpt_dss.c +++ b/src/sound/snd_lpt_dss.c @@ -8,7 +8,7 @@ * * Implementation of the LPT-based DSS sound device. * - * Version: @(#)snd_lpt_dss.c 1.0.3 2018/03/28 + * Version: @(#)snd_lpt_dss.c 1.0.4 2018/04/05 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -45,7 +45,7 @@ #include "../cpu/cpu.h" #include "../machine/machine.h" #include "../timer.h" -#include "../lpt.h" +#include "../parallel.h" #include "sound.h" #include "filters.h" #include "snd_lpt_dss.h" diff --git a/src/sound/sound.c b/src/sound/sound.c index ddce303..d360f6a 100644 --- a/src/sound/sound.c +++ b/src/sound/sound.c @@ -8,7 +8,7 @@ * * Sound emulation core. * - * Version: @(#)sound.c 1.0.5 2018/04/02 + * Version: @(#)sound.c 1.0.6 2018/04/05 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -68,14 +68,14 @@ typedef struct { - const char *name; - const char *internal_name; - const device_t *device; -} SOUND_CARD; + const char *name; + const char *internal_name; + const device_t *device; +} sound_t; typedef struct { - void (*get_buffer)(int32_t *buffer, int len, void *p); - void *priv; + void (*get_buffer)(int32_t *buffer, int len, void *p); + void *priv; } sound_handler_t; @@ -88,45 +88,49 @@ int sound_gain = 0; volatile int soundon = 1; -static int sound_card_last = 0; -static sound_handler_t sound_handlers[8]; -static sound_handler_t sound_process_handlers[8]; -static int sound_handlers_num; -static int sound_process_handlers_num; -static int64_t sound_poll_time = 0LL, sound_poll_latch; -static int16_t cd_buffer[CDROM_NUM][CD_BUFLEN * 2]; -static float cd_out_buffer[CD_BUFLEN * 2]; -static int16_t cd_out_buffer_int16[CD_BUFLEN * 2]; -static thread_t *sound_cd_thread_h; -static event_t *sound_cd_event; -static event_t *sound_cd_start_event; -static unsigned int cd_vol_l, cd_vol_r; -static int cd_buf_update = CD_BUFLEN / SOUNDBUFLEN; -static volatile int cdaudioon = 0; +static int sound_card_last = 0; +static sound_handler_t sound_handlers[8]; +static sound_handler_t sound_process_handlers[8]; +static int sound_handlers_num; +static int sound_process_handlers_num; +static int64_t sound_poll_time = 0LL, sound_poll_latch; +static int16_t cd_buffer[CDROM_NUM][CD_BUFLEN * 2]; +static float cd_out_buffer[CD_BUFLEN * 2]; +static int16_t cd_out_buffer_int16[CD_BUFLEN * 2]; +static thread_t *sound_cd_thread_h; +static event_t *sound_cd_event; +static event_t *sound_cd_start_event; +static unsigned int cd_vol_l, + cd_vol_r; +static int cd_buf_update = CD_BUFLEN / SOUNDBUFLEN; +static volatile int cdaudioon = 0; +static int32_t *outbuffer; +static float *outbuffer_ex; +static int16_t *outbuffer_ex_int16; +static int cd_thread_enable = 0; -static const SOUND_CARD sound_cards[] = -{ - { "None", "none", NULL }, - { "[ISA] Adlib", "adlib", &adlib_device }, - { "[ISA] Adlib Gold", "adlibgold",&adgold_device }, - { "[ISA] Sound Blaster 1.0", "sb", &sb_1_device }, - { "[ISA] Sound Blaster 1.5", "sb1.5", &sb_15_device }, - { "[ISA] Sound Blaster 2.0", "sb2.0", &sb_2_device }, - { "[ISA] Sound Blaster Pro v1", "sbprov1", &sb_pro_v1_device }, - { "[ISA] Sound Blaster Pro v2", "sbprov2", &sb_pro_v2_device }, - { "[ISA] Sound Blaster 16", "sb16", &sb_16_device }, - { "[ISA] Sound Blaster AWE32", "sbawe32", &sb_awe32_device }, +static const sound_t sound_cards[] = { + {"Disabled", "none", NULL }, + {"[ISA] Adlib", "adlib", &adlib_device }, + {"[ISA] Adlib Gold", "adlibgold", &adgold_device }, + {"[ISA] Sound Blaster 1.0", "sb", &sb_1_device }, + {"[ISA] Sound Blaster 1.5", "sb1.5", &sb_15_device }, + {"[ISA] Sound Blaster 2.0", "sb2.0", &sb_2_device }, + {"[ISA] Sound Blaster Pro v1", "sbprov1", &sb_pro_v1_device}, + {"[ISA] Sound Blaster Pro v2", "sbprov2", &sb_pro_v2_device}, + {"[ISA] Sound Blaster 16", "sb16", &sb_16_device }, + {"[ISA] Sound Blaster AWE32", "sbawe32", &sb_awe32_device}, #if defined(DEV_BRANCH) && defined(USE_PAS16) - { "[ISA] Pro Audio Spectrum 16","pas16", &pas16_device }, + {"[ISA] Pro Audio Spectrum 16", "pas16", &pas16_device }, #endif - { "[ISA] Windows Sound System", "wss", &wss_device }, - { "[MCA] Adlib", "adlib_mca", &adlib_mca_device }, - { "[MCA] Sound Blaster MCV", "sbmcv", &sb_mcv_device }, - { "[MCA] Sound Blaster Pro MCV","sbpromcv", &sb_pro_mcv_device }, - { "[PCI] Ensoniq AudioPCI (ES1371)","es1371", &es1371_device}, - { "[PCI] Sound Blaster PCI 128", "sbpci128", &es1371_device}, - { "", "", NULL } + {"[ISA] Windows Sound System", "wss", &wss_device }, + {"[MCA] Adlib", "adlib_mca", &adlib_mca_device}, + {"[MCA] Sound Blaster MCV", "sbmcv", &sb_mcv_device }, + {"[MCA] Sound Blaster Pro MCV", "sbpromcv", &sb_pro_mcv_device}, + {"[PCI] Ensoniq AudioPCI (ES1371)", "es1371", &es1371_device }, + {"[PCI] Sound Blaster PCI 128", "sbpci128", &es1371_device }, + {NULL, NULL, NULL } }; @@ -145,423 +149,400 @@ snddev_log(const char *fmt, ...) } -int sound_card_available(int card) +int +sound_card_available(int card) { - if (sound_cards[card].device) - return device_available(sound_cards[card].device); + if (sound_cards[card].device != NULL) + return(device_available(sound_cards[card].device)); - return 1; + return(1); } -char *sound_card_getname(int card) + +char * +sound_card_getname(int card) { - return (char *)sound_cards[card].name; + return((char *)sound_cards[card].name); } + const device_t *sound_card_getdevice(int card) { - return sound_cards[card].device; + return(sound_cards[card].device); } -int sound_card_has_config(int card) + +int +sound_card_has_config(int card) { - if (!sound_cards[card].device) - return 0; - return sound_cards[card].device->config ? 1 : 0; + if (sound_cards[card].device == NULL) return(0); + + return(sound_cards[card].device->config ? 1 : 0); } -char *sound_card_get_internal_name(int card) + +char * +sound_card_get_internal_name(int card) { - return (char *)sound_cards[card].internal_name; + return((char *)sound_cards[card].internal_name); } -int sound_card_get_from_internal_name(char *s) + +int +sound_card_get_from_internal_name(char *s) { - int c = 0; - - while (strlen((char *)sound_cards[c].internal_name)) - { - if (! strcmp((char *)sound_cards[c].internal_name, s)) - return c; - c++; - } - - return 0; + int c = 0; + + while (sound_cards[c].internal_name != NULL) { + if (! strcmp((char *)sound_cards[c].internal_name, s)) + return(c); + c++; + } + + return(0); } -void sound_card_init(void) + +void +sound_card_init(void) { - if (sound_cards[sound_card_current].device) - device_add(sound_cards[sound_card_current].device); - sound_card_last = sound_card_current; + if (sound_cards[sound_card_current].device != NULL) + device_add(sound_cards[sound_card_current].device); + + sound_card_last = sound_card_current; } -void sound_set_cd_volume(unsigned int vol_l, unsigned int vol_r) + +void +sound_set_cd_volume(unsigned int vol_l, unsigned int vol_r) { - cd_vol_l = vol_l; - cd_vol_r = vol_r; + cd_vol_l = vol_l; + cd_vol_r = vol_r; } -static void sound_cd_thread(void *param) + +static void +sound_cd_thread(void *param) { - int i = 0; + float cd_buffer_temp[2] = {0.0, 0.0}; + float cd_buffer_temp2[2] = {0.0, 0.0}; + int32_t cd_buffer_temp4[2] = {0, 0}; + int32_t audio_vol_l; + int32_t audio_vol_r; + int channel_select[2]; + int c, d, i, has_audio; - float cd_buffer_temp[2] = {0.0, 0.0}; - float cd_buffer_temp2[2] = {0.0, 0.0}; + thread_set_event(sound_cd_start_event); - int32_t cd_buffer_temp4[2] = {0, 0}; + while (cdaudioon) { + thread_wait_event(sound_cd_event, -1); + thread_reset_event(sound_cd_event); - int c, has_audio; - int d; + if (!soundon || !cdaudioon) return; - thread_set_event(sound_cd_start_event); - - while (cdaudioon) - { - thread_wait_event(sound_cd_event, -1); - thread_reset_event(sound_cd_event); - if (!soundon || !cdaudioon) - return; - for (c = 0; c < CD_BUFLEN*2; c += 2) - { - if (sound_is_float) - { - cd_out_buffer[c] = 0.0; - cd_out_buffer[c+1] = 0.0; - } - else - { - cd_out_buffer_int16[c] = 0; - cd_out_buffer_int16[c+1] = 0; - } + for (c = 0; c < CD_BUFLEN*2; c += 2) { + if (sound_is_float) { + cd_out_buffer[c] = 0.0; + cd_out_buffer[c+1] = 0.0; + } else { + cd_out_buffer_int16[c] = 0; + cd_out_buffer_int16[c+1] = 0; } - for (i = 0; i < CDROM_NUM; i++) - { - has_audio = 0; - if (cdrom_drives[i].bus_type == CDROM_BUS_DISABLED) - continue; - if (cdrom_drives[i].handler->audio_callback) - { - cdrom_drives[i].handler->audio_callback(i, cd_buffer[i], CD_BUFLEN*2); - has_audio = (cdrom_drives[i].bus_type && cdrom_drives[i].sound_on); - } else - continue; - if (soundon && has_audio) - { - int32_t audio_vol_l = cdrom_mode_sense_get_volume(i, 0); - int32_t audio_vol_r = cdrom_mode_sense_get_volume(i, 1); - int channel_select[2]; + } - channel_select[0] = cdrom_mode_sense_get_channel(i, 0); - channel_select[1] = cdrom_mode_sense_get_channel(i, 1); + for (i = 0; i < CDROM_NUM; i++) { + has_audio = 0; - for (c = 0; c < CD_BUFLEN*2; c += 2) - { - /* First, transfer the CD audio data to the temporary buffer. */ - cd_buffer_temp[0] = (float) cd_buffer[i][c]; - cd_buffer_temp[1] = (float) cd_buffer[i][c+1]; - - /* Then, adjust input from drive according to ATAPI/SCSI volume. */ - cd_buffer_temp[0] *= (float) audio_vol_l; - cd_buffer_temp[0] /= 511.0; - cd_buffer_temp[1] *= (float) audio_vol_r; - cd_buffer_temp[1] /= 511.0; + if (cdrom_drives[i].bus_type == CDROM_BUS_DISABLED) continue; - /*Apply ATAPI channel select*/ - cd_buffer_temp2[0] = cd_buffer_temp2[1] = 0.0; - if (channel_select[0] & 1) - { - cd_buffer_temp2[0] += cd_buffer_temp[0]; - } - if (channel_select[0] & 2) - { - cd_buffer_temp2[1] += cd_buffer_temp[0]; - } - if (channel_select[1] & 1) - { - cd_buffer_temp2[0] += cd_buffer_temp[1]; - } - if (channel_select[1] & 2) - { - cd_buffer_temp2[1] += cd_buffer_temp[1]; - } + if (cdrom_drives[i].handler->audio_callback) { + cdrom_drives[i].handler->audio_callback(i, cd_buffer[i], CD_BUFLEN*2); + has_audio = (cdrom_drives[i].bus_type && cdrom_drives[i].sound_on); + } else + continue; - if (sound_process_handlers_num) - { - cd_buffer_temp4[0] = (int32_t) cd_buffer_temp2[0]; - cd_buffer_temp4[1] = (int32_t) cd_buffer_temp2[1]; + if (soundon && has_audio) { + audio_vol_l = cdrom_mode_sense_get_volume(i, 0); + audio_vol_r = cdrom_mode_sense_get_volume(i, 1); - for (d = 0; d < sound_process_handlers_num; d++) - sound_process_handlers[d].get_buffer(cd_buffer_temp4, 1, sound_process_handlers[d].priv); + channel_select[0] = cdrom_mode_sense_get_channel(i, 0); + channel_select[1] = cdrom_mode_sense_get_channel(i, 1); - cd_buffer_temp2[0] = (float) cd_buffer_temp4[0]; - cd_buffer_temp2[1] = (float) cd_buffer_temp4[1]; - } - else - { - /*Apply sound card CD volume*/ - cd_buffer_temp2[0] *= (float) cd_vol_l; - cd_buffer_temp2[0] /= 65535.0; + for (c = 0; c < CD_BUFLEN*2; c += 2) { + /* First, transfer the CD audio data to the temporary buffer. */ + cd_buffer_temp[0] = (float) cd_buffer[i][c]; + cd_buffer_temp[1] = (float) cd_buffer[i][c+1]; - cd_buffer_temp2[1] *= (float) cd_vol_r; - cd_buffer_temp2[1] /= 65535.0; - } + /* Then, adjust input from drive according to ATAPI/SCSI volume. */ + cd_buffer_temp[0] *= (float) audio_vol_l; + cd_buffer_temp[0] /= 511.0; + cd_buffer_temp[1] *= (float) audio_vol_r; + cd_buffer_temp[1] /= 511.0; - if (sound_is_float) - { - cd_out_buffer[c] += (float)(cd_buffer_temp2[0] / 32768.0); - cd_out_buffer[c+1] += (float)(cd_buffer_temp2[1] / 32768.0); - } - else - { - if (cd_buffer_temp2[0] > 32767) - cd_buffer_temp2[0] = 32767; - if (cd_buffer_temp2[0] < -32768) - cd_buffer_temp2[0] = -32768; - if (cd_buffer_temp2[1] > 32767) - cd_buffer_temp2[1] = 32767; - if (cd_buffer_temp2[1] < -32768) - cd_buffer_temp2[1] = -32768; + /*Apply ATAPI channel select*/ + cd_buffer_temp2[0] = cd_buffer_temp2[1] = 0.0; + if (channel_select[0] & 1) + cd_buffer_temp2[0] += cd_buffer_temp[0]; + if (channel_select[0] & 2) + cd_buffer_temp2[1] += cd_buffer_temp[0]; + if (channel_select[1] & 1) + cd_buffer_temp2[0] += cd_buffer_temp[1]; + if (channel_select[1] & 2) + cd_buffer_temp2[1] += cd_buffer_temp[1]; - cd_out_buffer_int16[c] += (int16_t)cd_buffer_temp2[0]; - cd_out_buffer_int16[c+1] += (int16_t)cd_buffer_temp2[1]; - } + if (sound_process_handlers_num) { + cd_buffer_temp4[0] = (int32_t) cd_buffer_temp2[0]; + cd_buffer_temp4[1] = (int32_t) cd_buffer_temp2[1]; + + for (d = 0; d < sound_process_handlers_num; d++) + sound_process_handlers[d].get_buffer(cd_buffer_temp4, 1, sound_process_handlers[d].priv); + + cd_buffer_temp2[0] = (float) cd_buffer_temp4[0]; + cd_buffer_temp2[1] = (float) cd_buffer_temp4[1]; + } else { + /*Apply sound card CD volume*/ + cd_buffer_temp2[0] *= (float) cd_vol_l; + cd_buffer_temp2[0] /= 65535.0; + + cd_buffer_temp2[1] *= (float) cd_vol_r; + cd_buffer_temp2[1] /= 65535.0; + } + + if (sound_is_float) { + cd_out_buffer[c] += (float)(cd_buffer_temp2[0] / 32768.0); + cd_out_buffer[c+1] += (float)(cd_buffer_temp2[1] / 32768.0); + } else { + if (cd_buffer_temp2[0] > 32767) + cd_buffer_temp2[0] = 32767; + if (cd_buffer_temp2[0] < -32768) + cd_buffer_temp2[0] = -32768; + if (cd_buffer_temp2[1] > 32767) + cd_buffer_temp2[1] = 32767; + if (cd_buffer_temp2[1] < -32768) + cd_buffer_temp2[1] = -32768; + + cd_out_buffer_int16[c] += (int16_t)cd_buffer_temp2[0]; + cd_out_buffer_int16[c+1] += (int16_t)cd_buffer_temp2[1]; } } } - if (sound_is_float) - givealbuffer_cd(cd_out_buffer); - else - givealbuffer_cd(cd_out_buffer_int16); - } -} - -static int32_t *outbuffer; -static float *outbuffer_ex; -static int16_t *outbuffer_ex_int16; - -static int cd_thread_enable = 0; - -void sound_realloc_buffers(void) -{ - if (outbuffer_ex != NULL) - { - free(outbuffer_ex); - } - - if (outbuffer_ex_int16 != NULL) - { - free(outbuffer_ex_int16); } if (sound_is_float) - { - outbuffer_ex = malloc(SOUNDBUFLEN * 2 * sizeof(float)); - } + givealbuffer_cd(cd_out_buffer); else - { - outbuffer_ex_int16 = malloc(SOUNDBUFLEN * 2 * sizeof(int16_t)); - } + givealbuffer_cd(cd_out_buffer_int16); + } } -void sound_init(void) + +void +sound_realloc_buffers(void) { - int i = 0; - int available_cdrom_drives = 0; + if (outbuffer_ex != NULL) + free(outbuffer_ex); + if (outbuffer_ex_int16 != NULL) + free(outbuffer_ex_int16); - initalmain(0,NULL); - inital(); - - outbuffer_ex = NULL; - outbuffer_ex_int16 = NULL; - - outbuffer = malloc(SOUNDBUFLEN * 2 * sizeof(int32_t)); - - sound_realloc_buffers(); - - for (i = 0; i < CDROM_NUM; i++) - { - if (cdrom_drives[i].bus_type != CDROM_BUS_DISABLED) - { - available_cdrom_drives++; - } - } - - if (available_cdrom_drives) - { - cdaudioon = 1; - - sound_cd_start_event = thread_create_event(); - - sound_cd_event = thread_create_event(); - sound_cd_thread_h = thread_create(sound_cd_thread, NULL); - - /* pclog("Waiting for CD start event...\n"); */ - thread_wait_event(sound_cd_start_event, -1); - thread_reset_event(sound_cd_start_event); - /* pclog("Done!\n"); */ - } - else - cdaudioon = 0; - - cd_thread_enable = available_cdrom_drives ? 1 : 0; + if (sound_is_float) + outbuffer_ex = malloc(SOUNDBUFLEN * 2 * sizeof(float)); + else + outbuffer_ex_int16 = malloc(SOUNDBUFLEN * 2 * sizeof(int16_t)); } -void sound_add_handler(void (*get_buffer)(int32_t *buffer, int len, void *p), void *p) + +void +sound_init(void) { - sound_handlers[sound_handlers_num].get_buffer = get_buffer; - sound_handlers[sound_handlers_num].priv = p; - sound_handlers_num++; + int drives = 0; + int i; + + initalmain(0,NULL); + inital(); + + outbuffer_ex = NULL; + outbuffer_ex_int16 = NULL; + + outbuffer = malloc(SOUNDBUFLEN * 2 * sizeof(int32_t)); + + sound_realloc_buffers(); + + for (i = 0; i < CDROM_NUM; i++) { + if (cdrom_drives[i].bus_type != CDROM_BUS_DISABLED) + drives++; + } + + if (drives) { + cdaudioon = 1; + + sound_cd_start_event = thread_create_event(); + + sound_cd_event = thread_create_event(); + sound_cd_thread_h = thread_create(sound_cd_thread, NULL); + +#if 0 + pclog("Waiting for CD start event...\n"); +#endif + thread_wait_event(sound_cd_start_event, -1); + thread_reset_event(sound_cd_start_event); +#if 0 + pclog("Done!\n"); +#endif + } else + cdaudioon = 0; + + cd_thread_enable = drives ? 1 : 0; } -void sound_add_process_handler(void (*get_buffer)(int32_t *buffer, int len, void *p), void *p) + +void +sound_add_handler(void (*get_buffer)(int32_t *buffer, int len, void *p), void *p) { - sound_process_handlers[sound_process_handlers_num].get_buffer = get_buffer; - sound_process_handlers[sound_process_handlers_num].priv = p; - sound_process_handlers_num++; + sound_handlers[sound_handlers_num].get_buffer = get_buffer; + sound_handlers[sound_handlers_num].priv = p; + sound_handlers_num++; } -void sound_poll(void *priv) + +void +sound_add_process_handler(void (*get_buffer)(int32_t *buffer, int len, void *p), void *p) { - sound_poll_time += sound_poll_latch; - - midi_poll(); - - sound_pos_global++; - if (sound_pos_global == SOUNDBUFLEN) - { - int c; - - memset(outbuffer, 0, SOUNDBUFLEN * 2 * sizeof(int32_t)); - - for (c = 0; c < sound_handlers_num; c++) - sound_handlers[c].get_buffer(outbuffer, SOUNDBUFLEN, sound_handlers[c].priv); - - - for (c = 0; c < SOUNDBUFLEN * 2; c++) - { - if (sound_is_float) - { - outbuffer_ex[c] = (float)((outbuffer[c]) / 32768.0); - } - else - { - if (outbuffer[c] > 32767) - outbuffer[c] = 32767; - if (outbuffer[c] < -32768) - outbuffer[c] = -32768; - - outbuffer_ex_int16[c] = outbuffer[c]; - } - } - - if (soundon) - { - if (sound_is_float) - { - givealbuffer(outbuffer_ex); - } - else - { - givealbuffer(outbuffer_ex_int16); - } - } - - if (cd_thread_enable) - { - cd_buf_update--; - if (!cd_buf_update) - { - cd_buf_update = (48000 / SOUNDBUFLEN) / (CD_FREQ / CD_BUFLEN); - thread_set_event(sound_cd_event); - } - } - - sound_pos_global = 0; - } + sound_process_handlers[sound_process_handlers_num].get_buffer = get_buffer; + sound_process_handlers[sound_process_handlers_num].priv = p; + sound_process_handlers_num++; } -void sound_speed_changed(void) + +void +sound_poll(void *priv) { - sound_poll_latch = (int64_t)((double)TIMER_USEC * (1000000.0 / 48000.0)); -} + sound_poll_time += sound_poll_latch; -void sound_reset(void) -{ - int i = 0; + midi_poll(); - timer_add(sound_poll, &sound_poll_time, TIMER_ALWAYS_ENABLED, NULL); + sound_pos_global++; + if (sound_pos_global == SOUNDBUFLEN) { + int c; - sound_handlers_num = 0; - - sound_process_handlers_num = 0; + memset(outbuffer, 0, SOUNDBUFLEN * 2 * sizeof(int32_t)); - sound_set_cd_volume(65535, 65535); + for (c = 0; c < sound_handlers_num; c++) + sound_handlers[c].get_buffer(outbuffer, SOUNDBUFLEN, sound_handlers[c].priv); - for (i = 0; i < CDROM_NUM; i++) - { - if (cdrom_drives[i].handler->audio_stop) - { - cdrom_drives[i].handler->audio_stop(i); + for (c = 0; c < SOUNDBUFLEN * 2; c++) { + if (sound_is_float) { + outbuffer_ex[c] = (float)((outbuffer[c]) / 32768.0); + } else { + if (outbuffer[c] > 32767) + outbuffer[c] = 32767; + if (outbuffer[c] < -32768) + outbuffer[c] = -32768; + + outbuffer_ex_int16[c] = outbuffer[c]; } } -} - -void sound_cd_thread_end(void) -{ - if (cdaudioon) { - cdaudioon = 0; - - /* pclog("Waiting for CD Audio thread to terminate...\n"); */ - thread_set_event(sound_cd_event); - 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; - - if (sound_cd_start_event) { - thread_destroy_event(sound_cd_start_event); - sound_cd_event = NULL; - } + + if (soundon) { + if (sound_is_float) + givealbuffer(outbuffer_ex); + else + givealbuffer(outbuffer_ex_int16); } -} - -void sound_cd_thread_reset(void) -{ - int i = 0; - int available_cdrom_drives = 0; - - for (i = 0; i < CDROM_NUM; i++) - { - if (cdrom_drives[i].bus_type != CDROM_BUS_DISABLED) - { - available_cdrom_drives++; + + if (cd_thread_enable) { + cd_buf_update--; + if (! cd_buf_update) { + cd_buf_update = (48000 / SOUNDBUFLEN) / (CD_FREQ / CD_BUFLEN); + thread_set_event(sound_cd_event); } } - if (available_cdrom_drives && !cd_thread_enable) - { - cdaudioon = 1; + sound_pos_global = 0; + } +} - sound_cd_start_event = thread_create_event(); - sound_cd_event = thread_create_event(); - sound_cd_thread_h = thread_create(sound_cd_thread, NULL); +void +sound_speed_changed(void) +{ + sound_poll_latch = (int64_t)((double)TIMER_USEC * (1000000.0 / 48000.0)); +} - thread_wait_event(sound_cd_start_event, -1); - thread_reset_event(sound_cd_start_event); - } - else if (!available_cdrom_drives && cd_thread_enable) - { - sound_cd_thread_end(); - } - cd_thread_enable = available_cdrom_drives ? 1 : 0; +void +sound_reset(void) +{ + int i; + + timer_add(sound_poll, &sound_poll_time, TIMER_ALWAYS_ENABLED, NULL); + + sound_handlers_num = 0; + + sound_process_handlers_num = 0; + + sound_set_cd_volume(65535, 65535); + + for (i = 0; i < CDROM_NUM; i++) { + if (cdrom_drives[i].handler->audio_stop) + cdrom_drives[i].handler->audio_stop(i); + } +} + + +void +sound_cd_thread_end(void) +{ + if (! cdaudioon) return; + + cdaudioon = 0; + +#if 0 + pclog("Waiting for CD Audio thread to terminate...\n"); +#endif + thread_set_event(sound_cd_event); + thread_wait(sound_cd_thread_h, -1); +#if 0 + pclog("CD Audio thread terminated...\n"); +#endif + + if (sound_cd_event) { + thread_destroy_event(sound_cd_event); + sound_cd_event = NULL; + } + sound_cd_thread_h = NULL; + + if (sound_cd_start_event) { + thread_destroy_event(sound_cd_start_event); + sound_cd_event = NULL; + } +} + + +void +sound_cd_thread_reset(void) +{ + int drives = 0; + int i; + + for (i = 0; i < CDROM_NUM; i++) { + if (cdrom_drives[i].bus_type != CDROM_BUS_DISABLED) + drives++; + } + if (drives && !cd_thread_enable) { + cdaudioon = 1; + + sound_cd_start_event = thread_create_event(); + + sound_cd_event = thread_create_event(); + sound_cd_thread_h = thread_create(sound_cd_thread, NULL); + + thread_wait_event(sound_cd_start_event, -1); + thread_reset_event(sound_cd_start_event); + } else if (!drives && cd_thread_enable) { + sound_cd_thread_end(); + } + + cd_thread_enable = drives ? 1 : 0; } diff --git a/src/video/vid_colorplus.c b/src/video/vid_colorplus.c index 27746a6..8006ae5 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.2 2018/03/15 + * Version: @(#)vid_colorplus.c 1.0.3 2018/04/05 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -45,11 +45,11 @@ #include "../emu.h" #include "../cpu/cpu.h" #include "../io.h" -#include "../lpt.h" #include "../pit.h" #include "../mem.h" #include "../timer.h" #include "../device.h" +#include "../parallel.h" #include "video.h" #include "vid_cga.h" #include "vid_colorplus.h" @@ -426,7 +426,7 @@ void *colorplus_standalone_init(const device_t *info) mem_mapping_add(&colorplus->cga.mapping, 0xb8000, 0x08000, colorplus_read, NULL, NULL, colorplus_write, NULL, NULL, NULL, MEM_MAPPING_EXTERNAL, colorplus); io_sethandler(0x03d0, 0x0010, colorplus_in, NULL, NULL, colorplus_out, NULL, NULL, colorplus); - lpt3_init(0x3BC); + parallel_setup(3, 0x3BC); return colorplus; } diff --git a/src/video/vid_hercules.c b/src/video/vid_hercules.c index d94bf8a..b7c70af 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 2018/03/15 + * Version: @(#)vid_hercules.c 1.0.3 2018/04/05 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -42,13 +42,13 @@ #include #include #include "../emu.h" +#include "../io.h" +#include "../pit.h" #include "../mem.h" #include "../rom.h" -#include "../io.h" -#include "../lpt.h" -#include "../pit.h" #include "../timer.h" #include "../device.h" +#include "../parallel.h" #include "video.h" #include "vid_hercules.h" @@ -391,7 +391,7 @@ void *hercules_init(const device_t *info) } cgapal_rebuild(); - lpt3_init(0x3BC); + parallel_setup(3, 0x3BC); return hercules; } diff --git a/src/video/vid_herculesplus.c b/src/video/vid_herculesplus.c index 323d1a8..2f2edcc 100644 --- a/src/video/vid_herculesplus.c +++ b/src/video/vid_herculesplus.c @@ -8,7 +8,7 @@ * * Hercules InColor emulation. * - * Version: @(#)vid_hercules_plus.c 1.0.3 2018/03/15 + * Version: @(#)vid_hercules_plus.c 1.0.4 2018/04/05 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -43,12 +43,12 @@ #include #include "../emu.h" #include "../io.h" -#include "../lpt.h" #include "../pit.h" #include "../mem.h" #include "../rom.h" #include "../timer.h" #include "../device.h" +#include "../parallel.h" #include "video.h" #include "vid_herculesplus.h" @@ -729,7 +729,7 @@ void *herculesplus_init(const device_t *info) mdacols[0x80][0][1] = mdacols[0x80][1][1] = 16; mdacols[0x88][0][1] = mdacols[0x88][1][1] = 16; - lpt3_init(0x3BC); + parallel_setup(3, 0x3BC); return herculesplus; } diff --git a/src/video/vid_incolor.c b/src/video/vid_incolor.c index 84184bb..e0b1638 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.3 2018/03/15 + * Version: @(#)vid_incolor.c 1.0.4 2018/04/05 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -43,12 +43,12 @@ #include #include "../emu.h" #include "../io.h" -#include "../lpt.h" #include "../pit.h" #include "../mem.h" #include "../rom.h" #include "../timer.h" #include "../device.h" +#include "../parallel.h" #include "video.h" #include "vid_incolor.h" @@ -1073,7 +1073,7 @@ void *incolor_init(const device_t *info) } incolor->palette_idx = 0; - lpt3_init(0x3BC); + parallel_setup(3, 0x3BC); return incolor; } diff --git a/src/video/vid_mda.c b/src/video/vid_mda.c index 82364b4..a5bb061 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 2018/03/15 + * Version: @(#)vid_mda.c 1.0.3 2018/04/05 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -43,12 +43,12 @@ #include #include "../emu.h" #include "../io.h" -#include "../lpt.h" #include "../pit.h" #include "../mem.h" #include "../rom.h" #include "../timer.h" #include "../device.h" +#include "../parallel.h" #include "video.h" #include "vid_mda.h" @@ -340,7 +340,7 @@ void *mda_init(const device_t *info) } cgapal_rebuild(); - lpt3_init(0x3BC); + parallel_setup(3, 0x3BC); return mda; } diff --git a/src/win/VARCem.rc b/src/win/VARCem.rc index 2d29dac..64a9a50 100644 --- a/src/win/VARCem.rc +++ b/src/win/VARCem.rc @@ -8,7 +8,7 @@ * * Application resource script for Windows. * - * Version: @(#)VARCem.rc 1.0.12 2018/04/02 + * Version: @(#)VARCem.rc 1.0.14 2018/04/05 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -215,7 +215,7 @@ BEGIN END #endif MENUITEM "S&tatus", IDM_STATUS - MENUITEM "Take s&creenshot\tCtrl+Esc", IDM_ACTION_SCREENSHOT + MENUITEM "Take s&creenshot\tCtrl+Home", IDM_ACTION_SCREENSHOT MENUITEM SEPARATOR MENUITEM "&Update status bar icons", IDM_UPDATE_ICONS END @@ -519,25 +519,26 @@ DLG_CFG_PORTS DIALOG DISCARDABLE 97, 0, 267, 99 STYLE DS_CONTROL | WS_CHILD FONT 9, "Segoe UI" BEGIN - LTEXT "LPT1 Device:",IDT_1716,7,8,61,10 - COMBOBOX IDC_COMBO_LPT1,71,7,189,120,CBS_DROPDOWNLIST | + CONTROL "Parallel port 1",IDC_CHECK_PARALLEL1,"Button", + BS_AUTOCHECKBOX | WS_TABSTOP,7,8,70,10 + COMBOBOX IDC_COMBO_PARALLEL1,80,7,159,120,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP - LTEXT "LPT2 Device:",IDT_1717,7,27,61,10 - COMBOBOX IDC_COMBO_LPT2,71,26,189,120,CBS_DROPDOWNLIST | + CONTROL "Parallel port 2",IDC_CHECK_PARALLEL2,"Button", + BS_AUTOCHECKBOX | WS_TABSTOP,7,27,70,10 + COMBOBOX IDC_COMBO_PARALLEL2,80,26,159,120,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP - LTEXT "LPT3 Device:",IDT_1718,7,46,61,10 - COMBOBOX IDC_COMBO_LPT3,71,45,189,120,CBS_DROPDOWNLIST | + CONTROL "Parallel port 3",IDC_CHECK_PARALLEL3,"Button", + BS_AUTOCHECKBOX | WS_TABSTOP,7,46,70,10 + COMBOBOX IDC_COMBO_PARALLEL3,80,45,159,120,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP CONTROL "Serial port 1",IDC_CHECK_SERIAL1,"Button", - BS_AUTOCHECKBOX | WS_TABSTOP,7,64,94,10 - CONTROL "Serial port 2",IDC_CHECK_SERIAL2,"Button", - BS_AUTOCHECKBOX | WS_TABSTOP,147,64,94,10 + BS_AUTOCHECKBOX | WS_TABSTOP,7,69,94,10 - CONTROL "Parallel port",IDC_CHECK_PARALLEL,"Button", - BS_AUTOCHECKBOX | WS_TABSTOP,7,82,94,10 + CONTROL "Serial port 2",IDC_CHECK_SERIAL2,"Button", + BS_AUTOCHECKBOX | WS_TABSTOP,7,88,94,10 END DLG_CFG_PERIPHERALS DIALOG DISCARDABLE 97, 0, 267, 97 @@ -565,7 +566,7 @@ BEGIN BS_AUTOCHECKBOX | WS_TABSTOP,7,80,94,10 END -DLG_CFG_HARD_DISKS DIALOG DISCARDABLE 97, 0, 267, 154 +DLG_CFG_DISK DIALOG DISCARDABLE 97, 0, 267, 154 STYLE DS_CONTROL | WS_CHILD FONT 9, "Segoe UI" BEGIN @@ -592,7 +593,7 @@ BEGIN WS_VSCROLL | WS_TABSTOP END -DLG_CFG_HARD_DISKS_ADD DIALOG DISCARDABLE 0, 0, 219, 111 +DLG_CFG_DISK_ADD DIALOG DISCARDABLE 0, 0, 219, 111 STYLE DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU CAPTION "Add Hard Disk" FONT 9, "Segoe UI" @@ -632,7 +633,7 @@ BEGIN WS_BORDER,7,16,204,12 END -DLG_CFG_FLOPPY_DRIVES DIALOG DISCARDABLE 97, 0, 267, 103 +DLG_CFG_FLOPPY DIALOG DISCARDABLE 97, 0, 267, 103 STYLE DS_CONTROL | WS_CHILD FONT 9, "Segoe UI" BEGIN @@ -649,7 +650,7 @@ BEGIN BS_AUTOCHECKBOX | WS_TABSTOP,196,86,64,10 END -DLG_CFG_OTHER_REMOVABLE_DEVICES DIALOG DISCARDABLE 97, 0, 267, 221 +DLG_CFG_RMV_DEVICES DIALOG DISCARDABLE 97, 0, 267, 221 STYLE DS_CONTROL | WS_CHILD FONT 9, "Segoe UI" BEGIN @@ -698,7 +699,7 @@ END // 24 // #ifndef SKIP_MANIFEST -1 24 MOVEABLE PURE "VARCem.manifest" +1 24 MOVEABLE PURE "VARCem.manifest" #endif ///////////////////////////////////////////////////////////////////////////// // @@ -707,44 +708,44 @@ END // Icon with lowest ID value placed first to ensure application icon // remains consistent on all systems. -100 ICON DISCARDABLE "win/icons/varcem.ico" -128 ICON DISCARDABLE "win/icons/floppy_525.ico" -129 ICON DISCARDABLE "win/icons/floppy_525_active.ico" -144 ICON DISCARDABLE "win/icons/floppy_35.ico" -145 ICON DISCARDABLE "win/icons/floppy_35_active.ico" -160 ICON DISCARDABLE "win/icons/cdrom.ico" -161 ICON DISCARDABLE "win/icons/cdrom_active.ico" -176 ICON DISCARDABLE "win/icons/zip.ico" -177 ICON DISCARDABLE "win/icons/zip_active.ico" -192 ICON DISCARDABLE "win/icons/removable_disk.ico" -193 ICON DISCARDABLE "win/icons/removable_disk_active.ico" -208 ICON DISCARDABLE "win/icons/hard_disk.ico" -209 ICON DISCARDABLE "win/icons/hard_disk_active.ico" -224 ICON DISCARDABLE "win/icons/network.ico" -225 ICON DISCARDABLE "win/icons/network_active.ico" -256 ICON DISCARDABLE "win/icons/machine.ico" -257 ICON DISCARDABLE "win/icons/display.ico" -258 ICON DISCARDABLE "win/icons/input_devices.ico" -259 ICON DISCARDABLE "win/icons/sound.ico" -260 ICON DISCARDABLE "win/icons/network.ico" -261 ICON DISCARDABLE "win/icons/ports.ico" -262 ICON DISCARDABLE "win/icons/other_peripherals.ico" -263 ICON DISCARDABLE "win/icons/hard_disk.ico" -264 ICON DISCARDABLE "win/icons/floppy_drives.ico" -265 ICON DISCARDABLE "win/icons/other_removable_devices.ico" -384 ICON DISCARDABLE "win/icons/floppy_525_empty.ico" -385 ICON DISCARDABLE "win/icons/floppy_525_empty_active.ico" -400 ICON DISCARDABLE "win/icons/floppy_35_empty.ico" -401 ICON DISCARDABLE "win/icons/floppy_35_empty_active.ico" -416 ICON DISCARDABLE "win/icons/cdrom_empty.ico" -417 ICON DISCARDABLE "win/icons/cdrom_empty_active.ico" -432 ICON DISCARDABLE "win/icons/zip_empty.ico" -433 ICON DISCARDABLE "win/icons/zip_empty_active.ico" -448 ICON DISCARDABLE "win/icons/removable_disk_empty.ico" -449 ICON DISCARDABLE "win/icons/removable_disk_empty_active.ico" -512 ICON DISCARDABLE "win/icons/floppy_disabled.ico" -514 ICON DISCARDABLE "win/icons/cdrom_disabled.ico" -515 ICON DISCARDABLE "win/icons/zip_disabled.ico" +100 ICON DISCARDABLE "win/icons/varcem.ico" +128 ICON DISCARDABLE "win/icons/floppy_525.ico" +129 ICON DISCARDABLE "win/icons/floppy_525_active.ico" +144 ICON DISCARDABLE "win/icons/floppy_35.ico" +145 ICON DISCARDABLE "win/icons/floppy_35_active.ico" +160 ICON DISCARDABLE "win/icons/cdrom.ico" +161 ICON DISCARDABLE "win/icons/cdrom_active.ico" +176 ICON DISCARDABLE "win/icons/zip.ico" +177 ICON DISCARDABLE "win/icons/zip_active.ico" +192 ICON DISCARDABLE "win/icons/removable_disk.ico" +193 ICON DISCARDABLE "win/icons/removable_disk_active.ico" +208 ICON DISCARDABLE "win/icons/hard_disk.ico" +209 ICON DISCARDABLE "win/icons/hard_disk_active.ico" +224 ICON DISCARDABLE "win/icons/network.ico" +225 ICON DISCARDABLE "win/icons/network_active.ico" +256 ICON DISCARDABLE "win/icons/machine.ico" +257 ICON DISCARDABLE "win/icons/display.ico" +258 ICON DISCARDABLE "win/icons/input_devices.ico" +259 ICON DISCARDABLE "win/icons/sound.ico" +260 ICON DISCARDABLE "win/icons/network.ico" +261 ICON DISCARDABLE "win/icons/ports.ico" +262 ICON DISCARDABLE "win/icons/other_peripherals.ico" +263 ICON DISCARDABLE "win/icons/hard_disk.ico" +264 ICON DISCARDABLE "win/icons/floppy_drives.ico" +265 ICON DISCARDABLE "win/icons/other_removable_devices.ico" +384 ICON DISCARDABLE "win/icons/floppy_525_empty.ico" +385 ICON DISCARDABLE "win/icons/floppy_525_empty_active.ico" +400 ICON DISCARDABLE "win/icons/floppy_35_empty.ico" +401 ICON DISCARDABLE "win/icons/floppy_35_empty_active.ico" +416 ICON DISCARDABLE "win/icons/cdrom_empty.ico" +417 ICON DISCARDABLE "win/icons/cdrom_empty_active.ico" +432 ICON DISCARDABLE "win/icons/zip_empty.ico" +433 ICON DISCARDABLE "win/icons/zip_empty_active.ico" +448 ICON DISCARDABLE "win/icons/removable_disk_empty.ico" +449 ICON DISCARDABLE "win/icons/removable_disk_empty_active.ico" +512 ICON DISCARDABLE "win/icons/floppy_disabled.ico" +514 ICON DISCARDABLE "win/icons/cdrom_disabled.ico" +515 ICON DISCARDABLE "win/icons/zip_disabled.ico" #ifdef APSTUDIO_INVOKED ///////////////////////////////////////////////////////////////////////////// @@ -754,7 +755,7 @@ END 1 TEXTINCLUDE DISCARDABLE BEGIN - "resource.h\0" + "resource.h" END 2 TEXTINCLUDE DISCARDABLE @@ -763,13 +764,13 @@ BEGIN "#include ""windows.h""\r\n" "#undef APSTUDIO_HIDDEN_SYMBOLS\r\n" "#include ""resources.h""\r\n" - "\0" + "" END 3 TEXTINCLUDE DISCARDABLE BEGIN "\r\n" - "\0" + "" END #endif // APSTUDIO_INVOKED @@ -1023,14 +1024,7 @@ BEGIN IDS_2141 "Invalid PCap device" IDS_2142 "&Notify disk change" IDS_2143 "Type" - IDS_2144 "Disabled" - IDS_2145 "Standard 2-button joystick(s)" - IDS_2146 "Standard 4-button joystick" - IDS_2147 "Standard 6-button joystick" - IDS_2148 "Standard 8-button joystick" - IDS_2149 "CH Flightstick Pro" - IDS_2150 "Microsoft SideWinder Pad" - IDS_2151 "Thrustmaster Flight Control System" + /* IDS_2144-51 available */ IDS_2152 "None" IDS_2153 "Unable to load Keyboard Accelerators!" IDS_2154 "Unable to register Raw Input!" @@ -1039,7 +1033,7 @@ BEGIN IDS_2157 "%" PRIu64 " MB (CHS: %u, %u, %u)" IDS_2158 "Floppy %i (%s): %ls" IDS_2159 "All images (*.0??;*.1??;*.360;*.720;*.86F;*.BIN;*.CQ?;*.DSK;*.FLP;*.HDM;*.IM?;*.JSON;*.TD0;*.*FD?;*.XDF)\0*.0??;*.1??;*.360;*.720;*.86F;*.BIN;*.CQ?;*.DSK;*.FLP;*.HDM;*.IM?;*.JSON;*.TD0;*.*FD?;*.XDF\0Advanced sector images (*.IMD;*.JSON;*.TD0)\0*.IMD;*.JSON;*.TD0\0Basic sector images (*.0??;*.1??;*.360;*.720;*.BIN;*.CQ?;*.DSK;*.FLP;*.HDM;*.IM?;*.XDF;*.*FD?)\0*.0??;*.1??;*.360;*.720;*.BIN;*.CQ?;*.DSK;*.FLP;*.HDM;*.IM?;*.XDF;*.*FD?\0Flux images (*.FDI)\0*.FDI\0Surface images (*.86F)\0*.86F\0All files (*.*)\0*.*\0" - IDS_2160 "Configuration files (*.CFG)\0*.CFG\0All files (*.*)\0*.*\0" + IDS_2160 "Configuration files (*.VARC)\0*.VARC\0All files (*.*)\0*.*\0" IDS_2161 "&New image..." IDS_2162 "&Existing image..." IDS_2163 "Existing image (&Write-protected)..." diff --git a/src/win/mingw/Makefile.MinGW b/src/win/mingw/Makefile.MinGW index 9622da2..a275572 100644 --- a/src/win/mingw/Makefile.MinGW +++ b/src/win/mingw/Makefile.MinGW @@ -8,7 +8,7 @@ # # Makefile for Windows systems using the MinGW32 environment. # -# Version: @(#)Makefile.mingw 1.0.18 2018/03/31 +# Version: @(#)Makefile.mingw 1.0.19 2018/04/05 # # Author: Fred N. van Kempen, # @@ -509,7 +509,7 @@ MCHOBJ := machine.o machine_table.o \ m_at_430lx_nx.o m_at_430fx.o \ m_at_430hx.o m_at_430vx.o -DEVOBJ := bugger.o lpt.o $(SERIAL) \ +DEVOBJ := bugger.o parallel.o $(SERIAL) \ sio_fdc37c66x.o sio_fdc37c669.o sio_fdc37c93x.o \ sio_pc87306.o sio_w83877f.o sio_um8669f.o \ keyboard.o \ diff --git a/src/win/msvc/Makefile.VC b/src/win/msvc/Makefile.VC index 9248505..71d16c1 100644 --- a/src/win/msvc/Makefile.VC +++ b/src/win/msvc/Makefile.VC @@ -8,7 +8,7 @@ # # Makefile for Windows using Visual Studio 2015. # -# Version: @(#)Makefile.VC 1.0.3 2018/03/27 +# Version: @(#)Makefile.VC 1.0.4 2018/04/05 # # Author: Fred N. van Kempen, # @@ -440,9 +440,10 @@ CXXFLAGS := $(WX_FLAGS) $(OPTS) $(CXXOPTS) $(COPTS) $(DOPTS) $(AOPTIM) $(AFLAGS) # Create the (final) list of objects to build. # ######################################################################### MAINOBJ := pc.obj config.obj \ - random.obj timer.obj io.obj dma.obj nmi.obj pic.obj pit.obj ppi.obj \ - pci.obj mca.obj mcr.obj mem.obj memregs.obj rom.obj rom_load.obj \ - device.obj nvr.obj nvr_at.obj nvr_ps2.obj $(VNCOBJ) $(RDPOBJ) + random.obj timer.obj io.obj dma.obj nmi.obj pic.obj \ + pit.obj ppi.obj pci.obj mca.obj mcr.obj mem.obj \ + memregs.obj rom.obj rom_load.obj device.obj nvr.obj \ + nvr_at.obj nvr_ps2.obj $(VNCOBJ) $(RDPOBJ) INTELOBJ := intel.obj \ intel_flash.obj \ @@ -473,7 +474,7 @@ MCHOBJ := machine.obj machine_table.obj \ m_at_430lx_nx.obj m_at_430fx.obj \ m_at_430hx.obj m_at_430vx.obj -DEVOBJ := bugger.obj lpt.obj $(SERIAL) \ +DEVOBJ := bugger.obj parallel.obj $(SERIAL) \ sio_fdc37c66x.obj sio_fdc37c669.obj sio_fdc37c93x.obj \ sio_pc87306.obj sio_w83877f.obj sio_um8669f.obj \ keyboard.obj \ diff --git a/src/win/resource.h b/src/win/resource.h index 9bd009f..9b4b669 100644 --- a/src/win/resource.h +++ b/src/win/resource.h @@ -8,7 +8,7 @@ * * Windows resource defines. * - * Version: @(#)resource.h 1.0.8 2018/04/02 + * Version: @(#)resource.h 1.0.9 2018/04/05 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -53,10 +53,10 @@ #define DLG_CFG_NETWORK 115 /* sub-dialog of config */ #define DLG_CFG_PORTS 116 /* sub-dialog of config */ #define DLG_CFG_PERIPHERALS 117 /* sub-dialog of config */ -#define DLG_CFG_HARD_DISKS 118 /* sub-dialog of config */ -#define DLG_CFG_HARD_DISKS_ADD 119 /* sub-dialog of config */ -#define DLG_CFG_FLOPPY_DRIVES 120 /* sub-dialog of config */ -#define DLG_CFG_OTHER_REMOVABLE_DEVICES 121 /* sub-dialog of config */ +#define DLG_CFG_DISK 118 /* sub-dialog of config */ +#define DLG_CFG_DISK_ADD 119 /* sub-dialog of config */ +#define DLG_CFG_FLOPPY 120 /* sub-dialog of config */ +#define DLG_CFG_RMV_DEVICES 121 /* sub-dialog of config */ /* Static text label IDs. */ #define IDT_1700 1700 /* Language: */ @@ -168,12 +168,14 @@ #define IDC_COMBO_PCAP 1091 #define IDC_COMBO_NET 1092 -#define IDC_COMBO_LPT1 1110 /* ports config */ -#define IDC_COMBO_LPT2 1111 -#define IDC_COMBO_LPT3 1112 -#define IDC_CHECK_SERIAL1 1113 -#define IDC_CHECK_SERIAL2 1114 -#define IDC_CHECK_PARALLEL 1115 +#define IDC_CHECK_PARALLEL1 1110 /* ports config */ +#define IDC_CHECK_PARALLEL2 1111 +#define IDC_CHECK_PARALLEL3 1112 +#define IDC_COMBO_PARALLEL1 1113 +#define IDC_COMBO_PARALLEL2 1114 +#define IDC_COMBO_PARALLEL3 1115 +#define IDC_CHECK_SERIAL1 1116 +#define IDC_CHECK_SERIAL2 1117 #define IDC_OTHER_PERIPH 1120 /* other periph config */ #define IDC_COMBO_SCSI 1121 diff --git a/src/win/win_settings.c b/src/win/win_settings.c index 9ba530a..90ee805 100644 --- a/src/win/win_settings.c +++ b/src/win/win_settings.c @@ -8,7 +8,7 @@ * * Implementation of the Settings dialog. * - * Version: @(#)win_settings.c 1.0.17 2018/03/31 + * Version: @(#)win_settings.c 1.0.18 2018/04/05 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -53,8 +53,9 @@ #include "../nvr.h" #include "../machine/machine.h" #include "../game/gameport.h" -#include "../lpt.h" #include "../mouse.h" +#include "../parallel.h" +#include "../serial.h" #include "../disk/hdd.h" #include "../disk/hdc.h" #include "../disk/hdc_ide.h" @@ -75,7 +76,8 @@ /* Machine category */ -static int temp_machine, temp_cpu_m, temp_cpu, temp_wait_states, temp_mem_size, temp_fpu, temp_sync; +static int temp_machine, temp_cpu_m, temp_cpu, temp_wait_states, + temp_mem_size, temp_fpu, temp_sync; #ifdef USE_DYNAREC static int temp_dynarec; #endif @@ -87,22 +89,23 @@ static int temp_vid_card, temp_video_speed, temp_voodoo; static int temp_mouse, temp_joystick; /* Sound category */ -static int temp_sound_card, temp_midi_device, temp_mpu401, temp_SSI2001, temp_GAMEBLASTER, temp_GUS, temp_opl3_type; -static int temp_float; +static int temp_sound_card, temp_midi_device, temp_mpu401, temp_SSI2001, + temp_GAMEBLASTER, temp_GUS, temp_opl3_type, temp_float; /* Network category */ static int temp_net_type, temp_net_card; static char temp_host_dev[520]; /* Ports category */ -static char temp_lpt_device_names[3][16]; -static int temp_serial[2], temp_lpt; +static int temp_serial[SERIAL_MAX], temp_parallel[PARALLEL_MAX]; +static char temp_parallel_device[PARALLEL_MAX][16]; /* Other peripherals category */ -static int temp_scsi_card, temp_ide_ter, temp_ide_ter_irq, temp_ide_qua, temp_ide_qua_irq; -static char temp_hdc_name[16]; -static char *hdc_names[16]; -static int temp_bugger; +static int temp_hdc_type, + temp_scsi_card, + temp_ide_ter, temp_ide_ter_irq, + temp_ide_qua, temp_ide_qua_irq; +static int temp_bugger; static uint8_t temp_deviceconfig; @@ -130,8 +133,8 @@ static int settings_mouse_to_list[20], settings_list_to_mouse[20]; static int settings_scsi_to_list[20], settings_list_to_scsi[20]; static int settings_network_to_list[20], settings_list_to_network[20]; -static uint64_t mfm_tracking, esdi_tracking, xtide_tracking, ide_tracking, scsi_tracking[16]; - +static uint64_t mfm_tracking, esdi_tracking, xtide_tracking, + ide_tracking, scsi_tracking[16]; /* Show a MessageBox dialog. This is nasty, I know. --FvK */ @@ -196,15 +199,16 @@ settings_init(void) temp_net_card = network_card; /* Ports category */ - for (i = 0; i < 3; i++) - strncpy(temp_lpt_device_names[i], lpt_device_names[i], sizeof(temp_lpt_device_names[i]) - 1); - temp_serial[0] = serial_enabled[0]; - temp_serial[1] = serial_enabled[1]; - temp_lpt = lpt_enabled; + for (i = 0; i < SERIAL_MAX; i++) + temp_serial[i] = serial_enabled[i]; + for (i = 0; i < PARALLEL_MAX; i++) { + temp_parallel[i] = parallel_enabled[i]; + strcpy(temp_parallel_device[i], parallel_device[i]); + } /* Other peripherals category */ temp_scsi_card = scsi_card_current; - strncpy(temp_hdc_name, hdc_name, sizeof(temp_hdc_name) - 1); + temp_hdc_type = hdc_type; temp_ide_ter = ide_enable[2]; temp_ide_ter_irq = ide_irq[2]; temp_ide_qua = ide_enable[3]; @@ -270,8 +274,7 @@ settings_init(void) static int settings_changed(void) { - int i = 0; - int j = 0; + int i = 0, j; /* Machine category */ i = i || (machine != temp_machine); @@ -310,15 +313,16 @@ settings_changed(void) i = i || (network_card != temp_net_card); /* Ports category */ - for (j = 0; j < 3; j++) - i = i || strncmp(temp_lpt_device_names[j], lpt_device_names[j], sizeof(temp_lpt_device_names[j]) - 1); - i = i || (temp_serial[0] != serial_enabled[0]); - i = i || (temp_serial[1] != serial_enabled[1]); - i = i || (temp_lpt != lpt_enabled); + for (j = 0; j < SERIAL_MAX; j++) + i = i || (temp_serial[j] != serial_enabled[j]); + for (j = 0; j < PARALLEL_MAX; j++) { + i = i || strcmp(temp_parallel_device[j], parallel_device[j]); + i = i || (temp_parallel[j] != parallel_enabled[j]); + } /* Peripherals category */ - i = i || (scsi_card_current != temp_scsi_card); - i = i || strncmp(temp_hdc_name, hdc_name, sizeof(temp_hdc_name) - 1); + i = i || (temp_scsi_card != scsi_card_current); + i = i || (temp_hdc_type != hdc_type); i = i || (temp_ide_ter != ide_enable[2]); i = i || (temp_ide_ter_irq != ide_irq[2]); i = i || (temp_ide_qua != ide_enable[3]); @@ -348,8 +352,8 @@ settings_changed(void) static int msgbox_reset(void) { - int i = 0; int changed = 0; + int i = 0; changed = settings_changed(); @@ -371,7 +375,7 @@ msgbox_reset(void) static void settings_save(void) { - int i = 0; + int i; pc_reset_hard_close(); @@ -414,21 +418,16 @@ settings_save(void) network_card = temp_net_card; /* Ports category */ - for (i = 0; i < 3; i++) - strncpy(lpt_device_names[i], temp_lpt_device_names[i], sizeof(temp_lpt_device_names[i]) - 1); - serial_enabled[0] = temp_serial[0]; - serial_enabled[1] = temp_serial[1]; - lpt_enabled = temp_lpt; + for (i = 0; i < SERIAL_MAX; i++) + serial_enabled[i] = temp_serial[i]; + for (i = 0; i < PARALLEL_MAX; i++) { + parallel_enabled[i] = temp_parallel[i]; + strcpy(parallel_device[i], temp_parallel_device[i]); + } /* 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); + hdc_type = temp_hdc_type; ide_enable[2] = temp_ide_ter; ide_irq[2] = temp_ide_ter_irq; ide_enable[3] = temp_ide_qua; @@ -454,4786 +453,32 @@ settings_save(void) } -static void win_settings_machine_recalc_cpu(HWND hdlg) -{ - HWND h; - int temp_romset = 0; -#ifdef USE_DYNAREC - int cpu_flags; -#endif - int cpu_type; +#include "win_settings_machine.h" /* Machine dialog */ - temp_romset = machine_getromset_ex(temp_machine); +#include "win_settings_video.h" /* Video dialog */ - h = GetDlgItem(hdlg, IDC_COMBO_WS); - cpu_type = machines[romstomachine[temp_romset]].cpu[temp_cpu_m].cpus[temp_cpu].cpu_type; - if ((cpu_type >= CPU_286) && (cpu_type <= CPU_386DX)) - { - EnableWindow(h, TRUE); - } - else - { - EnableWindow(h, FALSE); - } +#include "win_settings_input.h" /* Input dialog */ -#ifdef USE_DYNAREC - h=GetDlgItem(hdlg, IDC_CHECK_DYNAREC); - cpu_flags = machines[romstomachine[temp_romset]].cpu[temp_cpu_m].cpus[temp_cpu].cpu_flags; - if (!(cpu_flags & CPU_SUPPORTS_DYNAREC) && (cpu_flags & CPU_REQUIRES_DYNAREC)) - { - fatal("Attempting to select a CPU that requires the recompiler and does not support it at the same time\n"); - } - if (!(cpu_flags & CPU_SUPPORTS_DYNAREC) || (cpu_flags & CPU_REQUIRES_DYNAREC)) - { - if (!(cpu_flags & CPU_SUPPORTS_DYNAREC)) - { - temp_dynarec = 0; - } - if (cpu_flags & CPU_REQUIRES_DYNAREC) - { - temp_dynarec = 1; - } - SendMessage(h, BM_SETCHECK, temp_dynarec, 0); - EnableWindow(h, FALSE); - } - else - { - EnableWindow(h, TRUE); - } -#endif +#include "win_settings_sound.h" /* Sound dialog */ - h = GetDlgItem(hdlg, IDC_CHECK_FPU); - cpu_type = machines[romstomachine[temp_romset]].cpu[temp_cpu_m].cpus[temp_cpu].cpu_type; - if ((cpu_type < CPU_i486DX) && (cpu_type >= CPU_286)) - { - EnableWindow(h, TRUE); - } - else if (cpu_type < CPU_286) - { - temp_fpu = 0; - EnableWindow(h, FALSE); - } - else - { - temp_fpu = 1; - EnableWindow(h, FALSE); - } - SendMessage(h, BM_SETCHECK, temp_fpu, 0); -} +#include "win_settings_ports.h" /* Ports dialog */ +#include "win_settings_periph.h" /* Other Peripherals dialog */ -static void win_settings_machine_recalc_cpu_m(HWND hdlg) -{ - HWND h; - int c = 0; - int temp_romset = 0; - LPTSTR lptsTemp; - char *stransi; +#include "win_settings_network.h" /* Network dialog */ - temp_romset = machine_getromset_ex(temp_machine); - lptsTemp = (LPTSTR) malloc(512); +#include "win_settings_floppy.h" /* Floppy dialog */ - h = GetDlgItem(hdlg, IDC_COMBO_CPU); - SendMessage(h, CB_RESETCONTENT, 0, 0); - c = 0; - while (machines[romstomachine[temp_romset]].cpu[temp_cpu_m].cpus[c].cpu_type != -1) - { - stransi = (char *)machines[romstomachine[temp_romset]].cpu[temp_cpu_m].cpus[c].name; - mbstowcs(lptsTemp, stransi, strlen(stransi) + 1); - SendMessage(h, CB_ADDSTRING, 0, (LPARAM)(LPCSTR)lptsTemp); - c++; - } - EnableWindow(h, TRUE); - if (temp_cpu >= c) - { - temp_cpu = (c - 1); - } - SendMessage(h, CB_SETCURSEL, temp_cpu, 0); +#include "win_settings_disk.h" /* (Hard) Disk dialog */ - win_settings_machine_recalc_cpu(hdlg); +#include "win_settings_remov.h" /* Removable Devices dialog */ - free(lptsTemp); -} - - -static void win_settings_machine_recalc_machine(HWND hdlg) -{ - HWND h; - int c = 0; - int temp_romset = 0; - LPTSTR lptsTemp; - const char *stransi; - UDACCEL accel; - - temp_romset = machine_getromset_ex(temp_machine); - lptsTemp = (LPTSTR) malloc(512); - - h = GetDlgItem(hdlg, IDC_CONFIGURE_MACHINE); - if (machine_getdevice(temp_machine)) - { - EnableWindow(h, TRUE); - } - else - { - EnableWindow(h, FALSE); - } - - h = GetDlgItem(hdlg, IDC_COMBO_CPU_TYPE); - SendMessage(h, CB_RESETCONTENT, 0, 0); - c = 0; - while (machines[romstomachine[temp_romset]].cpu[c].cpus != NULL && c < 4) - { - stransi = machines[romstomachine[temp_romset]].cpu[c].name; - mbstowcs(lptsTemp, stransi, strlen(stransi) + 1); - SendMessage(h, CB_ADDSTRING, 0, (LPARAM)(LPCSTR)lptsTemp); - c++; - } - EnableWindow(h, TRUE); - if (temp_cpu_m >= c) - { - temp_cpu_m = (c - 1); - } - SendMessage(h, CB_SETCURSEL, temp_cpu_m, 0); - if (c == 1) - { - EnableWindow(h, FALSE); - } - else - { - EnableWindow(h, TRUE); - } - - win_settings_machine_recalc_cpu_m(hdlg); - - h = GetDlgItem(hdlg, IDC_MEMSPIN); - SendMessage(h, UDM_SETRANGE, 0, (machines[romstomachine[temp_romset]].min_ram << 16) | machines[romstomachine[temp_romset]].max_ram); - accel.nSec = 0; - accel.nInc = machines[romstomachine[temp_romset]].ram_granularity; - SendMessage(h, UDM_SETACCEL, 1, (LPARAM)&accel); - if (!(machines[romstomachine[temp_romset]].flags & MACHINE_AT) || (machines[romstomachine[temp_romset]].ram_granularity >= 128)) - { - SendMessage(h, UDM_SETPOS, 0, temp_mem_size); - h = GetDlgItem(hdlg, IDC_TEXT_MB); - SendMessage(h, WM_SETTEXT, 0, (LPARAM) plat_get_string(IDS_2094)); - } - else - { - SendMessage(h, UDM_SETPOS, 0, temp_mem_size / 1024); - h = GetDlgItem(hdlg, IDC_TEXT_MB); - SendMessage(h, WM_SETTEXT, 0, (LPARAM) plat_get_string(IDS_2087)); - } - - free(lptsTemp); -} - - -#ifdef __amd64__ -static LRESULT CALLBACK -#else -static BOOL CALLBACK -#endif -machine_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) -{ - HWND h; - int c = 0; - int d = 0; - LPTSTR lptsTemp; - char *stransi; - - switch (message) - { - case WM_INITDIALOG: - lptsTemp = (LPTSTR) malloc(512); - - h = GetDlgItem(hdlg, IDC_COMBO_MACHINE); - for (c = 0; c < ROM_MAX; c++) - { - romstolist[c] = 0; - } - c = d = 0; - while (machines[c].id != -1) - { - if (romspresent[machines[c].id]) - { - stransi = (char *)machines[c].name; - mbstowcs(lptsTemp, stransi, strlen(stransi) + 1); - SendMessage(h, CB_ADDSTRING, 0, (LPARAM) lptsTemp); - machinetolist[c] = d; - listtomachine[d] = c; - romstolist[machines[c].id] = d; - romstomachine[machines[c].id] = c; - d++; - } - c++; - } - SendMessage(h, CB_SETCURSEL, machinetolist[temp_machine], 0); - - h = GetDlgItem(hdlg, IDC_COMBO_WS); - SendMessage(h, CB_ADDSTRING, 0, (LPARAM) plat_get_string(IDS_2131)); - - for (c = 0; c < 8; c++) - { - swprintf(lptsTemp, 511, plat_get_string(2132), c); - SendMessage(h, CB_ADDSTRING, 0, (LPARAM) lptsTemp); - } - - SendMessage(h, CB_SETCURSEL, temp_wait_states, 0); - -#ifdef USE_DYNAREC - h=GetDlgItem(hdlg, IDC_CHECK_DYNAREC); - SendMessage(h, BM_SETCHECK, temp_dynarec, 0); -#endif - - h = GetDlgItem(hdlg, IDC_MEMSPIN); - SendMessage(h, UDM_SETBUDDY, (WPARAM)GetDlgItem(hdlg, IDC_MEMTEXT), 0); - - h=GetDlgItem(hdlg, IDC_CHECK_SYNC); - SendMessage(h, BM_SETCHECK, temp_sync, 0); - - win_settings_machine_recalc_machine(hdlg); - - free(lptsTemp); - - return TRUE; - - case WM_COMMAND: - switch (LOWORD(wParam)) - { - case IDC_COMBO_MACHINE: - if (HIWORD(wParam) == CBN_SELCHANGE) - { - h = GetDlgItem(hdlg, IDC_COMBO_MACHINE); - temp_machine = listtomachine[SendMessage(h,CB_GETCURSEL,0,0)]; - - win_settings_machine_recalc_machine(hdlg); - } - break; - case IDC_COMBO_CPU_TYPE: - if (HIWORD(wParam) == CBN_SELCHANGE) - { - h = GetDlgItem(hdlg, IDC_COMBO_CPU_TYPE); - temp_cpu_m = SendMessage(h, CB_GETCURSEL, 0, 0); - - temp_cpu = 0; - win_settings_machine_recalc_cpu_m(hdlg); - } - break; - case IDC_COMBO_CPU: - if (HIWORD(wParam) == CBN_SELCHANGE) - { - h = GetDlgItem(hdlg, IDC_COMBO_CPU); - temp_cpu = SendMessage(h, CB_GETCURSEL, 0, 0); - - win_settings_machine_recalc_cpu(hdlg); - } - break; - case IDC_CONFIGURE_MACHINE: - h = GetDlgItem(hdlg, IDC_COMBO_MACHINE); - temp_machine = listtomachine[SendMessage(h, CB_GETCURSEL, 0, 0)]; - - temp_deviceconfig |= deviceconfig_open(hdlg, (void *)machine_getdevice(temp_machine)); - break; - } - - return FALSE; - - case WM_SAVESETTINGS: - lptsTemp = (LPTSTR) malloc(512); - stransi = (char *)malloc(512); - -#ifdef USE_DYNAREC - h=GetDlgItem(hdlg, IDC_CHECK_DYNAREC); - temp_dynarec = SendMessage(h, BM_GETCHECK, 0, 0); -#endif - - h=GetDlgItem(hdlg, IDC_CHECK_SYNC); - temp_sync = SendMessage(h, BM_GETCHECK, 0, 0); - - h=GetDlgItem(hdlg, IDC_CHECK_FPU); - temp_fpu = SendMessage(h, BM_GETCHECK, 0, 0); - - h = GetDlgItem(hdlg, IDC_COMBO_WS); - temp_wait_states = SendMessage(h, CB_GETCURSEL, 0, 0); - - h = GetDlgItem(hdlg, IDC_MEMTEXT); - SendMessage(h, WM_GETTEXT, 255, (LPARAM) lptsTemp); - wcstombs(stransi, lptsTemp, 512); - sscanf(stransi, "%i", &temp_mem_size); - temp_mem_size &= ~(machines[temp_machine].ram_granularity - 1); - if (temp_mem_size < machines[temp_machine].min_ram) - { - temp_mem_size = machines[temp_machine].min_ram; - } - else if (temp_mem_size > machines[temp_machine].max_ram) - { - temp_mem_size = machines[temp_machine].max_ram; - } - if ((machines[temp_machine].flags & MACHINE_AT) && (machines[temp_machine].ram_granularity < 128)) - { - temp_mem_size *= 1024; - } - if (machines[temp_machine].flags & MACHINE_VIDEO) - { - vid_card = VID_INTERNAL; - } - free(stransi); - free(lptsTemp); - - default: - return FALSE; - } - - return FALSE; -} - - -static void recalc_vid_list(HWND hdlg) -{ - HWND h = GetDlgItem(hdlg, IDC_COMBO_VIDEO); - int c = 0, d = 0; - int found_card = 0; - WCHAR szText[512]; - - SendMessage(h, CB_RESETCONTENT, 0, 0); - SendMessage(h, CB_SETCURSEL, 0, 0); - - while (1) - { - /* Skip "internal" if machine doesn't have it. */ - if (c==1 && !(machines[temp_machine].flags&MACHINE_VIDEO)) { - c++; - continue; - } - - char *s = video_card_getname(c); - - if (!s[0]) - break; - - if (video_card_available(c) && vid_present[video_new_to_old(c)] && - device_is_valid(video_card_getdevice(c), machines[temp_machine].flags)) - { - mbstowcs(szText, s, strlen(s) + 1); - SendMessage(h, CB_ADDSTRING, 0, (LPARAM) szText); - if (video_new_to_old(c) == temp_vid_card) - { - - SendMessage(h, CB_SETCURSEL, d, 0); - found_card = 1; - } - - d++; - } - - c++; - } - if (!found_card) - SendMessage(h, CB_SETCURSEL, 0, 0); - EnableWindow(h, machines[temp_machine].fixed_vidcard ? FALSE : TRUE); - - h = GetDlgItem(hdlg, IDC_CHECK_VOODOO); - EnableWindow(h, (machines[temp_machine].flags & MACHINE_PCI) ? TRUE : FALSE); - - h = GetDlgItem(hdlg, IDC_BUTTON_VOODOO); - EnableWindow(h, ((machines[temp_machine].flags & MACHINE_PCI) && temp_voodoo) ? TRUE : FALSE); -} - - -#ifdef __amd64__ -static LRESULT CALLBACK -#else -static BOOL CALLBACK -#endif -video_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) -{ - HWND h; - LPTSTR lptsTemp; - char *stransi; - int gfx = 0; - - switch (message) - { - case WM_INITDIALOG: - lptsTemp = (LPTSTR) malloc(512); - stransi = (char *) malloc(512); - - recalc_vid_list(hdlg); - - h = GetDlgItem(hdlg, IDC_COMBO_VIDEO_SPEED); - SendMessage(h, CB_ADDSTRING, 0, (LPARAM)plat_get_string(IDS_2131)); - SendMessage(h, CB_ADDSTRING, 0, (LPARAM)plat_get_string(IDS_2133)); - SendMessage(h, CB_ADDSTRING, 0, (LPARAM)plat_get_string(IDS_2134)); - SendMessage(h, CB_ADDSTRING, 0, (LPARAM)plat_get_string(IDS_2135)); - SendMessage(h, CB_ADDSTRING, 0, (LPARAM)plat_get_string(IDS_2136)); - SendMessage(h, CB_ADDSTRING, 0, (LPARAM)plat_get_string(IDS_2137)); - SendMessage(h, CB_ADDSTRING, 0, (LPARAM)plat_get_string(IDS_2138)); - SendMessage(h, CB_SETCURSEL, temp_video_speed + 1, 0); - - h=GetDlgItem(hdlg, IDC_CHECK_VOODOO); - SendMessage(h, BM_SETCHECK, temp_voodoo, 0); - - h = GetDlgItem(hdlg, IDC_COMBO_VIDEO); - SendMessage(h, CB_GETLBTEXT, SendMessage(h, CB_GETCURSEL, 0, 0), (LPARAM) lptsTemp); - wcstombs(stransi, lptsTemp, 512); - gfx = video_card_getid(stransi); - - h = GetDlgItem(hdlg, IDC_CONFIGURE_VID); - if (video_card_has_config(gfx)) - { - EnableWindow(h, TRUE); - } - else - { - EnableWindow(h, FALSE); - } - - free(stransi); - free(lptsTemp); - - return TRUE; - - case WM_COMMAND: - switch (LOWORD(wParam)) - { - case IDC_COMBO_VIDEO: - lptsTemp = (LPTSTR) malloc(512); - stransi = (char *) malloc(512); - - h = GetDlgItem(hdlg, IDC_COMBO_VIDEO); - SendMessage(h, CB_GETLBTEXT, SendMessage(h, CB_GETCURSEL, 0, 0), (LPARAM) lptsTemp); - wcstombs(stransi, lptsTemp, 512); - gfx = video_card_getid(stransi); - temp_vid_card = video_new_to_old(gfx); - - h = GetDlgItem(hdlg, IDC_CONFIGURE_VID); - if (video_card_has_config(gfx)) - { - EnableWindow(h, TRUE); - } - else - { - EnableWindow(h, FALSE); - } - - free(stransi); - free(lptsTemp); - break; - - case IDC_CHECK_VOODOO: - h = GetDlgItem(hdlg, IDC_CHECK_VOODOO); - temp_voodoo = SendMessage(h, BM_GETCHECK, 0, 0); - - h = GetDlgItem(hdlg, IDC_BUTTON_VOODOO); - EnableWindow(h, temp_voodoo ? TRUE : FALSE); - break; - - case IDC_BUTTON_VOODOO: - temp_deviceconfig |= deviceconfig_open(hdlg, (void *)&voodoo_device); - break; - - case IDC_CONFIGURE_VID: - lptsTemp = (LPTSTR) malloc(512); - stransi = (char *) malloc(512); - - h = GetDlgItem(hdlg, IDC_COMBO_VIDEO); - SendMessage(h, CB_GETLBTEXT, SendMessage(h, CB_GETCURSEL, 0, 0), (LPARAM) lptsTemp); - wcstombs(stransi, lptsTemp, 512); - temp_deviceconfig |= deviceconfig_open(hdlg, (void *)video_card_getdevice(video_card_getid(stransi))); - - free(stransi); - free(lptsTemp); - break; - } - return FALSE; - - case WM_SAVESETTINGS: - lptsTemp = (LPTSTR) malloc(512); - stransi = (char *) malloc(512); - - h = GetDlgItem(hdlg, IDC_COMBO_VIDEO); - SendMessage(h, CB_GETLBTEXT, SendMessage(h, CB_GETCURSEL, 0, 0), (LPARAM) lptsTemp); - wcstombs(stransi, lptsTemp, 512); - temp_vid_card = video_new_to_old(video_card_getid(stransi)); - - h = GetDlgItem(hdlg, IDC_COMBO_VIDEO_SPEED); - temp_video_speed = SendMessage(h, CB_GETCURSEL, 0, 0) - 1; - - h = GetDlgItem(hdlg, IDC_CHECK_VOODOO); - temp_voodoo = SendMessage(h, BM_GETCHECK, 0, 0); - - free(stransi); - free(lptsTemp); - - default: - return FALSE; - } - return FALSE; -} - - -static int mouse_valid(int num, int m) -{ - const device_t *dev; - - if ((num == MOUSE_TYPE_INTERNAL) && - !(machines[m].flags & MACHINE_MOUSE)) return(0); - - dev = mouse_get_device(num); - return(device_is_valid(dev, machines[m].flags)); -} - - -#ifdef __amd64__ -static LRESULT CALLBACK -#else -static BOOL CALLBACK -#endif -input_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) -{ - wchar_t str[128]; - HWND h; - int c = 0; - int d = 0; - - switch (message) - { - case WM_INITDIALOG: - h = GetDlgItem(hdlg, IDC_COMBO_MOUSE); - c = d = 0; - for (c = 0; c < mouse_get_ndev(); c++) - { - settings_mouse_to_list[c] = d; - - if (mouse_valid(c, temp_machine)) - { - mbstowcs(str, mouse_get_name(c), sizeof_w(str)); - SendMessage(h, CB_ADDSTRING, 0, (LPARAM)str); - - settings_list_to_mouse[d] = c; - d++; - } - } - - SendMessage(h, CB_SETCURSEL, settings_mouse_to_list[temp_mouse], 0); - - h = GetDlgItem(hdlg, IDC_CONFIGURE_MOUSE); - if (mouse_has_config(temp_mouse)) - { - EnableWindow(h, TRUE); - } - else - { - EnableWindow(h, FALSE); - } - - h = GetDlgItem(hdlg, IDC_COMBO_JOYSTICK); - c = 0; - while (joystick_get_name(c)) - { - SendMessage(h, CB_ADDSTRING, 0, (LPARAM)plat_get_string(2144 + c)); - c++; - } - EnableWindow(h, TRUE); - SendMessage(h, CB_SETCURSEL, temp_joystick, 0); - - h = GetDlgItem(hdlg, IDC_JOY1); - EnableWindow(h, (joystick_get_max_joysticks(temp_joystick) >= 1) ? TRUE : FALSE); - h = GetDlgItem(hdlg, IDC_JOY2); - EnableWindow(h, (joystick_get_max_joysticks(temp_joystick) >= 2) ? TRUE : FALSE); - h = GetDlgItem(hdlg, IDC_JOY3); - EnableWindow(h, (joystick_get_max_joysticks(temp_joystick) >= 3) ? TRUE : FALSE); - h = GetDlgItem(hdlg, IDC_JOY4); - EnableWindow(h, (joystick_get_max_joysticks(temp_joystick) >= 4) ? TRUE : FALSE); - - return TRUE; - - case WM_COMMAND: - switch (LOWORD(wParam)) - { - case IDC_COMBO_MOUSE: - h = GetDlgItem(hdlg, IDC_COMBO_MOUSE); - temp_mouse = settings_list_to_mouse[SendMessage(h, CB_GETCURSEL, 0, 0)]; - - h = GetDlgItem(hdlg, IDC_CONFIGURE_MOUSE); - if (mouse_has_config(temp_mouse)) - { - EnableWindow(h, TRUE); - } - else - { - EnableWindow(h, FALSE); - } - break; - - case IDC_CONFIGURE_MOUSE: - h = GetDlgItem(hdlg, IDC_COMBO_MOUSE); - temp_mouse = settings_list_to_mouse[SendMessage(h, CB_GETCURSEL, 0, 0)]; - temp_deviceconfig |= deviceconfig_open(hdlg, (void *)mouse_get_device(temp_mouse)); - break; - - case IDC_COMBO_JOYSTICK: - h = GetDlgItem(hdlg, IDC_COMBO_JOYSTICK); - temp_joystick = SendMessage(h, CB_GETCURSEL, 0, 0); - - h = GetDlgItem(hdlg, IDC_JOY1); - EnableWindow(h, (joystick_get_max_joysticks(temp_joystick) >= 1) ? TRUE : FALSE); - h = GetDlgItem(hdlg, IDC_JOY2); - EnableWindow(h, (joystick_get_max_joysticks(temp_joystick) >= 2) ? TRUE : FALSE); - h = GetDlgItem(hdlg, IDC_JOY3); - EnableWindow(h, (joystick_get_max_joysticks(temp_joystick) >= 3) ? TRUE : FALSE); - h = GetDlgItem(hdlg, IDC_JOY4); - EnableWindow(h, (joystick_get_max_joysticks(temp_joystick) >= 4) ? TRUE : FALSE); - break; - - case IDC_JOY1: - h = GetDlgItem(hdlg, IDC_COMBO_JOYSTICK); - temp_joystick = SendMessage(h, CB_GETCURSEL, 0, 0); - temp_deviceconfig |= joystickconfig_open(hdlg, 0, temp_joystick); - break; - - case IDC_JOY2: - h = GetDlgItem(hdlg, IDC_COMBO_JOYSTICK); - temp_joystick = SendMessage(h, CB_GETCURSEL, 0, 0); - temp_deviceconfig |= joystickconfig_open(hdlg, 1, temp_joystick); - break; - - case IDC_JOY3: - h = GetDlgItem(hdlg, IDC_COMBO_JOYSTICK); - temp_joystick = SendMessage(h, CB_GETCURSEL, 0, 0); - temp_deviceconfig |= joystickconfig_open(hdlg, 2, temp_joystick); - break; - - case IDC_JOY4: - h = GetDlgItem(hdlg, IDC_COMBO_JOYSTICK); - temp_joystick = SendMessage(h, CB_GETCURSEL, 0, 0); - temp_deviceconfig |= joystickconfig_open(hdlg, 3, temp_joystick); - break; - } - return FALSE; - - case WM_SAVESETTINGS: - h = GetDlgItem(hdlg, IDC_COMBO_MOUSE); - temp_mouse = settings_list_to_mouse[SendMessage(h, CB_GETCURSEL, 0, 0)]; - - h = GetDlgItem(hdlg, IDC_COMBO_JOYSTICK); - temp_joystick = SendMessage(h, CB_GETCURSEL, 0, 0); - - default: - return FALSE; - } - return FALSE; -} - - -int mpu401_present(void) -{ - char *n; - - n = sound_card_get_internal_name(temp_sound_card); - if (n != NULL) - { - if (!strcmp(n, "sb16") || !strcmp(n, "sbawe32")) - { - return 1; - } - } - - return temp_mpu401 ? 1 : 0; -} - -int mpu401_standalone_allow(void) -{ - char *n, *md; - - n = sound_card_get_internal_name(temp_sound_card); - md = midi_device_get_internal_name(temp_midi_device); - if (n != NULL) - { - if (!strcmp(n, "sb16") || !strcmp(n, "sbawe32")) - { - return 0; - } - } - - if (md != NULL) - { - if (!strcmp(md, "none")) - { - return 0; - } - } - - return 1; -} - -#ifdef __amd64__ -static LRESULT CALLBACK -#else -static BOOL CALLBACK -#endif -sound_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) -{ - HWND h; - int c = 0; - int d = 0; - LPTSTR lptsTemp; - const device_t *sound_dev; - char *s; - - switch (message) - { - case WM_INITDIALOG: - lptsTemp = (LPTSTR) malloc(512); - - h = GetDlgItem(hdlg, IDC_COMBO_SOUND); - c = d = 0; - while (1) - { - s = sound_card_getname(c); - - if (!s[0]) - { - break; - } - - settings_sound_to_list[c] = d; - - if (sound_card_available(c)) - { - sound_dev = sound_card_getdevice(c); - - if (device_is_valid(sound_dev, machines[temp_machine].flags)) - { - if (c == 0) - { - SendMessage(h, CB_ADDSTRING, 0, (LPARAM) plat_get_string(IDS_2152)); - } - else - { - mbstowcs(lptsTemp, s, strlen(s) + 1); - SendMessage(h, CB_ADDSTRING, 0, (LPARAM) lptsTemp); - } - settings_list_to_sound[d] = c; - d++; - } - } - - c++; - } - SendMessage(h, CB_SETCURSEL, settings_sound_to_list[temp_sound_card], 0); - - EnableWindow(h, d ? TRUE : FALSE); - - h = GetDlgItem(hdlg, IDC_CONFIGURE_SND); - if (sound_card_has_config(temp_sound_card)) - { - EnableWindow(h, TRUE); - } - else - { - EnableWindow(h, FALSE); - } - - h = GetDlgItem(hdlg, IDC_COMBO_MIDI); - c = d = 0; - while (1) - { - s = midi_device_getname(c); - - if (!s[0]) - { - break; - } - - settings_midi_to_list[c] = d; - - if (midi_device_available(c)) - { - /* midi_dev = midi_device_getdevice(c); */ - - if (c == 0) - { - SendMessage(h, CB_ADDSTRING, 0, (LPARAM)plat_get_string(IDS_2152)); - } - else - { - mbstowcs(lptsTemp, s, strlen(s) + 1); - SendMessage(h, CB_ADDSTRING, 0, (LPARAM) lptsTemp); - } - settings_list_to_midi[d] = c; - d++; - } - - c++; - } - SendMessage(h, CB_SETCURSEL, settings_midi_to_list[temp_midi_device], 0); - - h = GetDlgItem(hdlg, IDC_CONFIGURE_MIDI); - if (midi_device_has_config(temp_midi_device)) - { - EnableWindow(h, TRUE); - } - else - { - EnableWindow(h, FALSE); - } - - h = GetDlgItem(hdlg, IDC_CHECK_MPU401); - SendMessage(h, BM_SETCHECK, temp_mpu401, 0); - EnableWindow(h, mpu401_standalone_allow() ? TRUE : FALSE); - - h = GetDlgItem(hdlg, IDC_CONFIGURE_MPU401); - EnableWindow(h, (mpu401_standalone_allow() && temp_mpu401) ? TRUE : FALSE); - - h=GetDlgItem(hdlg, IDC_CHECK_CMS); - SendMessage(h, BM_SETCHECK, temp_GAMEBLASTER, 0); - - h=GetDlgItem(hdlg, IDC_CHECK_GUS); - SendMessage(h, BM_SETCHECK, temp_GUS, 0); - - h=GetDlgItem(hdlg, IDC_CHECK_SSI); - SendMessage(h, BM_SETCHECK, temp_SSI2001, 0); - - h=GetDlgItem(hdlg, IDC_CHECK_NUKEDOPL); - SendMessage(h, BM_SETCHECK, temp_opl3_type, 0); - - h=GetDlgItem(hdlg, IDC_CHECK_FLOAT); - SendMessage(h, BM_SETCHECK, temp_float, 0); - - free(lptsTemp); - - return TRUE; - - case WM_COMMAND: - switch (LOWORD(wParam)) - { - case IDC_COMBO_SOUND: - h = GetDlgItem(hdlg, IDC_COMBO_SOUND); - temp_sound_card = settings_list_to_sound[SendMessage(h, CB_GETCURSEL, 0, 0)]; - - h = GetDlgItem(hdlg, IDC_CONFIGURE_SND); - if (sound_card_has_config(temp_sound_card)) - { - EnableWindow(h, TRUE); - } - else - { - EnableWindow(h, FALSE); - } - - h = GetDlgItem(hdlg, IDC_CHECK_MPU401); - SendMessage(h, BM_SETCHECK, temp_mpu401, 0); - EnableWindow(h, mpu401_standalone_allow() ? TRUE : FALSE); - - h = GetDlgItem(hdlg, IDC_CONFIGURE_MPU401); - EnableWindow(h, (mpu401_standalone_allow() && temp_mpu401) ? TRUE : FALSE); - break; - - case IDC_CONFIGURE_SND: - h = GetDlgItem(hdlg, IDC_COMBO_SOUND); - temp_sound_card = settings_list_to_sound[SendMessage(h, CB_GETCURSEL, 0, 0)]; - - temp_deviceconfig |= deviceconfig_open(hdlg, (void *)sound_card_getdevice(temp_sound_card)); - break; - - case IDC_COMBO_MIDI: - h = GetDlgItem(hdlg, IDC_COMBO_MIDI); - temp_midi_device = settings_list_to_midi[SendMessage(h, CB_GETCURSEL, 0, 0)]; - - h = GetDlgItem(hdlg, IDC_CONFIGURE_MIDI); - if (midi_device_has_config(temp_midi_device)) - { - EnableWindow(h, TRUE); - } - else - { - EnableWindow(h, FALSE); - } - - h = GetDlgItem(hdlg, IDC_CHECK_MPU401); - SendMessage(h, BM_SETCHECK, temp_mpu401, 0); - EnableWindow(h, mpu401_standalone_allow() ? TRUE : FALSE); - - h = GetDlgItem(hdlg, IDC_CONFIGURE_MPU401); - EnableWindow(h, (mpu401_standalone_allow() && temp_mpu401) ? TRUE : FALSE); - break; - - case IDC_CONFIGURE_MIDI: - h = GetDlgItem(hdlg, IDC_COMBO_MIDI); - temp_midi_device = settings_list_to_midi[SendMessage(h, CB_GETCURSEL, 0, 0)]; - - temp_deviceconfig |= deviceconfig_open(hdlg, (void *)midi_device_getdevice(temp_midi_device)); - break; - - case IDC_CHECK_MPU401: - h = GetDlgItem(hdlg, IDC_CHECK_MPU401); - temp_mpu401 = SendMessage(h, BM_GETCHECK, 0, 0); - - h = GetDlgItem(hdlg, IDC_CONFIGURE_MPU401); - EnableWindow(h, mpu401_present() ? TRUE : FALSE); - break; - - case IDC_CONFIGURE_MPU401: - temp_deviceconfig |= deviceconfig_open(hdlg, (void *)&mpu401_device); - break; - } - return FALSE; - - case WM_SAVESETTINGS: - h = GetDlgItem(hdlg, IDC_COMBO_SOUND); - temp_sound_card = settings_list_to_sound[SendMessage(h, CB_GETCURSEL, 0, 0)]; - - h = GetDlgItem(hdlg, IDC_COMBO_MIDI); - temp_midi_device = settings_list_to_midi[SendMessage(h, CB_GETCURSEL, 0, 0)]; - - h = GetDlgItem(hdlg, IDC_CHECK_MPU401); - temp_mpu401 = SendMessage(h, BM_GETCHECK, 0, 0); - - h = GetDlgItem(hdlg, IDC_CHECK_CMS); - temp_GAMEBLASTER = SendMessage(h, BM_GETCHECK, 0, 0); - - h = GetDlgItem(hdlg, IDC_CHECK_GUS); - temp_GUS = SendMessage(h, BM_GETCHECK, 0, 0); - - h = GetDlgItem(hdlg, IDC_CHECK_SSI); - temp_SSI2001 = SendMessage(h, BM_GETCHECK, 0, 0); - - h = GetDlgItem(hdlg, IDC_CHECK_NUKEDOPL); - temp_opl3_type = SendMessage(h, BM_GETCHECK, 0, 0); - - h = GetDlgItem(hdlg, IDC_CHECK_FLOAT); - temp_float = SendMessage(h, BM_GETCHECK, 0, 0); - - default: - return FALSE; - } - return FALSE; -} - - -#ifdef __amd64__ -static LRESULT CALLBACK -#else -static BOOL CALLBACK -#endif -ports_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) -{ - HWND h; - int c = 0; - int d = 0; - const char *s; - LPTSTR lptsTemp; - int i; - - switch (message) - { - case WM_INITDIALOG: - lptsTemp = (LPTSTR) malloc(512); - - for (i = 0; i < 3; i++) { - h = GetDlgItem(hdlg, IDC_COMBO_LPT1 + i); - c = d = 0; - while (1) { - s = lpt_device_get_name(c); - - if (!s) - break; - - if (c == 0) { - SendMessage(h, CB_ADDSTRING, 0, (LPARAM) plat_get_string(IDS_2152)); - } else { - mbstowcs(lptsTemp, s, strlen(s) + 1); - SendMessage(h, CB_ADDSTRING, 0, (LPARAM) lptsTemp); - } - - if (!strcmp(temp_lpt_device_names[i], lpt_device_get_internal_name(c))) - d = c; - - c++; - } - SendMessage(h, CB_SETCURSEL, d, 0); - } - - h=GetDlgItem(hdlg, IDC_CHECK_SERIAL1); - SendMessage(h, BM_SETCHECK, temp_serial[0], 0); - - h=GetDlgItem(hdlg, IDC_CHECK_SERIAL2); - SendMessage(h, BM_SETCHECK, temp_serial[1], 0); - - h=GetDlgItem(hdlg, IDC_CHECK_PARALLEL); - SendMessage(h, BM_SETCHECK, temp_lpt, 0); - - free(lptsTemp); - - return TRUE; - - case WM_SAVESETTINGS: - for (i = 0; i < 3; i++) { - h = GetDlgItem(hdlg, IDC_COMBO_LPT1 + i); - c = SendMessage(h, CB_GETCURSEL, 0, 0); - strcpy(temp_lpt_device_names[i], lpt_device_get_internal_name(c)); - } - - h = GetDlgItem(hdlg, IDC_CHECK_SERIAL1); - temp_serial[0] = SendMessage(h, BM_GETCHECK, 0, 0); - - h = GetDlgItem(hdlg, IDC_CHECK_SERIAL2); - temp_serial[1] = SendMessage(h, BM_GETCHECK, 0, 0); - - h = GetDlgItem(hdlg, IDC_CHECK_PARALLEL); - temp_lpt = SendMessage(h, BM_GETCHECK, 0, 0); - - default: - return FALSE; - } - return FALSE; -} - - -static void recalc_hdc_list(HWND hdlg, int machine, int use_selected_hdc) -{ - HWND h; - - char *s; - int valid = 0; - char old_name[16]; - int c, d; - - LPTSTR lptsTemp; - - lptsTemp = (LPTSTR) malloc(512); - - h = GetDlgItem(hdlg, IDC_COMBO_HDC); - - valid = 0; - - if (use_selected_hdc) - { - c = SendMessage(h, CB_GETCURSEL, 0, 0); - - if (c != -1 && hdc_names[c]) - { - strncpy(old_name, hdc_names[c], sizeof(old_name) - 1); - } - else - { - strcpy(old_name, "none"); - } - } - else - { - strncpy(old_name, temp_hdc_name, sizeof(old_name) - 1); - } - - SendMessage(h, CB_RESETCONTENT, 0, 0); - c = d = 0; - while (1) - { - s = hdc_get_name(c); - if (s[0] == 0) - { - break; - } - if (c==1 && !(machines[temp_machine].flags&MACHINE_HDC)) - { - /* Skip "Internal" if machine doesn't have one. */ - c++; - continue; - } - if (!hdc_available(c) || !device_is_valid(hdc_get_device(c), machines[temp_machine].flags)) - { - c++; - continue; - } - mbstowcs(lptsTemp, s, strlen(s) + 1); - SendMessage(h, CB_ADDSTRING, 0, (LPARAM) lptsTemp); - - hdc_names[d] = hdc_get_internal_name(c); - if (!strcmp(old_name, hdc_names[d])) - { - SendMessage(h, CB_SETCURSEL, d, 0); - valid = 1; - } - c++; - d++; - } - - if (!valid) - { - SendMessage(h, CB_SETCURSEL, 0, 0); - } - - EnableWindow(h, d ? TRUE : FALSE); - - free(lptsTemp); -} - - -int valid_ide_irqs[11] = { 2, 3, 4, 5, 7, 9, 10, 11, 12, 14, 15 }; - - -int find_irq_in_array(int irq, int def) -{ - int i = 0; - - for (i = 0; i < 11; i++) - { - if (valid_ide_irqs[i] == irq) - { - return i + 1; - } - } - - return 7 + def; -} - - -#ifdef __amd64__ -static LRESULT CALLBACK -#else -static BOOL CALLBACK -#endif -peripherals_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) -{ - HWND h; - int c = 0; - int d = 0; - LPTSTR lptsTemp; - const device_t *scsi_dev; - - switch (message) - { - case WM_INITDIALOG: - lptsTemp = (LPTSTR) malloc(512); - - /*SCSI config*/ - h = GetDlgItem(hdlg, IDC_COMBO_SCSI); - c = d = 0; - while (1) - { - char *s = scsi_card_getname(c); - - if (!s[0]) - { - break; - } - - settings_scsi_to_list[c] = d; - - if (scsi_card_available(c)) - { - scsi_dev = scsi_card_getdevice(c); - - - if (device_is_valid(scsi_dev, machines[temp_machine].flags)) - { - if (c == 0) - { - SendMessage(h, CB_ADDSTRING, 0, (LPARAM) plat_get_string(IDS_2152)); - } - else - { - mbstowcs(lptsTemp, s, strlen(s) + 1); - SendMessage(h, CB_ADDSTRING, 0, (LPARAM) lptsTemp); - } - settings_list_to_scsi[d] = c; - d++; - } - } - - c++; - } - SendMessage(h, CB_SETCURSEL, settings_scsi_to_list[temp_scsi_card], 0); - - EnableWindow(h, d ? TRUE : FALSE); - - h = GetDlgItem(hdlg, IDC_CONFIGURE_SCSI); - if (scsi_card_has_config(temp_scsi_card)) - { - EnableWindow(h, TRUE); - } - else - { - EnableWindow(h, FALSE); - } - - recalc_hdc_list(hdlg, temp_machine, 0); - - h=GetDlgItem(hdlg, IDC_COMBO_IDE_TER); - SendMessage(h, CB_ADDSTRING, 0, (LPARAM)plat_get_string(IDS_5376)); - - for (c = 0; c < 11; c++) - { - swprintf(lptsTemp, 511, plat_get_string(IDS_2155), valid_ide_irqs[c]); - SendMessage(h, CB_ADDSTRING, 0, (LPARAM) lptsTemp); - } - - if (temp_ide_ter) - { - SendMessage(h, CB_SETCURSEL, find_irq_in_array(temp_ide_ter_irq, 0), 0); - } - else - { - SendMessage(h, CB_SETCURSEL, 0, 0); - } - - h=GetDlgItem(hdlg, IDC_COMBO_IDE_QUA); - SendMessage(h, CB_ADDSTRING, 0, (LPARAM)plat_get_string(IDS_5376)); - - for (c = 0; c < 11; c++) - { - swprintf(lptsTemp, 511, plat_get_string(IDS_2155), valid_ide_irqs[c]); - SendMessage(h, CB_ADDSTRING, 0, (LPARAM) lptsTemp); - } - - if (temp_ide_qua) - { - SendMessage(h, CB_SETCURSEL, find_irq_in_array(temp_ide_qua_irq, 1), 0); - } - else - { - SendMessage(h, CB_SETCURSEL, 0, 0); - } - - h=GetDlgItem(hdlg, IDC_CHECK_BUGGER); - SendMessage(h, BM_SETCHECK, temp_bugger, 0); - - free(lptsTemp); - - return TRUE; - - case WM_COMMAND: - switch (LOWORD(wParam)) - { - case IDC_CONFIGURE_SCSI: - h = GetDlgItem(hdlg, IDC_COMBO_SCSI); - temp_scsi_card = settings_list_to_scsi[SendMessage(h, CB_GETCURSEL, 0, 0)]; - - temp_deviceconfig |= deviceconfig_open(hdlg, (void *)scsi_card_getdevice(temp_scsi_card)); - break; - - case IDC_COMBO_SCSI: - h = GetDlgItem(hdlg, IDC_COMBO_SCSI); - temp_scsi_card = settings_list_to_scsi[SendMessage(h, CB_GETCURSEL, 0, 0)]; - - h = GetDlgItem(hdlg, IDC_CONFIGURE_SCSI); - if (scsi_card_has_config(temp_scsi_card)) - { - EnableWindow(h, TRUE); - } - else - { - EnableWindow(h, FALSE); - } - break; - } - return FALSE; - - case WM_SAVESETTINGS: - h = GetDlgItem(hdlg, IDC_COMBO_HDC); - c = SendMessage(h, CB_GETCURSEL, 0, 0); - if (hdc_names[c]) - { - strncpy(temp_hdc_name, hdc_names[c], sizeof(temp_hdc_name) - 1); - } - else - { - strcpy(temp_hdc_name, "none"); - } - - h = GetDlgItem(hdlg, IDC_COMBO_SCSI); - temp_scsi_card = settings_list_to_scsi[SendMessage(h, CB_GETCURSEL, 0, 0)]; - - h = GetDlgItem(hdlg, IDC_COMBO_IDE_TER); - temp_ide_ter = SendMessage(h, CB_GETCURSEL, 0, 0); - if (temp_ide_ter > 1) - { - temp_ide_ter_irq = valid_ide_irqs[temp_ide_ter - 1]; - temp_ide_ter = 1; - } - - h = GetDlgItem(hdlg, IDC_COMBO_IDE_QUA); - temp_ide_qua = SendMessage(h, CB_GETCURSEL, 0, 0); - if (temp_ide_qua > 1) - { - temp_ide_qua_irq = valid_ide_irqs[temp_ide_qua - 1]; - temp_ide_qua = 1; - } - - h = GetDlgItem(hdlg, IDC_CHECK_BUGGER); - temp_bugger = SendMessage(h, BM_GETCHECK, 0, 0); - - default: - return FALSE; - } - return FALSE; -} - - -int net_ignore_message = 0; - -static void network_recalc_combos(HWND hdlg) -{ - HWND h; - - net_ignore_message = 1; - - h = GetDlgItem(hdlg, IDC_COMBO_PCAP); - if (temp_net_type == NET_TYPE_PCAP) - { - EnableWindow(h, TRUE); - } - else - { - EnableWindow(h, FALSE); - } - - h = GetDlgItem(hdlg, IDC_COMBO_NET); - if (temp_net_type == NET_TYPE_SLIRP) - { - EnableWindow(h, TRUE); - } - else if ((temp_net_type == NET_TYPE_PCAP) && - (network_dev_to_id(temp_host_dev) > 0)) - { - EnableWindow(h, TRUE); - } - else - { - EnableWindow(h, FALSE); - } - - h = GetDlgItem(hdlg, IDC_CONFIGURE_NET); - if (network_card_has_config(temp_net_card) && - (temp_net_type == NET_TYPE_SLIRP)) - { - EnableWindow(h, TRUE); - } - else if (network_card_has_config(temp_net_card) && - (temp_net_type == NET_TYPE_PCAP) && - (network_dev_to_id(temp_host_dev) > 0)) - { - EnableWindow(h, TRUE); - } - else - { - EnableWindow(h, FALSE); - } - - net_ignore_message = 0; -} - -#ifdef __amd64__ -static LRESULT CALLBACK -#else -static BOOL CALLBACK -#endif -network_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) -{ - HWND h; - int c = 0; - int d = 0; - LPTSTR lptsTemp; - - switch (message) - { - case WM_INITDIALOG: - lptsTemp = (LPTSTR) malloc(512); - - h = GetDlgItem(hdlg, IDC_COMBO_NET_TYPE); - SendMessage(h, CB_ADDSTRING, 0, (LPARAM) L"None"); - SendMessage(h, CB_ADDSTRING, 0, (LPARAM) L"PCap"); - SendMessage(h, CB_ADDSTRING, 0, (LPARAM) L"SLiRP"); - SendMessage(h, CB_SETCURSEL, temp_net_type, 0); - - h = GetDlgItem(hdlg, IDC_COMBO_PCAP); - if (temp_net_type == NET_TYPE_PCAP) - { - EnableWindow(h, TRUE); - } - else - { - EnableWindow(h, FALSE); - } - - h = GetDlgItem(hdlg, IDC_COMBO_PCAP); - for (c = 0; c < network_ndev; c++) - { - mbstowcs(lptsTemp, network_devs[c].description, strlen(network_devs[c].description) + 1); - SendMessage(h, CB_ADDSTRING, 0, (LPARAM) lptsTemp); - } - SendMessage(h, CB_SETCURSEL, network_dev_to_id(temp_host_dev), 0); - - /*NIC config*/ - h = GetDlgItem(hdlg, IDC_COMBO_NET); - c = d = 0; - while (1) - { - char *s = network_card_getname(c); - - if (s[0] == '\0') - { - break; - } - - settings_network_to_list[c] = d; - - if (network_card_available(c) && device_is_valid(network_card_getdevice(c), machines[temp_machine].flags)) - { - if (c == 0) - { - SendMessage(h, CB_ADDSTRING, 0, (LPARAM) plat_get_string(2152)); - } - else - { - mbstowcs(lptsTemp, s, strlen(s) + 1); - SendMessage(h, CB_ADDSTRING, 0, (LPARAM) lptsTemp); - } - settings_list_to_network[d] = c; - d++; - } - - c++; - } - SendMessage(h, CB_SETCURSEL, settings_network_to_list[temp_net_card], 0); - - EnableWindow(h, d ? TRUE : FALSE); - - network_recalc_combos(hdlg); - - free(lptsTemp); - - return TRUE; - - case WM_COMMAND: - switch (LOWORD(wParam)) - { - case IDC_COMBO_NET_TYPE: - if (net_ignore_message) - { - return FALSE; - } - - h = GetDlgItem(hdlg, IDC_COMBO_NET_TYPE); - temp_net_type = SendMessage(h, CB_GETCURSEL, 0, 0); - - network_recalc_combos(hdlg); - break; - - case IDC_COMBO_PCAP: - if (net_ignore_message) - { - return FALSE; - } - - h = GetDlgItem(hdlg, IDC_COMBO_PCAP); - memset(temp_host_dev, '\0', sizeof(temp_host_dev)); - strcpy(temp_host_dev, network_devs[SendMessage(h, CB_GETCURSEL, 0, 0)].device); - - network_recalc_combos(hdlg); - break; - - case IDC_COMBO_NET: - if (net_ignore_message) - { - return FALSE; - } - - h = GetDlgItem(hdlg, IDC_COMBO_NET); - temp_net_card = settings_list_to_network[SendMessage(h, CB_GETCURSEL, 0, 0)]; - - network_recalc_combos(hdlg); - break; - - case IDC_CONFIGURE_NET: - if (net_ignore_message) - { - return FALSE; - } - - h = GetDlgItem(hdlg, IDC_COMBO_NET); - temp_net_card = settings_list_to_network[SendMessage(h, CB_GETCURSEL, 0, 0)]; - - temp_deviceconfig |= deviceconfig_open(hdlg, (void *)network_card_getdevice(temp_net_card)); - break; - } - return FALSE; - - case WM_SAVESETTINGS: - h = GetDlgItem(hdlg, IDC_COMBO_NET_TYPE); - temp_net_type = SendMessage(h, CB_GETCURSEL, 0, 0); - - h = GetDlgItem(hdlg, IDC_COMBO_PCAP); - memset(temp_host_dev, '\0', sizeof(temp_host_dev)); - strcpy(temp_host_dev, network_devs[SendMessage(h, CB_GETCURSEL, 0, 0)].device); - - h = GetDlgItem(hdlg, IDC_COMBO_NET); - temp_net_card = settings_list_to_network[SendMessage(h, CB_GETCURSEL, 0, 0)]; - - default: - return FALSE; - } - - return FALSE; -} - -static BOOL win_settings_hard_disks_image_list_init(HWND hwndList) -{ - HICON hiconItem; - HIMAGELIST hSmall; - - hSmall = ImageList_Create(GetSystemMetrics(SM_CXSMICON), - GetSystemMetrics(SM_CYSMICON), - ILC_MASK | ILC_COLOR32, 1, 1); - - hiconItem = LoadIcon(hinstance, (LPCWSTR) 208); - ImageList_AddIcon(hSmall, hiconItem); - DestroyIcon(hiconItem); - - hiconItem = LoadIcon(hinstance, (LPCWSTR) 192); - ImageList_AddIcon(hSmall, hiconItem); - DestroyIcon(hiconItem); - - ListView_SetImageList(hwndList, hSmall, LVSIL_SMALL); - - return TRUE; -} - -int next_free_id = 0; - -static void normalize_hd_list() -{ - hard_disk_t ihdd[HDD_NUM]; - int i, j; - - j = 0; - memset(ihdd, 0x00, HDD_NUM * sizeof(hard_disk_t)); - - for (i = 0; i < HDD_NUM; i++) - { - if (temp_hdd[i].bus != HDD_BUS_DISABLED) - { - memcpy(&(ihdd[j]), &(temp_hdd[i]), sizeof(hard_disk_t)); - j++; - } - } - - memcpy(temp_hdd, ihdd, HDD_NUM * sizeof(hard_disk_t)); -} - -int hdc_id_to_listview_index[HDD_NUM]; -int hd_listview_items; - -hard_disk_t new_hdd; -int hdlv_current_sel; - -static int get_selected_hard_disk(HWND hdlg) -{ - int hard_disk = -1; - int i, j = 0; - HWND h; - - if (hd_listview_items == 0) - { - return 0; - } - - for (i = 0; i < hd_listview_items; i++) - { - h = GetDlgItem(hdlg, IDC_LIST_HARD_DISKS); - j = ListView_GetItemState(h, i, LVIS_SELECTED); - if (j) - { - hard_disk = i; - } - } - - return hard_disk; -} - -static void add_locations(HWND hdlg) -{ - LPTSTR lptsTemp; - HWND h; - int i = 0; - - lptsTemp = (LPTSTR) malloc(512); - - h = GetDlgItem(hdlg, IDC_COMBO_HD_BUS); - for (i = 0; i < 7; i++) - { - SendMessage(h, CB_ADDSTRING, 0, (LPARAM)plat_get_string(IDS_4352 + i)); - } - - h = GetDlgItem(hdlg, IDC_COMBO_HD_CHANNEL); - for (i = 0; i < 8; i++) - { - swprintf(lptsTemp, 511, plat_get_string(IDS_4097), i >> 1, i & 1); - SendMessage(h, CB_ADDSTRING, 0, (LPARAM) lptsTemp); - } - - h = GetDlgItem(hdlg, IDC_COMBO_HD_ID); - for (i = 0; i < 16; i++) - { - swprintf(lptsTemp, 511, plat_get_string(IDS_4098), i); - SendMessage(h, CB_ADDSTRING, 0, (LPARAM) lptsTemp); - } - - h = GetDlgItem(hdlg, IDC_COMBO_HD_LUN); - for (i = 0; i < 8; i++) - { - swprintf(lptsTemp, 511, plat_get_string(IDS_4098), i); - SendMessage(h, CB_ADDSTRING, 0, (LPARAM) lptsTemp); - } - - h = GetDlgItem(hdlg, IDC_COMBO_HD_CHANNEL_IDE); - for (i = 0; i < 8; i++) - { - swprintf(lptsTemp, 511, plat_get_string(IDS_4097), i >> 1, i & 1); - SendMessage(h, CB_ADDSTRING, 0, (LPARAM) lptsTemp); - } - - free(lptsTemp); -} - -static uint8_t next_free_binary_channel(uint64_t *tracking) -{ - int8_t i; - - for (i = 0; i < 2; i++) { - if (!(*tracking & (0xffLL << (i << 3LL)))) - return i; - } - - return 2; -} - -static uint8_t next_free_ide_channel(void) -{ - int8_t i; - - for (i = 0; i < 8; i++) { - if (!(ide_tracking & (0xffLL << (i << 3LL)))) - return i; - } - - return 7; -} - -static void next_free_scsi_id_and_lun(uint8_t *id, uint8_t *lun) -{ - int i, j; - - for (i = 0; i < 16; i++) { - for (j = 0; j < 8; j++) { - if (! (scsi_tracking[i] & (0xffULL << (j << 3LL)))) { - *id = i; - *lun = j; - return; - } - } - } - - *id = 6; - *lun = 7; -} - -static void recalc_location_controls(HWND hdlg, int is_add_dlg, int assign_id) -{ - int i = 0; - HWND h; - - int bus = 0; - - for (i = IDT_1722; i <= IDT_1724; i++) - { - h = GetDlgItem(hdlg, i); - EnableWindow(h, FALSE); - ShowWindow(h, SW_HIDE); - } - - h = GetDlgItem(hdlg, IDC_COMBO_HD_CHANNEL); - EnableWindow(h, FALSE); - ShowWindow(h, SW_HIDE); - - h = GetDlgItem(hdlg, IDC_COMBO_HD_ID); - EnableWindow(h, FALSE); - ShowWindow(h, SW_HIDE); - - h = GetDlgItem(hdlg, IDC_COMBO_HD_LUN); - EnableWindow(h, FALSE); - ShowWindow(h, SW_HIDE); - - h = GetDlgItem(hdlg, IDC_COMBO_HD_CHANNEL_IDE); - EnableWindow(h, FALSE); - ShowWindow(h, SW_HIDE); - - if ((hd_listview_items > 0) || is_add_dlg) - { - h = GetDlgItem(hdlg, IDC_COMBO_HD_BUS); - bus = SendMessage(h, CB_GETCURSEL, 0, 0); - bus++; - - switch(bus) - { - case HDD_BUS_MFM: /* MFM */ - h = GetDlgItem(hdlg, IDT_1722); - ShowWindow(h, SW_SHOW); - EnableWindow(h, TRUE); - - h = GetDlgItem(hdlg, IDC_COMBO_HD_CHANNEL); - ShowWindow(h, SW_SHOW); - EnableWindow(h, TRUE); - if (assign_id) - temp_hdd[hdlv_current_sel].mfm_channel = next_free_binary_channel(&mfm_tracking); - SendMessage(h, CB_SETCURSEL, is_add_dlg ? new_hdd.mfm_channel : temp_hdd[hdlv_current_sel].mfm_channel, 0); - break; - case HDD_BUS_XTIDE: /* XT IDE */ - h = GetDlgItem(hdlg, IDT_1722); - ShowWindow(h, SW_SHOW); - EnableWindow(h, TRUE); - - h = GetDlgItem(hdlg, IDC_COMBO_HD_CHANNEL); - ShowWindow(h, SW_SHOW); - EnableWindow(h, TRUE); - if (assign_id) - temp_hdd[hdlv_current_sel].xtide_channel = next_free_binary_channel(&xtide_tracking); - SendMessage(h, CB_SETCURSEL, is_add_dlg ? new_hdd.xtide_channel : temp_hdd[hdlv_current_sel].xtide_channel, 0); - break; - case HDD_BUS_ESDI: /* ESDI */ - h = GetDlgItem(hdlg, IDT_1722); - ShowWindow(h, SW_SHOW); - EnableWindow(h, TRUE); - - h = GetDlgItem(hdlg, IDC_COMBO_HD_CHANNEL); - ShowWindow(h, SW_SHOW); - EnableWindow(h, TRUE); - if (assign_id) - temp_hdd[hdlv_current_sel].esdi_channel = next_free_binary_channel(&esdi_tracking); - SendMessage(h, CB_SETCURSEL, is_add_dlg ? new_hdd.esdi_channel : temp_hdd[hdlv_current_sel].esdi_channel, 0); - break; - case HDD_BUS_IDE_PIO_ONLY: /* IDE (PIO-only) */ - case HDD_BUS_IDE_PIO_AND_DMA: /* IDE (PIO and DMA) */ - h = GetDlgItem(hdlg, IDT_1722); - ShowWindow(h, SW_SHOW); - EnableWindow(h, TRUE); - - h = GetDlgItem(hdlg, IDC_COMBO_HD_CHANNEL_IDE); - ShowWindow(h, SW_SHOW); - EnableWindow(h, TRUE); - if (assign_id) - temp_hdd[hdlv_current_sel].ide_channel = next_free_ide_channel(); - SendMessage(h, CB_SETCURSEL, is_add_dlg ? new_hdd.ide_channel : temp_hdd[hdlv_current_sel].ide_channel, 0); - break; - case HDD_BUS_SCSI: /* SCSI */ - case HDD_BUS_SCSI_REMOVABLE: /* SCSI (removable) */ - h = GetDlgItem(hdlg, IDT_1723); - ShowWindow(h, SW_SHOW); - EnableWindow(h, TRUE); - h = GetDlgItem(hdlg, IDT_1724); - ShowWindow(h, SW_SHOW); - EnableWindow(h, TRUE); - - if (assign_id) - next_free_scsi_id_and_lun((uint8_t *) &temp_hdd[hdlv_current_sel].scsi_id, (uint8_t *) &temp_hdd[hdlv_current_sel].scsi_lun); - - h = GetDlgItem(hdlg, IDC_COMBO_HD_ID); - ShowWindow(h, SW_SHOW); - EnableWindow(h, TRUE); - SendMessage(h, CB_SETCURSEL, is_add_dlg ? new_hdd.scsi_id : temp_hdd[hdlv_current_sel].scsi_id, 0); - - h = GetDlgItem(hdlg, IDC_COMBO_HD_LUN); - ShowWindow(h, SW_SHOW); - EnableWindow(h, TRUE); - SendMessage(h, CB_SETCURSEL, is_add_dlg ? new_hdd.scsi_lun : temp_hdd[hdlv_current_sel].scsi_lun, 0); - break; - } - } - - if ((hd_listview_items == 0) && !is_add_dlg) - { - h = GetDlgItem(hdlg, IDT_1721); - EnableWindow(h, FALSE); - ShowWindow(h, SW_HIDE); - - h = GetDlgItem(hdlg, IDC_COMBO_HD_BUS); - EnableWindow(h, FALSE); ShowWindow(h, SW_HIDE); - } - else - { - h = GetDlgItem(hdlg, IDT_1721); - ShowWindow(h, SW_SHOW); - EnableWindow(h, TRUE); - - h = GetDlgItem(hdlg, IDC_COMBO_HD_BUS); - ShowWindow(h, SW_SHOW); - EnableWindow(h, TRUE); - } -} - -static int bus_full(uint64_t *tracking, int count) -{ - uint64_t full = 0; - switch(count) { - case 2: - default: - full = (*tracking & 0xFF00ULL); - full = full && (*tracking & 0x00FFULL); - return full != 0; - case 8: - full = (*tracking & 0xFF00000000000000ULL); - full = full && (*tracking & 0x00FF000000000000ULL); - full = full && (*tracking & 0x0000FF0000000000ULL); - full = full && (*tracking & 0x000000FF00000000ULL); - full = full && (*tracking & 0x00000000FF000000ULL); - full = full && (*tracking & 0x0000000000FF0000ULL); - full = full && (*tracking & 0x000000000000FF00ULL); - full = full && (*tracking & 0x00000000000000FFULL); - return full != 0; - } -} - -static void recalc_next_free_id(HWND hdlg) -{ - HWND h; - int i; - - int c_mfm = 0; - int c_esdi = 0; - int c_xtide = 0; - int c_ide_pio = 0; - int c_ide_dma = 0; - int c_scsi = 0; - int enable_add = 0; - - next_free_id = -1; - - for (i = 0; i < HDD_NUM; i++) - { - if (temp_hdd[i].bus == HDD_BUS_MFM) - { - c_mfm++; - } - else if (temp_hdd[i].bus == HDD_BUS_ESDI) - { - c_esdi++; - } - else if (temp_hdd[i].bus == HDD_BUS_XTIDE) - { - c_xtide++; - } - else if (temp_hdd[i].bus == HDD_BUS_IDE_PIO_ONLY) - { - c_ide_pio++; - } - else if (temp_hdd[i].bus == HDD_BUS_IDE_PIO_AND_DMA) - { - c_ide_dma++; - } - else if (temp_hdd[i].bus == HDD_BUS_SCSI) - { - c_scsi++; - } - else if (temp_hdd[i].bus == HDD_BUS_SCSI_REMOVABLE) - { - c_scsi++; - } - } - - for (i = 0; i < HDD_NUM; i++) - { - if (temp_hdd[i].bus == HDD_BUS_DISABLED) - { - next_free_id = i; - break; - } - } - - enable_add = enable_add || (next_free_id >= 0); - enable_add = enable_add && ((c_mfm < MFM_NUM) || (c_esdi < ESDI_NUM) || (c_xtide < XTIDE_NUM) || (c_ide_pio < IDE_NUM) || (c_ide_dma < IDE_NUM) || (c_scsi < SCSI_NUM)); - enable_add = enable_add && !bus_full(&mfm_tracking, 2); - enable_add = enable_add && !bus_full(&esdi_tracking, 2); - enable_add = enable_add && !bus_full(&xtide_tracking, 2); - enable_add = enable_add && !bus_full(&ide_tracking, 8); - for (i = 0; i < 16; i++) - enable_add = enable_add && !bus_full(&(scsi_tracking[i]), 8); - - h = GetDlgItem(hdlg, IDC_BUTTON_HDD_ADD_NEW); - - if (enable_add) - { - EnableWindow(h, TRUE); - } - else - { - EnableWindow(h, FALSE); - } - - h = GetDlgItem(hdlg, IDC_BUTTON_HDD_ADD); - - if (enable_add) - { - EnableWindow(h, TRUE); - } - else - { - EnableWindow(h, FALSE); - } - - h = GetDlgItem(hdlg, IDC_BUTTON_HDD_REMOVE); - - if ((c_mfm == 0) && (c_esdi == 0) && (c_xtide == 0) && (c_ide_pio == 0) && (c_ide_dma == 0) && (c_scsi == 0)) - { - EnableWindow(h, FALSE); - } - else - { - EnableWindow(h, TRUE); - } -} - -static void win_settings_hard_disks_update_item(HWND hwndList, int i, int column) -{ - LVITEM lvI; - WCHAR szText[256]; - - lvI.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_STATE; - lvI.stateMask = lvI.iSubItem = lvI.state = 0; - - lvI.iSubItem = column; - lvI.iItem = i; - - if (column == 0) - { - switch(temp_hdd[i].bus) - { - case HDD_BUS_MFM: - swprintf(szText, 255, plat_get_string(IDS_4608), temp_hdd[i].mfm_channel >> 1, temp_hdd[i].mfm_channel & 1); - break; - case HDD_BUS_XTIDE: - swprintf(szText, 255, plat_get_string(IDS_4609), temp_hdd[i].xtide_channel >> 1, temp_hdd[i].xtide_channel & 1); - break; - case HDD_BUS_ESDI: - swprintf(szText, 255, plat_get_string(IDS_4610), temp_hdd[i].esdi_channel >> 1, temp_hdd[i].esdi_channel & 1); - break; - case HDD_BUS_IDE_PIO_ONLY: - swprintf(szText, 255, plat_get_string(IDS_4611), temp_hdd[i].ide_channel >> 1, temp_hdd[i].ide_channel & 1); - break; - case HDD_BUS_IDE_PIO_AND_DMA: - swprintf(szText, 255, plat_get_string(IDS_4612), temp_hdd[i].ide_channel >> 1, temp_hdd[i].ide_channel & 1); - break; - case HDD_BUS_SCSI: - swprintf(szText, 255, plat_get_string(IDS_4613), temp_hdd[i].scsi_id, temp_hdd[i].scsi_lun); - break; - case HDD_BUS_SCSI_REMOVABLE: - swprintf(szText, 255, plat_get_string(IDS_4614), temp_hdd[i].scsi_id, temp_hdd[i].scsi_lun); - break; - } - lvI.pszText = szText; - lvI.iImage = (temp_hdd[i].bus == HDD_BUS_SCSI_REMOVABLE) ? 1 : 0; - } - else if (column == 1) - { - lvI.pszText = temp_hdd[i].fn; - lvI.iImage = 0; - } - else if (column == 2) - { - swprintf(szText, 255, plat_get_string(IDS_4098), temp_hdd[i].tracks); - lvI.pszText = szText; - lvI.iImage = 0; - } - else if (column == 3) - { - swprintf(szText, 255, plat_get_string(IDS_4098), temp_hdd[i].hpc); - lvI.pszText = szText; - lvI.iImage = 0; - } - else if (column == 4) - { - swprintf(szText, 255, plat_get_string(IDS_4098), temp_hdd[i].spt); - lvI.pszText = szText; - lvI.iImage = 0; - } - else if (column == 5) - { - swprintf(szText, 255, plat_get_string(IDS_4098), (temp_hdd[i].tracks * temp_hdd[i].hpc * temp_hdd[i].spt) >> 11); - lvI.pszText = szText; - lvI.iImage = 0; - } - - if (ListView_SetItem(hwndList, &lvI) == -1) - { - return; - } -} - -static BOOL win_settings_hard_disks_recalc_list(HWND hwndList) -{ - LVITEM lvI; - int i = 0; - int j = 0; - WCHAR szText[256]; - - hd_listview_items = 0; - hdlv_current_sel = -1; - - ListView_DeleteAllItems(hwndList); - - lvI.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_STATE; - lvI.stateMask = lvI.iSubItem = lvI.state = 0; - - for (i = 0; i < HDD_NUM; i++) - { - if (temp_hdd[i].bus > 0) - { - hdc_id_to_listview_index[i] = j; - lvI.iSubItem = 0; - switch(temp_hdd[i].bus) - { - case HDD_BUS_MFM: - swprintf(szText, 255, plat_get_string(IDS_4608), temp_hdd[i].mfm_channel >> 1, temp_hdd[i].mfm_channel & 1); - break; - case HDD_BUS_XTIDE: - swprintf(szText, 255, plat_get_string(IDS_4609), temp_hdd[i].xtide_channel >> 1, temp_hdd[i].xtide_channel & 1); - break; - case HDD_BUS_ESDI: - swprintf(szText, 255, plat_get_string(IDS_4610), temp_hdd[i].esdi_channel >> 1, temp_hdd[i].esdi_channel & 1); - break; - case HDD_BUS_IDE_PIO_ONLY: - swprintf(szText, 255, plat_get_string(IDS_4611), temp_hdd[i].ide_channel >> 1, temp_hdd[i].ide_channel & 1); - break; - case HDD_BUS_IDE_PIO_AND_DMA: - swprintf(szText, 255, plat_get_string(IDS_4612), temp_hdd[i].ide_channel >> 1, temp_hdd[i].ide_channel & 1); - break; - case HDD_BUS_SCSI: - swprintf(szText, 255, plat_get_string(IDS_4613), temp_hdd[i].scsi_id, temp_hdd[i].scsi_lun); - break; - case HDD_BUS_SCSI_REMOVABLE: - swprintf(szText, 255, plat_get_string(IDS_4614), temp_hdd[i].scsi_id, temp_hdd[i].scsi_lun); - break; - } - lvI.pszText = szText; - lvI.iItem = j; - lvI.iImage = (temp_hdd[i].bus == HDD_BUS_SCSI_REMOVABLE) ? 1 : 0; - - if (ListView_InsertItem(hwndList, &lvI) == -1) - { - return FALSE; - } - - lvI.iSubItem = 1; - lvI.pszText = temp_hdd[i].fn; - lvI.iItem = j; - lvI.iImage = 0; - - if (ListView_SetItem(hwndList, &lvI) == -1) - { - return FALSE; - } - - lvI.iSubItem = 2; - swprintf(szText, 255, plat_get_string(IDS_4098), temp_hdd[i].tracks); - lvI.pszText = szText; - lvI.iItem = j; - lvI.iImage = 0; - - if (ListView_SetItem(hwndList, &lvI) == -1) - { - return FALSE; - } - - lvI.iSubItem = 3; - swprintf(szText, 255, plat_get_string(IDS_4098), temp_hdd[i].hpc); - lvI.pszText = szText; - lvI.iItem = j; - lvI.iImage = 0; - - if (ListView_SetItem(hwndList, &lvI) == -1) - { - return FALSE; - } - - lvI.iSubItem = 4; - swprintf(szText, 255, plat_get_string(IDS_4098), temp_hdd[i].spt); - lvI.pszText = szText; - lvI.iItem = j; - lvI.iImage = 0; - - if (ListView_SetItem(hwndList, &lvI) == -1) - { - return FALSE; - } - - lvI.iSubItem = 5; - swprintf(szText, 255, plat_get_string(IDS_4098), (temp_hdd[i].tracks * temp_hdd[i].hpc * temp_hdd[i].spt) >> 11); - lvI.pszText = szText; - lvI.iItem = j; - lvI.iImage = 0; - - if (ListView_SetItem(hwndList, &lvI) == -1) - { - return FALSE; - } - - j++; - } - else - { - hdc_id_to_listview_index[i] = -1; - } - } - - hd_listview_items = j; - - return TRUE; -} - -/* Icon, Bus, File, C, H, S, Size */ -#define C_COLUMNS_HARD_DISKS 6 - -static BOOL win_settings_hard_disks_init_columns(HWND hwndList) -{ - LVCOLUMN lvc; - int iCol; - - lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM; - - for (iCol = 0; iCol < C_COLUMNS_HARD_DISKS; iCol++) - { - lvc.iSubItem = iCol; - lvc.pszText = plat_get_string(2082 + iCol); - - switch(iCol) - { - - case 0: /* Bus */ - lvc.cx = 135; - lvc.fmt = LVCFMT_LEFT; - break; - case 2: /* Cylinders */ - lvc.cx = 41; - lvc.fmt = LVCFMT_RIGHT; - break; - case 3: /* Heads */ - case 4: /* Sectors */ - lvc.cx = 25; - lvc.fmt = LVCFMT_RIGHT; - break; - case 1: /* File */ - lvc.cx = 150; - lvc.fmt = LVCFMT_LEFT; - break; - case 5: /* Size (MB) 8 */ - lvc.cx = 41; - lvc.fmt = LVCFMT_RIGHT; - break; - } - - if (ListView_InsertColumn(hwndList, iCol, &lvc) == -1) - { - return FALSE; - } - } - - return TRUE; -} - -static void get_edit_box_contents(HWND hdlg, int id, uint64_t *val) -{ - HWND h; - WCHAR szText[256]; - char stransi[256]; - - h = GetDlgItem(hdlg, id); - SendMessage(h, WM_GETTEXT, 255, (LPARAM) szText); - wcstombs(stransi, szText, 256); - sscanf(stransi, "%" PRIu64, val); -} - -static void get_combo_box_selection(HWND hdlg, int id, uint64_t *val) -{ - HWND h; - - h = GetDlgItem(hdlg, id); - *val = SendMessage(h, CB_GETCURSEL, 0, 0); -} - -static void set_edit_box_contents(HWND hdlg, int id, uint64_t val) -{ - HWND h; - WCHAR szText[256]; - - h = GetDlgItem(hdlg, id); - swprintf(szText, 255, plat_get_string(IDS_2156), val); - SendMessage(h, WM_SETTEXT, (WPARAM) wcslen(szText), (LPARAM) szText); -} - -int hard_disk_added = 0; -int max_spt = 63; -int max_hpc = 255; -int max_tracks = 266305; - -int no_update = 0; - -int existing = 0; -uint64_t selection = 127; - -uint64_t spt, hpc, tracks, size; -wchar_t hd_file_name[512]; - -static hard_disk_t *hdd_ptr; - -static uint64_t hdconf_initialize_hdt_combo(HWND hdlg) -{ - HWND h; - int i = 0; - uint64_t temp_size = 0; - uint64_t size_mb = 0; - WCHAR szText[256]; - - selection = 127; - - h = GetDlgItem(hdlg, IDC_COMBO_HD_TYPE); - for (i = 0; i < 127; i++) - { - temp_size = hdd_table[i].cyls * hdd_table[i].head * hdd_table[i].sect; - size_mb = temp_size >> 11; - swprintf(szText, 255, plat_get_string(IDS_2157), size_mb, - hdd_table[i].cyls, hdd_table[i].head, hdd_table[i].sect); - SendMessage(h, CB_ADDSTRING, 0, (LPARAM) szText); - if ((tracks == hdd_table[i].cyls) && (hpc == hdd_table[i].head) && (spt == hdd_table[i].sect)) - { - selection = i; - } - } - SendMessage(h, CB_ADDSTRING, 0, (LPARAM)plat_get_string(IDS_4100)); - SendMessage(h, CB_ADDSTRING, 0, (LPARAM)plat_get_string(IDS_4101)); - SendMessage(h, CB_SETCURSEL, selection & 0xffff, 0); - return selection; -} - -static void recalc_selection(HWND hdlg) -{ - HWND h; - int i = 0; - - selection = 127; - h = GetDlgItem(hdlg, IDC_COMBO_HD_TYPE); - for (i = 0; i < 127; i++) - { - if ((tracks == hdd_table[i].cyls) && (hpc == hdd_table[i].head) && (spt == hdd_table[i].sect)) - { - selection = i; - } - } - if ((selection == 127) && (hpc == 16) && (spt == 63)) - { - selection = 128; - } - SendMessage(h, CB_SETCURSEL, selection & 0xffff, 0); -} - -static int chs_enabled = 0; - -#ifdef __amd64__ -static LRESULT CALLBACK -#else -static BOOL CALLBACK -#endif -hard_disks_add_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) -{ - char buf[512], *big_buf; - HWND h = INVALID_HANDLE_VALUE; - uint64_t i = 0; - uint64_t temp; - FILE *f; - uint32_t sector_size = 512; - uint32_t zero = 0; - uint32_t base = 0x1000; - uint64_t signature = 0xD778A82044445459ll; - int b = 0; - uint64_t r = 0; - uint8_t channel = 0; - uint8_t id = 0, lun = 0; - wchar_t *twcs; - - switch (message) - { - case WM_INITDIALOG: - memset(hd_file_name, 0, sizeof(hd_file_name)); - - if (existing & 2) - { - next_free_id = (existing >> 3) & 0x1f; - hdd_ptr = &(hdd[next_free_id]); - } - else - { - hdd_ptr = &(temp_hdd[next_free_id]); - } - - SetWindowText(hdlg, plat_get_string((existing & 1) ? IDS_4103 : IDS_4102)); - - no_update = 1; - spt = (existing & 1) ? 0 : 17; - set_edit_box_contents(hdlg, IDC_EDIT_HD_SPT, spt); - hpc = (existing & 1) ? 0 : 15; - set_edit_box_contents(hdlg, IDC_EDIT_HD_HPC, hpc); - tracks = (existing & 1) ? 0 : 1023; - set_edit_box_contents(hdlg, IDC_EDIT_HD_CYL, tracks); - size = (tracks * hpc * spt) << 9; - set_edit_box_contents(hdlg, IDC_EDIT_HD_SIZE, size >> 20); - - hdconf_initialize_hdt_combo(hdlg); - if (existing & 1) - { - h = GetDlgItem(hdlg, IDC_EDIT_HD_SPT); - EnableWindow(h, FALSE); - h = GetDlgItem(hdlg, IDC_EDIT_HD_HPC); - EnableWindow(h, FALSE); - h = GetDlgItem(hdlg, IDC_EDIT_HD_CYL); - EnableWindow(h, FALSE); - h = GetDlgItem(hdlg, IDC_EDIT_HD_SIZE); - EnableWindow(h, FALSE); - h = GetDlgItem(hdlg, IDC_COMBO_HD_TYPE); - EnableWindow(h, FALSE); - chs_enabled = 0; - } - else - { - chs_enabled = 1; - } - - add_locations(hdlg); - - h = GetDlgItem(hdlg, IDC_COMBO_HD_BUS); - if (existing & 2) - { - hdd_ptr->bus = HDD_BUS_SCSI_REMOVABLE; - max_spt = 99; - max_hpc = 255; - } - else - { - hdd_ptr->bus = HDD_BUS_IDE_PIO_ONLY; - max_spt = 63; - max_hpc = 255; - } - SendMessage(h, CB_SETCURSEL, hdd_ptr->bus, 0); - max_tracks = 266305; - recalc_location_controls(hdlg, 1, 0); - - if (existing & 2) - { - /* We're functioning as a load image dialog for a removable SCSI hard disk, - called from win.c, so let's hide the bus selection as we should not - allow it at this point. */ - EnableWindow(h, FALSE); - ShowWindow(h, SW_HIDE); - - h = GetDlgItem(hdlg, 1798); - ShowWindow(h, SW_HIDE); - - /* Disable and hide the SCSI ID and LUN combo boxes. */ - h = GetDlgItem(hdlg, IDC_COMBO_HD_ID); - EnableWindow(h, FALSE); - ShowWindow(h, SW_HIDE); - - h = GetDlgItem(hdlg, IDC_COMBO_HD_LUN); - EnableWindow(h, FALSE); - ShowWindow(h, SW_HIDE); - - /* Set the file name edit box contents to our existing parameters. */ - h = GetDlgItem(hdlg, IDC_EDIT_HD_FILE_NAME); - SendMessage(h, WM_SETTEXT, 0, (LPARAM) hdd[next_free_id].fn); - } - else - { - channel = next_free_ide_channel(); - next_free_scsi_id_and_lun(&id, &lun); - h = GetDlgItem(hdlg, IDC_COMBO_HD_CHANNEL); - SendMessage(h, CB_SETCURSEL, 0, 0); - h = GetDlgItem(hdlg, IDC_COMBO_HD_ID); - SendMessage(h, CB_SETCURSEL, id, 0); - h = GetDlgItem(hdlg, IDC_COMBO_HD_LUN); - SendMessage(h, CB_SETCURSEL, lun, 0); - h = GetDlgItem(hdlg, IDC_COMBO_HD_CHANNEL_IDE); - SendMessage(h, CB_SETCURSEL, channel, 0); - - new_hdd.mfm_channel = next_free_binary_channel(&mfm_tracking); - new_hdd.esdi_channel = next_free_binary_channel(&esdi_tracking); - new_hdd.xtide_channel = next_free_binary_channel(&xtide_tracking); - new_hdd.ide_channel = channel; - new_hdd.scsi_id = id; - new_hdd.scsi_lun = lun; - } - h = GetDlgItem(hdlg, IDC_EDIT_HD_FILE_NAME); - EnableWindow(h, FALSE); - - h = GetDlgItem(hdlg, IDT_1752); - EnableWindow(h, FALSE); - ShowWindow(h, SW_HIDE); - - h = GetDlgItem(hdlg, IDC_PBAR_IMG_CREATE); - EnableWindow(h, FALSE); - ShowWindow(h, SW_HIDE); - - no_update = 0; - return TRUE; - - case WM_COMMAND: - switch (LOWORD(wParam)) - { - case IDOK: - if (!(existing & 2)) - { - h = GetDlgItem(hdlg, IDC_COMBO_HD_BUS); - hdd_ptr->bus = (SendMessage(h, CB_GETCURSEL, 0, 0) + 1) & 0xff; - } - - /* Make sure no file name is allowed with removable SCSI hard disks. */ - if ((wcslen(hd_file_name) == 0) && (hdd_ptr->bus != HDD_BUS_SCSI_REMOVABLE)) - { - hdd_ptr->bus = HDD_BUS_DISABLED; - settings_msgbox(MBX_ERROR, (wchar_t *)IDS_4112); - return TRUE; - } - else if ((wcslen(hd_file_name) == 0) && (hdd_ptr->bus == HDD_BUS_SCSI_REMOVABLE)) - { - /* Mark hard disk added but return empty - it will signify the disk was ejected. */ - hdd_ptr->tracks = 0; - hdd_ptr->spt = hdd_ptr->hpc = 0; - memset(hdd_ptr->fn, 0, sizeof(hdd_ptr->fn)); - - goto hd_add_ok_common; - } - - get_edit_box_contents(hdlg, IDC_EDIT_HD_SPT, &i); - hdd_ptr->spt = (uint8_t)i; - get_edit_box_contents(hdlg, IDC_EDIT_HD_HPC, &i); - hdd_ptr->hpc = (uint8_t)i; - get_edit_box_contents(hdlg, IDC_EDIT_HD_CYL, &i); - hdd_ptr->tracks = (uint16_t)i; - spt = hdd_ptr->spt; - hpc = hdd_ptr->hpc; - tracks = hdd_ptr->tracks; - - if (existing & 2) - { - if (hdd_ptr->bus == HDD_BUS_SCSI_REMOVABLE) - { - memset(hdd_ptr->prev_fn, 0, sizeof(hdd_ptr->prev_fn)); - wcscpy(hdd_ptr->prev_fn, hdd_ptr->fn); - } - } - else - { - switch(hdd_ptr->bus) - { - case HDD_BUS_MFM: - h = GetDlgItem(hdlg, IDC_COMBO_HD_CHANNEL); - hdd_ptr->mfm_channel = SendMessage(h, CB_GETCURSEL, 0, 0) & 0xff; - break; - case HDD_BUS_ESDI: - h = GetDlgItem(hdlg, IDC_COMBO_HD_CHANNEL); - hdd_ptr->esdi_channel = SendMessage(h, CB_GETCURSEL, 0, 0) & 0xff; - break; - case HDD_BUS_XTIDE: - h = GetDlgItem(hdlg, IDC_COMBO_HD_CHANNEL); - hdd_ptr->xtide_channel = SendMessage(h, CB_GETCURSEL, 0, 0) & 0xff; - break; - case HDD_BUS_IDE_PIO_ONLY: - case HDD_BUS_IDE_PIO_AND_DMA: - h = GetDlgItem(hdlg, IDC_COMBO_HD_CHANNEL_IDE); - hdd_ptr->ide_channel = SendMessage(h, CB_GETCURSEL, 0, 0) & 0xff; - break; - case HDD_BUS_SCSI: - case HDD_BUS_SCSI_REMOVABLE: - h = GetDlgItem(hdlg, IDC_COMBO_HD_ID); - hdd_ptr->scsi_id = SendMessage(h, CB_GETCURSEL, 0, 0) & 0xff; - h = GetDlgItem(hdlg, IDC_COMBO_HD_LUN); - hdd_ptr->scsi_lun = SendMessage(h, CB_GETCURSEL, 0, 0) & 0xff; - break; - } - } - - memset(hdd_ptr->fn, 0, sizeof(hdd_ptr->fn)); - wcscpy(hdd_ptr->fn, hd_file_name); - - sector_size = 512; - - if (!(existing & 1) && (wcslen(hd_file_name) > 0)) - { - f = _wfopen(hd_file_name, L"wb"); - - if (image_is_hdi(hd_file_name)) - { - if (size >= 0x100000000ll) - { - fclose(f); - settings_msgbox(MBX_ERROR, (wchar_t *)IDS_4104); - return TRUE; - } - - fwrite(&zero, 1, 4, f); /* 00000000: Zero/unknown */ - fwrite(&zero, 1, 4, f); /* 00000004: Zero/unknown */ - fwrite(&base, 1, 4, f); /* 00000008: Offset at which data starts */ - fwrite(&size, 1, 4, f); /* 0000000C: Full size of the data (32-bit) */ - fwrite(§or_size, 1, 4, f); /* 00000010: Sector size in bytes */ - fwrite(&spt, 1, 4, f); /* 00000014: Sectors per cylinder */ - fwrite(&hpc, 1, 4, f); /* 00000018: Heads per cylinder */ - fwrite(&tracks, 1, 4, f); /* 0000001C: Cylinders */ - - for (i = 0; i < 0x3f8; i++) - { - fwrite(&zero, 1, 4, f); - } - } - else if (image_is_hdx(hd_file_name, 0)) - { - if (size > 0xffffffffffffffffll) - { - fclose(f); - settings_msgbox(MBX_ERROR, (wchar_t *)IDS_4105); - return TRUE; - } - - fwrite(&signature, 1, 8, f); /* 00000000: Signature */ - fwrite(&size, 1, 8, f); /* 00000008: Full size of the data (64-bit) */ - fwrite(§or_size, 1, 4, f); /* 00000010: Sector size in bytes */ - fwrite(&spt, 1, 4, f); /* 00000014: Sectors per cylinder */ - fwrite(&hpc, 1, 4, f); /* 00000018: Heads per cylinder */ - fwrite(&tracks, 1, 4, f); /* 0000001C: Cylinders */ - fwrite(&zero, 1, 4, f); /* 00000020: [Translation] Sectors per cylinder */ - fwrite(&zero, 1, 4, f); /* 00000004: [Translation] Heads per cylinder */ - } - - memset(buf, 0, 512); - size >>= 9; - r = (size >> 11) << 11; - size -= r; - r >>= 11; - - if (size || r) { - h = GetDlgItem(hdlg, IDT_1731); - EnableWindow(h, FALSE); - ShowWindow(h, SW_HIDE); - - h = GetDlgItem(hdlg, IDC_EDIT_HD_FILE_NAME); - EnableWindow(h, FALSE); - ShowWindow(h, SW_HIDE); - - h = GetDlgItem(hdlg, IDC_CFILE); - EnableWindow(h, FALSE); - ShowWindow(h, SW_HIDE); - - h = GetDlgItem(hdlg, IDC_PBAR_IMG_CREATE); - SendMessage(h, PBM_SETRANGE32, (WPARAM) 0, (LPARAM) (size + r - 1)); - SendMessage(h, PBM_SETPOS, (WPARAM) 0, (LPARAM) 0); - EnableWindow(h, TRUE); - ShowWindow(h, SW_SHOW); - - h = GetDlgItem(hdlg, IDT_1752); - EnableWindow(h, TRUE); - ShowWindow(h, SW_SHOW); - } - - if (size) - { - for (i = 0; i < size; i++) - { - fwrite(buf, 1, 512, f); - SendMessage(h, PBM_SETPOS, (WPARAM) i, (LPARAM) 0); - } - } - - if (r) - { - big_buf = (char *) malloc(1048576); - memset(big_buf, 0, 1048576); - for (i = 0; i < r; i++) - { - fwrite(big_buf, 1, 1048576, f); - SendMessage(h, PBM_SETPOS, (WPARAM) (size + i), (LPARAM) 0); - } - free(big_buf); - } - - fclose(f); - settings_msgbox(MBX_INFO, (wchar_t *)IDS_4113); - } - -hd_add_ok_common: - hard_disk_added = 1; - EndDialog(hdlg, 0); - return TRUE; - - case IDCANCEL: - hard_disk_added = 0; - if (!(existing & 2)) - { - hdd_ptr->bus = HDD_BUS_DISABLED; - } - EndDialog(hdlg, 0); - return TRUE; - - case IDC_CFILE: - if (!file_dlg(hdlg, plat_get_string(IDS_4106), L"", !(existing & 1))) - { - if (!wcschr(wopenfilestring, L'.')) { - if (wcslen(wopenfilestring) && (wcslen(wopenfilestring) <= 256)) { - twcs = &wopenfilestring[wcslen(wopenfilestring)]; - twcs[0] = L'.'; - twcs[1] = L'i'; - twcs[2] = L'm'; - twcs[3] = L'g'; - } - } - - if (!(existing & 1)) - { - f = _wfopen(wopenfilestring, L"rb"); - if (f != NULL) - { - fclose(f); - if (settings_msgbox(MBX_QUESTION, (wchar_t *)IDS_4111) != 0) /* yes */ - { - return FALSE; - } - } - } - - f = _wfopen(wopenfilestring, (existing & 1) ? L"rb" : L"wb"); - if (f == NULL) - { -hdd_add_file_open_error: - settings_msgbox(MBX_ERROR, (existing & 1) ? (wchar_t *)IDS_4107 : (wchar_t *)IDS_4108); - return TRUE; - } - if (existing & 1) - { - if (image_is_hdi(wopenfilestring) || image_is_hdx(wopenfilestring, 1)) - { - fseeko64(f, 0x10, SEEK_SET); - fread(§or_size, 1, 4, f); - if (sector_size != 512) - { - settings_msgbox(MBX_ERROR, (wchar_t *)IDS_4109); - fclose(f); - return TRUE; - } - spt = hpc = tracks = 0; - fread(&spt, 1, 4, f); - fread(&hpc, 1, 4, f); - fread(&tracks, 1, 4, f); - } - else - { - fseeko64(f, 0, SEEK_END); - size = ftello64(f); - fclose(f); - if (((size % 17) == 0) && (size <= 142606336)) - { - spt = 17; - if (size <= 26738688) - { - hpc = 4; - } - else if (((size % 3072) == 0) && (size <= 53477376)) - { - hpc = 6; - } - else - { - for (i = 5; i < 16; i++) - { - if (((size % (i << 9)) == 0) && (size <= ((i * 17) << 19))) - { - break; - } - if (i == 5) - { - i++; - } - } - hpc = i; - } - } - else - { - spt = 63; - hpc = 16; - } - - tracks = ((size >> 9) / hpc) / spt; - } - - if ((spt > max_spt) || (hpc > max_hpc) || (tracks > max_tracks)) - { - goto hdd_add_file_open_error; - } - no_update = 1; - - set_edit_box_contents(hdlg, IDC_EDIT_HD_SPT, spt); - set_edit_box_contents(hdlg, IDC_EDIT_HD_HPC, hpc); - set_edit_box_contents(hdlg, IDC_EDIT_HD_CYL, tracks); - set_edit_box_contents(hdlg, IDC_EDIT_HD_SIZE, size >> 20); - recalc_selection(hdlg); - - h = GetDlgItem(hdlg, IDC_EDIT_HD_SPT); - EnableWindow(h, TRUE); - h = GetDlgItem(hdlg, IDC_EDIT_HD_HPC); - EnableWindow(h, TRUE); - h = GetDlgItem(hdlg, IDC_EDIT_HD_CYL); - EnableWindow(h, TRUE); - h = GetDlgItem(hdlg, IDC_EDIT_HD_SIZE); - EnableWindow(h, TRUE); - h = GetDlgItem(hdlg, IDC_COMBO_HD_TYPE); - EnableWindow(h, TRUE); - - chs_enabled = 1; - - no_update = 0; - } - else - { - fclose(f); - } - } - - h = GetDlgItem(hdlg, IDC_EDIT_HD_FILE_NAME); - SendMessage(h, WM_SETTEXT, 0, (LPARAM) wopenfilestring); - memset(hd_file_name, 0, sizeof(hd_file_name)); - wcscpy(hd_file_name, wopenfilestring); - - return TRUE; - - case IDC_EDIT_HD_CYL: - if (no_update) - { - return FALSE; - } - - no_update = 1; - get_edit_box_contents(hdlg, IDC_EDIT_HD_CYL, &temp); - if (temp != tracks) - { - tracks = temp; - size = (tracks * hpc * spt) << 9; - set_edit_box_contents(hdlg, IDC_EDIT_HD_SIZE, size >> 20); - recalc_selection(hdlg); - } - - if (tracks > max_tracks) - { - tracks = max_tracks; - size = (tracks * hpc * spt) << 9; - set_edit_box_contents(hdlg, IDC_EDIT_HD_CYL, tracks); - set_edit_box_contents(hdlg, IDC_EDIT_HD_SIZE, (size >> 20)); - recalc_selection(hdlg); - } - - no_update = 0; - break; - - case IDC_EDIT_HD_HPC: - if (no_update) - { - return FALSE; - } - - no_update = 1; - get_edit_box_contents(hdlg, IDC_EDIT_HD_HPC, &temp); - if (temp != hpc) - { - hpc = temp; - size = (tracks * hpc * spt) << 9; - set_edit_box_contents(hdlg, IDC_EDIT_HD_SIZE, size >> 20); - recalc_selection(hdlg); - } - - if (hpc > max_hpc) - { - hpc = max_hpc; - size = (tracks * hpc * spt) << 9; - set_edit_box_contents(hdlg, IDC_EDIT_HD_HPC, hpc); - set_edit_box_contents(hdlg, IDC_EDIT_HD_SIZE, (size >> 20)); - recalc_selection(hdlg); - } - - no_update = 0; - break; - - case IDC_EDIT_HD_SPT: - if (no_update) - { - return FALSE; - } - - no_update = 1; - get_edit_box_contents(hdlg, IDC_EDIT_HD_SPT, &temp); - if (temp != spt) - { - spt = temp; - size = (tracks * hpc * spt) << 9; - set_edit_box_contents(hdlg, IDC_EDIT_HD_SIZE, size >> 20); - recalc_selection(hdlg); - } - - if (spt > max_spt) - { - spt = max_spt; - size = (tracks * hpc * spt) << 9; - set_edit_box_contents(hdlg, IDC_EDIT_HD_SPT, spt); - set_edit_box_contents(hdlg, IDC_EDIT_HD_SIZE, (size >> 20)); - recalc_selection(hdlg); - } - - no_update = 0; - break; - - case IDC_EDIT_HD_SIZE: - if (no_update) - { - return FALSE; - } - - no_update = 1; - get_edit_box_contents(hdlg, IDC_EDIT_HD_SIZE, &temp); - if (temp != (size >> 20)) - { - size = temp << 20; - tracks = ((size >> 9) / hpc) / spt; - set_edit_box_contents(hdlg, IDC_EDIT_HD_CYL, tracks); - recalc_selection(hdlg); - } - - if (tracks > max_tracks) - { - tracks = max_tracks; - size = (tracks * hpc * spt) << 9; - set_edit_box_contents(hdlg, IDC_EDIT_HD_CYL, tracks); - set_edit_box_contents(hdlg, IDC_EDIT_HD_SIZE, (size >> 20)); - recalc_selection(hdlg); - } - - no_update = 0; - break; - - case IDC_COMBO_HD_TYPE: - if (no_update) - { - return FALSE; - } - - no_update = 1; - get_combo_box_selection(hdlg, IDC_COMBO_HD_TYPE, &temp); - if ((temp != selection) && (temp != 127) && (temp != 128)) - { - selection = temp; - tracks = hdd_table[selection].cyls; - hpc = hdd_table[selection].head; - spt = hdd_table[selection].sect; - size = (tracks * hpc * spt) << 9; - set_edit_box_contents(hdlg, IDC_EDIT_HD_CYL, tracks); - set_edit_box_contents(hdlg, IDC_EDIT_HD_HPC, hpc); - set_edit_box_contents(hdlg, IDC_EDIT_HD_SPT, spt); - set_edit_box_contents(hdlg, IDC_EDIT_HD_SIZE, size >> 20); - } - else if ((temp != selection) && (temp == 127)) - { - selection = temp; - } - else if ((temp != selection) && (temp == 128)) - { - selection = temp; - hpc = 16; - spt = 63; - size = (tracks * hpc * spt) << 9; - set_edit_box_contents(hdlg, IDC_EDIT_HD_HPC, hpc); - set_edit_box_contents(hdlg, IDC_EDIT_HD_SPT, spt); - set_edit_box_contents(hdlg, IDC_EDIT_HD_SIZE, size >> 20); - } - - if (spt > max_spt) - { - spt = max_spt; - size = (tracks * hpc * spt) << 9; - set_edit_box_contents(hdlg, IDC_EDIT_HD_SPT, spt); - set_edit_box_contents(hdlg, IDC_EDIT_HD_SIZE, (size >> 20)); - recalc_selection(hdlg); - } - - if (hpc > max_hpc) - { - hpc = max_hpc; - size = (tracks * hpc * spt) << 9; - set_edit_box_contents(hdlg, IDC_EDIT_HD_HPC, hpc); - set_edit_box_contents(hdlg, IDC_EDIT_HD_SIZE, (size >> 20)); - recalc_selection(hdlg); - } - - if (tracks > max_tracks) - { - tracks = max_tracks; - size = (tracks * hpc * spt) << 9; - set_edit_box_contents(hdlg, IDC_EDIT_HD_CYL, tracks); - set_edit_box_contents(hdlg, IDC_EDIT_HD_SIZE, (size >> 20)); - recalc_selection(hdlg); - } - - no_update = 0; - break; - - case IDC_COMBO_HD_BUS: - if (no_update) - { - return FALSE; - } - - no_update = 1; - recalc_location_controls(hdlg, 1, 0); - h = GetDlgItem(hdlg, IDC_COMBO_HD_BUS); - b = SendMessage(h,CB_GETCURSEL,0,0) + 1; - if (b == hdd_ptr->bus) - { - goto hd_add_bus_skip; - } - - hdd_ptr->bus = b; - - switch(hdd_ptr->bus) - { - case HDD_BUS_DISABLED: - default: - max_spt = max_hpc = max_tracks = 0; - break; - case HDD_BUS_MFM: - max_spt = 17; - max_hpc = 15; - max_tracks = 1023; - break; - case HDD_BUS_ESDI: - case HDD_BUS_XTIDE: - max_spt = 63; - max_hpc = 16; - max_tracks = 1023; - break; - case HDD_BUS_IDE_PIO_ONLY: - case HDD_BUS_IDE_PIO_AND_DMA: - max_spt = 63; - max_hpc = 255; - max_tracks = 266305; - break; - case HDD_BUS_SCSI_REMOVABLE: - if (spt == 0) - { - spt = 63; - size = (tracks * hpc * spt) << 9; - set_edit_box_contents(hdlg, IDC_EDIT_HD_SPT, spt); - set_edit_box_contents(hdlg, IDC_EDIT_HD_SIZE, (size >> 20)); - } - if (hpc == 0) - { - hpc = 16; - size = (tracks * hpc * spt) << 9; - set_edit_box_contents(hdlg, IDC_EDIT_HD_HPC, hpc); - set_edit_box_contents(hdlg, IDC_EDIT_HD_SIZE, (size >> 20)); - } - if (tracks == 0) - { - tracks = 1023; - size = (tracks * hpc * spt) << 9; - set_edit_box_contents(hdlg, IDC_EDIT_HD_CYL, tracks); - set_edit_box_contents(hdlg, IDC_EDIT_HD_SIZE, (size >> 20)); - } - case HDD_BUS_SCSI: - max_spt = 99; - max_hpc = 255; - max_tracks = 266305; - break; - } - - if ((hdd_ptr->bus == HDD_BUS_SCSI_REMOVABLE) && !chs_enabled) - { - h = GetDlgItem(hdlg, IDC_EDIT_HD_SPT); - EnableWindow(h, TRUE); - h = GetDlgItem(hdlg, IDC_EDIT_HD_HPC); - EnableWindow(h, TRUE); - h = GetDlgItem(hdlg, IDC_EDIT_HD_CYL); - EnableWindow(h, TRUE); - h = GetDlgItem(hdlg, IDC_EDIT_HD_SIZE); - EnableWindow(h, TRUE); - h = GetDlgItem(hdlg, IDC_COMBO_HD_TYPE); - EnableWindow(h, TRUE); - } - else if ((hdd_ptr->bus != HDD_BUS_SCSI_REMOVABLE) && !chs_enabled) - { - h = GetDlgItem(hdlg, IDC_EDIT_HD_SPT); - EnableWindow(h, FALSE); - h = GetDlgItem(hdlg, IDC_EDIT_HD_HPC); - EnableWindow(h, FALSE); - h = GetDlgItem(hdlg, IDC_EDIT_HD_CYL); - EnableWindow(h, FALSE); - h = GetDlgItem(hdlg, IDC_EDIT_HD_SIZE); - EnableWindow(h, FALSE); - h = GetDlgItem(hdlg, IDC_COMBO_HD_TYPE); - EnableWindow(h, FALSE); - } - - if (spt > max_spt) - { - spt = max_spt; - size = (tracks * hpc * spt) << 9; - set_edit_box_contents(hdlg, IDC_EDIT_HD_SPT, spt); - set_edit_box_contents(hdlg, IDC_EDIT_HD_SIZE, (size >> 20)); - recalc_selection(hdlg); - } - - if (hpc > max_hpc) - { - hpc = max_hpc; - size = (tracks * hpc * spt) << 9; - set_edit_box_contents(hdlg, IDC_EDIT_HD_HPC, hpc); - set_edit_box_contents(hdlg, IDC_EDIT_HD_SIZE, (size >> 20)); - recalc_selection(hdlg); - } - - if (tracks > max_tracks) - { - tracks = max_tracks; - size = (tracks * hpc * spt) << 9; - set_edit_box_contents(hdlg, IDC_EDIT_HD_CYL, tracks); - set_edit_box_contents(hdlg, IDC_EDIT_HD_SIZE, (size >> 20)); - recalc_selection(hdlg); - } - -hd_add_bus_skip: - no_update = 0; - break; - } - - return FALSE; - } - - return FALSE; -} - -int hard_disk_was_added(void) -{ - return hard_disk_added; -} - -void hard_disk_add_open(HWND hwnd, int is_existing) -{ - existing = is_existing; - hard_disk_added = 0; - DialogBox(hinstance, (LPCWSTR)DLG_CFG_HARD_DISKS_ADD, hwnd, hard_disks_add_proc); -} - -static void hard_disk_track(uint8_t id) -{ - switch(temp_hdd[id].bus) { - case HDD_BUS_MFM: - mfm_tracking |= (1ULL << (temp_hdd[id].mfm_channel << 3)); - break; - case HDD_BUS_ESDI: - esdi_tracking |= (1ULL << (temp_hdd[id].esdi_channel << 3)); - break; - case HDD_BUS_XTIDE: - xtide_tracking |= (1ULL << (temp_hdd[id].xtide_channel << 3)); - break; - case HDD_BUS_IDE_PIO_ONLY: - case HDD_BUS_IDE_PIO_AND_DMA: - ide_tracking |= (1ULL << (temp_hdd[id].ide_channel << 3)); - break; - case HDD_BUS_SCSI: - case HDD_BUS_SCSI_REMOVABLE: - scsi_tracking[temp_hdd[id].scsi_id] |= (1ULL << (temp_hdd[id].scsi_lun << 3)); - break; - } -} - -static void hard_disk_untrack(uint8_t id) -{ - switch(temp_hdd[id].bus) { - case HDD_BUS_MFM: - mfm_tracking &= ~(1 << (temp_hdd[id].mfm_channel << 3)); - break; - case HDD_BUS_ESDI: - esdi_tracking &= ~(1 << (temp_hdd[id].esdi_channel << 3)); - break; - case HDD_BUS_XTIDE: - xtide_tracking &= ~(1 << (temp_hdd[id].xtide_channel << 3)); - break; - case HDD_BUS_IDE_PIO_ONLY: - case HDD_BUS_IDE_PIO_AND_DMA: - ide_tracking &= ~(1 << (temp_hdd[id].ide_channel << 3)); - break; - case HDD_BUS_SCSI: - case HDD_BUS_SCSI_REMOVABLE: - scsi_tracking[temp_hdd[id].scsi_id] &= ~(1 << (temp_hdd[id].scsi_lun << 3)); - break; - } -} - -static void hard_disk_track_all(void) -{ - int i; - - for (i = 0; i < HDD_NUM; i++) - hard_disk_track(i); -} - -int ignore_change = 0; - -#ifdef __amd64__ -static LRESULT CALLBACK -#else -static BOOL CALLBACK -#endif -hard_disks_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) -{ - HWND h = INVALID_HANDLE_VALUE; - int old_sel = 0; - int b = 0; - int assign = 0; - - switch (message) - { - case WM_INITDIALOG: - ignore_change = 1; - - normalize_hd_list(); /* Normalize the hard disks so that non-disabled hard disks start from index 0, and so they are contiguous. - This will cause an emulator reset prompt on the first opening of this category with a messy hard disk list - (which can only happen by manually editing the configuration file). */ - h = GetDlgItem(hdlg, IDC_LIST_HARD_DISKS); - win_settings_hard_disks_init_columns(h); - win_settings_hard_disks_image_list_init(h); - win_settings_hard_disks_recalc_list(h); - recalc_next_free_id(hdlg); - add_locations(hdlg); - if (hd_listview_items > 0) - { - ListView_SetItemState(h, 0, LVIS_FOCUSED | LVIS_SELECTED, 0x000F); - hdlv_current_sel = 0; - h = GetDlgItem(hdlg, IDC_COMBO_HD_BUS); - SendMessage(h, CB_SETCURSEL, temp_hdd[0].bus - 1, 0); - } - else - { - hdlv_current_sel = -1; - } - recalc_location_controls(hdlg, 0, 0); - - ignore_change = 0; - return TRUE; - - case WM_NOTIFY: - if ((hd_listview_items == 0) || ignore_change) - { - return FALSE; - } - - if ((((LPNMHDR)lParam)->code == LVN_ITEMCHANGED) && (((LPNMHDR)lParam)->idFrom == IDC_LIST_HARD_DISKS)) - { - old_sel = hdlv_current_sel; - hdlv_current_sel = get_selected_hard_disk(hdlg); - if (hdlv_current_sel == old_sel) - { - return FALSE; - } - else if (hdlv_current_sel == -1) - { - ignore_change = 1; - hdlv_current_sel = old_sel; - ListView_SetItemState(h, hdlv_current_sel, LVIS_FOCUSED | LVIS_SELECTED, 0x000F); - ignore_change = 0; - return FALSE; - } - ignore_change = 1; - h = GetDlgItem(hdlg, IDC_COMBO_HD_BUS); - SendMessage(h, CB_SETCURSEL, temp_hdd[hdlv_current_sel].bus - 1, 0); - recalc_location_controls(hdlg, 0, 0); - ignore_change = 0; - } - break; - - case WM_COMMAND: - switch (LOWORD(wParam)) - { - case IDC_COMBO_HD_BUS: - if (ignore_change) - { - return FALSE; - } - - ignore_change = 1; - h = GetDlgItem(hdlg, IDC_COMBO_HD_BUS); - b = SendMessage(h, CB_GETCURSEL, 0, 0) + 1; - if (b == temp_hdd[hdlv_current_sel].bus) - { - goto hd_bus_skip; - } - hard_disk_untrack(hdlv_current_sel); - assign = (temp_hdd[hdlv_current_sel].bus == b) ? 0 : 1; - if ((b == HDD_BUS_IDE_PIO_ONLY) && (temp_hdd[hdlv_current_sel].bus == HDD_BUS_IDE_PIO_AND_DMA)) - assign = 0; - else if ((b == HDD_BUS_IDE_PIO_AND_DMA) && (temp_hdd[hdlv_current_sel].bus == HDD_BUS_IDE_PIO_ONLY)) - assign = 0; - temp_hdd[hdlv_current_sel].bus = b; - recalc_location_controls(hdlg, 0, assign); - hard_disk_track(hdlv_current_sel); - h = GetDlgItem(hdlg, IDC_LIST_HARD_DISKS); - win_settings_hard_disks_update_item(h, hdlv_current_sel, 0); -hd_bus_skip: - ignore_change = 0; - return FALSE; - - case IDC_COMBO_HD_CHANNEL: - if (ignore_change) - { - return FALSE; - } - - ignore_change = 1; - h = GetDlgItem(hdlg, IDC_COMBO_HD_CHANNEL); - hard_disk_untrack(hdlv_current_sel); - if (temp_hdd[hdlv_current_sel].bus == HDD_BUS_MFM) - { - temp_hdd[hdlv_current_sel].mfm_channel = SendMessage(h, CB_GETCURSEL, 0, 0) & 0xff; - } - else if (temp_hdd[hdlv_current_sel].bus == HDD_BUS_ESDI) - { - temp_hdd[hdlv_current_sel].esdi_channel = SendMessage(h, CB_GETCURSEL, 0, 0) & 0xff; - } - else if (temp_hdd[hdlv_current_sel].bus == HDD_BUS_XTIDE) - { - temp_hdd[hdlv_current_sel].xtide_channel = SendMessage(h, CB_GETCURSEL, 0, 0) & 0xff; - } - hard_disk_track(hdlv_current_sel); - h = GetDlgItem(hdlg, IDC_LIST_HARD_DISKS); - win_settings_hard_disks_update_item(h, hdlv_current_sel, 0); - ignore_change = 0; - return FALSE; - - case IDC_COMBO_HD_CHANNEL_IDE: - if (ignore_change) - { - return FALSE; - } - - ignore_change = 1; - h = GetDlgItem(hdlg, IDC_COMBO_HD_CHANNEL_IDE); - hard_disk_untrack(hdlv_current_sel); - temp_hdd[hdlv_current_sel].ide_channel = SendMessage(h, CB_GETCURSEL, 0, 0) & 0xff; - hard_disk_track(hdlv_current_sel); - h = GetDlgItem(hdlg, IDC_LIST_HARD_DISKS); - win_settings_hard_disks_update_item(h, hdlv_current_sel, 0); - ignore_change = 0; - return FALSE; - - case IDC_COMBO_HD_ID: - if (ignore_change) - { - return FALSE; - } - - ignore_change = 1; - h = GetDlgItem(hdlg, IDC_COMBO_HD_ID); - hard_disk_untrack(hdlv_current_sel); - temp_hdd[hdlv_current_sel].scsi_id = SendMessage(h, CB_GETCURSEL, 0, 0) & 0xff; - hard_disk_track(hdlv_current_sel); - h = GetDlgItem(hdlg, IDC_LIST_HARD_DISKS); - win_settings_hard_disks_update_item(h, hdlv_current_sel, 0); - ignore_change = 0; - return FALSE; - - case IDC_COMBO_HD_LUN: - if (ignore_change) - { - return FALSE; - } - - ignore_change = 1; - h = GetDlgItem(hdlg, IDC_COMBO_HD_LUN); - hard_disk_untrack(hdlv_current_sel); - temp_hdd[hdlv_current_sel].scsi_lun = SendMessage(h, CB_GETCURSEL, 0, 0) & 0xff; - hard_disk_track(hdlv_current_sel); - h = GetDlgItem(hdlg, IDC_LIST_HARD_DISKS); - win_settings_hard_disks_update_item(h, hdlv_current_sel, 0); - ignore_change = 0; - return FALSE; - - case IDC_BUTTON_HDD_ADD: - hard_disk_add_open(hdlg, 1); - if (hard_disk_added) - { - ignore_change = 1; - h = GetDlgItem(hdlg, IDC_LIST_HARD_DISKS); - win_settings_hard_disks_recalc_list(h); - recalc_next_free_id(hdlg); - hard_disk_track_all(); - ignore_change = 0; - } - return FALSE; - - case IDC_BUTTON_HDD_ADD_NEW: - hard_disk_add_open(hdlg, 0); - if (hard_disk_added) - { - ignore_change = 1; - h = GetDlgItem(hdlg, IDC_LIST_HARD_DISKS); - win_settings_hard_disks_recalc_list(h); - recalc_next_free_id(hdlg); - hard_disk_track_all(); - ignore_change = 0; - } - return FALSE; - - case IDC_BUTTON_HDD_REMOVE: - memcpy(temp_hdd[hdlv_current_sel].fn, L"", 4); - hard_disk_untrack(hdlv_current_sel); - temp_hdd[hdlv_current_sel].bus = HDD_BUS_DISABLED; /* Only set the bus to zero, the list normalize code below will take care of turning this entire entry to a complete zero. */ - normalize_hd_list(); /* Normalize the hard disks so that non-disabled hard disks start from index 0, and so they are contiguous. */ - ignore_change = 1; - h = GetDlgItem(hdlg, IDC_LIST_HARD_DISKS); - win_settings_hard_disks_recalc_list(h); - recalc_next_free_id(hdlg); - if (hd_listview_items > 0) - { - ListView_SetItemState(h, 0, LVIS_FOCUSED | LVIS_SELECTED, 0x000F); - hdlv_current_sel = 0; - h = GetDlgItem(hdlg, IDC_COMBO_HD_BUS); - SendMessage(h, CB_SETCURSEL, temp_hdd[0].bus - 1, 0); - } - else - { - hdlv_current_sel = -1; - } - recalc_location_controls(hdlg, 0, 0); - ignore_change = 0; - return FALSE; - } - - default: - return FALSE; - } - - return FALSE; -} - -static int fdlv_current_sel; - -static int cdlv_current_sel; -static int zdlv_current_sel; - -static int combo_id_to_string_id(int combo_id) -{ - return IDS_5376 + combo_id; -} - -static int combo_id_to_format_string_id(int combo_id) -{ - return IDS_5632 + combo_id; -} - -static BOOL win_settings_floppy_drives_image_list_init(HWND hwndList) -{ - HICON hiconItem; - HIMAGELIST hSmall; - - int i = 0; - - hSmall = ImageList_Create(GetSystemMetrics(SM_CXSMICON), - GetSystemMetrics(SM_CYSMICON), - ILC_MASK | ILC_COLOR32, 1, 1); - - for (i = 0; i < 14; i++) - { - hiconItem = LoadIcon(hinstance, (LPCWSTR) fdd_type_to_icon(i)); - ImageList_AddIcon(hSmall, hiconItem); - DestroyIcon(hiconItem); - } - - ListView_SetImageList(hwndList, hSmall, LVSIL_SMALL); - - return TRUE; -} - -static BOOL win_settings_cdrom_drives_image_list_init(HWND hwndList) -{ - HICON hiconItem; - HIMAGELIST hSmall; - - hSmall = ImageList_Create(GetSystemMetrics(SM_CXSMICON), - GetSystemMetrics(SM_CYSMICON), - ILC_MASK | ILC_COLOR32, 1, 1); - - hiconItem = LoadIcon(hinstance, (LPCWSTR) 514); - ImageList_AddIcon(hSmall, hiconItem); - DestroyIcon(hiconItem); - - hiconItem = LoadIcon(hinstance, (LPCWSTR) 160); - ImageList_AddIcon(hSmall, hiconItem); - DestroyIcon(hiconItem); - - ListView_SetImageList(hwndList, hSmall, LVSIL_SMALL); - - return TRUE; -} - -static BOOL win_settings_zip_drives_image_list_init(HWND hwndList) -{ - HICON hiconItem; - HIMAGELIST hSmall; - - hSmall = ImageList_Create(GetSystemMetrics(SM_CXSMICON), - GetSystemMetrics(SM_CYSMICON), - ILC_MASK | ILC_COLOR32, 1, 1); - - hiconItem = LoadIcon(hinstance, (LPCWSTR) 515); - ImageList_AddIcon(hSmall, hiconItem); - DestroyIcon(hiconItem); - - hiconItem = LoadIcon(hinstance, (LPCWSTR) 176); - ImageList_AddIcon(hSmall, hiconItem); - DestroyIcon(hiconItem); - - ListView_SetImageList(hwndList, hSmall, LVSIL_SMALL); - - return TRUE; -} - -static BOOL win_settings_floppy_drives_recalc_list(HWND hwndList) -{ - LVITEM lvI; - int i = 0; - char s[256]; - WCHAR szText[256]; - - lvI.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_STATE; - lvI.stateMask = lvI.state = 0; - - for (i = 0; i < 4; i++) - { - lvI.iSubItem = 0; - if (temp_fdd_types[i] > 0) - { - strcpy(s, fdd_getname(temp_fdd_types[i])); - mbstowcs(szText, s, strlen(s) + 1); - lvI.pszText = szText; - } - else - { - lvI.pszText = plat_get_string(IDS_5376); - } - lvI.iItem = i; - lvI.iImage = temp_fdd_types[i]; - - if (ListView_InsertItem(hwndList, &lvI) == -1) - return FALSE; - - lvI.iSubItem = 1; - lvI.pszText = plat_get_string(temp_fdd_turbo[i] ? IDS_2060 : IDS_2061); - lvI.iItem = i; - lvI.iImage = 0; - - if (ListView_SetItem(hwndList, &lvI) == -1) - { - return FALSE; - } - - lvI.iSubItem = 2; - lvI.pszText = plat_get_string(temp_fdd_check_bpb[i] ? IDS_2060 : IDS_2061); - lvI.iItem = i; - lvI.iImage = 0; - - if (ListView_SetItem(hwndList, &lvI) == -1) - { - return FALSE; - } - } - - return TRUE; -} - -static BOOL win_settings_cdrom_drives_recalc_list(HWND hwndList) -{ - LVITEM lvI; - int i = 0; - WCHAR szText[256]; - int fsid = 0; - - lvI.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_STATE; - lvI.stateMask = lvI.iSubItem = lvI.state = 0; - - for (i = 0; i < 4; i++) - { - fsid = combo_id_to_format_string_id(temp_cdrom_drives[i].bus_type); - - lvI.iSubItem = 0; - switch (temp_cdrom_drives[i].bus_type) - { - case CDROM_BUS_DISABLED: - default: - lvI.pszText = plat_get_string(fsid); - lvI.iImage = 0; - break; - case CDROM_BUS_ATAPI_PIO_ONLY: - swprintf(szText, 255, plat_get_string(fsid), temp_cdrom_drives[i].ide_channel >> 1, temp_cdrom_drives[i].ide_channel & 1); - lvI.pszText = szText; - lvI.iImage = 1; - break; - case CDROM_BUS_ATAPI_PIO_AND_DMA: - swprintf(szText, 255, plat_get_string(fsid), temp_cdrom_drives[i].ide_channel >> 1, temp_cdrom_drives[i].ide_channel & 1); - lvI.pszText = szText; - lvI.iImage = 1; - break; - case CDROM_BUS_SCSI: - swprintf(szText, 255, plat_get_string(fsid), temp_cdrom_drives[i].scsi_device_id, temp_cdrom_drives[i].scsi_device_lun); - lvI.pszText = szText; - lvI.iImage = 1; - break; - } - - lvI.iItem = i; - - if (ListView_InsertItem(hwndList, &lvI) == -1) - return FALSE; - - lvI.iSubItem = 1; - if (temp_cdrom_drives[i].bus_type == CDROM_BUS_DISABLED) - lvI.pszText = plat_get_string(IDS_2152); - else { - wsprintf(szText, L"%ix", - cdrom_speeds[temp_cdrom_drives[i].speed_idx].speed); - lvI.pszText = szText; - } - lvI.iItem = i; - lvI.iImage = 0; - - if (ListView_SetItem(hwndList, &lvI) == -1) - { - return FALSE; - } - } - - return TRUE; -} - -static BOOL win_settings_zip_drives_recalc_list(HWND hwndList) -{ - LVITEM lvI; - int i = 0; - WCHAR szText[256]; - int fsid = 0; - - lvI.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_STATE; - lvI.stateMask = lvI.iSubItem = lvI.state = 0; - - for (i = 0; i < 4; i++) - { - fsid = combo_id_to_format_string_id(temp_zip_drives[i].bus_type); - - lvI.iSubItem = 0; - switch (temp_zip_drives[i].bus_type) - { - case ZIP_BUS_DISABLED: - default: - lvI.pszText = plat_get_string(fsid); - lvI.iImage = 0; - break; - case ZIP_BUS_ATAPI_PIO_ONLY: - swprintf(szText, 255, plat_get_string(fsid), temp_zip_drives[i].ide_channel >> 1, temp_zip_drives[i].ide_channel & 1); - lvI.pszText = szText; - lvI.iImage = 1; - break; - case ZIP_BUS_ATAPI_PIO_AND_DMA: - swprintf(szText, 255, plat_get_string(fsid), temp_zip_drives[i].ide_channel >> 1, temp_zip_drives[i].ide_channel & 1); - lvI.pszText = szText; - lvI.iImage = 1; - break; - case ZIP_BUS_SCSI: - swprintf(szText, 255, plat_get_string(fsid), temp_zip_drives[i].scsi_device_id, temp_zip_drives[i].scsi_device_lun); - lvI.pszText = szText; - lvI.iImage = 1; - break; - } - - lvI.iItem = i; - - if (ListView_InsertItem(hwndList, &lvI) == -1) - return FALSE; - - lvI.iSubItem = 1; - lvI.pszText = plat_get_string(temp_zip_drives[i].is_250 ? IDS_5901 : IDS_5900); - lvI.iItem = i; - lvI.iImage = 0; - - if (ListView_SetItem(hwndList, &lvI) == -1) - { - return FALSE; - } - } - - return TRUE; -} - -static BOOL win_settings_floppy_drives_init_columns(HWND hwndList) -{ - LVCOLUMN lvc; - - lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM; - - lvc.iSubItem = 0; - lvc.pszText = plat_get_string(IDS_2143); - - lvc.cx = 292; - lvc.fmt = LVCFMT_LEFT; - - if (ListView_InsertColumn(hwndList, 0, &lvc) == -1) - { - return FALSE; - } - - lvc.iSubItem = 1; - lvc.pszText = plat_get_string(IDS_2059); - - lvc.cx = 50; - lvc.fmt = LVCFMT_LEFT; - - if (ListView_InsertColumn(hwndList, 1, &lvc) == -1) - { - return FALSE; - } - - lvc.iSubItem = 2; - lvc.pszText = plat_get_string(IDS_2170); - - lvc.cx = 75; - lvc.fmt = LVCFMT_LEFT; - - if (ListView_InsertColumn(hwndList, 2, &lvc) == -1) - { - return FALSE; - } - return TRUE; -} - -static BOOL win_settings_cdrom_drives_init_columns(HWND hwndList) -{ - LVCOLUMN lvc; - - lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM; - - lvc.iSubItem = 0; - lvc.pszText = plat_get_string(IDS_2082); - - lvc.cx = 342; - lvc.fmt = LVCFMT_LEFT; - - if (ListView_InsertColumn(hwndList, 0, &lvc) == -1) - { - return FALSE; - } - - lvc.iSubItem = 1; - lvc.pszText = plat_get_string(IDS_2179); - - lvc.cx = 50; - lvc.fmt = LVCFMT_LEFT; - - if (ListView_InsertColumn(hwndList, 1, &lvc) == -1) - { - return FALSE; - } - - return TRUE; -} - -static BOOL win_settings_zip_drives_init_columns(HWND hwndList) -{ - LVCOLUMN lvc; - - lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM; - - lvc.iSubItem = 0; - lvc.pszText = plat_get_string(IDS_2082); - - lvc.cx = 342; - lvc.fmt = LVCFMT_LEFT; - - if (ListView_InsertColumn(hwndList, 0, &lvc) == -1) - { - return FALSE; - } - - lvc.iSubItem = 1; - lvc.pszText = plat_get_string(IDS_2143); - - lvc.cx = 50; - lvc.fmt = LVCFMT_LEFT; - - if (ListView_InsertColumn(hwndList, 1, &lvc) == -1) - { - return FALSE; - } - - return TRUE; -} - -static int get_selected_floppy_drive(HWND hdlg) -{ - int floppy_drive = -1; - int i, j = 0; - HWND h; - - for (i = 0; i < 6; i++) - { - h = GetDlgItem(hdlg, IDC_LIST_FLOPPY_DRIVES); - j = ListView_GetItemState(h, i, LVIS_SELECTED); - if (j) - { - floppy_drive = i; - } - } - - return floppy_drive; -} - -static int get_selected_cdrom_drive(HWND hdlg) -{ - int cd_drive = -1; - int i, j = 0; - HWND h; - - for (i = 0; i < 6; i++) - { - h = GetDlgItem(hdlg, IDC_LIST_CDROM_DRIVES); - j = ListView_GetItemState(h, i, LVIS_SELECTED); - if (j) - { - cd_drive = i; - } - } - - return cd_drive; -} - -static int get_selected_zip_drive(HWND hdlg) -{ - int zip_disk_drive = -1; - int i, j = 0; - HWND h; - - for (i = 0; i < 6; i++) - { - h = GetDlgItem(hdlg, IDC_LIST_ZIP_DRIVES); - j = ListView_GetItemState(h, i, LVIS_SELECTED); - if (j) - { - zip_disk_drive = i; - } - } - - return zip_disk_drive; -} - -static void win_settings_floppy_drives_update_item(HWND hwndList, int i) -{ - LVITEM lvI; - char s[256]; - WCHAR szText[256]; - - lvI.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_STATE; - lvI.stateMask = lvI.iSubItem = lvI.state = 0; - - lvI.iSubItem = 0; - lvI.iItem = i; - - if (temp_fdd_types[i] > 0) - { - strcpy(s, fdd_getname(temp_fdd_types[i])); - mbstowcs(szText, s, strlen(s) + 1); - lvI.pszText = szText; - } - else - { - lvI.pszText = plat_get_string(IDS_5376); - } - lvI.iImage = temp_fdd_types[i]; - - if (ListView_SetItem(hwndList, &lvI) == -1) - { - return; - } - - lvI.iSubItem = 1; - lvI.pszText = plat_get_string(temp_fdd_turbo[i] ? IDS_2060 : IDS_2061); - lvI.iItem = i; - lvI.iImage = 0; - - if (ListView_SetItem(hwndList, &lvI) == -1) - { - return; - } - - lvI.iSubItem = 2; - lvI.pszText = plat_get_string(temp_fdd_check_bpb[i] ? IDS_2060 : IDS_2061); - lvI.iItem = i; - lvI.iImage = 0; - - if (ListView_SetItem(hwndList, &lvI) == -1) - { - return; - } -} - -static void win_settings_cdrom_drives_update_item(HWND hwndList, int i) -{ - LVITEM lvI; - WCHAR szText[256]; - int fsid; - - lvI.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_STATE; - lvI.stateMask = lvI.iSubItem = lvI.state = 0; - - lvI.iSubItem = 0; - lvI.iItem = i; - - fsid = combo_id_to_format_string_id(temp_cdrom_drives[i].bus_type); - - switch (temp_cdrom_drives[i].bus_type) - { - case CDROM_BUS_DISABLED: - default: - lvI.pszText = plat_get_string(fsid); - lvI.iImage = 0; - break; - case CDROM_BUS_ATAPI_PIO_ONLY: - swprintf(szText, 255, plat_get_string(fsid), temp_cdrom_drives[i].ide_channel >> 1, temp_cdrom_drives[i].ide_channel & 1); - lvI.pszText = szText; - lvI.iImage = 1; - break; - case CDROM_BUS_ATAPI_PIO_AND_DMA: - swprintf(szText, 255, plat_get_string(fsid), temp_cdrom_drives[i].ide_channel >> 1, temp_cdrom_drives[i].ide_channel & 1); - lvI.pszText = szText; - lvI.iImage = 1; - break; - case CDROM_BUS_SCSI: - swprintf(szText, 255, plat_get_string(fsid), temp_cdrom_drives[i].scsi_device_id, temp_cdrom_drives[i].scsi_device_lun); - lvI.pszText = szText; - lvI.iImage = 1; - break; - } - - if (ListView_SetItem(hwndList, &lvI) == -1) - { - return; - } - - lvI.iSubItem = 1; - if (temp_cdrom_drives[i].bus_type == CDROM_BUS_DISABLED) - lvI.pszText = plat_get_string(IDS_2152); - else { - wsprintf(szText, L"%ix", - cdrom_speeds[temp_cdrom_drives[i].speed_idx].speed); - lvI.pszText = szText; - } - lvI.iItem = i; - lvI.iImage = 0; - - if (ListView_SetItem(hwndList, &lvI) == -1) - { - return; - } -} - -static void win_settings_zip_drives_update_item(HWND hwndList, int i) -{ - LVITEM lvI; - WCHAR szText[256]; - int fsid; - - lvI.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_STATE; - lvI.stateMask = lvI.iSubItem = lvI.state = 0; - - lvI.iSubItem = 0; - lvI.iItem = i; - - fsid = combo_id_to_format_string_id(temp_zip_drives[i].bus_type); - - switch (temp_zip_drives[i].bus_type) - { - case ZIP_BUS_DISABLED: - default: - lvI.pszText = plat_get_string(fsid); - lvI.iImage = 0; - break; - case ZIP_BUS_ATAPI_PIO_ONLY: - swprintf(szText, 255, plat_get_string(fsid), temp_zip_drives[i].ide_channel >> 1, temp_zip_drives[i].ide_channel & 1); - lvI.pszText = szText; - lvI.iImage = 1; - break; - case ZIP_BUS_ATAPI_PIO_AND_DMA: - swprintf(szText, 255, plat_get_string(fsid), temp_zip_drives[i].ide_channel >> 1, temp_zip_drives[i].ide_channel & 1); - lvI.pszText = szText; - lvI.iImage = 1; - break; - case ZIP_BUS_SCSI: - swprintf(szText, 255, plat_get_string(fsid), temp_zip_drives[i].scsi_device_id, temp_zip_drives[i].scsi_device_lun); - lvI.pszText = szText; - lvI.iImage = 1; - break; - } - - if (ListView_SetItem(hwndList, &lvI) == -1) - { - return; - } - - lvI.iSubItem = 1; - lvI.pszText = plat_get_string(temp_zip_drives[i].is_250 ? IDS_5901 : IDS_5900); - lvI.iItem = i; - lvI.iImage = 0; - - if (ListView_SetItem(hwndList, &lvI) == -1) - { - return; - } -} - -static void cdrom_add_locations(HWND hdlg) -{ - LPTSTR lptsTemp; - HWND h; - int i = 0; - - lptsTemp = (LPTSTR) malloc(512); - - h = GetDlgItem(hdlg, IDC_COMBO_CD_BUS); - for (i = CDROM_BUS_DISABLED; i <= CDROM_BUS_SCSI; i++) - { - if ((i == CDROM_BUS_DISABLED) || (i >= CDROM_BUS_ATAPI_PIO_ONLY)) - { - SendMessage(h, CB_ADDSTRING, 0, (LPARAM)plat_get_string(combo_id_to_string_id(i))); - } - } - - /* Create a list of usable CD-ROM speeds. */ - h = GetDlgItem(hdlg, IDC_COMBO_CD_SPEED); - for (i = 0; cdrom_speeds[i].speed > 0; i++) - { - wsprintf(lptsTemp, L"%ix", cdrom_speeds[i]); - SendMessage(h, CB_ADDSTRING, 0, (LPARAM) lptsTemp); - } - - h = GetDlgItem(hdlg, IDC_COMBO_CD_ID); - for (i = 0; i < 16; i++) - { - swprintf(lptsTemp, 511, plat_get_string(IDS_4098), i); - SendMessage(h, CB_ADDSTRING, 0, (LPARAM) lptsTemp); - } - - h = GetDlgItem(hdlg, IDC_COMBO_CD_LUN); - for (i = 0; i < 8; i++) - { - swprintf(lptsTemp, 511, plat_get_string(IDS_4098), i); - SendMessage(h, CB_ADDSTRING, 0, (LPARAM) lptsTemp); - } - - h = GetDlgItem(hdlg, IDC_COMBO_CD_CHANNEL_IDE); - for (i = 0; i < 8; i++) - { - swprintf(lptsTemp, 511, plat_get_string(IDS_4097), i >> 1, i & 1); - SendMessage(h, CB_ADDSTRING, 0, (LPARAM) lptsTemp); - } - - free(lptsTemp); -} - -static void cdrom_recalc_location_controls(HWND hdlg, int assign_id) -{ - int i = 0; - HWND h; - - int bus = temp_cdrom_drives[cdlv_current_sel].bus_type; - - for (i = IDT_1741; i < (IDT_1743 + 1); i++) - { - h = GetDlgItem(hdlg, i); - EnableWindow(h, FALSE); - ShowWindow(h, SW_HIDE); - } - - h = GetDlgItem(hdlg, IDC_COMBO_CD_ID); - EnableWindow(h, FALSE); - ShowWindow(h, SW_HIDE); - - h = GetDlgItem(hdlg, IDC_COMBO_CD_LUN); - EnableWindow(h, FALSE); - ShowWindow(h, SW_HIDE); - - h = GetDlgItem(hdlg, IDC_COMBO_CD_CHANNEL_IDE); - EnableWindow(h, FALSE); - ShowWindow(h, SW_HIDE); - - h = GetDlgItem(hdlg, IDC_COMBO_CD_SPEED); - if (bus == CDROM_BUS_DISABLED) { - EnableWindow(h, FALSE); - ShowWindow(h, SW_HIDE); - } else { - ShowWindow(h, SW_SHOW); - EnableWindow(h, TRUE); - SendMessage(h, CB_SETCURSEL, temp_cdrom_drives[cdlv_current_sel].speed_idx, 0); - } - - switch(bus) - { - case CDROM_BUS_ATAPI_PIO_ONLY: /* ATAPI (PIO-only) */ - case CDROM_BUS_ATAPI_PIO_AND_DMA: /* ATAPI (PIO and DMA) */ - h = GetDlgItem(hdlg, IDT_1743); - ShowWindow(h, SW_SHOW); - EnableWindow(h, TRUE); - - if (assign_id) - temp_cdrom_drives[cdlv_current_sel].ide_channel = next_free_ide_channel(); - - h = GetDlgItem(hdlg, IDC_COMBO_CD_CHANNEL_IDE); - ShowWindow(h, SW_SHOW); - EnableWindow(h, TRUE); - SendMessage(h, CB_SETCURSEL, temp_cdrom_drives[cdlv_current_sel].ide_channel, 0); - break; - case CDROM_BUS_SCSI: /* SCSI */ - h = GetDlgItem(hdlg, IDT_1741); - ShowWindow(h, SW_SHOW); - EnableWindow(h, TRUE); - h = GetDlgItem(hdlg, IDT_1742); - ShowWindow(h, SW_SHOW); - EnableWindow(h, TRUE); - - if (assign_id) - next_free_scsi_id_and_lun((uint8_t *) &temp_cdrom_drives[cdlv_current_sel].scsi_device_id, (uint8_t *) &temp_cdrom_drives[cdlv_current_sel].scsi_device_lun); - - h = GetDlgItem(hdlg, IDC_COMBO_CD_ID); - ShowWindow(h, SW_SHOW); - EnableWindow(h, TRUE); - SendMessage(h, CB_SETCURSEL, temp_cdrom_drives[cdlv_current_sel].scsi_device_id, 0); - - h = GetDlgItem(hdlg, IDC_COMBO_CD_LUN); - ShowWindow(h, SW_SHOW); - EnableWindow(h, TRUE); - SendMessage(h, CB_SETCURSEL, temp_cdrom_drives[cdlv_current_sel].scsi_device_lun, 0); - break; - } -} - -static void zip_add_locations(HWND hdlg) -{ - LPTSTR lptsTemp; - HWND h; - int i = 0; - - lptsTemp = (LPTSTR) malloc(512); - - h = GetDlgItem(hdlg, IDC_COMBO_ZIP_BUS); - for (i = ZIP_BUS_DISABLED; i <= ZIP_BUS_SCSI; i++) - { - if ((i == ZIP_BUS_DISABLED) || (i >= ZIP_BUS_ATAPI_PIO_ONLY)) - { - SendMessage(h, CB_ADDSTRING, 0, (LPARAM)plat_get_string(combo_id_to_string_id(i))); - } - } - - h = GetDlgItem(hdlg, IDC_COMBO_ZIP_ID); - for (i = 0; i < 16; i++) - { - swprintf(lptsTemp, 511, plat_get_string(IDS_4098), i); - SendMessage(h, CB_ADDSTRING, 0, (LPARAM) lptsTemp); - } - - h = GetDlgItem(hdlg, IDC_COMBO_ZIP_LUN); - for (i = 0; i < 8; i++) - { - swprintf(lptsTemp, 511, plat_get_string(IDS_4098), i); - SendMessage(h, CB_ADDSTRING, 0, (LPARAM) lptsTemp); - } - - h = GetDlgItem(hdlg, IDC_COMBO_ZIP_CHANNEL_IDE); - for (i = 0; i < 8; i++) - { - swprintf(lptsTemp, 511, plat_get_string(IDS_4097), i >> 1, i & 1); - SendMessage(h, CB_ADDSTRING, 0, (LPARAM) lptsTemp); - } - - free(lptsTemp); -} - -static void zip_recalc_location_controls(HWND hdlg, int assign_id) -{ - int i = 0; - HWND h; - - int bus = temp_zip_drives[zdlv_current_sel].bus_type; - - for (i = IDT_1754; i < (IDT_1756 + 1); i++) - { - h = GetDlgItem(hdlg, i); - EnableWindow(h, FALSE); - ShowWindow(h, SW_HIDE); - } - - h = GetDlgItem(hdlg, IDC_COMBO_ZIP_ID); - EnableWindow(h, FALSE); - ShowWindow(h, SW_HIDE); - - h = GetDlgItem(hdlg, IDC_COMBO_ZIP_LUN); - EnableWindow(h, FALSE); - ShowWindow(h, SW_HIDE); - - h = GetDlgItem(hdlg, IDC_COMBO_ZIP_CHANNEL_IDE); - EnableWindow(h, FALSE); - ShowWindow(h, SW_HIDE); - - switch(bus) - { - case ZIP_BUS_ATAPI_PIO_ONLY: /* ATAPI (PIO-only) */ - case ZIP_BUS_ATAPI_PIO_AND_DMA: /* ATAPI (PIO and DMA) */ - h = GetDlgItem(hdlg, IDT_1756); - ShowWindow(h, SW_SHOW); - EnableWindow(h, TRUE); - - if (assign_id) - temp_zip_drives[zdlv_current_sel].ide_channel = next_free_ide_channel(); - - h = GetDlgItem(hdlg, IDC_COMBO_ZIP_CHANNEL_IDE); - ShowWindow(h, SW_SHOW); - EnableWindow(h, TRUE); - SendMessage(h, CB_SETCURSEL, temp_zip_drives[zdlv_current_sel].ide_channel, 0); - break; - case ZIP_BUS_SCSI: /* SCSI */ - h = GetDlgItem(hdlg, IDT_1754); - ShowWindow(h, SW_SHOW); - EnableWindow(h, TRUE); - h = GetDlgItem(hdlg, IDT_1755); - ShowWindow(h, SW_SHOW); - EnableWindow(h, TRUE); - - if (assign_id) - next_free_scsi_id_and_lun((uint8_t *) &temp_zip_drives[zdlv_current_sel].scsi_device_id, (uint8_t *) &temp_zip_drives[zdlv_current_sel].scsi_device_lun); - - h = GetDlgItem(hdlg, IDC_COMBO_ZIP_ID); - ShowWindow(h, SW_SHOW); - EnableWindow(h, TRUE); - SendMessage(h, CB_SETCURSEL, temp_zip_drives[zdlv_current_sel].scsi_device_id, 0); - - h = GetDlgItem(hdlg, IDC_COMBO_ZIP_LUN); - ShowWindow(h, SW_SHOW); - EnableWindow(h, TRUE); - SendMessage(h, CB_SETCURSEL, temp_zip_drives[zdlv_current_sel].scsi_device_lun, 0); - break; - } -} - - -static void cdrom_track(uint8_t id) -{ - if ((temp_cdrom_drives[id].bus_type == CDROM_BUS_ATAPI_PIO_ONLY) || (temp_cdrom_drives[id].bus_type == CDROM_BUS_ATAPI_PIO_ONLY)) - ide_tracking |= (2 << (temp_cdrom_drives[id].ide_channel << 3)); - else if (temp_cdrom_drives[id].bus_type == CDROM_BUS_SCSI) - scsi_tracking[temp_cdrom_drives[id].scsi_device_id] |= (1ULL << temp_cdrom_drives[id].scsi_device_lun); -} - -static void cdrom_untrack(uint8_t id) -{ - if ((temp_cdrom_drives[id].bus_type == CDROM_BUS_ATAPI_PIO_ONLY) || (temp_cdrom_drives[id].bus_type == CDROM_BUS_ATAPI_PIO_ONLY)) - ide_tracking &= ~(2 << (temp_cdrom_drives[id].ide_channel << 3)); - else if (temp_cdrom_drives[id].bus_type == CDROM_BUS_SCSI) - scsi_tracking[temp_cdrom_drives[id].scsi_device_id] &= ~(1ULL << temp_cdrom_drives[id].scsi_device_lun); -} - -#if 0 -static void cdrom_track_all(void) -{ - int i; - - for (i = 0; i < CDROM_NUM; i++) - cdrom_track(i); -} -#endif - - -static void zip_track(uint8_t id) -{ - if ((temp_zip_drives[id].bus_type == ZIP_BUS_ATAPI_PIO_ONLY) || (temp_zip_drives[id].bus_type == ZIP_BUS_ATAPI_PIO_ONLY)) - ide_tracking |= (1ULL << temp_zip_drives[id].ide_channel); - else if (temp_zip_drives[id].bus_type == ZIP_BUS_SCSI) - scsi_tracking[temp_zip_drives[id].scsi_device_id] |= (1ULL << temp_zip_drives[id].scsi_device_lun); -} - -static void zip_untrack(uint8_t id) -{ - if ((temp_zip_drives[id].bus_type == ZIP_BUS_ATAPI_PIO_ONLY) || (temp_zip_drives[id].bus_type == ZIP_BUS_ATAPI_PIO_ONLY)) - ide_tracking &= ~(1ULL << temp_zip_drives[id].ide_channel); - else if (temp_zip_drives[id].bus_type == ZIP_BUS_SCSI) - scsi_tracking[temp_zip_drives[id].scsi_device_id] &= ~(1ULL << temp_zip_drives[id].scsi_device_lun); -} - -#if 0 -static void zip_track_all(void) -{ - int i; - - for (i = 0; i < ZIP_NUM; i++) - zip_track(i); -} -#endif - - -int fd_ignore_change = 0; - -#ifdef __amd64__ -static LRESULT CALLBACK -#else -static BOOL CALLBACK -#endif -floppy_drives_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) -{ - HWND h = INVALID_HANDLE_VALUE; - int i = 0; - int old_sel = 0; - WCHAR szText[256]; - - switch (message) - { - case WM_INITDIALOG: - fd_ignore_change = 1; - - fdlv_current_sel = 0; - h = GetDlgItem(hdlg, IDC_LIST_FLOPPY_DRIVES); - win_settings_floppy_drives_init_columns(h); - win_settings_floppy_drives_image_list_init(h); - win_settings_floppy_drives_recalc_list(h); - ListView_SetItemState(h, 0, LVIS_FOCUSED | LVIS_SELECTED, 0x000F); - h = GetDlgItem(hdlg, IDC_COMBO_FD_TYPE); - for (i = 0; i < 14; i++) - { - if (i == 0) - { - SendMessage(h, CB_ADDSTRING, 0, (LPARAM)plat_get_string(IDS_5376)); - } - else - { - mbstowcs(szText, fdd_getname(i), strlen(fdd_getname(i)) + 1); - SendMessage(h, CB_ADDSTRING, 0, (LPARAM) szText); - } - } - SendMessage(h, CB_SETCURSEL, temp_fdd_types[fdlv_current_sel], 0); - - h = GetDlgItem(hdlg, IDC_CHECKTURBO); - SendMessage(h, BM_SETCHECK, temp_fdd_turbo[fdlv_current_sel], 0); - - h = GetDlgItem(hdlg, IDC_CHECKBPB); - SendMessage(h, BM_SETCHECK, temp_fdd_check_bpb[fdlv_current_sel], 0); - - fd_ignore_change = 0; - return TRUE; - - case WM_NOTIFY: - if (fd_ignore_change) - { - return FALSE; - } - - if ((((LPNMHDR)lParam)->code == LVN_ITEMCHANGED) && (((LPNMHDR)lParam)->idFrom == IDC_LIST_FLOPPY_DRIVES)) - { - old_sel = fdlv_current_sel; - fdlv_current_sel = get_selected_floppy_drive(hdlg); - if (fdlv_current_sel == old_sel) - { - return FALSE; - } - else if (fdlv_current_sel == -1) - { - fd_ignore_change = 1; - fdlv_current_sel = old_sel; - ListView_SetItemState(h, fdlv_current_sel, LVIS_FOCUSED | LVIS_SELECTED, 0x000F); - fd_ignore_change = 0; - return FALSE; - } - fd_ignore_change = 1; - h = GetDlgItem(hdlg, IDC_COMBO_FD_TYPE); - SendMessage(h, CB_SETCURSEL, temp_fdd_types[fdlv_current_sel], 0); - h = GetDlgItem(hdlg, IDC_CHECKTURBO); - SendMessage(h, BM_SETCHECK, temp_fdd_turbo[fdlv_current_sel], 0); - h = GetDlgItem(hdlg, IDC_CHECKBPB); - SendMessage(h, BM_SETCHECK, temp_fdd_check_bpb[fdlv_current_sel], 0); - fd_ignore_change = 0; - } - break; - - case WM_COMMAND: - switch (LOWORD(wParam)) - { - case IDC_COMBO_FD_TYPE: - if (fd_ignore_change) - { - return FALSE; - } - - fd_ignore_change = 1; - h = GetDlgItem(hdlg, IDC_COMBO_FD_TYPE); - temp_fdd_types[fdlv_current_sel] = SendMessage(h, CB_GETCURSEL, 0, 0); - h = GetDlgItem(hdlg, IDC_LIST_FLOPPY_DRIVES); - win_settings_floppy_drives_update_item(h, fdlv_current_sel); - fd_ignore_change = 0; - return FALSE; - - case IDC_CHECKTURBO: - if (fd_ignore_change) - { - return FALSE; - } - - fd_ignore_change = 1; - h = GetDlgItem(hdlg, IDC_CHECKTURBO); - temp_fdd_turbo[fdlv_current_sel] = SendMessage(h, BM_GETCHECK, 0, 0); - h = GetDlgItem(hdlg, IDC_LIST_FLOPPY_DRIVES); - win_settings_floppy_drives_update_item(h, fdlv_current_sel); - fd_ignore_change = 0; - return FALSE; - - case IDC_CHECKBPB: - if (fd_ignore_change) - { - return FALSE; - } - - fd_ignore_change = 1; - h = GetDlgItem(hdlg, IDC_CHECKBPB); - temp_fdd_check_bpb[fdlv_current_sel] = SendMessage(h, BM_GETCHECK, 0, 0); - h = GetDlgItem(hdlg, IDC_LIST_FLOPPY_DRIVES); - win_settings_floppy_drives_update_item(h, fdlv_current_sel); - fd_ignore_change = 0; - return FALSE; - } - - default: - return FALSE; - } - - return FALSE; -} - -int rd_ignore_change = 0; - -#ifdef __amd64__ -static LRESULT CALLBACK -#else -static BOOL CALLBACK -#endif -other_removable_devices_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) -{ - HWND h = INVALID_HANDLE_VALUE; - int old_sel = 0; - int b = 0; - int b2 = 0; - int assign = 0; - - switch (message) - { - case WM_INITDIALOG: - rd_ignore_change = 1; - - cdlv_current_sel = 0; - h = GetDlgItem(hdlg, IDC_LIST_CDROM_DRIVES); - win_settings_cdrom_drives_init_columns(h); - win_settings_cdrom_drives_image_list_init(h); - win_settings_cdrom_drives_recalc_list(h); - ListView_SetItemState(h, 0, LVIS_FOCUSED | LVIS_SELECTED, 0x000F); - cdrom_add_locations(hdlg); - - h = GetDlgItem(hdlg, IDC_COMBO_CD_BUS); - - switch (temp_cdrom_drives[cdlv_current_sel].bus_type) - { - case CDROM_BUS_DISABLED: - default: - b = 0; - break; - case CDROM_BUS_ATAPI_PIO_ONLY: - b = 1; - break; - case CDROM_BUS_ATAPI_PIO_AND_DMA: - b = 2; - break; - case CDROM_BUS_SCSI: - b = 3; - break; - } - - SendMessage(h, CB_SETCURSEL, b, 0); - - cdrom_recalc_location_controls(hdlg, 0); - - zdlv_current_sel = 0; - h = GetDlgItem(hdlg, IDC_LIST_ZIP_DRIVES); - win_settings_zip_drives_init_columns(h); - win_settings_zip_drives_image_list_init(h); - win_settings_zip_drives_recalc_list(h); - ListView_SetItemState(h, 0, LVIS_FOCUSED | LVIS_SELECTED, 0x000F); - zip_add_locations(hdlg); - - h = GetDlgItem(hdlg, IDC_COMBO_ZIP_BUS); - - switch (temp_zip_drives[zdlv_current_sel].bus_type) - { - case ZIP_BUS_DISABLED: - default: - b = 0; - break; - case ZIP_BUS_ATAPI_PIO_ONLY: - b = 1; - break; - case ZIP_BUS_ATAPI_PIO_AND_DMA: - b = 2; - break; - case ZIP_BUS_SCSI: - b = 3; - break; - } - - SendMessage(h, CB_SETCURSEL, b, 0); - - zip_recalc_location_controls(hdlg, 0); - - h = GetDlgItem(hdlg, IDC_CHECK250); - SendMessage(h, BM_SETCHECK, temp_zip_drives[zdlv_current_sel].is_250, 0); - - rd_ignore_change = 0; - return TRUE; - - case WM_NOTIFY: - if (rd_ignore_change) - { - return FALSE; - } - - if ((((LPNMHDR)lParam)->code == LVN_ITEMCHANGED) && (((LPNMHDR)lParam)->idFrom == IDC_LIST_CDROM_DRIVES)) - { - old_sel = cdlv_current_sel; - cdlv_current_sel = get_selected_cdrom_drive(hdlg); - if (cdlv_current_sel == old_sel) - { - return FALSE; - } - else if (cdlv_current_sel == -1) - { - rd_ignore_change = 1; - cdlv_current_sel = old_sel; - ListView_SetItemState(h, cdlv_current_sel, LVIS_FOCUSED | LVIS_SELECTED, 0x000F); - rd_ignore_change = 0; - return FALSE; - } - rd_ignore_change = 1; - - h = GetDlgItem(hdlg, IDC_COMBO_CD_BUS); - - switch (temp_cdrom_drives[cdlv_current_sel].bus_type) - { - case CDROM_BUS_DISABLED: - default: - b = 0; - break; - case CDROM_BUS_ATAPI_PIO_ONLY: - b = 1; - break; - case CDROM_BUS_ATAPI_PIO_AND_DMA: - b = 2; - break; - case CDROM_BUS_SCSI: - b = 3; - break; - } - - SendMessage(h, CB_SETCURSEL, b, 0); - - cdrom_recalc_location_controls(hdlg, 0); - rd_ignore_change = 0; - } - else if ((((LPNMHDR)lParam)->code == LVN_ITEMCHANGED) && (((LPNMHDR)lParam)->idFrom == IDC_LIST_ZIP_DRIVES)) - { - old_sel = zdlv_current_sel; - zdlv_current_sel = get_selected_zip_drive(hdlg); - if (zdlv_current_sel == old_sel) - { - return FALSE; - } - else if (zdlv_current_sel == -1) - { - rd_ignore_change = 1; - zdlv_current_sel = old_sel; - ListView_SetItemState(h, zdlv_current_sel, LVIS_FOCUSED | LVIS_SELECTED, 0x000F); - rd_ignore_change = 0; - return FALSE; - } - rd_ignore_change = 1; - - h = GetDlgItem(hdlg, IDC_COMBO_ZIP_BUS); - - switch (temp_zip_drives[zdlv_current_sel].bus_type) - { - case ZIP_BUS_DISABLED: - default: - b = 0; - break; - case ZIP_BUS_ATAPI_PIO_ONLY: - b = 1; - break; - case ZIP_BUS_ATAPI_PIO_AND_DMA: - b = 2; - break; - case ZIP_BUS_SCSI: - b = 3; - break; - } - - SendMessage(h, CB_SETCURSEL, b, 0); - - zip_recalc_location_controls(hdlg, 0); - - h = GetDlgItem(hdlg, IDC_CHECK250); - SendMessage(h, BM_SETCHECK, temp_zip_drives[zdlv_current_sel].is_250, 0); - - rd_ignore_change = 0; - } - break; - - case WM_COMMAND: - switch (LOWORD(wParam)) - { - case IDC_COMBO_CD_BUS: - if (rd_ignore_change) - { - return FALSE; - } - - rd_ignore_change = 1; - h = GetDlgItem(hdlg, IDC_COMBO_CD_BUS); - b = SendMessage(h, CB_GETCURSEL, 0, 0); - switch (b) - { - case 0: - b2 = CDROM_BUS_DISABLED; - break; - case 1: - b2 = CDROM_BUS_ATAPI_PIO_ONLY; - break; - case 2: - b2 = CDROM_BUS_ATAPI_PIO_AND_DMA; - break; - case 3: - b2 = CDROM_BUS_SCSI; - break; - } - if (b2 == temp_cdrom_drives[cdlv_current_sel].bus_type) - { - goto cdrom_bus_skip; - } - cdrom_untrack(cdlv_current_sel); - assign = (temp_cdrom_drives[cdlv_current_sel].bus_type == b2) ? 0 : 1; - if (temp_cdrom_drives[cdlv_current_sel].bus_type == CDROM_BUS_DISABLED) - temp_cdrom_drives[cdlv_current_sel].speed_idx = cdrom_speed_idx(cdrom_speed_idx(CDROM_SPEED_DEFAULT)); - if ((b2 == CDROM_BUS_ATAPI_PIO_ONLY) && (temp_cdrom_drives[cdlv_current_sel].bus_type == CDROM_BUS_ATAPI_PIO_AND_DMA)) - assign = 0; - else if ((b2 == CDROM_BUS_ATAPI_PIO_AND_DMA) && (temp_cdrom_drives[cdlv_current_sel].bus_type == CDROM_BUS_ATAPI_PIO_ONLY)) - assign = 0; - temp_cdrom_drives[cdlv_current_sel].bus_type = b2; - cdrom_recalc_location_controls(hdlg, assign); - cdrom_track(cdlv_current_sel); - h = GetDlgItem(hdlg, IDC_LIST_CDROM_DRIVES); - win_settings_cdrom_drives_update_item(h, cdlv_current_sel); -cdrom_bus_skip: - rd_ignore_change = 0; - return FALSE; - - case IDC_COMBO_CD_ID: - if (rd_ignore_change) - { - return FALSE; - } - - rd_ignore_change = 1; - h = GetDlgItem(hdlg, IDC_COMBO_CD_ID); - cdrom_untrack(cdlv_current_sel); - temp_cdrom_drives[cdlv_current_sel].scsi_device_id = SendMessage(h, CB_GETCURSEL, 0, 0); - cdrom_track(cdlv_current_sel); - h = GetDlgItem(hdlg, IDC_LIST_CDROM_DRIVES); - win_settings_cdrom_drives_update_item(h, cdlv_current_sel); - rd_ignore_change = 0; - return FALSE; - - case IDC_COMBO_CD_LUN: - if (rd_ignore_change) - { - return FALSE; - } - - rd_ignore_change = 1; - h = GetDlgItem(hdlg, IDC_COMBO_CD_LUN); - cdrom_untrack(cdlv_current_sel); - temp_cdrom_drives[cdlv_current_sel].scsi_device_lun = SendMessage(h, CB_GETCURSEL, 0, 0); - cdrom_track(cdlv_current_sel); - h = GetDlgItem(hdlg, IDC_LIST_CDROM_DRIVES); - win_settings_cdrom_drives_update_item(h, cdlv_current_sel); - rd_ignore_change = 0; - return FALSE; - - case IDC_COMBO_CD_CHANNEL_IDE: - if (rd_ignore_change) - { - return FALSE; - } - - rd_ignore_change = 1; - h = GetDlgItem(hdlg, IDC_COMBO_CD_CHANNEL_IDE); - cdrom_untrack(cdlv_current_sel); - temp_cdrom_drives[cdlv_current_sel].ide_channel = SendMessage(h, CB_GETCURSEL, 0, 0) & 0xff; - cdrom_track(cdlv_current_sel); - h = GetDlgItem(hdlg, IDC_LIST_CDROM_DRIVES); - win_settings_cdrom_drives_update_item(h, cdlv_current_sel); - rd_ignore_change = 0; - return FALSE; - - case IDC_COMBO_CD_SPEED: - if (rd_ignore_change) - { - return FALSE; - } - - rd_ignore_change = 1; - h = GetDlgItem(hdlg, IDC_COMBO_CD_SPEED); - temp_cdrom_drives[cdlv_current_sel].speed_idx = (uint8_t)SendMessage(h, CB_GETCURSEL, 0, 0); - h = GetDlgItem(hdlg, IDC_LIST_CDROM_DRIVES); - win_settings_cdrom_drives_update_item(h, cdlv_current_sel); - rd_ignore_change = 0; - return FALSE; - - case IDC_COMBO_ZIP_BUS: - if (rd_ignore_change) - { - return FALSE; - } - - rd_ignore_change = 1; - h = GetDlgItem(hdlg, IDC_COMBO_ZIP_BUS); - b = SendMessage(h, CB_GETCURSEL, 0, 0); - switch (b) - { - case 0: - b2 = ZIP_BUS_DISABLED; - break; - case 1: - b2 = ZIP_BUS_ATAPI_PIO_ONLY; - break; - case 2: - b2 = ZIP_BUS_ATAPI_PIO_AND_DMA; - break; - case 3: - b2 = ZIP_BUS_SCSI; - break; - } - if (b2 == temp_zip_drives[zdlv_current_sel].bus_type) - { - goto zip_bus_skip; - } - zip_untrack(zdlv_current_sel); - assign = (temp_zip_drives[zdlv_current_sel].bus_type == b2) ? 0 : 1; - if ((b2 == ZIP_BUS_ATAPI_PIO_ONLY) && (temp_zip_drives[zdlv_current_sel].bus_type == ZIP_BUS_ATAPI_PIO_AND_DMA)) - assign = 0; - else if ((b2 == ZIP_BUS_ATAPI_PIO_AND_DMA) && (temp_zip_drives[cdlv_current_sel].bus_type == ZIP_BUS_ATAPI_PIO_ONLY)) - assign = 0; - temp_zip_drives[zdlv_current_sel].bus_type = b2; - zip_recalc_location_controls(hdlg, assign); - zip_track(zdlv_current_sel); - h = GetDlgItem(hdlg, IDC_LIST_ZIP_DRIVES); - win_settings_zip_drives_update_item(h, zdlv_current_sel); -zip_bus_skip: - rd_ignore_change = 0; - return FALSE; - - case IDC_COMBO_ZIP_ID: - if (rd_ignore_change) - { - return FALSE; - } - - rd_ignore_change = 1; - h = GetDlgItem(hdlg, IDC_COMBO_ZIP_ID); - zip_untrack(zdlv_current_sel); - temp_zip_drives[zdlv_current_sel].scsi_device_id = SendMessage(h, CB_GETCURSEL, 0, 0); - zip_track(zdlv_current_sel); - h = GetDlgItem(hdlg, IDC_LIST_ZIP_DRIVES); - win_settings_zip_drives_update_item(h, zdlv_current_sel); - rd_ignore_change = 0; - return FALSE; - - case IDC_COMBO_ZIP_LUN: - if (rd_ignore_change) - { - return FALSE; - } - - rd_ignore_change = 1; - h = GetDlgItem(hdlg, IDC_COMBO_ZIP_LUN); - zip_untrack(zdlv_current_sel); - temp_zip_drives[zdlv_current_sel].scsi_device_lun = SendMessage(h, CB_GETCURSEL, 0, 0); - zip_track(zdlv_current_sel); - h = GetDlgItem(hdlg, IDC_LIST_ZIP_DRIVES); - win_settings_zip_drives_update_item(h, zdlv_current_sel); - rd_ignore_change = 0; - return FALSE; - - case IDC_COMBO_ZIP_CHANNEL_IDE: - if (rd_ignore_change) - { - return FALSE; - } - - rd_ignore_change = 1; - h = GetDlgItem(hdlg, IDC_COMBO_ZIP_CHANNEL_IDE); - zip_untrack(zdlv_current_sel); - temp_zip_drives[zdlv_current_sel].ide_channel = SendMessage(h, CB_GETCURSEL, 0, 0) & 0xff; - zip_track(zdlv_current_sel); - h = GetDlgItem(hdlg, IDC_LIST_ZIP_DRIVES); - win_settings_zip_drives_update_item(h, zdlv_current_sel); - rd_ignore_change = 0; - return FALSE; - - case IDC_CHECK250: - if (rd_ignore_change) - { - return FALSE; - } - - rd_ignore_change = 1; - h = GetDlgItem(hdlg, IDC_CHECK250); - temp_zip_drives[zdlv_current_sel].is_250 = SendMessage(h, BM_GETCHECK, 0, 0); - h = GetDlgItem(hdlg, IDC_LIST_ZIP_DRIVES); - win_settings_zip_drives_update_item(h, zdlv_current_sel); - rd_ignore_change = 0; - return FALSE; - } - - default: - return FALSE; - } - - return FALSE; -} +/************************************************************************ + * * + * Main Settings Dialog * + * * + ************************************************************************/ #define PAGE_MACHINE 0 #define PAGE_VIDEO 1 @@ -5260,43 +505,63 @@ show_child(HWND hwndParent, DWORD child_id) switch(child_id) { case PAGE_MACHINE: - hwndChildDialog = CreateDialog(hinstance, (LPCWSTR)DLG_CFG_MACHINE, hwndParent, machine_proc); + hwndChildDialog = CreateDialog(hinstance, + (LPCWSTR)DLG_CFG_MACHINE, + hwndParent, machine_proc); break; case PAGE_VIDEO: - hwndChildDialog = CreateDialog(hinstance, (LPCWSTR)DLG_CFG_VIDEO, hwndParent, video_proc); + hwndChildDialog = CreateDialog(hinstance, + (LPCWSTR)DLG_CFG_VIDEO, + hwndParent, video_proc); break; case PAGE_INPUT: - hwndChildDialog = CreateDialog(hinstance, (LPCWSTR)DLG_CFG_INPUT, hwndParent, input_proc); + hwndChildDialog = CreateDialog(hinstance, + (LPCWSTR)DLG_CFG_INPUT, + hwndParent, input_proc); break; case PAGE_SOUND: - hwndChildDialog = CreateDialog(hinstance, (LPCWSTR)DLG_CFG_SOUND, hwndParent, sound_proc); + hwndChildDialog = CreateDialog(hinstance, + (LPCWSTR)DLG_CFG_SOUND, + hwndParent, sound_proc); break; case PAGE_NETWORK: - hwndChildDialog = CreateDialog(hinstance, (LPCWSTR)DLG_CFG_NETWORK, hwndParent, network_proc); + hwndChildDialog = CreateDialog(hinstance, + (LPCWSTR)DLG_CFG_NETWORK, + hwndParent, network_proc); break; case PAGE_PORTS: - hwndChildDialog = CreateDialog(hinstance, (LPCWSTR)DLG_CFG_PORTS, hwndParent, ports_proc); + hwndChildDialog = CreateDialog(hinstance, + (LPCWSTR)DLG_CFG_PORTS, + hwndParent, ports_proc); break; case PAGE_PERIPHERALS: - hwndChildDialog = CreateDialog(hinstance, (LPCWSTR)DLG_CFG_PERIPHERALS, hwndParent, peripherals_proc); + hwndChildDialog = CreateDialog(hinstance, + (LPCWSTR)DLG_CFG_PERIPHERALS, + hwndParent, peripherals_proc); break; case PAGE_HARD_DISKS: - hwndChildDialog = CreateDialog(hinstance, (LPCWSTR)DLG_CFG_HARD_DISKS, hwndParent, hard_disks_proc); + hwndChildDialog = CreateDialog(hinstance, + (LPCWSTR)DLG_CFG_DISK, + hwndParent, disk_proc); break; case PAGE_FLOPPY_DRIVES: - hwndChildDialog = CreateDialog(hinstance, (LPCWSTR)DLG_CFG_FLOPPY_DRIVES, hwndParent, floppy_drives_proc); + hwndChildDialog = CreateDialog(hinstance, + (LPCWSTR)DLG_CFG_FLOPPY, + hwndParent, floppy_proc); break; case PAGE_OTHER_REMOVABLE_DEVICES: - hwndChildDialog = CreateDialog(hinstance, (LPCWSTR)DLG_CFG_OTHER_REMOVABLE_DEVICES, hwndParent, other_removable_devices_proc); + hwndChildDialog = CreateDialog(hinstance, + (LPCWSTR)DLG_CFG_RMV_DEVICES, + hwndParent, rmv_devices_proc); break; default: @@ -5358,7 +623,7 @@ static LRESULT CALLBACK #else static BOOL CALLBACK #endif -main_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) +settings_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) { HWND h; int category; @@ -5455,7 +720,7 @@ win_settings_open(HWND hwnd, int ask) } ask_sure = ask; - i = DialogBox(hinstance, (LPCWSTR)DLG_CONFIG, hwnd, main_proc); + i = DialogBox(hinstance, (LPCWSTR)DLG_CONFIG, hwnd, settings_proc); return(i); } diff --git a/src/win/win_settings_disk.h b/src/win/win_settings_disk.h new file mode 100644 index 0000000..569eae2 --- /dev/null +++ b/src/win/win_settings_disk.h @@ -0,0 +1,1738 @@ +/* + * VARCem Virtual ARchaeological Computer EMulator. + * An emulator of (mostly) x86-based PC systems and devices, + * using the ISA,EISA,VLB,MCA and PCI system buses, roughly + * spanning the era between 1981 and 1995. + * + * This file is part of the VARCem Project. + * + * Implementation of the Settings dialog. + * + * Version: @(#)win_settings_disk.h 1.0.1 2018/04/05 + * + * Authors: Fred N. van Kempen, + * Miran Grca, + * + * Copyright 2017,2018 Fred N. van Kempen. + * Copyright 2016-2018 Miran Grca. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the: + * + * Free Software Foundation, Inc. + * 59 Temple Place - Suite 330 + * Boston, MA 02111-1307 + * USA. + */ + + +/************************************************************************ + * * + * (Hard) Disk Dialog * + * * + ************************************************************************/ + +/* Global variables needed for the Hard Disk dialogs. */ +static hard_disk_t *hdd_ptr; +static wchar_t hd_file_name[512]; +static int hard_disk_added = 0; +static int max_spt = 63; +static int max_hpc = 255; +static int max_tracks = 266305; +static int no_update = 0; +static int existing = 0; +static uint64_t selection = 127; +static uint64_t spt, hpc, tracks, size; +static int chs_enabled = 0; +static int ignore_change = 0; +static int hdc_id_to_listview_index[HDD_NUM]; +static hard_disk_t new_hdd; +static int hd_listview_items; +static int hdlv_current_sel; +static int next_free_id = 0; + +static BOOL +disk_image_list_init(HWND hwndList) +{ + HICON hiconItem; + HIMAGELIST hSmall; + + hSmall = ImageList_Create(GetSystemMetrics(SM_CXSMICON), + GetSystemMetrics(SM_CYSMICON), + ILC_MASK | ILC_COLOR32, 1, 1); + + hiconItem = LoadIcon(hinstance, (LPCWSTR)208); + ImageList_AddIcon(hSmall, hiconItem); + DestroyIcon(hiconItem); + + hiconItem = LoadIcon(hinstance, (LPCWSTR)192); + ImageList_AddIcon(hSmall, hiconItem); + DestroyIcon(hiconItem); + + ListView_SetImageList(hwndList, hSmall, LVSIL_SMALL); + + return TRUE; +} + + +static void +disk_normalize_list(void) +{ + hard_disk_t ihdd[HDD_NUM]; + int i, j; + + memset(ihdd, 0x00, HDD_NUM * sizeof(hard_disk_t)); + + j = 0; + for (i = 0; i < HDD_NUM; i++) { + if (temp_hdd[i].bus != HDD_BUS_DISABLED) { + memcpy(&ihdd[j], &temp_hdd[i], sizeof(hard_disk_t)); + j++; + } + } + + memcpy(temp_hdd, ihdd, HDD_NUM * sizeof(hard_disk_t)); +} + + +static int +disk_get_selected(HWND hdlg) +{ + int hard_disk = -1; + int i, j; + HWND h; + + if (hd_listview_items == 0) + return 0; + + j = 0; + for (i = 0; i < hd_listview_items; i++) { + h = GetDlgItem(hdlg, IDC_LIST_HARD_DISKS); + j = ListView_GetItemState(h, i, LVIS_SELECTED); + if (j) + hard_disk = i; + } + + return hard_disk; +} + + +static void +disk_add_locations(HWND hdlg) +{ + WCHAR temp[128]; + HWND h; + int i; + + h = GetDlgItem(hdlg, IDC_COMBO_HD_BUS); + for (i = 0; i < 7; i++) + SendMessage(h, CB_ADDSTRING, 0, (LPARAM)plat_get_string(IDS_4352 + i)); + + h = GetDlgItem(hdlg, IDC_COMBO_HD_CHANNEL); + for (i = 0; i < 8; i++) { + swprintf(temp, sizeof_w(temp), plat_get_string(IDS_4097), i >> 1, i & 1); + SendMessage(h, CB_ADDSTRING, 0, (LPARAM)temp); + } + + h = GetDlgItem(hdlg, IDC_COMBO_HD_ID); + for (i = 0; i < 16; i++) { + swprintf(temp, sizeof_w(temp), plat_get_string(IDS_4098), i); + SendMessage(h, CB_ADDSTRING, 0, (LPARAM)temp); + } + + h = GetDlgItem(hdlg, IDC_COMBO_HD_LUN); + for (i = 0; i < 8; i++) { + swprintf(temp, sizeof_w(temp), plat_get_string(IDS_4098), i); + SendMessage(h, CB_ADDSTRING, 0, (LPARAM)temp); + } + + h = GetDlgItem(hdlg, IDC_COMBO_HD_CHANNEL_IDE); + for (i = 0; i < 8; i++) { + swprintf(temp, sizeof_w(temp), plat_get_string(IDS_4097), i >> 1, i & 1); + SendMessage(h, CB_ADDSTRING, 0, (LPARAM)temp); + } +} + + +// FIXME: this stuff has to be moved to the proper HDC/SCSI modules! --FVK +static int8_t +next_free_binary_channel(uint64_t *tracking) +{ + int8_t i; + + for (i = 0; i < 2; i++) { + if (!(*tracking & (0xffLL << (i << 3LL)))) + return i; + } + + return 2; +} + + +static int8_t +next_free_ide_channel(void) +{ + int8_t i; + + for (i = 0; i < 8; i++) { + if (!(ide_tracking & (0xffLL << (i << 3LL)))) + return i; + } + + return 7; +} + + +static void +next_free_scsi_id_and_lun(uint8_t *id, uint8_t *lun) +{ + int8_t i, j; + + for (i = 0; i < 16; i++) { + for (j = 0; j < 8; j++) { + if (! (scsi_tracking[i] & (0xffULL << (j << 3LL)))) { + *id = (uint8_t)i; + *lun = (uint8_t)j; + return; + } + } + } + + *id = 6; + *lun = 7; +} + + +static int +bus_full(uint64_t *tracking, int count) +{ + uint64_t full = 0; + + switch(count) { + case 2: + default: + full = (*tracking & 0xFF00ULL); + full = full && (*tracking & 0x00FFULL); + return full != 0; + + case 8: + full = (*tracking & 0xFF00000000000000ULL); + full = full && (*tracking & 0x00FF000000000000ULL); + full = full && (*tracking & 0x0000FF0000000000ULL); + full = full && (*tracking & 0x000000FF00000000ULL); + full = full && (*tracking & 0x00000000FF000000ULL); + full = full && (*tracking & 0x0000000000FF0000ULL); + full = full && (*tracking & 0x000000000000FF00ULL); + full = full && (*tracking & 0x00000000000000FFULL); + return full != 0; + } +} + + +static void +disk_recalc_location_controls(HWND hdlg, int is_add_dlg, int assign_id) +{ + HWND h; + int bus, i; + + for (i = IDT_1722; i <= IDT_1724; i++) { + h = GetDlgItem(hdlg, i); + EnableWindow(h, FALSE); + ShowWindow(h, SW_HIDE); + } + + h = GetDlgItem(hdlg, IDC_COMBO_HD_CHANNEL); + EnableWindow(h, FALSE); + ShowWindow(h, SW_HIDE); + + h = GetDlgItem(hdlg, IDC_COMBO_HD_ID); + EnableWindow(h, FALSE); + ShowWindow(h, SW_HIDE); + + h = GetDlgItem(hdlg, IDC_COMBO_HD_LUN); + EnableWindow(h, FALSE); + ShowWindow(h, SW_HIDE); + + h = GetDlgItem(hdlg, IDC_COMBO_HD_CHANNEL_IDE); + EnableWindow(h, FALSE); + ShowWindow(h, SW_HIDE); + + if ((hd_listview_items > 0) || is_add_dlg) { + h = GetDlgItem(hdlg, IDC_COMBO_HD_BUS); + bus = SendMessage(h, CB_GETCURSEL, 0, 0) + 1; + + switch(bus) { + case HDD_BUS_MFM: /* MFM */ + h = GetDlgItem(hdlg, IDT_1722); + ShowWindow(h, SW_SHOW); + EnableWindow(h, TRUE); + + h = GetDlgItem(hdlg, IDC_COMBO_HD_CHANNEL); + ShowWindow(h, SW_SHOW); + EnableWindow(h, TRUE); + if (assign_id) + temp_hdd[hdlv_current_sel].mfm_channel = next_free_binary_channel(&mfm_tracking); + SendMessage(h, CB_SETCURSEL, is_add_dlg ? new_hdd.mfm_channel : temp_hdd[hdlv_current_sel].mfm_channel, 0); + break; + + case HDD_BUS_XTIDE: /* XT IDE */ + h = GetDlgItem(hdlg, IDT_1722); + ShowWindow(h, SW_SHOW); + EnableWindow(h, TRUE); + + h = GetDlgItem(hdlg, IDC_COMBO_HD_CHANNEL); + ShowWindow(h, SW_SHOW); + EnableWindow(h, TRUE); + if (assign_id) + temp_hdd[hdlv_current_sel].xtide_channel = next_free_binary_channel(&xtide_tracking); + SendMessage(h, CB_SETCURSEL, is_add_dlg ? new_hdd.xtide_channel : temp_hdd[hdlv_current_sel].xtide_channel, 0); + break; + + case HDD_BUS_ESDI: /* ESDI */ + h = GetDlgItem(hdlg, IDT_1722); + ShowWindow(h, SW_SHOW); + EnableWindow(h, TRUE); + + h = GetDlgItem(hdlg, IDC_COMBO_HD_CHANNEL); + ShowWindow(h, SW_SHOW); + EnableWindow(h, TRUE); + if (assign_id) + temp_hdd[hdlv_current_sel].esdi_channel = next_free_binary_channel(&esdi_tracking); + SendMessage(h, CB_SETCURSEL, is_add_dlg ? new_hdd.esdi_channel : temp_hdd[hdlv_current_sel].esdi_channel, 0); + break; + + case HDD_BUS_IDE_PIO_ONLY: /* IDE (PIO-only) */ + case HDD_BUS_IDE_PIO_AND_DMA: /* IDE (PIO and DMA) */ + h = GetDlgItem(hdlg, IDT_1722); + ShowWindow(h, SW_SHOW); + EnableWindow(h, TRUE); + + h = GetDlgItem(hdlg, IDC_COMBO_HD_CHANNEL_IDE); + ShowWindow(h, SW_SHOW); + EnableWindow(h, TRUE); + if (assign_id) + temp_hdd[hdlv_current_sel].ide_channel = next_free_ide_channel(); + SendMessage(h, CB_SETCURSEL, is_add_dlg ? new_hdd.ide_channel : temp_hdd[hdlv_current_sel].ide_channel, 0); + break; + + case HDD_BUS_SCSI: /* SCSI */ + case HDD_BUS_SCSI_REMOVABLE: /* SCSI (removable) */ + h = GetDlgItem(hdlg, IDT_1723); + ShowWindow(h, SW_SHOW); + EnableWindow(h, TRUE); + h = GetDlgItem(hdlg, IDT_1724); + ShowWindow(h, SW_SHOW); + EnableWindow(h, TRUE); + + if (assign_id) + next_free_scsi_id_and_lun((uint8_t *) &temp_hdd[hdlv_current_sel].scsi_id, (uint8_t *) &temp_hdd[hdlv_current_sel].scsi_lun); + + h = GetDlgItem(hdlg, IDC_COMBO_HD_ID); + ShowWindow(h, SW_SHOW); + EnableWindow(h, TRUE); + SendMessage(h, CB_SETCURSEL, is_add_dlg ? new_hdd.scsi_id : temp_hdd[hdlv_current_sel].scsi_id, 0); + + h = GetDlgItem(hdlg, IDC_COMBO_HD_LUN); + ShowWindow(h, SW_SHOW); + EnableWindow(h, TRUE); + SendMessage(h, CB_SETCURSEL, is_add_dlg ? new_hdd.scsi_lun : temp_hdd[hdlv_current_sel].scsi_lun, 0); + break; + } + } + + if ((hd_listview_items == 0) && !is_add_dlg) { + h = GetDlgItem(hdlg, IDT_1721); + EnableWindow(h, FALSE); + ShowWindow(h, SW_HIDE); + + h = GetDlgItem(hdlg, IDC_COMBO_HD_BUS); + EnableWindow(h, FALSE); + ShowWindow(h, SW_HIDE); + } else { + h = GetDlgItem(hdlg, IDT_1721); + ShowWindow(h, SW_SHOW); + EnableWindow(h, TRUE); + + h = GetDlgItem(hdlg, IDC_COMBO_HD_BUS); + ShowWindow(h, SW_SHOW); + EnableWindow(h, TRUE); + } +} + + +static void +recalc_next_free_id(HWND hdlg) +{ + HWND h; + int c_mfm = 0; + int c_esdi = 0; + int c_xtide = 0; + int c_ide_pio = 0; + int c_ide_dma = 0; + int c_scsi = 0; + int enable_add = 0; + int i; + + next_free_id = -1; + + for (i = 0; i < HDD_NUM; i++) { + if (temp_hdd[i].bus == HDD_BUS_MFM) + c_mfm++; + else if (temp_hdd[i].bus == HDD_BUS_ESDI) + c_esdi++; + else if (temp_hdd[i].bus == HDD_BUS_XTIDE) + c_xtide++; + else if (temp_hdd[i].bus == HDD_BUS_IDE_PIO_ONLY) + c_ide_pio++; + else if (temp_hdd[i].bus == HDD_BUS_IDE_PIO_AND_DMA) + c_ide_dma++; + else if (temp_hdd[i].bus == HDD_BUS_SCSI) + c_scsi++; + else if (temp_hdd[i].bus == HDD_BUS_SCSI_REMOVABLE) + c_scsi++; + } + + for (i = 0; i < HDD_NUM; i++) { + if (temp_hdd[i].bus == HDD_BUS_DISABLED) { + next_free_id = i; + break; + } + } + + enable_add = enable_add || (next_free_id >= 0); + enable_add = enable_add && ((c_mfm < MFM_NUM) || (c_esdi < ESDI_NUM) || (c_xtide < XTIDE_NUM) || (c_ide_pio < IDE_NUM) || (c_ide_dma < IDE_NUM) || (c_scsi < SCSI_NUM)); + enable_add = enable_add && !bus_full(&mfm_tracking, 2); + enable_add = enable_add && !bus_full(&esdi_tracking, 2); + enable_add = enable_add && !bus_full(&xtide_tracking, 2); + enable_add = enable_add && !bus_full(&ide_tracking, 8); + for (i = 0; i < 16; i++) + enable_add = enable_add && !bus_full(&(scsi_tracking[i]), 8); + + h = GetDlgItem(hdlg, IDC_BUTTON_HDD_ADD_NEW); + if (enable_add) + EnableWindow(h, TRUE); + else + EnableWindow(h, FALSE); + + h = GetDlgItem(hdlg, IDC_BUTTON_HDD_ADD); + if (enable_add) + EnableWindow(h, TRUE); + else + EnableWindow(h, FALSE); + + h = GetDlgItem(hdlg, IDC_BUTTON_HDD_REMOVE); + if ((c_mfm == 0) && (c_esdi == 0) && (c_xtide == 0) && (c_ide_pio == 0) && (c_ide_dma == 0) && (c_scsi == 0)) + EnableWindow(h, FALSE); + else + EnableWindow(h, TRUE); +} + + +static void +disk_update_item(HWND hwndList, int i, int column) +{ + WCHAR temp[128]; + LVITEM lvI; + + lvI.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_STATE; + lvI.stateMask = lvI.iSubItem = lvI.state = 0; + lvI.iSubItem = column; + lvI.iItem = i; + + if (column == 0) { + switch(temp_hdd[i].bus) { + case HDD_BUS_MFM: + swprintf(temp, sizeof_w(temp), plat_get_string(IDS_4608), temp_hdd[i].mfm_channel >> 1, temp_hdd[i].mfm_channel & 1); + break; + + case HDD_BUS_XTIDE: + swprintf(temp, sizeof_w(temp), plat_get_string(IDS_4609), temp_hdd[i].xtide_channel >> 1, temp_hdd[i].xtide_channel & 1); + break; + + case HDD_BUS_ESDI: + swprintf(temp, sizeof_w(temp), plat_get_string(IDS_4610), temp_hdd[i].esdi_channel >> 1, temp_hdd[i].esdi_channel & 1); + break; + + case HDD_BUS_IDE_PIO_ONLY: + swprintf(temp, sizeof_w(temp), plat_get_string(IDS_4611), temp_hdd[i].ide_channel >> 1, temp_hdd[i].ide_channel & 1); + break; + + case HDD_BUS_IDE_PIO_AND_DMA: + swprintf(temp, sizeof_w(temp), plat_get_string(IDS_4612), temp_hdd[i].ide_channel >> 1, temp_hdd[i].ide_channel & 1); + break; + + case HDD_BUS_SCSI: + swprintf(temp, sizeof_w(temp), plat_get_string(IDS_4613), temp_hdd[i].scsi_id, temp_hdd[i].scsi_lun); + break; + + case HDD_BUS_SCSI_REMOVABLE: + swprintf(temp, sizeof_w(temp), plat_get_string(IDS_4614), temp_hdd[i].scsi_id, temp_hdd[i].scsi_lun); + break; + } + + lvI.pszText = temp; + lvI.iImage = (temp_hdd[i].bus == HDD_BUS_SCSI_REMOVABLE) ? 1 : 0; + } else if (column == 1) { + lvI.pszText = temp_hdd[i].fn; + lvI.iImage = 0; + } else if (column == 2) { + swprintf(temp, sizeof_w(temp), plat_get_string(IDS_4098), temp_hdd[i].tracks); + lvI.pszText = temp; + lvI.iImage = 0; + } else if (column == 3) { + swprintf(temp, sizeof_w(temp), plat_get_string(IDS_4098), temp_hdd[i].hpc); + lvI.pszText = temp; + lvI.iImage = 0; + } else if (column == 4) { + swprintf(temp, sizeof_w(temp), plat_get_string(IDS_4098), temp_hdd[i].spt); + lvI.pszText = temp; + lvI.iImage = 0; + } else if (column == 5) { + swprintf(temp, sizeof_w(temp), plat_get_string(IDS_4098), (temp_hdd[i].tracks * temp_hdd[i].hpc * temp_hdd[i].spt) >> 11); + lvI.pszText = temp; + lvI.iImage = 0; + } + + if (ListView_SetItem(hwndList, &lvI) == -1) { + /* Error, not used. */ + return; + } +} + + +static BOOL +disk_recalc_list(HWND hwndList) +{ + WCHAR temp[128]; + LVITEM lvI; + int i, j; + + hd_listview_items = 0; + hdlv_current_sel = -1; + + ListView_DeleteAllItems(hwndList); + + j = 0; + for (i = 0; i < HDD_NUM; i++) { + if (temp_hdd[i].bus <= 0) { + hdc_id_to_listview_index[i] = -1; + continue; + } + + /* Clear the item. */ + memset(&lvI, 0x00, sizeof(lvI)); + lvI.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_STATE; + lvI.stateMask = lvI.iSubItem = lvI.state = 0; + lvI.iSubItem = 0; + + hdc_id_to_listview_index[i] = j; + + switch(temp_hdd[i].bus) { + case HDD_BUS_MFM: + swprintf(temp, sizeof_w(temp), plat_get_string(IDS_4608), temp_hdd[i].mfm_channel >> 1, temp_hdd[i].mfm_channel & 1); + break; + + case HDD_BUS_XTIDE: + swprintf(temp, sizeof_w(temp), plat_get_string(IDS_4609), temp_hdd[i].xtide_channel >> 1, temp_hdd[i].xtide_channel & 1); + break; + + case HDD_BUS_ESDI: + swprintf(temp, sizeof_w(temp), plat_get_string(IDS_4610), temp_hdd[i].esdi_channel >> 1, temp_hdd[i].esdi_channel & 1); + break; + + case HDD_BUS_IDE_PIO_ONLY: + swprintf(temp, sizeof_w(temp), plat_get_string(IDS_4611), temp_hdd[i].ide_channel >> 1, temp_hdd[i].ide_channel & 1); + break; + + case HDD_BUS_IDE_PIO_AND_DMA: + swprintf(temp, sizeof_w(temp), plat_get_string(IDS_4612), temp_hdd[i].ide_channel >> 1, temp_hdd[i].ide_channel & 1); + break; + + case HDD_BUS_SCSI: + swprintf(temp, sizeof_w(temp), plat_get_string(IDS_4613), temp_hdd[i].scsi_id, temp_hdd[i].scsi_lun); + break; + + case HDD_BUS_SCSI_REMOVABLE: + swprintf(temp, sizeof_w(temp), plat_get_string(IDS_4614), temp_hdd[i].scsi_id, temp_hdd[i].scsi_lun); + break; + } + + lvI.pszText = temp; + lvI.iItem = j; + lvI.iImage = (temp_hdd[i].bus == HDD_BUS_SCSI_REMOVABLE) ? 1 : 0; + if (ListView_InsertItem(hwndList, &lvI) == -1) return FALSE; + + lvI.iSubItem = 1; + lvI.pszText = temp_hdd[i].fn; + lvI.iItem = j; + lvI.iImage = 0; + if (ListView_SetItem(hwndList, &lvI) == -1) return FALSE; + + lvI.iSubItem = 2; + swprintf(temp, sizeof_w(temp), plat_get_string(IDS_4098), temp_hdd[i].tracks); + lvI.pszText = temp; + lvI.iItem = j; + lvI.iImage = 0; + if (ListView_SetItem(hwndList, &lvI) == -1) return FALSE; + + lvI.iSubItem = 3; + swprintf(temp, sizeof_w(temp), plat_get_string(IDS_4098), temp_hdd[i].hpc); + lvI.pszText = temp; + lvI.iItem = j; + lvI.iImage = 0; + if (ListView_SetItem(hwndList, &lvI) == -1) return FALSE; + + lvI.iSubItem = 4; + swprintf(temp, sizeof_w(temp), plat_get_string(IDS_4098), temp_hdd[i].spt); + lvI.pszText = temp; + lvI.iItem = j; + lvI.iImage = 0; + if (ListView_SetItem(hwndList, &lvI) == -1) return FALSE; + + lvI.iSubItem = 5; + swprintf(temp, sizeof_w(temp), plat_get_string(IDS_4098), (temp_hdd[i].tracks * temp_hdd[i].hpc * temp_hdd[i].spt) >> 11); + lvI.pszText = temp; + lvI.iItem = j; + lvI.iImage = 0; + if (ListView_SetItem(hwndList, &lvI) == -1) return FALSE; + + j++; + } + + hd_listview_items = j; + + return TRUE; +} + + +static BOOL +disk_init_columns(HWND hwndList) +{ + LVCOLUMN lvc; + int iCol; + + /* Icon, Bus, File, C, H, S, Size */ + for (iCol = 0; iCol < 6; iCol++) { + memset(&lvc, 0x00, sizeof(lvc)); + lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM; + + lvc.iSubItem = iCol; + lvc.pszText = plat_get_string(2082 + iCol); + + switch(iCol) { + case 0: /* Bus */ + lvc.cx = 135; + lvc.fmt = LVCFMT_LEFT; + break; + + case 1: /* File */ + lvc.cx = 150; + lvc.fmt = LVCFMT_LEFT; + break; + + case 2: /* Cylinders */ + lvc.cx = 41; + lvc.fmt = LVCFMT_RIGHT; + break; + + case 3: /* Heads */ + case 4: /* Sectors */ + lvc.cx = 25; + lvc.fmt = LVCFMT_RIGHT; + break; + + case 5: /* Size (MB) 8 */ + lvc.cx = 41; + lvc.fmt = LVCFMT_RIGHT; + break; + } + + if (ListView_InsertColumn(hwndList, iCol, &lvc) == -1) return FALSE; + } + + return TRUE; +} + + +static void +get_edit_box_contents(HWND hdlg, int id, uint64_t *val) +{ + WCHAR temp[128]; + char tempA[128]; + HWND h; + + h = GetDlgItem(hdlg, id); + SendMessage(h, WM_GETTEXT, sizeof_w(temp), (LPARAM)temp); + wcstombs(tempA, temp, sizeof(tempA)); + sscanf(tempA, "%" PRIu64, val); +} + + +static void +get_combo_box_selection(HWND hdlg, int id, uint64_t *val) +{ + HWND h; + + h = GetDlgItem(hdlg, id); + *val = SendMessage(h, CB_GETCURSEL, 0, 0); +} + + +static void +set_edit_box_contents(HWND hdlg, int id, uint64_t val) +{ + WCHAR temp[128]; + HWND h; + + h = GetDlgItem(hdlg, id); + swprintf(temp, sizeof_w(temp), plat_get_string(IDS_2156), val); + SendMessage(h, WM_SETTEXT, (WPARAM)wcslen(temp), (LPARAM)temp); +} + + +static uint64_t +disk_initialize_hdt(HWND hdlg) +{ + WCHAR temp[128]; + uint64_t temp_size = 0; + uint64_t size_mb = 0; + HWND h; + int i; + + selection = 127; + + h = GetDlgItem(hdlg, IDC_COMBO_HD_TYPE); + for (i = 0; i < 127; i++) { + temp_size = hdd_table[i].cyls * hdd_table[i].head * hdd_table[i].sect; + size_mb = temp_size >> 11; + swprintf(temp, sizeof_w(temp), + plat_get_string(IDS_2157), + size_mb, hdd_table[i].cyls, + hdd_table[i].head, hdd_table[i].sect); + SendMessage(h, CB_ADDSTRING, 0, (LPARAM)temp); + if ((tracks == hdd_table[i].cyls) && (hpc == hdd_table[i].head) && (spt == hdd_table[i].sect)) + selection = i; + } + + SendMessage(h, CB_ADDSTRING, 0, (LPARAM)plat_get_string(IDS_4100)); + SendMessage(h, CB_ADDSTRING, 0, (LPARAM)plat_get_string(IDS_4101)); + SendMessage(h, CB_SETCURSEL, selection & 0xffff, 0); + + return selection; +} + + +static void +disk_recalc_selection(HWND hdlg) +{ + HWND h; + int i; + + selection = 127; + h = GetDlgItem(hdlg, IDC_COMBO_HD_TYPE); + for (i = 0; i < 127; i++) { + if ((tracks == hdd_table[i].cyls) && (hpc == hdd_table[i].head) && (spt == hdd_table[i].sect)) + selection = i; + } + + if ((selection == 127) && (hpc == 16) && (spt == 63)) + selection = 128; + + SendMessage(h, CB_SETCURSEL, selection & 0xffff, 0); +} + + +#ifdef __amd64__ +static LRESULT CALLBACK +#else +static BOOL CALLBACK +#endif +disk_add_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) +{ + char buf[512], *big_buf; + HWND h = INVALID_HANDLE_VALUE; + uint64_t i = 0; + uint64_t temp; + FILE *f; + uint32_t sector_size = 512; + uint32_t zero = 0; + uint32_t base = 0x1000; + uint64_t signature = 0xD778A82044445459ll; + int b = 0; + uint64_t r = 0; + uint8_t channel = 0; + uint8_t id = 0, lun = 0; + wchar_t *twcs; + + switch (message) { + case WM_INITDIALOG: + memset(hd_file_name, 0x00, sizeof(hd_file_name)); + + if (existing & 2) { + next_free_id = (existing >> 3) & 0x1f; + hdd_ptr = &(hdd[next_free_id]); + } else { + hdd_ptr = &(temp_hdd[next_free_id]); + } + + SetWindowText(hdlg, plat_get_string((existing & 1) ? IDS_4103 : IDS_4102)); + + no_update = 1; + spt = (existing & 1) ? 0 : 17; + set_edit_box_contents(hdlg, IDC_EDIT_HD_SPT, spt); + hpc = (existing & 1) ? 0 : 15; + set_edit_box_contents(hdlg, IDC_EDIT_HD_HPC, hpc); + tracks = (existing & 1) ? 0 : 1023; + set_edit_box_contents(hdlg, IDC_EDIT_HD_CYL, tracks); + size = (tracks * hpc * spt) << 9; + set_edit_box_contents(hdlg, IDC_EDIT_HD_SIZE, size >> 20); + + disk_initialize_hdt(hdlg); + + if (existing & 1) { + h = GetDlgItem(hdlg, IDC_EDIT_HD_SPT); + EnableWindow(h, FALSE); + h = GetDlgItem(hdlg, IDC_EDIT_HD_HPC); + EnableWindow(h, FALSE); + h = GetDlgItem(hdlg, IDC_EDIT_HD_CYL); + EnableWindow(h, FALSE); + h = GetDlgItem(hdlg, IDC_EDIT_HD_SIZE); + EnableWindow(h, FALSE); + h = GetDlgItem(hdlg, IDC_COMBO_HD_TYPE); + EnableWindow(h, FALSE); + chs_enabled = 0; + } else { + chs_enabled = 1; + } + + disk_add_locations(hdlg); + + h = GetDlgItem(hdlg, IDC_COMBO_HD_BUS); + if (existing & 2) { + hdd_ptr->bus = HDD_BUS_SCSI_REMOVABLE; + max_spt = 99; + max_hpc = 255; + } else { + hdd_ptr->bus = HDD_BUS_IDE_PIO_ONLY; + max_spt = 63; + max_hpc = 255; + } + SendMessage(h, CB_SETCURSEL, hdd_ptr->bus, 0); + max_tracks = 266305; + disk_recalc_location_controls(hdlg, 1, 0); + + if (existing & 2) { + /* We're functioning as a load image dialog for a removable SCSI hard disk, + called from win.c, so let's hide the bus selection as we should not + allow it at this point. */ + EnableWindow(h, FALSE); + ShowWindow(h, SW_HIDE); + + h = GetDlgItem(hdlg, 1798); + ShowWindow(h, SW_HIDE); + + /* Disable and hide the SCSI ID and LUN combo boxes. */ + h = GetDlgItem(hdlg, IDC_COMBO_HD_ID); + EnableWindow(h, FALSE); + ShowWindow(h, SW_HIDE); + + h = GetDlgItem(hdlg, IDC_COMBO_HD_LUN); + EnableWindow(h, FALSE); + ShowWindow(h, SW_HIDE); + + /* Set the file name edit box contents to our existing parameters. */ + h = GetDlgItem(hdlg, IDC_EDIT_HD_FILE_NAME); + SendMessage(h, WM_SETTEXT, 0, (LPARAM) hdd[next_free_id].fn); + } else { + channel = next_free_ide_channel(); + next_free_scsi_id_and_lun(&id, &lun); + h = GetDlgItem(hdlg, IDC_COMBO_HD_CHANNEL); + SendMessage(h, CB_SETCURSEL, 0, 0); + h = GetDlgItem(hdlg, IDC_COMBO_HD_ID); + SendMessage(h, CB_SETCURSEL, id, 0); + h = GetDlgItem(hdlg, IDC_COMBO_HD_LUN); + SendMessage(h, CB_SETCURSEL, lun, 0); + h = GetDlgItem(hdlg, IDC_COMBO_HD_CHANNEL_IDE); + SendMessage(h, CB_SETCURSEL, channel, 0); + + new_hdd.mfm_channel = next_free_binary_channel(&mfm_tracking); + new_hdd.esdi_channel = next_free_binary_channel(&esdi_tracking); + new_hdd.xtide_channel = next_free_binary_channel(&xtide_tracking); + new_hdd.ide_channel = channel; + new_hdd.scsi_id = id; + new_hdd.scsi_lun = lun; + } + h = GetDlgItem(hdlg, IDC_EDIT_HD_FILE_NAME); + EnableWindow(h, FALSE); + + h = GetDlgItem(hdlg, IDT_1752); + EnableWindow(h, FALSE); + ShowWindow(h, SW_HIDE); + + h = GetDlgItem(hdlg, IDC_PBAR_IMG_CREATE); + EnableWindow(h, FALSE); + ShowWindow(h, SW_HIDE); + + no_update = 0; + return TRUE; + + case WM_COMMAND: + switch (LOWORD(wParam)) { + case IDOK: + if (!(existing & 2)) { + h = GetDlgItem(hdlg, IDC_COMBO_HD_BUS); + hdd_ptr->bus = (SendMessage(h, CB_GETCURSEL, 0, 0) + 1) & 0xff; + } + + /* Make sure no file name is allowed with removable SCSI hard disks. */ + if ((wcslen(hd_file_name) == 0) && (hdd_ptr->bus != HDD_BUS_SCSI_REMOVABLE)) { + hdd_ptr->bus = HDD_BUS_DISABLED; + settings_msgbox(MBX_ERROR, (wchar_t *)IDS_4112); + return TRUE; + } else if ((wcslen(hd_file_name) == 0) && (hdd_ptr->bus == HDD_BUS_SCSI_REMOVABLE)) { + /* Mark hard disk added but return empty - it will signify the disk was ejected. */ + hdd_ptr->tracks = 0; + hdd_ptr->spt = hdd_ptr->hpc = 0; + memset(hdd_ptr->fn, 0, sizeof(hdd_ptr->fn)); + + goto hd_add_ok_common; + } + + get_edit_box_contents(hdlg, IDC_EDIT_HD_SPT, &i); + hdd_ptr->spt = (uint8_t)i; + get_edit_box_contents(hdlg, IDC_EDIT_HD_HPC, &i); + hdd_ptr->hpc = (uint8_t)i; + get_edit_box_contents(hdlg, IDC_EDIT_HD_CYL, &i); + hdd_ptr->tracks = (uint16_t)i; + spt = hdd_ptr->spt; + hpc = hdd_ptr->hpc; + tracks = hdd_ptr->tracks; + + if (existing & 2) { + if (hdd_ptr->bus == HDD_BUS_SCSI_REMOVABLE) { + memset(hdd_ptr->prev_fn, 0, sizeof(hdd_ptr->prev_fn)); + wcscpy(hdd_ptr->prev_fn, hdd_ptr->fn); + } + } else { + switch(hdd_ptr->bus) { + case HDD_BUS_MFM: + h = GetDlgItem(hdlg, IDC_COMBO_HD_CHANNEL); + hdd_ptr->mfm_channel = SendMessage(h, CB_GETCURSEL, 0, 0) & 0xff; + break; + + case HDD_BUS_ESDI: + h = GetDlgItem(hdlg, IDC_COMBO_HD_CHANNEL); + hdd_ptr->esdi_channel = SendMessage(h, CB_GETCURSEL, 0, 0) & 0xff; + break; + + case HDD_BUS_XTIDE: + h = GetDlgItem(hdlg, IDC_COMBO_HD_CHANNEL); + hdd_ptr->xtide_channel = SendMessage(h, CB_GETCURSEL, 0, 0) & 0xff; + break; + + case HDD_BUS_IDE_PIO_ONLY: + case HDD_BUS_IDE_PIO_AND_DMA: + h = GetDlgItem(hdlg, IDC_COMBO_HD_CHANNEL_IDE); + hdd_ptr->ide_channel = SendMessage(h, CB_GETCURSEL, 0, 0) & 0xff; + break; + + case HDD_BUS_SCSI: + case HDD_BUS_SCSI_REMOVABLE: + h = GetDlgItem(hdlg, IDC_COMBO_HD_ID); + hdd_ptr->scsi_id = SendMessage(h, CB_GETCURSEL, 0, 0) & 0xff; + h = GetDlgItem(hdlg, IDC_COMBO_HD_LUN); + hdd_ptr->scsi_lun = SendMessage(h, CB_GETCURSEL, 0, 0) & 0xff; + break; + } + } + + memset(hdd_ptr->fn, 0, sizeof(hdd_ptr->fn)); + wcscpy(hdd_ptr->fn, hd_file_name); + + sector_size = 512; + + if (!(existing & 1) && (wcslen(hd_file_name) > 0)) { + f = _wfopen(hd_file_name, L"wb"); + + if (image_is_hdi(hd_file_name)) { + if (size >= 0x100000000ll) { + fclose(f); + settings_msgbox(MBX_ERROR, (wchar_t *)IDS_4104); + return TRUE; + } + + fwrite(&zero, 1, 4, f); /* 00000000: Zero/unknown */ + fwrite(&zero, 1, 4, f); /* 00000004: Zero/unknown */ + fwrite(&base, 1, 4, f); /* 00000008: Offset at which data starts */ + fwrite(&size, 1, 4, f); /* 0000000C: Full size of the data (32-bit) */ + fwrite(§or_size, 1, 4, f); /* 00000010: Sector size in bytes */ + fwrite(&spt, 1, 4, f); /* 00000014: Sectors per cylinder */ + fwrite(&hpc, 1, 4, f); /* 00000018: Heads per cylinder */ + fwrite(&tracks, 1, 4, f); /* 0000001C: Cylinders */ + + for (i = 0; i < 0x3f8; i++) { + fwrite(&zero, 1, 4, f); + } + } else if (image_is_hdx(hd_file_name, 0)) { + if (size > 0xffffffffffffffffll) { + fclose(f); + settings_msgbox(MBX_ERROR, (wchar_t *)IDS_4105); + return TRUE; + } + + fwrite(&signature, 1, 8, f); /* 00000000: Signature */ + fwrite(&size, 1, 8, f); /* 00000008: Full size of the data (64-bit) */ + fwrite(§or_size, 1, 4, f); /* 00000010: Sector size in bytes */ + fwrite(&spt, 1, 4, f); /* 00000014: Sectors per cylinder */ + fwrite(&hpc, 1, 4, f); /* 00000018: Heads per cylinder */ + fwrite(&tracks, 1, 4, f); /* 0000001C: Cylinders */ + fwrite(&zero, 1, 4, f); /* 00000020: [Translation] Sectors per cylinder */ + fwrite(&zero, 1, 4, f); /* 00000004: [Translation] Heads per cylinder */ + } + + memset(buf, 0, 512); + size >>= 9; + r = (size >> 11) << 11; + size -= r; + r >>= 11; + + if (size || r) { + h = GetDlgItem(hdlg, IDT_1731); + EnableWindow(h, FALSE); + ShowWindow(h, SW_HIDE); + + h = GetDlgItem(hdlg, IDC_EDIT_HD_FILE_NAME); + EnableWindow(h, FALSE); + ShowWindow(h, SW_HIDE); + + h = GetDlgItem(hdlg, IDC_CFILE); + EnableWindow(h, FALSE); + ShowWindow(h, SW_HIDE); + + h = GetDlgItem(hdlg, IDC_PBAR_IMG_CREATE); + SendMessage(h, PBM_SETRANGE32, (WPARAM) 0, (LPARAM) (size + r - 1)); + SendMessage(h, PBM_SETPOS, (WPARAM) 0, (LPARAM) 0); + EnableWindow(h, TRUE); + ShowWindow(h, SW_SHOW); + + h = GetDlgItem(hdlg, IDT_1752); + EnableWindow(h, TRUE); + ShowWindow(h, SW_SHOW); + } + + if (size) { + for (i = 0; i < size; i++) { + fwrite(buf, 1, 512, f); + SendMessage(h, PBM_SETPOS, (WPARAM) i, (LPARAM) 0); + } + } + + if (r) { + big_buf = (char *) malloc(1048576); + memset(big_buf, 0, 1048576); + for (i = 0; i < r; i++) { + fwrite(big_buf, 1, 1048576, f); + SendMessage(h, PBM_SETPOS, (WPARAM) (size + i), (LPARAM) 0); + } + free(big_buf); + } + + fclose(f); + settings_msgbox(MBX_INFO, (wchar_t *)IDS_4113); + } + +hd_add_ok_common: + hard_disk_added = 1; + EndDialog(hdlg, 0); + return TRUE; + + case IDCANCEL: + hard_disk_added = 0; + if (!(existing & 2)) { + hdd_ptr->bus = HDD_BUS_DISABLED; + } + EndDialog(hdlg, 0); + return TRUE; + + case IDC_CFILE: + if (!file_dlg(hdlg, plat_get_string(IDS_4106), L"", !(existing & 1))) { + if (!wcschr(wopenfilestring, L'.')) { + if (wcslen(wopenfilestring) && (wcslen(wopenfilestring) <= 256)) { + twcs = &wopenfilestring[wcslen(wopenfilestring)]; + twcs[0] = L'.'; + twcs[1] = L'i'; + twcs[2] = L'm'; + twcs[3] = L'g'; + } + } + + if (!(existing & 1)) { + f = _wfopen(wopenfilestring, L"rb"); + if (f != NULL) { + fclose(f); + if (settings_msgbox(MBX_QUESTION, (wchar_t *)IDS_4111) != 0) { /* yes */ + return FALSE; + } + } + } + + f = _wfopen(wopenfilestring, (existing & 1) ? L"rb" : L"wb"); + if (f == NULL) { +hdd_add_file_open_error: + settings_msgbox(MBX_ERROR, (existing & 1) ? (wchar_t *)IDS_4107 : (wchar_t *)IDS_4108); + return TRUE; + } + if (existing & 1) { + if (image_is_hdi(wopenfilestring) || image_is_hdx(wopenfilestring, 1)) { + fseeko64(f, 0x10, SEEK_SET); + fread(§or_size, 1, 4, f); + if (sector_size != 512) { + settings_msgbox(MBX_ERROR, (wchar_t *)IDS_4109); + fclose(f); + return TRUE; + } + spt = hpc = tracks = 0; + fread(&spt, 1, 4, f); + fread(&hpc, 1, 4, f); + fread(&tracks, 1, 4, f); + } else { + fseeko64(f, 0, SEEK_END); + size = ftello64(f); + fclose(f); + if (((size % 17) == 0) && (size <= 142606336)) { + spt = 17; + if (size <= 26738688) { + hpc = 4; + } else if (((size % 3072) == 0) && (size <= 53477376)) { + hpc = 6; + } else { + for (i = 5; i < 16; i++) { + if (((size % (i << 9)) == 0) && (size <= ((i * 17) << 19))) + break; + if (i == 5) + i++; + } + hpc = i; + } + } else { + spt = 63; + hpc = 16; + } + + tracks = ((size >> 9) / hpc) / spt; + } + + if ((spt > max_spt) || (hpc > max_hpc) || (tracks > max_tracks)) { + goto hdd_add_file_open_error; + } + no_update = 1; + + set_edit_box_contents(hdlg, IDC_EDIT_HD_SPT, spt); + set_edit_box_contents(hdlg, IDC_EDIT_HD_HPC, hpc); + set_edit_box_contents(hdlg, IDC_EDIT_HD_CYL, tracks); + set_edit_box_contents(hdlg, IDC_EDIT_HD_SIZE, size >> 20); + disk_recalc_selection(hdlg); + + h = GetDlgItem(hdlg, IDC_EDIT_HD_SPT); + EnableWindow(h, TRUE); + h = GetDlgItem(hdlg, IDC_EDIT_HD_HPC); + EnableWindow(h, TRUE); + h = GetDlgItem(hdlg, IDC_EDIT_HD_CYL); + EnableWindow(h, TRUE); + h = GetDlgItem(hdlg, IDC_EDIT_HD_SIZE); + EnableWindow(h, TRUE); + h = GetDlgItem(hdlg, IDC_COMBO_HD_TYPE); + EnableWindow(h, TRUE); + + chs_enabled = 1; + + no_update = 0; + } else { + fclose(f); + } + } + + h = GetDlgItem(hdlg, IDC_EDIT_HD_FILE_NAME); + SendMessage(h, WM_SETTEXT, 0, (LPARAM)wopenfilestring); + memset(hd_file_name, 0, sizeof(hd_file_name)); + wcscpy(hd_file_name, wopenfilestring); + + return TRUE; + + case IDC_EDIT_HD_CYL: + if (no_update) + return FALSE; + + no_update = 1; + get_edit_box_contents(hdlg, IDC_EDIT_HD_CYL, &temp); + if (temp != tracks) { + tracks = temp; + size = (tracks * hpc * spt) << 9; + set_edit_box_contents(hdlg, IDC_EDIT_HD_SIZE, size >> 20); + disk_recalc_selection(hdlg); + } + + if (tracks > max_tracks) { + tracks = max_tracks; + size = (tracks * hpc * spt) << 9; + set_edit_box_contents(hdlg, IDC_EDIT_HD_CYL, tracks); + set_edit_box_contents(hdlg, IDC_EDIT_HD_SIZE, (size >> 20)); + disk_recalc_selection(hdlg); + } + + no_update = 0; + break; + + case IDC_EDIT_HD_HPC: + if (no_update) + return FALSE; + + no_update = 1; + get_edit_box_contents(hdlg, IDC_EDIT_HD_HPC, &temp); + if (temp != hpc) { + hpc = temp; + size = (tracks * hpc * spt) << 9; + set_edit_box_contents(hdlg, IDC_EDIT_HD_SIZE, size >> 20); + disk_recalc_selection(hdlg); + } + + if (hpc > max_hpc) { + hpc = max_hpc; + size = (tracks * hpc * spt) << 9; + set_edit_box_contents(hdlg, IDC_EDIT_HD_HPC, hpc); + set_edit_box_contents(hdlg, IDC_EDIT_HD_SIZE, (size >> 20)); + disk_recalc_selection(hdlg); + } + + no_update = 0; + break; + + case IDC_EDIT_HD_SPT: + if (no_update) + return FALSE; + + no_update = 1; + get_edit_box_contents(hdlg, IDC_EDIT_HD_SPT, &temp); + if (temp != spt) { + spt = temp; + size = (tracks * hpc * spt) << 9; + set_edit_box_contents(hdlg, IDC_EDIT_HD_SIZE, size >> 20); + disk_recalc_selection(hdlg); + } + + if (spt > max_spt) { + spt = max_spt; + size = (tracks * hpc * spt) << 9; + set_edit_box_contents(hdlg, IDC_EDIT_HD_SPT, spt); + set_edit_box_contents(hdlg, IDC_EDIT_HD_SIZE, (size >> 20)); + disk_recalc_selection(hdlg); + } + + no_update = 0; + break; + + case IDC_EDIT_HD_SIZE: + if (no_update) + return FALSE; + + no_update = 1; + get_edit_box_contents(hdlg, IDC_EDIT_HD_SIZE, &temp); + if (temp != (size >> 20)) { + size = temp << 20; + tracks = ((size >> 9) / hpc) / spt; + set_edit_box_contents(hdlg, IDC_EDIT_HD_CYL, tracks); + disk_recalc_selection(hdlg); + } + + if (tracks > max_tracks) { + tracks = max_tracks; + size = (tracks * hpc * spt) << 9; + set_edit_box_contents(hdlg, IDC_EDIT_HD_CYL, tracks); + set_edit_box_contents(hdlg, IDC_EDIT_HD_SIZE, (size >> 20)); + disk_recalc_selection(hdlg); + } + + no_update = 0; + break; + + case IDC_COMBO_HD_TYPE: + if (no_update) + return FALSE; + + no_update = 1; + get_combo_box_selection(hdlg, IDC_COMBO_HD_TYPE, &temp); + if ((temp != selection) && (temp != 127) && (temp != 128)) { + selection = temp; + tracks = hdd_table[selection].cyls; + hpc = hdd_table[selection].head; + spt = hdd_table[selection].sect; + size = (tracks * hpc * spt) << 9; + set_edit_box_contents(hdlg, IDC_EDIT_HD_CYL, tracks); + set_edit_box_contents(hdlg, IDC_EDIT_HD_HPC, hpc); + set_edit_box_contents(hdlg, IDC_EDIT_HD_SPT, spt); + set_edit_box_contents(hdlg, IDC_EDIT_HD_SIZE, size >> 20); + } else if ((temp != selection) && (temp == 127)) { + selection = temp; + } else if ((temp != selection) && (temp == 128)) { + selection = temp; + hpc = 16; + spt = 63; + size = (tracks * hpc * spt) << 9; + set_edit_box_contents(hdlg, IDC_EDIT_HD_HPC, hpc); + set_edit_box_contents(hdlg, IDC_EDIT_HD_SPT, spt); + set_edit_box_contents(hdlg, IDC_EDIT_HD_SIZE, size >> 20); + } + + if (spt > max_spt) { + spt = max_spt; + size = (tracks * hpc * spt) << 9; + set_edit_box_contents(hdlg, IDC_EDIT_HD_SPT, spt); + set_edit_box_contents(hdlg, IDC_EDIT_HD_SIZE, (size >> 20)); + disk_recalc_selection(hdlg); + } + + if (hpc > max_hpc) { + hpc = max_hpc; + size = (tracks * hpc * spt) << 9; + set_edit_box_contents(hdlg, IDC_EDIT_HD_HPC, hpc); + set_edit_box_contents(hdlg, IDC_EDIT_HD_SIZE, (size >> 20)); + disk_recalc_selection(hdlg); + } + + if (tracks > max_tracks) { + tracks = max_tracks; + size = (tracks * hpc * spt) << 9; + set_edit_box_contents(hdlg, IDC_EDIT_HD_CYL, tracks); + set_edit_box_contents(hdlg, IDC_EDIT_HD_SIZE, (size >> 20)); + disk_recalc_selection(hdlg); + } + + no_update = 0; + break; + + case IDC_COMBO_HD_BUS: + if (no_update) + return FALSE; + + no_update = 1; + disk_recalc_location_controls(hdlg, 1, 0); + h = GetDlgItem(hdlg, IDC_COMBO_HD_BUS); + b = SendMessage(h,CB_GETCURSEL,0,0) + 1; + if (b == hdd_ptr->bus) + goto hd_add_bus_skip; + + hdd_ptr->bus = b; + switch(hdd_ptr->bus) { + case HDD_BUS_DISABLED: + default: + max_spt = max_hpc = max_tracks = 0; + break; + + case HDD_BUS_MFM: + max_spt = 17; + max_hpc = 15; + max_tracks = 1023; + break; + + case HDD_BUS_ESDI: + case HDD_BUS_XTIDE: + max_spt = 63; + max_hpc = 16; + max_tracks = 1023; + break; + + case HDD_BUS_IDE_PIO_ONLY: + case HDD_BUS_IDE_PIO_AND_DMA: + max_spt = 63; + max_hpc = 255; + max_tracks = 266305; + break; + + case HDD_BUS_SCSI_REMOVABLE: + if (spt == 0) { + spt = 63; + size = (tracks * hpc * spt) << 9; + set_edit_box_contents(hdlg, IDC_EDIT_HD_SPT, spt); + set_edit_box_contents(hdlg, IDC_EDIT_HD_SIZE, (size >> 20)); + } + if (hpc == 0) { + hpc = 16; + size = (tracks * hpc * spt) << 9; + set_edit_box_contents(hdlg, IDC_EDIT_HD_HPC, hpc); + set_edit_box_contents(hdlg, IDC_EDIT_HD_SIZE, (size >> 20)); + } + if (tracks == 0) { + tracks = 1023; + size = (tracks * hpc * spt) << 9; + set_edit_box_contents(hdlg, IDC_EDIT_HD_CYL, tracks); + set_edit_box_contents(hdlg, IDC_EDIT_HD_SIZE, (size >> 20)); + } + /*FALLTHROUGH*/ + + case HDD_BUS_SCSI: + max_spt = 99; + max_hpc = 255; + max_tracks = 266305; + break; + } + + if ((hdd_ptr->bus == HDD_BUS_SCSI_REMOVABLE) && !chs_enabled) { + h = GetDlgItem(hdlg, IDC_EDIT_HD_SPT); + EnableWindow(h, TRUE); + h = GetDlgItem(hdlg, IDC_EDIT_HD_HPC); + EnableWindow(h, TRUE); + h = GetDlgItem(hdlg, IDC_EDIT_HD_CYL); + EnableWindow(h, TRUE); + h = GetDlgItem(hdlg, IDC_EDIT_HD_SIZE); + EnableWindow(h, TRUE); + h = GetDlgItem(hdlg, IDC_COMBO_HD_TYPE); + EnableWindow(h, TRUE); + } else if ((hdd_ptr->bus != HDD_BUS_SCSI_REMOVABLE) && !chs_enabled) { + h = GetDlgItem(hdlg, IDC_EDIT_HD_SPT); + EnableWindow(h, FALSE); + h = GetDlgItem(hdlg, IDC_EDIT_HD_HPC); + EnableWindow(h, FALSE); + h = GetDlgItem(hdlg, IDC_EDIT_HD_CYL); + EnableWindow(h, FALSE); + h = GetDlgItem(hdlg, IDC_EDIT_HD_SIZE); + EnableWindow(h, FALSE); + h = GetDlgItem(hdlg, IDC_COMBO_HD_TYPE); + EnableWindow(h, FALSE); + } + + if (spt > max_spt) { + spt = max_spt; + size = (tracks * hpc * spt) << 9; + set_edit_box_contents(hdlg, IDC_EDIT_HD_SPT, spt); + set_edit_box_contents(hdlg, IDC_EDIT_HD_SIZE, (size >> 20)); + disk_recalc_selection(hdlg); + } + + if (hpc > max_hpc) { + hpc = max_hpc; + size = (tracks * hpc * spt) << 9; + set_edit_box_contents(hdlg, IDC_EDIT_HD_HPC, hpc); + set_edit_box_contents(hdlg, IDC_EDIT_HD_SIZE, (size >> 20)); + disk_recalc_selection(hdlg); + } + + if (tracks > max_tracks) { + tracks = max_tracks; + size = (tracks * hpc * spt) << 9; + set_edit_box_contents(hdlg, IDC_EDIT_HD_CYL, tracks); + set_edit_box_contents(hdlg, IDC_EDIT_HD_SIZE, (size >> 20)); + disk_recalc_selection(hdlg); + } + +hd_add_bus_skip: + no_update = 0; + break; + } + + return FALSE; + } + + return FALSE; +} + + +void +disk_add_open(HWND hwnd, int is_existing) +{ + existing = is_existing; + + hard_disk_added = 0; + + DialogBox(hinstance, (LPCWSTR)DLG_CFG_DISK_ADD, hwnd, disk_add_proc); +} + + +static void +disk_track(uint8_t id) +{ + switch(temp_hdd[id].bus) { + case HDD_BUS_MFM: + mfm_tracking |= (1ULL << (temp_hdd[id].mfm_channel << 3)); + break; + + case HDD_BUS_ESDI: + esdi_tracking |= (1ULL << (temp_hdd[id].esdi_channel << 3)); + break; + + case HDD_BUS_XTIDE: + xtide_tracking |= (1ULL << (temp_hdd[id].xtide_channel << 3)); + break; + + case HDD_BUS_IDE_PIO_ONLY: + case HDD_BUS_IDE_PIO_AND_DMA: + ide_tracking |= (1ULL << (temp_hdd[id].ide_channel << 3)); + break; + + case HDD_BUS_SCSI: + case HDD_BUS_SCSI_REMOVABLE: + scsi_tracking[temp_hdd[id].scsi_id] |= (1ULL << (temp_hdd[id].scsi_lun << 3)); + break; + } +} + + +static void +disk_untrack(uint8_t id) +{ + switch(temp_hdd[id].bus) { + case HDD_BUS_MFM: + mfm_tracking &= ~(1 << (temp_hdd[id].mfm_channel << 3)); + break; + + case HDD_BUS_ESDI: + esdi_tracking &= ~(1 << (temp_hdd[id].esdi_channel << 3)); + break; + + case HDD_BUS_XTIDE: + xtide_tracking &= ~(1 << (temp_hdd[id].xtide_channel << 3)); + break; + + case HDD_BUS_IDE_PIO_ONLY: + case HDD_BUS_IDE_PIO_AND_DMA: + ide_tracking &= ~(1 << (temp_hdd[id].ide_channel << 3)); + break; + + case HDD_BUS_SCSI: + case HDD_BUS_SCSI_REMOVABLE: + scsi_tracking[temp_hdd[id].scsi_id] &= ~(1 << (temp_hdd[id].scsi_lun << 3)); + break; + } +} + + +static void +disk_track_all(void) +{ + int i; + + for (i = 0; i < HDD_NUM; i++) + disk_track(i); +} + + +#ifdef __amd64__ +static LRESULT CALLBACK +#else +static BOOL CALLBACK +#endif +disk_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) +{ + HWND h = INVALID_HANDLE_VALUE; + int old_sel = 0; + int b = 0; + int assign = 0; + + switch (message) { + case WM_INITDIALOG: + ignore_change = 1; + + /* + * Normalize the hard disks so that non-disabled hard + * disks start from index 0, and so they are contiguous. + * This will cause an emulator reset prompt on the first + * opening of this category with a messy hard disk list + * (which can only happen by manually editing the + * configuration file). + */ + disk_normalize_list(); + + h = GetDlgItem(hdlg, IDC_LIST_HARD_DISKS); + disk_init_columns(h); + disk_image_list_init(h); + disk_recalc_list(h); + recalc_next_free_id(hdlg); + disk_add_locations(hdlg); + + if (hd_listview_items > 0) { + ListView_SetItemState(h, 0, LVIS_FOCUSED | LVIS_SELECTED, 0x000F); + hdlv_current_sel = 0; + h = GetDlgItem(hdlg, IDC_COMBO_HD_BUS); + SendMessage(h, CB_SETCURSEL, temp_hdd[0].bus - 1, 0); + } else { + hdlv_current_sel = -1; + } + disk_recalc_location_controls(hdlg, 0, 0); + + ignore_change = 0; + return TRUE; + + case WM_NOTIFY: + if ((hd_listview_items == 0) || ignore_change) return FALSE; + + if ((((LPNMHDR)lParam)->code == LVN_ITEMCHANGED) && (((LPNMHDR)lParam)->idFrom == IDC_LIST_HARD_DISKS)) { + old_sel = hdlv_current_sel; + hdlv_current_sel = disk_get_selected(hdlg); + if (hdlv_current_sel == old_sel) + return FALSE; + + if (hdlv_current_sel == -1) { + ignore_change = 1; + hdlv_current_sel = old_sel; + ListView_SetItemState(h, hdlv_current_sel, LVIS_FOCUSED | LVIS_SELECTED, 0x000F); + ignore_change = 0; + return FALSE; + } + + ignore_change = 1; + h = GetDlgItem(hdlg, IDC_COMBO_HD_BUS); + SendMessage(h, CB_SETCURSEL, temp_hdd[hdlv_current_sel].bus - 1, 0); + disk_recalc_location_controls(hdlg, 0, 0); + } + ignore_change = 0; + break; + + case WM_COMMAND: + switch (LOWORD(wParam)) { + case IDC_COMBO_HD_BUS: + if (ignore_change) + return FALSE; + + ignore_change = 1; + h = GetDlgItem(hdlg, IDC_COMBO_HD_BUS); + b = SendMessage(h, CB_GETCURSEL, 0, 0) + 1; + if (b == temp_hdd[hdlv_current_sel].bus) + goto hd_bus_skip; + disk_untrack(hdlv_current_sel); + assign = (temp_hdd[hdlv_current_sel].bus == b) ? 0 : 1; + if ((b == HDD_BUS_IDE_PIO_ONLY) && (temp_hdd[hdlv_current_sel].bus == HDD_BUS_IDE_PIO_AND_DMA)) + assign = 0; + else if ((b == HDD_BUS_IDE_PIO_AND_DMA) && (temp_hdd[hdlv_current_sel].bus == HDD_BUS_IDE_PIO_ONLY)) + assign = 0; + temp_hdd[hdlv_current_sel].bus = b; + disk_recalc_location_controls(hdlg, 0, assign); + disk_track(hdlv_current_sel); + h = GetDlgItem(hdlg, IDC_LIST_HARD_DISKS); + disk_update_item(h, hdlv_current_sel, 0); +hd_bus_skip: + ignore_change = 0; + return FALSE; + + case IDC_COMBO_HD_CHANNEL: + if (ignore_change) + return FALSE; + + ignore_change = 1; + h = GetDlgItem(hdlg, IDC_COMBO_HD_CHANNEL); + disk_untrack(hdlv_current_sel); + if (temp_hdd[hdlv_current_sel].bus == HDD_BUS_MFM) + temp_hdd[hdlv_current_sel].mfm_channel = SendMessage(h, CB_GETCURSEL, 0, 0) & 0xff; + else if (temp_hdd[hdlv_current_sel].bus == HDD_BUS_ESDI) + temp_hdd[hdlv_current_sel].esdi_channel = SendMessage(h, CB_GETCURSEL, 0, 0) & 0xff; + else if (temp_hdd[hdlv_current_sel].bus == HDD_BUS_XTIDE) + temp_hdd[hdlv_current_sel].xtide_channel = SendMessage(h, CB_GETCURSEL, 0, 0) & 0xff; + disk_track(hdlv_current_sel); + h = GetDlgItem(hdlg, IDC_LIST_HARD_DISKS); + disk_update_item(h, hdlv_current_sel, 0); + ignore_change = 0; + return FALSE; + + case IDC_COMBO_HD_CHANNEL_IDE: + if (ignore_change) + return FALSE; + + ignore_change = 1; + h = GetDlgItem(hdlg, IDC_COMBO_HD_CHANNEL_IDE); + disk_untrack(hdlv_current_sel); + temp_hdd[hdlv_current_sel].ide_channel = SendMessage(h, CB_GETCURSEL, 0, 0) & 0xff; + disk_track(hdlv_current_sel); + h = GetDlgItem(hdlg, IDC_LIST_HARD_DISKS); + disk_update_item(h, hdlv_current_sel, 0); + ignore_change = 0; + return FALSE; + + case IDC_COMBO_HD_ID: + if (ignore_change) + return FALSE; + + ignore_change = 1; + h = GetDlgItem(hdlg, IDC_COMBO_HD_ID); + disk_untrack(hdlv_current_sel); + temp_hdd[hdlv_current_sel].scsi_id = SendMessage(h, CB_GETCURSEL, 0, 0) & 0xff; + disk_track(hdlv_current_sel); + h = GetDlgItem(hdlg, IDC_LIST_HARD_DISKS); + disk_update_item(h, hdlv_current_sel, 0); + ignore_change = 0; + return FALSE; + + case IDC_COMBO_HD_LUN: + if (ignore_change) + return FALSE; + + ignore_change = 1; + h = GetDlgItem(hdlg, IDC_COMBO_HD_LUN); + disk_untrack(hdlv_current_sel); + temp_hdd[hdlv_current_sel].scsi_lun = SendMessage(h, CB_GETCURSEL, 0, 0) & 0xff; + disk_track(hdlv_current_sel); + h = GetDlgItem(hdlg, IDC_LIST_HARD_DISKS); + disk_update_item(h, hdlv_current_sel, 0); + ignore_change = 0; + return FALSE; + + case IDC_BUTTON_HDD_ADD: + disk_add_open(hdlg, 1); + if (hard_disk_added) { + ignore_change = 1; + h = GetDlgItem(hdlg, IDC_LIST_HARD_DISKS); + disk_recalc_list(h); + recalc_next_free_id(hdlg); + disk_track_all(); + ignore_change = 0; + } + return FALSE; + + case IDC_BUTTON_HDD_ADD_NEW: + disk_add_open(hdlg, 0); + if (hard_disk_added) { + ignore_change = 1; + h = GetDlgItem(hdlg, IDC_LIST_HARD_DISKS); + disk_recalc_list(h); + recalc_next_free_id(hdlg); + disk_track_all(); + ignore_change = 0; + } + return FALSE; + + case IDC_BUTTON_HDD_REMOVE: + memcpy(temp_hdd[hdlv_current_sel].fn, L"", 4); + disk_untrack(hdlv_current_sel); + temp_hdd[hdlv_current_sel].bus = HDD_BUS_DISABLED; /* Only set the bus to zero, the list normalize code below will take care of turning this entire entry to a complete zero. */ + disk_normalize_list(); /* Normalize the hard disks so that non-disabled hard disks start from index 0, and so they are contiguous. */ + ignore_change = 1; + h = GetDlgItem(hdlg, IDC_LIST_HARD_DISKS); + disk_recalc_list(h); + recalc_next_free_id(hdlg); + if (hd_listview_items > 0) { + ListView_SetItemState(h, 0, LVIS_FOCUSED | LVIS_SELECTED, 0x000F); + hdlv_current_sel = 0; + h = GetDlgItem(hdlg, IDC_COMBO_HD_BUS); + SendMessage(h, CB_SETCURSEL, temp_hdd[0].bus - 1, 0); + } else { + hdlv_current_sel = -1; + } + disk_recalc_location_controls(hdlg, 0, 0); + ignore_change = 0; + return FALSE; + } + return FALSE; + + default: + break; + } + + return FALSE; +} diff --git a/src/win/win_settings_floppy.h b/src/win/win_settings_floppy.h new file mode 100644 index 0000000..c159cb5 --- /dev/null +++ b/src/win/win_settings_floppy.h @@ -0,0 +1,317 @@ +/* + * VARCem Virtual ARchaeological Computer EMulator. + * An emulator of (mostly) x86-based PC systems and devices, + * using the ISA,EISA,VLB,MCA and PCI system buses, roughly + * spanning the era between 1981 and 1995. + * + * This file is part of the VARCem Project. + * + * Implementation of the Settings dialog. + * + * Version: @(#)win_settings_floppy.h 1.0.1 2018/04/05 + * + * Authors: Fred N. van Kempen, + * Miran Grca, + * + * Copyright 2017,2018 Fred N. van Kempen. + * Copyright 2016-2018 Miran Grca. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the: + * + * Free Software Foundation, Inc. + * 59 Temple Place - Suite 330 + * Boston, MA 02111-1307 + * USA. + */ + + +/************************************************************************ + * * + * Floppy Dialog * + * * + ************************************************************************/ + +/* GLobal variables needed for the Floppy dialog. */ +static int fd_ignore_change = 0; +static int fdlv_current_sel; + +static void +floppy_image_list_init(HWND hwndList) +{ + HICON hiconItem; + HIMAGELIST hSmall; + int i; + + hSmall = ImageList_Create(GetSystemMetrics(SM_CXSMICON), + GetSystemMetrics(SM_CYSMICON), + ILC_MASK | ILC_COLOR32, 1, 1); + + for (i = 0; i < 14; i++) { + hiconItem = LoadIcon(hinstance, (LPCWSTR)fdd_type_to_icon(i)); + ImageList_AddIcon(hSmall, hiconItem); + DestroyIcon(hiconItem); + } + + ListView_SetImageList(hwndList, hSmall, LVSIL_SMALL); +} + + +static BOOL +floppy_recalc_list(HWND hwndList) +{ + WCHAR temp[128]; + char tempA[128]; + LVITEM lvI; + int i; + + lvI.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_STATE; + lvI.stateMask = lvI.state = 0; + + for (i = 0; i < 4; i++) { + lvI.iSubItem = 0; + if (temp_fdd_types[i] > 0) { + strcpy(tempA, fdd_getname(temp_fdd_types[i])); + mbstowcs(temp, tempA, sizeof_w(temp)); + lvI.pszText = temp; + } else { + lvI.pszText = plat_get_string(IDS_5376); + } + lvI.iItem = i; + lvI.iImage = temp_fdd_types[i]; + if (ListView_InsertItem(hwndList, &lvI) == -1) + return FALSE; + + lvI.iSubItem = 1; + lvI.pszText = plat_get_string(temp_fdd_turbo[i] ? IDS_2060 : IDS_2061); + lvI.iItem = i; + lvI.iImage = 0; + if (ListView_SetItem(hwndList, &lvI) == -1) + return FALSE; + + lvI.iSubItem = 2; + lvI.pszText = plat_get_string(temp_fdd_check_bpb[i] ? IDS_2060 : IDS_2061); + lvI.iItem = i; + lvI.iImage = 0; + if (ListView_SetItem(hwndList, &lvI) == -1) + return FALSE; + } + + return TRUE; +} + + +static BOOL +floppy_init_columns(HWND hwndList) +{ + LVCOLUMN lvc; + + lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM; + + lvc.iSubItem = 0; + lvc.pszText = plat_get_string(IDS_2143); + lvc.cx = 292; + lvc.fmt = LVCFMT_LEFT; + if (ListView_InsertColumn(hwndList, 0, &lvc) == -1) + return FALSE; + + lvc.iSubItem = 1; + lvc.pszText = plat_get_string(IDS_2059); + lvc.cx = 50; + lvc.fmt = LVCFMT_LEFT; + if (ListView_InsertColumn(hwndList, 1, &lvc) == -1) + return FALSE; + + lvc.iSubItem = 2; + lvc.pszText = plat_get_string(IDS_2170); + lvc.cx = 75; + lvc.fmt = LVCFMT_LEFT; + if (ListView_InsertColumn(hwndList, 2, &lvc) == -1) + return FALSE; + + return TRUE; +} + + +static int +floppy_get_selected(HWND hdlg) +{ + int drive = -1; + int i, j = 0; + HWND h; + + for (i = 0; i < 6; i++) { + h = GetDlgItem(hdlg, IDC_LIST_FLOPPY_DRIVES); + j = ListView_GetItemState(h, i, LVIS_SELECTED); + if (j) + drive = i; + } + + return drive; +} + + +static void +floppy_update_item(HWND hwndList, int i) +{ + WCHAR temp[128]; + char tempA[128]; + LVITEM lvI; + + lvI.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_STATE; + lvI.stateMask = lvI.iSubItem = lvI.state = 0; + + lvI.iSubItem = 0; + lvI.iItem = i; + + if (temp_fdd_types[i] > 0) { + strcpy(tempA, fdd_getname(temp_fdd_types[i])); + mbstowcs(temp, tempA, sizeof_w(temp)); + lvI.pszText = temp; + } else { + lvI.pszText = plat_get_string(IDS_5376); + } + lvI.iImage = temp_fdd_types[i]; + if (ListView_SetItem(hwndList, &lvI) == -1) + return; + + lvI.iSubItem = 1; + lvI.pszText = plat_get_string(temp_fdd_turbo[i] ? IDS_2060 : IDS_2061); + lvI.iItem = i; + lvI.iImage = 0; + if (ListView_SetItem(hwndList, &lvI) == -1) + return; + + lvI.iSubItem = 2; + lvI.pszText = plat_get_string(temp_fdd_check_bpb[i] ? IDS_2060 : IDS_2061); + lvI.iItem = i; + lvI.iImage = 0; + if (ListView_SetItem(hwndList, &lvI) == -1) + return; +} + + +#ifdef __amd64__ +static LRESULT CALLBACK +#else +static BOOL CALLBACK +#endif +floppy_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) +{ + WCHAR temp[128]; + HWND h = INVALID_HANDLE_VALUE; + int i = 0; + int old_sel = 0; + + switch (message) { + case WM_INITDIALOG: + fd_ignore_change = 1; + + fdlv_current_sel = 0; + h = GetDlgItem(hdlg, IDC_LIST_FLOPPY_DRIVES); + floppy_init_columns(h); + floppy_image_list_init(h); + floppy_recalc_list(h); + ListView_SetItemState(h, 0, LVIS_FOCUSED | LVIS_SELECTED, 0x000F); + h = GetDlgItem(hdlg, IDC_COMBO_FD_TYPE); + for (i = 0; i < 14; i++) { + if (i == 0) { + SendMessage(h, CB_ADDSTRING, 0, (LPARAM)plat_get_string(IDS_5376)); + } else { + mbstowcs(temp, fdd_getname(i), sizeof_w(temp)); + SendMessage(h, CB_ADDSTRING, 0, (LPARAM)temp); + } + } + SendMessage(h, CB_SETCURSEL, temp_fdd_types[fdlv_current_sel], 0); + + h = GetDlgItem(hdlg, IDC_CHECKTURBO); + SendMessage(h, BM_SETCHECK, temp_fdd_turbo[fdlv_current_sel], 0); + + h = GetDlgItem(hdlg, IDC_CHECKBPB); + SendMessage(h, BM_SETCHECK, temp_fdd_check_bpb[fdlv_current_sel], 0); + + fd_ignore_change = 0; + return TRUE; + + case WM_NOTIFY: + if (fd_ignore_change) + return FALSE; + + if ((((LPNMHDR)lParam)->code == LVN_ITEMCHANGED) && (((LPNMHDR)lParam)->idFrom == IDC_LIST_FLOPPY_DRIVES)) { + old_sel = fdlv_current_sel; + fdlv_current_sel = floppy_get_selected(hdlg); + if (fdlv_current_sel == old_sel) { + return FALSE; + } else if (fdlv_current_sel == -1) { + fd_ignore_change = 1; + fdlv_current_sel = old_sel; + ListView_SetItemState(h, fdlv_current_sel, LVIS_FOCUSED | LVIS_SELECTED, 0x000F); + fd_ignore_change = 0; + return FALSE; + } + fd_ignore_change = 1; + h = GetDlgItem(hdlg, IDC_COMBO_FD_TYPE); + SendMessage(h, CB_SETCURSEL, temp_fdd_types[fdlv_current_sel], 0); + h = GetDlgItem(hdlg, IDC_CHECKTURBO); + SendMessage(h, BM_SETCHECK, temp_fdd_turbo[fdlv_current_sel], 0); + h = GetDlgItem(hdlg, IDC_CHECKBPB); + SendMessage(h, BM_SETCHECK, temp_fdd_check_bpb[fdlv_current_sel], 0); + fd_ignore_change = 0; + } + break; + + case WM_COMMAND: + switch (LOWORD(wParam)) { + case IDC_COMBO_FD_TYPE: + if (fd_ignore_change) + return FALSE; + + fd_ignore_change = 1; + h = GetDlgItem(hdlg, IDC_COMBO_FD_TYPE); + temp_fdd_types[fdlv_current_sel] = SendMessage(h, CB_GETCURSEL, 0, 0); + h = GetDlgItem(hdlg, IDC_LIST_FLOPPY_DRIVES); + floppy_update_item(h, fdlv_current_sel); + fd_ignore_change = 0; + return FALSE; + + case IDC_CHECKTURBO: + if (fd_ignore_change) + return FALSE; + + fd_ignore_change = 1; + h = GetDlgItem(hdlg, IDC_CHECKTURBO); + temp_fdd_turbo[fdlv_current_sel] = SendMessage(h, BM_GETCHECK, 0, 0); + h = GetDlgItem(hdlg, IDC_LIST_FLOPPY_DRIVES); + floppy_update_item(h, fdlv_current_sel); + fd_ignore_change = 0; + return FALSE; + + case IDC_CHECKBPB: + if (fd_ignore_change) + return FALSE; + + fd_ignore_change = 1; + h = GetDlgItem(hdlg, IDC_CHECKBPB); + temp_fdd_check_bpb[fdlv_current_sel] = SendMessage(h, BM_GETCHECK, 0, 0); + h = GetDlgItem(hdlg, IDC_LIST_FLOPPY_DRIVES); + floppy_update_item(h, fdlv_current_sel); + fd_ignore_change = 0; + return FALSE; + } + + default: + break; + } + + return FALSE; +} diff --git a/src/win/win_settings_input.h b/src/win/win_settings_input.h new file mode 100644 index 0000000..9f38d7c --- /dev/null +++ b/src/win/win_settings_input.h @@ -0,0 +1,190 @@ +/* + * VARCem Virtual ARchaeological Computer EMulator. + * An emulator of (mostly) x86-based PC systems and devices, + * using the ISA,EISA,VLB,MCA and PCI system buses, roughly + * spanning the era between 1981 and 1995. + * + * This file is part of the VARCem Project. + * + * Implementation of the Settings dialog. + * + * Version: @(#)win_settings_input.h 1.0.1 2018/04/05 + * + * Authors: Fred N. van Kempen, + * Miran Grca, + * + * Copyright 2017,2018 Fred N. van Kempen. + * Copyright 2016-2018 Miran Grca. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the: + * + * Free Software Foundation, Inc. + * 59 Temple Place - Suite 330 + * Boston, MA 02111-1307 + * USA. + */ + + +/************************************************************************ + * * + * Input Dialog * + * * + ************************************************************************/ + +static int +mouse_valid(int num, int m) +{ + const device_t *dev; + + if ((num == MOUSE_TYPE_INTERNAL) && + !(machines[m].flags & MACHINE_MOUSE)) return(0); + + dev = mouse_get_device(num); + + return(device_is_valid(dev, machines[m].flags)); +} + + +#ifdef __amd64__ +static LRESULT CALLBACK +#else +static BOOL CALLBACK +#endif +input_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) +{ + WCHAR temp[128]; + char *stransi; + HWND h; + int c; + int d = 0; + + switch (message) { + case WM_INITDIALOG: + h = GetDlgItem(hdlg, IDC_COMBO_MOUSE); + d = 0; + for (c = 0; c < mouse_get_ndev(); c++) { + settings_mouse_to_list[c] = d; + + if (mouse_valid(c, temp_machine)) { + stransi = mouse_get_name(c); + mbstowcs(temp, stransi, sizeof_w(temp)); + SendMessage(h, CB_ADDSTRING, 0, (LPARAM)temp); + + settings_list_to_mouse[d] = c; + d++; + } + } + + SendMessage(h, CB_SETCURSEL, settings_mouse_to_list[temp_mouse], 0); + + h = GetDlgItem(hdlg, IDC_CONFIGURE_MOUSE); + if (mouse_has_config(temp_mouse)) + EnableWindow(h, TRUE); + else + EnableWindow(h, FALSE); + + h = GetDlgItem(hdlg, IDC_COMBO_JOYSTICK); + c = 0; + while ((stransi = joystick_get_name(c)) != NULL) { + mbstowcs(temp, stransi, sizeof_w(temp)); + SendMessage(h, CB_ADDSTRING, 0, (LPARAM)temp); + c++; + } + EnableWindow(h, TRUE); + SendMessage(h, CB_SETCURSEL, temp_joystick, 0); + + h = GetDlgItem(hdlg, IDC_JOY1); + EnableWindow(h, (joystick_get_max_joysticks(temp_joystick) >= 1) ? TRUE : FALSE); + h = GetDlgItem(hdlg, IDC_JOY2); + EnableWindow(h, (joystick_get_max_joysticks(temp_joystick) >= 2) ? TRUE : FALSE); + h = GetDlgItem(hdlg, IDC_JOY3); + EnableWindow(h, (joystick_get_max_joysticks(temp_joystick) >= 3) ? TRUE : FALSE); + h = GetDlgItem(hdlg, IDC_JOY4); + EnableWindow(h, (joystick_get_max_joysticks(temp_joystick) >= 4) ? TRUE : FALSE); + + return TRUE; + + case WM_COMMAND: + switch (LOWORD(wParam)) { + case IDC_COMBO_MOUSE: + h = GetDlgItem(hdlg, IDC_COMBO_MOUSE); + temp_mouse = settings_list_to_mouse[SendMessage(h, CB_GETCURSEL, 0, 0)]; + + h = GetDlgItem(hdlg, IDC_CONFIGURE_MOUSE); + if (mouse_has_config(temp_mouse)) + EnableWindow(h, TRUE); + else + EnableWindow(h, FALSE); + break; + + case IDC_CONFIGURE_MOUSE: + h = GetDlgItem(hdlg, IDC_COMBO_MOUSE); + temp_mouse = settings_list_to_mouse[SendMessage(h, CB_GETCURSEL, 0, 0)]; + temp_deviceconfig |= deviceconfig_open(hdlg, (void *)mouse_get_device(temp_mouse)); + break; + + case IDC_COMBO_JOYSTICK: + h = GetDlgItem(hdlg, IDC_COMBO_JOYSTICK); + temp_joystick = SendMessage(h, CB_GETCURSEL, 0, 0); + + h = GetDlgItem(hdlg, IDC_JOY1); + EnableWindow(h, (joystick_get_max_joysticks(temp_joystick) >= 1) ? TRUE : FALSE); + h = GetDlgItem(hdlg, IDC_JOY2); + EnableWindow(h, (joystick_get_max_joysticks(temp_joystick) >= 2) ? TRUE : FALSE); + h = GetDlgItem(hdlg, IDC_JOY3); + EnableWindow(h, (joystick_get_max_joysticks(temp_joystick) >= 3) ? TRUE : FALSE); + h = GetDlgItem(hdlg, IDC_JOY4); + EnableWindow(h, (joystick_get_max_joysticks(temp_joystick) >= 4) ? TRUE : FALSE); + break; + + case IDC_JOY1: + h = GetDlgItem(hdlg, IDC_COMBO_JOYSTICK); + temp_joystick = SendMessage(h, CB_GETCURSEL, 0, 0); + temp_deviceconfig |= joystickconfig_open(hdlg, 0, temp_joystick); + break; + + case IDC_JOY2: + h = GetDlgItem(hdlg, IDC_COMBO_JOYSTICK); + temp_joystick = SendMessage(h, CB_GETCURSEL, 0, 0); + temp_deviceconfig |= joystickconfig_open(hdlg, 1, temp_joystick); + break; + + case IDC_JOY3: + h = GetDlgItem(hdlg, IDC_COMBO_JOYSTICK); + temp_joystick = SendMessage(h, CB_GETCURSEL, 0, 0); + temp_deviceconfig |= joystickconfig_open(hdlg, 2, temp_joystick); + break; + + case IDC_JOY4: + h = GetDlgItem(hdlg, IDC_COMBO_JOYSTICK); + temp_joystick = SendMessage(h, CB_GETCURSEL, 0, 0); + temp_deviceconfig |= joystickconfig_open(hdlg, 3, temp_joystick); + break; + } + return FALSE; + + case WM_SAVESETTINGS: + h = GetDlgItem(hdlg, IDC_COMBO_MOUSE); + temp_mouse = settings_list_to_mouse[SendMessage(h, CB_GETCURSEL, 0, 0)]; + + h = GetDlgItem(hdlg, IDC_COMBO_JOYSTICK); + temp_joystick = SendMessage(h, CB_GETCURSEL, 0, 0); + return FALSE; + + default: + break; + } + + return FALSE; +} diff --git a/src/win/win_settings_machine.h b/src/win/win_settings_machine.h new file mode 100644 index 0000000..4554043 --- /dev/null +++ b/src/win/win_settings_machine.h @@ -0,0 +1,320 @@ +/* + * VARCem Virtual ARchaeological Computer EMulator. + * An emulator of (mostly) x86-based PC systems and devices, + * using the ISA,EISA,VLB,MCA and PCI system buses, roughly + * spanning the era between 1981 and 1995. + * + * This file is part of the VARCem Project. + * + * Implementation of the Settings dialog. + * + * Version: @(#)win_settings_machine.h 1.0.1 2018/04/05 + * + * Authors: Fred N. van Kempen, + * Miran Grca, + * + * Copyright 2017,2018 Fred N. van Kempen. + * Copyright 2016-2018 Miran Grca. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the: + * + * Free Software Foundation, Inc. + * 59 Temple Place - Suite 330 + * Boston, MA 02111-1307 + * USA. + */ + + +/************************************************************************ + * * + * Machine Dialog * + * * + ************************************************************************/ + +static void +machine_recalc_cpu(HWND hdlg) +{ + HWND h; +#ifdef USE_DYNAREC + int cpu_flags; +#endif + int cpu_type; + int rs = 0; + + rs = machine_getromset_ex(temp_machine); + + h = GetDlgItem(hdlg, IDC_COMBO_WS); + cpu_type = machines[romstomachine[rs]].cpu[temp_cpu_m].cpus[temp_cpu].cpu_type; + if ((cpu_type >= CPU_286) && (cpu_type <= CPU_386DX)) + EnableWindow(h, TRUE); + else + EnableWindow(h, FALSE); + +#ifdef USE_DYNAREC + h = GetDlgItem(hdlg, IDC_CHECK_DYNAREC); + cpu_flags = machines[romstomachine[rs]].cpu[temp_cpu_m].cpus[temp_cpu].cpu_flags; + if (!(cpu_flags & CPU_SUPPORTS_DYNAREC) && (cpu_flags & CPU_REQUIRES_DYNAREC)) { + fatal("Attempting to select a CPU that requires the recompiler and does not support it at the same time\n"); + } + if (!(cpu_flags & CPU_SUPPORTS_DYNAREC) || (cpu_flags & CPU_REQUIRES_DYNAREC)) { + if (!(cpu_flags & CPU_SUPPORTS_DYNAREC)) + temp_dynarec = 0; + if (cpu_flags & CPU_REQUIRES_DYNAREC) + temp_dynarec = 1; + SendMessage(h, BM_SETCHECK, temp_dynarec, 0); + EnableWindow(h, FALSE); + } else { + EnableWindow(h, TRUE); + } +#endif + + h = GetDlgItem(hdlg, IDC_CHECK_FPU); + cpu_type = machines[romstomachine[rs]].cpu[temp_cpu_m].cpus[temp_cpu].cpu_type; + if ((cpu_type < CPU_i486DX) && (cpu_type >= CPU_286)) { + EnableWindow(h, TRUE); + } else if (cpu_type < CPU_286) { + temp_fpu = 0; + EnableWindow(h, FALSE); + } else { + temp_fpu = 1; + EnableWindow(h, FALSE); + } + + SendMessage(h, BM_SETCHECK, temp_fpu, 0); +} + + +static void +machine_recalc_cpu_m(HWND hdlg) +{ + WCHAR temp[128]; + const char *stransi; + HWND h; + int c = 0; + int rs = 0; + + rs = machine_getromset_ex(temp_machine); + + h = GetDlgItem(hdlg, IDC_COMBO_CPU); + SendMessage(h, CB_RESETCONTENT, 0, 0); + c = 0; + while (machines[romstomachine[rs]].cpu[temp_cpu_m].cpus[c].cpu_type != -1) { + stransi = machines[romstomachine[rs]].cpu[temp_cpu_m].cpus[c].name; + mbstowcs(temp, stransi, sizeof_w(temp)); + SendMessage(h, CB_ADDSTRING, 0, (LPARAM)temp); + c++; + } + EnableWindow(h, TRUE); + + if (temp_cpu >= c) + temp_cpu = (c - 1); + SendMessage(h, CB_SETCURSEL, temp_cpu, 0); + + machine_recalc_cpu(hdlg); +} + + +static void +machine_recalc_machine(HWND hdlg) +{ + WCHAR temp[128]; + const char *stransi; + HWND h; + int c = 0; + int rs = 0; + UDACCEL accel; + + rs = machine_getromset_ex(temp_machine); + + h = GetDlgItem(hdlg, IDC_CONFIGURE_MACHINE); + if (machine_getdevice(temp_machine)) + EnableWindow(h, TRUE); + else + EnableWindow(h, FALSE); + + h = GetDlgItem(hdlg, IDC_COMBO_CPU_TYPE); + SendMessage(h, CB_RESETCONTENT, 0, 0); + c = 0; + while (machines[romstomachine[rs]].cpu[c].cpus != NULL && c < 4) { + stransi = machines[romstomachine[rs]].cpu[c].name; + mbstowcs(temp, stransi, sizeof_w(temp)); + SendMessage(h, CB_ADDSTRING, 0, (LPARAM)temp); + c++; + } + EnableWindow(h, TRUE); + + if (temp_cpu_m >= c) + temp_cpu_m = (c - 1); + SendMessage(h, CB_SETCURSEL, temp_cpu_m, 0); + if (c == 1) + EnableWindow(h, FALSE); + else + EnableWindow(h, TRUE); + + machine_recalc_cpu_m(hdlg); + + h = GetDlgItem(hdlg, IDC_MEMSPIN); + SendMessage(h, UDM_SETRANGE, 0, (machines[romstomachine[rs]].min_ram << 16) | machines[romstomachine[rs]].max_ram); + accel.nSec = 0; + accel.nInc = machines[romstomachine[rs]].ram_granularity; + SendMessage(h, UDM_SETACCEL, 1, (LPARAM)&accel); + + if (!(machines[romstomachine[rs]].flags & MACHINE_AT) || (machines[romstomachine[rs]].ram_granularity >= 128)) { + SendMessage(h, UDM_SETPOS, 0, temp_mem_size); + h = GetDlgItem(hdlg, IDC_TEXT_MB); + SendMessage(h, WM_SETTEXT, 0, (LPARAM)plat_get_string(IDS_2094)); + } else { + SendMessage(h, UDM_SETPOS, 0, temp_mem_size / 1024); + h = GetDlgItem(hdlg, IDC_TEXT_MB); + SendMessage(h, WM_SETTEXT, 0, (LPARAM)plat_get_string(IDS_2087)); + } +} + + +#ifdef __amd64__ +static LRESULT CALLBACK +#else +static BOOL CALLBACK +#endif +machine_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) +{ + WCHAR temp[128]; + char tempA[128]; + const char *stransi; + HWND h; + int c; + int d = 0; + + switch (message) { + case WM_INITDIALOG: + h = GetDlgItem(hdlg, IDC_COMBO_MACHINE); + for (c = 0; c < ROM_MAX; c++) + romstolist[c] = 0; + c = d = 0; + while (machines[c].id != -1) { + if (romspresent[machines[c].id]) { + stransi = machines[c].name; + mbstowcs(temp, stransi, sizeof_w(temp)); + SendMessage(h, CB_ADDSTRING, 0, (LPARAM)temp); + machinetolist[c] = d; + listtomachine[d] = c; + romstolist[machines[c].id] = d; + romstomachine[machines[c].id] = c; + d++; + } + c++; + } + SendMessage(h, CB_SETCURSEL, machinetolist[temp_machine], 0); + + h = GetDlgItem(hdlg, IDC_COMBO_WS); + SendMessage(h, CB_ADDSTRING, 0, (LPARAM)plat_get_string(IDS_2131)); + + for (c = 0; c < 8; c++) { + swprintf(temp, sizeof_w(temp), plat_get_string(2132), c); + SendMessage(h, CB_ADDSTRING, 0, (LPARAM)temp); + } + + SendMessage(h, CB_SETCURSEL, temp_wait_states, 0); + +#ifdef USE_DYNAREC + h = GetDlgItem(hdlg, IDC_CHECK_DYNAREC); + SendMessage(h, BM_SETCHECK, temp_dynarec, 0); +#endif + + h = GetDlgItem(hdlg, IDC_MEMSPIN); + SendMessage(h, UDM_SETBUDDY, (WPARAM)GetDlgItem(hdlg, IDC_MEMTEXT), 0); + + h = GetDlgItem(hdlg, IDC_CHECK_SYNC); + SendMessage(h, BM_SETCHECK, temp_sync, 0); + + machine_recalc_machine(hdlg); + + return TRUE; + + case WM_COMMAND: + switch (LOWORD(wParam)) { + case IDC_COMBO_MACHINE: + if (HIWORD(wParam) == CBN_SELCHANGE) { + h = GetDlgItem(hdlg, IDC_COMBO_MACHINE); + temp_machine = listtomachine[SendMessage(h, CB_GETCURSEL, 0, 0)]; + + machine_recalc_machine(hdlg); + } + break; + + case IDC_COMBO_CPU_TYPE: + if (HIWORD(wParam) == CBN_SELCHANGE) { + h = GetDlgItem(hdlg, IDC_COMBO_CPU_TYPE); + temp_cpu_m = SendMessage(h, CB_GETCURSEL, 0, 0); + + temp_cpu = 0; + machine_recalc_cpu_m(hdlg); + } + break; + + case IDC_COMBO_CPU: + if (HIWORD(wParam) == CBN_SELCHANGE) { + h = GetDlgItem(hdlg, IDC_COMBO_CPU); + temp_cpu = SendMessage(h, CB_GETCURSEL, 0, 0); + + machine_recalc_cpu(hdlg); + } + break; + + case IDC_CONFIGURE_MACHINE: + h = GetDlgItem(hdlg, IDC_COMBO_MACHINE); + temp_machine = listtomachine[SendMessage(h, CB_GETCURSEL, 0, 0)]; + + temp_deviceconfig |= deviceconfig_open(hdlg, (void *)machine_getdevice(temp_machine)); + break; + } + + return FALSE; + + case WM_SAVESETTINGS: +#ifdef USE_DYNAREC + h = GetDlgItem(hdlg, IDC_CHECK_DYNAREC); + temp_dynarec = SendMessage(h, BM_GETCHECK, 0, 0); +#endif + + h = GetDlgItem(hdlg, IDC_CHECK_SYNC); + temp_sync = SendMessage(h, BM_GETCHECK, 0, 0); + + h = GetDlgItem(hdlg, IDC_CHECK_FPU); + temp_fpu = SendMessage(h, BM_GETCHECK, 0, 0); + + h = GetDlgItem(hdlg, IDC_COMBO_WS); + temp_wait_states = SendMessage(h, CB_GETCURSEL, 0, 0); + + h = GetDlgItem(hdlg, IDC_MEMTEXT); + SendMessage(h, WM_GETTEXT, sizeof_w(temp), (LPARAM)temp); + wcstombs(tempA, temp, sizeof(tempA)); + sscanf(tempA, "%i", &temp_mem_size); + temp_mem_size &= ~(machines[temp_machine].ram_granularity - 1); + if (temp_mem_size < machines[temp_machine].min_ram) + temp_mem_size = machines[temp_machine].min_ram; + else if (temp_mem_size > machines[temp_machine].max_ram) + temp_mem_size = machines[temp_machine].max_ram; + if ((machines[temp_machine].flags & MACHINE_AT) && (machines[temp_machine].ram_granularity < 128)) + temp_mem_size *= 1024; + if (machines[temp_machine].flags & MACHINE_VIDEO) + vid_card = VID_INTERNAL; + return FALSE; + + default: + break; + } + + return FALSE; +} diff --git a/src/win/win_settings_network.h b/src/win/win_settings_network.h new file mode 100644 index 0000000..5217bd2 --- /dev/null +++ b/src/win/win_settings_network.h @@ -0,0 +1,206 @@ +/* + * VARCem Virtual ARchaeological Computer EMulator. + * An emulator of (mostly) x86-based PC systems and devices, + * using the ISA,EISA,VLB,MCA and PCI system buses, roughly + * spanning the era between 1981 and 1995. + * + * This file is part of the VARCem Project. + * + * Implementation of the Settings dialog. + * + * Version: @(#)win_settings_network.h 1.0.1 2018/04/05 + * + * Authors: Fred N. van Kempen, + * Miran Grca, + * + * Copyright 2017,2018 Fred N. van Kempen. + * Copyright 2016-2018 Miran Grca. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the: + * + * Free Software Foundation, Inc. + * 59 Temple Place - Suite 330 + * Boston, MA 02111-1307 + * USA. + */ + + +/************************************************************************ + * * + * Network Dialog * + * * + ************************************************************************/ + +/* Global variables for the Network dialog. */ +static int net_ignore_message = 0; + +static void +network_recalc_combos(HWND hdlg) +{ + HWND h; + + net_ignore_message = 1; + + h = GetDlgItem(hdlg, IDC_COMBO_PCAP); + if (temp_net_type == NET_TYPE_PCAP) + EnableWindow(h, TRUE); + else + EnableWindow(h, FALSE); + + h = GetDlgItem(hdlg, IDC_COMBO_NET); + if (temp_net_type == NET_TYPE_SLIRP) + EnableWindow(h, TRUE); + else if ((temp_net_type == NET_TYPE_PCAP) && (network_dev_to_id(temp_host_dev) > 0)) + EnableWindow(h, TRUE); + else + EnableWindow(h, FALSE); + + h = GetDlgItem(hdlg, IDC_CONFIGURE_NET); + if (network_card_has_config(temp_net_card) && (temp_net_type == NET_TYPE_SLIRP)) { + EnableWindow(h, TRUE); + } else if (network_card_has_config(temp_net_card) && + (temp_net_type == NET_TYPE_PCAP) && + (network_dev_to_id(temp_host_dev) > 0)) { + EnableWindow(h, TRUE); + } else { + EnableWindow(h, FALSE); + } + + net_ignore_message = 0; +} + + +#ifdef __amd64__ +static LRESULT CALLBACK +#else +static BOOL CALLBACK +#endif +network_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) +{ + WCHAR temp[128]; + char *stransi; + HWND h; + int c, d; + + switch (message) { + case WM_INITDIALOG: + h = GetDlgItem(hdlg, IDC_COMBO_NET_TYPE); +//FIXME: take strings from network.c table.. --FvK + SendMessage(h, CB_ADDSTRING, 0, (LPARAM)L"None"); + SendMessage(h, CB_ADDSTRING, 0, (LPARAM)L"PCap"); + SendMessage(h, CB_ADDSTRING, 0, (LPARAM)L"SLiRP"); + SendMessage(h, CB_SETCURSEL, temp_net_type, 0); + + h = GetDlgItem(hdlg, IDC_COMBO_PCAP); + if (temp_net_type == NET_TYPE_PCAP) + EnableWindow(h, TRUE); + else + EnableWindow(h, FALSE); + + h = GetDlgItem(hdlg, IDC_COMBO_PCAP); + for (c = 0; c < network_ndev; c++) { + mbstowcs(temp, network_devs[c].description, sizeof_w(temp)); + SendMessage(h, CB_ADDSTRING, 0, (LPARAM)temp); + } + SendMessage(h, CB_SETCURSEL, network_dev_to_id(temp_host_dev), 0); + + /*NIC config*/ + h = GetDlgItem(hdlg, IDC_COMBO_NET); + c = d = 0; + while (1) { + stransi = network_card_getname(c); + if (stransi == NULL) + break; + + settings_network_to_list[c] = d; + + if (network_card_available(c) && device_is_valid(network_card_getdevice(c), machines[temp_machine].flags)) { + mbstowcs(temp, stransi, sizeof_w(temp)); + SendMessage(h, CB_ADDSTRING, 0, (LPARAM)temp); + + settings_list_to_network[d] = c; + d++; + } + + c++; + } + SendMessage(h, CB_SETCURSEL, settings_network_to_list[temp_net_card], 0); + + EnableWindow(h, d ? TRUE : FALSE); + network_recalc_combos(hdlg); + return TRUE; + + case WM_COMMAND: + switch (LOWORD(wParam)) { + case IDC_COMBO_NET_TYPE: + if (net_ignore_message) + return FALSE; + + h = GetDlgItem(hdlg, IDC_COMBO_NET_TYPE); + temp_net_type = SendMessage(h, CB_GETCURSEL, 0, 0); + + network_recalc_combos(hdlg); + break; + + case IDC_COMBO_PCAP: + if (net_ignore_message) + return FALSE; + + h = GetDlgItem(hdlg, IDC_COMBO_PCAP); + memset(temp_host_dev, '\0', sizeof(temp_host_dev)); + strcpy(temp_host_dev, network_devs[SendMessage(h, CB_GETCURSEL, 0, 0)].device); + + network_recalc_combos(hdlg); + break; + + case IDC_COMBO_NET: + if (net_ignore_message) + return FALSE; + + h = GetDlgItem(hdlg, IDC_COMBO_NET); + temp_net_card = settings_list_to_network[SendMessage(h, CB_GETCURSEL, 0, 0)]; + + network_recalc_combos(hdlg); + break; + + case IDC_CONFIGURE_NET: + if (net_ignore_message) + return FALSE; + + h = GetDlgItem(hdlg, IDC_COMBO_NET); + temp_net_card = settings_list_to_network[SendMessage(h, CB_GETCURSEL, 0, 0)]; + + temp_deviceconfig |= deviceconfig_open(hdlg, (void *)network_card_getdevice(temp_net_card)); + break; + } + return FALSE; + + case WM_SAVESETTINGS: + h = GetDlgItem(hdlg, IDC_COMBO_NET_TYPE); + temp_net_type = SendMessage(h, CB_GETCURSEL, 0, 0); + + h = GetDlgItem(hdlg, IDC_COMBO_PCAP); + memset(temp_host_dev, '\0', sizeof(temp_host_dev)); + strcpy(temp_host_dev, network_devs[SendMessage(h, CB_GETCURSEL, 0, 0)].device); + + h = GetDlgItem(hdlg, IDC_COMBO_NET); + temp_net_card = settings_list_to_network[SendMessage(h, CB_GETCURSEL, 0, 0)]; + return FALSE; + + default: + break; + } + + return FALSE; +} diff --git a/src/win/win_settings_periph.h b/src/win/win_settings_periph.h new file mode 100644 index 0000000..8ce84f4 --- /dev/null +++ b/src/win/win_settings_periph.h @@ -0,0 +1,257 @@ +/* + * VARCem Virtual ARchaeological Computer EMulator. + * An emulator of (mostly) x86-based PC systems and devices, + * using the ISA,EISA,VLB,MCA and PCI system buses, roughly + * spanning the era between 1981 and 1995. + * + * This file is part of the VARCem Project. + * + * Implementation of the Settings dialog. + * + * Version: @(#)win_settings_periph.h 1.0.1 2018/04/05 + * + * Authors: Fred N. van Kempen, + * Miran Grca, + * + * Copyright 2017,2018 Fred N. van Kempen. + * Copyright 2016-2018 Miran Grca. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the: + * + * Free Software Foundation, Inc. + * 59 Temple Place - Suite 330 + * Boston, MA 02111-1307 + * USA. + */ + + +/************************************************************************ + * * + * (Other) Peripherals Dialog * + * * + ************************************************************************/ + +static char *hdc_names[16]; +static const int valid_ide_irqs[11] = { 2, 3, 4, 5, 7, 9, 10, 11, 12, 14, 15 }; + + +static int +find_irq_in_array(int irq, int def) +{ + int i; + + for (i = 0; i < 11; i++) { + if (valid_ide_irqs[i] == irq) + return(i + 1); + } + + return(7 + def); +} + + +static void +recalc_hdc_list(HWND hdlg, int machine, int use_selected_hdc) +{ + WCHAR temp[128]; + char old_name[32]; + char *stransi; + HWND h; + int valid; + int c, d; + + h = GetDlgItem(hdlg, IDC_COMBO_HDC); + valid = 0; + + if (use_selected_hdc) { + c = SendMessage(h, CB_GETCURSEL, 0, 0); + + if (c != -1 && hdc_names[c]) + strcpy(old_name, hdc_names[c]); + else + strcpy(old_name, "none"); + } else { + strcpy(old_name, hdc_get_internal_name(temp_hdc_type)); + } + + SendMessage(h, CB_RESETCONTENT, 0, 0); + c = d = 0; + while (1) { + stransi = hdc_get_name(c); + if (stransi == NULL) + break; + + if (c==1 && !(machines[temp_machine].flags&MACHINE_HDC)) { + /* Skip "Internal" if machine doesn't have one. */ + c++; + continue; + } + if (!hdc_available(c) || !device_is_valid(hdc_get_device(c), machines[temp_machine].flags)) { + c++; + continue; + } + mbstowcs(temp, stransi, sizeof_w(temp)); + SendMessage(h, CB_ADDSTRING, 0, (LPARAM)temp); + + hdc_names[d] = hdc_get_internal_name(c); + if (! strcmp(old_name, hdc_names[d])) { + SendMessage(h, CB_SETCURSEL, d, 0); + valid = 1; + } + c++; + d++; + } + + if (! valid) + SendMessage(h, CB_SETCURSEL, 0, 0); + + EnableWindow(h, d ? TRUE : FALSE); +} + + +#ifdef __amd64__ +static LRESULT CALLBACK +#else +static BOOL CALLBACK +#endif +peripherals_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) +{ + WCHAR temp[128]; + const char *stransi; + const device_t *dev; + int c, d; + HWND h; + + switch (message) { + case WM_INITDIALOG: + /*SCSI config*/ + h = GetDlgItem(hdlg, IDC_COMBO_SCSI); + c = d = 0; + while (1) { + stransi = scsi_card_getname(c); + if (! *stransi) + break; + + settings_scsi_to_list[c] = d; + if (scsi_card_available(c)) { + dev = scsi_card_getdevice(c); + + if (device_is_valid(dev, machines[temp_machine].flags)) { + if (c == 0) { + SendMessage(h, CB_ADDSTRING, 0, (LPARAM)plat_get_string(IDS_2152)); + } else { + mbstowcs(temp, stransi, sizeof_w(temp)); + SendMessage(h, CB_ADDSTRING, 0, (LPARAM)temp); + } + settings_list_to_scsi[d] = c; + d++; + } + } + + c++; + } + SendMessage(h, CB_SETCURSEL, settings_scsi_to_list[temp_scsi_card], 0); + EnableWindow(h, d ? TRUE : FALSE); + + h = GetDlgItem(hdlg, IDC_CONFIGURE_SCSI); + if (scsi_card_has_config(temp_scsi_card)) + EnableWindow(h, TRUE); + else + EnableWindow(h, FALSE); + + recalc_hdc_list(hdlg, temp_machine, 0); + + h = GetDlgItem(hdlg, IDC_COMBO_IDE_TER); + SendMessage(h, CB_ADDSTRING, 0, (LPARAM)plat_get_string(IDS_5376)); + for (c = 0; c < 11; c++) { + swprintf(temp, sizeof_w(temp), plat_get_string(IDS_2155), valid_ide_irqs[c]); + SendMessage(h, CB_ADDSTRING, 0, (LPARAM)temp); + } + if (temp_ide_ter) + SendMessage(h, CB_SETCURSEL, find_irq_in_array(temp_ide_ter_irq, 0), 0); + else + SendMessage(h, CB_SETCURSEL, 0, 0); + + h = GetDlgItem(hdlg, IDC_COMBO_IDE_QUA); + SendMessage(h, CB_ADDSTRING, 0, (LPARAM)plat_get_string(IDS_5376)); + for (c = 0; c < 11; c++) { + swprintf(temp, sizeof_w(temp), plat_get_string(IDS_2155), valid_ide_irqs[c]); + SendMessage(h, CB_ADDSTRING, 0, (LPARAM)temp); + } + if (temp_ide_qua) + SendMessage(h, CB_SETCURSEL, find_irq_in_array(temp_ide_qua_irq, 1), 0); + else + SendMessage(h, CB_SETCURSEL, 0, 0); + + h = GetDlgItem(hdlg, IDC_CHECK_BUGGER); + SendMessage(h, BM_SETCHECK, temp_bugger, 0); + + return TRUE; + + case WM_COMMAND: + switch (LOWORD(wParam)) { + case IDC_CONFIGURE_SCSI: + h = GetDlgItem(hdlg, IDC_COMBO_SCSI); + temp_scsi_card = settings_list_to_scsi[SendMessage(h, CB_GETCURSEL, 0, 0)]; + + temp_deviceconfig |= deviceconfig_open(hdlg, (void *)scsi_card_getdevice(temp_scsi_card)); + break; + + case IDC_COMBO_SCSI: + h = GetDlgItem(hdlg, IDC_COMBO_SCSI); + temp_scsi_card = settings_list_to_scsi[SendMessage(h, CB_GETCURSEL, 0, 0)]; + + h = GetDlgItem(hdlg, IDC_CONFIGURE_SCSI); + if (scsi_card_has_config(temp_scsi_card)) + EnableWindow(h, TRUE); + else + EnableWindow(h, FALSE); + break; + } + return FALSE; + + case WM_SAVESETTINGS: + h = GetDlgItem(hdlg, IDC_COMBO_HDC); + c = SendMessage(h, CB_GETCURSEL, 0, 0); + if (hdc_names[c]) + temp_hdc_type = hdc_get_from_internal_name(hdc_names[c]); + else + temp_hdc_type = 0; + + h = GetDlgItem(hdlg, IDC_COMBO_SCSI); + temp_scsi_card = settings_list_to_scsi[SendMessage(h, CB_GETCURSEL, 0, 0)]; + + h = GetDlgItem(hdlg, IDC_COMBO_IDE_TER); + temp_ide_ter = SendMessage(h, CB_GETCURSEL, 0, 0); + if (temp_ide_ter > 1) { + temp_ide_ter_irq = valid_ide_irqs[temp_ide_ter - 1]; + temp_ide_ter = 1; + } + + h = GetDlgItem(hdlg, IDC_COMBO_IDE_QUA); + temp_ide_qua = SendMessage(h, CB_GETCURSEL, 0, 0); + if (temp_ide_qua > 1) { + temp_ide_qua_irq = valid_ide_irqs[temp_ide_qua - 1]; + temp_ide_qua = 1; + } + + h = GetDlgItem(hdlg, IDC_CHECK_BUGGER); + temp_bugger = SendMessage(h, BM_GETCHECK, 0, 0); + return FALSE; + + default: + break; + } + + return FALSE; +} diff --git a/src/win/win_settings_ports.h b/src/win/win_settings_ports.h new file mode 100644 index 0000000..81bb8ea --- /dev/null +++ b/src/win/win_settings_ports.h @@ -0,0 +1,130 @@ +/* + * VARCem Virtual ARchaeological Computer EMulator. + * An emulator of (mostly) x86-based PC systems and devices, + * using the ISA,EISA,VLB,MCA and PCI system buses, roughly + * spanning the era between 1981 and 1995. + * + * This file is part of the VARCem Project. + * + * Implementation of the Settings dialog. + * + * Version: @(#)win_settings_ports.h 1.0.1 2018/04/05 + * + * Authors: Fred N. van Kempen, + * Miran Grca, + * + * Copyright 2017,2018 Fred N. van Kempen. + * Copyright 2016-2018 Miran Grca. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the: + * + * Free Software Foundation, Inc. + * 59 Temple Place - Suite 330 + * Boston, MA 02111-1307 + * USA. + */ + + +/************************************************************************ + * * + * Ports Dialog * + * * + ************************************************************************/ + +#ifdef __amd64__ +static LRESULT CALLBACK +#else +static BOOL CALLBACK +#endif +ports_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) +{ + WCHAR temp[128]; + const char *stransi; + HWND h; + int c, d, i; + + switch (message) { + case WM_INITDIALOG: + for (i = 0; i < PARALLEL_MAX; i++) { + /* Populate the "devices" list and select one. */ + h = GetDlgItem(hdlg, IDC_COMBO_PARALLEL1+i); + c = d = 0; + while (1) { + stransi = parallel_device_get_name(c); + if (stransi == NULL) + break; + + mbstowcs(temp, stransi, sizeof_w(temp)); + SendMessage(h, CB_ADDSTRING, 0, (LPARAM)temp); + + if (! strcmp(temp_parallel_device[i], parallel_device_get_internal_name(c))) + d = c; + + c++; + } + SendMessage(h, CB_SETCURSEL, d, 0); + + /* Enable or disable this port. */ + d = parallel_enabled[i]; + EnableWindow(h, d ? TRUE : FALSE); + h = GetDlgItem(hdlg, IDC_CHECK_PARALLEL1+i); + SendMessage(h, BM_SETCHECK, d, 0); + } + + /* Set up the serial port controls. */ + for (i = 0; i < SERIAL_MAX; i++) { + h = GetDlgItem(hdlg, IDC_CHECK_SERIAL1+i); + SendMessage(h, BM_SETCHECK, temp_serial[i], 0); + } + + return TRUE; + + case WM_COMMAND: + switch (LOWORD(wParam)) { + case IDC_CHECK_PARALLEL1: + case IDC_CHECK_PARALLEL2: + case IDC_CHECK_PARALLEL3: + h = GetDlgItem(hdlg, LOWORD(wParam)); + d = SendMessage(h, BM_GETCHECK, 0, 0); + c = (LOWORD(wParam) - IDC_CHECK_PARALLEL1); + h = GetDlgItem(hdlg, IDC_COMBO_PARALLEL1+c); + EnableWindow(h, d ? TRUE : FALSE); + break; + } + + return FALSE; + + case WM_SAVESETTINGS: + for (i = 0; i < PARALLEL_MAX; i++) { + h = GetDlgItem(hdlg, IDC_CHECK_PARALLEL1+i); + temp_parallel[i] = SendMessage(h, BM_GETCHECK, 0, 0); + + h = GetDlgItem(hdlg, IDC_COMBO_PARALLEL1+i); + c = SendMessage(h, CB_GETCURSEL, 0, 0); + strcpy(temp_parallel_device[i], parallel_device_get_internal_name(c)); + } + + for (i = 0; i < SERIAL_MAX; i++) { + h = GetDlgItem(hdlg, IDC_CHECK_SERIAL1+i); + temp_serial[i] = SendMessage(h, BM_GETCHECK, 0, 0); + } + + return FALSE; + + default: + break; + } + + return FALSE; +} diff --git a/src/win/win_settings_remov.h b/src/win/win_settings_remov.h new file mode 100644 index 0000000..7a0c3c1 --- /dev/null +++ b/src/win/win_settings_remov.h @@ -0,0 +1,1052 @@ +/* + * VARCem Virtual ARchaeological Computer EMulator. + * An emulator of (mostly) x86-based PC systems and devices, + * using the ISA,EISA,VLB,MCA and PCI system buses, roughly + * spanning the era between 1981 and 1995. + * + * This file is part of the VARCem Project. + * + * Implementation of the Settings dialog. + * + * Version: @(#)win_settings_remov.h 1.0.1 2018/04/05 + * + * Authors: Fred N. van Kempen, + * Miran Grca, + * + * Copyright 2017,2018 Fred N. van Kempen. + * Copyright 2016-2018 Miran Grca. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the: + * + * Free Software Foundation, Inc. + * 59 Temple Place - Suite 330 + * Boston, MA 02111-1307 + * USA. + */ + + +/************************************************************************ + * * + * Removable Devices Dialog * + * * + ************************************************************************/ + +/* GLobal variables needed for the Removable Devices dialog. */ +static int rd_ignore_change = 0; +static int cdlv_current_sel; +static int zdlv_current_sel; + +static int +combo_to_string(int combo_id) +{ + return IDS_5376 + combo_id; +} + + +static int +combo_to_format(int combo_id) +{ + return IDS_5632 + combo_id; +} + + +static void +cdrom_image_list_init(HWND hwndList) +{ + HICON hiconItem; + HIMAGELIST hSmall; + + hSmall = ImageList_Create(GetSystemMetrics(SM_CXSMICON), + GetSystemMetrics(SM_CYSMICON), + ILC_MASK | ILC_COLOR32, 1, 1); + + hiconItem = LoadIcon(hinstance, (LPCWSTR)514); + ImageList_AddIcon(hSmall, hiconItem); + DestroyIcon(hiconItem); + + hiconItem = LoadIcon(hinstance, (LPCWSTR)160); + ImageList_AddIcon(hSmall, hiconItem); + DestroyIcon(hiconItem); + + ListView_SetImageList(hwndList, hSmall, LVSIL_SMALL); +} + + +static BOOL +cdrom_recalc_list(HWND hwndList) +{ + WCHAR temp[128]; + LVITEM lvI; + int fsid, i; + + lvI.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_STATE; + lvI.stateMask = lvI.iSubItem = lvI.state = 0; + + for (i = 0; i < 4; i++) { + fsid = combo_to_format(temp_cdrom_drives[i].bus_type); + + lvI.iSubItem = 0; + switch (temp_cdrom_drives[i].bus_type) { + case CDROM_BUS_DISABLED: + default: + lvI.pszText = plat_get_string(fsid); + lvI.iImage = 0; + break; + + case CDROM_BUS_ATAPI_PIO_ONLY: + swprintf(temp, sizeof_w(temp), plat_get_string(fsid), temp_cdrom_drives[i].ide_channel >> 1, temp_cdrom_drives[i].ide_channel & 1); + lvI.pszText = temp; + lvI.iImage = 1; + break; + + case CDROM_BUS_ATAPI_PIO_AND_DMA: + swprintf(temp, sizeof_w(temp), plat_get_string(fsid), temp_cdrom_drives[i].ide_channel >> 1, temp_cdrom_drives[i].ide_channel & 1); + lvI.pszText = temp; + lvI.iImage = 1; + break; + + case CDROM_BUS_SCSI: + swprintf(temp, sizeof_w(temp), plat_get_string(fsid), temp_cdrom_drives[i].scsi_device_id, temp_cdrom_drives[i].scsi_device_lun); + lvI.pszText = temp; + lvI.iImage = 1; + break; + } + lvI.iItem = i; + if (ListView_InsertItem(hwndList, &lvI) == -1) + return FALSE; + + lvI.iSubItem = 1; + if (temp_cdrom_drives[i].bus_type == CDROM_BUS_DISABLED) { + lvI.pszText = plat_get_string(IDS_2152); + } else { + wsprintf(temp, L"%ix", + cdrom_speeds[temp_cdrom_drives[i].speed_idx].speed); + lvI.pszText = temp; + } + lvI.iItem = i; + lvI.iImage = 0; + if (ListView_SetItem(hwndList, &lvI) == -1) + return FALSE; + } + + return TRUE; +} + + +static BOOL +cdrom_init_columns(HWND hwndList) +{ + LVCOLUMN lvc; + + lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM; + + lvc.iSubItem = 0; + lvc.pszText = plat_get_string(IDS_2082); + lvc.cx = 342; + lvc.fmt = LVCFMT_LEFT; + if (ListView_InsertColumn(hwndList, 0, &lvc) == -1) + return FALSE; + + lvc.iSubItem = 1; + lvc.pszText = plat_get_string(IDS_2179); + lvc.cx = 50; + lvc.fmt = LVCFMT_LEFT; + if (ListView_InsertColumn(hwndList, 1, &lvc) == -1) + return FALSE; + + return TRUE; +} + + +static int +cdrom_get_selected(HWND hdlg) +{ + int drive = -1; + int i, j = 0; + HWND h; + + for (i = 0; i < 6; i++) { + h = GetDlgItem(hdlg, IDC_LIST_CDROM_DRIVES); + j = ListView_GetItemState(h, i, LVIS_SELECTED); + if (j) + drive = i; + } + + return drive; +} + + +static void +cdrom_update_item(HWND hwndList, int i) +{ + WCHAR temp[128]; + LVITEM lvI; + int fsid; + + lvI.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_STATE; + lvI.stateMask = lvI.iSubItem = lvI.state = 0; + + lvI.iSubItem = 0; + lvI.iItem = i; + + fsid = combo_to_format(temp_cdrom_drives[i].bus_type); + + switch (temp_cdrom_drives[i].bus_type) { + case CDROM_BUS_DISABLED: + default: + lvI.pszText = plat_get_string(fsid); + lvI.iImage = 0; + break; + + case CDROM_BUS_ATAPI_PIO_ONLY: + swprintf(temp, sizeof_w(temp), plat_get_string(fsid), temp_cdrom_drives[i].ide_channel >> 1, temp_cdrom_drives[i].ide_channel & 1); + lvI.pszText = temp; + lvI.iImage = 1; + break; + + case CDROM_BUS_ATAPI_PIO_AND_DMA: + swprintf(temp, sizeof_w(temp), plat_get_string(fsid), temp_cdrom_drives[i].ide_channel >> 1, temp_cdrom_drives[i].ide_channel & 1); + lvI.pszText = temp; + lvI.iImage = 1; + break; + + case CDROM_BUS_SCSI: + swprintf(temp, sizeof_w(temp), plat_get_string(fsid), temp_cdrom_drives[i].scsi_device_id, temp_cdrom_drives[i].scsi_device_lun); + lvI.pszText = temp; + lvI.iImage = 1; + break; + } + if (ListView_SetItem(hwndList, &lvI) == -1) + return; + + lvI.iSubItem = 1; + if (temp_cdrom_drives[i].bus_type == CDROM_BUS_DISABLED) { + lvI.pszText = plat_get_string(IDS_2152); + } else { + wsprintf(temp, L"%ix", + cdrom_speeds[temp_cdrom_drives[i].speed_idx].speed); + lvI.pszText = temp; + } + lvI.iItem = i; + lvI.iImage = 0; + if (ListView_SetItem(hwndList, &lvI) == -1) + return; +} + + +static void +cdrom_add_locations(HWND hdlg) +{ + WCHAR temp[128]; + HWND h; + int i = 0; + + h = GetDlgItem(hdlg, IDC_COMBO_CD_BUS); + for (i = CDROM_BUS_DISABLED; i <= CDROM_BUS_SCSI; i++) { + if ((i == CDROM_BUS_DISABLED) || (i >= CDROM_BUS_ATAPI_PIO_ONLY)) { + SendMessage(h, CB_ADDSTRING, 0, (LPARAM)plat_get_string(combo_to_string(i))); + } + } + + /* Create a list of usable CD-ROM speeds. */ + h = GetDlgItem(hdlg, IDC_COMBO_CD_SPEED); + for (i = 0; cdrom_speeds[i].speed > 0; i++) { + wsprintf(temp, L"%ix", cdrom_speeds[i]); + SendMessage(h, CB_ADDSTRING, 0, (LPARAM)temp); + } + + h = GetDlgItem(hdlg, IDC_COMBO_CD_ID); + for (i = 0; i < 16; i++) { + swprintf(temp, sizeof_w(temp), plat_get_string(IDS_4098), i); + SendMessage(h, CB_ADDSTRING, 0, (LPARAM)temp); + } + + h = GetDlgItem(hdlg, IDC_COMBO_CD_LUN); + for (i = 0; i < 8; i++) { + swprintf(temp, sizeof_w(temp), plat_get_string(IDS_4098), i); + SendMessage(h, CB_ADDSTRING, 0, (LPARAM)temp); + } + + h = GetDlgItem(hdlg, IDC_COMBO_CD_CHANNEL_IDE); + for (i = 0; i < 8; i++) { + swprintf(temp, sizeof_w(temp), plat_get_string(IDS_4097), i >> 1, i & 1); + SendMessage(h, CB_ADDSTRING, 0, (LPARAM)temp); + } +} + + +static void +cdrom_recalc_location_controls(HWND hdlg, int assign_id) +{ + HWND h; + int i; + int bus = temp_cdrom_drives[cdlv_current_sel].bus_type; + + for (i = IDT_1741; i < (IDT_1743 + 1); i++) { + h = GetDlgItem(hdlg, i); + EnableWindow(h, FALSE); + ShowWindow(h, SW_HIDE); + } + + h = GetDlgItem(hdlg, IDC_COMBO_CD_ID); + EnableWindow(h, FALSE); + ShowWindow(h, SW_HIDE); + + h = GetDlgItem(hdlg, IDC_COMBO_CD_LUN); + EnableWindow(h, FALSE); + ShowWindow(h, SW_HIDE); + + h = GetDlgItem(hdlg, IDC_COMBO_CD_CHANNEL_IDE); + EnableWindow(h, FALSE); + ShowWindow(h, SW_HIDE); + + h = GetDlgItem(hdlg, IDC_COMBO_CD_SPEED); + if (bus == CDROM_BUS_DISABLED) { + EnableWindow(h, FALSE); + ShowWindow(h, SW_HIDE); + } else { + ShowWindow(h, SW_SHOW); + EnableWindow(h, TRUE); + SendMessage(h, CB_SETCURSEL, temp_cdrom_drives[cdlv_current_sel].speed_idx, 0); + } + + switch(bus) { + case CDROM_BUS_ATAPI_PIO_ONLY: /* ATAPI (PIO-only) */ + case CDROM_BUS_ATAPI_PIO_AND_DMA: /* ATAPI (PIO and DMA) */ + h = GetDlgItem(hdlg, IDT_1743); + ShowWindow(h, SW_SHOW); + EnableWindow(h, TRUE); + if (assign_id) + temp_cdrom_drives[cdlv_current_sel].ide_channel = next_free_ide_channel(); + + h = GetDlgItem(hdlg, IDC_COMBO_CD_CHANNEL_IDE); + ShowWindow(h, SW_SHOW); + EnableWindow(h, TRUE); + SendMessage(h, CB_SETCURSEL, temp_cdrom_drives[cdlv_current_sel].ide_channel, 0); + break; + + case CDROM_BUS_SCSI: /* SCSI */ + h = GetDlgItem(hdlg, IDT_1741); + ShowWindow(h, SW_SHOW); + EnableWindow(h, TRUE); + h = GetDlgItem(hdlg, IDT_1742); + ShowWindow(h, SW_SHOW); + EnableWindow(h, TRUE); + if (assign_id) + next_free_scsi_id_and_lun((uint8_t *) &temp_cdrom_drives[cdlv_current_sel].scsi_device_id, (uint8_t *) &temp_cdrom_drives[cdlv_current_sel].scsi_device_lun); + + h = GetDlgItem(hdlg, IDC_COMBO_CD_ID); + ShowWindow(h, SW_SHOW); + EnableWindow(h, TRUE); + SendMessage(h, CB_SETCURSEL, temp_cdrom_drives[cdlv_current_sel].scsi_device_id, 0); + + h = GetDlgItem(hdlg, IDC_COMBO_CD_LUN); + ShowWindow(h, SW_SHOW); + EnableWindow(h, TRUE); + SendMessage(h, CB_SETCURSEL, temp_cdrom_drives[cdlv_current_sel].scsi_device_lun, 0); + break; + } +} + + +static void +cdrom_track(uint8_t id) +{ + if ((temp_cdrom_drives[id].bus_type == CDROM_BUS_ATAPI_PIO_ONLY) || (temp_cdrom_drives[id].bus_type == CDROM_BUS_ATAPI_PIO_ONLY)) + ide_tracking |= (2 << (temp_cdrom_drives[id].ide_channel << 3)); + else if (temp_cdrom_drives[id].bus_type == CDROM_BUS_SCSI) + scsi_tracking[temp_cdrom_drives[id].scsi_device_id] |= (1ULL << temp_cdrom_drives[id].scsi_device_lun); +} + + +static void +cdrom_untrack(uint8_t id) +{ + if ((temp_cdrom_drives[id].bus_type == CDROM_BUS_ATAPI_PIO_ONLY) || (temp_cdrom_drives[id].bus_type == CDROM_BUS_ATAPI_PIO_ONLY)) + ide_tracking &= ~(2 << (temp_cdrom_drives[id].ide_channel << 3)); + else if (temp_cdrom_drives[id].bus_type == CDROM_BUS_SCSI) + scsi_tracking[temp_cdrom_drives[id].scsi_device_id] &= ~(1ULL << temp_cdrom_drives[id].scsi_device_lun); +} + + +#if 0 +static void +cdrom_track_all(void) +{ + int i; + + for (i = 0; i < CDROM_NUM; i++) + cdrom_track(i); +} +#endif + + +static void +zip_image_list_init(HWND hwndList) +{ + HICON hiconItem; + HIMAGELIST hSmall; + + hSmall = ImageList_Create(GetSystemMetrics(SM_CXSMICON), + GetSystemMetrics(SM_CYSMICON), + ILC_MASK | ILC_COLOR32, 1, 1); + + hiconItem = LoadIcon(hinstance, (LPCWSTR)515); + ImageList_AddIcon(hSmall, hiconItem); + DestroyIcon(hiconItem); + + hiconItem = LoadIcon(hinstance, (LPCWSTR)176); + ImageList_AddIcon(hSmall, hiconItem); + DestroyIcon(hiconItem); + + ListView_SetImageList(hwndList, hSmall, LVSIL_SMALL); +} + + +static BOOL +zip_recalc_list(HWND hwndList) +{ + WCHAR temp[256]; + LVITEM lvI; + int fsid, i; + + lvI.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_STATE; + lvI.stateMask = lvI.iSubItem = lvI.state = 0; + + for (i = 0; i < 4; i++) { + fsid = combo_to_format(temp_zip_drives[i].bus_type); + + lvI.iSubItem = 0; + switch (temp_zip_drives[i].bus_type) { + case ZIP_BUS_DISABLED: + default: + lvI.pszText = plat_get_string(fsid); + lvI.iImage = 0; + break; + + case ZIP_BUS_ATAPI_PIO_ONLY: + swprintf(temp, sizeof_w(temp), plat_get_string(fsid), temp_zip_drives[i].ide_channel >> 1, temp_zip_drives[i].ide_channel & 1); + lvI.pszText = temp; + lvI.iImage = 1; + break; + + case ZIP_BUS_ATAPI_PIO_AND_DMA: + swprintf(temp, sizeof_w(temp), plat_get_string(fsid), temp_zip_drives[i].ide_channel >> 1, temp_zip_drives[i].ide_channel & 1); + lvI.pszText = temp; + lvI.iImage = 1; + break; + + case ZIP_BUS_SCSI: + swprintf(temp, sizeof_w(temp), plat_get_string(fsid), temp_zip_drives[i].scsi_device_id, temp_zip_drives[i].scsi_device_lun); + lvI.pszText = temp; + lvI.iImage = 1; + break; + } + lvI.iItem = i; + if (ListView_InsertItem(hwndList, &lvI) == -1) + return FALSE; + + lvI.iSubItem = 1; + lvI.pszText = plat_get_string(temp_zip_drives[i].is_250 ? IDS_5901 : IDS_5900); + lvI.iItem = i; + lvI.iImage = 0; + if (ListView_SetItem(hwndList, &lvI) == -1) + return FALSE; + } + + return TRUE; +} + + +static BOOL +zip_init_columns(HWND hwndList) +{ + LVCOLUMN lvc; + + lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM; + + lvc.iSubItem = 0; + lvc.pszText = plat_get_string(IDS_2082); + lvc.cx = 342; + lvc.fmt = LVCFMT_LEFT; + if (ListView_InsertColumn(hwndList, 0, &lvc) == -1) + return FALSE; + + lvc.iSubItem = 1; + lvc.pszText = plat_get_string(IDS_2143); + lvc.cx = 50; + lvc.fmt = LVCFMT_LEFT; + if (ListView_InsertColumn(hwndList, 1, &lvc) == -1) + return FALSE; + + return TRUE; +} + + +static int +zip_get_selected(HWND hdlg) +{ + int drive = -1; + int i, j = 0; + HWND h; + + for (i = 0; i < 6; i++) { + h = GetDlgItem(hdlg, IDC_LIST_ZIP_DRIVES); + j = ListView_GetItemState(h, i, LVIS_SELECTED); + if (j) + drive = i; + } + + return drive; +} + + +static void +zip_update_item(HWND hwndList, int i) +{ + WCHAR temp[128]; + LVITEM lvI; + int fsid; + + lvI.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_STATE; + lvI.stateMask = lvI.iSubItem = lvI.state = 0; + + lvI.iSubItem = 0; + lvI.iItem = i; + + fsid = combo_to_format(temp_zip_drives[i].bus_type); + + switch (temp_zip_drives[i].bus_type) { + case ZIP_BUS_DISABLED: + default: + lvI.pszText = plat_get_string(fsid); + lvI.iImage = 0; + break; + + case ZIP_BUS_ATAPI_PIO_ONLY: + swprintf(temp, sizeof_w(temp), plat_get_string(fsid), temp_zip_drives[i].ide_channel >> 1, temp_zip_drives[i].ide_channel & 1); + lvI.pszText = temp; + lvI.iImage = 1; + break; + + case ZIP_BUS_ATAPI_PIO_AND_DMA: + swprintf(temp, sizeof_w(temp), plat_get_string(fsid), temp_zip_drives[i].ide_channel >> 1, temp_zip_drives[i].ide_channel & 1); + lvI.pszText = temp; + lvI.iImage = 1; + break; + + case ZIP_BUS_SCSI: + swprintf(temp, sizeof_w(temp), plat_get_string(fsid), temp_zip_drives[i].scsi_device_id, temp_zip_drives[i].scsi_device_lun); + lvI.pszText = temp; + lvI.iImage = 1; + break; + } + if (ListView_SetItem(hwndList, &lvI) == -1) + return; + + lvI.iSubItem = 1; + lvI.pszText = plat_get_string(temp_zip_drives[i].is_250 ? IDS_5901 : IDS_5900); + lvI.iItem = i; + lvI.iImage = 0; + if (ListView_SetItem(hwndList, &lvI) == -1) + return; +} + + +static void +zip_add_locations(HWND hdlg) +{ + WCHAR temp[128]; + HWND h; + int i; + + h = GetDlgItem(hdlg, IDC_COMBO_ZIP_BUS); + for (i = ZIP_BUS_DISABLED; i <= ZIP_BUS_SCSI; i++) { + if ((i == ZIP_BUS_DISABLED) || (i >= ZIP_BUS_ATAPI_PIO_ONLY)) { + SendMessage(h, CB_ADDSTRING, 0, (LPARAM)plat_get_string(combo_to_string(i))); + } + } + + h = GetDlgItem(hdlg, IDC_COMBO_ZIP_ID); + for (i = 0; i < 16; i++) { + swprintf(temp, sizeof_w(temp), plat_get_string(IDS_4098), i); + SendMessage(h, CB_ADDSTRING, 0, (LPARAM)temp); + } + + h = GetDlgItem(hdlg, IDC_COMBO_ZIP_LUN); + for (i = 0; i < 8; i++) { + swprintf(temp, sizeof_w(temp), plat_get_string(IDS_4098), i); + SendMessage(h, CB_ADDSTRING, 0, (LPARAM)temp); + } + + h = GetDlgItem(hdlg, IDC_COMBO_ZIP_CHANNEL_IDE); + for (i = 0; i < 8; i++) { + swprintf(temp, sizeof_w(temp), plat_get_string(IDS_4097), i >> 1, i & 1); + SendMessage(h, CB_ADDSTRING, 0, (LPARAM)temp); + } +} + + +static void +zip_recalc_location_controls(HWND hdlg, int assign_id) +{ + HWND h; + int i; + int bus = temp_zip_drives[zdlv_current_sel].bus_type; + + for (i = IDT_1754; i < (IDT_1756 + 1); i++) { + h = GetDlgItem(hdlg, i); + EnableWindow(h, FALSE); + ShowWindow(h, SW_HIDE); + } + + h = GetDlgItem(hdlg, IDC_COMBO_ZIP_ID); + EnableWindow(h, FALSE); + ShowWindow(h, SW_HIDE); + + h = GetDlgItem(hdlg, IDC_COMBO_ZIP_LUN); + EnableWindow(h, FALSE); + ShowWindow(h, SW_HIDE); + + h = GetDlgItem(hdlg, IDC_COMBO_ZIP_CHANNEL_IDE); + EnableWindow(h, FALSE); + ShowWindow(h, SW_HIDE); + + switch(bus) { + case ZIP_BUS_ATAPI_PIO_ONLY: /* ATAPI (PIO-only) */ + case ZIP_BUS_ATAPI_PIO_AND_DMA: /* ATAPI (PIO and DMA) */ + h = GetDlgItem(hdlg, IDT_1756); + ShowWindow(h, SW_SHOW); + EnableWindow(h, TRUE); + + if (assign_id) + temp_zip_drives[zdlv_current_sel].ide_channel = next_free_ide_channel(); + + h = GetDlgItem(hdlg, IDC_COMBO_ZIP_CHANNEL_IDE); + ShowWindow(h, SW_SHOW); + EnableWindow(h, TRUE); + SendMessage(h, CB_SETCURSEL, temp_zip_drives[zdlv_current_sel].ide_channel, 0); + break; + + case ZIP_BUS_SCSI: /* SCSI */ + h = GetDlgItem(hdlg, IDT_1754); + ShowWindow(h, SW_SHOW); + EnableWindow(h, TRUE); + h = GetDlgItem(hdlg, IDT_1755); + ShowWindow(h, SW_SHOW); + EnableWindow(h, TRUE); + if (assign_id) + next_free_scsi_id_and_lun((uint8_t *) &temp_zip_drives[zdlv_current_sel].scsi_device_id, (uint8_t *) &temp_zip_drives[zdlv_current_sel].scsi_device_lun); + + h = GetDlgItem(hdlg, IDC_COMBO_ZIP_ID); + ShowWindow(h, SW_SHOW); + EnableWindow(h, TRUE); + SendMessage(h, CB_SETCURSEL, temp_zip_drives[zdlv_current_sel].scsi_device_id, 0); + + h = GetDlgItem(hdlg, IDC_COMBO_ZIP_LUN); + ShowWindow(h, SW_SHOW); + EnableWindow(h, TRUE); + SendMessage(h, CB_SETCURSEL, temp_zip_drives[zdlv_current_sel].scsi_device_lun, 0); + break; + } +} + + +static void +zip_track(uint8_t id) +{ + if ((temp_zip_drives[id].bus_type == ZIP_BUS_ATAPI_PIO_ONLY) || (temp_zip_drives[id].bus_type == ZIP_BUS_ATAPI_PIO_ONLY)) + ide_tracking |= (1ULL << temp_zip_drives[id].ide_channel); + else if (temp_zip_drives[id].bus_type == ZIP_BUS_SCSI) + scsi_tracking[temp_zip_drives[id].scsi_device_id] |= (1ULL << temp_zip_drives[id].scsi_device_lun); +} + + +static void +zip_untrack(uint8_t id) +{ + if ((temp_zip_drives[id].bus_type == ZIP_BUS_ATAPI_PIO_ONLY) || (temp_zip_drives[id].bus_type == ZIP_BUS_ATAPI_PIO_ONLY)) + ide_tracking &= ~(1ULL << temp_zip_drives[id].ide_channel); + else if (temp_zip_drives[id].bus_type == ZIP_BUS_SCSI) + scsi_tracking[temp_zip_drives[id].scsi_device_id] &= ~(1ULL << temp_zip_drives[id].scsi_device_lun); +} + + +#if 0 +static void +zip_track_all(void) +{ + int i; + + for (i = 0; i < ZIP_NUM; i++) + zip_track(i); +} +#endif + + +#ifdef __amd64__ +static LRESULT CALLBACK +#else +static BOOL CALLBACK +#endif +rmv_devices_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) +{ + HWND h = INVALID_HANDLE_VALUE; + int old_sel = 0; + int b = 0; + int b2 = 0; + int assign = 0; + + switch (message) { + case WM_INITDIALOG: + rd_ignore_change = 1; + + cdlv_current_sel = 0; + h = GetDlgItem(hdlg, IDC_LIST_CDROM_DRIVES); + cdrom_init_columns(h); + cdrom_image_list_init(h); + cdrom_recalc_list(h); + ListView_SetItemState(h, 0, LVIS_FOCUSED | LVIS_SELECTED, 0x000F); + cdrom_add_locations(hdlg); + h = GetDlgItem(hdlg, IDC_COMBO_CD_BUS); + switch (temp_cdrom_drives[cdlv_current_sel].bus_type) { + case CDROM_BUS_DISABLED: + default: + b = 0; + break; + + case CDROM_BUS_ATAPI_PIO_ONLY: + b = 1; + break; + + case CDROM_BUS_ATAPI_PIO_AND_DMA: + b = 2; + break; + + case CDROM_BUS_SCSI: + b = 3; + break; + } + SendMessage(h, CB_SETCURSEL, b, 0); + cdrom_recalc_location_controls(hdlg, 0); + + zdlv_current_sel = 0; + h = GetDlgItem(hdlg, IDC_LIST_ZIP_DRIVES); + zip_init_columns(h); + zip_image_list_init(h); + zip_recalc_list(h); + zip_add_locations(hdlg); + h = GetDlgItem(hdlg, IDC_COMBO_ZIP_BUS); + switch (temp_zip_drives[zdlv_current_sel].bus_type) { + case ZIP_BUS_DISABLED: + default: + b = 0; + break; + + case ZIP_BUS_ATAPI_PIO_ONLY: + b = 1; + break; + + case ZIP_BUS_ATAPI_PIO_AND_DMA: + b = 2; + break; + + case ZIP_BUS_SCSI: + b = 3; + break; + } + SendMessage(h, CB_SETCURSEL, b, 0); + zip_recalc_location_controls(hdlg, 0); + h = GetDlgItem(hdlg, IDC_CHECK250); + SendMessage(h, BM_SETCHECK, temp_zip_drives[zdlv_current_sel].is_250, 0); + rd_ignore_change = 0; + return TRUE; + + case WM_NOTIFY: + if (rd_ignore_change) + return FALSE; + + if ((((LPNMHDR)lParam)->code == LVN_ITEMCHANGED) && (((LPNMHDR)lParam)->idFrom == IDC_LIST_CDROM_DRIVES)) { + old_sel = cdlv_current_sel; + cdlv_current_sel = cdrom_get_selected(hdlg); + if (cdlv_current_sel == old_sel) + return FALSE; + if (cdlv_current_sel == -1) { + rd_ignore_change = 1; + cdlv_current_sel = old_sel; + ListView_SetItemState(h, cdlv_current_sel, LVIS_FOCUSED | LVIS_SELECTED, 0x000F); + rd_ignore_change = 0; + return FALSE; + } + rd_ignore_change = 1; + + h = GetDlgItem(hdlg, IDC_COMBO_CD_BUS); + switch (temp_cdrom_drives[cdlv_current_sel].bus_type) { + case CDROM_BUS_DISABLED: + default: + b = 0; + break; + case CDROM_BUS_ATAPI_PIO_ONLY: + b = 1; + break; + case CDROM_BUS_ATAPI_PIO_AND_DMA: + b = 2; + break; + case CDROM_BUS_SCSI: + b = 3; + break; + } + SendMessage(h, CB_SETCURSEL, b, 0); + cdrom_recalc_location_controls(hdlg, 0); + } else if ((((LPNMHDR)lParam)->code == LVN_ITEMCHANGED) && (((LPNMHDR)lParam)->idFrom == IDC_LIST_ZIP_DRIVES)) { + old_sel = zdlv_current_sel; + zdlv_current_sel = zip_get_selected(hdlg); + if (zdlv_current_sel == old_sel) + return FALSE; + + if (zdlv_current_sel == -1) { + rd_ignore_change = 1; + zdlv_current_sel = old_sel; + ListView_SetItemState(h, zdlv_current_sel, LVIS_FOCUSED | LVIS_SELECTED, 0x000F); + rd_ignore_change = 0; + return FALSE; + } + rd_ignore_change = 1; + + h = GetDlgItem(hdlg, IDC_COMBO_ZIP_BUS); + switch (temp_zip_drives[zdlv_current_sel].bus_type) { + case ZIP_BUS_DISABLED: + default: + b = 0; + break; + + case ZIP_BUS_ATAPI_PIO_ONLY: + b = 1; + break; + + case ZIP_BUS_ATAPI_PIO_AND_DMA: + b = 2; + break; + + case ZIP_BUS_SCSI: + b = 3; + break; + } + SendMessage(h, CB_SETCURSEL, b, 0); + zip_recalc_location_controls(hdlg, 0); + h = GetDlgItem(hdlg, IDC_CHECK250); + SendMessage(h, BM_SETCHECK, temp_zip_drives[zdlv_current_sel].is_250, 0); + } + rd_ignore_change = 0; + break; + + case WM_COMMAND: + switch (LOWORD(wParam)) { + case IDC_COMBO_CD_BUS: + if (rd_ignore_change) + return FALSE; + + rd_ignore_change = 1; + h = GetDlgItem(hdlg, IDC_COMBO_CD_BUS); + b = SendMessage(h, CB_GETCURSEL, 0, 0); + switch (b) { + case 0: + b2 = CDROM_BUS_DISABLED; + break; + + case 1: + b2 = CDROM_BUS_ATAPI_PIO_ONLY; + break; + + case 2: + b2 = CDROM_BUS_ATAPI_PIO_AND_DMA; + break; + + case 3: + b2 = CDROM_BUS_SCSI; + break; + } + if (b2 == temp_cdrom_drives[cdlv_current_sel].bus_type) + goto cdrom_bus_skip; + cdrom_untrack(cdlv_current_sel); + assign = (temp_cdrom_drives[cdlv_current_sel].bus_type == b2) ? 0 : 1; + if (temp_cdrom_drives[cdlv_current_sel].bus_type == CDROM_BUS_DISABLED) + temp_cdrom_drives[cdlv_current_sel].speed_idx = cdrom_speed_idx(cdrom_speed_idx(CDROM_SPEED_DEFAULT)); + if ((b2 == CDROM_BUS_ATAPI_PIO_ONLY) && (temp_cdrom_drives[cdlv_current_sel].bus_type == CDROM_BUS_ATAPI_PIO_AND_DMA)) + assign = 0; + else if ((b2 == CDROM_BUS_ATAPI_PIO_AND_DMA) && (temp_cdrom_drives[cdlv_current_sel].bus_type == CDROM_BUS_ATAPI_PIO_ONLY)) + assign = 0; + temp_cdrom_drives[cdlv_current_sel].bus_type = b2; + cdrom_recalc_location_controls(hdlg, assign); + cdrom_track(cdlv_current_sel); + h = GetDlgItem(hdlg, IDC_LIST_CDROM_DRIVES); + cdrom_update_item(h, cdlv_current_sel); +cdrom_bus_skip: + rd_ignore_change = 0; + return FALSE; + + case IDC_COMBO_CD_ID: + if (rd_ignore_change) + return FALSE; + + rd_ignore_change = 1; + h = GetDlgItem(hdlg, IDC_COMBO_CD_ID); + cdrom_untrack(cdlv_current_sel); + temp_cdrom_drives[cdlv_current_sel].scsi_device_id = SendMessage(h, CB_GETCURSEL, 0, 0); + cdrom_track(cdlv_current_sel); + h = GetDlgItem(hdlg, IDC_LIST_CDROM_DRIVES); + cdrom_update_item(h, cdlv_current_sel); + rd_ignore_change = 0; + return FALSE; + + case IDC_COMBO_CD_LUN: + if (rd_ignore_change) + return FALSE; + + rd_ignore_change = 1; + h = GetDlgItem(hdlg, IDC_COMBO_CD_LUN); + cdrom_untrack(cdlv_current_sel); + temp_cdrom_drives[cdlv_current_sel].scsi_device_lun = SendMessage(h, CB_GETCURSEL, 0, 0); + cdrom_track(cdlv_current_sel); + h = GetDlgItem(hdlg, IDC_LIST_CDROM_DRIVES); + cdrom_update_item(h, cdlv_current_sel); + rd_ignore_change = 0; + return FALSE; + + case IDC_COMBO_CD_CHANNEL_IDE: + if (rd_ignore_change) + return FALSE; + + rd_ignore_change = 1; + h = GetDlgItem(hdlg, IDC_COMBO_CD_CHANNEL_IDE); + cdrom_untrack(cdlv_current_sel); + temp_cdrom_drives[cdlv_current_sel].ide_channel = SendMessage(h, CB_GETCURSEL, 0, 0) & 0xff; + cdrom_track(cdlv_current_sel); + h = GetDlgItem(hdlg, IDC_LIST_CDROM_DRIVES); + cdrom_update_item(h, cdlv_current_sel); + rd_ignore_change = 0; + return FALSE; + + case IDC_COMBO_CD_SPEED: + if (rd_ignore_change) + return FALSE; + + rd_ignore_change = 1; + h = GetDlgItem(hdlg, IDC_COMBO_CD_SPEED); + temp_cdrom_drives[cdlv_current_sel].speed_idx = (uint8_t)SendMessage(h, CB_GETCURSEL, 0, 0); + h = GetDlgItem(hdlg, IDC_LIST_CDROM_DRIVES); + cdrom_update_item(h, cdlv_current_sel); + rd_ignore_change = 0; + return FALSE; + + case IDC_COMBO_ZIP_BUS: + if (rd_ignore_change) + return FALSE; + + rd_ignore_change = 1; + h = GetDlgItem(hdlg, IDC_COMBO_ZIP_BUS); + b = SendMessage(h, CB_GETCURSEL, 0, 0); + switch (b) { + case 0: + b2 = ZIP_BUS_DISABLED; + break; + case 1: + b2 = ZIP_BUS_ATAPI_PIO_ONLY; + break; + case 2: + b2 = ZIP_BUS_ATAPI_PIO_AND_DMA; + break; + case 3: + b2 = ZIP_BUS_SCSI; + break; + } + if (b2 == temp_zip_drives[zdlv_current_sel].bus_type) + goto zip_bus_skip; + zip_untrack(zdlv_current_sel); + assign = (temp_zip_drives[zdlv_current_sel].bus_type == b2) ? 0 : 1; + if ((b2 == ZIP_BUS_ATAPI_PIO_ONLY) && (temp_zip_drives[zdlv_current_sel].bus_type == ZIP_BUS_ATAPI_PIO_AND_DMA)) + assign = 0; + else if ((b2 == ZIP_BUS_ATAPI_PIO_AND_DMA) && (temp_zip_drives[cdlv_current_sel].bus_type == ZIP_BUS_ATAPI_PIO_ONLY)) + assign = 0; + temp_zip_drives[zdlv_current_sel].bus_type = b2; + zip_recalc_location_controls(hdlg, assign); + zip_track(zdlv_current_sel); + h = GetDlgItem(hdlg, IDC_LIST_ZIP_DRIVES); + zip_update_item(h, zdlv_current_sel); +zip_bus_skip: + rd_ignore_change = 0; + return FALSE; + + case IDC_COMBO_ZIP_ID: + if (rd_ignore_change) + return FALSE; + + rd_ignore_change = 1; + h = GetDlgItem(hdlg, IDC_COMBO_ZIP_ID); + zip_untrack(zdlv_current_sel); + temp_zip_drives[zdlv_current_sel].scsi_device_id = SendMessage(h, CB_GETCURSEL, 0, 0); + zip_track(zdlv_current_sel); + h = GetDlgItem(hdlg, IDC_LIST_ZIP_DRIVES); + zip_update_item(h, zdlv_current_sel); + rd_ignore_change = 0; + return FALSE; + + case IDC_COMBO_ZIP_LUN: + if (rd_ignore_change) + return FALSE; + + rd_ignore_change = 1; + h = GetDlgItem(hdlg, IDC_COMBO_ZIP_LUN); + zip_untrack(zdlv_current_sel); + temp_zip_drives[zdlv_current_sel].scsi_device_lun = SendMessage(h, CB_GETCURSEL, 0, 0); + zip_track(zdlv_current_sel); + h = GetDlgItem(hdlg, IDC_LIST_ZIP_DRIVES); + zip_update_item(h, zdlv_current_sel); + rd_ignore_change = 0; + return FALSE; + + case IDC_COMBO_ZIP_CHANNEL_IDE: + if (rd_ignore_change) + return FALSE; + + rd_ignore_change = 1; + h = GetDlgItem(hdlg, IDC_COMBO_ZIP_CHANNEL_IDE); + zip_untrack(zdlv_current_sel); + temp_zip_drives[zdlv_current_sel].ide_channel = SendMessage(h, CB_GETCURSEL, 0, 0) & 0xff; + zip_track(zdlv_current_sel); + h = GetDlgItem(hdlg, IDC_LIST_ZIP_DRIVES); + zip_update_item(h, zdlv_current_sel); + rd_ignore_change = 0; + return FALSE; + + case IDC_CHECK250: + if (rd_ignore_change) + return FALSE; + + rd_ignore_change = 1; + h = GetDlgItem(hdlg, IDC_CHECK250); + temp_zip_drives[zdlv_current_sel].is_250 = SendMessage(h, BM_GETCHECK, 0, 0); + h = GetDlgItem(hdlg, IDC_LIST_ZIP_DRIVES); + zip_update_item(h, zdlv_current_sel); + rd_ignore_change = 0; + return FALSE; + } + return FALSE; + + default: + break; + } + + return FALSE; +} diff --git a/src/win/win_settings_sound.h b/src/win/win_settings_sound.h new file mode 100644 index 0000000..d3f73fd --- /dev/null +++ b/src/win/win_settings_sound.h @@ -0,0 +1,275 @@ +/* + * VARCem Virtual ARchaeological Computer EMulator. + * An emulator of (mostly) x86-based PC systems and devices, + * using the ISA,EISA,VLB,MCA and PCI system buses, roughly + * spanning the era between 1981 and 1995. + * + * This file is part of the VARCem Project. + * + * Implementation of the Settings dialog. + * + * Version: @(#)win_settings_sound.h 1.0.1 2018/04/05 + * + * Authors: Fred N. van Kempen, + * Miran Grca, + * + * Copyright 2017,2018 Fred N. van Kempen. + * Copyright 2016-2018 Miran Grca. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the: + * + * Free Software Foundation, Inc. + * 59 Temple Place - Suite 330 + * Boston, MA 02111-1307 + * USA. + */ + + +/************************************************************************ + * * + * Sound Dialog * + * * + ************************************************************************/ + +static int +mpu401_present(void) +{ + char *stransi; + + stransi = sound_card_get_internal_name(temp_sound_card); + if (stransi != NULL) { + if (!strcmp(stransi, "sb16") || !strcmp(stransi, "sbawe32")) + return 1; + } + + return temp_mpu401 ? 1 : 0; +} + + +static int +mpu401_standalone_allow(void) +{ + char *n, *md; + + n = sound_card_get_internal_name(temp_sound_card); + md = midi_device_get_internal_name(temp_midi_device); + if (n != NULL) { + if (!strcmp(n, "sb16") || !strcmp(n, "sbawe32")) + return 0; + } + + if (md != NULL) { + if (! strcmp(md, "none")) + return 0; + } + + return 1; +} + + +#ifdef __amd64__ +static LRESULT CALLBACK +#else +static BOOL CALLBACK +#endif +sound_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) +{ + WCHAR temp[128]; + char *stransi; + const device_t *dev; + HWND h; + int c, d; + + switch (message) { + case WM_INITDIALOG: + h = GetDlgItem(hdlg, IDC_COMBO_SOUND); + c = d = 0; + while (1) { + stransi = sound_card_getname(c); + if (stransi == NULL) + break; + + settings_sound_to_list[c] = d; + + if (sound_card_available(c)) { + dev = sound_card_getdevice(c); + if (device_is_valid(dev, machines[temp_machine].flags)) { + mbstowcs(temp, stransi, sizeof_w(temp)); + SendMessage(h, CB_ADDSTRING, 0, (LPARAM)temp); + settings_list_to_sound[d] = c; + d++; + } + } + + c++; + } + SendMessage(h, CB_SETCURSEL, settings_sound_to_list[temp_sound_card], 0); + + EnableWindow(h, d ? TRUE : FALSE); + + h = GetDlgItem(hdlg, IDC_CONFIGURE_SND); + if (sound_card_has_config(temp_sound_card)) + EnableWindow(h, TRUE); + else + EnableWindow(h, FALSE); + + h = GetDlgItem(hdlg, IDC_COMBO_MIDI); + c = d = 0; + while (1) { + stransi = midi_device_getname(c); + if (stransi == NULL) + break; + + settings_midi_to_list[c] = d; + + if (midi_device_available(c)) { + mbstowcs(temp, stransi, sizeof_w(temp)); + SendMessage(h, CB_ADDSTRING, 0, (LPARAM)temp); + + settings_list_to_midi[d] = c; + d++; + } + + c++; + } + SendMessage(h, CB_SETCURSEL, settings_midi_to_list[temp_midi_device], 0); + + h = GetDlgItem(hdlg, IDC_CONFIGURE_MIDI); + if (midi_device_has_config(temp_midi_device)) + EnableWindow(h, TRUE); + else + EnableWindow(h, FALSE); + + h = GetDlgItem(hdlg, IDC_CHECK_MPU401); + SendMessage(h, BM_SETCHECK, temp_mpu401, 0); + EnableWindow(h, mpu401_standalone_allow() ? TRUE : FALSE); + + h = GetDlgItem(hdlg, IDC_CONFIGURE_MPU401); + EnableWindow(h, (mpu401_standalone_allow() && temp_mpu401) ? TRUE : FALSE); + + h = GetDlgItem(hdlg, IDC_CHECK_CMS); + SendMessage(h, BM_SETCHECK, temp_GAMEBLASTER, 0); + + h = GetDlgItem(hdlg, IDC_CHECK_GUS); + SendMessage(h, BM_SETCHECK, temp_GUS, 0); + + h = GetDlgItem(hdlg, IDC_CHECK_SSI); + SendMessage(h, BM_SETCHECK, temp_SSI2001, 0); + + h = GetDlgItem(hdlg, IDC_CHECK_NUKEDOPL); + SendMessage(h, BM_SETCHECK, temp_opl3_type, 0); + + h = GetDlgItem(hdlg, IDC_CHECK_FLOAT); + SendMessage(h, BM_SETCHECK, temp_float, 0); + + return TRUE; + + case WM_COMMAND: + switch (LOWORD(wParam)) { + case IDC_COMBO_SOUND: + h = GetDlgItem(hdlg, IDC_COMBO_SOUND); + temp_sound_card = settings_list_to_sound[SendMessage(h, CB_GETCURSEL, 0, 0)]; + + h = GetDlgItem(hdlg, IDC_CONFIGURE_SND); + if (sound_card_has_config(temp_sound_card)) + EnableWindow(h, TRUE); + else + EnableWindow(h, FALSE); + + h = GetDlgItem(hdlg, IDC_CHECK_MPU401); + SendMessage(h, BM_SETCHECK, temp_mpu401, 0); + EnableWindow(h, mpu401_standalone_allow() ? TRUE : FALSE); + + h = GetDlgItem(hdlg, IDC_CONFIGURE_MPU401); + EnableWindow(h, (mpu401_standalone_allow() && temp_mpu401) ? TRUE : FALSE); + break; + + case IDC_CONFIGURE_SND: + h = GetDlgItem(hdlg, IDC_COMBO_SOUND); + temp_sound_card = settings_list_to_sound[SendMessage(h, CB_GETCURSEL, 0, 0)]; + + temp_deviceconfig |= deviceconfig_open(hdlg, (void *)sound_card_getdevice(temp_sound_card)); + break; + + case IDC_COMBO_MIDI: + h = GetDlgItem(hdlg, IDC_COMBO_MIDI); + temp_midi_device = settings_list_to_midi[SendMessage(h, CB_GETCURSEL, 0, 0)]; + + h = GetDlgItem(hdlg, IDC_CONFIGURE_MIDI); + if (midi_device_has_config(temp_midi_device)) + EnableWindow(h, TRUE); + else + EnableWindow(h, FALSE); + + h = GetDlgItem(hdlg, IDC_CHECK_MPU401); + SendMessage(h, BM_SETCHECK, temp_mpu401, 0); + EnableWindow(h, mpu401_standalone_allow() ? TRUE : FALSE); + + h = GetDlgItem(hdlg, IDC_CONFIGURE_MPU401); + EnableWindow(h, (mpu401_standalone_allow() && temp_mpu401) ? TRUE : FALSE); + break; + + case IDC_CONFIGURE_MIDI: + h = GetDlgItem(hdlg, IDC_COMBO_MIDI); + temp_midi_device = settings_list_to_midi[SendMessage(h, CB_GETCURSEL, 0, 0)]; + + temp_deviceconfig |= deviceconfig_open(hdlg, (void *)midi_device_getdevice(temp_midi_device)); + break; + + case IDC_CHECK_MPU401: + h = GetDlgItem(hdlg, IDC_CHECK_MPU401); + temp_mpu401 = SendMessage(h, BM_GETCHECK, 0, 0); + + h = GetDlgItem(hdlg, IDC_CONFIGURE_MPU401); + EnableWindow(h, mpu401_present() ? TRUE : FALSE); + break; + + case IDC_CONFIGURE_MPU401: + temp_deviceconfig |= deviceconfig_open(hdlg, (void *)&mpu401_device); + break; + } + return FALSE; + + case WM_SAVESETTINGS: + h = GetDlgItem(hdlg, IDC_COMBO_SOUND); + temp_sound_card = settings_list_to_sound[SendMessage(h, CB_GETCURSEL, 0, 0)]; + + h = GetDlgItem(hdlg, IDC_COMBO_MIDI); + temp_midi_device = settings_list_to_midi[SendMessage(h, CB_GETCURSEL, 0, 0)]; + + h = GetDlgItem(hdlg, IDC_CHECK_MPU401); + temp_mpu401 = SendMessage(h, BM_GETCHECK, 0, 0); + + h = GetDlgItem(hdlg, IDC_CHECK_CMS); + temp_GAMEBLASTER = SendMessage(h, BM_GETCHECK, 0, 0); + + h = GetDlgItem(hdlg, IDC_CHECK_GUS); + temp_GUS = SendMessage(h, BM_GETCHECK, 0, 0); + + h = GetDlgItem(hdlg, IDC_CHECK_SSI); + temp_SSI2001 = SendMessage(h, BM_GETCHECK, 0, 0); + + h = GetDlgItem(hdlg, IDC_CHECK_NUKEDOPL); + temp_opl3_type = SendMessage(h, BM_GETCHECK, 0, 0); + + h = GetDlgItem(hdlg, IDC_CHECK_FLOAT); + temp_float = SendMessage(h, BM_GETCHECK, 0, 0); + return FALSE; + + default: + break; + } + + return FALSE; +} diff --git a/src/win/win_settings_video.h b/src/win/win_settings_video.h new file mode 100644 index 0000000..055148f --- /dev/null +++ b/src/win/win_settings_video.h @@ -0,0 +1,193 @@ +/* + * VARCem Virtual ARchaeological Computer EMulator. + * An emulator of (mostly) x86-based PC systems and devices, + * using the ISA,EISA,VLB,MCA and PCI system buses, roughly + * spanning the era between 1981 and 1995. + * + * This file is part of the VARCem Project. + * + * Implementation of the Settings dialog. + * + * Version: @(#)win_settings_video.h 1.0.1 2018/04/05 + * + * Authors: Fred N. van Kempen, + * Miran Grca, + * + * Copyright 2017,2018 Fred N. van Kempen. + * Copyright 2016-2018 Miran Grca. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the: + * + * Free Software Foundation, Inc. + * 59 Temple Place - Suite 330 + * Boston, MA 02111-1307 + * USA. + */ + + +/************************************************************************ + * * + * Video Dialog * + * * + ************************************************************************/ + +static void +recalc_vid_list(HWND hdlg) +{ + WCHAR temp[128]; + const char *stransi; + HWND h = GetDlgItem(hdlg, IDC_COMBO_VIDEO); + int c = 0, d = 0; + int found_card = 0; + + SendMessage(h, CB_RESETCONTENT, 0, 0); + SendMessage(h, CB_SETCURSEL, 0, 0); + + while (1) { + /* Skip "internal" if machine doesn't have it. */ + if (c == 1 && !(machines[temp_machine].flags&MACHINE_VIDEO)) { + c++; + continue; + } + + stransi = video_card_getname(c); + if (! *stransi) + break; + + if (video_card_available(c) && vid_present[video_new_to_old(c)] && + device_is_valid(video_card_getdevice(c), machines[temp_machine].flags)) { + mbstowcs(temp, stransi, sizeof_w(temp)); + SendMessage(h, CB_ADDSTRING, 0, (LPARAM)temp); + if (video_new_to_old(c) == temp_vid_card) { + SendMessage(h, CB_SETCURSEL, d, 0); + found_card = 1; + } + + d++; + } + + c++; + } + if (! found_card) + SendMessage(h, CB_SETCURSEL, 0, 0); + + EnableWindow(h, machines[temp_machine].fixed_vidcard ? FALSE : TRUE); + + h = GetDlgItem(hdlg, IDC_CHECK_VOODOO); + EnableWindow(h, (machines[temp_machine].flags & MACHINE_PCI) ? TRUE:FALSE); + + h = GetDlgItem(hdlg, IDC_BUTTON_VOODOO); + EnableWindow(h, ((machines[temp_machine].flags & MACHINE_PCI) && temp_voodoo) ? TRUE : FALSE); +} + + +#ifdef __amd64__ +static LRESULT CALLBACK +#else +static BOOL CALLBACK +#endif +video_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) +{ + WCHAR temp[128]; + char tempA[128]; + int vid; + HWND h; + + switch (message) { + case WM_INITDIALOG: + recalc_vid_list(hdlg); + + h = GetDlgItem(hdlg, IDC_COMBO_VIDEO_SPEED); + SendMessage(h, CB_ADDSTRING, 0, (LPARAM)plat_get_string(IDS_2131)); + SendMessage(h, CB_ADDSTRING, 0, (LPARAM)plat_get_string(IDS_2133)); + SendMessage(h, CB_ADDSTRING, 0, (LPARAM)plat_get_string(IDS_2134)); + SendMessage(h, CB_ADDSTRING, 0, (LPARAM)plat_get_string(IDS_2135)); + SendMessage(h, CB_ADDSTRING, 0, (LPARAM)plat_get_string(IDS_2136)); + SendMessage(h, CB_ADDSTRING, 0, (LPARAM)plat_get_string(IDS_2137)); + SendMessage(h, CB_ADDSTRING, 0, (LPARAM)plat_get_string(IDS_2138)); + SendMessage(h, CB_SETCURSEL, temp_video_speed+1, 0); + + h = GetDlgItem(hdlg, IDC_CHECK_VOODOO); + SendMessage(h, BM_SETCHECK, temp_voodoo, 0); + + h = GetDlgItem(hdlg, IDC_COMBO_VIDEO); + SendMessage(h, CB_GETLBTEXT, SendMessage(h, CB_GETCURSEL, 0, 0), (LPARAM)temp); + wcstombs(tempA, temp, sizeof(tempA)); + vid = video_card_getid(tempA); + + h = GetDlgItem(hdlg, IDC_CONFIGURE_VID); + if (video_card_has_config(vid)) + EnableWindow(h, TRUE); + else + EnableWindow(h, FALSE); + + return TRUE; + + case WM_COMMAND: + switch (LOWORD(wParam)) { + case IDC_COMBO_VIDEO: + h = GetDlgItem(hdlg, IDC_COMBO_VIDEO); + SendMessage(h, CB_GETLBTEXT, SendMessage(h, CB_GETCURSEL, 0, 0), (LPARAM)temp); + wcstombs(tempA, temp, sizeof(tempA)); + vid = video_card_getid(tempA); + temp_vid_card = video_new_to_old(vid); + + h = GetDlgItem(hdlg, IDC_CONFIGURE_VID); + if (video_card_has_config(vid)) + EnableWindow(h, TRUE); + else + EnableWindow(h, FALSE); + break; + + case IDC_CHECK_VOODOO: + h = GetDlgItem(hdlg, IDC_CHECK_VOODOO); + temp_voodoo = SendMessage(h, BM_GETCHECK, 0, 0); + + h = GetDlgItem(hdlg, IDC_BUTTON_VOODOO); + EnableWindow(h, temp_voodoo ? TRUE : FALSE); + break; + + case IDC_BUTTON_VOODOO: + temp_deviceconfig |= deviceconfig_open(hdlg, (void *)&voodoo_device); + break; + + case IDC_CONFIGURE_VID: + h = GetDlgItem(hdlg, IDC_COMBO_VIDEO); + SendMessage(h, CB_GETLBTEXT, SendMessage(h, CB_GETCURSEL, 0, 0), (LPARAM)temp); + wcstombs(tempA, temp, sizeof(temp)); + temp_deviceconfig |= deviceconfig_open(hdlg, (void *)video_card_getdevice(video_card_getid(tempA))); + + break; + } + return FALSE; + + case WM_SAVESETTINGS: + h = GetDlgItem(hdlg, IDC_COMBO_VIDEO); + SendMessage(h, CB_GETLBTEXT, SendMessage(h, CB_GETCURSEL, 0, 0), (LPARAM)temp); + wcstombs(tempA, temp, sizeof(tempA)); + temp_vid_card = video_new_to_old(video_card_getid(tempA)); + + h = GetDlgItem(hdlg, IDC_COMBO_VIDEO_SPEED); + temp_video_speed = SendMessage(h, CB_GETCURSEL, 0, 0) - 1; + + h = GetDlgItem(hdlg, IDC_CHECK_VOODOO); + temp_voodoo = SendMessage(h, BM_GETCHECK, 0, 0); + return FALSE; + + default: + break; + } + + return FALSE; +} diff --git a/src/win/win_stbar.c b/src/win/win_stbar.c index 814589f..26dde3e 100644 --- a/src/win/win_stbar.c +++ b/src/win/win_stbar.c @@ -8,7 +8,7 @@ * * Implementation of the Status Bar module. * - * Version: @(#)win_stbar.c 1.0.5 2018/03/31 + * Version: @(#)win_stbar.c 1.0.6 2018/04/05 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -661,14 +661,9 @@ ui_sb_update_panes(void) } for (i=0; i * Miran Grca, @@ -428,6 +428,7 @@ MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) break; case WM_COMMAND: + UpdateWindow(hwnd); hmenu = GetMenu(hwnd); switch (LOWORD(wParam)) { case IDM_ACTION_SCREENSHOT: