~ubuntu-branches/ubuntu/vivid/fceux/vivid

« back to all changes in this revision

Viewing changes to src/state.cpp

  • Committer: Package Import Robot
  • Author(s): Joe Nahmias
  • Date: 2014-03-02 19:22:04 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20140302192204-9f0aehi5stfnhn7d
Tags: 2.2.2+dfsg0-1
* Imported Upstream version 2.2.2
  + remove patches merged upstream; refresh remaining
  + remove windows compiled help files and non-free Visual C files
* Use C++11 standard static assertion functionality
* fix upstream installation of support files
* New patch 0004-ignore-missing-windows-help-CHM-file.patch
* update d/copyright for new, renamed, deleted files
* d/control: bump std-ver to 3.9.5, no changes needed

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 
21
21
//  TODO: Add (better) file io error checking
22
22
 
23
 
#include <string>
24
 
#include <stdio.h>
25
 
#include <stdlib.h>
26
 
#include <string.h>
27
 
//#include <unistd.h> //mbg merge 7/17/06 removed
28
 
 
29
 
#include <vector>
30
 
#include <fstream>
31
 
 
32
23
#include "version.h"
33
24
#include "types.h"
34
25
#include "x6502.h"
58
49
#include "drivers/win/ramwatch.h"
59
50
#endif
60
51
 
 
52
#include <string>
 
53
#include <cstdio>
 
54
#include <cstdlib>
 
55
#include <cstring>
 
56
//#include <unistd.h> //mbg merge 7/17/06 removed
 
57
 
 
58
#include <vector>
 
59
#include <fstream>
 
60
 
61
61
using namespace std;
62
62
 
63
63
static void (*SPreSave)(void);
100
100
extern SFORMAT FCEUCTRL_STATEINFO[];
101
101
extern SFORMAT FCEUMOV_STATEINFO[];
102
102
 
 
103
//why two separate CPU structs?? who knows
103
104
 
104
105
SFORMAT SFCPU[]={
105
106
        { &X.PC, 2|RLSB, "PC\0"},
106
107
        { &X.A, 1, "A\0\0"},
107
 
        { &X.P, 1, "P\0\0"},
108
108
        { &X.X, 1, "X\0\0"},
109
109
        { &X.Y, 1, "Y\0\0"},
110
110
        { &X.S, 1, "S\0\0"},
 
111
        { &X.P, 1, "P\0\0"},
 
112
        { &X.DB, 1, "DB"},
111
113
        { &RAM, 0x800 | FCEUSTATE_INDIRECT, "RAM", },
112
114
        { 0 }
113
115
};
278
280
                                        ret=false;
279
281
                        }
280
282
                        break;
281
 
                case 0x10:if(!ReadStateChunk(is,SFMDATA,size)) ret=false; break;
 
283
                case 0x10:
 
284
                        if(!ReadStateChunk(is,SFMDATA,size)) 
 
285
                                ret=false; 
 
286
                        break;
282
287
 
283
288
                        // now it gets hackier:
284
289
                case 5:
446
451
}
447
452
 
448
453
 
449
 
void FCEUSS_Save(const char *fname)
 
454
void FCEUSS_Save(const char *fname, bool display_message)
450
455
{
451
456
        EMUFILE* st = 0;
452
457
        char fn[2048];
453
458
 
454
 
        if(geniestage==1)
 
459
        if (geniestage==1)
455
460
        {
456
 
                FCEU_DispMessage("Cannot save FCS in GG screen.",0);
 
461
                if (display_message)
 
462
                        FCEU_DispMessage("Cannot save FCS in GG screen.",0);
457
463
                return;
458
464
        }
459
465
 
480
486
                st = FCEUD_UTF8_fstream(fn,"wb");
481
487
        }
482
488
 
483
 
        if(st == NULL || st->get_fp() == NULL)
 
489
        if (st == NULL || st->get_fp() == NULL)
