From: Toni Wilen Date: Fri, 12 Jul 2019 16:36:56 +0000 (+0300) Subject: PCMCIA insert/eject update. X-Git-Tag: 4300~183 X-Git-Url: https://git.unchartedbackwaters.co.uk/w/?a=commitdiff_plain;h=fbb091fbe19aa484fa601aa6951a47e037f122a8;p=francis%2Fwinuae.git PCMCIA insert/eject update. --- diff --git a/filesys.cpp b/filesys.cpp index ceb9db80..3a7c9d5c 100644 --- a/filesys.cpp +++ b/filesys.cpp @@ -877,8 +877,11 @@ int kill_filesys_unitconfig (struct uae_prefs *p, int nr) return 0; uci = getuci (p->mountconfig, nr); hardfile_do_disk_change (uci, 0); - if (uci->configoffset >= 0 && uci->ci.controller_type == HD_CONTROLLER_TYPE_UAE) - filesys_media_change (uci->ci.rootdir, 0, uci); + if (uci->configoffset >= 0 && uci->ci.controller_type == HD_CONTROLLER_TYPE_UAE) { + filesys_media_change(uci->ci.rootdir, 0, uci); + } else { + pcmcia_disk_reinsert(p, &uci->ci, true); + } while (nr < MOUNT_CONFIG_SIZE) { memmove (&p->mountconfig[nr], &p->mountconfig[nr + 1], sizeof (struct uaedev_config_data)); nr++; diff --git a/gayle.cpp b/gayle.cpp index 3799e481..b3b125e0 100644 --- a/gayle.cpp +++ b/gayle.cpp @@ -148,13 +148,14 @@ DE0000 to DEFFFF 64 KB Motherboard resources static struct ide_hdf *idedrive[TOTAL_IDE * 2]; static struct ide_hdf *archoshd[2]; -struct hd_hardfiledata *pcmcia_sram; +struct hd_hardfiledata *pcmcia_disk; static int pcmcia_card; static int pcmcia_readonly; static int pcmcia_type; static uae_u8 pcmcia_configuration[20]; static int pcmcia_configured; +static int pcmcia_delayed_insert, pcmcia_delayed_insert_count; static int gayle_id_cnt; static uae_u8 gayle_irq, gayle_int, gayle_cs, gayle_cs_mask, gayle_cfg; @@ -975,16 +976,6 @@ static uae_u16 pcmcia_idedata; static const struct pci_board *ne2000; static struct pci_board_state *ne2000_board_state; -void gayle_hsync(void) -{ - if (ne2000) - ne2000->hsync(ne2000_board_state); - if (ide_interrupt_hsync(idedrive[0]) || ide_interrupt_hsync(idedrive[2]) || ide_interrupt_hsync(idedrive[4]) || checkpcmciane2000irq()) - devices_rethink_all(rethink_gayle); - if (archoshd[0]) - ide_interrupt_hsync(archoshd[0]); -} - static uaecptr from_gayle_pcmcmia(uaecptr addr) { addr &= 0x80000 - 1; @@ -1200,7 +1191,7 @@ static void initscideattr (int readonly) { uae_u8 *rp; uae_u8 *p = pcmcia_attrs; - struct hardfiledata *hfd = &pcmcia_sram->hfd; + struct hardfiledata *hfd = &pcmcia_disk->hfd; /* Mostly just copied from real CF cards.. */ @@ -1291,7 +1282,7 @@ static void initsramattr (int size, int readonly) uae_u8 *rp; uae_u8 *p = pcmcia_attrs; int sm, su, code, units; - struct hardfiledata *hfd = &pcmcia_sram->hfd; + struct hardfiledata *hfd = &pcmcia_disk->hfd; int real = hfd->flags & HFD_FLAGS_REALDRIVE; code = 0; @@ -1362,7 +1353,7 @@ static void initsramattr (int size, int readonly) static void check_sram_flush (int addr) { - if (pcmcia_card == 0 || pcmcia_sram == 0) + if (pcmcia_card == 0 || pcmcia_disk == 0) return; if (pcmcia_readonly) return; @@ -1374,13 +1365,13 @@ static void check_sram_flush (int addr) } if (pcmcia_write_min >= 0) { if (abs (pcmcia_write_min - addr) >= 512 || abs (pcmcia_write_max - addr) >= 512) { - int blocksize = pcmcia_sram->hfd.ci.blocksize; + int blocksize = pcmcia_disk->hfd.ci.blocksize; int mask = ~(blocksize - 1); int start = pcmcia_write_min & mask; int end = (pcmcia_write_max + blocksize - 1) & mask; int len = end - start; if (len > 0) { - hdf_write (&pcmcia_sram->hfd, pcmcia_common + start, start, len); + hdf_write (&pcmcia_disk->hfd, pcmcia_common + start, start, len); pcmcia_write_min = -1; pcmcia_write_max = -1; } @@ -1394,14 +1385,14 @@ static void check_sram_flush (int addr) static int freepcmcia (int reset) { - if (pcmcia_sram) { + if (pcmcia_disk) { check_sram_flush(-1); if (reset) { - hdf_hd_close (pcmcia_sram); - xfree (pcmcia_sram); - pcmcia_sram = NULL; + hdf_hd_close (pcmcia_disk); + xfree (pcmcia_disk); + pcmcia_disk = NULL; } else { - pcmcia_sram->hfd.drive_empty = 1; + pcmcia_disk->hfd.drive_empty = 1; } } remove_ide_unit(idedrive, PCMCIA_IDE_ID * 2); @@ -1436,24 +1427,24 @@ static int initpcmcia (const TCHAR *path, int readonly, int type, int reset, str if (currprefs.cs_pcmcia == 0) return 0; freepcmcia (reset); - if (!pcmcia_sram) - pcmcia_sram = xcalloc (struct hd_hardfiledata, 1); - if (!pcmcia_sram->hfd.handle_valid) + if (!pcmcia_disk) + pcmcia_disk = xcalloc (struct hd_hardfiledata, 1); + if (!pcmcia_disk->hfd.handle_valid) reset = 1; if (path != NULL) - _tcscpy (pcmcia_sram->hfd.ci.rootdir, path); - pcmcia_sram->hfd.ci.readonly = readonly != 0; - pcmcia_sram->hfd.ci.blocksize = 512; + _tcscpy (pcmcia_disk->hfd.ci.rootdir, path); + pcmcia_disk->hfd.ci.readonly = readonly != 0; + pcmcia_disk->hfd.ci.blocksize = 512; if (type == PCMCIA_SRAM) { if (reset) { if (path) - hdf_hd_open (pcmcia_sram); + hdf_hd_open (pcmcia_disk); } else { - pcmcia_sram->hfd.drive_empty = 0; + pcmcia_disk->hfd.drive_empty = 0; } - if (pcmcia_sram->hfd.ci.readonly) + if (pcmcia_disk->hfd.ci.readonly) readonly = 1; pcmcia_common_size = 0; pcmcia_readonly = readonly; @@ -1461,15 +1452,15 @@ static int initpcmcia (const TCHAR *path, int readonly, int type, int reset, str pcmcia_attrs = xcalloc (uae_u8, pcmcia_attrs_size); pcmcia_type = type; - if (!pcmcia_sram->hfd.drive_empty) { - pcmcia_common_size = pcmcia_sram->hfd.virtsize; - if (pcmcia_sram->hfd.virtsize > 4 * 1024 * 1024) { - write_log (_T("PCMCIA SRAM: too large device, %llu bytes\n"), pcmcia_sram->hfd.virtsize); + if (!pcmcia_disk->hfd.drive_empty) { + pcmcia_common_size = pcmcia_disk->hfd.virtsize; + if (pcmcia_disk->hfd.virtsize > 4 * 1024 * 1024) { + write_log (_T("PCMCIA SRAM: too large device, %llu bytes\n"), pcmcia_disk->hfd.virtsize); pcmcia_common_size = 4 * 1024 * 1024; } pcmcia_common = xcalloc (uae_u8, pcmcia_common_size); write_log (_T("PCMCIA SRAM: '%s' open, size=%d\n"), path, pcmcia_common_size); - hdf_read (&pcmcia_sram->hfd, pcmcia_common, 0, pcmcia_common_size); + hdf_read (&pcmcia_disk->hfd, pcmcia_common, 0, pcmcia_common_size); pcmcia_card = 1; initsramattr (pcmcia_common_size, readonly); } @@ -1512,7 +1503,7 @@ static int initpcmcia (const TCHAR *path, int readonly, int type, int reset, str } else if (type == PCMCIA_ARCHOSHD) { - pcmcia_sram->hfd.drive_empty = 0; + pcmcia_disk->hfd.drive_empty = 0; pcmcia_common_size = 0; pcmcia_readonly = 1; pcmcia_type = type; @@ -1865,11 +1856,11 @@ bool gayle_init_pcmcia(struct autoconfig_info *aci) return true; } -// eject any inserted PCMCIA card -void pcmcia_eject(struct uae_prefs *p) +static int pcmcia_eject2(struct uae_prefs *p) { for (int i = 0; i < MAX_EXPANSION_BOARDS; i++) { struct boardromconfig *brc_changed = &changed_prefs.expansionboard[i]; + struct boardromconfig *brc_cur = &currprefs.expansionboard[i]; struct boardromconfig *brc = &p->expansionboard[i]; if (brc->device_type) { const struct expansionromtype *ert = get_device_expansion_rom(brc->device_type); @@ -1877,13 +1868,47 @@ void pcmcia_eject(struct uae_prefs *p) write_log(_T("PCMCIA: '%s' removed\n"), ert->friendlyname); brc->roms[0].inserted = false; brc_changed->roms[0].inserted = false; + brc_cur->roms[0].inserted = false; freepcmcia(0); + return i; } } } + return -1; +} + +// eject any inserted PCMCIA card +void pcmcia_eject(struct uae_prefs *p) +{ + pcmcia_eject2(p); +} + +// eject and insert card back after few second delay +void pcmcia_reinsert(struct uae_prefs *p) +{ + pcmcia_delayed_insert_count = 0; + int num = pcmcia_eject2(p); + if (num < 0) + return; + pcmcia_delayed_insert = num + 1; + pcmcia_delayed_insert_count = 3 * 50 * 300; } -static void pcmcia_card_check(int changecheck) +bool pcmcia_disk_reinsert(struct uae_prefs *p, struct uaedev_config_info *uci, bool ejectonly) +{ + const struct expansionromtype *ert = get_unit_expansion_rom(uci->controller_type); + if (ert && (ert->deviceflags & EXPANSIONTYPE_PCMCIA)) { + if (ejectonly) { + pcmcia_eject2(p); + } else { + pcmcia_reinsert(p); + } + return true; + } + return false; +} + +static void pcmcia_card_check(int changecheck, int insertdev) { // allow only max single PCMCIA care inserted bool found = false; @@ -1893,6 +1918,9 @@ static void pcmcia_card_check(int changecheck) if (brc->device_type) { const struct expansionromtype *ert = get_device_expansion_rom(brc->device_type); if (ert && ert->deviceflags & EXPANSIONTYPE_PCMCIA) { + if (insertdev - 1 == i) { + brc->roms[0].inserted = true; + } if (found) { brc->roms[0].inserted = false; brc_prev->roms[0].inserted = false; @@ -1960,6 +1988,23 @@ static void pcmcia_card_check(int changecheck) } } +void gayle_hsync(void) +{ + if (ne2000) + ne2000->hsync(ne2000_board_state); + if (ide_interrupt_hsync(idedrive[0]) || ide_interrupt_hsync(idedrive[2]) || ide_interrupt_hsync(idedrive[4]) || checkpcmciane2000irq()) + devices_rethink_all(rethink_gayle); + if (archoshd[0]) + ide_interrupt_hsync(archoshd[0]); + if (pcmcia_delayed_insert_count > 0) { + pcmcia_delayed_insert_count--; + if (pcmcia_delayed_insert_count == 0) { + pcmcia_card_check(1, pcmcia_delayed_insert); + pcmcia_delayed_insert = 0; + } + } +} + static void initide (void) { gayle_its.idetable = idedrive; @@ -2009,14 +2054,14 @@ void gayle_reset (int hardreset) gayle_bank.name = bankname; gayle_dataflyer_enable(false); - pcmcia_card_check(0); + pcmcia_card_check(0, -1); } void check_prefs_changed_gayle(void) { if (!currprefs.cs_pcmcia) return; - pcmcia_card_check(1); + pcmcia_card_check(1, -1); } uae_u8 *restore_gayle (uae_u8 *src) diff --git a/hardfile.cpp b/hardfile.cpp index b393df2f..dcb6d641 100644 --- a/hardfile.cpp +++ b/hardfile.cpp @@ -30,6 +30,7 @@ #include "ide.h" #include "debug.h" #include "ini.h" +#include "rommgr.h" #ifdef WITH_CHD #include "archivers/chd/chdtypes.h" @@ -2347,16 +2348,12 @@ void hardfile_do_disk_change (struct uaedev_config_data *uci, bool insert) int fsid = uci->configoffset; struct hardfiledata *hfd; -#if 0 - if (uci->ci.controller_type == HD_CONTROLLER_TYPE_PCMCIA) { - if (uci->ci.controller_type_unit == 0) { - gayle_modify_pcmcia_sram_unit (&uci->ci, insert); - } else { - gayle_modify_pcmcia_ide_unit (&uci->ci, insert); - } + const struct expansionromtype *ert = get_unit_expansion_rom(uci->ci.controller_type); + if (ert && (ert->deviceflags & EXPANSIONTYPE_PCMCIA)) { + pcmcia_reinsert(&currprefs); return; } -#endif + hfd = get_hardfile_data (fsid); if (!hfd) return; diff --git a/include/gayle.h b/include/gayle.h index 936600a2..f106d9ed 100644 --- a/include/gayle.h +++ b/include/gayle.h @@ -16,6 +16,8 @@ extern bool gayle_init_pcmcia(struct autoconfig_info *aci); extern bool gayle_init_board_io_pcmcia(struct autoconfig_info *aci); extern bool gayle_init_board_common_pcmcia(struct autoconfig_info *aci); void pcmcia_eject(struct uae_prefs *p); +void pcmcia_reinsert(struct uae_prefs*); +bool pcmcia_disk_reinsert(struct uae_prefs *p, struct uaedev_config_info *uci, bool ejectonly); extern int gary_toenb; // non-existing memory access = bus error. extern int gary_timeout; // non-existing memory access = delay diff --git a/od-win32/hardfile_win32.cpp b/od-win32/hardfile_win32.cpp index 8b48b5f0..05d68f0b 100644 --- a/od-win32/hardfile_win32.cpp +++ b/od-win32/hardfile_win32.cpp @@ -16,6 +16,9 @@ #include "win32gui.h" #include "zfile.h" #include "ini.h" +#include "memory.h" +#include "autoconf.h" +#include "rommgr.h" #define hfd_log write_log #define hdf_log2 @@ -1031,7 +1034,7 @@ static bool readidentity(HANDLE h, struct uae_driveinfo *udi, struct hardfiledat memset(cmd, 0, sizeof(cmd)); memset(data, 0, 512); - cmd[0] = 0x85; // SAT ATA PASSTHROUGH (16) + cmd[0] = 0x85; // SAT ATA PASSTHROUGH (16) (12 conflicts with MMC BLANK command) cmd[1] = 4 << 1; // PIO data-in cmd[2] = 0x08 | 0x04 | 0x02; // dir = from device, 512 byte block, sector count = block cnt cmd[6] = 1; // block count @@ -3044,7 +3047,7 @@ static BOOL GetDevicePropertyFromName(const TCHAR *DevicePath, DWORD Index, DWOR if (ischs(udi->identity) && gli.Length.QuadPart == 0) { int c, h, s; tochs(udi->identity, -1, &c, &h, &s); - udi->size = c * h * s * 512; + udi->size = (uae_u64)c * h * s * 512; udi->cylinders = c; udi->heads = h; udi->sectors = s; @@ -3541,16 +3544,15 @@ int win32_hardfile_media_change (const TCHAR *drvname, int inserted) } } } -#if 0 for (i = 0; i < currprefs.mountitems; i++) { - extern struct hd_hardfiledata *pcmcia_sram; + extern struct hd_hardfiledata *pcmcia_disk; int reopen = 0; struct uaedev_config_data *uci = &currprefs.mountconfig[i]; - if (uci->ci.controller_type == HD_CONTROLLER_TYPE_PCMCIA && uci->ci.controller_type_unit == 0) { - hmc_check (&pcmcia_sram->hfd, uci, &rescanned, &reopen, &gotinsert, drvname, inserted); + const struct expansionromtype *ert = get_unit_expansion_rom(uci->ci.controller_type); + if (ert && (ert->deviceflags & EXPANSIONTYPE_PCMCIA) && pcmcia_disk) { + hmc_check (&pcmcia_disk->hfd, uci, &rescanned, &reopen, &gotinsert, drvname, inserted); } } -#endif //write_log (_T("win32_hardfile_media_change returned %d\n"), gotinsert); return gotinsert; }