@@ -872,6 +872,78 @@ void PpuScriptObject::writeByte(int address, int value)
872
872
}
873
873
}
874
874
// ----------------------------------------------------
875
+ // ---- Movie Script Object
876
+ // ----------------------------------------------------
877
+ // ----------------------------------------------------
878
+ MovieScriptObject::MovieScriptObject (QObject* parent)
879
+ : QObject(parent)
880
+ {
881
+ script = qobject_cast<QtScriptInstance*>(parent);
882
+ engine = script->getEngine ();
883
+ }
884
+ // ----------------------------------------------------
885
+ MovieScriptObject::~MovieScriptObject ()
886
+ {
887
+ }
888
+ // ----------------------------------------------------
889
+ bool MovieScriptObject::active ()
890
+ {
891
+ bool movieActive = (FCEUMOV_IsRecording () || FCEUMOV_IsPlaying ());
892
+ return movieActive;
893
+ }
894
+ // ----------------------------------------------------
895
+ bool MovieScriptObject::isPlaying ()
896
+ {
897
+ bool playing = FCEUMOV_IsPlaying ();
898
+ return playing;
899
+ }
900
+ // ----------------------------------------------------
901
+ bool MovieScriptObject::isRecording ()
902
+ {
903
+ bool recording = FCEUMOV_IsRecording ();
904
+ return recording;
905
+ }
906
+ // ----------------------------------------------------
907
+ bool MovieScriptObject::isPowerOn ()
908
+ {
909
+ bool flag = false ;
910
+ if (FCEUMOV_IsRecording () || FCEUMOV_IsPlaying ())
911
+ {
912
+ flag = FCEUMOV_FromPoweron ();
913
+ }
914
+ return flag;
915
+ }
916
+ // ----------------------------------------------------
917
+ bool MovieScriptObject::isFromSaveState ()
918
+ {
919
+ bool flag = false ;
920
+ if (FCEUMOV_IsRecording () || FCEUMOV_IsPlaying ())
921
+ {
922
+ flag = !FCEUMOV_FromPoweron ();
923
+ }
924
+ return flag;
925
+ }
926
+ // ----------------------------------------------------
927
+ bool MovieScriptObject::record (const QString& filename, int saveType, const QString author)
928
+ {
929
+ if (filename.isEmpty ())
930
+ {
931
+ script->throwError (QJSValue::GenericError, " movie.record(): Filename required" );
932
+ return false ;
933
+ }
934
+
935
+ // No need to use the full functionality of the enum
936
+ EMOVIE_FLAG flags;
937
+ if (saveType == FROM_SAVESTATE) flags = MOVIE_FLAG_NONE; // from savestate
938
+ else if (saveType == FROM_SAVERAM ) flags = MOVIE_FLAG_FROM_SAVERAM;
939
+ else flags = MOVIE_FLAG_FROM_POWERON;
940
+
941
+ // Save it!
942
+ FCEUI_SaveMovie ( filename.toLocal8Bit ().data (), flags, author.toStdWString ());
943
+
944
+ return true ;
945
+ }
946
+ // ----------------------------------------------------
875
947
// ---- Input Script Object
876
948
// ----------------------------------------------------
877
949
// ----------------------------------------------------
@@ -1437,6 +1509,11 @@ void QtScriptInstance::shutdownEngine()
1437
1509
delete input;
1438
1510
input = nullptr ;
1439
1511
}
1512
+ if (movie != nullptr )
1513
+ {
1514
+ delete movie;
1515
+ movie = nullptr ;
1516
+ }
1440
1517
1441
1518
if (ui_rootWidget != nullptr )
1442
1519
{
@@ -1464,6 +1541,7 @@ int QtScriptInstance::initEngine()
1464
1541
ppu = new JS::PpuScriptObject (this );
1465
1542
mem = new JS::MemoryScriptObject (this );
1466
1543
input = new JS::InputScriptObject (this );
1544
+ movie = new JS::MovieScriptObject (this );
1467
1545
1468
1546
emu->setDialog (dialog);
1469
1547
rom->setDialog (dialog);
@@ -1500,6 +1578,11 @@ int QtScriptInstance::initEngine()
1500
1578
1501
1579
engine->globalObject ().setProperty (" input" , inputObject);
1502
1580
1581
+ // movie
1582
+ QJSValue movieObject = engine->newQObject (movie);
1583
+
1584
+ engine->globalObject ().setProperty (" movie" , movieObject);
1585
+
1503
1586
// gui
1504
1587
QJSValue guiObject = engine->newQObject (this );
1505
1588
@@ -1668,8 +1751,7 @@ bool QtScriptInstance::onGuiThread()
1668
1751
int QtScriptInstance::throwError (QJSValue::ErrorType errorType, const QString &message)
1669
1752
{
1670
1753
running = false ;
1671
- print (message);
1672
- engine->setInterrupted (true );
1754
+ engine->throwError (errorType, message);
1673
1755
return 0 ;
1674
1756
}
1675
1757
// ----------------------------------------------------
0 commit comments