484
490
        {
485
 
                FCEU_DispMessage("State %d save error.",0,CurrentState);
 
491
                if (display_message)
 
492
                        FCEU_DispMessage("State %d save error.", 0, CurrentState);
486
493
                return;
487
494
        }
488
495
 
521
528
 
522
529
        if(!fname)
523
530
        {
524
 
                SaveStateStatus[CurrentState]=1;
525
 
                FCEU_DispMessage("State %d saved.",0,CurrentState);
 
531
                SaveStateStatus[CurrentState] = 1;
 
532
                if (display_message)
 
533
                        FCEU_DispMessage("State %d saved.", 0, CurrentState);
526
534
        }
527
535
        redoSS = false;                                 //we have a new savestate so redo is not possible
528
536
}
701
709
}
702
710
 
703
711
 
704
 
bool FCEUSS_Load(const char *fname)
 
712
bool FCEUSS_Load(const char *fname, bool display_message)
705
713
{
706
714
        EMUFILE* st;
707
715
        char fn[2048];
713
721
        //      MovieFlushHeader();
714
722
        //}
715
723
 
716
 
        if(geniestage==1)
 
724
        if (geniestage == 1)
717
725
        {
718
 
                FCEU_DispMessage("Cannot load FCS in GG screen.",0);
 
726
                if (display_message)
 
727
                        FCEU_DispMessage("Cannot load FCS in GG screen.",0);
719
728
                return false;
720
729
        }
721
 
        if(fname)
 
730
        if (fname)
722
731
        {
723
 
                st=FCEUD_UTF8_fstream(fname, "rb");
 
732
                st = FCEUD_UTF8_fstream(fname, "rb");
724
733
                strcpy(fn, fname);
725
 
        }
726
 
        else
 
734
        } else
727
735
        {
728
736
                strcpy(fn, FCEU_MakeFName(FCEUMKF_STATE,CurrentState,fname).c_str());
729
737
                st=FCEUD_UTF8_fstream(fn,"rb");
730
738
        strcpy(lastLoadstateMade,fn);
731
739
        }
732
740
 
733
 
        if(st == NULL || (st->get_fp() == NULL))
 
741
        if (st == NULL || (st->get_fp() == NULL))
734
742
        {
735
 
                FCEU_DispMessage("State %d load error.",0,CurrentState);
736
 
                //FCEU_DispMessage("State %d load error. Filename: %s",0,CurrentState, fn);
737
 
                SaveStateStatus[CurrentState]=0;
 
743
                if (display_message)
 
744
                {
 
745
                        FCEU_DispMessage("State %d load error.", 0, CurrentState);
 
746
                        //FCEU_DispMessage("State %d load error. Filename: %s", 0, CurrentState, fn);
 
747
                }
 
748
                SaveStateStatus[CurrentState] = 0;
738
749
                return false;
739
750
        }
740
751
 
741
752
        //If in bot mode, don't do a backup when loading.
742
753
        //Otherwise you eat at the hard disk, since so many
743
754
        //states are being loaded.
744
 
        if(FCEUSS_LoadFP(st, backupSavestates ? SSLOADPARAM_BACKUP : SSLOADPARAM_NOBACKUP))
 
755
        if (FCEUSS_LoadFP(st, backupSavestates ? SSLOADPARAM_BACKUP : SSLOADPARAM_NOBACKUP))
745
756
        {
746
 
                if(fname)
 
757
                if (fname)
747
758
                {
748
759
                        char szFilename[260]={0};
749
760
                        splitpath(fname, 0, 0, szFilename, 0);
750
 
                        FCEU_DispMessage("State %s loaded.",0,szFilename);
751
 
                        //FCEU_DispMessage("State %s loaded. Filename: %s",0,szFilename, fn);
752
 
                }
753
 
                else
 
761
            if (display_message)
 
762
                        {
 
763
                FCEU_DispMessage("State %s loaded.", 0, szFilename);
 
764
                                //FCEU_DispMessage("State %s loaded. Filename: %s", 0, szFilename, fn);
 
765
            }
 
766
                } else
