~ubuntu-branches/ubuntu/utopic/fceux/utopic-proposed

« back to all changes in this revision

Viewing changes to src/movie.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:
1
 
#include <stdio.h>
2
 
#include <stdlib.h>
3
 
#include <string.h>
4
 
#include <assert.h>
5
 
#include <zlib.h>
6
 
#include <iomanip>
7
 
#include <fstream>
8
 
#include <limits.h>
9
 
#include <stdarg.h>
10
 
 
11
1
#include "emufile.h"
12
2
#include "version.h"
13
3
#include "types.h"
22
12
#include "video.h"
23
13
#include "movie.h"
24
14
#include "fds.h"
 
15
#include "vsuni.h"
25
16
#ifdef _S9XLUA_H
26
17
#include "fceulua.h"
27
18
#endif
39
30
#include "./drivers/win/common.h"
40
31
#include "./drivers/win/window.h"
41
32
extern void AddRecentMovieFile(const char *filename);
42
 
 
43
33
#include "./drivers/win/taseditor.h"
44
34
extern bool mustEngageTaseditor;
45
35
#endif
46
36
 
 
37
#include <cstdio>
 
38
#include <cstdlib>
 
39
#include <cstring>
 
40
#include <cassert>
 
41
#include <iomanip>
 
42
#include <fstream>
 
43
#include <climits>
 
44
#include <cstdarg>
 
45
#include <zlib.h>
 
46
 
47
47
using namespace std;
48
48
 
49
49
#define MOVIE_VERSION           3
103
103
char curMovieFilename[512] = {0};
104
104
MovieData currMovieData;
105
105
MovieData defaultMovieData;
106
 
int currRerecordCount;
107
106
 
108
107
char lagcounterbuf[32] = {0};
109
108
 
346
345
 
347
346
void MovieRecord::dump(MovieData* md, EMUFILE* os, int index)
348
347
{
349
 
        //dump the misc commands
 
348
        // dump the commands
350
349
        //*os << '|' << setw(1) << (int)commands;
351
350
        os->fputc('|');
352
 
        putdec<uint8,1,true>(os,commands);
 
351
        putdec<uint8,3,false>(os, commands);    // "variable length decimal integer"
353
352
 
354
353
        //a special case: if fourscore is enabled, dump four gamepads
355
354
        if(md->fourscore)
903
902
        pauseframe = _pauseframe;
904
903
        movie_readonly = _read_only;
905
904
        movieMode = MOVIEMODE_PLAY;
906
 
        currRerecordCount = currMovieData.rerecordCount;
907
905
 
908
906
        if(movie_readonly)
909
907
                FCEU_DispMessage("Replay started Read-Only.",0);
974
972
 
975
973
        movieMode = MOVIEMODE_RECORD;
976
974
        movie_readonly = false;
977
 
        currRerecordCount = 0;
978
975
 
979
976
        FCEU_DispMessage("Movie recording started.",0);
980
977
}
1004
1001
                joyports[0].load(mr);
1005
1002
                joyports[1].load(mr);
1006
1003
                // replay commands
1007
 
                if(mr->command_power())
 
1004
                if (mr->command_power())
1008
1005
                        PowerNES();
1009
 
                if(mr->command_reset())
 
1006
                if (mr->command_reset())
1010
1007
                        ResetNES();
1011
 
                if(mr->command_fds_insert())
 
1008
                if (mr->command_fds_insert())
1012
1009
                        FCEU_FDSInsert();
1013
 
                if(mr->command_fds_select())
 
1010
                if (mr->command_fds_select())
1014
1011
                        FCEU_FDSSelect();
 
1012
                if (mr->command_vs_insertcoin())
 
1013
                        FCEU_VSUniCoin();
1015
1014
                _currCommand = 0;
1016
1015
        } else
1017
1016
#endif
1018
 
        if(movieMode == MOVIEMODE_PLAY)
 
1017
        if (movieMode == MOVIEMODE_PLAY)
