Post Reply 
WP31s error recovery
03-04-2015, 12:52 AM
Post: #20
RE: WP31s error recovery

Even better: [f] [UNDO] switches between two saved states, or in other words, you can undo the undo operation. This patch also takes care of saving the undo state in the emulators.

Code:
diff -ur wp31s_r3756/keys.c wp31s_fix_undo_r3756_20150303/keys.c
--- wp31s_r3756/keys.c  2015-02-07 13:09:33.000000000 -0500
+++ wp31s_fix_undo_r3756_20150303/keys.c        2015-03-03 19:46:28.440076188 -0500
@@ -1964,6 +1964,7 @@
                        OpCode = 0;
 
                        if (c == (OP_NIL | OP_OFF) || !is_bad_cmdline()) {
+                               process_cmdline();
                                xcopy(&Undo2State, &UndoState, sizeof(TPersistentRam));
                                xcopy(&UndoState, &PersistentRam, sizeof(TPersistentRam));
                                xeq(c);
@@ -2028,19 +2029,28 @@
                        break;
 
                case STATE_UNDO:
-                       xcopy(&PersistentRam, &UndoState, sizeof(TPersistentRam));
+                       if (CmdLineLength)
+                               CmdLineLength = CmdLineEex = CmdLineDot = 0;
+                       else {
+                               xcopy(&Undo2State, &PersistentRam, sizeof(TPersistentRam));
+                               xcopy(&PersistentRam, &UndoState, sizeof(TPersistentRam));
+                               xcopy(&UndoState, &Undo2State, sizeof(TPersistentRam));
+                       }
                        break;
 
                default:
                        if (c >= (OP_SPEC | OP_ENTER) && c <= (OP_SPEC | OP_F)) {
                                if (c != (OP_SPEC | OP_ENTER) || !is_bad_cmdline()) {
                                        // Data entry key
-                                       xcopy(&Undo2State, &UndoState, sizeof(TPersistentRam));
-                                       xcopy(&UndoState, &PersistentRam, sizeof(TPersistentRam));
+                                       cmdline_empty = (CmdLineLength == 0);
+                                       if (c == (OP_SPEC | OP_ENTER) || (CmdLineLength == 0 && c == (OP_SPEC | OP_CLX))) {
+                                               process_cmdline();
+                                               xcopy(&Undo2State, &UndoState, sizeof(TPersistentRam));
+                                               xcopy(&UndoState, &PersistentRam, sizeof(TPersistentRam));
+                                       }
 #ifndef CONSOLE
                                        WasDataEntry = 1;
 #endif
-                                       cmdline_empty = (CmdLineLength == 0);
                                        xeq(c);
                                        cmdline_empty |= (CmdLineLength == 0);
                                }
diff -ur wp31s_r3756/QtGui/QtEmulatorAdapter.c wp31s_fix_undo_r3756_20150303/QtGui/QtEmulatorAdapter.c
--- wp31s_r3756/QtGui/QtEmulatorAdapter.c       2014-11-26 21:09:35.000000000 -0500
+++ wp31s_fix_undo_r3756_20150303/QtGui/QtEmulatorAdapter.c     2015-03-03 19:46:44.064075811 -0500
@@ -186,6 +186,11 @@
        return (char*) &PersistentRam;
 }
 
+char* get_undo_memory()
+{
+       return (char*) &UndoState;
+}
+
 int get_memory_size()
 {
        return sizeof(PersistentRam);
diff -ur wp31s_r3756/QtGui/QtEmulatorAdapter.h wp31s_fix_undo_r3756_20150303/QtGui/QtEmulatorAdapter.h
--- wp31s_r3756/QtGui/QtEmulatorAdapter.h       2014-11-15 13:19:35.000000000 -0500
+++ wp31s_fix_undo_r3756_20150303/QtGui/QtEmulatorAdapter.h     2015-03-03 19:46:40.076075907 -0500
@@ -23,6 +23,7 @@
 extern void forward_keycode(int);
 extern void forward_key_released();
 extern char* get_memory();
+extern char* get_undo_memory();
 extern int get_memory_size();
 extern char* get_backup();
 extern int get_backup_size();
diff -ur wp31s_r3756/QtGui/QtEmulator.cpp wp31s_fix_undo_r3756_20150303/QtGui/QtEmulator.cpp
--- wp31s_r3756/QtGui/QtEmulator.cpp    2014-11-15 13:19:35.000000000 -0500
+++ wp31s_fix_undo_r3756_20150303/QtGui/QtEmulator.cpp  2015-03-03 19:46:47.568075727 -0500
@@ -774,15 +774,19 @@
        }
 
        int memorySize=get_memory_size();
-       if(memoryFile.size()!=memorySize)
+       if(memoryFile.size()!=memorySize && memoryFile.size()!=2*memorySize)
        {
-               memoryWarning(memoryFile.fileName()+" expected size is "+QString::number(memorySize)
+               memoryWarning(memoryFile.fileName()+" expected size is "+QString::number(2*memorySize)
                +" but file size is "+QString::number(memoryFile.size()));
                return;
        }
 
        QDataStream dataStream(&memoryFile);
        int reallyRead=dataStream.readRawData(get_memory(), memorySize);
+       if(reallyRead==memorySize && memoryFile.size()==2*memorySize)
+       {
+               reallyRead=dataStream.readRawData(get_undo_memory(), memorySize);
+       }
        if(reallyRead!=memorySize)
        {
                memoryWarning("Error whilst reading "+memoryFile.fileName());
@@ -834,6 +838,10 @@
        QDataStream dataStream(&memoryFile);
        int memorySize=get_memory_size();
        int reallyWritten=dataStream.writeRawData(get_memory(), memorySize);
+       if (reallyWritten==memorySize)
+       {
+               reallyWritten=dataStream.writeRawData(get_undo_memory(), memorySize);
+       }
        if(reallyWritten!=memorySize)
        {
                memoryWarning("Cannot write "+memoryFile.fileName());
diff -ur wp31s_r3756/storage.c wp31s_fix_undo_r3756_20150303/storage.c
--- wp31s_r3756/storage.c       2015-02-07 13:09:33.000000000 -0500
+++ wp31s_fix_undo_r3756_20150303/storage.c     2015-03-03 19:46:33.512076065 -0500
@@ -415,6 +415,7 @@
        init_state();
        checksum_all();
        fwrite( &PersistentRam, sizeof( PersistentRam ), 1, f );
+       fwrite( &UndoState, sizeof( UndoState ), 1, f );
        fclose( f );
 #ifdef DEBUG
        printf( "sizeof struct _state = %d\n", (int)sizeof( struct _state ) );
@@ -436,6 +437,7 @@
        FILE *f = fopen( STATE_FILE, "rb" );
        if ( f != NULL ) {
                fread( &PersistentRam, sizeof( PersistentRam ), 1, f );
+               fread( &UndoState, sizeof( UndoState ), 1, f );
                fclose( f );
        }
        f = fopen( BACKUP_FILE, "rb" );
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
WP31s error recovery - Dieter - 03-01-2015, 10:07 PM
RE: WP31s error recovery - BarryMead - 03-02-2015, 03:41 AM
RE: WP31s error recovery - Dieter - 03-02-2015, 06:42 AM
RE: WP31s error recovery - BarryMead - 03-02-2015, 07:57 AM
RE: WP31s error recovery - Dieter - 03-02-2015, 07:34 PM
RE: WP31s error recovery - BarryMead - 03-02-2015, 07:44 PM
RE: WP31s error recovery - Dieter - 03-03-2015, 07:10 AM
RE: WP31s error recovery - Bit - 03-03-2015, 01:54 PM
RE: WP31s error recovery - rprosperi - 03-03-2015, 01:58 PM
RE: WP31s error recovery - Bit - 03-04-2015, 12:56 AM
RE: WP31s error recovery - rprosperi - 03-04-2015, 02:48 AM
RE: WP31s error recovery - Dieter - 03-03-2015, 07:34 PM
RE: WP31s error recovery - BarryMead - 03-03-2015, 08:10 PM
RE: WP31s error recovery - Dieter - 03-03-2015, 08:48 PM
RE: WP31s error recovery - BarryMead - 03-03-2015, 08:57 PM
RE: WP31s error recovery - Dieter - 03-03-2015, 09:15 PM
RE: WP31s error recovery - Bit - 03-04-2015, 01:02 AM
RE: WP31s error recovery - Dieter - 03-04-2015, 01:30 PM
RE: WP31s error recovery - Bit - 03-05-2015, 04:15 AM
RE: WP31s error recovery - Paul Dale - 03-05-2015, 04:58 AM
RE: WP31s error recovery - Dieter - 03-05-2015, 08:25 PM
RE: WP31s error recovery - Bit - 03-02-2015, 05:43 PM
RE: WP31s error recovery - Bit - 03-04-2015 12:52 AM
RE: WP31s error recovery - BarryMead - 03-05-2015, 07:31 PM
RE: WP31s error recovery - Dieter - 03-05-2015, 08:04 PM
RE: WP31s error recovery - rprosperi - 03-05-2015, 08:13 PM
RE: WP31s error recovery - BarryMead - 03-05-2015, 08:29 PM
RE: WP31s error recovery - rprosperi - 03-05-2015, 09:39 PM
RE: WP31s error recovery - BarryMead - 03-05-2015, 09:51 PM
RE: WP31s error recovery - rprosperi - 03-05-2015, 10:44 PM
RE: WP31s error recovery - Dieter - 03-05-2015, 08:35 PM
RE: WP31s error recovery - BarryMead - 03-05-2015, 08:51 PM
RE: WP31s error recovery - Bit - 03-07-2015, 04:29 AM
RE: WP31s error recovery - rprosperi - 03-07-2015, 02:09 PM
RE: WP31s error recovery - walter b - 03-08-2015, 03:36 AM
RE: WP31s error recovery - Paul Dale - 03-07-2015, 10:36 PM
RE: WP31s error recovery - Bit - 03-15-2015, 04:31 PM
RE: WP31s error recovery - Paul Dale - 03-04-2015, 06:22 AM
RE: WP31s error recovery - Bit - 03-04-2015, 02:02 PM



User(s) browsing this thread: 1 Guest(s)