diff --git a/src/cdrom/cdrom.c b/src/cdrom/cdrom.c index 134f614..87492f8 100644 --- a/src/cdrom/cdrom.c +++ b/src/cdrom/cdrom.c @@ -9,7 +9,7 @@ * Implementation of the CD-ROM drive with SCSI(-like) * commands, for both ATAPI and SCSI usage. * - * Version: @(#)cdrom.c 1.0.10 2018/03/21 + * Version: @(#)cdrom.c 1.0.11 2018/03/31 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -2866,7 +2866,7 @@ uint8_t cdrom_phase_data_out(uint8_t id) switch(dev->current_cdb[0]) { case GPCMD_MODE_SELECT_6: case GPCMD_MODE_SELECT_10: - f = nvr_fopen(L"modeselect.bin", L"wb"); + f = plat_fopen(nvr_path(L"modeselect.bin"), L"wb"); fwrite(cdbufferb, 1, dev->total_length, f); fclose(f); diff --git a/src/config.c b/src/config.c index 46b1059..dc9d979 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.7 2018/03/20 + * Version: @(#)config.c 1.0.9 2018/03/31 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -76,6 +76,9 @@ #include "ui.h" +#define ANSI_CFG 1 /* for now, always */ + + typedef struct _list_ { struct _list_ *next; } list_t; @@ -450,6 +453,7 @@ load_general(void) video_graytype = config_get_int(cat, "video_graytype", 0); rctrl_is_lalt = config_get_int(cat, "rctrl_is_lalt", 0); + update_icons = config_get_int(cat, "update_icons", 1); window_remember = config_get_int(cat, "window_remember", 0); @@ -492,20 +496,6 @@ load_machine(void) if (machine >= machine_count()) machine = machine_count() - 1; - /* This is for backwards compatibility. */ - p = config_get_string(cat, "model", NULL); - if (p != NULL) { - /* Detect the old model typos and fix them. */ - if (! strcmp(p, "p55r2p4")) { - machine = machine_get_machine_from_internal_name("p55t2p4"); - } else { - machine = machine_get_machine_from_internal_name(p); - } - config_delete_var(cat, "model"); - } - if (machine >= machine_count()) - machine = machine_count() - 1; - romset = machine_getromset(); cpu_manufacturer = config_get_int(cat, "cpu_manufacturer", 0); cpu = config_get_int(cat, "cpu", 0); @@ -523,9 +513,6 @@ load_machine(void) enable_external_fpu = !!config_get_int(cat, "cpu_enable_fpu", 0); enable_sync = !!config_get_int(cat, "enable_sync", 1); - - /* Remove this after a while.. */ - config_delete_var(cat, "nvr_path"); } @@ -542,6 +529,8 @@ load_video(void) vid_card = VID_INTERNAL; } else { p = config_get_string(cat, "video_card", NULL); + + /* Remove this after 01-JUL-2018. --FvK */ if (p == NULL) { p = config_get_string(cat, "gfxcard", NULL); if (p != NULL) @@ -614,7 +603,15 @@ load_sound(void) char temp[512]; char *p; - p = config_get_string(cat, "sndcard", NULL); + p = config_get_string(cat, "sound_card", NULL); + + /* Remove this after 01-JUL-2018. --FvK */ + if (p == NULL) { + p = config_get_string(cat, "sndcard", NULL); + if (p != NULL) + config_delete_var(cat, "sndcard"); + } + if (p != NULL) sound_card_current = sound_card_get_from_internal_name(p); else @@ -706,9 +703,9 @@ load_ports(void) char *cat = "Ports (COM & LPT)"; char *p; - serial_enabled[0] = !!config_get_int(cat, "serial1_enabled", 1); - serial_enabled[1] = !!config_get_int(cat, "serial2_enabled", 1); - lpt_enabled = !!config_get_int(cat, "lpt_enabled", 1); + 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); p = (char *)config_get_string(cat, "lpt1_device", NULL); if (p != NULL) @@ -738,7 +735,15 @@ load_other_peripherals(void) char temp[512], *p; int c; - p = config_get_string(cat, "scsicard", NULL); + p = config_get_string(cat, "scsi_card", NULL); + + /* Remove this after 01-JUL-2018. --FvK */ + if (p == NULL) { + p = config_get_string(cat, "scsicard", NULL); + if (p != NULL) + config_delete_var(cat, "scsicard"); + } + if (p != NULL) scsi_card_current = scsi_card_get_from_internal_name(p); else @@ -749,11 +754,6 @@ load_other_peripherals(void) hdc_name = NULL; } p = config_get_string(cat, "hdc", NULL); - if (p == NULL) { - p = config_get_string(cat, "hdd_controller", NULL); - if (p != NULL) - config_delete_var(cat, "hdd_controller"); - } if (p == NULL) { if (machines[machine].flags & MACHINE_HDC) { hdc_name = (char *) malloc((strlen("internal") + 1) * sizeof(char)); @@ -778,8 +778,8 @@ load_other_peripherals(void) } bugger_enabled = !!config_get_int(cat, "bugger_enabled", 0); -#ifdef WALTJE +#ifdef WALTJE romdos_enabled = !!config_get_int(cat, "romdos_enabled", 0); #endif } @@ -818,12 +818,12 @@ load_hard_disks(void) sprintf(temp, "hdd_%02i_parameters", c+1); p = config_get_string(cat, temp, "0, 0, 0, 0, none"); if (tally_char(p, ',') == 3) { - sscanf(p, "%" PRIu64 ", %" PRIu64", %" PRIu64 ", %s", - &hdd[c].spt, &hdd[c].hpc, &hdd[c].tracks, s); + sscanf(p, "%u, %u, %u, %s", + (int *)&hdd[c].spt, (int *)&hdd[c].hpc, (int *)&hdd[c].tracks, s); hdd[c].wp = 0; } else { - sscanf(p, "%" PRIu64 ", %" PRIu64", %" PRIu64 ", %i, %s", - &hdd[c].spt, &hdd[c].hpc, &hdd[c].tracks, (int *)&hdd[c].wp, s); + sscanf(p, "%u, %u, %u, %d, %s", + (int *)&hdd[c].spt, (int *)&hdd[c].hpc, (int *)&hdd[c].tracks, (int *)&hdd[c].wp, s); } hdd[c].bus = hdd_string_to_bus(s, 0); @@ -935,24 +935,8 @@ load_hard_disks(void) sprintf(temp, "hdd_%02i_fn", c+1); wp = config_get_wstring(cat, temp, L""); -#if 0 - /* - * NOTE: - * Temporary hack to remove the absolute - * path currently saved in most config - * files. We should remove this before - * finalizing this release! --FvK - */ - if (! wcsnicmp(wp, usr_path, wcslen(usr_path))) { - /* - * Yep, its absolute and prefixed - * with the CFG path. Just strip - * that off for now... - */ - wcsncpy(hdd[c].fn, &wp[wcslen(usr_path)], sizeof_w(hdd[c].fn)); - } else -#endif - wcsncpy(hdd[c].fn, wp, sizeof_w(hdd[c].fn)); + /* Try to make relative, and copy to destination. */ + pc_path(hdd[c].fn, sizeof_w(hdd[c].fn), wp); /* If disk is empty or invalid, mark it for deletion. */ if (! hdd_is_valid(c)) { @@ -1005,24 +989,8 @@ load_removable_devices(void) sprintf(temp, "fdd_%02i_fn", c + 1); wp = config_get_wstring(cat, temp, L""); -#if 0 - /* - * NOTE: - * Temporary hack to remove the absolute - * path currently saved in most config - * files. We should remove this before - * finalizing this release! --FvK - */ - if (! wcsnicmp(wp, usr_path, wcslen(usr_path))) { - /* - * Yep, its absolute and prefixed - * with the EXE path. Just strip - * that off for now... - */ - wcsncpy(floppyfns[c], &wp[wcslen(usr_path)], sizeof_w(floppyfns[c])); - } else -#endif - wcsncpy(floppyfns[c], wp, sizeof_w(floppyfns[c])); + /* Try to make relative, and copy to destination. */ + pc_path(floppyfns[c], sizeof_w(floppyfns[c]), wp); sprintf(temp, "fdd_%02i_writeprot", c+1); ui_writeprot[c] = !!config_get_int(cat, temp, 0); @@ -1104,24 +1072,8 @@ load_removable_devices(void) sprintf(temp, "cdrom_%02i_image_path", c+1); wp = config_get_wstring(cat, temp, L""); -#if 0 - /* - * NOTE: - * Temporary hack to remove the absolute - * path currently saved in most config - * files. We should remove this before - * finalizing this release! --FvK - */ - if (! wcsnicmp(wp, usr_path, wcslen(usr_path))) { - /* - * Yep, its absolute and prefixed - * with the EXE path. Just strip - * that off for now... - */ - wcsncpy(cdrom_image[c].image_path, &wp[wcslen(usr_path)], sizeof_w(cdrom_image[c].image_path)); - } else -#endif - wcsncpy(cdrom_image[c].image_path, wp, sizeof_w(cdrom_image[c].image_path)); + /* Try to make relative, and copy to destination. */ + pc_path(cdrom_image[c].image_path, sizeof_w(cdrom_image[c].image_path), wp); if (cdrom_drives[c].host_drive < 'A') cdrom_drives[c].host_drive = 0; @@ -1173,24 +1125,8 @@ load_floppy_drives(void) sprintf(temp, "fdd_%02i_fn", c + 1); wp = config_get_wstring(cat, temp, L""); -#if 0 - /* - * NOTE: - * Temporary hack to remove the absolute - * path currently saved in most config - * files. We should remove this before - * finalizing this release! --FvK - */ - if (! wcsnicmp(wp, usr_path, wcslen(usr_path))) { - /* - * Yep, its absolute and prefixed - * with the EXE path. Just strip - * that off for now... - */ - wcsncpy(floppyfns[c], &wp[wcslen(usr_path)], sizeof_w(floppyfns[c])); - } else -#endif - wcsncpy(floppyfns[c], wp, sizeof_w(floppyfns[c])); + /* Try to make relative, and copy to destination. */ + pc_path(floppyfns[c], sizeof_w(floppyfns[c]), wp); sprintf(temp, "fdd_%02i_writeprot", c+1); ui_writeprot[c] = !!config_get_int(cat, temp, 0); @@ -1294,24 +1230,8 @@ load_other_removable_devices(void) sprintf(temp, "cdrom_%02i_image_path", c+1); wp = config_get_wstring(cat, temp, L""); -#if 0 - /* - * NOTE: - * Temporary hack to remove the absolute - * path currently saved in most config - * files. We should remove this before - * finalizing this release! --FvK - */ - if (! wcsnicmp(wp, usr_path, wcslen(usr_path))) { - /* - * Yep, its absolute and prefixed - * with the EXE path. Just strip - * that off for now... - */ - wcsncpy(cdrom_image[c].image_path, &wp[wcslen(usr_path)], sizeof_w(cdrom_image[c].image_path)); - } else -#endif - wcsncpy(cdrom_image[c].image_path, wp, sizeof_w(cdrom_image[c].image_path)); + /* Try to make relative, and copy to destination. */ + pc_path(cdrom_image[c].image_path, sizeof_w(cdrom_image[c].image_path), wp); if (cdrom_drives[c].host_drive < 'A') cdrom_drives[c].host_drive = 0; @@ -1394,24 +1314,8 @@ load_other_removable_devices(void) sprintf(temp, "zip_%02i_image_path", c+1); wp = config_get_wstring(cat, temp, L""); -#if 0 - /* - * NOTE: - * Temporary hack to remove the absolute - * path currently saved in most config - * files. We should remove this before - * finalizing this release! --FvK - */ - if (! wcsnicmp(wp, usr_path, wcslen(usr_path))) { - /* - * Yep, its absolute and prefixed - * with the EXE path. Just strip - * that off for now... - */ - wcsncpy(zip_drives[c].image_path, &wp[wcslen(usr_path)], sizeof_w(zip_drives[c].image_path)); - } else -#endif - wcsncpy(zip_drives[c].image_path, wp, sizeof_w(zip_drives[c].image_path)); + /* Try to make relative, and copy to destination. */ + pc_path(zip_drives[c].image_path, sizeof_w(zip_drives[c].image_path), wp); /* If the CD-ROM is disabled, delete all its variables. */ if (zip_drives[c].bus_type == ZIP_BUS_DISABLED) { @@ -1719,9 +1623,9 @@ save_sound(void) char *cat = "Sound"; if (sound_card_current == 0) - config_delete_var(cat, "sndcard"); + config_delete_var(cat, "sound_card"); else - config_set_string(cat, "sndcard", sound_card_get_internal_name(sound_card_current)); + config_set_string(cat, "sound_card", sound_card_get_internal_name(sound_card_current)); if (!strcmp(midi_device_get_internal_name(midi_device_current), "none")) config_delete_var(cat, "midi_device"); @@ -1800,34 +1704,34 @@ save_ports(void) char *cat = "Ports (COM & LPT)"; if (serial_enabled[0]) - config_delete_var(cat, "serial1_enabled"); - else config_set_int(cat, "serial1_enabled", serial_enabled[0]); + else + config_delete_var(cat, "serial1_enabled"); if (serial_enabled[1]) - config_delete_var(cat, "serial2_enabled"); - else config_set_int(cat, "serial2_enabled", serial_enabled[1]); + else + config_delete_var(cat, "serial2_enabled"); if (lpt_enabled) - config_delete_var(cat, "lpt_enabled"); - else config_set_int(cat, "lpt_enabled", lpt_enabled); - - if (!strcmp(lpt_device_names[0], "none")) - config_delete_var(cat, "lpt1_device"); else + config_delete_var(cat, "lpt_enabled"); + + if (strcmp(lpt_device_names[0], "none")) config_set_string(cat, "lpt1_device", lpt_device_names[0]); - - if (!strcmp(lpt_device_names[1], "none")) - config_delete_var(cat, "lpt2_device"); else + config_delete_var(cat, "lpt1_device"); + + if (strcmp(lpt_device_names[1], "none")) config_set_string(cat, "lpt2_device", lpt_device_names[1]); - - if (!strcmp(lpt_device_names[2], "none")) - config_delete_var(cat, "lpt3_device"); 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"); delete_section_if_empty(cat); } @@ -1842,9 +1746,9 @@ save_other_peripherals(void) int c; if (scsi_card_current == 0) - config_delete_var(cat, "scsicard"); + config_delete_var(cat, "scsi_card"); else - config_set_string(cat, "scsicard", + config_set_string(cat, "scsi_card", scsi_card_get_internal_name(scsi_card_current)); config_set_string(cat, "hdc", hdc_name); @@ -1882,7 +1786,7 @@ save_hard_disks(void) sprintf(temp, "hdd_%02i_parameters", c+1); if (hdd_is_valid(c)) { p = hdd_bus_to_string(hdd[c].bus, 0); - sprintf(tmp2, "%" PRIu64 ", %" PRIu64", %" PRIu64 ", %i, %s", + sprintf(tmp2, "%u, %u, %u, %d, %s", hdd[c].spt, hdd[c].hpc, hdd[c].tracks, hdd[c].wp, p); config_set_string(cat, temp, tmp2); } else { @@ -2105,7 +2009,7 @@ config_save(void) save_other_removable_devices(); /* Other removable devices */ /* Not if we are running readonly! */ - if (config_ro) + if (! config_ro) config_write(cfg_path); } diff --git a/src/crcspeed/crcspeed.c b/src/crcspeed/crcspeed.c index d2d97a8..ecb58f4 100644 --- a/src/crcspeed/crcspeed.c +++ b/src/crcspeed/crcspeed.c @@ -98,7 +98,7 @@ void crcspeed16big_init(crcfn16 fn, uint16_t big_table[8][256]) { crcspeed16little_init(fn, big_table); for (int k = 0; k < 8; k++) { for (int n = 0; n < 256; n++) { - big_table[k][n] = rev8(big_table[k][n]); + big_table[k][n] = (uint16_t)rev8(big_table[k][n]); } } } @@ -242,7 +242,7 @@ uint16_t crcspeed16big(uint16_t big_table[8][256], uint16_t crc_in, void *buf, len--; } - return rev8(crc); + return (uint16_t)rev8(crc); } /* Return the CRC of buf[0..len-1] with initial crc, processing eight bytes diff --git a/src/disk/hdc_esdi_at.c b/src/disk/hdc_esdi_at.c index b31a934..13e22b6 100644 --- a/src/disk/hdc_esdi_at.c +++ b/src/disk/hdc_esdi_at.c @@ -8,7 +8,7 @@ * * Driver for the ESDI controller (WD1007-vse1) for PC/AT. * - * Version: @(#)hdc_esdi_at.c 1.0.4 2018/03/27 + * Version: @(#)hdc_esdi_at.c 1.0.5 2018/03/31 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -60,7 +60,7 @@ #define HDC_TIME (TIMER_USEC*10LL) -#define ESDI_BIOS_FILE L"roms/hdd/esdi_at/62-000279-061.bin" +#define ESDI_BIOS_FILE L"hdd/esdi_at/62-000279-061.bin" #define STAT_ERR 0x01 #define STAT_INDEX 0x02 diff --git a/src/disk/hdc_esdi_mca.c b/src/disk/hdc_esdi_mca.c index 1aad2fc..a0331b4 100644 --- a/src/disk/hdc_esdi_mca.c +++ b/src/disk/hdc_esdi_mca.c @@ -52,7 +52,7 @@ * however, are auto-configured by the system software as * shown above. * - * Version: @(#)hdc_esdi_mca.c 1.0.3 2018/03/27 + * Version: @(#)hdc_esdi_mca.c 1.0.4 2018/03/31 * * Authors: Fred N. van Kempen, * Sarah Walker, @@ -102,8 +102,8 @@ #define ESDI_IOADDR_SEC 0x3518 #define ESDI_IRQCHAN 14 -#define BIOS_FILE_L L"roms/hdd/esdi/90x8969.bin" -#define BIOS_FILE_H L"roms/hdd/esdi/90x8970.bin" +#define BIOS_FILE_L L"hdd/esdi/90x8969.bin" +#define BIOS_FILE_H L"hdd/esdi/90x8970.bin" #define ESDI_TIME (200LL*TIMER_USEC) diff --git a/src/disk/hdc_mfm_xt.c b/src/disk/hdc_mfm_xt.c index 2478f87..1035c88 100644 --- a/src/disk/hdc_mfm_xt.c +++ b/src/disk/hdc_mfm_xt.c @@ -41,7 +41,7 @@ * Since all controllers (including the ones made by DTC) use * (mostly) the same API, we keep them all in this module. * - * Version: @(#)hdc_mfm_xt.c 1.0.3 2018/03/27 + * Version: @(#)hdc_mfm_xt.c 1.0.5 2018/03/31 * * Authors: Fred N. van Kempen, * Sarah Walker, @@ -90,8 +90,8 @@ #define MFM_TIME (2000LL*TIMER_USEC) -#define XEBEC_BIOS_FILE L"roms/hdd/mfm_xebec/ibm_xebec_62x0822_1985.bin" -#define DTC_BIOS_FILE L"roms/hdd/mfm_xebec/dtc_cxd21a.bin" +#define XEBEC_BIOS_FILE L"hdd/mfm_xebec/ibm_xebec_62x0822_1985.bin" +#define DTC_BIOS_FILE L"hdd/mfm_xebec/dtc_cxd21a.bin" enum { @@ -108,34 +108,38 @@ enum { typedef struct { - int spt, hpc; - int tracks; - int cfg_spt; - int cfg_hpc; - int cfg_cyl; - int current_cylinder; - int present; - int hdd_num; + int spt, + hpc; + int tracks; + int cfg_spt; + int cfg_hpc; + int cfg_cyl; + int current_cylinder; + int present; + int hdd_num; } drive_t; typedef struct { - rom_t bios_rom; - int64_t callback; - int state; - uint8_t status; - uint8_t command[6]; - int command_pos; - uint8_t data[512]; - int data_pos, data_len; - uint8_t sector_buf[512]; - uint8_t irq_dma_mask; - uint8_t completion_byte; - uint8_t error; - int drive_sel; - drive_t drives[2]; - int sector, head, cylinder; - int sector_count; - uint8_t switches; + rom_t bios_rom; + int64_t callback; + int state; + uint8_t status; + uint8_t command[6]; + int command_pos; + uint8_t data[512]; + int data_pos, + data_len; + uint8_t sector_buf[512]; + uint8_t irq_dma_mask; + uint8_t completion_byte; + uint8_t error; + int drive_sel; + drive_t drives[2]; + int sector, + head, + cylinder; + int sector_count; + uint8_t switches; } mfm_t; #define STAT_IRQ 0x20 @@ -173,46 +177,46 @@ typedef struct { static uint8_t mfm_read(uint16_t port, void *priv) { - mfm_t *mfm = (mfm_t *)priv; + mfm_t *dev = (mfm_t *)priv; uint8_t temp = 0xff; switch (port) { case 0x320: /*Read data*/ - mfm->status &= ~STAT_IRQ; - switch (mfm->state) { + dev->status &= ~STAT_IRQ; + switch (dev->state) { case STATE_COMPLETION_BYTE: - if ((mfm->status & 0xf) != (STAT_CD | STAT_IO | STAT_REQ | STAT_BSY)) - fatal("Read data STATE_COMPLETION_BYTE, status=%02x\n", mfm->status); + if ((dev->status & 0xf) != (STAT_CD | STAT_IO | STAT_REQ | STAT_BSY)) + fatal("Read data STATE_COMPLETION_BYTE, status=%02x\n", dev->status); - temp = mfm->completion_byte; - mfm->status = 0; - mfm->state = STATE_IDLE; + temp = dev->completion_byte; + dev->status = 0; + dev->state = STATE_IDLE; break; case STATE_SEND_DATA: - if ((mfm->status & 0xf) != (STAT_IO | STAT_REQ | STAT_BSY)) - fatal("Read data STATE_COMPLETION_BYTE, status=%02x\n", mfm->status); - if (mfm->data_pos >= mfm->data_len) + if ((dev->status & 0xf) != (STAT_IO | STAT_REQ | STAT_BSY)) + fatal("Read data STATE_COMPLETION_BYTE, status=%02x\n", dev->status); + if (dev->data_pos >= dev->data_len) fatal("Data write with full data!\n"); - temp = mfm->data[mfm->data_pos++]; - if (mfm->data_pos == mfm->data_len) { - mfm->status = STAT_BSY; - mfm->state = STATE_SENT_DATA; - mfm->callback = MFM_TIME; + temp = dev->data[dev->data_pos++]; + if (dev->data_pos == dev->data_len) { + dev->status = STAT_BSY; + dev->state = STATE_SENT_DATA; + dev->callback = MFM_TIME; } break; default: - fatal("Read data register - %i, %02x\n", mfm->state, mfm->status); + fatal("Read data register - %i, %02x\n", dev->state, dev->status); } break; case 0x321: /*Read status*/ - temp = mfm->status; + temp = dev->status; break; case 0x322: /*Read option jumpers*/ - temp = mfm->switches; + temp = dev->switches; break; } @@ -223,129 +227,130 @@ mfm_read(uint16_t port, void *priv) static void mfm_write(uint16_t port, uint8_t val, void *priv) { - mfm_t *mfm = (mfm_t *)priv; + mfm_t *dev = (mfm_t *)priv; switch (port) { case 0x320: /*Write data*/ - switch (mfm->state) { + switch (dev->state) { case STATE_RECEIVE_COMMAND: - if ((mfm->status & 0xf) != (STAT_BSY | STAT_CD | STAT_REQ)) - fatal("Bad write data state - STATE_START_COMMAND, status=%02x\n", mfm->status); - if (mfm->command_pos >= 6) + if ((dev->status & 0xf) != (STAT_BSY | STAT_CD | STAT_REQ)) + fatal("Bad write data state - STATE_START_COMMAND, status=%02x\n", dev->status); + if (dev->command_pos >= 6) fatal("Command write with full command!\n"); /*Command data*/ - mfm->command[mfm->command_pos++] = val; - if (mfm->command_pos == 6) { - mfm->status = STAT_BSY; - mfm->state = STATE_START_COMMAND; - mfm->callback = MFM_TIME; + dev->command[dev->command_pos++] = val; + if (dev->command_pos == 6) { + dev->status = STAT_BSY; + dev->state = STATE_START_COMMAND; + dev->callback = MFM_TIME; } break; case STATE_RECEIVE_DATA: - if ((mfm->status & 0xf) != (STAT_BSY | STAT_REQ)) - fatal("Bad write data state - STATE_RECEIVE_DATA, status=%02x\n", mfm->status); - if (mfm->data_pos >= mfm->data_len) + if ((dev->status & 0xf) != (STAT_BSY | STAT_REQ)) + fatal("Bad write data state - STATE_RECEIVE_DATA, status=%02x\n", dev->status); + if (dev->data_pos >= dev->data_len) fatal("Data write with full data!\n"); /*Command data*/ - mfm->data[mfm->data_pos++] = val; - if (mfm->data_pos == mfm->data_len) { - mfm->status = STAT_BSY; - mfm->state = STATE_RECEIVED_DATA; - mfm->callback = MFM_TIME; + dev->data[dev->data_pos++] = val; + if (dev->data_pos == dev->data_len) { + dev->status = STAT_BSY; + dev->state = STATE_RECEIVED_DATA; + dev->callback = MFM_TIME; } break; default: - fatal("Write data unknown state - %i %02x\n", mfm->state, mfm->status); + fatal("Write data unknown state - %i %02x\n", dev->state, dev->status); } break; case 0x321: /*Controller reset*/ - mfm->status = 0; + dev->status = 0; break; case 0x322: /*Generate controller-select-pulse*/ - mfm->status = STAT_BSY | STAT_CD | STAT_REQ; - mfm->command_pos = 0; - mfm->state = STATE_RECEIVE_COMMAND; + dev->status = STAT_BSY | STAT_CD | STAT_REQ; + dev->command_pos = 0; + dev->state = STATE_RECEIVE_COMMAND; break; case 0x323: /*DMA/IRQ mask register*/ - mfm->irq_dma_mask = val; + dev->irq_dma_mask = val; break; } } -static void mfm_complete(mfm_t *mfm) +static void +mfm_complete(mfm_t *dev) { - mfm->status = STAT_REQ | STAT_CD | STAT_IO | STAT_BSY; - mfm->state = STATE_COMPLETION_BYTE; + dev->status = STAT_REQ | STAT_CD | STAT_IO | STAT_BSY; + dev->state = STATE_COMPLETION_BYTE; - if (mfm->irq_dma_mask & IRQ_ENA) { - mfm->status |= STAT_IRQ; + if (dev->irq_dma_mask & IRQ_ENA) { + dev->status |= STAT_IRQ; picint(1 << 5); } } static void -mfm_error(mfm_t *mfm, uint8_t error) +mfm_error(mfm_t *dev, uint8_t error) { - mfm->completion_byte |= 0x02; - mfm->error = error; + dev->completion_byte |= 0x02; + dev->error = error; - pclog("mfm_error - %02x\n", mfm->error); + pclog("mfm_error - %02x\n", dev->error); } static int -get_sector(mfm_t *mfm, off64_t *addr) +get_sector(mfm_t *dev, off64_t *addr) { - drive_t *drive = &mfm->drives[mfm->drive_sel]; + drive_t *drive = &dev->drives[dev->drive_sel]; int heads = drive->cfg_hpc; - if (drive->current_cylinder != mfm->cylinder) { + if (drive->current_cylinder != dev->cylinder) { pclog("mfm_get_sector: wrong cylinder\n"); - mfm->error = ERR_ILLEGAL_SECTOR_ADDRESS; + dev->error = ERR_ILLEGAL_SECTOR_ADDRESS; return(1); } - if (mfm->head > heads) { + if (dev->head > heads) { pclog("mfm_get_sector: past end of configured heads\n"); - mfm->error = ERR_ILLEGAL_SECTOR_ADDRESS; + dev->error = ERR_ILLEGAL_SECTOR_ADDRESS; return(1); } - if (mfm->head > drive->hpc) { + if (dev->head > drive->hpc) { pclog("mfm_get_sector: past end of heads\n"); - mfm->error = ERR_ILLEGAL_SECTOR_ADDRESS; + dev->error = ERR_ILLEGAL_SECTOR_ADDRESS; return(1); } - if (mfm->sector >= 17) { + if (dev->sector >= 17) { pclog("mfm_get_sector: past end of sectors\n"); - mfm->error = ERR_ILLEGAL_SECTOR_ADDRESS; + dev->error = ERR_ILLEGAL_SECTOR_ADDRESS; return(1); } - *addr = ((((off64_t) mfm->cylinder * heads) + mfm->head) * - 17) + mfm->sector; + *addr = ((((off64_t) dev->cylinder * heads) + dev->head) * + 17) + dev->sector; return(0); } static void -next_sector(mfm_t *mfm) +next_sector(mfm_t *dev) { - drive_t *drive = &mfm->drives[mfm->drive_sel]; + drive_t *drive = &dev->drives[dev->drive_sel]; - mfm->sector++; - if (mfm->sector >= 17) { - mfm->sector = 0; - mfm->head++; - if (mfm->head >= drive->cfg_hpc) { - mfm->head = 0; - mfm->cylinder++; + dev->sector++; + if (dev->sector >= 17) { + dev->sector = 0; + dev->head++; + if (dev->head >= drive->cfg_hpc) { + dev->head = 0; + dev->cylinder++; drive->current_cylinder++; if (drive->current_cylinder >= drive->cfg_cyl) drive->current_cylinder = drive->cfg_cyl-1; @@ -357,423 +362,422 @@ next_sector(mfm_t *mfm) static void mfm_callback(void *priv) { - mfm_t *mfm = (mfm_t *)priv; + mfm_t *dev = (mfm_t *)priv; drive_t *drive; off64_t addr; - mfm->callback = 0LL; + dev->callback = 0LL; - mfm->drive_sel = (mfm->command[1] & 0x20) ? 1 : 0; - mfm->completion_byte = mfm->drive_sel & 0x20; - drive = &mfm->drives[mfm->drive_sel]; + dev->drive_sel = (dev->command[1] & 0x20) ? 1 : 0; + dev->completion_byte = dev->drive_sel & 0x20; + drive = &dev->drives[dev->drive_sel]; - switch (mfm->command[0]) { + switch (dev->command[0]) { case CMD_TEST_DRIVE_READY: if (!drive->present) - mfm_error(mfm, ERR_NOT_READY); - mfm_complete(mfm); + mfm_error(dev, ERR_NOT_READY); + mfm_complete(dev); break; case CMD_RECALIBRATE: if (!drive->present) - mfm_error(mfm, ERR_NOT_READY); + mfm_error(dev, ERR_NOT_READY); else { - mfm->cylinder = 0; + dev->cylinder = 0; drive->current_cylinder = 0; } - mfm_complete(mfm); + mfm_complete(dev); break; case CMD_READ_STATUS: - switch (mfm->state) { + switch (dev->state) { case STATE_START_COMMAND: - mfm->state = STATE_SEND_DATA; - mfm->data_pos = 0; - mfm->data_len = 4; - mfm->status = STAT_BSY | STAT_IO | STAT_REQ; - mfm->data[0] = mfm->error; - mfm->data[1] = mfm->drive_sel ? 0x20 : 0; - mfm->data[2] = mfm->data[3] = 0; - mfm->error = 0; + dev->state = STATE_SEND_DATA; + dev->data_pos = 0; + dev->data_len = 4; + dev->status = STAT_BSY | STAT_IO | STAT_REQ; + dev->data[0] = dev->error; + dev->data[1] = dev->drive_sel ? 0x20 : 0; + dev->data[2] = dev->data[3] = 0; + dev->error = 0; break; case STATE_SENT_DATA: - mfm_complete(mfm); + mfm_complete(dev); break; } break; case CMD_VERIFY_SECTORS: - switch (mfm->state) { + switch (dev->state) { case STATE_START_COMMAND: - mfm->cylinder = mfm->command[3] | ((mfm->command[2] & 0xc0) << 2); - drive->current_cylinder = (mfm->cylinder >= drive->cfg_cyl) ? drive->cfg_cyl-1 : mfm->cylinder; - mfm->head = mfm->command[1] & 0x1f; - mfm->sector = mfm->command[2] & 0x1f; - mfm->sector_count = mfm->command[4]; + dev->cylinder = dev->command[3] | ((dev->command[2] & 0xc0) << 2); + drive->current_cylinder = (dev->cylinder >= drive->cfg_cyl) ? drive->cfg_cyl-1 : dev->cylinder; + dev->head = dev->command[1] & 0x1f; + dev->sector = dev->command[2] & 0x1f; + dev->sector_count = dev->command[4]; do { - if (get_sector(mfm, &addr)) { + if (get_sector(dev, &addr)) { pclog("get_sector failed\n"); - mfm_error(mfm, mfm->error); - mfm_complete(mfm); + mfm_error(dev, dev->error); + mfm_complete(dev); return; } - next_sector(mfm); + next_sector(dev); - mfm->sector_count = (mfm->sector_count-1) & 0xff; - } while (mfm->sector_count); + dev->sector_count = (dev->sector_count-1) & 0xff; + } while (dev->sector_count); - mfm_complete(mfm); + mfm_complete(dev); ui_sb_update_icon(SB_HDD | HDD_BUS_MFM, 1); break; default: - fatal("CMD_VERIFY_SECTORS: bad state %i\n", mfm->state); + fatal("CMD_VERIFY_SECTORS: bad state %i\n", dev->state); } break; case CMD_FORMAT_TRACK: - mfm->cylinder = mfm->command[3] | ((mfm->command[2] & 0xc0) << 2); - drive->current_cylinder = (mfm->cylinder >= drive->cfg_cyl) ? drive->cfg_cyl-1 : mfm->cylinder; - mfm->head = mfm->command[1] & 0x1f; + dev->cylinder = dev->command[3] | ((dev->command[2] & 0xc0) << 2); + drive->current_cylinder = (dev->cylinder >= drive->cfg_cyl) ? drive->cfg_cyl-1 : dev->cylinder; + dev->head = dev->command[1] & 0x1f; - if (get_sector(mfm, &addr)) { + if (get_sector(dev, &addr)) { pclog("get_sector failed\n"); - mfm_error(mfm, mfm->error); - mfm_complete(mfm); + mfm_error(dev, dev->error); + mfm_complete(dev); return; } hdd_image_zero(drive->hdd_num, addr, 17); - mfm_complete(mfm); + mfm_complete(dev); break; case CMD_READ_SECTORS: - switch (mfm->state) { + switch (dev->state) { case STATE_START_COMMAND: - mfm->cylinder = mfm->command[3] | ((mfm->command[2] & 0xc0) << 2); - drive->current_cylinder = (mfm->cylinder >= drive->cfg_cyl) ? drive->cfg_cyl-1 : mfm->cylinder; - mfm->head = mfm->command[1] & 0x1f; - mfm->sector = mfm->command[2] & 0x1f; - mfm->sector_count = mfm->command[4]; - mfm->state = STATE_SEND_DATA; - mfm->data_pos = 0; - mfm->data_len = 512; + dev->cylinder = dev->command[3] | ((dev->command[2] & 0xc0) << 2); + drive->current_cylinder = (dev->cylinder >= drive->cfg_cyl) ? drive->cfg_cyl-1 : dev->cylinder; + dev->head = dev->command[1] & 0x1f; + dev->sector = dev->command[2] & 0x1f; + dev->sector_count = dev->command[4]; + dev->state = STATE_SEND_DATA; + dev->data_pos = 0; + dev->data_len = 512; - if (get_sector(mfm, &addr)) { - mfm_error(mfm, mfm->error); - mfm_complete(mfm); + if (get_sector(dev, &addr)) { + mfm_error(dev, dev->error); + mfm_complete(dev); return; } hdd_image_read(drive->hdd_num, addr, 1, - (uint8_t *) mfm->sector_buf); + (uint8_t *) dev->sector_buf); ui_sb_update_icon(SB_HDD|HDD_BUS_MFM, 1); - if (mfm->irq_dma_mask & DMA_ENA) - mfm->callback = MFM_TIME; + if (dev->irq_dma_mask & DMA_ENA) + dev->callback = MFM_TIME; else { - mfm->status = STAT_BSY | STAT_IO | STAT_REQ; - memcpy(mfm->data, mfm->sector_buf, 512); + dev->status = STAT_BSY | STAT_IO | STAT_REQ; + memcpy(dev->data, dev->sector_buf, 512); } break; case STATE_SEND_DATA: - mfm->status = STAT_BSY; - if (mfm->irq_dma_mask & DMA_ENA) { - for (; mfm->data_pos < 512; mfm->data_pos++) { - int val = dma_channel_write(3, mfm->sector_buf[mfm->data_pos]); + dev->status = STAT_BSY; + if (dev->irq_dma_mask & DMA_ENA) { + for (; dev->data_pos < 512; dev->data_pos++) { + int val = dma_channel_write(3, dev->sector_buf[dev->data_pos]); if (val == DMA_NODATA) { pclog("CMD_READ_SECTORS out of data!\n"); - mfm->status = STAT_BSY | STAT_CD | STAT_IO | STAT_REQ; - mfm->callback = MFM_TIME; + dev->status = STAT_BSY | STAT_CD | STAT_IO | STAT_REQ; + dev->callback = MFM_TIME; return; } } - mfm->state = STATE_SENT_DATA; - mfm->callback = MFM_TIME; + dev->state = STATE_SENT_DATA; + dev->callback = MFM_TIME; } else fatal("Read sectors no DMA! - shouldn't get here\n"); break; case STATE_SENT_DATA: - next_sector(mfm); + next_sector(dev); - mfm->data_pos = 0; + dev->data_pos = 0; - mfm->sector_count = (mfm->sector_count-1) & 0xff; + dev->sector_count = (dev->sector_count-1) & 0xff; - if (mfm->sector_count) { - if (get_sector(mfm, &addr)) { - mfm_error(mfm, mfm->error); - mfm_complete(mfm); + if (dev->sector_count) { + if (get_sector(dev, &addr)) { + mfm_error(dev, dev->error); + mfm_complete(dev); return; } hdd_image_read(drive->hdd_num, addr, 1, - (uint8_t *) mfm->sector_buf); + (uint8_t *) dev->sector_buf); ui_sb_update_icon(SB_HDD|HDD_BUS_MFM, 1); - mfm->state = STATE_SEND_DATA; + dev->state = STATE_SEND_DATA; - if (mfm->irq_dma_mask & DMA_ENA) - mfm->callback = MFM_TIME; + if (dev->irq_dma_mask & DMA_ENA) + dev->callback = MFM_TIME; else { - mfm->status = STAT_BSY | STAT_IO | STAT_REQ; - memcpy(mfm->data, mfm->sector_buf, 512); + dev->status = STAT_BSY | STAT_IO | STAT_REQ; + memcpy(dev->data, dev->sector_buf, 512); } } else { - mfm_complete(mfm); + mfm_complete(dev); ui_sb_update_icon(SB_HDD | HDD_BUS_MFM, 0); } break; default: - fatal("CMD_READ_SECTORS: bad state %i\n", mfm->state); + fatal("CMD_READ_SECTORS: bad state %i\n", dev->state); } break; case CMD_WRITE_SECTORS: - switch (mfm->state) { + switch (dev->state) { case STATE_START_COMMAND: - mfm->cylinder = mfm->command[3] | ((mfm->command[2] & 0xc0) << 2); - drive->current_cylinder = (mfm->cylinder >= drive->cfg_cyl) ? drive->cfg_cyl-1 : mfm->cylinder; - mfm->head = mfm->command[1] & 0x1f; - mfm->sector = mfm->command[2] & 0x1f; - mfm->sector_count = mfm->command[4]; - mfm->state = STATE_RECEIVE_DATA; - mfm->data_pos = 0; - mfm->data_len = 512; - if (mfm->irq_dma_mask & DMA_ENA) - mfm->callback = MFM_TIME; + dev->cylinder = dev->command[3] | ((dev->command[2] & 0xc0) << 2); + drive->current_cylinder = (dev->cylinder >= drive->cfg_cyl) ? drive->cfg_cyl-1 : dev->cylinder; + dev->head = dev->command[1] & 0x1f; + dev->sector = dev->command[2] & 0x1f; + dev->sector_count = dev->command[4]; + dev->state = STATE_RECEIVE_DATA; + dev->data_pos = 0; + dev->data_len = 512; + if (dev->irq_dma_mask & DMA_ENA) + dev->callback = MFM_TIME; else - mfm->status = STAT_BSY | STAT_REQ; + dev->status = STAT_BSY | STAT_REQ; break; case STATE_RECEIVE_DATA: - mfm->status = STAT_BSY; - if (mfm->irq_dma_mask & DMA_ENA) { - for (; mfm->data_pos < 512; mfm->data_pos++) { + dev->status = STAT_BSY; + if (dev->irq_dma_mask & DMA_ENA) { + for (; dev->data_pos < 512; dev->data_pos++) { int val = dma_channel_read(3); if (val == DMA_NODATA) { pclog("CMD_WRITE_SECTORS out of data!\n"); - mfm->status = STAT_BSY | STAT_CD | STAT_IO | STAT_REQ; - mfm->callback = MFM_TIME; + dev->status = STAT_BSY | STAT_CD | STAT_IO | STAT_REQ; + dev->callback = MFM_TIME; return; } - mfm->sector_buf[mfm->data_pos] = val & 0xff; + dev->sector_buf[dev->data_pos] = val & 0xff; } - mfm->state = STATE_RECEIVED_DATA; - mfm->callback = MFM_TIME; + dev->state = STATE_RECEIVED_DATA; + dev->callback = MFM_TIME; } else fatal("Write sectors no DMA! - should never get here\n"); break; case STATE_RECEIVED_DATA: - if (! (mfm->irq_dma_mask & DMA_ENA)) - memcpy(mfm->sector_buf, mfm->data, 512); + if (! (dev->irq_dma_mask & DMA_ENA)) + memcpy(dev->sector_buf, dev->data, 512); - if (get_sector(mfm, &addr)) - { - mfm_error(mfm, mfm->error); - mfm_complete(mfm); + if (get_sector(dev, &addr)) { + mfm_error(dev, dev->error); + mfm_complete(dev); return; } hdd_image_write(drive->hdd_num, addr, 1, - (uint8_t *) mfm->sector_buf); + (uint8_t *) dev->sector_buf); ui_sb_update_icon(SB_HDD|HDD_BUS_MFM, 1); - next_sector(mfm); - mfm->data_pos = 0; - mfm->sector_count = (mfm->sector_count-1) & 0xff; + next_sector(dev); + dev->data_pos = 0; + dev->sector_count = (dev->sector_count-1) & 0xff; - if (mfm->sector_count) { - mfm->state = STATE_RECEIVE_DATA; - if (mfm->irq_dma_mask & DMA_ENA) - mfm->callback = MFM_TIME; + if (dev->sector_count) { + dev->state = STATE_RECEIVE_DATA; + if (dev->irq_dma_mask & DMA_ENA) + dev->callback = MFM_TIME; else - mfm->status = STAT_BSY | STAT_REQ; + dev->status = STAT_BSY | STAT_REQ; } else - mfm_complete(mfm); + mfm_complete(dev); break; default: - fatal("CMD_WRITE_SECTORS: bad state %i\n", mfm->state); + fatal("CMD_WRITE_SECTORS: bad state %i\n", dev->state); } break; case CMD_SEEK: if (! drive->present) - mfm_error(mfm, ERR_NOT_READY); + mfm_error(dev, ERR_NOT_READY); else { - int cylinder = mfm->command[3] | ((mfm->command[2] & 0xc0) << 2); + int cylinder = dev->command[3] | ((dev->command[2] & 0xc0) << 2); drive->current_cylinder = (cylinder >= drive->cfg_cyl) ? drive->cfg_cyl-1 : cylinder; if (cylinder != drive->current_cylinder) - mfm_error(mfm, ERR_SEEK_ERROR); + mfm_error(dev, ERR_SEEK_ERROR); } - mfm_complete(mfm); + mfm_complete(dev); break; case CMD_INIT_DRIVE_PARAMS: - switch (mfm->state) { + switch (dev->state) { case STATE_START_COMMAND: - mfm->state = STATE_RECEIVE_DATA; - mfm->data_pos = 0; - mfm->data_len = 8; - mfm->status = STAT_BSY | STAT_REQ; + dev->state = STATE_RECEIVE_DATA; + dev->data_pos = 0; + dev->data_len = 8; + dev->status = STAT_BSY | STAT_REQ; break; case STATE_RECEIVED_DATA: - drive->cfg_cyl = mfm->data[1] | (mfm->data[0] << 8); - drive->cfg_hpc = mfm->data[2]; - pclog("Drive %i: cylinders=%i, heads=%i\n", mfm->drive_sel, drive->cfg_cyl, drive->cfg_hpc); - mfm_complete(mfm); + drive->cfg_cyl = dev->data[1] | (dev->data[0] << 8); + drive->cfg_hpc = dev->data[2]; + pclog("Drive %i: cylinders=%i, heads=%i\n", dev->drive_sel, drive->cfg_cyl, drive->cfg_hpc); + mfm_complete(dev); break; default: - fatal("CMD_INIT_DRIVE_PARAMS bad state %i\n", mfm->state); + fatal("CMD_INIT_DRIVE_PARAMS bad state %i\n", dev->state); } break; case CMD_WRITE_SECTOR_BUFFER: - switch (mfm->state) { + switch (dev->state) { case STATE_START_COMMAND: - mfm->state = STATE_RECEIVE_DATA; - mfm->data_pos = 0; - mfm->data_len = 512; - if (mfm->irq_dma_mask & DMA_ENA) - mfm->callback = MFM_TIME; + dev->state = STATE_RECEIVE_DATA; + dev->data_pos = 0; + dev->data_len = 512; + if (dev->irq_dma_mask & DMA_ENA) + dev->callback = MFM_TIME; else - mfm->status = STAT_BSY | STAT_REQ; + dev->status = STAT_BSY | STAT_REQ; break; case STATE_RECEIVE_DATA: - if (mfm->irq_dma_mask & DMA_ENA) { - mfm->status = STAT_BSY; + if (dev->irq_dma_mask & DMA_ENA) { + dev->status = STAT_BSY; - for (; mfm->data_pos < 512; mfm->data_pos++) { + for (; dev->data_pos < 512; dev->data_pos++) { int val = dma_channel_read(3); if (val == DMA_NODATA) { pclog("CMD_WRITE_SECTOR_BUFFER out of data!\n"); - mfm->status = STAT_BSY | STAT_CD | STAT_IO | STAT_REQ; - mfm->callback = MFM_TIME; + dev->status = STAT_BSY | STAT_CD | STAT_IO | STAT_REQ; + dev->callback = MFM_TIME; return; } - mfm->data[mfm->data_pos] = val & 0xff; + dev->data[dev->data_pos] = val & 0xff; } - mfm->state = STATE_RECEIVED_DATA; - mfm->callback = MFM_TIME; + dev->state = STATE_RECEIVED_DATA; + dev->callback = MFM_TIME; } else fatal("CMD_WRITE_SECTOR_BUFFER - should never get here!\n"); break; case STATE_RECEIVED_DATA: - memcpy(mfm->sector_buf, mfm->data, 512); - mfm_complete(mfm); + memcpy(dev->sector_buf, dev->data, 512); + mfm_complete(dev); break; default: - fatal("CMD_WRITE_SECTOR_BUFFER bad state %i\n", mfm->state); + fatal("CMD_WRITE_SECTOR_BUFFER bad state %i\n", dev->state); } break; case CMD_BUFFER_DIAGNOSTIC: case CMD_CONTROLLER_DIAGNOSTIC: - mfm_complete(mfm); + mfm_complete(dev); break; case 0xfa: - mfm_complete(mfm); + mfm_complete(dev); break; case CMD_DTC_SET_STEP_RATE: - mfm_complete(mfm); + mfm_complete(dev); break; case CMD_DTC_GET_DRIVE_PARAMS: - switch (mfm->state) { + switch (dev->state) { case STATE_START_COMMAND: - mfm->state = STATE_SEND_DATA; - mfm->data_pos = 0; - mfm->data_len = 4; - mfm->status = STAT_BSY | STAT_IO | STAT_REQ; - memset(mfm->data, 0, 4); - mfm->data[0] = drive->tracks & 0xff; - mfm->data[1] = 17 | ((drive->tracks >> 2) & 0xc0); - mfm->data[2] = drive->hpc-1; - pclog("Get drive params %02x %02x %02x %i\n", mfm->data[0], mfm->data[1], mfm->data[2], drive->tracks); + dev->state = STATE_SEND_DATA; + dev->data_pos = 0; + dev->data_len = 4; + dev->status = STAT_BSY | STAT_IO | STAT_REQ; + memset(dev->data, 0, 4); + dev->data[0] = drive->tracks & 0xff; + dev->data[1] = 17 | ((drive->tracks >> 2) & 0xc0); + dev->data[2] = drive->hpc-1; + pclog("Get drive params %02x %02x %02x %i\n", dev->data[0], dev->data[1], dev->data[2], drive->tracks); break; case STATE_SENT_DATA: - mfm_complete(mfm); + mfm_complete(dev); break; default: - fatal("CMD_INIT_DRIVE_PARAMS bad state %i\n", mfm->state); + fatal("CMD_INIT_DRIVE_PARAMS bad state %i\n", dev->state); } break; case CMD_DTC_GET_GEOMETRY: - switch (mfm->state) { + switch (dev->state) { case STATE_START_COMMAND: - mfm->state = STATE_SEND_DATA; - mfm->data_pos = 0; - mfm->data_len = 16; - mfm->status = STAT_BSY | STAT_IO | STAT_REQ; - memset(mfm->data, 0, 16); - mfm->data[0x4] = drive->tracks & 0xff; - mfm->data[0x5] = (drive->tracks >> 8) & 0xff; - mfm->data[0xa] = drive->hpc; + dev->state = STATE_SEND_DATA; + dev->data_pos = 0; + dev->data_len = 16; + dev->status = STAT_BSY | STAT_IO | STAT_REQ; + memset(dev->data, 0, 16); + dev->data[0x4] = drive->tracks & 0xff; + dev->data[0x5] = (drive->tracks >> 8) & 0xff; + dev->data[0xa] = drive->hpc; break; case STATE_SENT_DATA: - mfm_complete(mfm); + mfm_complete(dev); break; } break; case CMD_DTC_SET_GEOMETRY: - switch (mfm->state) { + switch (dev->state) { case STATE_START_COMMAND: - mfm->state = STATE_RECEIVE_DATA; - mfm->data_pos = 0; - mfm->data_len = 16; - mfm->status = STAT_BSY | STAT_REQ; + dev->state = STATE_RECEIVE_DATA; + dev->data_pos = 0; + dev->data_len = 16; + dev->status = STAT_BSY | STAT_REQ; break; case STATE_RECEIVED_DATA: /*Bit of a cheat here - we always report the actual geometry of the drive in use*/ - mfm_complete(mfm); + mfm_complete(dev); break; } break; default: fatal("Unknown Xebec command - %02x %02x %02x %02x %02x %02x\n", - mfm->command[0], mfm->command[1], - mfm->command[2], mfm->command[3], - mfm->command[4], mfm->command[5]); + dev->command[0], dev->command[1], + dev->command[2], dev->command[3], + dev->command[4], dev->command[5]); } } static void -loadhd(mfm_t *mfm, int c, int d, const wchar_t *fn) +loadhd(mfm_t *dev, int c, int d, const wchar_t *fn) { - drive_t *drive = &mfm->drives[d]; + drive_t *drive = &dev->drives[d]; if (! hdd_image_load(d)) { drive->present = 0; @@ -782,14 +786,15 @@ loadhd(mfm_t *mfm, int c, int d, const wchar_t *fn) drive->spt = (uint8_t)hdd[c].spt; drive->hpc = (uint8_t)hdd[c].hpc; - drive->tracks = (uint8_t)hdd[c].tracks; + drive->tracks = (uint16_t)hdd[c].tracks; drive->hdd_num = c; drive->present = 1; } -static struct { - int tracks, hpc; +static const struct { + uint16_t tracks; + uint8_t hpc; } hd_types[4] = { { 306, 4 }, /* Type 0 */ { 612, 4 }, /* Type 16 */ @@ -799,14 +804,14 @@ static struct { static void -mfm_set_switches(mfm_t *mfm) +mfm_set_switches(mfm_t *dev) { int c, d; - mfm->switches = 0; + dev->switches = 0; for (d=0; d<2; d++) { - drive_t *drive = &mfm->drives[d]; + drive_t *drive = &dev->drives[d]; if (! drive->present) continue; @@ -814,118 +819,88 @@ mfm_set_switches(mfm_t *mfm) if (drive->spt == 17 && drive->hpc == hd_types[c].hpc && drive->tracks == hd_types[c].tracks) { - mfm->switches |= (c << (d ? 0 : 2)); + dev->switches |= (c << (d ? 0 : 2)); break; } } if (c == 4) - pclog("WARNING: Drive %c: has format not supported by Fixed Disk Adapter", d ? 'D' : 'C'); + pclog("WARNING: drive %d has unsupported format %d/%d/%d !\n", + d, drive->tracks, drive->hpc, drive->spt); } } static void * -xebec_init(const device_t *info) +mfm_init(const device_t *info) { - int i, c = 0; + wchar_t *fn = NULL; + mfm_t *dev; + int i, c; - mfm_t *xebec = malloc(sizeof(mfm_t)); - memset(xebec, 0x00, sizeof(mfm_t)); + dev = malloc(sizeof(mfm_t)); + memset(dev, 0x00, sizeof(mfm_t)); pclog("MFM: looking for disks..\n"); + c = 0; for (i=0; i MFM_NUM) break; } } pclog("MFM: %d disks loaded.\n", c); - mfm_set_switches(xebec); + switch(info->local) { + case 0: /* Xebec */ + fn = XEBEC_BIOS_FILE; + mfm_set_switches(dev); + break; - rom_init(&xebec->bios_rom, XEBEC_BIOS_FILE, + case 1: /* DTC5150 */ + fn = DTC_BIOS_FILE; + dev->switches = 0xff; + dev->drives[0].cfg_cyl = dev->drives[0].tracks; + dev->drives[0].cfg_hpc = dev->drives[0].hpc; + dev->drives[1].cfg_cyl = dev->drives[1].tracks; + dev->drives[1].cfg_hpc = dev->drives[1].hpc; + break; + } + + rom_init(&dev->bios_rom, fn, 0xc8000, 0x4000, 0x3fff, 0, MEM_MAPPING_EXTERNAL); - + io_sethandler(0x0320, 4, - mfm_read, NULL, NULL, mfm_write, NULL, NULL, xebec); + mfm_read,NULL,NULL, mfm_write,NULL,NULL, dev); - timer_add(mfm_callback, &xebec->callback, &xebec->callback, xebec); - - return(xebec); + timer_add(mfm_callback, &dev->callback, &dev->callback, dev); + + return(dev); } static void mfm_close(void *priv) { - mfm_t *mfm = (mfm_t *)priv; + mfm_t *dev = (mfm_t *)priv; int d; for (d=0; d<2; d++) { - drive_t *drive = &mfm->drives[d]; + drive_t *drive = &dev->drives[d]; hdd_image_close(drive->hdd_num); } - - free(mfm); + + free(dev); } static int xebec_available(void) { - return(rom_present(XEBEC_BIOS_FILE)); -} - - -const device_t mfm_xt_xebec_device = { - "IBM PC Fixed Disk Adapter", - DEVICE_ISA, - 0, - xebec_init, mfm_close, NULL, - xebec_available, NULL, NULL, NULL, - NULL -}; - - -static void * -dtc5150x_init(const device_t *info) -{ - int i, c = 0; - - mfm_t *dtc = malloc(sizeof(mfm_t)); - memset(dtc, 0x00, sizeof(mfm_t)); - - pclog("MFM: looking for disks..\n"); - for (i=0; i MFM_NUM) break; - } - } - pclog("MFM: %d disks loaded.\n", c); - - dtc->switches = 0xff; - - dtc->drives[0].cfg_cyl = dtc->drives[0].tracks; - dtc->drives[0].cfg_hpc = dtc->drives[0].hpc; - dtc->drives[1].cfg_cyl = dtc->drives[1].tracks; - dtc->drives[1].cfg_hpc = dtc->drives[1].hpc; - - rom_init(&dtc->bios_rom, DTC_BIOS_FILE, - 0xc8000, 0x4000, 0x3fff, 0, MEM_MAPPING_EXTERNAL); - - io_sethandler(0x0320, 4, - mfm_read, NULL, NULL, mfm_write, NULL, NULL, dtc); - - timer_add(mfm_callback, &dtc->callback, &dtc->callback, dtc); - - return(dtc); + return(rom_present(XEBEC_BIOS_FILE)); } @@ -936,11 +911,20 @@ dtc5150x_available(void) } +const device_t mfm_xt_xebec_device = { + "IBM PC Fixed Disk Adapter", + DEVICE_ISA, + 0, + mfm_init, mfm_close, NULL, + xebec_available, NULL, NULL, NULL, + NULL +}; + const device_t mfm_xt_dtc5150x_device = { "DTC 5150X", DEVICE_ISA, - 0, - dtc5150x_init, mfm_close, NULL, + 1, + mfm_init, mfm_close, NULL, dtc5150x_available, NULL, NULL, NULL, NULL }; diff --git a/src/disk/hdc_xtide.c b/src/disk/hdc_xtide.c index 52b5cd6..2cf6ef5 100644 --- a/src/disk/hdc_xtide.c +++ b/src/disk/hdc_xtide.c @@ -21,7 +21,7 @@ * already on their way out, the newer IDE standard based on the * PC/AT controller and 16b design became the IDE we now know. * - * Version: @(#)hdc_xtide.c 1.0.3 2018/03/15 + * Version: @(#)hdc_xtide.c 1.0.4 2018/03/31 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -61,10 +61,10 @@ #include "hdc_ide.h" -#define ROM_PATH_XT L"roms/hdd/xtide/ide_xt.bin" -#define ROM_PATH_AT L"roms/hdd/xtide/ide_at.bin" -#define ROM_PATH_PS2 L"roms/hdd/xtide/side1v12.bin" -#define ROM_PATH_PS2AT L"roms/hdd/xtide/ide_at_1_1_5.bin" +#define ROM_PATH_XT L"hdd/xtide/ide_xt.bin" +#define ROM_PATH_AT L"hdd/xtide/ide_at.bin" +#define ROM_PATH_PS2 L"hdd/xtide/side1v12.bin" +#define ROM_PATH_PS2AT L"hdd/xtide/ide_at_1_1_5.bin" typedef struct { diff --git a/src/disk/hdd.h b/src/disk/hdd.h index b5b9f6a..768ad73 100644 --- a/src/disk/hdd.h +++ b/src/disk/hdd.h @@ -8,7 +8,7 @@ * * Definitions for the hard disk image handler. * - * Version: @(#)hdd.h 1.0.1 2018/02/14 + * Version: @(#)hdd.h 1.0.3 2018/03/31 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -55,6 +55,13 @@ enum { }; +/* Define a hard disk table entry. */ +typedef struct { + uint16_t cyls; + uint8_t head; + uint8_t sect; +} hddtab_t; + /* Define the virtual Hard Disk. */ typedef struct { int8_t is_hdi; /* image type (should rename) */ @@ -71,11 +78,11 @@ typedef struct { uint32_t base; - uint64_t spt, - hpc, /* physical geometry parameters */ - tracks; + uint8_t spt, /* physical geometry parameters */ + hpc; + uint16_t tracks; - uint64_t at_spt, /* [Translation] parameters */ + uint8_t at_spt, /* [Translation] parameters */ at_hpc; FILE *f; /* current file handle to image */ @@ -86,7 +93,7 @@ typedef struct { extern hard_disk_t hdd[HDD_NUM]; -extern uint64_t hdd_table[128][3]; +extern const hddtab_t hdd_table[128]; extern int hdd_init(void); @@ -104,7 +111,7 @@ extern void hdd_image_zero(uint8_t id, uint32_t sector, uint32_t count); extern int hdd_image_zero_ex(uint8_t id, uint32_t sector, uint32_t count); extern uint32_t hdd_image_get_last_sector(uint8_t id); extern uint8_t hdd_image_get_type(uint8_t id); -extern void hdd_image_specify(uint8_t id, uint64_t hpc, uint64_t spt); +extern void hdd_image_specify(uint8_t id, int hpc, int spt); extern void hdd_image_unload(uint8_t id, int fn_preserve); extern void hdd_image_close(uint8_t id); diff --git a/src/disk/hdd_image.c b/src/disk/hdd_image.c index 74da7db..feeb7db 100644 --- a/src/disk/hdd_image.c +++ b/src/disk/hdd_image.c @@ -8,7 +8,7 @@ * * Handling of hard disk image files. * - * Version: @(#)hdd_image.c 1.0.2 2018/03/27 + * Version: @(#)hdd_image.c 1.0.3 2018/03/31 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -144,10 +144,9 @@ int hdd_image_load(int id) uint32_t sector_size = 512; uint32_t zero = 0; uint64_t signature = 0xD778A82044445459ll; - uint64_t full_size = 0; - uint64_t spt = 0, hpc = 0, tracks = 0; - int c; - uint64_t i = 0, s = 0, t = 0; + uint64_t s = 0, t, full_size = 0; + int spt = 0, hpc = 0, tracks = 0; + int c, i; wchar_t *fn = hdd[id].fn; int is_hdx[2] = { 0, 0 }; @@ -260,9 +259,9 @@ int hdd_image_load(int id) return 0; } } - hdd[id].spt = spt; - hdd[id].hpc = hpc; - hdd[id].tracks = tracks; + hdd[id].spt = (uint8_t)spt; + hdd[id].hpc = (uint8_t)hpc; + hdd[id].tracks = (uint16_t)tracks; hdd_images[id].type = 1; } else if (is_hdx[1]) { hdd_images[id].base = 0x28; @@ -290,9 +289,9 @@ int hdd_image_load(int id) return 0; } } - hdd[id].spt = spt; - hdd[id].hpc = hpc; - hdd[id].tracks = tracks; + hdd[id].spt = (uint8_t)spt; + hdd[id].hpc = (uint8_t)hpc; + hdd[id].tracks = (uint16_t)tracks; fread(&(hdd[id].at_spt), 1, 4, hdd_images[id].file); fread(&(hdd[id].at_hpc), 1, 4, hdd_images[id].file); hdd_images[id].type = 2; @@ -435,11 +434,11 @@ uint8_t hdd_image_get_type(uint8_t id) return hdd_images[id].type; } -void hdd_image_specify(uint8_t id, uint64_t hpc, uint64_t spt) +void hdd_image_specify(uint8_t id, int hpc, int spt) { if (hdd_images[id].type == 2) { - hdd[id].at_hpc = hpc; - hdd[id].at_spt = spt; + hdd[id].at_hpc = (uint8_t)hpc; + hdd[id].at_spt = (uint8_t)spt; fseeko64(hdd_images[id].file, 0x20, SEEK_SET); fwrite(&(hdd[id].at_spt), 1, 4, hdd_images[id].file); fwrite(&(hdd[id].at_hpc), 1, 4, hdd_images[id].file); diff --git a/src/disk/hdd_table.c b/src/disk/hdd_table.c index 98395b4..6386144 100644 --- a/src/disk/hdd_table.c +++ b/src/disk/hdd_table.c @@ -8,7 +8,7 @@ * * Define the available hard disk types. * - * Version: @(#)hdd_table.c 1.0.1 2018/02/14 + * Version: @(#)hdd_table.c 1.0.2 2018/03/29 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -43,7 +43,7 @@ #include "hdd.h" -uint64_t hdd_table[128][3] = { +const hddtab_t hdd_table[128] = { { 306, 4, 17 }, /* 0 - 7 */ { 615, 2, 17 }, { 306, 4, 26 }, diff --git a/src/emu.h b/src/emu.h index 40fffb9..6854f07 100644 --- a/src/emu.h +++ b/src/emu.h @@ -8,7 +8,7 @@ * * Main include file for the application. * - * Version: @(#)emu.h 1.0.10 2018/03/20 + * Version: @(#)emu.h 1.0.12 2018/03/31 * * Author: Fred N. van Kempen, * @@ -58,10 +58,11 @@ #define NVR_PATH L"nvr" #define ROMS_PATH L"roms" #define MACHINES_PATH L"machines" -#define VIDEO_PATH L"machines" +#define VIDEO_PATH L"video" #define SCREENSHOT_PATH L"screenshots" -#define CONFIG_FILE L"varcem.cfg" +#define CONFIG_FILE L"config.varc" +#define CONFIG_FILE_EXT L".varc" #define BIOS_FILE L"bios.txt" @@ -94,8 +95,6 @@ extern int do_dump_config; /* (O) dump cfg after load */ extern int start_in_fullscreen; /* (O) start in fullscreen */ #ifdef _WIN32 extern int force_debug; /* (O) force debug output */ -extern uint64_t unique_id; /* (O) -H id */ -extern uint64_t source_hwnd; /* (O) -H hwnd */ #endif #ifdef USE_WX extern int video_fps; /* (O) render speed in fps */ @@ -176,10 +175,11 @@ extern int config_changed; /* config has changed */ extern void pclog_ex(const char *fmt, va_list); #endif extern void pclog(const char *fmt, ...); -extern void pc_version(const char *platform); extern void fatal(const char *fmt, ...); -extern int pc_init_modules(void); +extern void pc_version(const char *platform); +extern void pc_path(wchar_t *dest, int dest_sz, wchar_t *src); extern int pc_init(int argc, wchar_t *argv[]); +extern int pc_init_modules(void); extern void pc_close(void *threadid); extern void pc_reset_hard_close(void); extern void pc_reset_hard_init(void); diff --git a/src/intel_flash.c b/src/intel_flash.c index 1adc41c..b25d94a 100644 --- a/src/intel_flash.c +++ b/src/intel_flash.c @@ -8,7 +8,7 @@ * * Implementation of the Intel 2 Mbit 8-bit flash devices. * - * Version: @(#)intel_flash.c 1.0.4 2018/03/15 + * Version: @(#)intel_flash.c 1.0.5 2018/03/31 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -256,7 +256,7 @@ void *intel_flash_init(uint8_t type) flash->command = CMD_READ_ARRAY; flash->status = 0; - f = nvr_fopen(flash_path, L"rb"); + f = plat_fopen(nvr_path(flash_path), L"rb"); if (f) { fread(&(flash->array[flash->block_start[BLOCK_MAIN]]), flash->block_len[BLOCK_MAIN], 1, f); fread(&(flash->array[flash->block_start[BLOCK_DATA1]]), flash->block_len[BLOCK_DATA1], 1, f); @@ -298,7 +298,7 @@ void intel_flash_close(void *p) FILE *f; flash_t *flash = (flash_t *)p; - f = nvr_fopen(flash_path, L"wb"); + f = plat_fopen(nvr_path(flash_path), L"wb"); fwrite(&(flash->array[flash->block_start[BLOCK_MAIN]]), flash->block_len[BLOCK_MAIN], 1, f); fwrite(&(flash->array[flash->block_start[BLOCK_DATA1]]), flash->block_len[BLOCK_DATA1], 1, f); fwrite(&(flash->array[flash->block_start[BLOCK_DATA2]]), flash->block_len[BLOCK_DATA2], 1, f); diff --git a/src/machine/m_ps1.c b/src/machine/m_ps1.c index 2fbbb0c..e454417 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.7 2018/03/27 + * Version: @(#)m_ps1.c 1.0.8 2018/03/31 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -508,7 +508,7 @@ ps1_setup(int model) #if 0 rom_init(&ps->high_rom, - L"roms/machines/ibmps1es/f80000_shell.bin", + L"machines/ibmps1es/f80000_shell.bin", 0xf80000, 0x80000, 0x7ffff, 0, MEM_MAPPING_EXTERNAL); #endif @@ -532,11 +532,11 @@ ps1_setup(int model) #if 1 rom_init(&ps->high_rom, - L"roms/machines/ibmps1_2121/fc0000.bin", + L"machines/ibmps1_2121/fc0000.bin", 0xfc0000, 0x20000, 0x1ffff, 0, MEM_MAPPING_EXTERNAL); #else rom_init(&ps->high_rom, - L"roms/machines/ibmps1_2121/fc0000_shell.bin", + L"machines/ibmps1_2121/fc0000_shell.bin", 0xfc0000, 0x40000, 0x3ffff, 0, MEM_MAPPING_EXTERNAL); #endif diff --git a/src/machine/m_tandy.c b/src/machine/m_tandy.c index df301e4..2a89519 100644 --- a/src/machine/m_tandy.c +++ b/src/machine/m_tandy.c @@ -8,7 +8,7 @@ * * Emulation of Tandy models 1000, 1000HX and 1000SL2. * - * Version: @(#)m_tandy.c 1.0.4 2018/03/21 + * Version: @(#)m_tandy.c 1.0.5 2018/03/31 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -60,6 +60,7 @@ #include "../sound/snd_sn76489.h" #include "../video/video.h" #include "../video/vid_cga_comp.h" +#include "../plat.h" #include "machine.h" @@ -1540,7 +1541,7 @@ eep_init(const device_t *info) } - f = nvr_fopen(eep->path, L"rb"); + f = plat_fopen(nvr_path(eep->path), L"rb"); if (f != NULL) { fread(eep->store, 128, 1, f); (void)fclose(f); @@ -1558,7 +1559,7 @@ eep_close(void *priv) t1keep_t *eep = (t1keep_t *)priv; FILE *f = NULL; - f = nvr_fopen(eep->path, L"rb"); + f = plat_fopen(nvr_path(eep->path), L"rb"); if (f != NULL) { (void)fwrite(eep->store, 128, 1, f); (void)fclose(f); @@ -1685,8 +1686,8 @@ init_rom(tandy_t *dev) { dev->rom = (uint8_t *)malloc(0x80000); - if (! rom_load_interleaved(L"roms/machines/tandy1000sl2/8079047.hu1", - L"roms/machines/tandy1000sl2/8079048.hu2", + if (! rom_load_interleaved(L"machines/tandy1000sl2/8079047.hu1", + L"machines/tandy1000sl2/8079048.hu2", 0x000000, 0x80000, 0, dev->rom)) { pclog("TANDY: unable to load BIOS for 1000/SL2 !\n"); free(dev->rom); diff --git a/src/machine/m_xt.c b/src/machine/m_xt.c index aaed126..0f18cc8 100644 --- a/src/machine/m_xt.c +++ b/src/machine/m_xt.c @@ -8,7 +8,7 @@ * * Implementation of standard IBM PC/XT class machine. * - * Version: @(#)m_xt.c 1.0.4 2018/03/21 + * Version: @(#)m_xt.c 1.0.5 2018/03/29 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -52,11 +52,55 @@ #include "machine.h" +/* Nasty, used by config.sys. Will re-do later. --FvK */ +int rom_basic = 0; /* is ROM BASIC enabled? */ + + +static const device_config_t xt_config[] = { + { + "rom_basic", "ROM BASIC", CONFIG_SELECTION, "", 0, + { + { + "Disabled", 0 + }, + { + "Enabled", 1 + }, + { + "" + } + } + }, + { + "", "", -1 + } +}; + + +static const device_t m_xt_device = { + "PC/XT Configuration Device", + MACHINE_ISA, + 0, + NULL, NULL, NULL, + NULL, + NULL, NULL, NULL, + xt_config +}; + + void machine_xt_init(const machine_t *model, void *arg) { machine_common_init(model, arg); + /* Check if we support a BASIC ROM. */ + if (model->get_device != NULL) { + pclog("This (%s) machine supports a BASIC ROM.\n", model->name); + + rom_basic = machine_get_config_int("rom_basic"); + pclog("ROM BASIC is currently %sabled.\n", (rom_basic)?"en":"dis"); + } + pit_set_out_func(&pit, 1, pit_refresh_timer_xt); device_add(&keyboard_xt_device); @@ -68,3 +112,10 @@ machine_xt_init(const machine_t *model, void *arg) if (joystick_type != JOYSTICK_TYPE_NONE) device_add(&gameport_device); } + + +const device_t * +xt_get_device(void) +{ + return(&m_xt_device); +} diff --git a/src/machine/m_xt_t1000.c b/src/machine/m_xt_t1000.c index 07e798a..f815622 100644 --- a/src/machine/m_xt_t1000.c +++ b/src/machine/m_xt_t1000.c @@ -48,7 +48,9 @@ * hold a single BCD digit. Hence everything has 'ones' and * 'tens' digits. * - * Version: @(#)m_xt_t1000.c 1.0.6 2018/03/21 + * FIXME: The ROM drive should be re-done using the "option file". + * + * Version: @(#)m_xt_t1000.c 1.0.7 2018/03/31 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -102,7 +104,8 @@ #include "m_xt_t1000.h" -#define T1000_ROMSIZE (512*1024UL) /* Maximum ROM drive size is 512k */ +#define T1000_ROMDOS_SIZE (512*1024UL) /* Max romdrive size is 512k */ +#define T1000_ROMDOS_PATH L"machines/toshiba/t1000/t1000dos.rom" enum TC8521_ADDR { @@ -814,7 +817,7 @@ t1000_write_rom_ctl(uint16_t addr, uint8_t val, void *priv) sys->rom_ctl = val; if (sys->romdrive && (val & 0x80)) { /* Enable */ - sys->rom_offset = ((val & 0x7f) * 0x10000) % T1000_ROMSIZE; + sys->rom_offset = ((val & 0x7f) * 0x10000) % T1000_ROMDOS_SIZE; mem_mapping_set_addr(&sys->rom_mapping, 0xa0000, 0x10000); mem_mapping_set_exec(&sys->rom_mapping, sys->romdrive + sys->rom_offset); mem_mapping_enable(&sys->rom_mapping); @@ -876,7 +879,7 @@ machine_xt_t1000_init(const machine_t *model, void *arg) t1000.ems_port_index = 7; /* EMS disabled */ /* Load the T1000 CGA Font ROM. */ - loadfont(L"roms/machines/toshiba/t1000/t1000font.rom", 2); + loadfont(L"machines/toshiba/t1000/t1000font.rom", 2); /* * The ROM drive is optional. @@ -884,12 +887,12 @@ machine_xt_t1000_init(const machine_t *model, void *arg) * If the file is missing, continue to boot; the BIOS will * complain 'No ROM drive' but boot normally from floppy. */ - f = rom_fopen(L"roms/machines/toshiba/t1000/t1000dos.rom"); + f = plat_fopen(rom_path(T1000_ROMDOS_PATH), L"rb"); if (f != NULL) { - t1000.romdrive = malloc(T1000_ROMSIZE); + t1000.romdrive = malloc(T1000_ROMDOS_SIZE); if (t1000.romdrive) { - memset(t1000.romdrive, 0xff, T1000_ROMSIZE); - fread(t1000.romdrive, T1000_ROMSIZE, 1, f); + memset(t1000.romdrive, 0xff, T1000_ROMDOS_SIZE); + fread(t1000.romdrive, T1000_ROMDOS_SIZE, 1, f); } fclose(f); } @@ -976,7 +979,7 @@ machine_xt_t1200_init(const machine_t *model, void *arg) t1000.ems_port_index = 7; /* EMS disabled */ /* Load the T1200 CGA Font ROM. */ - loadfont(L"roms/machines/toshiba/t1200/t1000font.bin", 2); + loadfont(L"machines/toshiba/t1200/t1000font.bin", 2); /* Map the EMS page frame */ for (pg = 0; pg < 4; pg++) { diff --git a/src/machine/machine.c b/src/machine/machine.c index ada19dc..d86e2dd 100644 --- a/src/machine/machine.c +++ b/src/machine/machine.c @@ -85,6 +85,7 @@ machine_init(void) /* Activate the ROM BIOS. */ mem_add_bios(); + /* Reset the IDE bus master pointers. */ ide_set_bus_master(NULL, NULL, NULL); /* All good, boot the machine! */ diff --git a/src/machine/machine.h b/src/machine/machine.h index e8d1a47..3bd7a21 100644 --- a/src/machine/machine.h +++ b/src/machine/machine.h @@ -8,7 +8,7 @@ * * Handling of the emulated machines. * - * Version: @(#)machine.h 1.0.12 2018/03/21 + * Version: @(#)machine.h 1.0.13 2018/03/29 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -341,6 +341,9 @@ extern void machine_tandy1k_init(const machine_t *, void *); extern int tandy1k_eeprom_read(void); extern void machine_xt_init(const machine_t *, void *); +#ifdef EMU_DEVICE_H +extern const device_t *xt_get_device(void); +#endif extern void machine_xt_compaq_init(const machine_t *, void *); #if defined(DEV_BRANCH) && defined(USE_LASERXT) extern void machine_xt_laserxt_init(const machine_t *, void *); diff --git a/src/machine/machine_table.c b/src/machine/machine_table.c index 0ffa963..d30cac7 100644 --- a/src/machine/machine_table.c +++ b/src/machine/machine_table.c @@ -11,7 +11,7 @@ * NOTES: OpenAT wip for 286-class machine with open BIOS. * PS2_M80-486 wip, pending receipt of TRM's for machine. * - * Version: @(#)machine_table.c 1.0.14 2018/03/22 + * Version: @(#)machine_table.c 1.0.15 2018/03/29 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -53,13 +53,13 @@ const machine_t machines[] = { - { "[8088] AMI XT clone", ROM_AMIXT, "ami_xt", L"generic/ami/xt", {{"", cpus_8088}, {"", NULL}, {"", NULL}, {"", NULL}, {"", NULL}}, 0, MACHINE_ISA, 64, 640, 64, 0, machine_xt_init, NULL, NULL }, - { "[8088] Compaq Portable", ROM_PORTABLE, "compaq_portable", L"compaq/portable", {{"", cpus_8088}, {"", NULL}, {"", NULL}, {"", NULL}, {"", NULL}}, 0, MACHINE_ISA | MACHINE_VIDEO, 128, 640, 128, 0, machine_xt_compaq_init, NULL, NULL }, - { "[8088] DTK XT clone", ROM_DTKXT, "dtk_xt", L"dtk/xt", {{"", cpus_8088}, {"", NULL}, {"", NULL}, {"", NULL}, {"", NULL}}, 0, MACHINE_ISA, 64, 640, 64, 0, machine_xt_init, NULL, NULL }, - { "[8088] IBM PC", ROM_IBMPC, "ibm_pc", L"ibm/pc", {{"", cpus_8088}, {"", NULL}, {"", NULL}, {"", NULL}, {"", NULL}}, 0, MACHINE_ISA, 64, 640, 32, 0, machine_xt_init, NULL, NULL }, + { "[8088] IBM PC", ROM_IBMPC, "ibm_pc", L"ibm/pc", {{"", cpus_8088}, {"", NULL}, {"", NULL}, {"", NULL}, {"", NULL}}, 0, MACHINE_ISA, 64, 640, 32, 0, machine_xt_init, xt_get_device, NULL }, { "[8088] IBM PCjr", ROM_IBMPCJR, "ibm_pcjr", L"ibm/pcjr", {{"", cpus_pcjr}, {"", NULL}, {"", NULL}, {"", NULL}, {"", NULL}}, 1, MACHINE_ISA | MACHINE_VIDEO, 128, 640, 128, 0, machine_pcjr_init, pcjr_get_device, NULL }, - { "[8088] IBM XT", ROM_IBMXT, "ibm_xt", L"ibm/xt", {{"", cpus_8088}, {"", NULL}, {"", NULL}, {"", NULL}, {"", NULL}}, 0, MACHINE_ISA, 64, 640, 64, 0, machine_xt_init, NULL, NULL }, - { "[8088] Generic XT clone", ROM_GENXT, "open_xt", L"generic/open_xt", {{"", cpus_8088}, {"", NULL}, {"", NULL}, {"", NULL}, {"", NULL}}, 0, MACHINE_ISA, 64, 640, 64, 0, machine_xt_init, NULL, NULL }, + { "[8088] IBM XT", ROM_IBMXT, "ibm_xt", L"ibm/xt", {{"", cpus_8088}, {"", NULL}, {"", NULL}, {"", NULL}, {"", NULL}}, 0, MACHINE_ISA, 64, 640, 64, 0, machine_xt_init, xt_get_device, NULL }, + { "[8088] OpenXT Generic Clone", ROM_GENXT, "open_xt", L"generic/open_xt", {{"", cpus_8088}, {"", NULL}, {"", NULL}, {"", NULL}, {"", NULL}}, 0, MACHINE_ISA, 64, 640, 64, 0, machine_xt_init, xt_get_device, NULL }, + { "[8088] AMI XT clone", ROM_AMIXT, "ami_xt", L"generic/ami/xt", {{"", cpus_8088}, {"", NULL}, {"", NULL}, {"", NULL}, {"", NULL}}, 0, MACHINE_ISA, 64, 640, 64, 0, machine_xt_init, xt_get_device, NULL }, + { "[8088] Compaq Portable", ROM_PORTABLE, "compaq_portable", L"compaq/portable", {{"", cpus_8088}, {"", NULL}, {"", NULL}, {"", NULL}, {"", NULL}}, 0, MACHINE_ISA | MACHINE_VIDEO, 128, 640, 128, 0, machine_xt_compaq_init, NULL, NULL }, + { "[8088] DTK XT clone", ROM_DTKXT, "dtk_xt", L"dtk/xt", {{"", cpus_8088}, {"", NULL}, {"", NULL}, {"", NULL}, {"", NULL}}, 0, MACHINE_ISA, 64, 640, 64, 0, machine_xt_init, xt_get_device, NULL }, { "[8088] Juko XT clone", ROM_JUKOPC, "juko_pc", L"juko/pc", {{"", cpus_8088}, {"", NULL}, {"", NULL}, {"", NULL}, {"", NULL}}, 0, MACHINE_ISA, 64, 640, 64, 0, machine_xt_init, NULL, NULL }, { "[8088] Phoenix XT clone", ROM_PXXT, "phoenix_xt", L"generic/phoenix/xt", {{"", cpus_8088}, {"", NULL}, {"", NULL}, {"", NULL}, {"", NULL}}, 0, MACHINE_ISA, 64, 640, 64, 0, machine_xt_init, NULL, NULL }, { "[8088] Schneider EuroPC", ROM_EUROPC, "schneider_europc", L"schneider/europc", {{"Siemens", cpus_europc}, {"", NULL}, {"", NULL}, {"", NULL}, {"", NULL}}, 0, MACHINE_ISA | MACHINE_HDC | MACHINE_VIDEO | MACHINE_MOUSE, 512, 640, 128, 16, machine_europc_init, NULL, NULL }, @@ -69,8 +69,8 @@ const machine_t machines[] = { #if defined(DEV_BRANCH) && defined(USE_LASERXT) { "[8088] VTech Laser Turbo XT", ROM_LTXT, "vtech_ltxt", L"vtech/ltxt", {{"", cpus_8088}, {"", NULL}, {"", NULL}, {"", NULL}, {"", NULL}}, 0, MACHINE_ISA, 512, 512, 256, 0, machine_xt_laserxt_init, NULL, NULL }, #endif - { "[8088] Xi8088", ROM_XI8088, "malinov_xi8088", L"malinov/xi8088", {{"", cpus_8088}, {"", NULL}, {"", NULL}, {"", NULL}, {"", NULL}}, 0, MACHINE_ISA /*| MACDHINE_AT*/ | MACHINE_PS2, 64, 1024, 128, 128, machine_xt_xi8088_init, NULL, NULL }, + { "[8086] Amstrad PC1512", ROM_PC1512, "amstrad_pc1512", L"amstrad/pc1512", {{"", cpus_pc1512}, {"", NULL}, {"", NULL}, {"", NULL}, {"", NULL}}, 0, MACHINE_ISA | MACHINE_VIDEO | MACHINE_MOUSE, 512, 640, 128, 64, machine_amstrad_init, NULL, NULL }, { "[8086] Amstrad PC1640", ROM_PC1640, "amstrad_pc1640", L"amstrad/pc1640", {{"", cpus_8086}, {"", NULL}, {"", NULL}, {"", NULL}, {"", NULL}}, 0, MACHINE_ISA | MACHINE_VIDEO | MACHINE_MOUSE, 640, 640, 0, 64, machine_amstrad_init, NULL, NULL }, { "[8086] Amstrad PC2086", ROM_PC2086, "amstrad_pc2086", L"amstrad/pc2086", {{"", cpus_8086}, {"", NULL}, {"", NULL}, {"", NULL}, {"", NULL}}, 1, MACHINE_ISA | MACHINE_VIDEO | MACHINE_MOUSE, 640, 640, 0, 64, machine_amstrad_init, NULL, NULL }, diff --git a/src/mem.c b/src/mem.c index 3b775bd..e3f4aa2 100644 --- a/src/mem.c +++ b/src/mem.c @@ -12,7 +12,7 @@ * the DYNAMIC_TABLES=1 enables this. Will eventually go * away, either way... * - * Version: @(#)mem.c 1.0.10 2018/03/27 + * Version: @(#)mem.c 1.0.11 2018/03/30 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -77,7 +77,7 @@ mem_mapping_t romext_mapping; page_t *pages, /* RAM page table */ **page_lookup; /* pagetable lookup */ -uint32_t pages_sz; /* #pages in table */ +uint32_t pages_sz = 0; /* #pages in table */ uint8_t isram[0x10000]; @@ -1614,7 +1614,7 @@ mem_reset(void) #if DYNAMIC_TABLES pclog("MEM: reset: previous pages=%08lx, pages_sz=%i\n", pages, pages_sz); #endif - if (pages_sz != m) { + if (pages_sz != m || pages_sz == 0) { pages_sz = m; free(pages); pages = (page_t *)malloc(m*sizeof(page_t)); diff --git a/src/mouse.c b/src/mouse.c index 62397ae..4ce6fa4 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.3 2018/03/18 + * Version: @(#)mouse.c 1.0.4 2018/03/29 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -164,7 +164,7 @@ mouse_process(void) { static int poll_delay = 2; - if (mouse_devices[mouse_type].device == NULL) return; + if (mouse_type == MOUSE_TYPE_NONE) return; if (--poll_delay) return; diff --git a/src/network/net_ne2000.c b/src/network/net_ne2000.c index 05b2ec6..62f9e35 100644 --- a/src/network/net_ne2000.c +++ b/src/network/net_ne2000.c @@ -12,7 +12,7 @@ * - Realtek RTL8019AS (ISA 16-bit, PnP); * - Realtek RTL8029AS (PCI). * - * Version: @(#)net_ne2000.c 1.0.3 2018/03/15 + * Version: @(#)net_ne2000.c 1.0.4 2018/03/31 * * Based on @(#)ne2k.cc v1.56.2.1 2004/02/02 22:37:22 cbothamy * @@ -61,6 +61,7 @@ #include "../pic.h" #include "../random.h" #include "../device.h" +#include "../plat.h" #include "../ui.h" #include "network.h" #include "net_ne2000.h" @@ -76,10 +77,10 @@ enum { /* ROM BIOS file paths. */ -#define ROM_PATH_NE1000 L"roms/network/ne1000/ne1000.rom" -#define ROM_PATH_NE2000 L"roms/network/ne2000/ne2000.rom" -#define ROM_PATH_RTL8019 L"roms/network/rtl8019as/rtl8019as.rom" -#define ROM_PATH_RTL8029 L"roms/network/rtl8029as/rtl8029as.rom" +#define ROM_PATH_NE1000 L"network/ne1000/ne1000.rom" +#define ROM_PATH_NE2000 L"network/ne2000/ne2000.rom" +#define ROM_PATH_RTL8019 L"network/rtl8019as/rtl8019as.rom" +#define ROM_PATH_RTL8029 L"network/rtl8029as/rtl8029as.rom" /* PCI info. */ #define PNP_VENDID 0x4a8c /* Realtek, Inc */ @@ -2348,7 +2349,7 @@ nic_rom_init(nic_t *dev, wchar_t *s) if (dev->bios_addr == 0) return; - if ((f = rom_fopen(s)) != NULL) { + if ((f = plat_fopen(rom_path(s), L"rb")) != NULL) { fseek(f, 0L, SEEK_END); temp = ftell(f); fclose(f); diff --git a/src/network/pcap_if.c b/src/network/pcap_if.c index defb7b1..6dbe4af 100644 --- a/src/network/pcap_if.c +++ b/src/network/pcap_if.c @@ -10,7 +10,7 @@ * * Based on the "libpcap" examples. * - * Version: @(#)pcap_if.c 1.0.12 2018/03/26 + * Version: @(#)pcap_if.c 1.0.3 2018/03/30 * * Author: Fred N. van Kempen, * diff --git a/src/nvr.c b/src/nvr.c index 148f699..b14e08f 100644 --- a/src/nvr.c +++ b/src/nvr.c @@ -10,7 +10,7 @@ * * NOTE: I should re-do 'intclk' using a TM struct. * - * Version: @(#)nvr.c 1.0.3 2018/03/20 + * Version: @(#)nvr.c 1.0.4 2018/03/31 * * Author: Fred N. van Kempen, * @@ -197,6 +197,31 @@ nvr_init(nvr_t *nvr) } +/* Get path to the NVR folder. */ +wchar_t * +nvr_path(wchar_t *str) +{ + static wchar_t temp[1024]; + + /* Get the full prefix in place. */ + wcscpy(temp, usr_path); + wcscat(temp, NVR_PATH); + + /* Create the directory if needed. */ + if (! plat_dir_check(temp)) + plat_dir_create(temp); + + /* Now append the actual filename. */ + plat_append_slash(temp); + wcscat(temp, str); + + /* Make sure path is clean. */ + pc_path(temp, sizeof_w(temp), NULL); + + return(temp); +} + + /* * Load an NVR from file. * @@ -211,6 +236,7 @@ nvr_init(nvr_t *nvr) int nvr_load(void) { + wchar_t *path; FILE *f; /* Make sure we have been initialized. */ @@ -225,8 +251,9 @@ nvr_load(void) /* Load the (relevant) part of the NVR contents. */ if (saved_nvr->size != 0) { - pclog("NVR: loading from '%ls'\n", nvr_path(saved_nvr->fn)); - f = plat_fopen(nvr_path(saved_nvr->fn), L"rb"); + path = nvr_path(saved_nvr->fn); + pclog("NVR: loading from '%ls'\n", path); + f = plat_fopen(path, L"rb"); if (f != NULL) { /* Read NVR contents from file. */ (void)fread(saved_nvr->regs, saved_nvr->size, 1, f); @@ -246,14 +273,16 @@ nvr_load(void) int nvr_save(void) { + wchar_t *path; FILE *f; /* Make sure we have been initialized. */ if (config_ro || saved_nvr == NULL) return(0); if (saved_nvr->size != 0) { - pclog("NVR: saving to '%ls'\n", nvr_path(saved_nvr->fn)); - f = plat_fopen(nvr_path(saved_nvr->fn), L"wb"); + path = nvr_path(saved_nvr->fn); + pclog("NVR: saving to '%ls'\n", path); + f = plat_fopen(path, L"wb"); if (f != NULL) { /* Save NVR contents to file. */ (void)fwrite(saved_nvr->regs, saved_nvr->size, 1, f); @@ -302,34 +331,3 @@ nvr_time_set(struct tm *tm) intclk.mon = (tm->tm_mon + 1); intclk.year = (tm->tm_year + 1900); } - - -/* Get an absolute path to the NVR folder. */ -wchar_t * -nvr_path(wchar_t *str) -{ - static wchar_t temp[1024]; - - /* Get the full prefix in place. */ - memset(temp, 0x00, sizeof(temp)); - wcscpy(temp, usr_path); - wcscat(temp, NVR_PATH); - - /* Create the directory if needed. */ - if (! plat_dir_check(temp)) - plat_dir_create(temp); - - /* Now append the actual filename. */ - plat_append_slash(temp); - wcscat(temp, str); - - return(temp); -} - - -/* Open or create a file in the NVR area. */ -FILE * -nvr_fopen(wchar_t *str, wchar_t *mode) -{ - return(plat_fopen(nvr_path(str), mode)); -} diff --git a/src/nvr.h b/src/nvr.h index 50b06d4..8b5110f 100644 --- a/src/nvr.h +++ b/src/nvr.h @@ -1,105 +1,98 @@ -/* - * 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. - * - * Definitions for the generic NVRAM/CMOS driver. - * - * Version: @(#)nvr.h 1.0.4 2018/03/19 - * - * Author: Fred N. van Kempen, - * - * Copyright 2017,2018 Fred N. van Kempen. - * - * Redistribution and use in source and binary forms, with - * or without modification, are permitted provided that the - * following conditions are met: - * - * 1. Redistributions of source code must retain the entire - * above notice, this list of conditions and the following - * disclaimer. - * - * 2. Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other - * materials provided with the distribution. - * - * 3. Neither the name of the copyright holder nor the names - * of its contributors may be used to endorse or promote - * products derived from this software without specific - * prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#ifndef EMU_NVR_H -# define EMU_NVR_H - - -#define NVR_MAXSIZE 128 /* max size of NVR data */ - -/* Conversion from BCD to Binary and vice versa. */ -#define RTC_BCD(x) (((x) % 10) | (((x) / 10) << 4)) -#define RTC_DCB(x) ((((x) & 0xf0) >> 4) * 10 + ((x) & 0x0f)) -#define RTC_BCDINC(x,y) RTC_BCD(RTC_DCB(x) + y) - - -/* Define a generic RTC/NVRAM device. */ -typedef struct _nvr_ { - uint8_t regs[NVR_MAXSIZE]; /* these are the registers */ - wchar_t *fn; /* pathname of image file */ - uint16_t size; /* device configuration */ - int8_t irq; - - int8_t upd_stat, /* FIXME: move to private struct */ - addr; - int64_t upd_ecount, /* FIXME: move to private struct */ - onesec_time, - onesec_cnt, - rtctime; - - /* Hooks to device functions. */ - void (*reset)(struct _nvr_ *); - void (*start)(struct _nvr_ *); - void (*tick)(struct _nvr_ *); -} nvr_t; - - -extern int nvr_dosave; -#ifdef EMU_DEVICE_H -extern const device_t at_nvr_device; -extern const device_t amstrad_nvr_device; -#endif - - -extern void nvr_init(nvr_t *); -extern int nvr_load(void); -extern int nvr_save(void); - -extern int nvr_is_leap(int year); -extern int nvr_get_days(int month, int year); -extern void nvr_time_get(struct tm *); -extern void nvr_time_set(struct tm *); - -extern wchar_t *nvr_path(wchar_t *str); -extern FILE *nvr_fopen(wchar_t *str, wchar_t *mode); - -#if 0 -extern void nvr_at_init(int irq); -extern void nvr_at_close(void); +/* + * 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. + * + * Definitions for the generic NVRAM/CMOS driver. + * + * Version: @(#)nvr.h 1.0.5 2018/03/31 + * + * Author: Fred N. van Kempen, + * + * Copyright 2017,2018 Fred N. van Kempen. + * + * Redistribution and use in source and binary forms, with + * or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the entire + * above notice, this list of conditions and the following + * disclaimer. + * + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the + * following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names + * of its contributors may be used to endorse or promote + * products derived from this software without specific + * prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef EMU_NVR_H +# define EMU_NVR_H + + +#define NVR_MAXSIZE 128 /* max size of NVR data */ + +/* Conversion from BCD to Binary and vice versa. */ +#define RTC_BCD(x) (((x) % 10) | (((x) / 10) << 4)) +#define RTC_DCB(x) ((((x) & 0xf0) >> 4) * 10 + ((x) & 0x0f)) +#define RTC_BCDINC(x,y) RTC_BCD(RTC_DCB(x) + y) + + +/* Define a generic RTC/NVRAM device. */ +typedef struct _nvr_ { + uint8_t regs[NVR_MAXSIZE]; /* these are the registers */ + wchar_t *fn; /* pathname of image file */ + uint16_t size; /* device configuration */ + int8_t irq; + + int8_t upd_stat, /* FIXME: move to private struct */ + addr; + int64_t upd_ecount, /* FIXME: move to private struct */ + onesec_time, + onesec_cnt, + rtctime; + + /* Hooks to device functions. */ + void (*reset)(struct _nvr_ *); + void (*start)(struct _nvr_ *); + void (*tick)(struct _nvr_ *); +} nvr_t; + + +extern int nvr_dosave; +#ifdef EMU_DEVICE_H +extern const device_t at_nvr_device; +extern const device_t amstrad_nvr_device; #endif - - -#endif /*EMU_NVR_H*/ + + +extern void nvr_init(nvr_t *); +extern wchar_t *nvr_path(wchar_t *fn); +extern int nvr_load(void); +extern int nvr_save(void); + +extern int nvr_is_leap(int year); +extern int nvr_get_days(int month, int year); +extern void nvr_time_get(struct tm *); +extern void nvr_time_set(struct tm *); + + +#endif /*EMU_NVR_H*/ diff --git a/src/nvr_ps2.c b/src/nvr_ps2.c index 844b975..d4b1780 100644 --- a/src/nvr_ps2.c +++ b/src/nvr_ps2.c @@ -8,7 +8,7 @@ * * Handling of the PS/2 series CMOS devices. * - * Version: @(#)nvr_ps2.c 1.0.5 2018/03/15 + * Version: @(#)nvr_ps2.c 1.0.6 2018/03/31 * * Authors: Fred N. van Kempen, * Sarah Walker, @@ -45,6 +45,7 @@ #include "device.h" #include "io.h" #include "nvr.h" +#include "plat.h" #include "nvr_ps2.h" @@ -114,15 +115,15 @@ ps2_nvr_init(const device_t *info) switch (romset) { case ROM_IBMPS2_M70_TYPE3: - f = nvr_fopen(L"ibmps2_m70_type3_sec.nvr", L"rb"); + f = plat_fopen(nvr_path(L"ibmps2_m70_type3_sec.nvr"), L"rb"); break; case ROM_IBMPS2_M70_TYPE4: - f = nvr_fopen(L"ibmps2_m70_type4_sec.nvr", L"rb"); + f = plat_fopen(nvr_path(L"ibmps2_m70_type4_sec.nvr"), L"rb"); break; case ROM_IBMPS2_M80: - f = nvr_fopen(L"ibmps2_m80_sec.nvr", L"rb"); + f = plat_fopen(nvr_path(L"ibmps2_m80_sec.nvr"), L"rb"); break; } @@ -144,15 +145,15 @@ ps2_nvr_close(void *priv) switch (romset) { case ROM_IBMPS2_M70_TYPE3: - f = nvr_fopen(L"ibmps2_m70_type3_sec.nvr", L"wb"); + f = plat_fopen(nvr_path(L"ibmps2_m70_type3_sec.nvr"), L"wb"); break; case ROM_IBMPS2_M70_TYPE4: - f = nvr_fopen(L"ibmps2_m70_type4_sec.nvr", L"wb"); + f = plat_fopen(nvr_path(L"ibmps2_m70_type4_sec.nvr"), L"wb"); break; case ROM_IBMPS2_M80: - f = nvr_fopen(L"ibmps2_m80_sec.nvr", L"wb"); + f = plat_fopen(nvr_path(L"ibmps2_m80_sec.nvr"), L"wb"); break; } diff --git a/src/pc.c b/src/pc.c index beebf07..5705950 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.16 2018/03/27 + * Version: @(#)pc.c 1.0.17 2018/03/31 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -102,8 +102,6 @@ int do_dump_config = 0; /* (O) dump config on load */ int start_in_fullscreen = 0; /* (O) start in fullscreen */ #ifdef _WIN32 int force_debug = 0; /* (O) force debug output */ -uint64_t unique_id = 0; /* (O) -H id */ -uint64_t source_hwnd = 0; /* (O) -H hwnd */ #endif #ifdef USE_WX int video_fps = RENDER_FPS; /* (O) render speed in fps */ @@ -325,6 +323,45 @@ pc_version(const char *platform) } +/* + * NOTE: + * + * Although we now use relative pathnames in the code, + * we may still bump into old configuration files that + * still have old, absolute pathnames. + * + * We try to "fix" those by stripping the "usr_path" + * component from them, if they have that. If another + * path, well, nothing we can do here. + */ +void +pc_path(wchar_t *dst, int sz, wchar_t *src) +{ + if ((src != NULL) && !wcsnicmp(src, usr_path, wcslen(usr_path))) + src += wcslen(usr_path); + + /* + * Fix all the slashes. + * + * Since Windows will handle both \ and / paths, we + * now convert ALL paths to the latter format, so it + * is always the same. + */ + if (src == NULL) + src = dst; + while ((sz > 0) && (*src != L'\0')) { + if (*src == L'\\') + *dst = L'/'; + else + *dst = *src; + src++; + dst++; + sz--; + } + *dst = L'\0'; +} + + /* * Perform initial startup of the PC. * @@ -387,6 +424,9 @@ pc_init(int argc, wchar_t *argv[]) if (!wcscasecmp(argv[c], L"--help") || !wcscasecmp(argv[c], L"-?")) { usage: +#ifdef _WIN32 + plat_console(1); +#endif printf("\n%s %s\n", emu_title, emu_fullversion); printf("\nUsage: varcem [options] [cfg-file]\n\n"); printf("Valid options are:\n\n"); @@ -403,9 +443,6 @@ usage: printf(" -R or --fps num - set render speed to 'num' fps\n"); #endif printf(" -S or --settings - show only the settings dialog\n"); -#ifdef _WIN32 - printf(" -H or --hwnd id,hwnd - sends back the main dialog's hwnd\n"); -#endif printf(" -W or --readonly - do not modify the config file\n"); printf("\nA config file can be specified. If none is, the default file will be used.\n"); return(0); @@ -442,15 +479,6 @@ usage: } else if (!wcscasecmp(argv[c], L"--settings") || !wcscasecmp(argv[c], L"-S")) { settings_only = 1; -#ifdef _WIN32 - } else if (!wcscasecmp(argv[c], L"--hwnd") || - !wcscasecmp(argv[c], L"-H")) { - - if ((c+1) == argc) goto usage; - - wcstombs(temp, argv[++c], sizeof(temp)); - sscanf(temp, "%016" PRIX64 ",%016" PRIX64, &unique_id, &source_hwnd); -#endif } else if (!wcscasecmp(argv[c], L"--readonly") || !wcscasecmp(argv[c], L"-W")) { config_ro = 1; @@ -537,10 +565,22 @@ usage: /* At this point, we can safely create the full path name. */ plat_append_filename(cfg_path, usr_path, p); + /* If no extension was given, tack on the default one. */ + if ((cfg = wcschr(p, L'.')) == NULL) + wcscat(cfg_path, CONFIG_FILE_EXT); + /* * This is where we start outputting to the log file, * if there is one. Create a little info header first. + * + * For the Windows version, if we do not have a console + * meaning, not logging to file..), request one if we + * have force_debug set. */ +#ifdef _WIN32 + if (force_debug) + plat_console(1); +#endif (void)time(&now); info = localtime(&now); strftime(temp, sizeof(temp), "%Y/%m/%d %H:%M:%S", info); @@ -556,11 +596,12 @@ usage: * disks are an example) so we have to initialize those * modules before we load the config.. */ - hdd_init(); - network_init(); mouse_init(); + sound_global_init(); + hdd_init(); cdrom_global_init(); zip_global_init(); + network_init(); /* Load the configuration file. */ config_load(); diff --git a/src/plat.h b/src/plat.h index 521c6b6..d3ee116 100644 --- a/src/plat.h +++ b/src/plat.h @@ -8,7 +8,7 @@ * * Define the various platform support functions. * - * Version: @(#)plat.h 1.0.6 2018/03/28 + * Version: @(#)plat.h 1.0.7 2018/03/31 * * Author: Fred N. van Kempen, * @@ -100,6 +100,9 @@ GLOBAL int infocus; /* System-related functions. */ +#ifdef _WIN32 +extern void plat_console(int on); +#endif extern wchar_t *fix_emu_path(wchar_t *str); extern FILE *plat_fopen(wchar_t *path, wchar_t *mode); extern void plat_remove(wchar_t *path); diff --git a/src/rom.c b/src/rom.c index 8279713..2072957 100644 --- a/src/rom.c +++ b/src/rom.c @@ -12,7 +12,7 @@ * - pc2386 video BIOS is underdumped (16k instead of 24k) * - c386sx16 BIOS fails checksum * - * Version: @(#)rom.c 1.0.8 2018/03/12 + * Version: @(#)rom.c 1.0.10 2018/03/31 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -53,44 +53,32 @@ #include "plat.h" -FILE * -rom_fopen(wchar_t *fn) +/* Return the base path for ROM images. */ +wchar_t * +rom_path(wchar_t *str) { - wchar_t temp[1024]; + static wchar_t temp[1024]; + /* Get the full path in place. */ wcscpy(temp, emu_path); + wcscat(temp, ROMS_PATH); plat_append_slash(temp); - wcscat(temp, fn); + wcscat(temp, str); - return(plat_fopen(temp, L"rb")); -} - - -int -rom_getfile(wchar_t *fn, wchar_t *s, int size) -{ - FILE *f; - - wcscpy(s, emu_path); - plat_append_slash(s); - wcscat(s, fn); - - f = plat_fopen(s, L"rb"); - if (f != NULL) { - (void)fclose(f); - return(1); - } - - return(0); + /* Make sure path is clean. */ + pc_path(temp, sizeof_w(temp), NULL); + + return(temp); } +/* Used by the available() functions to check if a file exists. */ int rom_present(wchar_t *fn) { FILE *f; - f = rom_fopen(fn); + f = plat_fopen(rom_path(fn), L"rb"); if (f != NULL) { (void)fclose(f); return(1); @@ -149,8 +137,9 @@ rom_readl(uint32_t addr, void *priv) int rom_load_linear(wchar_t *fn, uint32_t addr, int sz, int off, uint8_t *ptr) { - FILE *f = rom_fopen(fn); - + FILE *f; + + f = plat_fopen(rom_path(fn), L"rb"); if (f == NULL) { pclog("ROM: image '%ls' not found\n", fn); return(0); @@ -174,8 +163,9 @@ rom_load_linear(wchar_t *fn, uint32_t addr, int sz, int off, uint8_t *ptr) int rom_load_linear_inverted(wchar_t *fn, uint32_t addr, int sz, int off, uint8_t *ptr) { - FILE *f = rom_fopen(fn); + FILE *f; + f = plat_fopen(rom_path(fn), L"rb"); if (f == NULL) { pclog("ROM: image '%ls' not found\n", fn); return(0); @@ -206,8 +196,8 @@ rom_load_linear_inverted(wchar_t *fn, uint32_t addr, int sz, int off, uint8_t *p int rom_load_interleaved(wchar_t *fnl, wchar_t *fnh, uint32_t addr, int sz, int off, uint8_t *ptr) { - FILE *fl = rom_fopen(fnl); - FILE *fh = rom_fopen(fnh); + FILE *fl = plat_fopen(rom_path(fnl), L"rb"); + FILE *fh = plat_fopen(rom_path(fnh), L"rb"); int c; if (fl == NULL || fh == NULL) { diff --git a/src/rom.h b/src/rom.h index 3e46561..9da5672 100644 --- a/src/rom.h +++ b/src/rom.h @@ -8,7 +8,7 @@ * * Definitions for the ROM image handler. * - * Version: @(#)rom.h 1.0.7 2018/03/21 + * Version: @(#)rom.h 1.0.9 2018/03/31 * * Authors: Fred N. van Kempen, * @@ -71,6 +71,7 @@ typedef struct { int mode; uint32_t offset; uint32_t skip; + uint32_t size; } files[ROMDEF_NFILES]; } romdef_t; @@ -79,8 +80,7 @@ extern uint8_t rom_read(uint32_t addr, void *p); extern uint16_t rom_readw(uint32_t addr, void *p); extern uint32_t rom_readl(uint32_t addr, void *p); -extern FILE *rom_fopen(wchar_t *fn); -extern int rom_getfile(wchar_t *fn, wchar_t *s, int size); +extern wchar_t *rom_path(wchar_t *fn); extern int rom_present(wchar_t *fn); extern int rom_load_linear(wchar_t *fn, uint32_t addr, int sz, diff --git a/src/rom_load.c b/src/rom_load.c index 15f5243..d1b85f6 100644 --- a/src/rom_load.c +++ b/src/rom_load.c @@ -17,7 +17,7 @@ * or to use a generic handler, and then pass it a pointer * to a command table. For now, we don't. * - * Version: @(#)rom_load.c 1.0.5 2018/03/21 + * Version: @(#)rom_load.c 1.0.6 2018/03/31 * * Author: Fred N. van Kempen, * @@ -62,23 +62,40 @@ #include "emu.h" #include "mem.h" #include "rom.h" +#include "device.h" #include "plat.h" -#define PATH_BIOS "bios.txt" /* name of the script we run */ #define MAX_ARGS 16 /* max number of arguments */ +/* Grab the value from a string. */ +static uint32_t +get_val(char *str) +{ + long unsigned int l = 0UL; + + if ((strlen(str) > 1) && /* hex always is 0x... */ + (sscanf(str, "0x%lx", &l) == 0)) /* no valid field found */ + sscanf(str, "%i", (int *)&l); /* try decimal.. */ + + return(l); +} + + /* Process a single (logical) command line. */ static int process(int ln, int argc, char **argv, romdef_t *r) { +again: if (! strcmp(argv[0], "size")) { - sscanf(argv[1], "%i", &r->total); + /* Total size of image. */ + r->total = get_val(argv[1]); } else if (! strcmp(argv[0], "offset")) { - if (sscanf(argv[1], "0x%lx", (long unsigned int *)&r->offset) == 0) - sscanf(argv[1], "%i", &r->offset); + /* Offset into the ROM area. */ + r->offset = get_val(argv[1]); } else if (! strcmp(argv[0], "mode")) { + /* Loading method to use for this image. */ if (! strcmp(argv[1], "linear")) r->mode = 0; else if (! strcmp(argv[1], "interleaved")) @@ -87,23 +104,46 @@ process(int ln, int argc, char **argv, romdef_t *r) pclog("ROM: invalid mode '%s' on line %d.\n", argv[1], ln); return(0); } + } else if (! strcmp(argv[0], "optional")) { + /* + * This is an optional file. + * Next word is the name of the configuration + * variable this depends on, for example "basic" + * or "romdos". + */ + if (! machine_get_config_int(argv[1])) return(1); + + /* Skip the keyword and variable name, and re-parse. */ + argv += 2; + argc -= 2; + goto again; } else if (! strcmp(argv[0], "file")) { + /* Specify the image filename and/or additional parameters. */ mbstowcs(r->files[r->nfiles].path, argv[1], sizeof_w(r->files[r->nfiles].path)); - if (argc >= 3) - sscanf(argv[2], "%i", &r->files[r->nfiles].skip); - else - r->files[r->nfiles].skip = 0; - if (argc == 4) { - if (sscanf(argv[3], "0x%lx", (long unsigned int *)&r->files[r->nfiles].offset) == 0) - sscanf(argv[3], "%i", &r->files[r->nfiles].offset); - } else - r->files[r->nfiles].offset = r->offset; + r->files[r->nfiles].skip = 0; + r->files[r->nfiles].offset = r->offset; + r->files[r->nfiles].size = r->total; + switch(argc) { + case 5: + r->files[r->nfiles].size = get_val(argv[4]); + /*FALLTHROUGH*/ + + case 4: + r->files[r->nfiles].offset = get_val(argv[3]); + /*FALLTHROUGH*/ + + case 3: + r->files[r->nfiles].skip = get_val(argv[2]); + break; + } r->nfiles++; } else if (! strcmp(argv[0], "font")) { + /* Load a video controller font. */ r->fontnum = atoi(argv[1]); mbstowcs(r->fontfn, argv[2], sizeof_w(r->fontfn)); } else if (! strcmp(argv[0], "video")) { + /* Load a video controller BIOS. */ mbstowcs(r->vidfn, argv[1], sizeof_w(r->vidfn)); sscanf(argv[2], "%i", &r->vidsz); } else { @@ -313,19 +353,23 @@ parser(FILE *fp, romdef_t *r) int rom_load_bios(romdef_t *r, wchar_t *fn, int test_only) { - wchar_t path[1024], script[1024]; + wchar_t path[1024]; wchar_t temp[1024]; + wchar_t script[1024]; FILE *fp; int c, i; + /* Generate the BIOS pathname. */ + wcscpy(path, fn); + plat_append_slash(path); + /* Generate the full script pathname. */ - wcscpy(script, ROMS_PATH); plat_append_slash(script); - wcscat(script, fn); plat_append_slash(script); - wcscpy(path, script); + wcscpy(script, path); wcscat(script, BIOS_FILE); + pc_path(script, sizeof_w(script), NULL); if (! test_only) { - pclog("ROM: loading script '%ls'\n", fn); + pclog("ROM: loading script '%ls'\n", rom_path(script)); /* If not done yet, allocate a 128KB buffer for the BIOS ROM. */ if (rom == NULL) @@ -341,8 +385,8 @@ rom_load_bios(romdef_t *r, wchar_t *fn, int test_only) } /* Open the script file. */ - if ((fp = rom_fopen(script)) == NULL) { - pclog("ROM: unable to open '%ls'\n", script); + if ((fp = plat_fopen(rom_path(script), L"rb")) == NULL) { + pclog("ROM: unable to open '%ls'\n", rom_path(script)); return(0); } @@ -362,8 +406,9 @@ rom_load_bios(romdef_t *r, wchar_t *fn, int test_only) pclog("Mode : %s\n", (r->mode == 1)?"interleaved":"linear"); pclog("Files : %d\n", r->nfiles); for (c=0; cnfiles; c++) { - pclog(" [%d] : '%ls', %d, 0x%06lx\n", c+1, - r->files[c].path, r->files[c].skip, r->files[c].offset); + pclog(" [%d] : '%ls', %i, 0x%06lx, %i\n", c+1, + r->files[c].path, r->files[c].skip, + r->files[c].offset, r->files[c].size); } if (r->fontnum != -1) pclog("Font : %i, '%ls'\n", r->fontnum, r->fontfn); @@ -377,11 +422,12 @@ rom_load_bios(romdef_t *r, wchar_t *fn, int test_only) for (c=0; cnfiles; c++) { wcscpy(script, path); wcscat(script, r->files[c].path); + pc_path(script, sizeof_w(script), NULL); i = rom_load_linear(script, r->files[c].offset, - r->total, + r->files[c].size, r->files[c].skip, rom); - if (i != 0) break; + if (i != 1) break; } if (r->total >= 0x010000) biosmask = (r->total - 1); @@ -392,13 +438,15 @@ rom_load_bios(romdef_t *r, wchar_t *fn, int test_only) for (c=0; cnfiles/2; c+=2) { wcscpy(script, path); wcscat(script, r->files[c].path); + pc_path(script, sizeof_w(script), NULL); wcscpy(temp, path); wcscat(temp, r->files[c+1].path); + pc_path(temp, sizeof_w(temp), NULL); i = rom_load_interleaved(script, temp, r->files[c].offset, - r->total, + r->files[c].size, r->files[c].skip, rom); - if (i != 0) break; + if (i != 1) break; } if (r->total >= 0x010000) biosmask = (r->total - 1); @@ -409,14 +457,14 @@ rom_load_bios(romdef_t *r, wchar_t *fn, int test_only) if (r->fontnum != -1) { wcscpy(temp, path); wcscat(temp, r->fontfn); - wcscpy(r->fontfn, temp); + pc_path(r->fontfn, sizeof_w(r->fontfn), temp); } /* Create a full pathname for the video BIOS file. */ if (r->vidsz != 0) { wcscpy(temp, path); wcscat(temp, r->vidfn); - wcscpy(r->vidfn, temp); + pc_path(r->vidfn, sizeof_w(r->vidfn), temp); } pclog("ROM: status %d, tot %u, mask 0x%06lx\n", diff --git a/src/scsi/scsi_aha154x.c b/src/scsi/scsi_aha154x.c index 68b5a89..d6e2a97 100644 --- a/src/scsi/scsi_aha154x.c +++ b/src/scsi/scsi_aha154x.c @@ -10,7 +10,7 @@ * made by Adaptec, Inc. These controllers were designed for * the ISA bus. * - * Version: @(#)scsi_aha154x.c 1.0.5 2018/03/15 + * Version: @(#)scsi_aha154x.c 1.0.6 2018/03/31 * * Based on original code from TheCollector1995 and Miran Grca. * @@ -47,7 +47,6 @@ #include #define HAVE_STDARG_H #include "../emu.h" -#include "../cpu/cpu.h" // for debug, temporary #include "../io.h" #include "../mca.h" #include "../mem.h" @@ -64,6 +63,14 @@ #include "scsi_x54x.h" +#define AHA1540B_330_BIOS_PATH L"scsi/adaptec/aha1540b320_330.bin" +#define AHA1540B_334_BIOS_PATH L"scsi/adaptec/aha1540b320_334.bin" +#define AHA1540C_BIOS_PATH L"scsi/adaptec/aha1542c102.bin" +#define AHA1540CF_BIOS_PATH L"scsi/adaptec/aha1542cf211.bin" +#define AHA1540CP_BIOS_PATH L"scsi/adaptec/aha1542cp102.bin" +#define AHA1640_BIOS_PATH L"scsi/adaptec/aha1640.bin" + + enum { AHA_154xB, AHA_154xC, @@ -73,12 +80,12 @@ enum { }; -#define CMD_WRITE_EEPROM 0x22 /* UNDOC: Write EEPROM */ -#define CMD_READ_EEPROM 0x23 /* UNDOC: Read EEPROM */ +#define CMD_WR_EEPROM 0x22 /* UNDOC: Write EEPROM */ +#define CMD_RD_EEPROM 0x23 /* UNDOC: Read EEPROM */ #define CMD_SHADOW_RAM 0x24 /* UNDOC: BIOS shadow ram */ #define CMD_BIOS_MBINIT 0x25 /* UNDOC: BIOS mailbox initialization */ -#define CMD_MEMORY_MAP_1 0x26 /* UNDOC: Memory Mapper */ -#define CMD_MEMORY_MAP_2 0x27 /* UNDOC: Memory Mapper */ +#define CMD_MEM_MAP_1 0x26 /* UNDOC: Memory Mapper */ +#define CMD_MEM_MAP_2 0x27 /* UNDOC: Memory Mapper */ #define CMD_EXTBIOS 0x28 /* UNDOC: return extended BIOS info */ #define CMD_MBENABLE 0x29 /* set mailbox interface enable */ #define CMD_BIOS_SCSI 0x82 /* start ROM BIOS SCSI command */ @@ -114,8 +121,6 @@ aha_log(const char *fmt, ...) va_list ap; if (aha_do_log) { -// for debug, temporary -pclog("In %s mode: ",(msw&1)?((eflags&VM_FLAG)?"V86":"protected"):"real"); va_start(ap, fmt); pclog_ex(fmt, ap); va_end(ap); @@ -135,7 +140,7 @@ pclog("In %s mode: ",(msw&1)?((eflags&VM_FLAG)?"V86":"protected"):"real"); * We enable/disable this memory through AHA command 0x24. */ static void -aha_mem_write(uint32_t addr, uint8_t val, void *priv) +mem_write(uint32_t addr, uint8_t val, void *priv) { x54x_t *dev = (x54x_t *)priv; @@ -147,7 +152,7 @@ aha_mem_write(uint32_t addr, uint8_t val, void *priv) static uint8_t -aha_mem_read(uint32_t addr, void *priv) +mem_read(uint32_t addr, void *priv) { x54x_t *dev = (x54x_t *)priv; rom_t *rom = &dev->bios; @@ -162,7 +167,7 @@ aha_mem_read(uint32_t addr, void *priv) static uint8_t -aha154x_shram(x54x_t *dev, uint8_t cmd) +shram_cmd(x54x_t *dev, uint8_t cmd) { /* If not supported, give up. */ if (dev->rom_shram == 0x0000) return(0x04); @@ -177,13 +182,12 @@ aha154x_shram(x54x_t *dev, uint8_t cmd) static void -aha_eeprom_save(x54x_t *dev) +eeprom_save(x54x_t *dev) { FILE *f; - f = nvr_fopen(dev->nvr_path, L"wb"); - if (f) - { + f = plat_fopen(nvr_path(dev->nvr_path), L"wb"); + if (f != NULL) { fwrite(dev->nvr, 1, NVR_SIZE, f); fclose(f); f = NULL; @@ -192,7 +196,7 @@ aha_eeprom_save(x54x_t *dev) static uint8_t -aha154x_eeprom(x54x_t *dev, uint8_t cmd,uint8_t arg,uint8_t len,uint8_t off,uint8_t *bufp) +eeprom_cmd(x54x_t *dev, uint8_t cmd,uint8_t arg,uint8_t len,uint8_t off,uint8_t *bufp) { uint8_t r = 0xff; int c; @@ -209,7 +213,7 @@ aha154x_eeprom(x54x_t *dev, uint8_t cmd,uint8_t arg,uint8_t len,uint8_t off,uint dev->nvr[(off + c) & 0xff] = bufp[c]; r = 0; - aha_eeprom_save(dev); + eeprom_save(dev); } if (cmd == 0x23) { @@ -225,7 +229,7 @@ aha154x_eeprom(x54x_t *dev, uint8_t cmd,uint8_t arg,uint8_t len,uint8_t off,uint /* Map either the main or utility (Select) ROM into the memory space. */ static uint8_t -aha154x_mmap(x54x_t *dev, uint8_t cmd) +mmap_cmd(x54x_t *dev, uint8_t cmd) { aha_log("%s: MEMORY cmd=%02x\n", dev->name, cmd); @@ -246,211 +250,208 @@ aha154x_mmap(x54x_t *dev, uint8_t cmd) static uint8_t -aha_get_host_id(void *p) +get_host_id(void *p) { x54x_t *dev = (x54x_t *)p; - return dev->nvr[0] & 0x07; + return(dev->nvr[0] & 0x07); } static uint8_t -aha_get_irq(void *p) +get_irq(void *p) { x54x_t *dev = (x54x_t *)p; - return (dev->nvr[1] & 0x07) + 9; + return((dev->nvr[1] & 0x07) + 9); } static uint8_t -aha_get_dma(void *p) +get_dma(void *p) { x54x_t *dev = (x54x_t *)p; - return (dev->nvr[1] >> 4) & 0x07; + return((dev->nvr[1] >> 4) & 0x07); } static uint8_t -aha_cmd_is_fast(void *p) +cmd_is_fast(void *p) { x54x_t *dev = (x54x_t *)p; if (dev->Command == CMD_BIOS_SCSI) - return 1; - else - return 0; + return(1); + + return(0); } static uint8_t -aha_fast_cmds(void *p, uint8_t cmd) +fast_cmds(void *p, uint8_t cmd) { x54x_t *dev = (x54x_t *)p; if (cmd == CMD_BIOS_SCSI) { dev->BIOSMailboxReq++; - return 1; + return(1); } - return 0; + return(0); } static uint8_t -aha_param_len(void *p) +param_len(void *p) { x54x_t *dev = (x54x_t *)p; switch (dev->Command) { case CMD_BIOS_MBINIT: /* Same as 0x01 for AHA. */ - return sizeof(MailboxInit_t); + return(sizeof(MailboxInit_t)); break; case CMD_SHADOW_RAM: - return 1; + return(1); break; - case CMD_WRITE_EEPROM: - return 3+32; + case CMD_WR_EEPROM: + return(3+32); break; - case CMD_READ_EEPROM: - return 3; + case CMD_RD_EEPROM: + return(3); case CMD_MBENABLE: - return 2; + return(2); default: - return 0; + break; } + + return(0); } static uint8_t -aha_cmds(void *p) +aha_cmds(void *priv) { - x54x_t *dev = (x54x_t *)p; + x54x_t *dev = (x54x_t *)priv; MailboxInit_t *mbi; - if (! dev->CmdParamLeft) { - aha_log("Running Operation Code 0x%02X\n", dev->Command); - switch (dev->Command) { - case CMD_WRITE_EEPROM: /* write EEPROM */ - /* Sent by CF BIOS. */ - dev->DataReplyLeft = - aha154x_eeprom(dev, - dev->Command, - dev->CmdBuf[0], - dev->CmdBuf[1], - dev->CmdBuf[2], - &(dev->CmdBuf[3])); - if (dev->DataReplyLeft == 0xff) { - dev->DataReplyLeft = 0; - dev->Status |= STAT_INVCMD; - } - break; + if (dev->CmdParamLeft) return(0); - case CMD_READ_EEPROM: /* read EEPROM */ - /* Sent by CF BIOS. */ - dev->DataReplyLeft = - aha154x_eeprom(dev, - dev->Command, - dev->CmdBuf[0], - dev->CmdBuf[1], - dev->CmdBuf[2], - dev->DataBuf); - if (dev->DataReplyLeft == 0xff) { - dev->DataReplyLeft = 0; - dev->Status |= STAT_INVCMD; - } - break; - - case CMD_SHADOW_RAM: /* Shadow RAM */ - /* - * For AHA1542CF, this is the command - * to play with the Shadow RAM. BIOS - * gives us one argument (00,02,03) - * and expects a 0x04 back in the INTR - * register. --FvK - */ - /* dev->Interrupt = aha154x_shram(dev,val); */ - dev->Interrupt = aha154x_shram(dev, dev->CmdBuf[0]); - break; - - case CMD_BIOS_MBINIT: /* BIOS Mailbox Initialization */ - /* Sent by CF BIOS. */ - dev->Mbx24bit = 1; - - mbi = (MailboxInit_t *)dev->CmdBuf; - - dev->BIOSMailboxInit = 1; - dev->BIOSMailboxCount = mbi->Count; - dev->BIOSMailboxOutAddr = ADDR_TO_U32(mbi->Address); - - aha_log("Initialize BIOS Mailbox: MBO=0x%08lx, %d entries at 0x%08lx\n", - dev->BIOSMailboxOutAddr, - mbi->Count, - ADDR_TO_U32(mbi->Address)); - - dev->Status &= ~STAT_INIT; - dev->DataReplyLeft = 0; - break; - - case CMD_MEMORY_MAP_1: /* AHA memory mapper */ - case CMD_MEMORY_MAP_2: /* AHA memory mapper */ - /* Sent by CF BIOS. */ - dev->DataReplyLeft = - aha154x_mmap(dev, dev->Command); - break; - - case CMD_EXTBIOS: /* Return extended BIOS information */ - dev->DataBuf[0] = 0x08; - dev->DataBuf[1] = dev->Lock; - dev->DataReplyLeft = 2; - break; - - case CMD_MBENABLE: /* Mailbox interface enable Command */ - dev->DataReplyLeft = 0; - if (dev->CmdBuf[1] == dev->Lock) { - if (dev->CmdBuf[0] & 1) { - dev->Lock = 1; - } else { - dev->Lock = 0; - } - } - break; - - case 0x2C: /* AHA-1542CP sends this */ - dev->DataBuf[0] = 0x00; - dev->DataReplyLeft = 1; - break; - - case 0x33: /* AHA-1542CP sends this */ - dev->DataBuf[0] = 0x00; - dev->DataBuf[1] = 0x00; - dev->DataBuf[2] = 0x00; - dev->DataBuf[3] = 0x00; - dev->DataReplyLeft = 256; - break; - - default: + aha_log("Running Operation Code 0x%02X\n", dev->Command); + switch (dev->Command) { + case CMD_WR_EEPROM: /* write EEPROM */ + /* Sent by CF BIOS. */ + dev->DataReplyLeft = eeprom_cmd(dev, + dev->Command, + dev->CmdBuf[0], + dev->CmdBuf[1], + dev->CmdBuf[2], + &(dev->CmdBuf[3])); + if (dev->DataReplyLeft == 0xff) { dev->DataReplyLeft = 0; dev->Status |= STAT_INVCMD; - break; - } + } + break; + + case CMD_RD_EEPROM: /* read EEPROM */ + /* Sent by CF BIOS. */ + dev->DataReplyLeft = eeprom_cmd(dev, + dev->Command, + dev->CmdBuf[0], + dev->CmdBuf[1], + dev->CmdBuf[2], + dev->DataBuf); + if (dev->DataReplyLeft == 0xff) { + dev->DataReplyLeft = 0; + dev->Status |= STAT_INVCMD; + } + break; + + case CMD_SHADOW_RAM: /* Shadow RAM */ + /* + * For AHA1542CF, this is the command + * to play with the Shadow RAM. BIOS + * gives us one argument (00,02,03) + * and expects a 0x04 back in the INTR + * register. --FvK + */ + dev->Interrupt = shram_cmd(dev, dev->CmdBuf[0]); + break; + + case CMD_BIOS_MBINIT: /* BIOS Mailbox Initialization */ + /* Sent by CF BIOS. */ + dev->Mbx24bit = 1; + + mbi = (MailboxInit_t *)dev->CmdBuf; + + dev->BIOSMailboxInit = 1; + dev->BIOSMailboxCount = mbi->Count; + dev->BIOSMailboxOutAddr = ADDR_TO_U32(mbi->Address); + + aha_log("Initialize BIOS Mailbox: MBO=0x%08lx, %d entries at 0x%08lx\n", + dev->BIOSMailboxOutAddr, + mbi->Count, + ADDR_TO_U32(mbi->Address)); + + dev->Status &= ~STAT_INIT; + dev->DataReplyLeft = 0; + break; + + case CMD_MEM_MAP_1: /* AHA memory mapper */ + case CMD_MEM_MAP_2: /* AHA memory mapper */ + /* Sent by CF BIOS. */ + dev->DataReplyLeft = mmap_cmd(dev, dev->Command); + break; + + case CMD_EXTBIOS: /* Return extended BIOS information */ + dev->DataBuf[0] = 0x08; + dev->DataBuf[1] = dev->Lock; + dev->DataReplyLeft = 2; + break; + + case CMD_MBENABLE: /* Mailbox interface enable Command */ + dev->DataReplyLeft = 0; + if (dev->CmdBuf[1] == dev->Lock) { + if (dev->CmdBuf[0] & 1) + dev->Lock = 1; + else + dev->Lock = 0; + } + break; + + case 0x2c: /* AHA-1542CP sends this */ + dev->DataBuf[0] = 0x00; + dev->DataReplyLeft = 1; + break; + + case 0x33: /* AHA-1542CP sends this */ + dev->DataBuf[0] = 0x00; + dev->DataBuf[1] = 0x00; + dev->DataBuf[2] = 0x00; + dev->DataBuf[3] = 0x00; + dev->DataReplyLeft = 256; + break; + + default: + dev->DataReplyLeft = 0; + dev->Status |= STAT_INVCMD; + break; } - return 0; + return(0); } static void -aha_setup_data(void *p) +setup_data(void *priv) { - x54x_t *dev = (x54x_t *)p; + x54x_t *dev = (x54x_t *)priv; ReplyInquireSetupInformation *ReplyISI; aha_setup_t *aha_setup; @@ -461,17 +462,17 @@ aha_setup_data(void *p) ReplyISI->fParityCheckingEnabled = dev->parity & 1; U32_TO_ADDR(aha_setup->BIOSMailboxAddress, dev->BIOSMailboxOutAddr); - aha_setup->uChecksum = 0xA3; - aha_setup->uUnknown = 0xC2; + aha_setup->uChecksum = 0xa3; + aha_setup->uUnknown = 0xc2; } static void -aha_do_bios_mail(x54x_t *dev) +do_bios_mail(x54x_t *dev) { dev->MailboxIsBIOS = 1; - if (!dev->BIOSMailboxCount) { + if (! dev->BIOSMailboxCount) { aha_log("aha_do_bios_mail(): No BIOS Mailboxes\n"); return; } @@ -485,12 +486,12 @@ aha_do_bios_mail(x54x_t *dev) static void -aha_callback(void *p) +call_back(void *priv) { - x54x_t *dev = (x54x_t *)p; + x54x_t *dev = (x54x_t *)priv; if (dev->BIOSMailboxInit && dev->BIOSMailboxReq) - aha_do_bios_mail(dev); + do_bios_mail(dev); } @@ -528,27 +529,27 @@ aha_mca_write(int port, uint8_t val, void *priv) /* Extract the BIOS ROM address info. */ if (! (dev->pos_regs[2] & 0x80)) switch(dev->pos_regs[3] & 0x38) { case 0x38: /* [1]=xx11 1xxx */ - dev->rom_addr = 0xDC000; + dev->rom_addr = 0xdc000; break; case 0x30: /* [1]=xx11 0xxx */ - dev->rom_addr = 0xD8000; + dev->rom_addr = 0xd8000; break; case 0x28: /* [1]=xx10 1xxx */ - dev->rom_addr = 0xD4000; + dev->rom_addr = 0xd4000; break; case 0x20: /* [1]=xx10 0xxx */ - dev->rom_addr = 0xD0000; + dev->rom_addr = 0xd0000; break; case 0x18: /* [1]=xx01 1xxx */ - dev->rom_addr = 0xCC000; + dev->rom_addr = 0xcc000; break; case 0x10: /* [1]=xx01 0xxx */ - dev->rom_addr = 0xC8000; + dev->rom_addr = 0xc8000; break; } else { /* Disabled. */ @@ -604,7 +605,7 @@ aha_mca_write(int port, uint8_t val, void *priv) /* Initialize the board's ROM BIOS. */ static void -aha_setbios(x54x_t *dev) +set_bios(x54x_t *dev) { uint32_t size; uint32_t mask; @@ -617,7 +618,7 @@ aha_setbios(x54x_t *dev) /* Open the BIOS image file and make sure it exists. */ aha_log("%s: loading BIOS from '%ls'\n", dev->name, dev->bios_path); - if ((f = rom_fopen(dev->bios_path)) == NULL) { + if ((f = plat_fopen(rom_path(dev->bios_path), L"rb")) == NULL) { aha_log("%s: BIOS ROM not found!\n", dev->name); return; } @@ -680,8 +681,8 @@ aha_setbios(x54x_t *dev) /* Map this system into the memory map. */ mem_mapping_add(&dev->bios.mapping, dev->rom_addr, size, - aha_mem_read, NULL, NULL, /* aha_mem_readw, aha_mem_readl, */ - aha_mem_write, NULL, NULL, + mem_read, NULL, NULL, /* aha_mem_readw, aha_mem_readl, */ + mem_write, NULL, NULL, dev->bios.rom, MEM_MAPPING_EXTERNAL, dev); mem_mapping_disable(&dev->bios.mapping); @@ -704,6 +705,7 @@ aha_setbios(x54x_t *dev) return; } dev->bios.rom[dev->rom_ioaddr] = (uint8_t)i; + /* Negation of the DIP switches to satify the checksum. */ dev->bios.rom[dev->rom_ioaddr + 1] = (uint8_t)((i ^ 0xff) + 1); } @@ -711,7 +713,7 @@ aha_setbios(x54x_t *dev) static void -aha_initnvr(x54x_t *dev) +init_nvr(x54x_t *dev) { /* Initialize the on-board EEPROM. */ dev->nvr[0] = dev->HostID; /* SCSI ID 7 */ @@ -729,7 +731,7 @@ aha_initnvr(x54x_t *dev) /* Initialize the board's EEPROM (NVR.) */ static void -aha_setnvr(x54x_t *dev) +set_nvr(x54x_t *dev) { FILE *f; @@ -740,13 +742,13 @@ aha_setnvr(x54x_t *dev) dev->nvr = (uint8_t *)malloc(NVR_SIZE); memset(dev->nvr, 0x00, NVR_SIZE); - f = nvr_fopen(dev->nvr_path, L"rb"); + f = plat_fopen(nvr_path(dev->nvr_path), L"rb"); if (f != NULL) { - fread(dev->nvr, 1, NVR_SIZE, f); + (void)fread(dev->nvr, 1, NVR_SIZE, f); fclose(f); f = NULL; } else { - aha_initnvr(dev); + init_nvr(dev); } } @@ -779,12 +781,12 @@ aha_init(const device_t *info) dev->bit32 = 0; dev->lba_bios = 0; - dev->ven_callback = aha_callback; - dev->ven_cmd_is_fast = aha_cmd_is_fast; - dev->ven_fast_cmds = aha_fast_cmds; - dev->get_ven_param_len = aha_param_len; + dev->ven_callback = call_back; + dev->ven_cmd_is_fast = cmd_is_fast; + dev->ven_fast_cmds = fast_cmds; + dev->get_ven_param_len = param_len; dev->ven_cmds = aha_cmds; - dev->get_ven_data = aha_setup_data; + dev->get_ven_data = setup_data; strcpy(dev->vendor, "Adaptec"); @@ -794,88 +796,86 @@ aha_init(const device_t *info) strcpy(dev->name, "AHA-154xB"); switch(dev->Base) { case 0x0330: - dev->bios_path = - L"roms/scsi/adaptec/aha1540b320_330.bin"; + dev->bios_path = AHA1540B_330_BIOS_PATH; break; case 0x0334: - dev->bios_path = - L"roms/scsi/adaptec/aha1540b320_334.bin"; + dev->bios_path = AHA1540B_334_BIOS_PATH; break; } dev->fw_rev = "A005"; /* The 3.2 microcode says A012. */ dev->HostID = device_get_config_int("hostid"); - dev->rom_shram = 0x3F80; /* shadow RAM address base */ + dev->rom_shram = 0x3f80; /* shadow RAM address base */ dev->rom_shramsz = 128; /* size of shadow RAM */ dev->ha_bps = 5000000.0; /* normal SCSI */ break; case AHA_154xC: strcpy(dev->name, "AHA-154xC"); - dev->bios_path = L"roms/scsi/adaptec/aha1542c102.bin"; + dev->bios_path = AHA1540C_BIOS_PATH; dev->nvr_path = L"aha1542c.nvr"; dev->fw_rev = "D001"; - dev->rom_shram = 0x3F80; /* shadow RAM address base */ + dev->rom_shram = 0x3f80; /* shadow RAM address base */ dev->rom_shramsz = 128; /* size of shadow RAM */ - dev->rom_ioaddr = 0x3F7E; /* [2:0] idx into addr table */ + dev->rom_ioaddr = 0x3f7e; /* [2:0] idx into addr table */ dev->rom_fwhigh = 0x0022; /* firmware version (hi/lo) */ - dev->ven_get_host_id = aha_get_host_id; /* function to return host ID from EEPROM */ - dev->ven_get_irq = aha_get_irq; /* function to return IRQ from EEPROM */ - dev->ven_get_dma = aha_get_dma; /* function to return DMA channel from EEPROM */ + dev->ven_get_host_id = get_host_id; /* function to return host ID from EEPROM */ + dev->ven_get_irq = get_irq; /* function to return IRQ from EEPROM */ + dev->ven_get_dma = get_dma; /* function to return DMA channel from EEPROM */ dev->ha_bps = 5000000.0; /* normal SCSI */ break; case AHA_154xCF: strcpy(dev->name, "AHA-154xCF"); - dev->bios_path = L"roms/scsi/adaptec/aha1542cf211.bin"; + dev->bios_path = AHA1540CF_BIOS_PATH; dev->nvr_path = L"aha1542cf.nvr"; dev->fw_rev = "E001"; - dev->rom_shram = 0x3F80; /* shadow RAM address base */ + dev->rom_shram = 0x3f80; /* shadow RAM address base */ dev->rom_shramsz = 128; /* size of shadow RAM */ - dev->rom_ioaddr = 0x3F7E; /* [2:0] idx into addr table */ + dev->rom_ioaddr = 0x3f7e; /* [2:0] idx into addr table */ dev->rom_fwhigh = 0x0022; /* firmware version (hi/lo) */ dev->cdrom_boot = 1; - dev->ven_get_host_id = aha_get_host_id; /* function to return host ID from EEPROM */ - dev->ven_get_irq = aha_get_irq; /* function to return IRQ from EEPROM */ - dev->ven_get_dma = aha_get_dma; /* function to return DMA channel from EEPROM */ + dev->ven_get_host_id = get_host_id; /* function to return host ID from EEPROM */ + dev->ven_get_irq = get_irq; /* function to return IRQ from EEPROM */ + dev->ven_get_dma = get_dma; /* function to return DMA channel from EEPROM */ dev->ha_bps = 10000000.0; /* fast SCSI */ break; case AHA_154xCP: strcpy(dev->name, "AHA-154xCP"); - dev->bios_path = L"roms/scsi/adaptec/aha1542cp102.bin"; + dev->bios_path = AHA1540CP_BIOS_PATH; dev->nvr_path = L"aha1540cp.nvr"; dev->fw_rev = "F001"; - dev->rom_shram = 0x3F80; /* shadow RAM address base */ + dev->rom_shram = 0x3f80; /* shadow RAM address base */ dev->rom_shramsz = 128; /* size of shadow RAM */ - dev->rom_ioaddr = 0x3F7E; /* [2:0] idx into addr table */ + dev->rom_ioaddr = 0x3f7e; /* [2:0] idx into addr table */ dev->rom_fwhigh = 0x0055; /* firmware version (hi/lo) */ - dev->ven_get_host_id = aha_get_host_id; /* function to return host ID from EEPROM */ - dev->ven_get_irq = aha_get_irq; /* function to return IRQ from EEPROM */ - dev->ven_get_dma = aha_get_dma; /* function to return DMA channel from EEPROM */ + dev->ven_get_host_id = get_host_id; /* function to return host ID from EEPROM */ + dev->ven_get_irq = get_irq; /* function to return IRQ from EEPROM */ + dev->ven_get_dma = get_dma; /* function to return DMA channel from EEPROM */ dev->ha_bps = 10000000.0; /* fast SCSI */ break; case AHA_1640: strcpy(dev->name, "AHA-1640"); - dev->bios_path = L"roms/scsi/adaptec/aha1640.bin"; + dev->bios_path = AHA1640_BIOS_PATH; dev->fw_rev = "BB01"; dev->lba_bios = 1; /* Enable MCA. */ - dev->pos_regs[0] = 0x1F; /* MCA board ID */ - dev->pos_regs[1] = 0x0F; + dev->pos_regs[0] = 0x1f; /* MCA board ID */ + dev->pos_regs[1] = 0x0f; mca_add(aha_mca_read, aha_mca_write, dev); dev->ha_bps = 5000000.0; /* normal SCSI */ break; } /* Initialize ROM BIOS if needed. */ - aha_setbios(dev); + set_bios(dev); /* Initialize EEPROM (NVR) if needed. */ - aha_setnvr(dev); + set_nvr(dev); if (dev->Base != 0) { /* Initialize the device. */ diff --git a/src/scsi/scsi_buslogic.c b/src/scsi/scsi_buslogic.c index e5f09f9..07d7d05 100644 --- a/src/scsi/scsi_buslogic.c +++ b/src/scsi/scsi_buslogic.c @@ -13,7 +13,7 @@ * 1 - BT-545S ISA; * 2 - BT-958D PCI * - * Version: @(#)scsi_buslogic.c 1.0.7 2018/03/27 + * Version: @(#)scsi_buslogic.c 1.0.8 2018/03/31 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -66,6 +66,17 @@ #include "scsi_x54x.h" +#define BT542_BIOS_PATH L"scsi/buslogic/bt-542bh_bios.rom" +#define BT545_BIOS_PATH L"scsi/buslogic/bt-545s_bios.rom" +#define BT545_AUTO_BIOS_PATH L"scsi/buslogic/bt-545s_autoscsi.rom" +#define BT640A_BIOS_PATH L"scsi/buslogic/bt-640a_bios.rom" +#define BT445S_BIOS_PATH L"scsi/buslogic/bt-445s_bios.rom" +#define BT445S_AUTO_BIOS_PATH L"scsi/buslogic/bt-445s_autoscsi.rom" +#define BT958D_BIOS_PATH L"scsi/buslogic/bt-958d_bios.rom" +#define BT958D_AUTO_BIOS_PATH L"scsi/buslogic/bt-958d_autoscsi.rom" +#define BT958D_SCAM_BIOS_PATH L"scsi/buslogic/bt-958d_scam.rom" + + /* * Auto SCSI structure which is located * in host adapter RAM and contains several @@ -77,15 +88,15 @@ typedef struct { uint8_t cbInformation; uint8_t aHostAdaptertype[6]; uint8_t uReserved1; - uint8_t fFloppyEnabled :1, - fFloppySecondary :1, - fLevelSensitiveInterrupt:1, - uReserved2 :2, - uSystemRAMAreForBIOS :3; - uint8_t uDMAChannel :7, - fDMAAutoConfiguration :1, - uIrqChannel :7, - fIrqAutoConfiguration :1; + uint8_t fFloppyEnabled : 1, + fFloppySecondary : 1, + fLevelSensitiveInterrupt : 1, + uReserved2 : 2, + uSystemRAMAreForBIOS : 3; + uint8_t uDMAChannel : 7, + fDMAAutoConfiguration : 1, + uIrqChannel : 7, + fIrqAutoConfiguration : 1; uint8_t uDMATransferRate; uint8_t uSCSIId; uint8_t uSCSIConfiguration; @@ -99,36 +110,36 @@ typedef struct { uint16_t u16DisconnectPermittedMask; uint16_t u16SendStartUnitCommandMask; uint16_t u16IgnoreInBIOSScanMask; - unsigned char uPCIInterruptPin : 2; - unsigned char uHostAdapterIoPortAddress : 2; - uint8_t fRoundRobinScheme : 1; - uint8_t fVesaBusSpeedGreaterThan33MHz : 1; - uint8_t fVesaBurstWrite : 1; - uint8_t fVesaBurstRead : 1; - uint16_t u16UltraPermittedMask; - uint32_t uReserved5; - uint8_t uReserved6; - uint8_t uAutoSCSIMaximumLUN; - uint8_t fReserved7 : 1; - uint8_t fSCAMDominant : 1; - uint8_t fSCAMenabled : 1; - uint8_t fSCAMLevel2 : 1; - unsigned char uReserved8 : 4; - uint8_t fInt13Extension : 1; - uint8_t fReserved9 : 1; - uint8_t fCDROMBoot : 1; - unsigned char uReserved10 : 2; - uint8_t fMultiBoot : 1; - unsigned char uReserved11 : 2; - unsigned char uBootTargetId : 4; - unsigned char uBootChannel : 4; - uint8_t fForceBusDeviceScanningOrder : 1; - unsigned char uReserved12 : 7; - uint16_t u16NonTaggedToAlternateLunPermittedMask; - uint16_t u16RenegotiateSyncAfterCheckConditionMask; - uint8_t aReserved14[10]; - uint8_t aManufacturingDiagnostic[2]; - uint16_t u16Checksum; + uint8_t uPCIInterruptPin : 2, + uHostAdapterIoPortAddress : 2, + fRoundRobinScheme : 1, + fVesaBusSpeedGreaterThan33MHz : 1, + fVesaBurstWrite : 1, + fVesaBurstRead : 1; + uint16_t u16UltraPermittedMask; + uint32_t uReserved5; + uint8_t uReserved6; + uint8_t uAutoSCSIMaximumLUN; + uint8_t fReserved7 : 1, + fSCAMDominant : 1, + fSCAMenabled : 1, + fSCAMLevel2 : 1, + uReserved8 : 4; + uint8_t fInt13Extension : 1, + fReserved9 : 1, + fCDROMBoot : 1, + uReserved10 : 2, + fMultiBoot : 1, + uReserved11 : 2; + uint8_t uBootTargetId : 4, + uBootChannel : 4; + uint8_t fForceBusDeviceScanningOrder : 1, + uReserved12 : 7; + uint16_t u16NonTaggedToAlternateLunPermittedMask; + uint16_t u16RenegotiateSyncAfterCheckConditionMask; + uint8_t aReserved14[10]; + uint8_t aManufacturingDiagnostic[2]; + uint16_t u16Checksum; } AutoSCSIRam; #pragma pack(pop) @@ -199,26 +210,16 @@ typedef struct { #pragma pack(pop) #pragma pack(push,1) -typedef struct -{ - /** Data length. */ - uint32_t DataLength; - /** Data pointer. */ - uint32_t DataPointer; - /** The device the request is sent to. */ - uint8_t TargetId; - /** The LUN in the device. */ - uint8_t LogicalUnit; - /** Reserved */ - unsigned char Reserved1 : 3; - /** Data direction for the request. */ - unsigned char DataDirection : 2; - /** Reserved */ - unsigned char Reserved2 : 3; - /** Length of the SCSI CDB. */ - uint8_t CDBLength; - /** The SCSI CDB. (A CDB can be 12 bytes long.) */ - uint8_t CDB[12]; +typedef struct { + uint32_t DataLength; /* data length */ + uint32_t DataPointer; /* data pointer */ + uint8_t TargetId; /* device request is sent to */ + uint8_t LogicalUnit; /* LUN in the device */ + uint8_t Reserved1 : 3, /* reserved */ + DataDirection : 2, /* data direction for the request */ + Reserved2 : 3; /* reserved */ + uint8_t CDBLength; /* length of the SCSI CDB */ + uint8_t CDB[12]; /* the SCSI CDB */ } ESCMD; #pragma pack(pop) @@ -279,181 +280,198 @@ buslogic_log(const char *fmt, ...) static wchar_t * -BuslogicGetNVRFileName(buslogic_data_t *bl) +GetNVRFileName(buslogic_data_t *bl) { - switch(bl->chip) - { - case CHIP_BUSLOGIC_ISA_542: - return L"bt542bh.nvr"; - case CHIP_BUSLOGIC_ISA: - return L"bt545s.nvr"; - case CHIP_BUSLOGIC_MCA: - return L"bt640a.nvr"; - case CHIP_BUSLOGIC_VLB: - return L"bt445s.nvr"; - case CHIP_BUSLOGIC_PCI: - return L"bt958d.nvr"; - default: - fatal("Unrecognized BusLogic chip: %i\n", bl->chip); - return NULL; - } + switch(bl->chip) { + case CHIP_BUSLOGIC_ISA_542: + return L"bt542bh.nvr"; + + case CHIP_BUSLOGIC_ISA: + return L"bt545s.nvr"; + + case CHIP_BUSLOGIC_MCA: + return L"bt640a.nvr"; + + case CHIP_BUSLOGIC_VLB: + return L"bt445s.nvr"; + + case CHIP_BUSLOGIC_PCI: + return L"bt958d.nvr"; + + default: + fatal("Unrecognized BusLogic chip: %i\n", bl->chip); + return NULL; + } } static void -BuslogicAutoSCSIRamSetDefaults(x54x_t *dev, uint8_t safe) +AutoSCSIRamSetDefaults(x54x_t *dev, uint8_t safe) { buslogic_data_t *bl = (buslogic_data_t *) dev->ven_data; - HALocalRAM *HALR = &bl->LocalRAM; + HALocalRAM *halr = &bl->LocalRAM; - memset(&(HALR->structured.autoSCSIData), 0, sizeof(AutoSCSIRam)); + memset(&(halr->structured.autoSCSIData), 0, sizeof(AutoSCSIRam)); - HALR->structured.autoSCSIData.aInternalSignature[0] = 'F'; - HALR->structured.autoSCSIData.aInternalSignature[1] = 'A'; + halr->structured.autoSCSIData.aInternalSignature[0] = 'F'; + halr->structured.autoSCSIData.aInternalSignature[1] = 'A'; - HALR->structured.autoSCSIData.cbInformation = 64; + halr->structured.autoSCSIData.cbInformation = 64; - HALR->structured.autoSCSIData.uReserved1 = 6; + halr->structured.autoSCSIData.uReserved1 = 6; - HALR->structured.autoSCSIData.aHostAdaptertype[0] = ' '; - HALR->structured.autoSCSIData.aHostAdaptertype[5] = ' '; + halr->structured.autoSCSIData.aHostAdaptertype[0] = ' '; + halr->structured.autoSCSIData.aHostAdaptertype[5] = ' '; switch (bl->chip) { case CHIP_BUSLOGIC_ISA_542: - memcpy(&(HALR->structured.autoSCSIData.aHostAdaptertype[1]), "542BH", 5); + memcpy(&(halr->structured.autoSCSIData.aHostAdaptertype[1]), "542BH", 5); break; + case CHIP_BUSLOGIC_ISA: - memcpy(&(HALR->structured.autoSCSIData.aHostAdaptertype[1]), "545S", 4); + memcpy(&(halr->structured.autoSCSIData.aHostAdaptertype[1]), "545S", 4); break; + case CHIP_BUSLOGIC_MCA: - memcpy(&(HALR->structured.autoSCSIData.aHostAdaptertype[1]), "640A", 4); + memcpy(&(halr->structured.autoSCSIData.aHostAdaptertype[1]), "640A", 4); break; + case CHIP_BUSLOGIC_VLB: - memcpy(&(HALR->structured.autoSCSIData.aHostAdaptertype[1]), "445S", 4); + memcpy(&(halr->structured.autoSCSIData.aHostAdaptertype[1]), "445S", 4); break; + case CHIP_BUSLOGIC_PCI: - memcpy(&(HALR->structured.autoSCSIData.aHostAdaptertype[1]), "958D", 4); + memcpy(&(halr->structured.autoSCSIData.aHostAdaptertype[1]), "958D", 4); break; } - HALR->structured.autoSCSIData.fLevelSensitiveInterrupt = (bl->chip == CHIP_BUSLOGIC_PCI) ? 1 : 0; - HALR->structured.autoSCSIData.uSystemRAMAreForBIOS = 6; + halr->structured.autoSCSIData.fLevelSensitiveInterrupt = (bl->chip == CHIP_BUSLOGIC_PCI) ? 1 : 0; + halr->structured.autoSCSIData.uSystemRAMAreForBIOS = 6; if (bl->chip != CHIP_BUSLOGIC_PCI) { switch(dev->DmaChannel) { case 5: - HALR->structured.autoSCSIData.uDMAChannel = 1; + halr->structured.autoSCSIData.uDMAChannel = 1; break; + case 6: - HALR->structured.autoSCSIData.uDMAChannel = 2; + halr->structured.autoSCSIData.uDMAChannel = 2; break; + case 7: - HALR->structured.autoSCSIData.uDMAChannel = 3; + halr->structured.autoSCSIData.uDMAChannel = 3; break; + default: - HALR->structured.autoSCSIData.uDMAChannel = 0; + + halr->structured.autoSCSIData.uDMAChannel = 0; break; } } - HALR->structured.autoSCSIData.fDMAAutoConfiguration = (bl->chip == CHIP_BUSLOGIC_PCI) ? 0 : 1; + halr->structured.autoSCSIData.fDMAAutoConfiguration = (bl->chip == CHIP_BUSLOGIC_PCI) ? 0 : 1; if (bl->chip != CHIP_BUSLOGIC_PCI) { switch(dev->Irq) { case 9: - HALR->structured.autoSCSIData.uIrqChannel = 1; + halr->structured.autoSCSIData.uIrqChannel = 1; break; + case 10: - HALR->structured.autoSCSIData.uIrqChannel = 2; + halr->structured.autoSCSIData.uIrqChannel = 2; break; + case 11: - HALR->structured.autoSCSIData.uIrqChannel = 3; + halr->structured.autoSCSIData.uIrqChannel = 3; break; + case 12: - HALR->structured.autoSCSIData.uIrqChannel = 4; + halr->structured.autoSCSIData.uIrqChannel = 4; break; + case 14: - HALR->structured.autoSCSIData.uIrqChannel = 5; + halr->structured.autoSCSIData.uIrqChannel = 5; break; + case 15: - HALR->structured.autoSCSIData.uIrqChannel = 6; + halr->structured.autoSCSIData.uIrqChannel = 6; break; + default: - HALR->structured.autoSCSIData.uIrqChannel = 0; + halr->structured.autoSCSIData.uIrqChannel = 0; break; } } - HALR->structured.autoSCSIData.fIrqAutoConfiguration = (bl->chip == CHIP_BUSLOGIC_PCI) ? 0 : 1; + halr->structured.autoSCSIData.fIrqAutoConfiguration = (bl->chip == CHIP_BUSLOGIC_PCI) ? 0 : 1; - HALR->structured.autoSCSIData.uDMATransferRate = (bl->chip == CHIP_BUSLOGIC_PCI) ? 0 : 1; + halr->structured.autoSCSIData.uDMATransferRate = (bl->chip == CHIP_BUSLOGIC_PCI) ? 0 : 1; - HALR->structured.autoSCSIData.uSCSIId = 7; - HALR->structured.autoSCSIData.uSCSIConfiguration = 0x3F; - HALR->structured.autoSCSIData.uBusOnDelay = (bl->chip == CHIP_BUSLOGIC_PCI) ? 0 : 7; - HALR->structured.autoSCSIData.uBusOffDelay = (bl->chip == CHIP_BUSLOGIC_PCI) ? 0 : 4; - HALR->structured.autoSCSIData.uBIOSConfiguration = (bl->has_bios) ? 0x33 : 0x32; + halr->structured.autoSCSIData.uSCSIId = 7; + halr->structured.autoSCSIData.uSCSIConfiguration = 0x3F; + halr->structured.autoSCSIData.uBusOnDelay = (bl->chip == CHIP_BUSLOGIC_PCI) ? 0 : 7; + halr->structured.autoSCSIData.uBusOffDelay = (bl->chip == CHIP_BUSLOGIC_PCI) ? 0 : 4; + halr->structured.autoSCSIData.uBIOSConfiguration = (bl->has_bios) ? 0x33 : 0x32; if (!safe) - HALR->structured.autoSCSIData.uBIOSConfiguration |= 0x04; + halr->structured.autoSCSIData.uBIOSConfiguration |= 0x04; - HALR->structured.autoSCSIData.u16DeviceEnabledMask = 0xffff; - HALR->structured.autoSCSIData.u16WidePermittedMask = 0xffff; - HALR->structured.autoSCSIData.u16FastPermittedMask = 0xffff; - HALR->structured.autoSCSIData.u16DisconnectPermittedMask = 0xffff; + halr->structured.autoSCSIData.u16DeviceEnabledMask = 0xffff; + halr->structured.autoSCSIData.u16WidePermittedMask = 0xffff; + halr->structured.autoSCSIData.u16FastPermittedMask = 0xffff; + halr->structured.autoSCSIData.u16DisconnectPermittedMask = 0xffff; - HALR->structured.autoSCSIData.uPCIInterruptPin = PCI_INTA; - HALR->structured.autoSCSIData.fVesaBusSpeedGreaterThan33MHz = 1; + halr->structured.autoSCSIData.uPCIInterruptPin = PCI_INTA; + halr->structured.autoSCSIData.fVesaBusSpeedGreaterThan33MHz = 1; - HALR->structured.autoSCSIData.uAutoSCSIMaximumLUN = 7; + halr->structured.autoSCSIData.uAutoSCSIMaximumLUN = 7; - HALR->structured.autoSCSIData.fForceBusDeviceScanningOrder = 1; - HALR->structured.autoSCSIData.fInt13Extension = safe ? 0 : 1; - HALR->structured.autoSCSIData.fCDROMBoot = safe ? 0 : 1; - HALR->structured.autoSCSIData.fMultiBoot = safe ? 0 : 1; - HALR->structured.autoSCSIData.fRoundRobinScheme = safe ? 1 : 0; /* 1 = aggressive, 0 = strict */ + halr->structured.autoSCSIData.fForceBusDeviceScanningOrder = 1; + halr->structured.autoSCSIData.fInt13Extension = safe ? 0 : 1; + halr->structured.autoSCSIData.fCDROMBoot = safe ? 0 : 1; + halr->structured.autoSCSIData.fMultiBoot = safe ? 0 : 1; + halr->structured.autoSCSIData.fRoundRobinScheme = safe ? 1 : 0; /* 1 = aggressive, 0 = strict */ - HALR->structured.autoSCSIData.uHostAdapterIoPortAddress = 2; /* 0 = primary (330h), 1 = secondary (334h), 2 = disable, 3 = reserved */ + halr->structured.autoSCSIData.uHostAdapterIoPortAddress = 2; /* 0 = primary (330h), 1 = secondary (334h), 2 = disable, 3 = reserved */ } static void -BuslogicInitializeAutoSCSIRam(x54x_t *dev) +InitializeAutoSCSIRam(x54x_t *dev) { buslogic_data_t *bl = (buslogic_data_t *) dev->ven_data; - HALocalRAM *HALR = &bl->LocalRAM; + HALocalRAM *halr = &bl->LocalRAM; FILE *f; - f = nvr_fopen(BuslogicGetNVRFileName(bl), L"rb"); - if (f) - { - fread(&(bl->LocalRAM.structured.autoSCSIData), 1, 64, f); + f = plat_fopen(nvr_path(GetNVRFileName(bl)), L"rb"); + if (f != NULL) { + (void)fread(&(bl->LocalRAM.structured.autoSCSIData), 1, 64, f); fclose(f); f = NULL; if (bl->chip == CHIP_BUSLOGIC_PCI) { x54x_io_remove(dev, dev->Base, 4); - switch(HALR->structured.autoSCSIData.uHostAdapterIoPortAddress) { + switch(halr->structured.autoSCSIData.uHostAdapterIoPortAddress) { case 0: dev->Base = 0x330; break; + case 1: dev->Base = 0x334; break; + default: dev->Base = 0; break; } x54x_io_set(dev, dev->Base, 4); } - } - else - { - BuslogicAutoSCSIRamSetDefaults(dev, 0); + } else { + AutoSCSIRamSetDefaults(dev, 0); } } static void -buslogic_cmd_phase1(void *p) +cmd_phase1(void *priv) { - x54x_t *dev = (x54x_t *)p; + x54x_t *dev = (x54x_t *)priv; if ((dev->CmdParam == 2) && (dev->Command == 0x90)) { dev->CmdParamLeft = dev->CmdBuf[1]; @@ -476,63 +494,59 @@ buslogic_cmd_phase1(void *p) static uint8_t -buslogic_get_host_id(void *p) +get_host_id(void *priv) { - x54x_t *dev = (x54x_t *)p; - buslogic_data_t *bl = (buslogic_data_t *) dev->ven_data; - - HALocalRAM *HALR = &bl->LocalRAM; + x54x_t *dev = (x54x_t *)priv; + buslogic_data_t *bl = (buslogic_data_t *)dev->ven_data; + HALocalRAM *halr = &bl->LocalRAM; if (bl->chip == CHIP_BUSLOGIC_ISA_542) return dev->HostID; else - return HALR->structured.autoSCSIData.uSCSIId; + return halr->structured.autoSCSIData.uSCSIId; } static uint8_t -buslogic_get_irq(void *p) +get_irq(void *priv) { - x54x_t *dev = (x54x_t *)p; - buslogic_data_t *bl = (buslogic_data_t *) dev->ven_data; - + x54x_t *dev = (x54x_t *)priv; + buslogic_data_t *bl = (buslogic_data_t *)dev->ven_data; uint8_t bl_irq[7] = { 0, 9, 10, 11, 12, 14, 15 }; - - HALocalRAM *HALR = &bl->LocalRAM; + HALocalRAM *halr = &bl->LocalRAM; if (bl->chip == CHIP_BUSLOGIC_PCI) return dev->Irq; else - return bl_irq[HALR->structured.autoSCSIData.uIrqChannel]; + return bl_irq[halr->structured.autoSCSIData.uIrqChannel]; } static uint8_t -buslogic_get_dma(void *p) +get_dma(void *priv) { - x54x_t *dev = (x54x_t *)p; - buslogic_data_t *bl = (buslogic_data_t *) dev->ven_data; - + x54x_t *dev = (x54x_t *)priv; + buslogic_data_t *bl = (buslogic_data_t *)dev->ven_data; uint8_t bl_dma[4] = { 0, 5, 6, 7 }; - - HALocalRAM *HALR = &bl->LocalRAM; + HALocalRAM *halr = &bl->LocalRAM; if (bl->chip == CHIP_BUSLOGIC_PCI) return (dev->Base ? 7 : 0); else - return bl_dma[HALR->structured.autoSCSIData.uDMAChannel]; + return bl_dma[halr->structured.autoSCSIData.uDMAChannel]; } static uint8_t -buslogic_param_len(void *p) +param_len(void *priv) { - x54x_t *dev = (x54x_t *)p; - buslogic_data_t *bl = (buslogic_data_t *) dev->ven_data; + x54x_t *dev = (x54x_t *)priv; + buslogic_data_t *bl = (buslogic_data_t *)dev->ven_data; switch (dev->Command) { case 0x21: return 5; + case 0x25: case 0x8B: case 0x8C: @@ -541,33 +555,43 @@ buslogic_param_len(void *p) case 0x92: case 0x96: return 1; + case 0x81: return sizeof(MailboxInitExtended_t); + case 0x83: return 12; + case 0x90: case 0x91: return 2; + case 0x94: return 3; + case 0x93: /* Valid only for VLB */ return (bl->chip == CHIP_BUSLOGIC_VLB) ? 1 : 0; + case 0x95: /* Valid only for PCI */ return (bl->chip == CHIP_BUSLOGIC_PCI) ? 1 : 0; + case 0x97: /* Valid only for PCI */ case 0xA7: /* Valid only for PCI */ return (bl->chip == CHIP_BUSLOGIC_PCI) ? 10 : 0; + case 0xA8: /* Valid only for PCI */ case 0xA9: /* Valid only for PCI */ return (bl->chip == CHIP_BUSLOGIC_PCI) ? 4 : 0; default: - return 0; + break; } + + return 0; } static void -BuslogicSCSIBIOSDMATransfer(ESCMD *ESCSICmd, uint8_t TargetID, uint8_t LUN, int dir) +SCSIBIOSDMATransfer(ESCMD *ESCSICmd, uint8_t TargetID, uint8_t LUN, int dir) { uint32_t DataPointer = ESCSICmd->DataPointer; uint32_t DataLength = ESCSICmd->DataLength; @@ -576,11 +600,11 @@ BuslogicSCSIBIOSDMATransfer(ESCMD *ESCSICmd, uint8_t TargetID, uint8_t LUN, int if (ESCSICmd->DataDirection == 0x03) { /* Non-data command. */ - buslogic_log("BuslogicSCSIBIOSDMATransfer(): Non-data control byte\n"); + buslogic_log("SCSIBIOSDMATransfer(): Non-data control byte\n"); return; } - buslogic_log("BuslogicSCSIBIOSDMATransfer(): BIOS Data Buffer read: length %d, pointer 0x%04X\n", DataLength, DataPointer); + buslogic_log("SCSIBIOSDMATransfer(): BIOS Data Buffer read: length %d, pointer 0x%04X\n", DataLength, DataPointer); /* If the control byte is 0x00, it means that the transfer direction is set up by the SCSI command without checking its length, so do this procedure for both read/write commands. */ @@ -600,7 +624,7 @@ BuslogicSCSIBIOSDMATransfer(ESCMD *ESCSICmd, uint8_t TargetID, uint8_t LUN, int static void -BuslogicSCSIBIOSRequestSetup(x54x_t *dev, uint8_t *CmdBuf, uint8_t *DataInBuf, uint8_t DataReply) +SCSIBIOSRequestSetup(x54x_t *dev, uint8_t *CmdBuf, uint8_t *DataInBuf, uint8_t DataReply) { ESCMD *ESCSICmd = (ESCMD *)CmdBuf; uint32_t i; @@ -663,7 +687,7 @@ BuslogicSCSIBIOSRequestSetup(x54x_t *dev, uint8_t *CmdBuf, uint8_t *DataInBuf, u if (phase != SCSI_PHASE_STATUS) { if (phase == SCSI_PHASE_DATA_IN) scsi_device_command_phase1(ESCSICmd->TargetId, ESCSICmd->LogicalUnit); - BuslogicSCSIBIOSDMATransfer(ESCSICmd, ESCSICmd->TargetId, ESCSICmd->LogicalUnit, (phase == SCSI_PHASE_DATA_OUT)); + SCSIBIOSDMATransfer(ESCSICmd, ESCSICmd->TargetId, ESCSICmd->LogicalUnit, (phase == SCSI_PHASE_DATA_OUT)); if (phase == SCSI_PHASE_DATA_OUT) scsi_device_command_phase1(ESCSICmd->TargetId, ESCSICmd->LogicalUnit); } @@ -685,13 +709,11 @@ BuslogicSCSIBIOSRequestSetup(x54x_t *dev, uint8_t *CmdBuf, uint8_t *DataInBuf, u static uint8_t -buslogic_cmds(void *p) +buslogic_cmds(void *priv) { - x54x_t *dev = (x54x_t *)p; - buslogic_data_t *bl = (buslogic_data_t *) dev->ven_data; - - HALocalRAM *HALR = &bl->LocalRAM; - + x54x_t *dev = (x54x_t *)priv; + buslogic_data_t *bl = (buslogic_data_t *)dev->ven_data; + HALocalRAM *halr = &bl->LocalRAM; FILE *f; uint16_t TargetsPresentMask = 0; uint32_t Offset; @@ -707,37 +729,42 @@ buslogic_cmds(void *p) dev->DataReplyLeft = 0; x54x_reset_ctrl(dev, 1); break; + case 0x21: if (dev->CmdParam == 1) dev->CmdParamLeft = dev->CmdBuf[0]; dev->DataReplyLeft = 0; break; + case 0x23: memset(dev->DataBuf, 0, 8); for (i = 8; i < 15; i++) { dev->DataBuf[i-8] = 0; for (j=0; j<8; j++) { - if (scsi_device_present(i, j) && (i != buslogic_get_host_id(dev))) + if (scsi_device_present(i, j) && (i != get_host_id(dev))) dev->DataBuf[i-8] |= (1<DataReplyLeft = 8; break; + case 0x24: for (i=0; i<15; i++) { - if (scsi_device_present(i, 0) && (i != buslogic_get_host_id(dev))) + if (scsi_device_present(i, 0) && (i != get_host_id(dev))) TargetsPresentMask |= (1 << i); } dev->DataBuf[0] = TargetsPresentMask & 0xFF; dev->DataBuf[1] = TargetsPresentMask >> 8; dev->DataReplyLeft = 2; break; + case 0x25: if (dev->CmdBuf[0] == 0) dev->IrqEnabled = 0; else dev->IrqEnabled = 1; return 1; + case 0x81: dev->Mbx24bit = 0; @@ -756,19 +783,22 @@ buslogic_cmds(void *p) dev->Status &= ~STAT_INIT; dev->DataReplyLeft = 0; break; + case 0x83: if (dev->CmdParam == 12) { dev->CmdParamLeft = dev->CmdBuf[11]; buslogic_log("Execute SCSI BIOS Command: %u more bytes follow\n", dev->CmdParamLeft); } else { buslogic_log("Execute SCSI BIOS Command: received %u bytes\n", dev->CmdBuf[0]); - BuslogicSCSIBIOSRequestSetup(dev, dev->CmdBuf, dev->DataBuf, 4); + SCSIBIOSRequestSetup(dev, dev->CmdBuf, dev->DataBuf, 4); } break; + case 0x84: dev->DataBuf[0] = dev->fw_rev[4]; dev->DataReplyLeft = 1; break; + case 0x85: if (strlen(dev->fw_rev) == 6) dev->DataBuf[0] = dev->fw_rev[5]; @@ -776,6 +806,7 @@ buslogic_cmds(void *p) dev->DataBuf[0] = ' '; dev->DataReplyLeft = 1; break; + case 0x86: if (bl->chip == CHIP_BUSLOGIC_PCI) { ReplyPI = (BuslogicPCIInformation_t *) dev->DataBuf; @@ -785,21 +816,27 @@ buslogic_cmds(void *p) case 0x330: ReplyPI->IsaIOPort = 0; break; + case 0x334: ReplyPI->IsaIOPort = 1; break; + case 0x230: ReplyPI->IsaIOPort = 2; break; + case 0x234: ReplyPI->IsaIOPort = 3; break; + case 0x130: ReplyPI->IsaIOPort = 4; break; + case 0x134: ReplyPI->IsaIOPort = 5; break; + default: ReplyPI->IsaIOPort = 6; break; @@ -811,6 +848,7 @@ buslogic_cmds(void *p) dev->Status |= STAT_INVCMD; } break; + case 0x8B: /* The reply length is set by the guest and is found in the first byte of the command buffer. */ dev->DataReplyLeft = dev->CmdBuf[0]; @@ -823,10 +861,12 @@ buslogic_cmds(void *p) memcpy(dev->DataBuf, &(bl->LocalRAM.structured.autoSCSIData.aHostAdaptertype[1]), cCharsToTransfer); break; + case 0x8C: dev->DataReplyLeft = dev->CmdBuf[0]; memset(dev->DataBuf, 0, dev->DataReplyLeft); break; + case 0x8D: dev->DataReplyLeft = dev->CmdBuf[0]; ReplyIESI = (ReplyInquireExtendedSetupInformation *)dev->DataBuf; @@ -836,13 +876,15 @@ buslogic_cmds(void *p) case CHIP_BUSLOGIC_ISA_542: case CHIP_BUSLOGIC_ISA: case CHIP_BUSLOGIC_VLB: - ReplyIESI->uBusType = 'A'; /* ISA style */ + ReplyIESI->uBusType = 'A'; /* ISA style */ break; + case CHIP_BUSLOGIC_MCA: - ReplyIESI->uBusType = 'M'; /* MCA style */ + ReplyIESI->uBusType = 'M'; /* MCA style */ break; + case CHIP_BUSLOGIC_PCI: - ReplyIESI->uBusType = 'E'; /* PCI style */ + ReplyIESI->uBusType = 'E'; /* PCI style */ break; } ReplyIESI->uBiosAddress = 0xd8; @@ -857,11 +899,13 @@ buslogic_cmds(void *p) memcpy(ReplyIESI->aFirmwareRevision, &(dev->fw_rev[strlen(dev->fw_rev) - 3]), sizeof(ReplyIESI->aFirmwareRevision)); buslogic_log("Return Extended Setup Information: %d\n", dev->CmdBuf[0]); break; + case 0x8F: bl->fAggressiveRoundRobinMode = dev->CmdBuf[0] & 1; dev->DataReplyLeft = 0; break; + case 0x90: buslogic_log("Store Local RAM\n"); Offset = dev->CmdBuf[0]; @@ -870,6 +914,7 @@ buslogic_cmds(void *p) dev->DataReply = 0; break; + case 0x91: buslogic_log("Fetch Local RAM\n"); Offset = dev->CmdBuf[0]; @@ -878,12 +923,14 @@ buslogic_cmds(void *p) dev->DataReply = 0; break; + case 0x93: if (bl->chip != CHIP_BUSLOGIC_VLB) { dev->DataReplyLeft = 0; dev->Status |= STAT_INVCMD; break; } + case 0x92: if ((bl->chip == CHIP_BUSLOGIC_ISA_542) || (bl->chip == CHIP_BUSLOGIC_MCA)) { dev->DataReplyLeft = 0; @@ -896,19 +943,22 @@ buslogic_cmds(void *p) switch (dev->CmdBuf[0]) { case 0: case 2: - BuslogicAutoSCSIRamSetDefaults(dev, 0); + AutoSCSIRamSetDefaults(dev, 0); break; + case 3: - BuslogicAutoSCSIRamSetDefaults(dev, 3); + AutoSCSIRamSetDefaults(dev, 3); break; + case 1: - f = nvr_fopen(BuslogicGetNVRFileName(bl), L"wb"); - if (f) { - fwrite(&(bl->LocalRAM.structured.autoSCSIData), 1, 64, f); + f = plat_fopen(nvr_path(GetNVRFileName(bl)), L"wb"); + if (f != NULL) { + (void)fwrite(&(bl->LocalRAM.structured.autoSCSIData), 1, 64, f); fclose(f); f = NULL; } break; + default: dev->Status |= STAT_INVCMD; break; @@ -916,13 +966,15 @@ buslogic_cmds(void *p) if ((bl->chip == CHIP_BUSLOGIC_PCI) && !(dev->Status & STAT_INVCMD)) { x54x_io_remove(dev, dev->Base, 4); - switch(HALR->structured.autoSCSIData.uHostAdapterIoPortAddress) { + switch(halr->structured.autoSCSIData.uHostAdapterIoPortAddress) { case 0: dev->Base = 0x330; break; + case 1: dev->Base = 0x334; break; + default: dev->Base = 0; break; @@ -930,6 +982,7 @@ buslogic_cmds(void *p) x54x_io_set(dev, dev->Base, 4); } break; + case 0x94: if ((bl->chip == CHIP_BUSLOGIC_ISA_542) || (bl->chip == CHIP_BUSLOGIC_MCA)) { dev->DataReplyLeft = 0; @@ -949,6 +1002,7 @@ buslogic_cmds(void *p) buslogic_log("Returning AutoSCSI ROM (%04X %04X %04X %04X)\n", dev->DataBuf[0], dev->DataBuf[1], dev->DataBuf[2], dev->DataBuf[3]); } break; + case 0x95: if (bl->chip == CHIP_BUSLOGIC_PCI) { if (dev->Base != 0) @@ -965,6 +1019,7 @@ buslogic_cmds(void *p) dev->Status |= STAT_INVCMD; } break; + case 0x96: if (dev->CmdBuf[0] == 0) bl->ExtendedLUNCCBFormat = 0; @@ -973,11 +1028,13 @@ buslogic_cmds(void *p) dev->DataReplyLeft = 0; break; + case 0x97: case 0xA7: /* TODO: Actually correctly implement this whole SCSI BIOS Flash stuff. */ dev->DataReplyLeft = 0; break; + case 0xA8: if (bl->chip != CHIP_BUSLOGIC_PCI) { dev->DataReplyLeft = 0; @@ -997,6 +1054,7 @@ buslogic_cmds(void *p) dev->DataReply = 0; break; + case 0xA9: if (bl->chip != CHIP_BUSLOGIC_PCI) { dev->DataReplyLeft = 0; @@ -1017,47 +1075,51 @@ buslogic_cmds(void *p) dev->DataReply = 0; break; + default: dev->DataReplyLeft = 0; dev->Status |= STAT_INVCMD; break; } + return 0; } static void -buslogic_setup_data(void *p) +setup_data(void *priv) { - x54x_t *dev = (x54x_t *)p; + x54x_t *dev = (x54x_t *)priv; ReplyInquireSetupInformation *ReplyISI; buslogic_setup_t *bl_setup; - buslogic_data_t *bl = (buslogic_data_t *) dev->ven_data; - HALocalRAM *HALR = &bl->LocalRAM; + buslogic_data_t *bl = (buslogic_data_t *)dev->ven_data; + HALocalRAM *halr = &bl->LocalRAM; ReplyISI = (ReplyInquireSetupInformation *)dev->DataBuf; bl_setup = (buslogic_setup_t *)ReplyISI->VendorSpecificData; - ReplyISI->fSynchronousInitiationEnabled = HALR->structured.autoSCSIData.u16SynchronousPermittedMask ? 1 : 0; - ReplyISI->fParityCheckingEnabled = (HALR->structured.autoSCSIData.uSCSIConfiguration & 2) ? 1 : 0; + ReplyISI->fSynchronousInitiationEnabled = halr->structured.autoSCSIData.u16SynchronousPermittedMask ? 1 : 0; + ReplyISI->fParityCheckingEnabled = (halr->structured.autoSCSIData.uSCSIConfiguration & 2) ? 1 : 0; bl_setup->uSignature = 'B'; /* The 'D' signature prevents Buslogic's OS/2 drivers from getting too * friendly with Adaptec hardware and upsetting the HBA state. */ bl_setup->uCharacterD = 'D'; /* BusLogic model. */ - switch(bl->chip) - { + switch(bl->chip) { case CHIP_BUSLOGIC_ISA_542: case CHIP_BUSLOGIC_ISA: bl_setup->uHostBusType = 'A'; break; + case CHIP_BUSLOGIC_MCA: bl_setup->uHostBusType = 'B'; break; + case CHIP_BUSLOGIC_VLB: bl_setup->uHostBusType = 'E'; break; + case CHIP_BUSLOGIC_PCI: bl_setup->uHostBusType = 'F'; break; @@ -1066,20 +1128,20 @@ buslogic_setup_data(void *p) static uint8_t -buslogic_is_aggressive_mode(void *p) +is_aggressive_mode(void *priv) { - x54x_t *dev = (x54x_t *)p; - buslogic_data_t *bl = (buslogic_data_t *) dev->ven_data; + x54x_t *dev = (x54x_t *)priv; + buslogic_data_t *bl = (buslogic_data_t *)dev->ven_data; return bl->fAggressiveRoundRobinMode; } static uint8_t -buslogic_interrupt_type(void *p) +interrupt_type(void *priv) { - x54x_t *dev = (x54x_t *)p; - buslogic_data_t *bl = (buslogic_data_t *) dev->ven_data; + x54x_t *dev = (x54x_t *)priv; + buslogic_data_t *bl = (buslogic_data_t *)dev->ven_data; if ((bl->chip == CHIP_BUSLOGIC_ISA_542) || (bl->chip == CHIP_BUSLOGIC_MCA)) return 0; @@ -1089,10 +1151,10 @@ buslogic_interrupt_type(void *p) static void -buslogic_reset(void *p) +buslogic_reset(void *priv) { - x54x_t *dev = (x54x_t *)p; - buslogic_data_t *bl = (buslogic_data_t *) dev->ven_data; + x54x_t *dev = (x54x_t *)priv; + buslogic_data_t *bl = (buslogic_data_t *)dev->ven_data; bl->ExtendedLUNCCBFormat = 0; } @@ -1103,7 +1165,7 @@ bar_t buslogic_pci_bar[3]; static void -BuslogicBIOSUpdate(buslogic_data_t *bl) +BIOSUpdate(buslogic_data_t *bl) { int bios_enabled = buslogic_pci_bar[2].addr_regs[0] & 0x01; @@ -1123,80 +1185,108 @@ BuslogicBIOSUpdate(buslogic_data_t *bl) } } + static uint8_t -BuslogicPCIRead(int func, int addr, void *p) +PCIRead(int func, int addr, void *priv) { - x54x_t *dev = (x54x_t *)p; - buslogic_data_t *bl = (buslogic_data_t *) dev->ven_data; + x54x_t *dev = (x54x_t *)priv; + buslogic_data_t *bl = (buslogic_data_t *)dev->ven_data; buslogic_log("BT-958D: Reading register %02X\n", addr & 0xff); switch (addr) { case 0x00: return 0x4b; + case 0x01: return 0x10; + case 0x02: return 0x40; + case 0x03: return 0x10; + case 0x04: return buslogic_pci_regs[0x04] & 0x03; /*Respond to IO and memory accesses*/ + case 0x05: return 0; + case 0x07: return 2; + case 0x08: return 1; /*Revision ID*/ + case 0x09: return 0; /*Programming interface*/ + case 0x0A: return 0; /*Subclass*/ + case 0x0B: return 1; /*Class code*/ + case 0x0E: return 0; /*Header type */ + case 0x10: return (buslogic_pci_bar[0].addr_regs[0] & 0xe0) | 1; /*I/O space*/ + case 0x11: return buslogic_pci_bar[0].addr_regs[1]; + case 0x12: return buslogic_pci_bar[0].addr_regs[2]; + case 0x13: return buslogic_pci_bar[0].addr_regs[3]; + case 0x14: return (buslogic_pci_bar[1].addr_regs[0] & 0xe0); /*Memory space*/ + case 0x15: return buslogic_pci_bar[1].addr_regs[1]; + case 0x16: return buslogic_pci_bar[1].addr_regs[2]; + case 0x17: return buslogic_pci_bar[1].addr_regs[3]; + case 0x2C: return 0x4b; + case 0x2D: return 0x10; + case 0x2E: return 0x40; + case 0x2F: return 0x10; + case 0x30: /* PCI_ROMBAR */ buslogic_log("BT-958D: BIOS BAR 00 = %02X\n", buslogic_pci_bar[2].addr_regs[0] & 0x01); return buslogic_pci_bar[2].addr_regs[0] & 0x01; + + case 0x31: /* PCI_ROMBAR 15:11 */ buslogic_log("BT-958D: BIOS BAR 01 = %02X\n", (buslogic_pci_bar[2].addr_regs[1] & bl->bios_mask)); return buslogic_pci_bar[2].addr_regs[1]; - break; + case 0x32: /* PCI_ROMBAR 23:16 */ buslogic_log("BT-958D: BIOS BAR 02 = %02X\n", buslogic_pci_bar[2].addr_regs[2]); return buslogic_pci_bar[2].addr_regs[2]; - break; + case 0x33: /* PCI_ROMBAR 31:24 */ buslogic_log("BT-958D: BIOS BAR 03 = %02X\n", buslogic_pci_bar[2].addr_regs[3]); return buslogic_pci_bar[2].addr_regs[3]; - break; + case 0x3C: return dev->Irq; + case 0x3D: return PCI_INTA; } @@ -1206,11 +1296,10 @@ BuslogicPCIRead(int func, int addr, void *p) static void -BuslogicPCIWrite(int func, int addr, uint8_t val, void *p) +PCIWrite(int func, int addr, uint8_t val, void *priv) { - x54x_t *dev = (x54x_t *)p; - buslogic_data_t *bl = (buslogic_data_t *) dev->ven_data; - + x54x_t *dev = (x54x_t *)priv; + buslogic_data_t *bl = (buslogic_data_t *)dev->ven_data; uint8_t valxor; buslogic_log("BT-958D: Write value %02X to register %02X\n", val, addr & 0xff); @@ -1284,7 +1373,7 @@ BuslogicPCIWrite(int func, int addr, uint8_t val, void *p) buslogic_pci_bar[2].addr &= 0xffffc001; bl->bios_addr = buslogic_pci_bar[2].addr & 0xffffc000; buslogic_log("BT-958D: BIOS BAR %02X = NOW %02X (%02X)\n", addr & 3, buslogic_pci_bar[2].addr_regs[addr & 3], val); - BuslogicBIOSUpdate(bl); + BIOSUpdate(bl); return; case 0x3C: @@ -1300,7 +1389,7 @@ BuslogicPCIWrite(int func, int addr, uint8_t val, void *p) static void -BuslogicInitializeLocalRAM(buslogic_data_t *bl) +InitializeLocalRAM(buslogic_data_t *bl) { memset(bl->LocalRAM.u8View, 0, sizeof(HALocalRAM)); if (bl->chip == CHIP_BUSLOGIC_PCI) { @@ -1332,9 +1421,8 @@ static void buslogic_mca_write(int port, uint8_t val, void *priv) { x54x_t *dev = (x54x_t *) priv; - buslogic_data_t *bl = (buslogic_data_t *) dev->ven_data; - - HALocalRAM *HALR = &bl->LocalRAM; + buslogic_data_t *bl = (buslogic_data_t *)dev->ven_data; + HALocalRAM *halr = &bl->LocalRAM; /* MCA does not write registers below 0x0100. */ if (port < 0x0102) return; @@ -1359,35 +1447,35 @@ buslogic_mca_write(int port, uint8_t val, void *priv) /* Extract the BIOS ROM address info. */ if (dev->pos_regs[2] & 0xe0) switch(dev->pos_regs[2] & 0xe0) { - case 0xe0: /* [0]=111x xxxx */ + case 0xe0: /* [0]=111x xxxx */ bl->bios_addr = 0xDC000; break; - case 0x00: /* [0]=000x xxxx */ + case 0x00: /* [0]=000x xxxx */ bl->bios_addr = 0; break; - case 0xc0: /* [0]=110x xxxx */ + case 0xc0: /* [0]=110x xxxx */ bl->bios_addr = 0xD8000; break; - case 0xa0: /* [0]=101x xxxx */ + case 0xa0: /* [0]=101x xxxx */ bl->bios_addr = 0xD4000; break; - case 0x80: /* [0]=100x xxxx */ + case 0x80: /* [0]=100x xxxx */ bl->bios_addr = 0xD0000; break; - case 0x60: /* [0]=011x xxxx */ + case 0x60: /* [0]=011x xxxx */ bl->bios_addr = 0xCC000; break; - case 0x40: /* [0]=010x xxxx */ + case 0x40: /* [0]=010x xxxx */ bl->bios_addr = 0xC8000; break; - case 0x20: /* [0]=001x xxxx */ + case 0x20: /* [0]=001x xxxx */ bl->bios_addr = 0xC4000; break; } else { @@ -1412,15 +1500,15 @@ buslogic_mca_write(int port, uint8_t val, void *priv) * DOS Disk Space > 1GBytes is pos[2] = xxxx1xxx. */ /* Parity. */ - HALR->structured.autoSCSIData.uSCSIConfiguration &= ~2; - HALR->structured.autoSCSIData.uSCSIConfiguration |= (dev->pos_regs[4] & 2); + halr->structured.autoSCSIData.uSCSIConfiguration &= ~2; + halr->structured.autoSCSIData.uSCSIConfiguration |= (dev->pos_regs[4] & 2); /* Sync. */ - HALR->structured.autoSCSIData.u16SynchronousPermittedMask = (dev->pos_regs[4] & 0x10) ? 0xffff : 0x0000; + halr->structured.autoSCSIData.u16SynchronousPermittedMask = (dev->pos_regs[4] & 0x10) ? 0xffff : 0x0000; /* DOS Disk Space > 1GBytes */ - HALR->structured.autoSCSIData.uBIOSConfiguration &= ~4; - HALR->structured.autoSCSIData.uBIOSConfiguration |= (dev->pos_regs[4] & 8) ? 4 : 0; + halr->structured.autoSCSIData.uBIOSConfiguration &= ~4; + halr->structured.autoSCSIData.uBIOSConfiguration |= (dev->pos_regs[4] & 8) ? 4 : 0; /* * The PS/2 Model 80 BIOS always enables a card if it finds one, @@ -1453,15 +1541,15 @@ buslogic_mca_write(int port, uint8_t val, void *priv) void -BuslogicDeviceReset(void *p) +BuslogicDeviceReset(void *priv) { - x54x_t *dev = (x54x_t *) p; - buslogic_data_t *bl = (buslogic_data_t *) dev->ven_data; + x54x_t *dev = (x54x_t *)priv; + buslogic_data_t *bl = (buslogic_data_t *)dev->ven_data; x54x_device_reset(dev); - BuslogicInitializeLocalRAM(bl); - BuslogicInitializeAutoSCSIRam(dev); + InitializeLocalRAM(bl); + InitializeAutoSCSIRam(dev); } @@ -1488,7 +1576,7 @@ buslogic_init(const device_t *info) dev->ven_data = malloc(sizeof(buslogic_data_t)); memset(dev->ven_data, 0x00, sizeof(buslogic_data_t)); - bl = (buslogic_data_t *) dev->ven_data; + bl = (buslogic_data_t *)dev->ven_data; dev->bus = info->flags; if (!(info->flags & DEVICE_MCA) && !(info->flags & DEVICE_PCI)) { @@ -1521,26 +1609,25 @@ buslogic_init(const device_t *info) bl->has_bios = !!bios_rom_addr; } - dev->ven_cmd_phase1 = buslogic_cmd_phase1; - dev->ven_get_host_id = buslogic_get_host_id; - dev->ven_get_irq = buslogic_get_irq; - dev->ven_get_dma = buslogic_get_dma; - dev->get_ven_param_len = buslogic_param_len; + dev->ven_cmd_phase1 = cmd_phase1; + dev->ven_get_host_id = get_host_id; + dev->ven_get_irq = get_irq; + dev->ven_get_dma = get_dma; + dev->get_ven_param_len = param_len; dev->ven_cmds = buslogic_cmds; - dev->interrupt_type = buslogic_interrupt_type; - dev->is_aggressive_mode = buslogic_is_aggressive_mode; - dev->get_ven_data = buslogic_setup_data; + dev->interrupt_type = interrupt_type; + dev->is_aggressive_mode = is_aggressive_mode; + dev->get_ven_data = setup_data; dev->ven_reset = buslogic_reset; strcpy(dev->vendor, "BusLogic"); bl->fAggressiveRoundRobinMode = 1; - switch(bl->chip) - { + switch(bl->chip) { case CHIP_BUSLOGIC_ISA_542: strcpy(dev->name, "BT-542BH"); - bios_rom_name = L"roms/scsi/buslogic/bt-542bh_bios.rom"; + bios_rom_name = BT542_BIOS_PATH; bios_rom_size = 0x4000; bios_rom_mask = 0x3fff; has_autoscsi_rom = 0; @@ -1552,11 +1639,11 @@ buslogic_init(const device_t *info) case CHIP_BUSLOGIC_ISA: default: strcpy(dev->name, "BT-545S"); - bios_rom_name = L"roms/scsi/buslogic/bt-545s_bios.rom"; + bios_rom_name = BT545_BIOS_PATH; bios_rom_size = 0x4000; bios_rom_mask = 0x3fff; has_autoscsi_rom = 1; - autoscsi_rom_name = L"roms/scsi/buslogic/bt-545s_autoscsi.rom"; + autoscsi_rom_name = BT545_AUTO_BIOS_PATH; autoscsi_rom_size = 0x4000; has_scam_rom = 0; dev->fw_rev = "AA421E"; @@ -1565,7 +1652,7 @@ buslogic_init(const device_t *info) case CHIP_BUSLOGIC_MCA: strcpy(dev->name, "BT-640A"); - bios_rom_name = L"roms/scsi/buslogic/bt-640a_bios.rom"; + bios_rom_name = BT640A_BIOS_PATH; bios_rom_size = 0x4000; bios_rom_mask = 0x3fff; has_autoscsi_rom = 0; @@ -1580,11 +1667,11 @@ buslogic_init(const device_t *info) case CHIP_BUSLOGIC_VLB: strcpy(dev->name, "BT-445S"); - bios_rom_name = L"roms/scsi/buslogic/bt-445s_bios.rom"; + bios_rom_name = BT445S_BIOS_PATH; bios_rom_size = 0x4000; bios_rom_mask = 0x3fff; has_autoscsi_rom = 1; - autoscsi_rom_name = L"roms/scsi/buslogic/bt-445s_autoscsi.rom"; + autoscsi_rom_name = BT445S_AUTO_BIOS_PATH; autoscsi_rom_size = 0x4000; has_scam_rom = 0; dev->fw_rev = "AA421E"; @@ -1594,14 +1681,14 @@ buslogic_init(const device_t *info) case CHIP_BUSLOGIC_PCI: strcpy(dev->name, "BT-958D"); - bios_rom_name = L"roms/scsi/buslogic/bt-958d_bios.rom"; + bios_rom_name = BT958D_BIOS_PATH; bios_rom_size = 0x4000; bios_rom_mask = 0x3fff; has_autoscsi_rom = 1; - autoscsi_rom_name = L"roms/scsi/buslogic/bt-958d_autoscsi.rom"; + autoscsi_rom_name = BT958D_AUTO_BIOS_PATH; autoscsi_rom_size = 0x8000; has_scam_rom = 1; - scam_rom_name = L"roms/scsi/buslogic/bt-958d_scam.rom"; + scam_rom_name = BT958D_SCAM_BIOS_PATH; scam_rom_size = 0x0200; dev->fw_rev = "AA507B"; dev->cdrom_boot = 1; @@ -1627,18 +1714,18 @@ buslogic_init(const device_t *info) rom_init(&bl->bios, bios_rom_name, bios_rom_addr, bios_rom_size, bios_rom_mask, 0, MEM_MAPPING_EXTERNAL); if (has_autoscsi_rom) { - f = rom_fopen(autoscsi_rom_name); - if (f) { - fread(bl->AutoSCSIROM, 1, autoscsi_rom_size, f); + f = plat_fopen(rom_path(autoscsi_rom_name), L"rb"); + if (f != NULL) { + (void)fread(bl->AutoSCSIROM, 1, autoscsi_rom_size, f); fclose(f); f = NULL; } } if (has_scam_rom) { - f = rom_fopen(scam_rom_name); - if (f) { - fread(bl->SCAMData, 1, scam_rom_size, f); + f = plat_fopen(rom_path(scam_rom_name), L"rb"); + if (f != NULL) { + (void)fread(bl->SCAMData, 1, scam_rom_size, f); fclose(f); f = NULL; } @@ -1646,12 +1733,11 @@ buslogic_init(const device_t *info) } else { bl->bios_size = 0; - bl->bios_mask = 0; } if (bl->chip == CHIP_BUSLOGIC_PCI) { - dev->pci_slot = pci_add_card(PCI_ADD_NORMAL, BuslogicPCIRead, BuslogicPCIWrite, dev); + dev->pci_slot = pci_add_card(PCI_ADD_NORMAL, PCIRead, PCIWrite, dev); buslogic_pci_bar[0].addr_regs[0] = 1; buslogic_pci_bar[1].addr_regs[0] = 0; @@ -1676,8 +1762,8 @@ buslogic_init(const device_t *info) x54x_device_reset(dev); if ((bl->chip != CHIP_BUSLOGIC_ISA_542) && (bl->chip != CHIP_BUSLOGIC_MCA)) { - BuslogicInitializeLocalRAM(bl); - BuslogicInitializeAutoSCSIRam(dev); + InitializeLocalRAM(bl); + InitializeAutoSCSIRam(dev); } return(dev); diff --git a/src/scsi/scsi_ncr5380.c b/src/scsi/scsi_ncr5380.c index 82b3067..eb8361a 100644 --- a/src/scsi/scsi_ncr5380.c +++ b/src/scsi/scsi_ncr5380.c @@ -9,7 +9,7 @@ * Implementation of the NCR 5380 series of SCSI Host Adapters * made by NCR. These controllers were designed for the ISA bus. * - * Version: @(#)scsi_ncr5380.c 1.0.4 2018/03/15 + * Version: @(#)scsi_ncr5380.c 1.0.5 2018/03/31 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -62,10 +62,10 @@ #include "scsi_ncr5380.h" -#define LCS6821N_ROM L"roms/scsi/ncr5380/longshine lcs-6821n - bios version 1.04.bin" -#define RT1000B_ROM L"roms/scsi/ncr5380/rancho_rt1000_rtbios_version_8.10r.bin" -#define T130B_ROM L"roms/scsi/ncr5380/trantor_t130b_bios_v2.14.bin" -#define SCSIAT_ROM L"roms/scsi/ncr5380/sumo_scsiat_bios_v6.3.bin" +#define LCS6821N_ROM L"scsi/ncr5380/longshine lcs-6821n - bios version 1.04.bin" +#define RT1000B_ROM L"scsi/ncr5380/rancho_rt1000_rtbios_version_8.10r.bin" +#define T130B_ROM L"scsi/ncr5380/trantor_t130b_bios_v2.14.bin" +#define SCSIAT_ROM L"scsi/ncr5380/sumo_scsiat_bios_v6.3.bin" #define NCR_CURDATA 0 /* current SCSI data (read only) */ diff --git a/src/sound/midi_fluidsynth.c b/src/sound/midi_fluidsynth.c index e8e9ea1..5ebee57 100644 --- a/src/sound/midi_fluidsynth.c +++ b/src/sound/midi_fluidsynth.c @@ -17,7 +17,7 @@ * website (for 32bit and 64bit Windows) are working, and * need no additional support files other than sound fonts. * - * Version: @(#)midi_fluidsynth.c 1.0.5 2018/03/19 + * Version: @(#)midi_fluidsynth.c 1.0.6 2018/03/31 * * Code borrowed from scummvm. * @@ -286,13 +286,6 @@ fluidsynth_init(const device_t *info) memset(data, 0x00, sizeof(fluidsynth_t)); - /* Try loading the DLL. */ - fluidsynth_handle = dynld_module(PATH_FS_DLL, fluidsynth_imports); - if (fluidsynth_handle == NULL) { - ui_msgbox(MBX_ERROR, (wchar_t *)IDS_2171); - return(NULL); - } - data->settings = f_new_fluid_settings(); f_fluid_settings_setnum(data->settings, "synth.sample-rate", 44100); @@ -386,6 +379,11 @@ fluidsynth_close(void* priv) { if (priv == NULL) return; + if (fluidsynth_handle == NULL) { + ui_msgbox(MBX_ERROR, (wchar_t *)IDS_2171); + return; + } + fluidsynth_t* data = &fsdev; if (data->sound_font != -1) { @@ -423,6 +421,14 @@ fluidsynth_close(void* priv) } +void +fluidsynth_global_init(void) +{ + /* Try loading the DLL. */ + fluidsynth_handle = dynld_module(PATH_FS_DLL, fluidsynth_imports); +} + + static const device_config_t fluidsynth_config[] = { { .name = "sound_font", diff --git a/src/sound/midi_fluidsynth.h b/src/sound/midi_fluidsynth.h index 3c0efe5..0a77edd 100644 --- a/src/sound/midi_fluidsynth.h +++ b/src/sound/midi_fluidsynth.h @@ -8,7 +8,7 @@ * * Definitions for the FluidSynth driver. * - * Version: @(#)midi_fluidsynth.h 1.0.2 2018/03/15 + * Version: @(#)midi_fluidsynth.h 1.0.3 2018/03/31 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -41,4 +41,7 @@ extern const device_t fluidsynth_device; +extern void fluidsynth_global_init(void); + + #endif /*SOUND_MIDI_FLUIDSYNTH_H*/ diff --git a/src/sound/midi_mt32.c b/src/sound/midi_mt32.c index f9fb78f..848de59 100644 --- a/src/sound/midi_mt32.c +++ b/src/sound/midi_mt32.c @@ -8,7 +8,7 @@ * * Interface to the MuNT32 MIDI synthesizer. * - * Version: @(#)midi_mt32.c 1.0.2 2018/03/15 + * Version: @(#)midi_mt32.c 1.0.3 2018/03/31 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -52,330 +52,350 @@ #include "midi_mt32.h" +#define MT32_CTRL_ROM_PATH L"sound/mt32/mt32_control.rom" +#define MT32_PCM_ROM_PATH L"sound/mt32/mt32_pcm.rom" +#define CM32_CTRL_ROM_PATH L"sound/cm32l/cm32l_control.rom" +#define CM32_PCM_ROM_PATH L"sound/cm32l/cm32l_pcm.rom" + + extern void givealbuffer_midi(void *buf, uint32_t size); extern void pclog(const char *format, ...); extern void al_set_midi(int freq, int buf_size); -static const mt32emu_report_handler_i_v0 handler_v0 = { - /** Returns the actual interface version ID */ - NULL, //mt32emu_report_handler_version (*getVersionID)(mt32emu_report_handler_i i); +extern int soundon; - /** Callback for debug messages, in vprintf() format */ - NULL, //void (*printDebug)(void *instance_data, const char *fmt, va_list list); - /** Callbacks for reporting errors */ - NULL, //void (*onErrorControlROM)(void *instance_data); - NULL, //void (*onErrorPCMROM)(void *instance_data); - /** Callback for reporting about displaying a new custom message on LCD */ - NULL, //void (*showLCDMessage)(void *instance_data, const char *message); - /** Callback for reporting actual processing of a MIDI message */ - NULL, //void (*onMIDIMessagePlayed)(void *instance_data); - /** - * Callback for reporting an overflow of the input MIDI queue. - * Returns MT32EMU_BOOL_TRUE if a recovery action was taken - * and yet another attempt to enqueue the MIDI event is desired. - */ - NULL, //mt32emu_boolean (*onMIDIQueueOverflow)(void *instance_data); - /** - * Callback invoked when a System Realtime MIDI message is detected in functions - * mt32emu_parse_stream and mt32emu_play_short_message and the likes. - */ - NULL, //void (*onMIDISystemRealtime)(void *instance_data, mt32emu_bit8u system_realtime); - /** Callbacks for reporting system events */ - NULL, //void (*onDeviceReset)(void *instance_data); - NULL, //void (*onDeviceReconfig)(void *instance_data); - /** Callbacks for reporting changes of reverb settings */ - NULL, //void (*onNewReverbMode)(void *instance_data, mt32emu_bit8u mode); - NULL, //void (*onNewReverbTime)(void *instance_data, mt32emu_bit8u time); - NULL, //void (*onNewReverbLevel)(void *instance_data, mt32emu_bit8u level); - /** Callbacks for reporting various information */ - NULL, //void (*onPolyStateChanged)(void *instance_data, mt32emu_bit8u part_num); - NULL, //void (*onProgramChanged)(void *instance_data, mt32emu_bit8u part_num, const char *sound_group_name, const char *patch_name); + +static const mt32emu_report_handler_i_v0 handler_v0 = { + /** Returns the actual interface version ID */ + NULL, //mt32emu_report_handler_version (*getVersionID)(mt32emu_report_handler_i i); + + /** Callback for debug messages, in vprintf() format */ + NULL, //void (*printDebug)(void *instance_data, const char *fmt, va_list list); + /** Callbacks for reporting errors */ + NULL, //void (*onErrorControlROM)(void *instance_data); + NULL, //void (*onErrorPCMROM)(void *instance_data); + /** Callback for reporting about displaying a new custom message on LCD */ + NULL, //void (*showLCDMessage)(void *instance_data, const char *message); + /** Callback for reporting actual processing of a MIDI message */ + NULL, //void (*onMIDIMessagePlayed)(void *instance_data); + /** + * Callback for reporting an overflow of the input MIDI queue. + * Returns MT32EMU_BOOL_TRUE if a recovery action was taken + * and yet another attempt to enqueue the MIDI event is desired. + */ + NULL, //mt32emu_boolean (*onMIDIQueueOverflow)(void *instance_data); + /** + * Callback invoked when a System Realtime MIDI message is detected in functions + * mt32emu_parse_stream and mt32emu_play_short_message and the likes. + */ + NULL, //void (*onMIDISystemRealtime)(void *instance_data, mt32emu_bit8u system_realtime); + /** Callbacks for reporting system events */ + NULL, //void (*onDeviceReset)(void *instance_data); + NULL, //void (*onDeviceReconfig)(void *instance_data); + /** Callbacks for reporting changes of reverb settings */ + NULL, //void (*onNewReverbMode)(void *instance_data, mt32emu_bit8u mode); + NULL, //void (*onNewReverbTime)(void *instance_data, mt32emu_bit8u time); + NULL, //void (*onNewReverbLevel)(void *instance_data, mt32emu_bit8u level); + /** Callbacks for reporting various information */ + NULL, //void (*onPolyStateChanged)(void *instance_data, mt32emu_bit8u part_num); + NULL, //void (*onProgramChanged)(void *instance_data, mt32emu_bit8u part_num, const char *sound_group_name, const char *patch_name); }; -static const mt32emu_report_handler_i handler = { &handler_v0 }; - -static mt32emu_context context = NULL; -static int roms_present[2] = {-1, -1}; - -mt32emu_return_code mt32_check(const char* func, mt32emu_return_code ret, mt32emu_return_code expected) -{ - if (ret != expected) - { - /* pclog("%s() failed, expected %d but returned %d\n", func, expected, ret); */ - return 0; - } - return 1; -} - -int mt32_available() -{ - if (roms_present[0] < 0) - roms_present[0] = (rom_present(L"roms/sound/mt32/mt32_control.rom") && rom_present(L"roms/sound/mt32/mt32_pcm.rom")); - return roms_present[0]; -} - -int cm32l_available() -{ - if (roms_present[1] < 0) - roms_present[1] = (rom_present(L"roms/sound/cm32l/cm32l_control.rom") && rom_present(L"roms/sound/cm32l/cm32l_pcm.rom")); - return roms_present[1]; -} - -static thread_t *thread_h = NULL; -static event_t *event = NULL; #define RENDER_RATE 100 #define BUFFER_SEGMENTS 10 + +static thread_t *thread_h = NULL; +static event_t *event = NULL; static uint32_t samplerate = 44100; static int buf_size = 0; static float* buffer = NULL; static int16_t* buffer_int16 = NULL; static int midi_pos = 0; +static const mt32emu_report_handler_i handler = { &handler_v0 }; +static mt32emu_context context = NULL; +static int mtroms_present[2] = {-1, -1}; -void mt32_stream(float* stream, int len) + +mt32emu_return_code +mt32_check(const char *func, mt32emu_return_code ret, mt32emu_return_code expected) { - if (context) mt32emu_render_float(context, stream, len); + if (ret != expected) { +#if 0 + pclog("%s() failed, expected %d but returned %d\n", func, expected, ret); +#endif + return 0; + } + + return 1; } -void mt32_stream_int16(int16_t* stream, int len) + +int +mt32_available(void) { - if (context) mt32emu_render_bit16s(context, stream, len); + if (mtroms_present[0] < 0) + mtroms_present[0] = (rom_present(MT32_CTRL_ROM_PATH) && + rom_present(MT32_PCM_ROM_PATH)); + return mtroms_present[0]; } -void mt32_poll() + +int +cm32l_available(void) { - midi_pos++; - if (midi_pos == 48000/RENDER_RATE) - { - midi_pos = 0; - thread_set_event(event); - } + if (mtroms_present[1] < 0) + mtroms_present[1] = (rom_present(CM32_CTRL_ROM_PATH) && + rom_present(CM32_PCM_ROM_PATH)); + return mtroms_present[1]; } -extern int soundon; -static void mt32_thread(void *param) +void +mt32_stream(float* stream, int len) { - int buf_pos = 0; - int bsize = buf_size / BUFFER_SEGMENTS; - while (1) - { - thread_wait_event(event, -1); + if (context) mt32emu_render_float(context, stream, len); +} - if (sound_is_float) - { - float *buf = (float *) ((uint8_t*)buffer + buf_pos); - memset(buf, 0, bsize); - mt32_stream(buf, bsize / (2 * sizeof(float))); - buf_pos += bsize; - if (buf_pos >= buf_size) - { - if (soundon) - givealbuffer_midi(buffer, buf_size / sizeof(float)); - buf_pos = 0; - } + +void +mt32_stream_int16(int16_t* stream, int len) +{ + if (context) mt32emu_render_bit16s(context, stream, len); +} + + +void +mt32_poll(void) +{ + midi_pos++; + if (midi_pos == 48000/RENDER_RATE) { + midi_pos = 0; + thread_set_event(event); + } +} + + +static void +mt32_thread(void *param) +{ + int buf_pos = 0; + int bsize = buf_size / BUFFER_SEGMENTS; + + while (1) { + thread_wait_event(event, -1); + + if (sound_is_float) { + float *buf = (float *) ((uint8_t*)buffer + buf_pos); + + memset(buf, 0, bsize); + mt32_stream(buf, bsize / (2 * sizeof(float))); + buf_pos += bsize; + if (buf_pos >= buf_size) { + if (soundon) + givealbuffer_midi(buffer, buf_size / sizeof(float)); + buf_pos = 0; } - else - { - int16_t *buf = (int16_t *) ((uint8_t*)buffer_int16 + buf_pos); - memset(buf, 0, bsize); - mt32_stream_int16(buf, bsize / (2 * sizeof(int16_t))); - buf_pos += bsize; - if (buf_pos >= buf_size) - { - if (soundon) - givealbuffer_midi(buffer_int16, buf_size / sizeof(int16_t)); - buf_pos = 0; - } + } else { + int16_t *buf = (int16_t *) ((uint8_t*)buffer_int16 + buf_pos); + + memset(buf, 0, bsize); + mt32_stream_int16(buf, bsize / (2 * sizeof(int16_t))); + buf_pos += bsize; + if (buf_pos >= buf_size) { + if (soundon) + givealbuffer_midi(buffer_int16, buf_size / sizeof(int16_t)); + buf_pos = 0; } - } -} - -void mt32_msg(uint8_t* val) -{ - if (context) mt32_check("mt32emu_play_msg", mt32emu_play_msg(context, *(uint32_t*)val), MT32EMU_RC_OK); -} - -void mt32_sysex(uint8_t* data, unsigned int len) -{ - if (context) mt32_check("mt32emu_play_sysex", mt32emu_play_sysex(context, data, len), MT32EMU_RC_OK); -} - -void* mt32emu_init(wchar_t *control_rom, wchar_t *pcm_rom) -{ - wchar_t s[512]; - char fn[512]; - context = mt32emu_create_context(handler, NULL); - if (!rom_getfile(control_rom, s, 512)) return 0; - wcstombs(fn, s, (wcslen(s) << 1) + 2); - if (!mt32_check("mt32emu_add_rom_file", mt32emu_add_rom_file(context, fn), MT32EMU_RC_ADDED_CONTROL_ROM)) return 0; - if (!rom_getfile(pcm_rom, s, 512)) return 0; - wcstombs(fn, s, (wcslen(s) << 1) + 2); - if (!mt32_check("mt32emu_add_rom_file", mt32emu_add_rom_file(context, fn), MT32EMU_RC_ADDED_PCM_ROM)) return 0; - - if (!mt32_check("mt32emu_open_synth", mt32emu_open_synth(context), MT32EMU_RC_OK)) return 0; - - event = thread_create_event(); - thread_h = thread_create(mt32_thread, 0); - samplerate = mt32emu_get_actual_stereo_output_samplerate(context); - /* buf_size = samplerate/RENDER_RATE*2; */ - if (sound_is_float) - { - buf_size = (samplerate/RENDER_RATE)*2*BUFFER_SEGMENTS*sizeof(float); - buffer = malloc(buf_size); - buffer_int16 = NULL; } - else - { - buf_size = (samplerate/RENDER_RATE)*2*BUFFER_SEGMENTS*sizeof(int16_t); - buffer = NULL; - buffer_int16 = malloc(buf_size); - } - - mt32emu_set_output_gain(context, device_get_config_int("output_gain")/100.0f); - mt32emu_set_reverb_enabled(context, device_get_config_int("reverb")); - mt32emu_set_reverb_output_gain(context, device_get_config_int("reverb_output_gain")/100.0f); - mt32emu_set_reversed_stereo_enabled(context, device_get_config_int("reversed_stereo")); - mt32emu_set_nice_amp_ramp_enabled(context, device_get_config_int("nice_ramp")); - - /* pclog("mt32 output gain: %f\n", mt32emu_get_output_gain(context)); - pclog("mt32 reverb output gain: %f\n", mt32emu_get_reverb_output_gain(context)); - pclog("mt32 reverb: %d\n", mt32emu_is_reverb_enabled(context)); - pclog("mt32 reversed stereo: %d\n", mt32emu_is_reversed_stereo_enabled(context)); */ - - al_set_midi(samplerate, buf_size); - - /* pclog("mt32 (Munt %s) initialized, samplerate %d, buf_size %d\n", mt32emu_get_library_version_string(), samplerate, buf_size); */ - - midi_device_t* dev = malloc(sizeof(midi_device_t)); - memset(dev, 0, sizeof(midi_device_t)); - - dev->play_msg = mt32_msg; - dev->play_sysex = mt32_sysex; - dev->poll = mt32_poll; - - midi_init(dev); - - return dev; + } } -void *mt32_init(const device_t *info) + +void +mt32_msg(uint8_t* val) { - return mt32emu_init(L"roms/sound/mt32/mt32_control.rom", L"roms/sound/mt32/mt32_pcm.rom"); + if (context) mt32_check("mt32emu_play_msg", mt32emu_play_msg(context, *(uint32_t*)val), MT32EMU_RC_OK); } -void *cm32l_init(const device_t *info) + +void +mt32_sysex(uint8_t* data, unsigned int len) { - return mt32emu_init(L"roms/sound/cm32l/cm32l_control.rom", L"roms/sound/cm32l/cm32l_pcm.rom"); + if (context) mt32_check("mt32emu_play_sysex", mt32emu_play_sysex(context, data, len), MT32EMU_RC_OK); } -void mt32_close(void* p) + +static void * +mt32emu_init(wchar_t *control_rom, wchar_t *pcm_rom) { - if (!p) return; + wchar_t path[1024]; + char fn[1024]; - if (thread_h) - thread_kill(thread_h); - if (event) - thread_destroy_event(event); - event = NULL; - thread_h = NULL; + context = mt32emu_create_context(handler, NULL); - if (context) - { - mt32emu_close_synth(context); - mt32emu_free_context(context); - } - context = NULL; + pc_path(path, sizeof_w(path), rom_path(control_rom)); + wcstombs(fn, path, sizeof(fn)); + if (!mt32_check("mt32emu_add_rom_file", mt32emu_add_rom_file(context, fn), MT32EMU_RC_ADDED_CONTROL_ROM)) return 0; - if (buffer) - free(buffer); - buffer = NULL; + pc_path(path, sizeof_w(path), rom_path(pcm_rom)); + wcstombs(fn, path, sizeof(fn)); + if (!mt32_check("mt32emu_add_rom_file", mt32emu_add_rom_file(context, fn), MT32EMU_RC_ADDED_PCM_ROM)) return 0; - if (buffer_int16) - free(buffer_int16); - buffer_int16 = NULL; + if (!mt32_check("mt32emu_open_synth", mt32emu_open_synth(context), MT32EMU_RC_OK)) return 0; - midi_close(); + event = thread_create_event(); + thread_h = thread_create(mt32_thread, 0); + samplerate = mt32emu_get_actual_stereo_output_samplerate(context); - free((midi_device_t*)p); + /* buf_size = samplerate/RENDER_RATE*2; */ + if (sound_is_float) { + buf_size = (samplerate/RENDER_RATE)*2*BUFFER_SEGMENTS*sizeof(float); + buffer = malloc(buf_size); + buffer_int16 = NULL; + } else { + buf_size = (samplerate/RENDER_RATE)*2*BUFFER_SEGMENTS*sizeof(int16_t); + buffer = NULL; + buffer_int16 = malloc(buf_size); + } - /* pclog("mt32 closed\n"); */ + mt32emu_set_output_gain(context, device_get_config_int("output_gain")/100.0f); + mt32emu_set_reverb_enabled(context, device_get_config_int("reverb")); + mt32emu_set_reverb_output_gain(context, device_get_config_int("reverb_output_gain")/100.0f); + mt32emu_set_reversed_stereo_enabled(context, device_get_config_int("reversed_stereo")); + mt32emu_set_nice_amp_ramp_enabled(context, device_get_config_int("nice_ramp")); + + /* pclog("mt32 output gain: %f\n", mt32emu_get_output_gain(context)); + pclog("mt32 reverb output gain: %f\n", mt32emu_get_reverb_output_gain(context)); + pclog("mt32 reverb: %d\n", mt32emu_is_reverb_enabled(context)); + pclog("mt32 reversed stereo: %d\n", mt32emu_is_reversed_stereo_enabled(context)); */ + + al_set_midi(samplerate, buf_size); + + /* pclog("mt32 (Munt %s) initialized, samplerate %d, buf_size %d\n", mt32emu_get_library_version_string(), samplerate, buf_size); */ + + midi_device_t* dev = malloc(sizeof(midi_device_t)); + memset(dev, 0, sizeof(midi_device_t)); + + dev->play_msg = mt32_msg; + dev->play_sysex = mt32_sysex; + dev->poll = mt32_poll; + + midi_init(dev); + + return dev; } + +static void * +mt32_init(const device_t *info) +{ + return mt32emu_init(MT32_CTRL_ROM_PATH, MT32_PCM_ROM_PATH); +} + + +static void * +cm32l_init(const device_t *info) +{ + return mt32emu_init(CM32_CTRL_ROM_PATH, CM32_PCM_ROM_PATH); +} + + +static void +mt32_close(void *priv) +{ + if (priv == NULL) return; + + if (thread_h) + thread_kill(thread_h); + if (event) + thread_destroy_event(event); + event = NULL; + thread_h = NULL; + + if (context) { + mt32emu_close_synth(context); + mt32emu_free_context(context); + } + context = NULL; + + if (buffer) + free(buffer); + buffer = NULL; + + if (buffer_int16) + free(buffer_int16); + buffer_int16 = NULL; + + midi_close(); + + free((midi_device_t*)priv); +} + + static const device_config_t mt32_config[] = { - { - .name = "output_gain", - .description = "Output Gain", - .type = CONFIG_SPINNER, - .spinner = - { - .min = 0, - .max = 100 - }, - .default_int = 100 - }, - { - .name = "reverb", - .description = "Reverb", - .type = CONFIG_BINARY, - .default_int = 1 - }, - { - .name = "reverb_output_gain", - .description = "Reverb Output Gain", - .type = CONFIG_SPINNER, - .spinner = - { - .min = 0, - .max = 100 - }, - .default_int = 100 - }, - { - .name = "reversed_stereo", - .description = "Reversed stereo", - .type = CONFIG_BINARY, - .default_int = 0 - }, - { - .name = "nice_ramp", - .description = "Nice ramp", - .type = CONFIG_BINARY, - .default_int = 1 - }, - { - .type = -1 - } + { + .name = "output_gain", + .description = "Output Gain", + .type = CONFIG_SPINNER, + .spinner = + { + .min = 0, + .max = 100 + }, + .default_int = 100 + }, + { + .name = "reverb", + .description = "Reverb", + .type = CONFIG_BINARY, + .default_int = 1 + }, + { + .name = "reverb_output_gain", + .description = "Reverb Output Gain", + .type = CONFIG_SPINNER, + .spinner = + { + .min = 0, + .max = 100 + }, + .default_int = 100 + }, + { + .name = "reversed_stereo", + .description = "Reversed stereo", + .type = CONFIG_BINARY, + .default_int = 0 + }, + { + .name = "nice_ramp", + .description = "Nice ramp", + .type = CONFIG_BINARY, + .default_int = 1 + }, + { + .type = -1 + } }; -const device_t mt32_device = -{ - "Roland MT-32 Emulation", - 0, - 0, - mt32_init, - mt32_close, - NULL, - mt32_available, - NULL, - NULL, - NULL, - mt32_config + +const device_t mt32_device = { + "Roland MT-32 Emulation", + 0, 0, + mt32_init, mt32_close, NULL, + mt32_available, + NULL, NULL, NULL, + mt32_config }; -const device_t cm32l_device = -{ - "Roland CM-32L Emulation", - 0, - 0, - cm32l_init, - mt32_close, - NULL, - cm32l_available, - NULL, - NULL, - NULL, - mt32_config +const device_t cm32l_device = { + "Roland CM-32L Emulation", + 0, 0, + cm32l_init, mt32_close, NULL, + cm32l_available, + NULL, NULL, NULL, + mt32_config }; diff --git a/src/sound/snd_adlibgold.c b/src/sound/snd_adlibgold.c index e38f609..fa2adbd 100644 --- a/src/sound/snd_adlibgold.c +++ b/src/sound/snd_adlibgold.c @@ -10,7 +10,7 @@ * * TODO: Stack allocation of big buffers (line 688 et al.) * - * Version: @(#)snd_adlibgold.c 1.0.5 2018/03/28 + * Version: @(#)snd_adlibgold.c 1.0.6 2018/03/31 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -53,6 +53,7 @@ #include "../nvr.h" #include "../timer.h" #include "../device.h" +#include "../plat.h" #include "sound.h" #include "filters.h" #include "snd_opl.h" @@ -827,10 +828,10 @@ void *adgold_init(const device_t *info) for (; c >= 0; c--) attenuation[c] = 0; - f = nvr_fopen(L"adgold.bin", L"rb"); - if (f) + f = plat_fopen(nvr_path(L"adgold.bin"), L"rb"); + if (f != NULL) { - fread(adgold->adgold_eeprom, 0x18, 1, f); + (void)fread(adgold->adgold_eeprom, 0x18, 1, f); fclose(f); } @@ -867,10 +868,10 @@ void adgold_close(void *p) FILE *f; adgold_t *adgold = (adgold_t *)p; - f = nvr_fopen(L"adgold.bin", L"wb"); - if (f) + f = plat_fopen(nvr_path(L"adgold.bin"), L"wb"); + if (f != NULL) { - fwrite(adgold->adgold_eeprom, 0x18, 1, f); + (void)fwrite(adgold->adgold_eeprom, 0x18, 1, f); fclose(f); } diff --git a/src/sound/snd_emu8k.c b/src/sound/snd_emu8k.c index 2ab3f60..e5014c6 100644 --- a/src/sound/snd_emu8k.c +++ b/src/sound/snd_emu8k.c @@ -8,7 +8,7 @@ * * Implementation of Emu8000 emulator. * - * Version: @(#)snd_emu8k.c 1.0.6 2018/03/28 + * Version: @(#)snd_emu8k.c 1.0.7 2018/03/31 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -51,10 +51,14 @@ #include "../mem.h" #include "../rom.h" #include "../timer.h" +#include "../plat.h" #include "sound.h" #include "snd_emu8k.h" +#define EMU8K_ROM_PATH L"sound/awe32.raw" + + #if !defined FILTER_INITIAL && !defined FILTER_MOOG && !defined FILTER_CONSTANT //#define FILTER_INITIAL #define FILTER_MOOG @@ -2176,8 +2180,8 @@ void emu8k_init(emu8k_t *emu8k, uint16_t emu_addr, int onboard_ram) int c; double out; - f = rom_fopen(L"roms/sound/awe32.raw"); - if (!f) + f = plat_fopen(rom_path(EMU8K_ROM_PATH), L"rb"); + if (f == NULL) fatal("AWE32.RAW not found\n"); emu8k->rom = malloc(1024 * 1024); diff --git a/src/sound/snd_sb.c b/src/sound/snd_sb.c index 5f11bec..30c5fe2 100644 --- a/src/sound/snd_sb.c +++ b/src/sound/snd_sb.c @@ -8,7 +8,7 @@ * * Sound Blaster emulation. * - * Version: @(#)sound_sb.c 1.0.3 2018/03/15 + * Version: @(#)sound_sb.c 1.0.4 2018/03/31 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -1277,7 +1277,7 @@ void *sb_16_init(const device_t *info) int sb_awe32_available() { - return rom_present(L"roms/sound/awe32.raw"); + return rom_present(L"sound/awe32.raw"); } void *sb_awe32_init(const device_t *info) diff --git a/src/sound/sound.c b/src/sound/sound.c index 442f51c..49e8f7c 100644 --- a/src/sound/sound.c +++ b/src/sound/sound.c @@ -8,7 +8,7 @@ * * Sound emulation core. * - * Version: @(#)sound.c 1.0.3 2018/03/28 + * Version: @(#)sound.c 1.0.4 2018/03/31 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -53,6 +53,9 @@ #include "snd_adlibgold.h" #include "snd_audiopci.h" #include "snd_mpu401.h" +#ifdef USE_FLUIDSYNTH +# include "midi_fluidsynth.h" +#endif #if defined(DEV_BRANCH) && defined(USE_PAS16) # include "snd_pas16.h" #endif @@ -540,3 +543,13 @@ void sound_cd_thread_reset(void) cd_thread_enable = available_cdrom_drives ? 1 : 0; } + + +/* Called once, at application startup. */ +void +sound_global_init(void) +{ +#ifdef USE_FLUIDSYNTH + fluidsynth_global_init(); +#endif +} diff --git a/src/sound/sound.h b/src/sound/sound.h index d3137b4..ce335cc 100644 --- a/src/sound/sound.h +++ b/src/sound/sound.h @@ -8,7 +8,7 @@ * * Definitions for the Sound Emulation core. * - * Version: @(#)sound.h 1.0.2 2018/03/15 + * Version: @(#)sound.h 1.0.3 2018/03/31 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -77,6 +77,7 @@ extern void sound_speed_changed(void); extern void sound_realloc_buffers(void); +extern void sound_global_init(void); extern void sound_init(void); extern void sound_reset(void); diff --git a/src/version.h b/src/version.h index 0dce06a..09f2f15 100644 --- a/src/version.h +++ b/src/version.h @@ -8,7 +8,7 @@ * * Define application version and build info. * - * Version: @(#)version.h 1.0.2 2018/03/20 + * Version: @(#)version.h 1.0.3 2018/03/30 * * Author: Fred N. van Kempen, * @@ -55,6 +55,7 @@ #define EMU_VER_MAJOR 0 #define EMU_VER_MINOR 1 #define EMU_VER_REV 3 +#define EMU_VER_PATCH 4 /* Standard C preprocessor macros. */ @@ -64,7 +65,7 @@ /* These are used in the application. */ #define EMU_VER_NUM EMU_VER_MAJOR.EMU_VER_MINOR.EMU_VER_REV -#define EMU_VER_NUM_4 EMU_VER_MAJOR.EMU_VER_MINOR.EMU_VER_REV.0 +#define EMU_VER_NUM_4 EMU_VER_MAJOR.EMU_VER_MINOR.EMU_VER_REV.EMU_VER_PATCH #define EMU_VERSION STR(EMU_VER_NUM) #define EMU_VERSION_4 STR(EMU_VER_NUM_4) diff --git a/src/video/vid_ati18800.c b/src/video/vid_ati18800.c index 497becf..528c069 100644 --- a/src/video/vid_ati18800.c +++ b/src/video/vid_ati18800.c @@ -8,7 +8,7 @@ * * ATI 18800 emulation (VGA Edge-16) * - * Version: @(#)vid_ati18800.c 1.0.5 2018/03/26 + * Version: @(#)vid_ati18800.c 1.0.6 2018/03/31 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -54,9 +54,9 @@ #include "vid_svga_render.h" -#define BIOS_ROM_PATH_WONDER L"roms/video/ati/ati18800/vga_wonder_v3-1.02.bin" -#define BIOS_ROM_PATH_VGA88 L"roms/video/ati/ati18800/vga88.bin" -#define BIOS_ROM_PATH_EDGE16 L"roms/video/ati/ati18800/vgaedge16.vbi" +#define BIOS_ROM_PATH_WONDER L"video/ati/ati18800/vga_wonder_v3-1.02.bin" +#define BIOS_ROM_PATH_VGA88 L"video/ati/ati18800/vga88.bin" +#define BIOS_ROM_PATH_EDGE16 L"video/ati/ati18800/vgaedge16.vbi" enum { ATI18800_WONDER = 0, diff --git a/src/video/vid_ati28800.c b/src/video/vid_ati28800.c index 8fbd541..7180683 100644 --- a/src/video/vid_ati28800.c +++ b/src/video/vid_ati28800.c @@ -8,7 +8,7 @@ * * ATI 28800 emulation (VGA Charger and Korean VGA) * - * Version: @(#)vid_ati28800.c 1.0.10 2018/03/26 + * Version: @(#)vid_ati28800.c 1.0.11 2018/03/31 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -57,17 +57,17 @@ #include "vid_svga_render.h" -#define BIOS_ATIKOR_PATH L"roms/video/ati/ati28800/atikorvga.bin" +#define BIOS_ATIKOR_PATH L"video/ati/ati28800/atikorvga.bin" -#define BIOS_VGAXL_EVEN_PATH L"roms/video/ati/ati28800/xleven.bin" -#define BIOS_VGAXL_ODD_PATH L"roms/video/ati/ati28800/xlodd.bin" +#define BIOS_VGAXL_EVEN_PATH L"video/ati/ati28800/xleven.bin" +#define BIOS_VGAXL_ODD_PATH L"video/ati/ati28800/xlodd.bin" #if defined(DEV_BRANCH) && defined(USE_XL24) -#define BIOS_XL24_EVEN_PATH L"roms/video/ati/ati28800/112-14318-102.bin" -#define BIOS_XL24_ODD_PATH L"roms/video/ati/ati28800/112-14319-102.bin" +#define BIOS_XL24_EVEN_PATH L"video/ati/ati28800/112-14318-102.bin" +#define BIOS_XL24_ODD_PATH L"video/ati/ati28800/112-14319-102.bin" #endif -#define BIOS_ROM_PATH L"roms/video/ati/ati28800/bios.bin" +#define BIOS_ROM_PATH L"video/ati/ati28800/bios.bin" typedef struct ati28800_t diff --git a/src/video/vid_ati_eeprom.c b/src/video/vid_ati_eeprom.c index dc7191d..0f71671 100644 --- a/src/video/vid_ati_eeprom.c +++ b/src/video/vid_ati_eeprom.c @@ -8,7 +8,7 @@ * * Emulation of the EEPROM on select ATI cards. * - * Version: @(#)vid_ati_eeprom.c 1.0.1 2018/02/14 + * Version: @(#)vid_ati_eeprom.c 1.0.2 2018/03/31 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -43,6 +43,7 @@ #include "../emu.h" #include "../mem.h" #include "../nvr.h" +#include "../plat.h" #include "vid_ati_eeprom.h" @@ -76,24 +77,27 @@ enum void ati_eeprom_load(ati_eeprom_t *eeprom, wchar_t *fn, int type) { FILE *f; + eeprom->type = type; + memset(eeprom->data, 0, eeprom->type ? 512 : 128); + wcscpy(eeprom->fn, fn); - f = nvr_fopen(eeprom->fn, L"rb"); - if (!f) + f = plat_fopen(nvr_path(eeprom->fn), L"rb"); + if (f != NULL) { - memset(eeprom->data, 0, eeprom->type ? 512 : 128); - return; + (void)fread(eeprom->data, 1, eeprom->type ? 512 : 128, f); + fclose(f); } - fread(eeprom->data, 1, eeprom->type ? 512 : 128, f); - fclose(f); } void ati_eeprom_save(ati_eeprom_t *eeprom) { - FILE *f = nvr_fopen(eeprom->fn, L"wb"); - if (!f) return; - fwrite(eeprom->data, 1, eeprom->type ? 512 : 128, f); - fclose(f); + FILE *f = plat_fopen(nvr_path(eeprom->fn), L"wb"); + + if (f != NULL) { + (void)fwrite(eeprom->data, 1, eeprom->type ? 512 : 128, f); + fclose(f); + } } void ati_eeprom_write(ati_eeprom_t *eeprom, int ena, int clk, int dat) diff --git a/src/video/vid_ati_mach64.c b/src/video/vid_ati_mach64.c index b8cb89c..b182a5d 100644 --- a/src/video/vid_ati_mach64.c +++ b/src/video/vid_ati_mach64.c @@ -8,7 +8,7 @@ * * ATi Mach64 graphics card emulation. * - * Version: @(#)vid_ati_mach64.c 1.0.8 2018/03/26 + * Version: @(#)vid_ati_mach64.c 1.0.9 2018/03/31 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -60,10 +60,10 @@ #undef CLAMP #endif -#define BIOS_ROM_PATH L"roms/video/ati/mach64/bios.bin" -#define BIOS_ISA_ROM_PATH L"roms/video/ati/mach64/m64-1994.vbi" -#define BIOS_VLB_ROM_PATH L"roms/video/ati/mach64/mach64_vlb_vram.bin" -#define BIOS_ROMVT2_PATH L"roms/video/ati/mach64/atimach64vt2pci.bin" +#define BIOS_ROM_PATH L"video/ati/mach64/bios.bin" +#define BIOS_ISA_ROM_PATH L"video/ati/mach64/m64-1994.vbi" +#define BIOS_VLB_ROM_PATH L"video/ati/mach64/mach64_vlb_vram.bin" +#define BIOS_ROMVT2_PATH L"video/ati/mach64/atimach64vt2pci.bin" #define FIFO_SIZE 65536 diff --git a/src/video/vid_cl54xx.c b/src/video/vid_cl54xx.c index e107ca0..aa846d5 100644 --- a/src/video/vid_cl54xx.c +++ b/src/video/vid_cl54xx.c @@ -9,7 +9,7 @@ * Emulation of select Cirrus Logic cards (CL-GD 5428, * CL-GD 5429, 5430, 5434 and 5436 are supported). * - * Version: @(#)vid_cl54xx.c 1.0.13 2018/03/26 + * Version: @(#)vid_cl54xx.c 1.0.14 2018/03/31 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -59,17 +59,17 @@ #include "vid_cl54xx.h" -#define BIOS_GD5426_PATH L"roms/video/cirruslogic/diamond speedstar pro vlb v3.04.bin" -#define BIOS_GD5428_ISA_PATH L"roms/video/cirruslogic/gd5428.bin" -#define BIOS_GD5428_VLB_PATH L"roms/video/cirruslogic/vlbusjapan.bin" -#define BIOS_GD5429_PATH L"roms/video/cirruslogic/gd5429.vbi" -#define BIOS_GD5430_VLB_PATH L"roms/video/cirruslogic/diamondvlbus.bin" -#define BIOS_GD5430_PCI_PATH L"roms/video/cirruslogic/gd5430pci.bin" -#define BIOS_GD5434_PATH L"roms/video/cirruslogic/gd5434.bin" -#define BIOS_GD5436_PATH L"roms/video/cirruslogic/gd5436.vbi" -#define BIOS_GD5446_PATH L"roms/video/cirruslogic/gd5446bv.vbi" -#define BIOS_GD5446_STB_PATH L"roms/video/cirruslogic/stb_nitro64v.bin" -#define BIOS_GD5480_PATH L"roms/video/cirruslogic/gd5480.rom" +#define BIOS_GD5426_PATH L"video/cirruslogic/diamond speedstar pro vlb v3.04.bin" +#define BIOS_GD5428_ISA_PATH L"video/cirruslogic/gd5428.bin" +#define BIOS_GD5428_VLB_PATH L"video/cirruslogic/vlbusjapan.bin" +#define BIOS_GD5429_PATH L"video/cirruslogic/gd5429.vbi" +#define BIOS_GD5430_VLB_PATH L"video/cirruslogic/diamondvlbus.bin" +#define BIOS_GD5430_PCI_PATH L"video/cirruslogic/gd5430pci.bin" +#define BIOS_GD5434_PATH L"video/cirruslogic/gd5434.bin" +#define BIOS_GD5436_PATH L"video/cirruslogic/gd5436.vbi" +#define BIOS_GD5446_PATH L"video/cirruslogic/gd5446bv.vbi" +#define BIOS_GD5446_STB_PATH L"video/cirruslogic/stb_nitro64v.bin" +#define BIOS_GD5480_PATH L"video/cirruslogic/gd5480.rom" #define CIRRUS_ID_CLGD5426 0x90 #define CIRRUS_ID_CLGD5428 0x98 diff --git a/src/video/vid_ega.c b/src/video/vid_ega.c index 241dc68..e377040 100644 --- a/src/video/vid_ega.c +++ b/src/video/vid_ega.c @@ -9,7 +9,7 @@ * Emulation of the EGA, Chips & Technologies SuperEGA, and * AX JEGA graphics cards. * - * Version: @(#)vid_ega.c 1.0.4 2018/03/15 + * Version: @(#)vid_ega.c 1.0.5 2018/03/31 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -55,9 +55,9 @@ #include "vid_ega_render.h" -#define BIOS_IBM_PATH L"roms/video/ibm/ega/ibm_6277356_ega_card_u44_27128.bin" -#define BIOS_CPQ_PATH L"roms/video/compaq/ega/108281-001.bin" -#define BIOS_SEGA_PATH L"roms/video/phoenix/ega/lega.vbi" +#define BIOS_IBM_PATH L"video/ibm/ega/ibm_6277356_ega_card_u44_27128.bin" +#define BIOS_CPQ_PATH L"video/compaq/ega/108281-001.bin" +#define BIOS_SEGA_PATH L"video/phoenix/ega/lega.vbi" enum { @@ -1158,8 +1158,8 @@ void *jega_standalone_init(const device_t *info) { ega_t *ega = (ega_t *)ega_standalone_init(info); - LoadFontxFile(L"roms/video/ibm/ega/JPNHN19X.FNT"); - LoadFontxFile(L"roms/video/ibm/ega/JPNZN16X.FNT"); + LoadFontxFile(L"video/ibm/ega/jpnhn19x.fnt"); + LoadFontxFile(L"video/ibm/ega/jpnzn16x.fnt"); ega->is_jega = 1; diff --git a/src/video/vid_et4000.c b/src/video/vid_et4000.c index 90d161e..60ae459 100644 --- a/src/video/vid_et4000.c +++ b/src/video/vid_et4000.c @@ -8,7 +8,7 @@ * * Emulation of the Tseng Labs ET4000. * - * Version: @(#)vid_et4000.c 1.0.4 2018/03/15 + * Version: @(#)vid_et4000.c 1.0.5 2018/03/31 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -52,7 +52,7 @@ #include "vid_et4000.h" -#define BIOS_ROM_PATH L"roms/video/tseng/et4000/et4000.bin" +#define BIOS_ROM_PATH L"video/tseng/et4000/et4000.bin" typedef struct et4000_t diff --git a/src/video/vid_et4000w32.c b/src/video/vid_et4000w32.c index b723d5f..8217e9d 100644 --- a/src/video/vid_et4000w32.c +++ b/src/video/vid_et4000w32.c @@ -10,7 +10,7 @@ * * Known bugs: Accelerator doesn't work in planar modes * - * Version: @(#)vid_et4000w32.c 1.0.5 2018/03/26 + * Version: @(#)vid_et4000w32.c 1.0.6 2018/03/31 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -60,9 +60,9 @@ #if defined(DEV_BRANCH) && defined(USE_STEALTH32) -# define BIOS_ROM_PATH_DIAMOND L"roms/video/tseng/et4000w32/et4000w32.bin" +# define BIOS_ROM_PATH_DIAMOND L"video/tseng/et4000w32/et4000w32.bin" #endif -#define BIOS_ROM_PATH_CARDEX L"roms/video/tseng/et4000w32/cardex.vbi" +#define BIOS_ROM_PATH_CARDEX L"video/tseng/et4000w32/cardex.vbi" #define FIFO_SIZE 65536 diff --git a/src/video/vid_genius.c b/src/video/vid_genius.c index abcd9d0..e2eb41d 100644 --- a/src/video/vid_genius.c +++ b/src/video/vid_genius.c @@ -63,7 +63,7 @@ * reducing the height of characters so they fit in an 8x12 cell * if necessary. * - * Version: @(#)vid_genius.c 1.0.3 2018/03/15 + * Version: @(#)vid_genius.c 1.0.4 2018/03/31 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -108,7 +108,7 @@ #include "vid_genius.h" -#define BIOS_ROM_PATH L"roms/video/mdsi/genius/8x12.bin" +#define BIOS_ROM_PATH L"video/mdsi/genius/8x12.bin" #define GENIUS_XSIZE 728 diff --git a/src/video/vid_oak_oti.c b/src/video/vid_oak_oti.c index a85d945..91945c3 100644 --- a/src/video/vid_oak_oti.c +++ b/src/video/vid_oak_oti.c @@ -8,7 +8,7 @@ * * Oak OTI037C/67/077 emulation. * - * Version: @(#)vid_oak_oti.c 1.0.7 2018/03/26 + * Version: @(#)vid_oak_oti.c 1.0.8 2018/03/31 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -51,11 +51,11 @@ #include "vid_svga.h" -#define BIOS_37C_PATH L"roms/video/oti/oti037c/bios.bin" +#define BIOS_37C_PATH L"video/oti/oti037c/bios.bin" #if 0 -# define BIOS_67_PATH L"roms/video/oti/bios.bin" +# define BIOS_67_PATH L"video/oti/bios.bin" #endif -#define BIOS_77_PATH L"roms/video/oti/oti077.vbi" +#define BIOS_77_PATH L"video/oti/oti077.vbi" typedef struct { diff --git a/src/video/vid_paradise.c b/src/video/vid_paradise.c index 6c79450..9661fe9 100644 --- a/src/video/vid_paradise.c +++ b/src/video/vid_paradise.c @@ -13,7 +13,7 @@ * NOTE: The MegaPC video device should be moved to the MegaPC * machine file. * - * Version: @(#)vid_paradise.c 1.0.3 2018/03/15 + * Version: @(#)vid_paradise.c 1.0.4 2018/03/31 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -410,7 +410,7 @@ static void *paradise_pvga1a_pc2086_init(const device_t *info) paradise_t *paradise = paradise_pvga1a_init(info, 1 << 18); if (paradise) - rom_init(¶dise->bios_rom, L"roms/machines/pc2086/40186.ic171", 0xc0000, 0x8000, 0x7fff, 0, MEM_MAPPING_EXTERNAL); + rom_init(¶dise->bios_rom, L"machines/pc2086/40186.ic171", 0xc0000, 0x8000, 0x7fff, 0, MEM_MAPPING_EXTERNAL); return paradise; } @@ -419,7 +419,7 @@ static void *paradise_pvga1a_pc3086_init(const device_t *info) paradise_t *paradise = paradise_pvga1a_init(info, 1 << 18); if (paradise) - rom_init(¶dise->bios_rom, L"roms/machines/pc3086/c000.bin", 0xc0000, 0x8000, 0x7fff, 0, MEM_MAPPING_EXTERNAL); + rom_init(¶dise->bios_rom, L"machines/pc3086/c000.bin", 0xc0000, 0x8000, 0x7fff, 0, MEM_MAPPING_EXTERNAL); return paradise; } @@ -435,14 +435,14 @@ static void *paradise_pvga1a_standalone_init(const device_t *info) paradise = paradise_pvga1a_init(info, memory); if (paradise) - rom_init(¶dise->bios_rom, L"roms/video/paradise/pvga1a/bios.bin", 0xc0000, 0x8000, 0x7fff, 0, MEM_MAPPING_EXTERNAL); + rom_init(¶dise->bios_rom, L"video/paradise/pvga1a/bios.bin", 0xc0000, 0x8000, 0x7fff, 0, MEM_MAPPING_EXTERNAL); return paradise; } static int paradise_pvga1a_standalone_available(void) { - return rom_present(L"roms/video/paradise/pvga1a/bios.bin"); + return rom_present(L"video/paradise/pvga1a/bios.bin"); } static void *paradise_wd90c11_megapc_init(const device_t *info) @@ -451,8 +451,8 @@ static void *paradise_wd90c11_megapc_init(const device_t *info) if (paradise) rom_init_interleaved(¶dise->bios_rom, - L"roms/machines/amstrad/megapc/41651-bios lo.u18", - L"roms/machines/amstrad/megapc/211253-bios hi.u19", + L"machines/amstrad/megapc/41651-bios lo.u18", + L"machines/amstrad/megapc/211253-bios hi.u19", 0xc0000, 0x8000, 0x7fff, 0, MEM_MAPPING_EXTERNAL); return paradise; @@ -463,14 +463,14 @@ static void *paradise_wd90c11_standalone_init(const device_t *info) paradise_t *paradise = paradise_wd90c11_init(info); if (paradise) - rom_init(¶dise->bios_rom, L"roms/video/wd/wd90c11/wd90c11.vbi", 0xc0000, 0x8000, 0x7fff, 0, MEM_MAPPING_EXTERNAL); + rom_init(¶dise->bios_rom, L"video/wd/wd90c11/wd90c11.vbi", 0xc0000, 0x8000, 0x7fff, 0, MEM_MAPPING_EXTERNAL); return paradise; } static int paradise_wd90c11_standalone_available(void) { - return rom_present(L"roms/video/wd/wd90c11/wd90c11.vbi"); + return rom_present(L"video/wd/wd90c11/wd90c11.vbi"); } static void *paradise_wd90c30_standalone_init(const device_t *info) @@ -484,14 +484,14 @@ static void *paradise_wd90c30_standalone_init(const device_t *info) paradise = paradise_wd90c30_init(info, memory); if (paradise) - rom_init(¶dise->bios_rom, L"roms/video/wd/wd90c30/90c30-lr.vbi", 0xc0000, 0x8000, 0x7fff, 0, MEM_MAPPING_EXTERNAL); + rom_init(¶dise->bios_rom, L"video/wd/wd90c30/90c30-lr.vbi", 0xc0000, 0x8000, 0x7fff, 0, MEM_MAPPING_EXTERNAL); return paradise; } static int paradise_wd90c30_standalone_available(void) { - return rom_present(L"roms/video/wd/wd90c30/90c30-lr.vbi"); + return rom_present(L"video/wd/wd90c30/90c30-lr.vbi"); } void paradise_close(void *p) diff --git a/src/video/vid_s3.c b/src/video/vid_s3.c index d9d051f..65db5ee 100644 --- a/src/video/vid_s3.c +++ b/src/video/vid_s3.c @@ -10,7 +10,7 @@ * * NOTE: ROM images need more/better organization per chipset. * - * Version: @(#)vid_s3.c 1.0.6 2018/03/21 + * Version: @(#)vid_s3.c 1.0.7 2018/03/11 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -2366,29 +2366,29 @@ void *s3_vision864_init(const device_t *info, wchar_t *bios_fn) static void *s3_bahamas64_init(const device_t *info) { - s3_t *s3 = s3_vision864_init(info, L"roms/video/s3/s3/bahamas64.bin"); + s3_t *s3 = s3_vision864_init(info, L"video/s3/s3/bahamas64.bin"); return s3; } static void *s3_phoenix_vision864_init(const device_t *info) { - s3_t *s3 = s3_vision864_init(info, L"roms/video/s3/s3/86c864p.bin"); + s3_t *s3 = s3_vision864_init(info, L"video/s3/s3/86c864p.bin"); return s3; } static int s3_bahamas64_available(void) { - return rom_present(L"roms/video/s3/s3/bahamas64.bin"); + return rom_present(L"video/s3/s3/bahamas64.bin"); } static int s3_phoenix_vision864_available(void) { - return rom_present(L"roms/video/s3/s3/86c864p.bin"); + return rom_present(L"video/s3/s3/86c864p.bin"); } static void *s3_phoenix_trio32_init(const device_t *info) { - s3_t *s3 = s3_init(info, L"roms/video/s3/s3/86c732p.bin", S3_TRIO32); + s3_t *s3 = s3_init(info, L"video/s3/s3/86c732p.bin", S3_TRIO32); s3->id = 0xe1; /*Trio32*/ s3->id_ext = 0x10; @@ -2403,7 +2403,7 @@ static void *s3_phoenix_trio32_init(const device_t *info) static int s3_phoenix_trio32_available(void) { - return rom_present(L"roms/video/s3/s3/86c732p.bin"); + return rom_present(L"video/s3/s3/86c732p.bin"); } static void *s3_trio64_init(const device_t *info, wchar_t *bios_fn) @@ -2422,13 +2422,13 @@ static void *s3_trio64_init(const device_t *info, wchar_t *bios_fn) static void *s3_9fx_init(const device_t *info) { - s3_t *s3 = s3_trio64_init(info, L"roms/video/s3/s3/s3_764.bin"); + s3_t *s3 = s3_trio64_init(info, L"video/s3/s3/s3_764.bin"); return s3; } static void *s3_phoenix_trio64_init(const device_t *info) { - s3_t *s3 = s3_trio64_init(info, L"roms/video/s3/s3/86c764x1.bin"); + s3_t *s3 = s3_trio64_init(info, L"video/s3/s3/86c764x1.bin"); if (device_get_config_int("memory") == 1) s3->svga.vram_max = 1 << 20; /*Phoenix BIOS does not expect VRAM to be mirrored*/ return s3; @@ -2444,7 +2444,7 @@ static void *s3_phoenix_trio64_onboard_init(const device_t *info) static void *s3_diamond_stealth64_init(const device_t *info) { - s3_t *s3 = s3_trio64_init(info, L"roms/video/s3/s3/stealt64.bin"); + s3_t *s3 = s3_trio64_init(info, L"video/s3/s3/stealt64.bin"); if (device_get_config_int("memory") == 1) s3->svga.vram_max = 1 << 20; /*Phoenix BIOS does not expect VRAM to be mirrored*/ return s3; @@ -2452,17 +2452,17 @@ static void *s3_diamond_stealth64_init(const device_t *info) static int s3_9fx_available(void) { - return rom_present(L"roms/video/s3/s3/s3_764.bin"); + return rom_present(L"video/s3/s3/s3_764.bin"); } static int s3_phoenix_trio64_available(void) { - return rom_present(L"roms/video/s3/s3/86c764x1.bin"); + return rom_present(L"video/s3/s3/86c764x1.bin"); } static int s3_diamond_stealth64_available(void) { - return rom_present(L"roms/video/s3/s3/stealt64.bin"); + return rom_present(L"video/s3/s3/stealt64.bin"); } static void s3_close(void *p) diff --git a/src/video/vid_s3_virge.c b/src/video/vid_s3_virge.c index 018fdfc..5bde40e 100644 --- a/src/video/vid_s3_virge.c +++ b/src/video/vid_s3_virge.c @@ -8,7 +8,7 @@ * * S3 ViRGE emulation. * - * Version: @(#)vid_s3_virge.c 1.0.6 2018/03/22 + * Version: @(#)vid_s3_virge.c 1.0.7 2018/03/31 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -3838,7 +3838,7 @@ static void *s3_virge_init(const device_t *info) virge->pci = !!(info->flags & DEVICE_PCI); - rom_init(&virge->bios_rom, L"roms/video/s3/s3virge/s3virge.bin", 0xc0000, 0x8000, 0x7fff, 0, MEM_MAPPING_EXTERNAL); + rom_init(&virge->bios_rom, L"video/s3/s3virge/s3virge.bin", 0xc0000, 0x8000, 0x7fff, 0, MEM_MAPPING_EXTERNAL); if (info->flags & DEVICE_PCI) mem_mapping_disable(&virge->bios_rom.mapping); @@ -3937,7 +3937,7 @@ static void *s3_virge_988_init(const device_t *info) virge->pci = !!(info->flags & DEVICE_PCI); - rom_init(&virge->bios_rom, L"roms/video/s3/s3virge/diamondstealth3000.vbi", 0xc0000, 0x8000, 0x7fff, 0, MEM_MAPPING_EXTERNAL); + rom_init(&virge->bios_rom, L"video/s3/s3virge/diamondstealth3000.vbi", 0xc0000, 0x8000, 0x7fff, 0, MEM_MAPPING_EXTERNAL); if (info->flags & DEVICE_PCI) mem_mapping_disable(&virge->bios_rom.mapping); @@ -4121,12 +4121,12 @@ static void *s3_virge_375_init(const device_t *info, wchar_t *romfn) static void *s3_virge_375_1_init(const device_t *info) { - return s3_virge_375_init(info, L"roms/video/s3/s3virge/86c375_1.bin"); + return s3_virge_375_init(info, L"video/s3/s3virge/86c375_1.bin"); } static void *s3_virge_375_4_init(const device_t *info) { - return s3_virge_375_init(info, L"roms/video/s3/s3virge/86c375_4.bin"); + return s3_virge_375_init(info, L"video/s3/s3virge/86c375_4.bin"); } static void s3_virge_close(void *p) @@ -4149,22 +4149,22 @@ static void s3_virge_close(void *p) static int s3_virge_available(void) { - return rom_present(L"roms/video/s3/s3virge/s3virge.bin"); + return rom_present(L"video/s3/s3virge/s3virge.bin"); } static int s3_virge_988_available(void) { - return rom_present(L"roms/video/s3/s3virge/diamondstealth3000.vbi"); + return rom_present(L"video/s3/s3virge/diamondstealth3000.vbi"); } static int s3_virge_375_1_available(void) { - return rom_present(L"roms/video/s3/s3virge/86c375_1.bin"); + return rom_present(L"video/s3/s3virge/86c375_1.bin"); } static int s3_virge_375_4_available(void) { - return rom_present(L"roms/video/s3/s3virge/86c375_4.bin"); + return rom_present(L"video/s3/s3virge/86c375_4.bin"); } static void s3_virge_speed_changed(void *p) diff --git a/src/video/vid_table.c b/src/video/vid_table.c index 2d323d4..c50df91 100644 --- a/src/video/vid_table.c +++ b/src/video/vid_table.c @@ -8,7 +8,7 @@ * * Define all known video cards. * - * Version: @(#)vid_table.c 1.0.12 2018/03/21 + * Version: @(#)vid_table.c 1.0.13 2018/03/31 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -214,9 +214,9 @@ video_reset(int card) cgapal_rebuild(); /* Initialize the video font tables. */ - loadfont(L"roms/video/ibm/mda/mda.rom", 0); - loadfont(L"roms/video/wyse/wyse700/wy700.rom", 3); - loadfont(L"roms/video/mdsi/genius/8x12.bin", 4); + loadfont(L"video/ibm/mda/mda.rom", 0); + loadfont(L"video/wyse/wyse700/wy700.rom", 3); + loadfont(L"video/mdsi/genius/8x12.bin", 4); /* Do not initialize internal cards here. */ if ((card == VID_NONE) || \ diff --git a/src/video/vid_tgui9440.c b/src/video/vid_tgui9440.c index c4299db..cdc5ad4 100644 --- a/src/video/vid_tgui9440.c +++ b/src/video/vid_tgui9440.c @@ -47,7 +47,7 @@ * access size or host data has any affect, but the Windows 3.1 * driver always reads bytes and write words of 0xffff. * - * Version: @(#)vid_tgui9440.c 1.0.4 2018/03/15 + * Version: @(#)vid_tgui9440.c 1.0.5 2018/03/31 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -832,22 +832,22 @@ static void *tgui_init(const device_t *info, wchar_t *bios_fn, int type) static void *tgui9400cxi_init(const device_t *info) { - return tgui_init(info, L"roms/video/trident/tgui9440/9400cxi.vbi", TGUI_9400CXI); + return tgui_init(info, L"video/trident/tgui9440/9400cxi.vbi", TGUI_9400CXI); } static void *tgui9440_init(const device_t *info) { - return tgui_init(info, L"roms/video/trident/tgui9440/9440.vbi", TGUI_9440); + return tgui_init(info, L"video/trident/tgui9440/9440.vbi", TGUI_9440); } static int tgui9400cxi_available() { - return rom_present(L"roms/video/trident/tgui9440/9400cxi.vbi"); + return rom_present(L"video/trident/tgui9440/9400cxi.vbi"); } static int tgui9440_available() { - return rom_present(L"roms/video/trident/tgui9440/9440.vbi"); + return rom_present(L"video/trident/tgui9440/9440.vbi"); } void tgui_close(void *p) diff --git a/src/video/vid_tvga.c b/src/video/vid_tvga.c index 40c49f3..d3369c5 100644 --- a/src/video/vid_tvga.c +++ b/src/video/vid_tvga.c @@ -8,7 +8,7 @@ * * Trident TVGA (8900D) emulation. * - * Version: @(#)vid_tvga.c 1.0.4 2018/03/15 + * Version: @(#)vid_tvga.c 1.0.5 2018/03/31 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -321,7 +321,7 @@ static void *tvga8900d_init(const device_t *info) tvga->vram_size = device_get_config_int("memory") << 10; tvga->vram_mask = tvga->vram_size - 1; - rom_init(&tvga->bios_rom, L"roms/video/trident/tvga/trident.bin", 0xc0000, 0x8000, 0x7fff, 0, MEM_MAPPING_EXTERNAL); + rom_init(&tvga->bios_rom, L"video/trident/tvga/trident.bin", 0xc0000, 0x8000, 0x7fff, 0, MEM_MAPPING_EXTERNAL); svga_init(&tvga->svga, tvga, tvga->vram_size, tvga_recalctimings, @@ -336,7 +336,7 @@ static void *tvga8900d_init(const device_t *info) static int tvga8900d_available(void) { - return rom_present(L"roms/video/trident/tvga/trident.bin"); + return rom_present(L"video/trident/tvga/trident.bin"); } void tvga_close(void *p) diff --git a/src/video/vid_vga.c b/src/video/vid_vga.c index c916c23..22819f3 100644 --- a/src/video/vid_vga.c +++ b/src/video/vid_vga.c @@ -8,7 +8,7 @@ * * IBM VGA emulation. * - * Version: @(#)vid_vga.c 1.0.3 2018/03/15 + * Version: @(#)vid_vga.c 1.0.4 2018/03/31 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -122,7 +122,7 @@ static void *vga_init(const device_t *info) vga_t *vga = malloc(sizeof(vga_t)); memset(vga, 0, sizeof(vga_t)); - rom_init(&vga->bios_rom, L"roms/video/ibm/vga/ibm_vga.bin", 0xc0000, 0x8000, 0x7fff, 0x2000, MEM_MAPPING_EXTERNAL); + rom_init(&vga->bios_rom, L"video/ibm/vga/ibm_vga.bin", 0xc0000, 0x8000, 0x7fff, 0x2000, MEM_MAPPING_EXTERNAL); svga_init(&vga->svga, vga, 1 << 18, /*256kb*/ NULL, @@ -145,7 +145,7 @@ static void *trigem_unk_init(const device_t *info) vga_t *vga = malloc(sizeof(vga_t)); memset(vga, 0, sizeof(vga_t)); - rom_init(&vga->bios_rom, L"roms/video/ibm/vga/ibm_vga.bin", 0xc0000, 0x8000, 0x7fff, 0x2000, MEM_MAPPING_EXTERNAL); + rom_init(&vga->bios_rom, L"video/ibm/vga/ibm_vga.bin", 0xc0000, 0x8000, 0x7fff, 0x2000, MEM_MAPPING_EXTERNAL); svga_init(&vga->svga, vga, 1 << 18, /*256kb*/ NULL, @@ -188,7 +188,7 @@ void *ps1vga_init(const device_t *info) static int vga_available(void) { - return rom_present(L"roms/video/ibm/vga/ibm_vga.bin"); + return rom_present(L"video/ibm/vga/ibm_vga.bin"); } void vga_close(void *p) diff --git a/src/video/vid_voodoo.c b/src/video/vid_voodoo.c index 6b7b845..01a547a 100644 --- a/src/video/vid_voodoo.c +++ b/src/video/vid_voodoo.c @@ -8,7 +8,7 @@ * * Emulation of the 3DFX Voodoo Graphics controller. * - * Version: @(#)vid_voodoo.c 1.0.5 2018/03/17 + * Version: @(#)vid_voodoo.c 1.0.6 2018/03/31 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -7860,14 +7860,20 @@ void voodoo_card_close(voodoo_t *voodoo) int c; #ifndef RELEASE_BUILD - f = nvr_fopen(L"texram.dmp", L"wb"); - fwrite(voodoo->tex_mem[0], voodoo->texture_size*1024*1024, 1, f); - fclose(f); + f = plat_fopen(nvr_path(L"texram.dmp"), L"wb"); + if (f != NULL) + { + (void)fwrite(voodoo->tex_mem[0], voodoo->texture_size*1024*1024, 1, f); + fclose(f); + } if (voodoo->dual_tmus) { - f = nvr_fopen(L"texram2.dmp", L"wb"); - fwrite(voodoo->tex_mem[1], voodoo->texture_size*1024*1024, 1, f); - fclose(f); + f = plat_fopen(nvr_path(L"texram2.dmp"), L"wb"); + if (f != NULL) + { + (void)fwrite(voodoo->tex_mem[1], voodoo->texture_size*1024*1024, 1, f); + fclose(f); + } } #endif diff --git a/src/video/video.c b/src/video/video.c index a608027..c0b6cc8 100644 --- a/src/video/video.c +++ b/src/video/video.c @@ -40,7 +40,7 @@ * W = 3 bus clocks * L = 4 bus clocks * - * Version: @(#)video.c 1.0.8 2018/03/21 + * Version: @(#)video.c 1.0.10 2018/03/31 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -713,7 +713,7 @@ loadfont(wchar_t *s, int format) FILE *f; int c,d; - f = rom_fopen(s); + f = plat_fopen(rom_path(s), L"rb"); if (f == NULL) { pclog("VIDEO: cannot load font '%ls', fmt=%d\n", s, format); return; diff --git a/src/video/video.h b/src/video/video.h index 6a65114..5fa3b2a 100644 --- a/src/video/video.h +++ b/src/video/video.h @@ -8,7 +8,7 @@ * * Definitions for the video controller module. * - * Version: @(#)video.h 1.0.11 2018/03/27 + * Version: @(#)video.h 1.0.12 2018/03/31 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -40,7 +40,7 @@ # define EMU_VIDEO_H -#define FONT_ATIKOR_PATH L"roms/video/ati/ati28800/ati_ksc5601.rom" +#define FONT_ATIKOR_PATH L"video/ati/ati28800/ati_ksc5601.rom" #define makecol(r, g, b) ((b) | ((g) << 8) | ((r) << 16)) diff --git a/src/win/VARCem.rc b/src/win/VARCem.rc index 95af334..db6f95a 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.9 2018/03/28 + * Version: @(#)VARCem.rc 1.0.11 2018/03/31 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -66,8 +66,6 @@ MainMenu MENU DISCARDABLE BEGIN POPUP "&Action" BEGIN - MENUITEM "&Right CTRL is left ALT", IDM_ACTION_RCTRL_IS_LALT - MENUITEM SEPARATOR MENUITEM "&Hard Reset", IDM_ACTION_HRESET MENUITEM "&Ctrl+Alt+Del\tCtrl+F12", IDM_ACTION_RESET_CAD MENUITEM SEPARATOR @@ -133,6 +131,8 @@ BEGIN MENUITEM SEPARATOR MENUITEM "F&orce 4:3 display ratio", IDM_VID_FORCE43 MENUITEM "Change contrast for &monochrome display", IDM_VID_CGACON + MENUITEM SEPARATOR + MENUITEM "R&ight CTRL is left ALT", IDM_KBD_RCTRL_IS_LALT END POPUP "&Tools" BEGIN @@ -631,13 +631,7 @@ END // Icon with lowest ID value placed first to ensure application icon // remains consistent on all systems. -#ifdef RELEASE_BUILD -/* Icon by Devcore - https://commons.wikimedia.org/wiki/File:Icon_PC_256x256.png */ -100 ICON DISCARDABLE "win/icons/emu-rb.ico" -#else -/* Icon by Devcore - https://commons.wikimedia.org/wiki/File:Icon_PC2_256x256.png */ -100 ICON DISCARDABLE "win/icons/emu.ico" -#endif +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" @@ -966,7 +960,7 @@ BEGIN IDS_2154 "Unable to register Raw Input!" IDS_2155 "IRQ %i" IDS_2156 "%" PRIu64 - IDS_2157 "%" PRIu64 " MB (CHS: %" PRIu64 ", %" PRIu64 ", %" PRIu64 ")" + 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" @@ -1077,8 +1071,13 @@ END // VS_VERSION_INFO VERSIONINFO +#ifdef EMU_VER_PATCH + FILEVERSION EMU_VER_MAJOR,EMU_VER_MINOR,EMU_VER_REV,EMU_VER_PATCH + PRODUCTVERSION EMU_VER_MAJOR,EMU_VER_MINOR,EMU_VER_REV,EMU_VER_PATCH +#else FILEVERSION EMU_VER_MAJOR,EMU_VER_MINOR,EMU_VER_REV,0 PRODUCTVERSION EMU_VER_MAJOR,EMU_VER_MINOR,EMU_VER_REV,0 +#endif FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x1L diff --git a/src/win/icons/.attic/amu_2.ico b/src/win/icons/.attic/amu_2.ico new file mode 100644 index 0000000..8d98359 Binary files /dev/null and b/src/win/icons/.attic/amu_2.ico differ diff --git a/src/win/icons/.attic/chip-32x32.ico b/src/win/icons/.attic/chip-32x32.ico new file mode 100644 index 0000000..2c732fb Binary files /dev/null and b/src/win/icons/.attic/chip-32x32.ico differ diff --git a/src/win/icons/.attic/chip2-32x32.ico b/src/win/icons/.attic/chip2-32x32.ico new file mode 100644 index 0000000..a64b20d Binary files /dev/null and b/src/win/icons/.attic/chip2-32x32.ico differ diff --git a/src/win/icons/emu-rb.ico b/src/win/icons/.attic/emu-rb.ico similarity index 100% rename from src/win/icons/emu-rb.ico rename to src/win/icons/.attic/emu-rb.ico diff --git a/src/win/icons/emu.ico b/src/win/icons/.attic/emu.ico similarity index 100% rename from src/win/icons/emu.ico rename to src/win/icons/.attic/emu.ico diff --git a/src/win/icons/varcem.ico b/src/win/icons/varcem.ico new file mode 100644 index 0000000..8d179fe Binary files /dev/null and b/src/win/icons/varcem.ico differ diff --git a/src/win/mingw/Makefile.MinGW b/src/win/mingw/Makefile.MinGW index a0241c9..9622da2 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.17 2018/03/27 +# Version: @(#)Makefile.mingw 1.0.18 2018/03/31 # # Author: Fred N. van Kempen, # @@ -240,6 +240,9 @@ else endif PREPROC := cpp WINDRES := windres + ifndef CAT + CAT := cat + endif SYSINC := -Iwin/mingw/include SYSLIB := @@ -688,6 +691,9 @@ ifneq ($(DEBUG), y) @strip hello.exe endif +foo.exe: foo.o + @$(CC) $(LDFLAGS) -o foo.exe \ + foo.o $(LIBS) clean: @echo Cleaning objects.. @@ -712,8 +718,8 @@ depclean: depends: DEPOBJ=$(OBJ:%.o=%.d) depends: depclean $(OBJ:%.o=%.d) - @-cat $(DEPOBJ) >>$(DEPFILE) - @-rm -f $(DEPOBJ) + @$(CAT) $(DEPOBJ) >>$(DEPFILE) +# @-rm -f $(DEPOBJ) $(DEPFILE): endif diff --git a/src/win/msvc/vc14/VARCem.vcxproj b/src/win/msvc/vc14/VARCem.vcxproj index c151fd4..f3e8086 100644 --- a/src/win/msvc/vc14/VARCem.vcxproj +++ b/src/win/msvc/vc14/VARCem.vcxproj @@ -659,25 +659,21 @@ true - $(ProjectDir)\..\Include;$(ProjectDir)\..\..\mingw\include;$(ProjectDir)\..\..\mingw\include\pcap;$(IncludePath) - $(ProjectDir)\..\Lib\x86;$(VC_LibraryPath_x86);$(WindowsSDK_LibraryPath_x86);$(NETFXKitsDir)Lib\um\x86 + $(ProjectDir)\..\Lib\x86;$(VC_LibraryPath_x86);$(WindowsSDK_LibraryPath_x86) true false - $(ProjectDir)\..\Include;$(ProjectDir)\..\..\mingw\include;$(ProjectDir)\..\..\mingw\include\pcap;$(IncludePath) - $(ProjectDir)\..\Lib\x64;$(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64);$(NETFXKitsDir)Lib\um\x64 + $(ProjectDir)\..\Lib\x64;$(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64) false - $(ProjectDir)\..\Include;$(ProjectDir)\..\..\mingw\include;$(ProjectDir)\..\..\mingw\include\pcap;$(IncludePath) - $(ProjectDir)\..\Lib\x86;$(VC_LibraryPath_x86);$(WindowsSDK_LibraryPath_x86);$(NETFXKitsDir)Lib\um\x86 + $(ProjectDir)\..\Lib\x86;$(VC_LibraryPath_x86);$(WindowsSDK_LibraryPath_x86) false false - $(ProjectDir)\..\Include;$(ProjectDir)\..\..\mingw\include;$(ProjectDir)\..\..\mingw\include\pcap;$(IncludePath) - $(ProjectDir)\..\Lib\x64;$(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64);$(NETFXKitsDir)Lib\um\x64 + $(ProjectDir)\..\Lib\x64;$(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64) diff --git a/src/win/msvc/vc14/global.props b/src/win/msvc/vc14/global.props index 1384760..d29a058 100644 --- a/src/win/msvc/vc14/global.props +++ b/src/win/msvc/vc14/global.props @@ -3,7 +3,7 @@ - $(ProjectDir)\..\..\mingw\include;$(ProjectDir)\..\..\mingw\include\pcap;$(IncludePath) + $(ProjectDir)\..\Include;$(ProjectDir)\..\..\mingw\include;$(ProjectDir)\..\..\mingw\include\pcap;$(IncludePath) diff --git a/src/win/msvc/vc15/VARCem.vcxproj b/src/win/msvc/vc15/VARCem.vcxproj index 7f36393..a006272 100644 --- a/src/win/msvc/vc15/VARCem.vcxproj +++ b/src/win/msvc/vc15/VARCem.vcxproj @@ -659,16 +659,20 @@ true + $(ProjectDir)\..\Lib\x86;$(VC_LibraryPath_x86);$(WindowsSDK_LibraryPath_x86) true + $(ProjectDir)\..\Lib\x64;$(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64) false false + $(ProjectDir)\..\Lib\x86;$(VC_LibraryPath_x86);$(WindowsSDK_LibraryPath_x86) false + $(ProjectDir)\..\Lib\x64;$(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64) false @@ -756,4 +760,4 @@ - \ No newline at end of file + diff --git a/src/win/msvc/vc15/global.props b/src/win/msvc/vc15/global.props index 1384760..d29a058 100644 --- a/src/win/msvc/vc15/global.props +++ b/src/win/msvc/vc15/global.props @@ -3,7 +3,7 @@ - $(ProjectDir)\..\..\mingw\include;$(ProjectDir)\..\..\mingw\include\pcap;$(IncludePath) + $(ProjectDir)\..\Include;$(ProjectDir)\..\..\mingw\include;$(ProjectDir)\..\..\mingw\include\pcap;$(IncludePath) diff --git a/src/win/pcap_if.rc b/src/win/pcap_if.rc index 92ecd74..6d83bb5 100644 --- a/src/win/pcap_if.rc +++ b/src/win/pcap_if.rc @@ -10,7 +10,7 @@ * * NOTE: Will be moved to the tools/ folder soon. * - * Version: @(#)pcap_if.rc 1.0.1 2018/02/14 + * Version: @(#)pcap_if.rc 1.0.3 2018/03/30 * * Author: Fred N. van Kempen, * @@ -53,20 +53,12 @@ LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US #endif //_WIN32 -/* - * Icons by Devcore - * - https://commons.wikimedia.org/wiki/File:Icon_PC_256x256.png - */ -#ifdef RELEASE_BUILD -100 ICON DISCARDABLE "win/icons/emu-rb.ico" -#else -100 ICON DISCARDABLE "win/icons/emu.ico" -#endif +100 ICON DISCARDABLE "win/icons/varcem.ico" VS_VERSION_INFO VERSIONINFO - FILEVERSION 1,0,2,0 - PRODUCTVERSION 1,0,2,0 + FILEVERSION 1,0,3,0 + PRODUCTVERSION 1,0,3,0 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x1L @@ -81,18 +73,14 @@ BEGIN BEGIN BLOCK "040904b0" BEGIN - VALUE "Comments", "\0" - VALUE "CompanyName", "IRC #VARCem on FreeNode\0" - VALUE "FileDescription", "PCap_IF - test tool for WinPcap\0" - VALUE "FileVersion", "1.0.2\0" - VALUE "InternalName", "pcap_if\0" - VALUE "LegalCopyright", "Copyright 2017,2018 Fred N. van Kempen\0" - VALUE "LegalTrademarks", "\0" - VALUE "OriginalFilename", "pcap_if.exe\0" - VALUE "PrivateBuild", "\0" - VALUE "ProductName", "WinPcap Test Tool\0" - VALUE "ProductVersion", "1.0.2\0" - VALUE "SpecialBuild", "\0" + VALUE "CompanyName", "IRC #VARCem on FreeNode" + VALUE "FileDescription", "PCap_IF - test tool for WinPcap" + VALUE "FileVersion", "1.0.3" + VALUE "InternalName", "pcap_if" + VALUE "LegalCopyright", "Copyright 2017,2018 Fred N. van Kempen" + VALUE "OriginalFilename", "pcap_if.exe" + VALUE "ProductName", "WinPcap Test Tool" + VALUE "ProductVersion", "1.0.3" END END BLOCK "VarFileInfo" diff --git a/src/win/resource.h b/src/win/resource.h index 5ebb120..af2c251 100644 --- a/src/win/resource.h +++ b/src/win/resource.h @@ -8,7 +8,7 @@ * * Windows resource defines. * - * Version: @(#)resource.h 1.0.6 2018/03/25 + * Version: @(#)resource.h 1.0.7 2018/03/31 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -249,7 +249,6 @@ #define IDM_ABOUT 40001 #define IDC_ABOUT_ICON 65535 -#define IDM_ACTION_RCTRL_IS_LALT 40010 #define IDM_ACTION_SCREENSHOT 40011 #define IDM_ACTION_HRESET 40012 #define IDM_ACTION_RESET_CAD 40013 @@ -289,6 +288,7 @@ #define IDM_VID_GRAY_AMBER 40092 #define IDM_VID_GRAY_GREEN 40093 #define IDM_VID_GRAY_WHITE 40094 +#define IDM_KBD_RCTRL_IS_LALT 40101 #define IDM_LOG_BREAKPOINT 51201 #define IDM_DUMP_VRAM 51202 // should be an Action diff --git a/src/win/win.c b/src/win/win.c index 5df4f1d..97967af 100644 --- a/src/win/win.c +++ b/src/win/win.c @@ -8,7 +8,7 @@ * * Platform main support module for Windows. * - * Version: @(#)win.c 1.0.9 2018/03/20 + * Version: @(#)win.c 1.0.10 2018/03/31 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -249,10 +249,75 @@ plat_get_string(int i) } +/* Process the commandline, and create standard argc/argv array. */ +static int +ProcessCommandLine(wchar_t ***argw) +{ + WCHAR *cmdline; + wchar_t *argbuf; + wchar_t **args; + int argc_max; + int i, q, argc; + + cmdline = GetCommandLine(); + i = wcslen(cmdline) + 1; + argbuf = (wchar_t *)malloc(sizeof(wchar_t)*i); + wcscpy(argbuf, cmdline); + + argc = 0; + argc_max = 64; + args = (wchar_t **)malloc(sizeof(wchar_t *) * argc_max); + if (args == NULL) { + free(argbuf); + return(0); + } + + /* parse commandline into argc/argv format */ + i = 0; + while (argbuf[i]) { + while (argbuf[i] == L' ') + i++; + + if (argbuf[i]) { + if ((argbuf[i] == L'\'') || (argbuf[i] == L'"')) { + q = argbuf[i++]; + if (!argbuf[i]) + break; + } else + q = 0; + + args[argc++] = &argbuf[i]; + + if (argc >= argc_max) { + argc_max += 64; + args = realloc(args, sizeof(wchar_t *)*argc_max); + if (args == NULL) { + free(argbuf); + return(0); + } + } + + while ((argbuf[i]) && ((q) + ? (argbuf[i]!=q) : (argbuf[i]!=L' '))) i++; + + if (argbuf[i]) { + argbuf[i] = 0; + i++; + } + } + } + + args[argc] = NULL; + *argw = args; + + return(argc); +} + + #ifndef USE_WX /* Create a console if we don't already have one. */ -static void -CreateConsole(int init) +void +plat_console(int init) { HANDLE h; FILE *fp; @@ -334,71 +399,6 @@ CreateConsole(int init) } -/* Process the commandline, and create standard argc/argv array. */ -static int -ProcessCommandLine(wchar_t ***argw) -{ - WCHAR *cmdline; - wchar_t *argbuf; - wchar_t **args; - int argc_max; - int i, q, argc; - - cmdline = GetCommandLine(); - i = wcslen(cmdline) + 1; - argbuf = (wchar_t *)malloc(sizeof(wchar_t)*i); - wcscpy(argbuf, cmdline); - - argc = 0; - argc_max = 64; - args = (wchar_t **)malloc(sizeof(wchar_t *) * argc_max); - if (args == NULL) { - free(argbuf); - return(0); - } - - /* parse commandline into argc/argv format */ - i = 0; - while (argbuf[i]) { - while (argbuf[i] == L' ') - i++; - - if (argbuf[i]) { - if ((argbuf[i] == L'\'') || (argbuf[i] == L'"')) { - q = argbuf[i++]; - if (!argbuf[i]) - break; - } else - q = 0; - - args[argc++] = &argbuf[i]; - - if (argc >= argc_max) { - argc_max += 64; - args = realloc(args, sizeof(wchar_t *)*argc_max); - if (args == NULL) { - free(argbuf); - return(0); - } - } - - while ((argbuf[i]) && ((q) - ? (argbuf[i]!=q) : (argbuf[i]!=L' '))) i++; - - if (argbuf[i]) { - argbuf[i] = 0; - i++; - } - } - } - - args[argc] = NULL; - *argw = args; - - return(argc); -} - - /* For the Windows platform, this is the start of the application. */ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpszArg, int nCmdShow) @@ -424,7 +424,8 @@ WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpszArg, int nCmdShow) set_language(0x0409); /* Create console window. */ - CreateConsole(1); + if (force_debug) + plat_console(1); /* Process the command line for options. */ argc = ProcessCommandLine(&argw); @@ -432,13 +433,13 @@ WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpszArg, int nCmdShow) /* Pre-initialize the system, this loads the config file. */ if (! pc_init(argc, argw)) { /* Detach from console. */ - CreateConsole(0); + plat_console(0); return(1); } /* Cleanup: we may no longer need the console. */ if (! force_debug) - CreateConsole(0); + plat_console(0); /* Handle our GUI. */ i = ui_init(nCmdShow); diff --git a/src/win/win.h b/src/win/win.h index 72fc1f2..d33181d 100644 --- a/src/win/win.h +++ b/src/win/win.h @@ -8,7 +8,7 @@ * * Platform support defintions for Win32. * - * Version: @(#)win.h 1.0.5 2018/03/08 + * Version: @(#)win.h 1.0.6 2018/03/31 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -72,9 +72,8 @@ extern HICON hIcon[512]; extern int status_is_open; -extern char openfilestring[260]; -extern WCHAR wopenfilestring[260]; - +extern char openfilestring[]; +extern WCHAR wopenfilestring[]; extern DWORD filterindex; @@ -144,14 +143,8 @@ extern void StatusBarCreate(HWND hwndParent, uintptr_t idStatus, /* Functions in win_dialog.c: */ extern void dialog_center(HWND hdlg); - -extern wchar_t *BrowseFolder(wchar_t *saved_path, wchar_t *title); - -extern int file_dlg_w(HWND hwnd, WCHAR *f, WCHAR *fn, int save); -extern int file_dlg(HWND hwnd, WCHAR *f, char *fn, int save); -extern int file_dlg_mb(HWND hwnd, char *f, char *fn, int save); -extern int file_dlg_w_st(HWND hwnd, int i, WCHAR *fn, int save); -extern int file_dlg_st(HWND hwnd, int i, char *fn, int save); +extern int file_dlg(HWND hwnd, WCHAR *filt, WCHAR *ifn, int save); +extern int file_dlg_st(HWND hwnd, int i, WCHAR *fn, int save); #ifdef __cplusplus diff --git a/src/win/win_devconf.c b/src/win/win_devconf.c index 1ed2081..46192f6 100644 --- a/src/win/win_devconf.c +++ b/src/win/win_devconf.c @@ -8,7 +8,11 @@ * * Imlementation of the Device Configuration dialog. * - * Version: @(#)win_devconf.c 1.0.6 2018/03/20 + * This module takes a standard 'device_config_t' structure, + * and builds a complete Win32 DIALOG resource block in a + * buffer in memory, and then passes that to the API handler. + * + * Version: @(#)win_devconf.c 1.0.7 2018/03/31 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -52,9 +56,8 @@ #include "win.h" -static device_t *config_device; - -static uint8_t deviceconfig_changed = 0; +static device_t *config_device; +static uint8_t deviceconfig_changed = 0; #ifdef __amd64__ @@ -62,10 +65,11 @@ static LRESULT CALLBACK #else static BOOL CALLBACK #endif -deviceconfig_dlgproc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) +dlg_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) { + wchar_t ws[512]; + char s[512]; HWND h; - int val_int; int id; int c; @@ -73,26 +77,20 @@ deviceconfig_dlgproc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) int changed; int cid; const device_config_t *config; - char s[80]; - wchar_t ws[512]; LPTSTR lptsTemp; switch (message) { - case WM_INITDIALOG: - { - id = IDC_CONFIG_BASE; - config = config_device->config; + case WM_INITDIALOG: + id = IDC_CONFIG_BASE; + config = config_device->config; + lptsTemp = (LPTSTR)malloc(512); - lptsTemp = (LPTSTR) malloc(512); + while (config->type != -1) { + const device_config_selection_t *selection = config->selection; + h = GetDlgItem(hdlg, id); - while (config->type != -1) - { - const device_config_selection_t *selection = config->selection; - h = GetDlgItem(hdlg, id); - - switch (config->type) - { - case CONFIG_BINARY: + switch (config->type) { + case CONFIG_BINARY: val_int = config_get_int((char *)config_device->name, (char *)config->name, config->default_int); SendMessage(h, BM_SETCHECK, val_int, 0); @@ -100,12 +98,11 @@ deviceconfig_dlgproc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) id++; break; - case CONFIG_SELECTION: + case CONFIG_SELECTION: val_int = config_get_int((char *)config_device->name, (char *)config->name, config->default_int); c = 0; - while (selection->description && selection->description[0]) - { + while (selection->description && selection->description[0]) { mbstowcs(lptsTemp, selection->description, strlen(selection->description) + 1); SendMessage(h, CB_ADDSTRING, 0, (LPARAM)(LPCSTR)lptsTemp); if (val_int == selection->value) @@ -113,50 +110,45 @@ deviceconfig_dlgproc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) selection++; c++; } - id += 2; break; - case CONFIG_MIDI: + case CONFIG_MIDI: val_int = config_get_int((char *)config_device->name, (char *)config->name, config->default_int); num = plat_midi_get_num_devs(); - for (c = 0; c < num; c++) - { + for (c = 0; c < num; c++) { plat_midi_get_dev_name(c, s); mbstowcs(lptsTemp, s, strlen(s) + 1); SendMessage(h, CB_ADDSTRING, 0, (LPARAM)(LPCSTR)lptsTemp); if (val_int == c) SendMessage(h, CB_SETCURSEL, c, 0); } - id += 2; break; - case CONFIG_SPINNER: + case CONFIG_SPINNER: val_int = config_get_int((char *)config_device->name, (char *)config->name, config->default_int); _swprintf(ws, L"%i", val_int); SendMessage(h, WM_SETTEXT, 0, (LPARAM)ws); - id += 2; break; - case CONFIG_FNAME: + case CONFIG_FNAME: { - wchar_t* str = config_get_wstring((char *)config_device->name, (char *)config->name, 0); - if (str) - SendMessage(h, WM_SETTEXT, 0, (LPARAM)str); - id += 3; + wchar_t* str = config_get_wstring((char *)config_device->name, (char *)config->name, 0); + if (str) + SendMessage(h, WM_SETTEXT, 0, (LPARAM)str); + id += 3; } break; - case CONFIG_HEX16: + case CONFIG_HEX16: val_int = config_get_hex16((char *)config_device->name, (char *)config->name, config->default_int); c = 0; - while (selection->description && selection->description[0]) - { + while (selection->description && selection->description[0]) { mbstowcs(lptsTemp, selection->description, strlen(selection->description) + 1); SendMessage(h, CB_ADDSTRING, 0, (LPARAM)(LPCSTR)lptsTemp); if (val_int == selection->value) @@ -164,16 +156,14 @@ deviceconfig_dlgproc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) selection++; c++; } - id += 2; break; - case CONFIG_HEX20: + case CONFIG_HEX20: val_int = config_get_hex20((char *)config_device->name, (char *)config->name, config->default_int); c = 0; - while (selection->description && selection->description[0]) - { + while (selection->description && selection->description[0]) { mbstowcs(lptsTemp, selection->description, strlen(selection->description) + 1); SendMessage(h, CB_ADDSTRING, 0, (LPARAM)(LPCSTR)lptsTemp); if (val_int == selection->value) @@ -181,44 +171,36 @@ deviceconfig_dlgproc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) selection++; c++; } - id += 2; break; - } - config++; } - - free(lptsTemp); + config++; } + + free(lptsTemp); return TRUE; - case WM_COMMAND: - { - cid = LOWORD(wParam); - if (cid == IDOK) - { - id = IDC_CONFIG_BASE; - config = config_device->config; - changed = 0; - char s[512]; + case WM_COMMAND: + cid = LOWORD(wParam); + if (cid == IDOK) { + id = IDC_CONFIG_BASE; + config = config_device->config; + changed = 0; - while (config->type != -1) - { - const device_config_selection_t *selection = config->selection; - h = GetDlgItem(hdlg, id); + while (config->type != -1) { + const device_config_selection_t *selection = config->selection; + h = GetDlgItem(hdlg, id); - switch (config->type) - { - case CONFIG_BINARY: + switch (config->type) { + case CONFIG_BINARY: val_int = config_get_int((char *)config_device->name, (char *)config->name, config->default_int); if (val_int != SendMessage(h, BM_GETCHECK, 0, 0)) changed = 1; - id++; break; - case CONFIG_SELECTION: + case CONFIG_SELECTION: val_int = config_get_int((char *)config_device->name, (char *)config->name, config->default_int); c = SendMessage(h, CB_GETCURSEL, 0, 0); @@ -228,33 +210,30 @@ deviceconfig_dlgproc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) if (val_int != selection->value) changed = 1; - id += 2; break; - case CONFIG_MIDI: + case CONFIG_MIDI: val_int = config_get_int((char *)config_device->name, (char *)config->name, config->default_int); c = SendMessage(h, CB_GETCURSEL, 0, 0); if (val_int != c) changed = 1; - id += 2; break; - case CONFIG_FNAME: + case CONFIG_FNAME: { - char* str = config_get_string((char *)config_device->name, (char *)config->name, (char*)""); - SendMessage(h, WM_GETTEXT, 511, (LPARAM)s); - if (strcmp(str, s)) + char* str = config_get_string((char *)config_device->name, (char *)config->name, (char*)""); + SendMessage(h, WM_GETTEXT, 511, (LPARAM)s); + if (strcmp(str, s)) changed = 1; - id += 3; } break; - case CONFIG_SPINNER: + case CONFIG_SPINNER: val_int = config_get_int((char *)config_device->name, (char *)config->name, config->default_int); if (val_int > config->spinner.max) val_int = config->spinner.max; @@ -267,11 +246,10 @@ deviceconfig_dlgproc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) if (val_int != c) changed = 1; - id += 2; break; - case CONFIG_HEX16: + case CONFIG_HEX16: val_int = config_get_hex16((char *)config_device->name, (char *)config->name, config->default_int); c = SendMessage(h, CB_GETCURSEL, 0, 0); @@ -281,11 +259,10 @@ deviceconfig_dlgproc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) if (val_int != selection->value) changed = 1; - id += 2; break; - case CONFIG_HEX20: + case CONFIG_HEX20: val_int = config_get_hex20((char *)config_device->name, (char *)config->name, config->default_int); c = SendMessage(h, CB_GETCURSEL, 0, 0); @@ -295,39 +272,35 @@ deviceconfig_dlgproc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) if (val_int != selection->value) changed = 1; - id += 2; break; - } - config++; } + config++; + } - if (!changed) - { - deviceconfig_changed = 0; - EndDialog(hdlg, 0); - return TRUE; - } + if (! changed) { + deviceconfig_changed = 0; + EndDialog(hdlg, 0); + return TRUE; + } - deviceconfig_changed = 1; + deviceconfig_changed = 1; - id = IDC_CONFIG_BASE; - config = config_device->config; + id = IDC_CONFIG_BASE; + config = config_device->config; - while (config->type != -1) - { - const device_config_selection_t *selection = config->selection; - h = GetDlgItem(hdlg, id); + while (config->type != -1) { + const device_config_selection_t *selection = config->selection; + h = GetDlgItem(hdlg, id); - switch (config->type) - { - case CONFIG_BINARY: + switch (config->type) { + case CONFIG_BINARY: config_set_int((char *)config_device->name, (char *)config->name, SendMessage(h, BM_GETCHECK, 0, 0)); id++; break; - case CONFIG_SELECTION: + case CONFIG_SELECTION: c = SendMessage(h, CB_GETCURSEL, 0, 0); for (; c > 0; c--) selection++; @@ -336,21 +309,21 @@ deviceconfig_dlgproc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) id += 2; break; - case CONFIG_MIDI: + case CONFIG_MIDI: c = SendMessage(h, CB_GETCURSEL, 0, 0); config_set_int((char *)config_device->name, (char *)config->name, c); id += 2; break; - case CONFIG_FNAME: + case CONFIG_FNAME: SendMessage(h, WM_GETTEXT, 511, (LPARAM)ws); config_set_wstring((char *)config_device->name, (char *)config->name, ws); id += 3; break; - case CONFIG_SPINNER: + case CONFIG_SPINNER: SendMessage(h, WM_GETTEXT, 79, (LPARAM)ws); wcstombs(s, ws, 79); sscanf(s, "%i", &c); @@ -364,7 +337,7 @@ deviceconfig_dlgproc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) id += 2; break; - case CONFIG_HEX16: + case CONFIG_HEX16: c = SendMessage(h, CB_GETCURSEL, 0, 0); for (; c > 0; c--) selection++; @@ -373,7 +346,7 @@ deviceconfig_dlgproc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) id += 2; break; - case CONFIG_HEX20: + case CONFIG_HEX20: c = SendMessage(h, CB_GETCURSEL, 0, 0); for (; c > 0; c--) selection++; @@ -381,139 +354,127 @@ deviceconfig_dlgproc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) id += 2; break; - } - config++; } + config++; + } - EndDialog(hdlg, 0); - return TRUE; - } - else if (cid == IDCANCEL) - { - deviceconfig_changed = 0; - EndDialog(hdlg, 0); - return TRUE; - } - else - { - int id = IDC_CONFIG_BASE; - const device_config_t *config = config_device->config; + EndDialog(hdlg, 0); + return TRUE; + } else if (cid == IDCANCEL) { + deviceconfig_changed = 0; + EndDialog(hdlg, 0); + return TRUE; + } else { + int id = IDC_CONFIG_BASE; + const device_config_t *config = config_device->config; - while (config->type != -1) - { - switch (config->type) - { - case CONFIG_BINARY: + while (config->type != -1) { + switch (config->type) { + case CONFIG_BINARY: id++; break; - case CONFIG_SELECTION: - case CONFIG_MIDI: - case CONFIG_SPINNER: + case CONFIG_SELECTION: + case CONFIG_MIDI: + case CONFIG_SPINNER: id += 2; break; - case CONFIG_FNAME: - { - if (cid == id+1) - { - char s[512]; - s[0] = 0; - int c, d; - HWND h = GetDlgItem(hdlg, id); - SendMessage(h, WM_GETTEXT, 511, (LPARAM)s); - char file_filter[512]; - file_filter[0] = 0; + case CONFIG_FNAME: + if (cid == id+1) { + int c, d; + HWND h = GetDlgItem(hdlg, id); + SendMessage(h, WM_GETTEXT, 511, (LPARAM)s); + char file_filter[512]; + file_filter[0] = 0; - c = 0; - while (config->file_filter[c].description && config->file_filter[c].description[0]) - { - if (c > 0) - strcat(file_filter, "|"); - strcat(file_filter, config->file_filter[c].description); - strcat(file_filter, " ("); - d = 0; - while (config->file_filter[c].extensions[d] && config->file_filter[c].extensions[d][0]) - { + c = 0; + while (config->file_filter[c].description && config->file_filter[c].description[0]) { + if (c > 0) + strcat(file_filter, "|"); + strcat(file_filter, config->file_filter[c].description); + strcat(file_filter, " ("); + d = 0; + while (config->file_filter[c].extensions[d] && config->file_filter[c].extensions[d][0]) { if (d > 0) - strcat(file_filter, ";"); - strcat(file_filter, "*."); - strcat(file_filter, config->file_filter[c].extensions[d]); - d++; - } - strcat(file_filter, ")|"); - d = 0; - while (config->file_filter[c].extensions[d] && config->file_filter[c].extensions[d][0]) - { - if (d > 0) - strcat(file_filter, ";"); - strcat(file_filter, "*."); - strcat(file_filter, config->file_filter[c].extensions[d]); - d++; - } - c++; + strcat(file_filter, ";"); + strcat(file_filter, "*."); + strcat(file_filter, config->file_filter[c].extensions[d]); + d++; } - strcat(file_filter, "|All files (*.*)|*.*|"); - mbstowcs(ws, file_filter, strlen(file_filter) + 1); - d = strlen(file_filter); - - /* replace | with \0 */ - for (c = 0; c < d; ++c) - if (ws[c] == L'|') - ws[c] = 0; - - if (!file_dlg(hdlg, ws, s, 0)) - SendMessage(h, WM_SETTEXT, 0, (LPARAM)wopenfilestring); + strcat(file_filter, ")|"); + d = 0; + while (config->file_filter[c].extensions[d] && config->file_filter[c].extensions[d][0]) { + if (d > 0) + strcat(file_filter, ";"); + strcat(file_filter, "*."); + strcat(file_filter, config->file_filter[c].extensions[d]); + d++; + } + c++; } - } - break; - } - config++; + strcat(file_filter, "|All files (*.*)|*.*|"); + mbstowcs(ws, file_filter, strlen(file_filter) + 1); + d = strlen(file_filter); + + /* replace | with \0 */ + for (c = 0; c < d; ++c) + if (ws[c] == L'|') + ws[c] = 0; + + if (! file_dlg(hdlg, ws, L"", 0)) + SendMessage(h, WM_SETTEXT, 0, (LPARAM)wopenfilestring); + } + break; } - } - } - break; - } - return FALSE; + config++; + } + } + break; + } + + return FALSE; } -uint8_t deviceconfig_open(HWND hwnd, device_t *device) + +uint8_t +deviceconfig_open(HWND hwnd, device_t *device) { - const device_config_t *config = device->config; - uint16_t *data_block = malloc(16384); - uint16_t *data; - DLGTEMPLATE *dlg = (DLGTEMPLATE *)data_block; - DLGITEMTEMPLATE *item; - int y = 10; - int id = IDC_CONFIG_BASE; + const device_config_t *config = device->config; + uint16_t *data_block = malloc(16384); + uint16_t *data; + DLGTEMPLATE *dlg = (DLGTEMPLATE *)data_block; + DLGITEMTEMPLATE *item; + int y = 10; + int id = IDC_CONFIG_BASE; - deviceconfig_changed = 0; + deviceconfig_changed = 0; - memset(data_block, 0, 4096); + memset(data_block, 0x00, sizeof(16384)); - dlg->style = DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU; - dlg->x = 10; - dlg->y = 10; - dlg->cx = 220; - dlg->cy = 70; + dlg->style = DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | \ + WS_POPUP | WS_CAPTION | WS_SYSMENU; + dlg->x = 10; + dlg->y = 10; + dlg->cx = 220; + dlg->cy = 70; - data = (uint16_t *)(dlg + 1); + data = (uint16_t *)(dlg + 1); - *data++ = 0; /*no menu*/ - *data++ = 0; /*predefined dialog box class*/ - data += MultiByteToWideChar(CP_ACP, 0, "Device Configuration", -1, data, 50); + *data++ = 0; /*no menu*/ + *data++ = 0; /*predefined dialog box class*/ + data += MultiByteToWideChar(CP_ACP, 0, + "Device Configuration", -1, data, 50); - *data++ = 9; /*Point*/ - data += MultiByteToWideChar(CP_ACP, 0, "Segoe UI", -1, data, 50); + *data++ = 9; /*Point*/ + data += MultiByteToWideChar(CP_ACP, 0, "Segoe UI", -1, data, 50); - if (((uintptr_t)data) & 2) - data++; + if (((uintptr_t)data) & 2) + data++; - while (config->type != -1) - { - switch (config->type) - { - case CONFIG_BINARY: + while (config->type != -1) { + switch (config->type) { + case CONFIG_BINARY: item = (DLGITEMTEMPLATE *)data; item->x = 10; item->y = y; @@ -528,16 +489,17 @@ uint8_t deviceconfig_open(HWND hwnd, device_t *device) *data++ = 0xFFFF; *data++ = 0x0080; /* button class */ - data += MultiByteToWideChar(CP_ACP, 0, config->description, -1, data, 256); + data += MultiByteToWideChar(CP_ACP, 0, + config->description, -1, data, 256); *data++ = 0; /* no creation data */ y += 20; break; - case CONFIG_SELECTION: - case CONFIG_MIDI: - case CONFIG_HEX16: - case CONFIG_HEX20: + case CONFIG_SELECTION: + case CONFIG_MIDI: + case CONFIG_HEX16: + case CONFIG_HEX20: /*Combo box*/ item = (DLGITEMTEMPLATE *)data; item->x = 70; @@ -547,13 +509,15 @@ uint8_t deviceconfig_open(HWND hwnd, device_t *device) item->cx = 140; item->cy = 150; - item->style = WS_CHILD | WS_VISIBLE | CBS_DROPDOWN | WS_VSCROLL; + item->style = WS_CHILD | WS_VISIBLE | \ + CBS_DROPDOWN | WS_VSCROLL; data = (uint16_t *)(item + 1); *data++ = 0xFFFF; *data++ = 0x0085; /* combo box class */ - data += MultiByteToWideChar(CP_ACP, 0, config->description, -1, data, 256); + data += MultiByteToWideChar(CP_ACP, 0, + config->description, -1, data, 256); *data++ = 0; /* no creation data */ if (((uintptr_t)data) & 2) @@ -574,7 +538,8 @@ uint8_t deviceconfig_open(HWND hwnd, device_t *device) *data++ = 0xFFFF; *data++ = 0x0082; /* static class */ - data += MultiByteToWideChar(CP_ACP, 0, config->description, -1, data, 256); + data += MultiByteToWideChar(CP_ACP, 0, + config->description, -1, data, 256); *data++ = 0; /* no creation data */ if (((uintptr_t)data) & 2) @@ -583,7 +548,7 @@ uint8_t deviceconfig_open(HWND hwnd, device_t *device) y += 20; break; - case CONFIG_SPINNER: + case CONFIG_SPINNER: /*Spinner*/ item = (DLGITEMTEMPLATE *)data; item->x = 70; @@ -593,14 +558,16 @@ uint8_t deviceconfig_open(HWND hwnd, device_t *device) item->cx = 140; item->cy = 14; - item->style = WS_CHILD | WS_VISIBLE | ES_AUTOHSCROLL | ES_NUMBER; + item->style = WS_CHILD | WS_VISIBLE | \ + ES_AUTOHSCROLL | ES_NUMBER; item->dwExtendedStyle = WS_EX_CLIENTEDGE; data = (uint16_t *)(item + 1); *data++ = 0xFFFF; *data++ = 0x0081; /* edit text class */ - data += MultiByteToWideChar(CP_ACP, 0, "", -1, data, 256); + data += MultiByteToWideChar(CP_ACP, 0, + "", -1, data, 256); *data++ = 0; /* no creation data */ if (((uintptr_t)data) & 2) @@ -622,7 +589,8 @@ uint8_t deviceconfig_open(HWND hwnd, device_t *device) *data++ = 0xFFFF; *data++ = 0x0082; /* static class */ - data += MultiByteToWideChar(CP_ACP, 0, config->description, -1, data, 256); + data += MultiByteToWideChar(CP_ACP, 0, + config->description, -1, data, 256); *data++ = 0; /* no creation data */ if (((uintptr_t)data) & 2) @@ -631,7 +599,7 @@ uint8_t deviceconfig_open(HWND hwnd, device_t *device) y += 20; break; - case CONFIG_FNAME: + case CONFIG_FNAME: /*File*/ item = (DLGITEMTEMPLATE *)data; item->x = 70; @@ -648,7 +616,8 @@ uint8_t deviceconfig_open(HWND hwnd, device_t *device) *data++ = 0xFFFF; *data++ = 0x0081; /* edit text class */ - data += MultiByteToWideChar(CP_ACP, 0, "", -1, data, 256); + data += MultiByteToWideChar(CP_ACP, 0, + "", -1, data, 256); *data++ = 0; /* no creation data */ if (((uintptr_t)data) & 2) @@ -669,7 +638,8 @@ uint8_t deviceconfig_open(HWND hwnd, device_t *device) *data++ = 0xFFFF; *data++ = 0x0080; /* button class */ - data += MultiByteToWideChar(CP_ACP, 0, "Browse", -1, data, 256); + data += MultiByteToWideChar(CP_ACP, 0, + "Browse", -1, data, 256); *data++ = 0; /* no creation data */ if (((uintptr_t)data) & 2) @@ -690,7 +660,8 @@ uint8_t deviceconfig_open(HWND hwnd, device_t *device) *data++ = 0xFFFF; *data++ = 0x0082; /* static class */ - data += MultiByteToWideChar(CP_ACP, 0, config->description, -1, data, 256); + data += MultiByteToWideChar(CP_ACP, 0, + config->description, -1, data, 256); *data++ = 0; /* no creation data */ if (((uintptr_t)data) & 2) @@ -698,56 +669,56 @@ uint8_t deviceconfig_open(HWND hwnd, device_t *device) y += 20; break; - } - - if (((uintptr_t)data) & 2) - data++; - - config++; } - dlg->cdit = (id - IDC_CONFIG_BASE) + 2; - - item = (DLGITEMTEMPLATE *)data; - item->x = 20; - item->y = y; - item->cx = 50; - item->cy = 14; - item->id = IDOK; /* OK button identifier */ - item->style = WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON; - - data = (uint16_t *)(item + 1); - *data++ = 0xFFFF; - *data++ = 0x0080; /* button class */ - - data += MultiByteToWideChar(CP_ACP, 0, "OK", -1, data, 50); - *data++ = 0; /* no creation data */ - if (((uintptr_t)data) & 2) data++; - item = (DLGITEMTEMPLATE *)data; - item->x = 80; - item->y = y; - item->cx = 50; - item->cy = 14; - item->id = IDCANCEL; /* OK button identifier */ - item->style = WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON; + config++; + } - data = (uint16_t *)(item + 1); - *data++ = 0xFFFF; - *data++ = 0x0080; /* button class */ + dlg->cdit = (id - IDC_CONFIG_BASE) + 2; - data += MultiByteToWideChar(CP_ACP, 0, "Cancel", -1, data, 50); - *data++ = 0; /* no creation data */ + item = (DLGITEMTEMPLATE *)data; + item->x = 20; + item->y = y; + item->cx = 50; + item->cy = 14; + item->id = IDOK; /* OK button identifier */ + item->style = WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON; - dlg->cy = y + 20; + data = (uint16_t *)(item + 1); + *data++ = 0xFFFF; + *data++ = 0x0080; /* button class */ - config_device = device; + data += MultiByteToWideChar(CP_ACP, 0, "OK", -1, data, 50); + *data++ = 0; /* no creation data */ - DialogBoxIndirect(hinstance, dlg, hwnd, deviceconfig_dlgproc); + if (((uintptr_t)data) & 2) + data++; - free(data_block); + item = (DLGITEMTEMPLATE *)data; + item->x = 80; + item->y = y; + item->cx = 50; + item->cy = 14; + item->id = IDCANCEL; /* OK button identifier */ + item->style = WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON; - return deviceconfig_changed; + data = (uint16_t *)(item + 1); + *data++ = 0xFFFF; + *data++ = 0x0080; /* button class */ + + data += MultiByteToWideChar(CP_ACP, 0, "Cancel", -1, data, 50); + *data++ = 0; /* no creation data */ + + dlg->cy = y + 20; + + config_device = device; + + DialogBoxIndirect(hinstance, dlg, hwnd, dlg_proc); + + free(data_block); + + return deviceconfig_changed; } diff --git a/src/win/win_dialog.c b/src/win/win_dialog.c index ae4066a..8a2e6f0 100644 --- a/src/win/win_dialog.c +++ b/src/win/win_dialog.c @@ -8,7 +8,7 @@ * * Implementation of server several dialogs. * - * Version: @(#)win_dialog.c 1.0.4 2018/03/08 + * Version: @(#)win_dialog.c 1.0.5 2018/03/31 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -53,22 +53,12 @@ #include "win.h" -WCHAR path[MAX_PATH]; -WCHAR wopenfilestring[260]; -char openfilestring[260]; +WCHAR wopenfilestring[1024]; +char openfilestring[1024]; DWORD filterindex = 0; -static int CALLBACK -BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData) -{ - if (uMsg == BFFM_INITIALIZED) - SendMessage(hwnd, BFFM_SETSELECTION, TRUE, lpData); - - return(0); -} - - +/* Center a dialog window with respect to the main window. */ void dialog_center(HWND hdlg) { @@ -96,37 +86,6 @@ dialog_center(HWND hdlg) } -wchar_t * -BrowseFolder(wchar_t *saved_path, wchar_t *title) -{ - BROWSEINFO bi = { 0 }; - LPITEMIDLIST pidl; - IMalloc *imalloc; - - bi.lpszTitle = title; - bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_NEWDIALOGSTYLE; - bi.lpfn = BrowseCallbackProc; - bi.lParam = (LPARAM) saved_path; - - pidl = SHBrowseForFolder(&bi); - if (pidl != 0) { - /* Get the name of the folder and put it in path. */ - SHGetPathFromIDList(pidl, path); - - /* Free memory used. */ - imalloc = 0; - if (SUCCEEDED(SHGetMalloc(&imalloc))) { - imalloc->lpVtbl->Free(imalloc, pidl); - imalloc->lpVtbl->Release(imalloc); - } - - return(path); - } - - return(L""); -} - - int ui_msgbox(int flags, void *arg) { @@ -209,101 +168,78 @@ ui_msgbox(int flags, void *arg) } -#if 0 int -msgbox_reset_yn(HWND hwnd) -{ - return(MessageBox(hwnd, plat_get_string(IDS_2051), -#endif - - -int -file_dlg_w(HWND hwnd, WCHAR *f, WCHAR *fn, int save) +file_dlg(HWND hwnd, WCHAR *filt, WCHAR *ifn, int save) { OPENFILENAME ofn; + wchar_t fn[1024]; + char temp[1024]; BOOL r; - /* DWORD err; */ + DWORD err; - /* Initialize OPENFILENAME */ - ZeroMemory(&ofn, sizeof(ofn)); + /* Clear out the ("initial") pathname. */ + memset(fn, 0x00, sizeof(fn)); + + /* Initialize OPENFILENAME. */ + memset(&ofn, 0x00, sizeof(OPENFILENAME)); ofn.lStructSize = sizeof(ofn); ofn.hwndOwner = hwnd; - ofn.lpstrFile = wopenfilestring; - /* - * Set lpstrFile[0] to '\0' so that GetOpenFileName does - * not use the contents of szFile to initialize itself. - */ - memcpy(ofn.lpstrFile, fn, (wcslen(fn) << 1) + 2); - ofn.nMaxFile = 259; - ofn.lpstrFilter = f; + /* This is the buffer in which to place the resulting filename. */ + ofn.lpstrFile = fn; + ofn.nMaxFile = sizeof_w(fn); + + /* Set up the "file types" filter. */ + ofn.lpstrFilter = filt; ofn.nFilterIndex = 1; ofn.lpstrFileTitle = NULL; ofn.nMaxFileTitle = 0; - ofn.lpstrInitialDir = NULL; + + /* Tell the dialog where to go initially. */ + ofn.lpstrInitialDir = usr_path; + + /* Set up the flags for this dialog. */ ofn.Flags = OFN_PATHMUSTEXIST; if (! save) ofn.Flags |= OFN_FILEMUSTEXIST; /* Display the Open dialog box. */ - if (save) { -// pclog("GetSaveFileName - lpstrFile = %s\n", ofn.lpstrFile); + if (save) r = GetSaveFileName(&ofn); - } else { -// pclog("GetOpenFileName - lpstrFile = %s\n", ofn.lpstrFile); + else r = GetOpenFileName(&ofn); - } + /* OK, just to make sure the dialog did not change our CWD. */ plat_chdir(usr_path); if (r) { + /* All good, see if we can make this a relative path. */ + pc_path(wopenfilestring, sizeof_w(wopenfilestring), fn); + + /* All good, create an ASCII copy of the string as well. */ wcstombs(openfilestring, wopenfilestring, sizeof(openfilestring)); + + /* Remember the file type for next time. */ filterindex = ofn.nFilterIndex; -// pclog("File dialog return true\n"); return(0); } - /* pclog("File dialog return false\n"); */ - /* err = CommDlgExtendedError(); - pclog("CommDlgExtendedError return %04X\n", err); */ + /* If an error occurred, log this. */ + err = CommDlgExtendedError(); + if (err != NO_ERROR) { + sprintf(temp, "OpenFile(%ls, %d):\n\n error 0x%08lx", + usr_path, save, err); + pclog("%s\n", temp); + (void)ui_msgbox(MBX_ERROR|MBX_ANSI, temp); + } return(1); } int -file_dlg(HWND hwnd, WCHAR *f, char *fn, int save) -{ - WCHAR ufn[512]; - - mbstowcs(ufn, fn, strlen(fn) + 1); - - return(file_dlg_w(hwnd, f, ufn, save)); -} - - -int -file_dlg_mb(HWND hwnd, char *f, char *fn, int save) -{ - WCHAR uf[512], ufn[512]; - - mbstowcs(uf, f, strlen(fn) + 1); - mbstowcs(ufn, fn, strlen(fn) + 1); - - return(file_dlg_w(hwnd, uf, ufn, save)); -} - - -int -file_dlg_w_st(HWND hwnd, int id, WCHAR *fn, int save) -{ - return(file_dlg_w(hwnd, plat_get_string(id), fn, save)); -} - - -int -file_dlg_st(HWND hwnd, int id, char *fn, int save) +file_dlg_st(HWND hwnd, int id, WCHAR *fn, int save) { return(file_dlg(hwnd, plat_get_string(id), fn, save)); } diff --git a/src/win/win_new_floppy.c b/src/win/win_new_floppy.c index 518b53f..670eec0 100644 --- a/src/win/win_new_floppy.c +++ b/src/win/win_new_floppy.c @@ -8,7 +8,7 @@ * * Implementation of the New Floppy Image dialog. * - * Version: @(#)win_new_floppy.c 1.0.8 2018/03/18 + * Version: @(#)win_new_floppy.c 1.0.9 2018/03/31 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -643,7 +643,7 @@ NewFloppyDialogProcedure(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) return TRUE; case IDC_CFILE: - if (!file_dlg_w(hdlg, plat_get_string(is_zip ? IDS_2176 : IDS_2174), L"", 1)) { + if (!file_dlg(hdlg, plat_get_string(is_zip ? IDS_2176 : IDS_2174), L"", 1)) { if (!wcschr(wopenfilestring, L'.')) { if (wcslen(wopenfilestring) && (wcslen(wopenfilestring) <= 256)) { twcs = &wopenfilestring[wcslen(wopenfilestring)]; diff --git a/src/win/win_settings.c b/src/win/win_settings.c index e3359fc..9ba530a 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.15 2018/03/28 + * Version: @(#)win_settings.c 1.0.17 2018/03/31 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -2122,11 +2122,11 @@ static uint8_t next_free_ide_channel(void) static void next_free_scsi_id_and_lun(uint8_t *id, uint8_t *lun) { - uint8_t i, j; + int i, j; - for (j = 0; j < 8; j++) { - for (i = 0; i < 16; i++) { - if (!(scsi_tracking[i] & (0xffLL << (j << 3LL)))) { + for (i = 0; i < 16; i++) { + for (j = 0; j < 8; j++) { + if (! (scsi_tracking[i] & (0xffULL << (j << 3LL)))) { *id = i; *lun = j; return; @@ -2697,11 +2697,12 @@ static uint64_t hdconf_initialize_hdt_combo(HWND hdlg) h = GetDlgItem(hdlg, IDC_COMBO_HD_TYPE); for (i = 0; i < 127; i++) { - temp_size = hdd_table[i][0] * hdd_table[i][1] * hdd_table[i][2]; + 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][0], hdd_table[i][1], hdd_table[i][2]); + 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][0]) && (hpc == hdd_table[i][1]) && (spt == hdd_table[i][2])) + if ((tracks == hdd_table[i].cyls) && (hpc == hdd_table[i].head) && (spt == hdd_table[i].sect)) { selection = i; } @@ -2721,7 +2722,7 @@ static void recalc_selection(HWND hdlg) h = GetDlgItem(hdlg, IDC_COMBO_HD_TYPE); for (i = 0; i < 127; i++) { - if ((tracks == hdd_table[i][0]) && (hpc == hdd_table[i][1]) && (spt == hdd_table[i][2])) + if ((tracks == hdd_table[i].cyls) && (hpc == hdd_table[i].head) && (spt == hdd_table[i].sect)) { selection = i; } @@ -2742,6 +2743,7 @@ 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; @@ -2750,8 +2752,6 @@ hard_disks_add_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) uint32_t zero = 0; uint32_t base = 0x1000; uint64_t signature = 0xD778A82044445459ll; - char buf[512]; - char *big_buf; int b = 0; uint64_t r = 0; uint8_t channel = 0; @@ -2784,6 +2784,7 @@ hard_disks_add_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) 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) { @@ -2803,7 +2804,9 @@ hard_disks_add_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) { chs_enabled = 1; } + add_locations(hdlg); + h = GetDlgItem(hdlg, IDC_COMBO_HD_BUS); if (existing & 2) { @@ -2820,6 +2823,7 @@ hard_disks_add_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) 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, @@ -2898,15 +2902,19 @@ hard_disks_add_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) 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->spt = hdd_ptr->hpc = hdd_ptr->tracks = 0; + 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, &(hdd_ptr->spt)); - get_edit_box_contents(hdlg, IDC_EDIT_HD_HPC, &(hdd_ptr->hpc)); - get_edit_box_contents(hdlg, IDC_EDIT_HD_CYL, &(hdd_ptr->tracks)); + 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; @@ -3071,7 +3079,7 @@ hd_add_ok_common: return TRUE; case IDC_CFILE: - if (!file_dlg_w(hdlg, plat_get_string(IDS_4106), L"", !(existing & 1))) + if (!file_dlg(hdlg, plat_get_string(IDS_4106), L"", !(existing & 1))) { if (!wcschr(wopenfilestring, L'.')) { if (wcslen(wopenfilestring) && (wcslen(wopenfilestring) <= 256)) { @@ -3324,9 +3332,9 @@ hdd_add_file_open_error: if ((temp != selection) && (temp != 127) && (temp != 128)) { selection = temp; - tracks = hdd_table[selection][0]; - hpc = hdd_table[selection][1]; - spt = hdd_table[selection][2]; + 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); diff --git a/src/win/win_stbar.c b/src/win/win_stbar.c index eda867f..814589f 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.4 2018/03/18 + * Version: @(#)win_stbar.c 1.0.5 2018/03/31 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -1023,7 +1023,7 @@ StatusBarProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) if ((part == -1) || (sb_menu_handles == NULL)) break; - ret = file_dlg_w_st(hwnd, IDS_2159, floppyfns[id], 0); + ret = file_dlg_st(hwnd, IDS_2159, floppyfns[id], 0); if (! ret) ui_sb_mount_floppy_img(id, part, (item_id == IDM_FLOPPY_IMAGE_EXISTING_WP) ? 1 : 0, wopenfilestring); break; @@ -1048,7 +1048,7 @@ StatusBarProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) if ((part == -1) || (sb_menu_handles == NULL)) break; - ret = file_dlg_w_st(hwnd, IDS_2173, floppyfns[id], 1); + ret = file_dlg_st(hwnd, IDS_2173, floppyfns[id], 1); if (! ret) { plat_pause(1); ret = d86f_export(id, wopenfilestring); @@ -1086,7 +1086,7 @@ StatusBarProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) if ((part == -1) || (sb_menu_handles == NULL)) break; - if (!file_dlg_w_st(hwnd, IDS_2075, cdrom_image[id].image_path, 0)) { + if (!file_dlg_st(hwnd, IDS_2075, cdrom_image[id].image_path, 0)) { cdrom_drives[id].prev_host_drive = cdrom_drives[id].host_drive; wcscpy(temp_path, wopenfilestring); if (!cdrom_image[id].prev_image_path) @@ -1164,7 +1164,7 @@ StatusBarProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) if ((part == -1) || (sb_menu_handles == NULL)) break; - ret = file_dlg_w_st(hwnd, IDS_2175, zip_drives[id].image_path, 0); + ret = file_dlg_st(hwnd, IDS_2175, zip_drives[id].image_path, 0); if (! ret) ui_sb_mount_zip_img(id, part, (item_id == IDM_ZIP_IMAGE_EXISTING_WP) ? 1 : 0, wopenfilestring); break; @@ -1197,7 +1197,7 @@ StatusBarProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) case IDM_RDISK_IMAGE: case IDM_RDISK_IMAGE_WP: id = item_params & 0x001f; - ret = file_dlg_w_st(hwnd, IDS_4106, hdd[id].fn, id); + ret = file_dlg_st(hwnd, IDS_4106, hdd[id].fn, id); if (!ret) { removable_disk_unload(id); memset(hdd[id].fn, 0, sizeof(hdd[id].fn)); diff --git a/src/win/win_ui.c b/src/win/win_ui.c index 3eea816..60b30c0 100644 --- a/src/win/win_ui.c +++ b/src/win/win_ui.c @@ -8,7 +8,7 @@ * * Implement the user Interface module. * - * Version: @(#)win_ui.c 1.0.7 2018/03/20 + * Version: @(#)win_ui.c 1.0.8 2018/03/31 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -151,7 +151,7 @@ ResetAllMenus(void) EnableMenuItem(menuMain, IDM_CONFIG_SAVE, MF_DISABLED); #endif - CheckMenuItem(menuMain, IDM_ACTION_RCTRL_IS_LALT, MF_UNCHECKED); + CheckMenuItem(menuMain, IDM_KBD_RCTRL_IS_LALT, MF_UNCHECKED); CheckMenuItem(menuMain, IDM_UPDATE_ICONS, MF_UNCHECKED); @@ -213,7 +213,7 @@ ResetAllMenus(void) CheckMenuItem(menuMain, IDM_VID_GRAY_RGB+3, MF_UNCHECKED); CheckMenuItem(menuMain, IDM_VID_GRAY_RGB+4, MF_UNCHECKED); - CheckMenuItem(menuMain, IDM_ACTION_RCTRL_IS_LALT, rctrl_is_lalt ? MF_CHECKED : MF_UNCHECKED); + CheckMenuItem(menuMain, IDM_KBD_RCTRL_IS_LALT, rctrl_is_lalt ? MF_CHECKED : MF_UNCHECKED); CheckMenuItem(menuMain, IDM_UPDATE_ICONS, update_icons ? MF_CHECKED : MF_UNCHECKED); @@ -331,12 +331,6 @@ MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) keyboard_send_cae(); break; - case IDM_ACTION_RCTRL_IS_LALT: - rctrl_is_lalt ^= 1; - CheckMenuItem(hmenu, IDM_ACTION_RCTRL_IS_LALT, rctrl_is_lalt ? MF_CHECKED : MF_UNCHECKED); - config_save(); - break; - case IDM_ACTION_PAUSE: plat_pause(dopause ^ 1); CheckMenuItem(menuMain, IDM_ACTION_PAUSE, dopause ? MF_CHECKED : MF_UNCHECKED); @@ -510,6 +504,12 @@ MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) config_save(); break; + case IDM_KBD_RCTRL_IS_LALT: + rctrl_is_lalt ^= 1; + CheckMenuItem(hmenu, IDM_KBD_RCTRL_IS_LALT, rctrl_is_lalt ? MF_CHECKED : MF_UNCHECKED); + config_save(); + break; + #ifdef ENABLE_LOG_TOGGLES # ifdef ENABLE_BUSLOGIC_LOG case IDM_LOG_BUSLOGIC: @@ -575,7 +575,7 @@ MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) case IDM_CONFIG_LOAD: plat_pause(1); - if (!file_dlg_st(hwnd, IDS_2160, "", 0) && + if (! file_dlg_st(hwnd, IDS_2160, L"", 0) && (ui_msgbox(MBX_QUESTION, (wchar_t *)IDS_2051) == IDYES)) { pc_reload(wopenfilestring); ResetAllMenus(); @@ -585,7 +585,7 @@ MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) case IDM_CONFIG_SAVE: plat_pause(1); - if (! file_dlg_st(hwnd, IDS_2160, "", 1)) { + if (! file_dlg_st(hwnd, IDS_2160, L"", 1)) { config_write(wopenfilestring); } plat_pause(0); @@ -891,7 +891,6 @@ ui_init(int nCmdShow) /* Create the Machine Rendering window. */ hwndRender = CreateWindow(L"STATIC", NULL, WS_CHILD|SS_BITMAP, 0, 0, 1, 1, hwnd, NULL, hinstance, NULL); - MoveWindow(hwndRender, 0, 0, scrnsz_x, scrnsz_y, TRUE); /* That looks good, now continue setting up the machine. */ switch (pc_init_modules()) { @@ -928,8 +927,13 @@ ui_init(int nCmdShow) if (start_in_fullscreen) plat_setfullscreen(1); + /* Activate the render window, this will also set the screen size. */ + MoveWindow(hwndRender, 0, 0, scrnsz_x, scrnsz_y, TRUE); + +#if 0 /* Set up the current window size. */ plat_resize(scrnsz_x, scrnsz_y); +#endif /* Fire up the machine. */ pc_reset_hard(); @@ -937,13 +941,6 @@ ui_init(int nCmdShow) /* Set the PAUSE mode depending on the renderer. */ plat_pause(0); - /* If so requested via the command line, inform the - * application that started us of our HWND, using the - * the hWnd and unique ID the application has given - * us. */ - if (source_hwnd) - SendMessage((HWND) (uintptr_t) source_hwnd, WM_SENDHWND, (WPARAM) unique_id, (LPARAM) hwndMain); - /* * Everything has been configured, and all seems to work, * so now it is time to start the main thread to do some