diff --git a/a2065.cpp b/a2065.cpp index a27cb9b56..eb0d16cad 100644 --- a/a2065.cpp +++ b/a2065.cpp @@ -1153,7 +1153,7 @@ static bool a2065_config (struct autoconfig_info *aci) device_add_hsync(a2065_hsync_handler); device_add_rethink(rethink_a2065); - device_add_exit(a2065_free); + device_add_exit(a2065_free, NULL); return true; } diff --git a/a2091.cpp b/a2091.cpp index 999197558..fb76d9819 100644 --- a/a2091.cpp +++ b/a2091.cpp @@ -4567,9 +4567,9 @@ static void wd_init(void) { device_add_hsync(scsi_hsync); device_add_rethink(rethink_a2091); - device_add_exit(a2091_free); - device_add_exit(gvp_free); - device_add_exit(a3000scsi_free); + device_add_exit(a2091_free, NULL); + device_add_exit(gvp_free, NULL); + device_add_exit(a3000scsi_free, NULL); } #if 0 diff --git a/akiko.cpp b/akiko.cpp index 06b34c1e7..c988bef99 100644 --- a/akiko.cpp +++ b/akiko.cpp @@ -2154,7 +2154,7 @@ int akiko_init(void) device_add_rethink(rethink_akiko); } - device_add_exit(akiko_free); + device_add_exit(akiko_free, NULL); return 1; } diff --git a/cd32_fmv.cpp b/cd32_fmv.cpp index 0c69f00f0..4f693f0b1 100644 --- a/cd32_fmv.cpp +++ b/cd32_fmv.cpp @@ -1585,7 +1585,7 @@ addrbank *cd32_fmv_init (struct autoconfig_info *aci) device_add_hsync(cd32_fmv_hsync_handler); device_add_vsync_pre(cd32_fmv_vsync_handler); - device_add_exit(cd32_fmv_free); + device_add_exit(cd32_fmv_free, NULL); device_add_rethink(rethink_cd32fmv); return &fmv_rom_bank; diff --git a/cdtv.cpp b/cdtv.cpp index 86e44ae08..af7ab11a0 100644 --- a/cdtv.cpp +++ b/cdtv.cpp @@ -1760,7 +1760,7 @@ bool cdtv_init(struct autoconfig_info *aci) device_add_hsync(CDTV_hsync_handler); device_add_rethink(rethink_cdtv); - device_add_exit(cdtv_free); + device_add_exit(cdtv_free, NULL); return true; } diff --git a/cdtvcr.cpp b/cdtvcr.cpp index 43ff29655..738c4426c 100644 --- a/cdtvcr.cpp +++ b/cdtvcr.cpp @@ -1043,7 +1043,7 @@ bool cdtvcr_init(struct autoconfig_info *aci) device_add_hsync(CDTVCR_hsync_handler); device_add_rethink(rethink_cdtvcr); - device_add_exit(cdtvcr_free); + device_add_exit(cdtvcr_free, NULL); return true; } diff --git a/devices.cpp b/devices.cpp index f527fa68b..1473677ed 100644 --- a/devices.cpp +++ b/devices.cpp @@ -96,6 +96,8 @@ static int device_rethink_cnt; static DEVICE_VOID device_rethinks[MAX_DEVICE_ITEMS]; static int device_leave_cnt; static DEVICE_VOID device_leaves[MAX_DEVICE_ITEMS]; +static int device_leave_early_cnt; +static DEVICE_VOID device_leaves_early[MAX_DEVICE_ITEMS]; static int device_resets_cnt; static DEVICE_INT device_resets[MAX_DEVICE_ITEMS]; static bool device_reset_done[MAX_DEVICE_ITEMS]; @@ -109,6 +111,7 @@ static void reset_device_items(void) device_rethink_cnt = 0; device_resets_cnt = 0; device_leave_cnt = 0; + device_leave_early_cnt = 0; memset(device_reset_done, 0, sizeof(device_reset_done)); } @@ -132,9 +135,14 @@ void device_add_check_config(DEVICE_VOID p) { add_device_item(device_configs, &device_configs_cnt, p); } -void device_add_exit(DEVICE_VOID p) +void device_add_exit(DEVICE_VOID p, DEVICE_VOID p2) { - add_device_item(device_leaves, &device_leave_cnt, p); + if (p != NULL) { + add_device_item(device_leaves, &device_leave_cnt, p); + } + if (p2 != NULL) { + add_device_item(device_leaves_early, &device_leave_early_cnt, p2); + } } void device_add_reset(DEVICE_INT p) { @@ -308,6 +316,9 @@ void virtualdevice_free(void) // must be first uae_ppc_free(); #endif + + execute_device_items(device_leaves_early, device_leave_early_cnt); + #ifdef FILESYS filesys_cleanup(); #endif diff --git a/gayle.cpp b/gayle.cpp index 4db68d1a9..312d22104 100644 --- a/gayle.cpp +++ b/gayle.cpp @@ -2207,7 +2207,7 @@ static void gayle_init(void) device_add_check_config(check_prefs_changed_gayle); device_add_rethink(rethink_gayle); device_add_hsync(gayle_hsync); - device_add_exit(gayle_free); + device_add_exit(gayle_free, NULL); } uae_u8 *save_gayle(size_t *len, uae_u8 *dstptr) diff --git a/idecontrollers.cpp b/idecontrollers.cpp index 4d4b4d275..c65e4a071 100644 --- a/idecontrollers.cpp +++ b/idecontrollers.cpp @@ -1974,7 +1974,7 @@ static struct ide_board *getide(struct autoconfig_info *aci) { device_add_rethink(idecontroller_rethink); device_add_hsync(idecontroller_hsync); - device_add_exit(idecontroller_free); + device_add_exit(idecontroller_free, NULL); for (int i = 0; i < MAX_IDE_UNITS; i++) { if (ide_boards[i]) { diff --git a/include/devices.h b/include/devices.h index 0df38e310..75c769044 100644 --- a/include/devices.h +++ b/include/devices.h @@ -30,7 +30,7 @@ void device_add_rethink(DEVICE_VOID p); void device_add_check_config(DEVICE_VOID p); void device_add_reset(DEVICE_INT p); void device_add_reset_imm(DEVICE_INT p); -void device_add_exit(DEVICE_VOID p); +void device_add_exit(DEVICE_VOID p, DEVICE_VOID p2); #define IRQ_SOURCE_PCI 0 #define IRQ_SOURCE_SOUND 1 diff --git a/ncr9x_scsi.cpp b/ncr9x_scsi.cpp index bd9a0768f..a90bce2d6 100644 --- a/ncr9x_scsi.cpp +++ b/ncr9x_scsi.cpp @@ -1931,7 +1931,7 @@ static void ncr9x_reset_board(struct ncr9x_state *ncr) device_add_rethink(ncr9x_rethink); device_add_reset(ncr9x_reset); - device_add_exit(ncr9x_free); + device_add_exit(ncr9x_free, NULL); } void ncr_squirrel_init(struct romconfig *rc, uaecptr baseaddress) diff --git a/ncr_scsi.cpp b/ncr_scsi.cpp index de5332bdb..d84c1ceb6 100644 --- a/ncr_scsi.cpp +++ b/ncr_scsi.cpp @@ -872,7 +872,7 @@ static void ncr_reset_board (struct ncr_state *ncr) ncr->irq = false; device_add_rethink(ncr_rethink); - device_add_exit(ncr_free); + device_add_exit(ncr_free, NULL); device_add_vsync_pre(ncr_vsync); device_add_reset(ncr_reset); } diff --git a/od-win32/picasso96_win.cpp b/od-win32/picasso96_win.cpp index a2e7a5807..ad7759dac 100644 --- a/od-win32/picasso96_win.cpp +++ b/od-win32/picasso96_win.cpp @@ -6659,7 +6659,7 @@ void uaegfx_install_code (uaecptr start) device_add_reset(picasso_reset); device_add_hsync(picasso_handle_hsync); - device_add_exit(picasso_free); + device_add_exit(picasso_free, NULL); } #define UAEGFX_VERSION 3 diff --git a/pci.cpp b/pci.cpp index 2835fdead..60d643e9c 100644 --- a/pci.cpp +++ b/pci.cpp @@ -1768,7 +1768,7 @@ static void pci_init(void) { device_add_reset(pci_reset); device_add_rethink(pci_rethink); - device_add_exit(pci_free); + device_add_exit(pci_free, NULL); device_add_hsync(pci_hsync); } diff --git a/qemuvga/ne2000.cpp b/qemuvga/ne2000.cpp index a2a60ac0f..dbfe3598d 100644 --- a/qemuvga/ne2000.cpp +++ b/qemuvga/ne2000.cpp @@ -1947,7 +1947,7 @@ static void ne2000_free(void) static void init(void) { - device_add_exit(ne2000_free); + device_add_exit(ne2000_free, NULL); device_add_reset(ne2000_reset); device_add_hsync(ne2000_hsync); device_add_rethink(rethink_ne2000); diff --git a/scsi.cpp b/scsi.cpp index 176eebb8d..c431fe28f 100644 --- a/scsi.cpp +++ b/scsi.cpp @@ -4327,7 +4327,7 @@ static struct soft_scsi *getscsi(struct romconfig *rc) { device_add_rethink(ncr80_rethink); device_add_reset(soft_scsi_reset); - device_add_exit(soft_scsi_free); + device_add_exit(soft_scsi_free, NULL); if (rc->unitdata) return (struct soft_scsi *)rc->unitdata; return NULL; diff --git a/sndboard.cpp b/sndboard.cpp index 2fdb8a46a..7a6cdbdba 100644 --- a/sndboard.cpp +++ b/sndboard.cpp @@ -3002,8 +3002,8 @@ static void snd_init(void) device_add_hsync(sndboard_hsync); device_add_vsync_post(sndboard_vsync); device_add_rethink(sndboard_rethink); - device_add_exit(sndboard_free); - device_add_exit(uaesndboard_free); + device_add_exit(sndboard_free, NULL); + device_add_exit(uaesndboard_free, NULL); } diff --git a/x86.cpp b/x86.cpp index 1505a35f7..6093e1073 100644 --- a/x86.cpp +++ b/x86.cpp @@ -3854,7 +3854,7 @@ bool x86_bridge_init(struct autoconfig_info *aci, uae_u32 romtype, int type) device_add_hsync(x86_bridge_hsync); device_add_vsync_pre(x86_bridge_vsync); - device_add_exit(x86_bridge_free); + device_add_exit(x86_bridge_free, NULL); device_add_rethink(x86_bridge_rethink); return true;