@@ -53,19 +53,33 @@ public override bool SaveRamModified
5353
5454 public override byte [ ] CloneSaveRam ( bool clearDirty )
5555 {
56- _exe . AddTransientFile ( Array . Empty < byte > ( ) , "SAV:flash" ) ;
57-
58- if ( ! _neopop . GetSaveRam ( ) )
56+ _exe . AddTransientFile ( [ ] , "SAV:flash" ) ;
57+ var success = _neopop . GetSaveRam ( ) ;
58+ var ret = _exe . RemoveTransientFile ( "SAV:flash" ) ;
59+ if ( ! success )
60+ {
5961 throw new InvalidOperationException ( "Error returning saveram" ) ;
60- return _exe . RemoveTransientFile ( "SAV:flash" ) ;
62+ }
63+
64+ return ret ;
6165 }
6266
6367 public override void StoreSaveRam ( byte [ ] data )
6468 {
65- _exe . AddTransientFile ( data , "SAV:flash" ) ;
66- if ( ! _neopop . PutSaveRam ( ) )
69+ if ( data . Length == 0 )
70+ {
71+ // Empty SaveRAM is valid here, that means at the time of flushing SaveRAM, flash was not attempted to be used yet
72+ // The core will reject attempts to put this empty file however, so we must return here
73+ return ;
74+ }
75+
76+ _exe . AddReadonlyFile ( data , "SAV:flash" ) ;
77+ var success = _neopop . PutSaveRam ( ) ;
78+ _exe . RemoveReadonlyFile ( "SAV:flash" ) ;
79+ if ( ! success )
80+ {
6781 throw new InvalidOperationException ( "Core rejected the saveram" ) ;
68- _exe . RemoveTransientFile ( "SAV:flash" ) ;
82+ }
6983 }
7084
7185 protected override IDictionary < string , SettingOverride > SettingOverrides { get ; } = new Dictionary < string , SettingOverride >
0 commit comments