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" );