diff --git a/src/floppy/fdc_monster.c b/src/floppy/fdc_monster.c index 2feafdf07..d2dedb5c0 100644 --- a/src/floppy/fdc_monster.c +++ b/src/floppy/fdc_monster.c @@ -26,6 +26,8 @@ #include <86box/device.h> #include <86box/io.h> #include <86box/mem.h> +#include <86box/timer.h> +#include <86box/nvr.h> #include <86box/rom.h> #include <86box/machine.h> #include <86box/timer.h> @@ -41,7 +43,7 @@ typedef struct monster_fdc_t { rom_t bios_rom; fdc_t *fdc_pri; fdc_t *fdc_sec; - char *nvr_path; + char nvr_path[64]; } monster_fdc_t; static void @@ -100,10 +102,12 @@ monster_fdc_close(void *priv) { monster_fdc_t *dev = (monster_fdc_t *) priv; - FILE *f = fopen(dev->nvr_path, "wb"); - if (f != NULL) { - fwrite(dev->bios_rom.rom, 1, 0x2000, f); - fclose(f); + if (dev->nvr_path[0] != 0x00) { + FILE *f = nvr_fopen(dev->nvr_path, "wb"); + if (f != NULL) { + fwrite(dev->bios_rom.rom, 1, 0x2000, f); + fclose(f); + } } free(dev); @@ -114,8 +118,7 @@ monster_fdc_init(UNUSED(const device_t *info)) { monster_fdc_t *dev; - dev = (monster_fdc_t *) malloc(sizeof(monster_fdc_t)); - memset(dev, 0, sizeof(monster_fdc_t)); + dev = (monster_fdc_t *) calloc(1, sizeof(monster_fdc_t)); #if 0 uint8_t sec_irq = device_get_config_int("sec_irq"); @@ -140,15 +143,13 @@ monster_fdc_init(UNUSED(const device_t *info)) uint8_t rom_writes_enabled = device_get_config_int("rom_writes_enabled"); if (rom_writes_enabled) { mem_mapping_set_write_handler(&dev->bios_rom.mapping, rom_write, rom_writew, rom_writel); - dev->nvr_path = "monster_fdc_0.nvr"; - dev->nvr_path[12] = device_get_instance() + 0x30; - FILE *f = fopen(dev->nvr_path, "rb"); + sprintf(dev->nvr_path, "monster_fdc_%i.nvr", device_get_instance()); + FILE *f = nvr_fopen(dev->nvr_path, "rb"); if (f != NULL) { fread(dev->bios_rom.rom, 1, 0x2000, f); fclose(f); } - } else - dev->nvr_path = NULL; + } return dev; } diff --git a/src/include/86box/scsi_x54x.h b/src/include/86box/scsi_x54x.h index 0f1874302..8d5964de5 100644 --- a/src/include/86box/scsi_x54x.h +++ b/src/include/86box/scsi_x54x.h @@ -476,7 +476,8 @@ typedef struct x54x_t { /* 8 bytes */ char *bios_path; /* path to BIOS image file */ char *mcode_path; /* path to microcode image file, needed by the AHA-1542CP */ - char *nvr_path; /* path to NVR image file */ + + char nvr_path[64]; /* path to NVR image file */ /* 56 bytes */ /* Pointer to a structure of vendor-specific data that only the vendor-specific code can understand */ diff --git a/src/scsi/scsi_aha154x.c b/src/scsi/scsi_aha154x.c index c811c2c87..7d9f1ba24 100644 --- a/src/scsi/scsi_aha154x.c +++ b/src/scsi/scsi_aha154x.c @@ -921,7 +921,7 @@ aha_setnvr(x54x_t *dev) FILE *fp; /* Only if this device has an EEPROM. */ - if (dev->nvr_path == NULL) + if (dev->nvr_path[0] == 0x00) return; /* Allocate and initialize the EEPROM. */ @@ -1043,8 +1043,7 @@ aha_init(const device_t *info) case AHA_154xC: strcpy(dev->name, "AHA-154xC"); dev->bios_path = "roms/scsi/adaptec/aha1542c102.bin"; - dev->nvr_path = "aha1542c_0.nvr"; - dev->nvr_path[9] = device_get_instance() + 0x30; + sprintf(dev->nvr_path, "aha1542c_%i.nvr", device_get_instance()); dev->fw_rev = "D001"; dev->rom_shram = 0x3F80; /* shadow RAM address base */ dev->rom_shramsz = 128; /* size of shadow RAM */ @@ -1060,8 +1059,7 @@ aha_init(const device_t *info) case AHA_154xCF: strcpy(dev->name, "AHA-154xCF"); dev->bios_path = "roms/scsi/adaptec/aha1542cf211.bin"; - dev->nvr_path = "aha1542cf_0.nvr"; - dev->nvr_path[10] = device_get_instance() + 0x30; + sprintf(dev->nvr_path, "aha1542cf_%i.nvr", device_get_instance()); dev->fw_rev = "E001"; dev->rom_shram = 0x3F80; /* shadow RAM address base */ dev->rom_shramsz = 128; /* size of shadow RAM */ @@ -1082,8 +1080,7 @@ aha_init(const device_t *info) bios_rev = (char *) device_get_config_bios("bios_rev"); dev->bios_path = (char *) device_get_bios_file(info, bios_rev, 0); dev->mcode_path = (char *) device_get_bios_file(info, bios_rev, 1); - dev->nvr_path = "aha1542cp_0.nvr"; - dev->nvr_path[10] = device_get_instance() + 0x30; + sprintf(dev->nvr_path, "aha1542cp_%i.nvr", device_get_instance()); dev->fw_rev = aha1542cp_rev; dev->rom_shram = 0x3F80; /* shadow RAM address base */ dev->rom_shramsz = 128; /* size of shadow RAM */ diff --git a/src/scsi/scsi_ncr53c8xx.c b/src/scsi/scsi_ncr53c8xx.c index 1fd9fcdba..1395c2f6f 100644 --- a/src/scsi/scsi_ncr53c8xx.c +++ b/src/scsi/scsi_ncr53c8xx.c @@ -205,7 +205,7 @@ typedef enum { } scsi_state_t; typedef struct ncr53c8xx_t { - char *nvr_path; + char nvr_path[64]; uint8_t pci_slot; uint8_t chip, wide; int has_bios; @@ -2571,39 +2571,37 @@ ncr53c8xx_init(const device_t *info) switch (dev->chip) { case CHIP_810: - dev->nvr_path = "ncr53c810_0.nvr"; + sprintf(dev->nvr_path, "ncr53c810_%i.nvr", device_get_instance()); dev->wide = 0; break; case CHIP_815: dev->chip_rev = 0x04; - dev->nvr_path = "ncr53c815_0.nvr"; + sprintf(dev->nvr_path, "ncr53c815_%i.nvr", device_get_instance()); dev->wide = 0; break; case CHIP_820: - dev->nvr_path = "ncr53c820_0.nvr"; + sprintf(dev->nvr_path, "ncr53c820_%i.nvr", device_get_instance()); dev->wide = 1; break; case CHIP_825: dev->chip_rev = 0x26; - dev->nvr_path = "ncr53c825_0.nvr"; + sprintf(dev->nvr_path, "ncr53c825a_%i.nvr", device_get_instance()); dev->wide = 1; break; case CHIP_860: scsi_bus_set_speed(dev->bus, 20000000.0); dev->chip_rev = 0x04; - dev->nvr_path = "ncr53c860_0.nvr"; + sprintf(dev->nvr_path, "ncr53c860_%i.nvr", device_get_instance()); dev->wide = 1; break; case CHIP_875: scsi_bus_set_speed(dev->bus, 40000000.0); dev->chip_rev = 0x04; - dev->nvr_path = "ncr53c875_0.nvr"; + sprintf(dev->nvr_path, "ncr53c875_%i.nvr", device_get_instance()); dev->wide = 1; break; } - dev->nvr_path[10] = device_get_instance() + 0x30; - ncr53c8xx_pci_bar[0].addr_regs[0] = 1; ncr53c8xx_pci_bar[1].addr_regs[0] = 0; ncr53c8xx_pci_regs[0x04] = 3; diff --git a/src/scsi/scsi_pcscsi.c b/src/scsi/scsi_pcscsi.c index 48b2d52fa..a714ada96 100644 --- a/src/scsi/scsi_pcscsi.c +++ b/src/scsi/scsi_pcscsi.c @@ -152,7 +152,7 @@ typedef struct esp_t { mem_mapping_t mmio_mapping; mem_mapping_t ram_mapping; - char *nvr_path; + char nvr_path[64]; uint8_t pci_slot; int has_bios; int BIOSBase; @@ -1856,8 +1856,7 @@ dc390_init(UNUSED(const device_t *info)) if (dev->has_bios) esp_bios_disable(dev); - dev->nvr_path = "dc390_0.nvr"; - dev->nvr_path[6] = device_get_instance() + 0x30; + sprintf(dev->nvr_path, "dc390_%i.nvr", device_get_instance()); /* Load the serial EEPROM. */ dc390_load_eeprom(dev);