comparison genesis.c @ 2335:c05b7c5e6f11

Automatically format Sega CD backup RAM
author Michael Pavone <pavone@retrodev.com>
date Sat, 26 Aug 2023 20:32:53 -0700
parents 9dd27530c570
children 83f5529086c5
comparison
equal deleted inserted replaced
2334:57ebbc1ade30 2335:c05b7c5e6f11
1605 uint32_t read = fread(cd->bram, 1, 8 * 1024, f); 1605 uint32_t read = fread(cd->bram, 1, 8 * 1024, f);
1606 fclose(f); 1606 fclose(f);
1607 if (read > 0) { 1607 if (read > 0) {
1608 printf("Loaded internal BRAM from %s\n", bram_name); 1608 printf("Loaded internal BRAM from %s\n", bram_name);
1609 } 1609 }
1610 } else {
1611 segacd_format_bram(cd->bram, 8 * 1024);
1610 } 1612 }
1611 free(bram_name); 1613 free(bram_name);
1612 bram_name = path_append(system->save_dir, "cart.bram"); 1614 bram_name = path_append(system->save_dir, "cart.bram");
1613 f = fopen(bram_name, "rb"); 1615 f = fopen(bram_name, "rb");
1616 long configured_size = 0x2000 << cd->bram_cart_id;
1614 if (f) { 1617 if (f) {
1615 long existing_size = nearest_pow2(file_size(f)); 1618 long existing_size = nearest_pow2(file_size(f));
1616 if (existing_size > 1 * 1024 * 1024) { 1619 if (existing_size > 1 * 1024 * 1024) {
1617 existing_size = 1 * 1024 * 1024; 1620 existing_size = 1 * 1024 * 1024;
1618 } 1621 }
1619 long configured_size = 0x2000 << cd->bram_cart_id;
1620 if (existing_size != configured_size) { 1622 if (existing_size != configured_size) {
1621 if (existing_size > configured_size) { 1623 if (existing_size > configured_size) {
1622 free(cd->bram_cart); 1624 free(cd->bram_cart);
1623 cd->bram_cart = calloc(existing_size, 1); 1625 cd->bram_cart = calloc(existing_size, 1);
1624 } 1626 }
1630 uint32_t read = fread(cd->bram_cart, 1, existing_size, f); 1632 uint32_t read = fread(cd->bram_cart, 1, existing_size, f);
1631 fclose(f); 1633 fclose(f);
1632 if (read > 0) { 1634 if (read > 0) {
1633 printf("Loaded BRAM cart from %s\n", bram_name); 1635 printf("Loaded BRAM cart from %s\n", bram_name);
1634 } 1636 }
1637 } else {
1638 segacd_format_bram(cd->bram_cart, configured_size);
1635 } 1639 }
1636 free(bram_name); 1640 free(bram_name);
1637 } 1641 }
1638 } 1642 }
1639 1643