From: Toni Wilen Date: Fri, 12 Jul 2019 16:33:01 +0000 (+0300) Subject: Expansion device statefile framework. X-Git-Tag: 4300~185 X-Git-Url: https://git.unchartedbackwaters.co.uk/w/?a=commitdiff_plain;h=cf2c7cbbf1b2896bb1dd7338be07cb5a1e42e78a;p=francis%2Fwinuae.git Expansion device statefile framework. --- diff --git a/devices.cpp b/devices.cpp index d00e120e..f60f8af5 100644 --- a/devices.cpp +++ b/devices.cpp @@ -468,7 +468,7 @@ void devices_restore_start(void) } changed_prefs.mbresmem_low_size = 0; changed_prefs.mbresmem_high_size = 0; - restore_expansion_board(NULL); + restore_expansion_boards(NULL); } void devices_syncchange(void) diff --git a/expansion.cpp b/expansion.cpp index 67de7d85..e09b0c8a 100644 --- a/expansion.cpp +++ b/expansion.cpp @@ -2759,7 +2759,7 @@ static void reset_ac(struct uae_prefs *p) else uae_id = hackers_id; - if (!savestate_state) { + if (restore_cardno == 0) { for (int i = 0; i < MAX_EXPANSION_BOARD_SPACE; i++) { memset(&cards_set[i], 0, sizeof(struct card_data)); } @@ -3939,7 +3939,7 @@ uae_u8 *restore_expansion (uae_u8 *src) return src; } -uae_u8 *save_expansion_board(int *len, uae_u8 *dstptr, int cardnum) +uae_u8 *save_expansion_boards(int *len, uae_u8 *dstptr, int cardnum) { uae_u8 *dst, *dstbak; if (cardnum >= cardno) @@ -3975,7 +3975,7 @@ uae_u8 *save_expansion_board(int *len, uae_u8 *dstptr, int cardnum) return dstbak; } -uae_u8 *restore_expansion_board(uae_u8 *src) +uae_u8 *restore_expansion_boards(uae_u8 *src) { if (!src) { restore_cardno = 0; @@ -4005,12 +4005,14 @@ uae_u8 *restore_expansion_board(uae_u8 *src) if (romtype != 0xffffffff) { dev_num = restore_u32(); ec->aci.devnum = dev_num; - if (!get_device_rom(&currprefs, romtype, dev_num, NULL)) { - get_device_rom_new(&currprefs, romtype, dev_num, NULL); + struct boardromconfig* brc = get_device_rom(&currprefs, romtype, dev_num, NULL); + if (!brc) { + brc = get_device_rom_new(&currprefs, romtype, dev_num, NULL); } struct romconfig *rc = get_device_romconfig(&currprefs, romtype, dev_num); if (rc) { ec->rc = rc; + rc->back = brc; ec->ert = get_device_expansion_rom(romtype); s = restore_string(); _tcscpy(rc->romfile, s); @@ -4028,6 +4030,64 @@ uae_u8 *restore_expansion_board(uae_u8 *src) return src; } +#if 0 +// old style +uae_u8 *save_expansion_info_old(int *len, uae_u8 *dstptr) +{ + uae_u8* dst, * dstbak; + if (dstptr) + dst = dstbak = dstptr; + else + dstbak = dst = xmalloc(uae_u8, 100 + MAX_EXPANSION_BOARD_SPACE * 100); + save_u32(1); + save_u32(0); + save_u32(cardno); + for (int i = 0; i < cardno; i++) { + struct card_data* ec = cards[i]; + if (ec->rc) { + save_u32(ec->rc->back->device_type); + save_u32(ec->rc->back->device_num); + save_string(ec->rc->romfile); + save_string(ec->rc->romident); + } + else { + save_u32(0xffffffff); + } + save_u32(ec->base); + save_u32(ec->size); + save_u32(ec->flags); + save_string(ec->name); + } + save_u32(0); + *len = dst - dstbak; + return dstbak; +} + +uae_u8 *restore_expansion_info_old(uae_u8 *src) +{ + if (restore_cardno) + return src; + if (restore_u32() != 1) + return src; + restore_u32(); + int num = restore_u32(); + for (int i = 0; i < num; i++) { + int romtype = restore_u32(); + if (romtype != 0xffffffff) { + restore_u32(); + restore_string(); + restore_string(); + } + restore_u32(); + restore_u32(); + restore_u32(); + restore_string(); + } + restore_u32(); + return src; +} +#endif + void restore_expansion_finish(void) { cardno = restore_cardno; diff --git a/include/savestate.h b/include/savestate.h index facffae0..5f902752 100644 --- a/include/savestate.h +++ b/include/savestate.h @@ -217,8 +217,12 @@ extern uae_u8 *save_a3000hram (int *); extern uae_u8 *restore_rom (uae_u8 *); extern uae_u8 *save_rom (int, int *, uae_u8 *); -extern uae_u8 *save_expansion_board(int*, uae_u8*,int); -extern uae_u8 *restore_expansion_board(uae_u8*); +extern uae_u8 *save_expansion_boards(int*, uae_u8*, int); +extern uae_u8 *restore_expansion_boards(uae_u8*); +#if 0 +extern uae_u8 *save_expansion_info_old(int*, uae_u8*); +extern uae_u8 *restore_expansion_info_old(uae_u8*); +#endif extern void restore_expansion_finish(void); extern uae_u8 *restore_action_replay (uae_u8 *); diff --git a/savestate.cpp b/savestate.cpp index 9f56b71a..35ca3ce0 100644 --- a/savestate.cpp +++ b/savestate.cpp @@ -781,9 +781,13 @@ void restore_state (const TCHAR *filename) #ifdef A2065 else if (!_tcsncmp (name, _T("2065"), 4)) end = restore_a2065 (chunk); +#endif +#if 0 + else if (!_tcsncmp(name, _T("EXPI"), 4)) + end = restore_expansion_info_old(chunk); #endif else if (!_tcsncmp (name, _T("EXPB"), 4)) - end = restore_expansion_board(chunk); + end = restore_expansion_boards(chunk); else if (!_tcsncmp (name, _T("DMWP"), 4)) end = restore_debug_memwatch (chunk); else if (!_tcsncmp(name, _T("PIC0"), 4)) @@ -1037,14 +1041,20 @@ static int save_state_internal (struct zfile *f, const TCHAR *description, int c xfree (dst); #ifdef AUTOCONFIG + // new i = 0; for (;;) { - dst = save_expansion_board(&len, 0, i); + dst = save_expansion_boards(&len, 0, i); if (!dst) break; save_chunk(f, dst, len, _T("EXPB"), 0); i++; } +#if 0 + // old + dst = save_expansion_info_old(&len, 0); + save_chunk(f, dst, len, _T("EXPI"), 0); +#endif dst = save_expansion(&len, 0); save_chunk(f, dst, len, _T("EXPA"), 0); #endif