754
767
                {
755
 
                        FCEU_DispMessage("State %d loaded.",0,CurrentState);
756
 
                        //FCEU_DispMessage("State %d loaded. Filename: %s",0,CurrentState, fn);
757
 
                        SaveStateStatus[CurrentState]=1;
 
768
            if (display_message)
 
769
                        {
 
770
                FCEU_DispMessage("State %d loaded.", 0, CurrentState);
 
771
                                //FCEU_DispMessage("State %d loaded. Filename: %s", 0, CurrentState, fn);
 
772
            }
 
773
                        SaveStateStatus[CurrentState] = 1;
758
774
                }
759
775
                delete st;
760
776
 
789
805
                cur_input_display = FCEU_GetJoyJoy(); //Input display should show the last buttons pressed (stored in the savestate)
790
806
 
791
807
                return true;
792
 
        }
793
 
        else
 
808
        } else
794
809
        {
795
810
                if(!fname)
 
811
                        SaveStateStatus[CurrentState] = 1;
 
812
 
 
813
                if (display_message)
796
814
                {
797
 
                        SaveStateStatus[CurrentState]=1;
 
815
                        FCEU_DispMessage("Error(s) reading state %d!", 0, CurrentState);
 
816
                        //FCEU_DispMessage("Error(s) reading state %d! Filename: %s", 0, CurrentState, fn);
798
817
                }
799
 
                FCEU_DispMessage("Error(s) reading state %d!",0,CurrentState);
800
 
                //FCEU_DispMessage("Error(s) reading state %d! Filename: %s",0,CurrentState, fn);
801
818
                delete st;
802
819
                return 0;
803
820
        }
913
930
        return oldstate;
914
931
}
915
932
 
916
 
void FCEUI_SaveState(const char *fname)
 
933
void FCEUI_SaveState(const char *fname, bool display_message)
917
934
{
918
935
        if(!FCEU_IsValidUI(FCEUI_SAVESTATE)) return;
919
936
 
920
 
        StateShow=0;
 
937
        StateShow = 0;
921
938
 
922
 
        FCEUSS_Save(fname);
 
939
        FCEUSS_Save(fname, display_message);
923
940
}
924
941
 
925
942
int loadStateFailed = 0; // hack, this function should return a value instead
933
950
    }
934
951
    return false;
935
952
}
936
 
void FCEUI_LoadState(const char *fname)
 
953
void FCEUI_LoadState(const char *fname, bool display_message)
937
954
{
938
955
        if(!FCEU_IsValidUI(FCEUI_LOADSTATE)) return;
939
956
 
945
962
        information expected in newer save states, desynchronization won't occur(at least not
946
963
        from this ;)).
947
964
        */
948
 
        if (backupSavestates) BackupLoadState();        //If allowed, backup the current state before loading a new one
 
965
        if (backupSavestates)
 
966
                BackupLoadState();      // If allowed, backup the current state before loading a new one
949
967
 
950
968
        if (!movie_readonly && autoMovieBackup && freshMovie) //If auto-backup is on, movie has not been altered this session and the movie is in read+write mode
951
969
        {
956
974
                loadStateFailed = 1;
957
975
                return; // state doesn't exist; exit cleanly
958
976
        }
959
 
        if(FCEUSS_Load(fname))
 
977
        if (FCEUSS_Load(fname, display_message))
960
978
        {
961
979
                //mbg todo netplay
962
 
                /*if(FCEUnetplay)
 
980
#if 0 
 
981
                if(FCEUnetplay)
963
982
                {
964
983
                        char *fn = strdup(FCEU_MakeFName(FCEUMKF_NPTEMP, 0, 0).c_str());
965
984
                        FILE *fp;
980
999
                        }
981
1000
 
982
1001
                        free(fn);
983
 
                }*/
 
1002
                }
 
1003
#endif
984
1004
                freshMovie = false;             //The movie has been altered so it is no longer fresh
985
 
        }
986
 
        else
 
1005
        } else
987
1006
        {
988
1007
                loadStateFailed = 1;
989
1008
        }