]> git.unchartedbackwaters.co.uk Git - francis/winuae.git/commitdiff
Autoconfig statefile framework.
authorToni Wilen <twilen@winuae.net>
Tue, 18 Jun 2019 17:37:25 +0000 (20:37 +0300)
committerToni Wilen <twilen@winuae.net>
Tue, 18 Jun 2019 17:37:25 +0000 (20:37 +0300)
devices.cpp
expansion.cpp
include/savestate.h
savestate.cpp

index ddf072d639336b9353c84847756fa44e50573f92..d00e120e51e5edd7b35f65503b906f4d39b9699b 100644 (file)
@@ -468,6 +468,7 @@ void devices_restore_start(void)
        }
        changed_prefs.mbresmem_low_size = 0;
        changed_prefs.mbresmem_high_size = 0;
+       restore_expansion_board(NULL);
 }
 
 void devices_syncchange(void)
index 0cb30e6353877c093a7aeba5d7d537f628a4435a..67de7d85a3def2dda7102bb0942b7c54a5687ad1 100644 (file)
@@ -201,6 +201,7 @@ static struct card_data cards_set[MAX_EXPANSION_BOARD_SPACE];
 static struct card_data *cards[MAX_EXPANSION_BOARD_SPACE];
 
 static int ecard, cardno, z3num;
+static int restore_cardno;
 static addrbank *expamem_bank_current;
 
 static uae_u16 uae_id;
@@ -2758,8 +2759,10 @@ static void reset_ac(struct uae_prefs *p)
        else
                uae_id = hackers_id;
 
-       for (int i = 0; i < MAX_EXPANSION_BOARD_SPACE; i++) {
-               memset(&cards_set[i], 0, sizeof(struct card_data));
+       if (!savestate_state) {
+               for (int i = 0; i < MAX_EXPANSION_BOARD_SPACE; i++) {
+                       memset(&cards_set[i], 0, sizeof(struct card_data));
+               }
        }
 
        ecard = 0;
@@ -3936,58 +3939,121 @@ uae_u8 *restore_expansion (uae_u8 *src)
        return src;
 }
 
-uae_u8 *save_expansion_info(int *len, uae_u8 *dstptr)
+uae_u8 *save_expansion_board(int *len, uae_u8 *dstptr, int cardnum)
 {
        uae_u8 *dst, *dstbak;
+       if (cardnum >= cardno)
+               return NULL;
        if (dstptr)
                dst = dstbak = dstptr;
        else
-               dstbak = dst = xmalloc(uae_u8, 100 + MAX_EXPANSION_BOARD_SPACE * 100);
-       save_u32(1);
+               dstbak = dst = xmalloc(uae_u8, 1000);
+       save_u32(3);
        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(cardnum);
+       struct card_data *ec = cards[cardnum];
+       save_u32(ec->base);
+       save_u32(ec->size);
+       save_u32(ec->flags);
+       save_string(ec->name);
+       for (int j = 0; j < 16; j++) {
+               save_u8(ec->aci.autoconfig_bytes[j]);
+       }
+       struct romconfig *rc = ec->rc;
+       if (rc) {
+               save_u32(rc->back->device_type);
+               save_u32(rc->back->device_num);
+               save_string(rc->romfile);
+               save_string(rc->romident);
+               save_u32(rc->device_id);
+               save_u32(rc->device_settings);
+               save_string(rc->configtext);
+       } else {
+               save_u32(0xffffffff);
        }
-       save_u32(0);
        *len = dst - dstbak;
        return dstbak;
 }
 
-uae_u8 *restore_expansion_info(uae_u8 *src)
+uae_u8 *restore_expansion_board(uae_u8 *src)
 {
-       if (restore_u32() != 1)
+       if (!src) {
+               restore_cardno = 0;
+               return NULL;
+       }
+       TCHAR *s;
+       uae_u32 flags = restore_u32();
+       if (!(flags & 2))
                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();
+       int cardnum = restore_u32();
+       restore_cardno = cardnum + 1;
+       struct card_data *ec = &cards_set[cardnum];
+       cards[cardnum] = ec;
+
+       ec->base = restore_u32();
+       ec->size = restore_u32();
+       ec->flags = restore_u32();
+       s = restore_string();
+       xfree(s);
+       for (int j = 0; j < 16; j++) {
+               ec->aci.autoconfig_bytes[j] = restore_u8();
+       }
+
+       uae_u32 dev_num = 0;
+       uae_u32 romtype = restore_u32();
+       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 romconfig *rc = get_device_romconfig(&currprefs, romtype, dev_num);
+               if (rc) {
+                       ec->rc = rc;
+                       ec->ert = get_device_expansion_rom(romtype);
+                       s = restore_string();
+                       _tcscpy(rc->romfile, s);
+                       xfree(s);
+                       s = restore_string();
+                       _tcscpy(rc->romident, s);
+                       xfree(s);
+                       rc->device_id = restore_u32();
+                       rc->device_settings = restore_u32();
+                       s = restore_string();
+                       _tcscpy(rc->configtext, s);
+                       xfree(s);
                }
-               restore_u32();
-               restore_u32();
-               restore_u32();
-               restore_string();
        }
