src/emu/mame.c
| r1676 | r1677 | |
| 143 | 143 | UINT8 exit_pending; |
| 144 | 144 | const game_driver *new_driver_pending; |
| 145 | 145 | astring * saveload_pending_file; |
| 146 | const char * saveload_searchpath; |
| 146 | 147 | emu_timer * soft_reset_timer; |
| 147 | 148 | mame_file * logfile; |
| 148 | 149 | |
| r1676 | r1677 | |
| 670 | 671 | |
| 671 | 672 | |
| 672 | 673 | /*------------------------------------------------- |
| 673 | | mame_schedule_save - schedule a save to |
| 674 | | occur as soon as possible |
| 674 | set_saveload_filename - specifies the filename |
| 675 | for state loading/saving |
| 675 | 676 | -------------------------------------------------*/ |
| 676 | 677 | |
| 677 | | void mame_schedule_save(running_machine *machine, const char *filename) |
| 678 | static void set_saveload_filename(running_machine *machine, const char *filename) |
| 678 | 679 | { |
| 679 | 680 | mame_private *mame = machine->mame_data; |
| 680 | 681 | |
| 681 | 682 | /* free any existing request and allocate a copy of the requested name */ |
| 682 | 683 | if (mame->saveload_pending_file != NULL) |
| 683 | 684 | astring_free(mame->saveload_pending_file); |
| 684 | | mame->saveload_pending_file = astring_assemble_4(astring_alloc(), machine->basename, PATH_SEPARATOR, filename, ".sta"); |
| 685 | 685 | |
| 686 | if (osd_is_absolute_path(filename)) |
| 687 | { |
| 688 | mame->saveload_searchpath = NULL; |
| 689 | mame->saveload_pending_file = astring_dupc(filename); |
| 690 | } |
| 691 | else |
| 692 | { |
| 693 | mame->saveload_searchpath = SEARCHPATH_STATE; |
| 694 | mame->saveload_pending_file = astring_assemble_4(astring_alloc(), machine->basename, PATH_SEPARATOR, filename, ".sta"); |
| 695 | } |
| 696 | } |
| 697 | |
| 698 | |
| 699 | /*------------------------------------------------- |
| 700 | mame_schedule_save - schedule a save to |
| 701 | occur as soon as possible |
| 702 | -------------------------------------------------*/ |
| 703 | |
| 704 | void mame_schedule_save(running_machine *machine, const char *filename) |
| 705 | { |
| 706 | mame_private *mame = machine->mame_data; |
| 707 | |
| 708 | /* specify the filename to save or load */ |
| 709 | set_saveload_filename(machine, filename); |
| 710 | |
| 686 | 711 | /* note the start time and set a timer for the next timeslice to actually schedule it */ |
| 687 | 712 | mame->saveload_schedule_callback = handle_save; |
| 688 | 713 | mame->saveload_schedule_time = timer_get_time(); |
| r1676 | r1677 | |
| 701 | 726 | { |
| 702 | 727 | mame_private *mame = machine->mame_data; |
| 703 | 728 | |
| 704 | | /* free any existing request and allocate a copy of the requested name */ |
| 705 | | if (mame->saveload_pending_file != NULL) |
| 706 | | astring_free(mame->saveload_pending_file); |
| 707 | | mame->saveload_pending_file = astring_assemble_4(astring_alloc(), machine->basename, PATH_SEPARATOR, filename, ".sta"); |
| 729 | /* specify the filename to save or load */ |
| 730 | set_saveload_filename(machine, filename); |
| 708 | 731 | |
| 709 | 732 | /* note the start time and set a timer for the next timeslice to actually schedule it */ |
| 710 | 733 | mame->saveload_schedule_callback = handle_load; |
| r1676 | r1677 | |
| 1698 | 1721 | } |
| 1699 | 1722 | |
| 1700 | 1723 | /* open the file */ |
| 1701 | | filerr = mame_fopen(SEARCHPATH_STATE, astring_c(mame->saveload_pending_file), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS, &file); |
| 1724 | filerr = mame_fopen(mame->saveload_searchpath, astring_c(mame->saveload_pending_file), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS, &file); |
| 1702 | 1725 | if (filerr == FILERR_NONE) |
| 1703 | 1726 | { |
| 1704 | 1727 | int cpunum; |
| r1676 | r1677 | |
| 1748 | 1771 | cancel: |
| 1749 | 1772 | /* unschedule the save */ |
| 1750 | 1773 | astring_free(mame->saveload_pending_file); |
| 1774 | mame->saveload_searchpath = NULL; |
| 1751 | 1775 | mame->saveload_pending_file = NULL; |
| 1752 | 1776 | mame->saveload_schedule_callback = NULL; |
| 1753 | 1777 | } |
| r1676 | r1677 | |
| 1784 | 1808 | } |
| 1785 | 1809 | |
| 1786 | 1810 | /* open the file */ |
| 1787 | | filerr = mame_fopen(SEARCHPATH_STATE, astring_c(mame->saveload_pending_file), OPEN_FLAG_READ, &file); |
| 1811 | filerr = mame_fopen(mame->saveload_searchpath, astring_c(mame->saveload_pending_file), OPEN_FLAG_READ, &file); |
| 1788 | 1812 | if (filerr == FILERR_NONE) |
| 1789 | 1813 | { |
| 1790 | 1814 | /* start loading */ |