1019
1018
        {
1020
1019
                //stop when we run out of frames
1021
 
                if(currFrameCounter >= (int)currMovieData.records.size())
 
1020
                if (currFrameCounter >= (int)currMovieData.records.size())
1022
1021
                {
1023
1022
                        FinishPlayback();
1024
1023
                        //tell all drivers to poll input and set up their logical states
1025
1024
                        for(int port=0;port<2;port++)
1026
1025
                                joyports[port].driver->Update(port,joyports[port].ptr,joyports[port].attrib);
1027
1026
                        portFC.driver->Update(portFC.ptr,portFC.attrib);
1028
 
                }
1029
 
                else
 
1027
                } else
1030
1028
                {
1031
1029
                        MovieRecord* mr = &currMovieData.records[currFrameCounter];
1032
1030
 
1039
1037
                                FCEU_FDSInsert();
1040
1038
                        if(mr->command_fds_select())
1041
1039
                                FCEU_FDSSelect();
 
1040
                        if (mr->command_vs_insertcoin())
 
1041
                                FCEU_VSUniCoin();
1042
1042
 
1043
1043
                        joyports[0].load(mr);
1044
1044
                        joyports[1].load(mr);
1045
1045
                }
1046
1046
 
1047
1047
                //if we are on the last frame, then pause the emulator if the player requested it
1048
 
                if(currFrameCounter == currMovieData.records.size()-1)
 
1048
                if (currFrameCounter == currMovieData.records.size()-1)
1049
1049
                {
1050
1050
                        if(FCEUD_PauseAfterPlayback())
1051
1051
                        {
1054
1054
                }
1055
1055
 
1056
1056
                //pause the movie at a specified frame
1057
 
                if(FCEUMOV_ShouldPause() && FCEUI_EmulationPaused()==0)
 
1057
                if (FCEUMOV_ShouldPause() && FCEUI_EmulationPaused()==0)
1058
1058
                {
1059
1059
                        FCEUI_ToggleEmulationPause();
1060
1060
                        FCEU_DispMessage("Paused at specified movie frame",0);
1061
1061
                }
1062
1062
 
1063
 
        }
1064
 
        else if(movieMode == MOVIEMODE_RECORD)
 
1063
        } else if (movieMode == MOVIEMODE_RECORD)
1065
1064
        {
1066
1065
                MovieRecord mr;
1067
1066
 
1094
1093
        if(movieMode != MOVIEMODE_RECORD && movieMode != MOVIEMODE_TASEDITOR)
1095
1094
                return;
1096
1095
 
1097
 
        //NOTE: EMOVIECMD matches FCEUNPCMD_RESET and FCEUNPCMD_POWER
1098
 
        //we are lucky (well, I planned it that way)
1099
 
 
1100
 
        switch(cmd) {
 
1096
        // translate "FCEU NetPlay" command to "FCEU Movie" command
 
1097
        switch (cmd)
 
1098
        {
 
1099
                case FCEUNPCMD_RESET: cmd = MOVIECMD_RESET; break;
 
1100
                case FCEUNPCMD_POWER: cmd = MOVIECMD_POWER; break;
1101
1101
                case FCEUNPCMD_FDSINSERT: cmd = MOVIECMD_FDS_INSERT; break;
1102
1102
                case FCEUNPCMD_FDSSELECT: cmd = MOVIECMD_FDS_SELECT; break;
 
1103
                case FCEUNPCMD_VSUNICOIN: cmd = MOVIECMD_VS_INSERTCOIN; break;
 
1104
                // all other netplay commands (e.g. FCEUNPCMD_VSUNIDIP0) are not supported by movie recorder for now
 
1105
                default: return;
1103
1106
        }
1104
1107
 
1105
1108
        _currCommand |= cmd;
1112
1115
                char counterbuf[32] = {0};
1113
1116
                int color = 0x20;
1114
1117
                if(movieMode == MOVIEMODE_PLAY)
1115
 
                        sprintf(counterbuf,"%d/%d",currFrameCounter,currMovieData.records.size());
 
1118
                        sprintf(counterbuf,"%d/%d",currFrameCounter,(int)currMovieData.records.size());
1116
1119
                else if(movieMode == MOVIEMODE_RECORD)
1117
1120
                        sprintf(counterbuf,"%d",currFrameCounter);
1118
1121
                else if (movieMode == MOVIEMODE_FINISHED)
1119
1122
                {
1120
 
                        sprintf(counterbuf,"%d/%d (finished)",currFrameCounter,currMovieData.records.size());
 
1123
                        sprintf(counterbuf,"%d/%d (finished)",currFrameCounter,(int)currMovieData.records.size());
1121
1124
                        color = 0x17; //Show red to get attention
1122
1125
                } else if(movieMode == MOVIEMODE_TASEDITOR)
1123
1126
                {
1353
1356
                                // Finally, this is a savestate file for this movie
1354
1357
                                movieMode = MOVIEMODE_PLAY;
1355
1358
                        }
1356
 
                }
1357
 
                else //Read + write
 
1359
                } else