-       restore_u32();
        return src;
 }
 
+void restore_expansion_finish(void)
+{
+       cardno = restore_cardno;
+       for (int i = 0; i < cardno; i++) {
+               struct card_data *ec = &cards_set[i];
+               cards[i] = ec;
+               struct romconfig *rc = ec->rc;
+               // Handle only IO boards, RAM boards are handled differently
+               if (rc && ec->ert) {
+                       ec->aci.doinit = false;
+                       ec->aci.start = ec->base;
+                       ec->aci.size = ec->size;
+                       _tcscpy(ec->aci.name, ec->ert->friendlyname);
+                       if (ec->ert->init) {
+                               if (ec->ert->init(&ec->aci)) {
+                                       if (ec->aci.addrbank) {
+                                               map_banks(ec->aci.addrbank, ec->base >> 16, ec->size >> 16, 0);
+                                       }
+                               }
+                       }
+                       ec->aci.doinit = true;
+               }
+       }
+}
+
+
 #endif /* SAVESTATE */
 
 #if 0
index 0a43b5624237dff6aa3d1c5c8597df455404bf1e..facffae06ad0a8dc7642614600c699162d42d62a 100644 (file)
@@ -217,8 +217,9 @@ 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_info(int*, uae_u8*);
-extern uae_u8 *restore_expansion_info(uae_u8*);
+extern uae_u8 *save_expansion_board(int*, uae_u8*,int);
+extern uae_u8 *restore_expansion_board(uae_u8*);
+extern void restore_expansion_finish(void);
 
 extern uae_u8 *restore_action_replay (uae_u8 *);
 extern uae_u8 *save_action_replay (int *, uae_u8 *);
index e1889adfa30dcd658665cf40a0490b945fc41dad..9f56b71aa75e01a858b00e9bf9162dc1c14b702a 100644 (file)
@@ -782,8 +782,8 @@ void restore_state (const TCHAR *filename)
                else if (!_tcsncmp (name, _T("2065"), 4))
                        end = restore_a2065 (chunk);
 #endif
-               else if (!_tcsncmp (name, _T("EXPI"), 4))
-                       end = restore_expansion_info(chunk);
+               else if (!_tcsncmp (name, _T("EXPB"), 4))
+                       end = restore_expansion_board(chunk);
                else if (!_tcsncmp (name, _T("DMWP"), 4))
                        end = restore_debug_memwatch (chunk);
                else if (!_tcsncmp(name, _T("PIC0"), 4))
@@ -830,6 +830,7 @@ void savestate_restore_finish (void)
        restore_audio_finish ();
        restore_disk_finish ();
        restore_blitter_finish ();
+       restore_expansion_finish();
        restore_akiko_finish ();
 #ifdef CDTV
        restore_cdtv_finish ();
@@ -1001,9 +1002,11 @@ static int save_state_internal (struct zfile *f, const TCHAR *description, int c
        save_chunk (f, dst, len, _T("CINP"), 0);
        xfree (dst);
 
-       dst = save_custom_agacolors (&len, 0);
-       save_chunk (f, dst, len, _T("AGAC"), 0);
-       xfree (dst);
+       dst = save_custom_agacolors(&len, 0);
+       if (dst) {
+               save_chunk(f, dst, len, _T("AGAC"), 0);
+               xfree(dst);
+       }
 
        _tcscpy (name, _T("SPRx"));
        for (i = 0; i < 8; i++) {
@@ -1034,8 +1037,14 @@ static int save_state_internal (struct zfile *f, const TCHAR *description, int c
        xfree (dst);
 
 #ifdef AUTOCONFIG
-       dst = save_expansion_info(&len, 0);
-       save_chunk(f, dst, len, _T("EXPI"), 0);
+       i = 0;
+       for (;;) {
+               dst = save_expansion_board(&len, 0, i);
+               if (!dst)
+                       break;
+               save_chunk(f, dst, len, _T("EXPB"), 0);
+               i++;
+       }
        dst = save_expansion(&len, 0);
        save_chunk(f, dst, len, _T("EXPA"), 0);
 #endif