1358
1360
                {
 
1361
                        //Read+Write mode
1359
1362
                        if (currFrameCounter > (int)tempMovieData.records.size())
1360
1363
                        {
1361
1364
                                //This is a post movie savestate, handle it differently
1364
1367
                                openRecordingMovie(curMovieFilename);
1365
1368
                                currMovieData.dump(osRecordingMovie, false/*currMovieData.binaryFlag*/);
1366
1369
                                FinishPlayback();
1367
 
                        }
1368
 
                        else
 
1370
                        } else
1369
1371
                        {
1370
1372
                                //truncate before we copy, just to save some time, unless the user selects a full copy option
1371
1373
                                if (!fullSaveStateLoads)
1372
 
                                        tempMovieData.truncateAt(currFrameCounter); //we can only assume this here since we have checked that the frame counter is not greater than the movie data
 
1374
                                        //we can only assume this here since we have checked that the frame counter is not greater than the movie data
 
1375
                                        tempMovieData.truncateAt(currFrameCounter);
 
1376
                                
1373
1377
                                currMovieData = tempMovieData;
1374
 
#ifdef _S9XLUA_H
1375
 
                                if(!FCEU_LuaRerecordCountSkip())
1376
 
                                        currRerecordCount++;
1377
 
#else
1378
 
                                currRerecordCount++;
1379
 
#endif
1380
 
                                currMovieData.rerecordCount = currRerecordCount;
 
1378
                                FCEUMOV_IncrementRerecordCount();
1381
1379
                                openRecordingMovie(curMovieFilename);
1382
1380
                                currMovieData.dump(osRecordingMovie, false/*currMovieData.binaryFlag*/);
1383
1381
                                movieMode = MOVIEMODE_RECORD;
1404
1402
                return load_successful;
1405
1403
}
1406
1404
 
 
1405
void FCEUMOV_IncrementRerecordCount()
 
1406
{
 
1407
#ifdef _S9XLUA_H
 
1408
        if(!FCEU_LuaRerecordCountSkip())
 
1409
                currMovieData.rerecordCount++;
 
1410
#else
 
1411
        currMovieData.rerecordCount++;
 
1412
#endif
 
1413
}
 
1414
 
1407
1415
void FCEUI_MovieToggleFrameDisplay(void)
1408
1416
{
1409
1417
        frame_display=!frame_display;
1478
1486
        if(movie_readonly)
1479
1487
                strcpy(message, "Movie is now Read+Write");
1480
1488
        else
1481
 
        {
1482
1489
                strcpy(message, "Movie is now Read-Only");
1483
 
        }
1484
1490
 
1485
 
        if(movieMode == MOVIEMODE_INACTIVE)
 
1491
        if (movieMode == MOVIEMODE_INACTIVE)
1486
1492
                strcat(message, " (no movie)");
1487
1493
        else if (movieMode == MOVIEMODE_FINISHED)
1488
1494
                strcat(message, " (finished)");
1502
1508
        {
1503
1509
                if (currMovieData.savestate.empty())
1504
1510
                {
1505
 
                        movie_readonly=true;
 
1511
                        movie_readonly = true;
1506
1512
                        movieMode = MOVIEMODE_PLAY;
1507
1513
                        poweron(true);
1508
 
                        currFrameCounter=0;
 
1514
                        currFrameCounter = 0;
1509
1515
                        FCEU_DispMessage("Movie is now Read-Only. Playing from beginning.",0);
1510
1516
                }
1511
1517
                else