diff --git a/doc/commands/stack.md b/doc/commands/stack.md index a98f0cb0..c3e9cabb 100644 --- a/doc/commands/stack.md +++ b/doc/commands/stack.md @@ -35,6 +35,19 @@ Duplicate the same object twice on the stack ## DuplicateN (DUPN) Duplicate a group of N objects, N being given in stack level 1 +## LastArguments (LASTARG) +Put the last arguments back on the stack + +## LastX +Put the last first argument on the stack. + +This command does not exist on HP RPL calculators, and is here to make it easier +to adapt RPN programs that use LastX a bit more often. + +## Undo +Restore the stack to its last state before executing an interactive command. +Note that this command can be used from a program, but it will restore the state +prior to program execution. ## NDUPN Replicate one object N times and return N diff --git a/fonts/EditorFont.cc b/fonts/EditorFont.cc index 8628b4b6..78ec056d 100644 --- a/fonts/EditorFont.cc +++ b/fonts/EditorFont.cc @@ -7,7 +7,7 @@ extern const unsigned char EditorFont_sparse_font_data[]; const unsigned char EditorFont_sparse_font_data[73676] FONT_QSPI = { - 0xBC, 0x02, 0xC7, 0xBF, 0x04, 0x36, 0x00, 0x01, 0x00, 0x2C, 0x01, 0x01, 0x00, 0x00, 0x0D, 0x01, + 0xBD, 0x02, 0xC7, 0xBF, 0x04, 0x36, 0x00, 0x01, 0x00, 0x2C, 0x01, 0x01, 0x00, 0x00, 0x0D, 0x01, 0x00, 0x2C, 0x01, 0x01, 0x08, 0x00, 0x20, 0x5F, 0x00, 0x2C, 0x01, 0x01, 0x08, 0x00, 0x02, 0x0B, 0x05, 0x21, 0x09, 0xEF, 0xBD, 0xF7, 0xDE, 0x7B, 0xEF, 0xBD, 0xF7, 0xDE, 0x7B, 0xEF, 0xBD, 0xF7, 0x1E, 0x00, 0x00, 0xB8, 0xFF, 0xFF, 0xFF, 0x0E, 0x03, 0x0B, 0x0B, 0x0F, 0x11, 0x8F, 0x7F, 0xFC, diff --git a/fonts/HelpFont.cc b/fonts/HelpFont.cc index 411b1ef9..89c94564 100644 --- a/fonts/HelpFont.cc +++ b/fonts/HelpFont.cc @@ -7,7 +7,7 @@ extern const unsigned char HelpFont_sparse_font_data[]; const unsigned char HelpFont_sparse_font_data[15010] FONT_QSPI = { - 0xBC, 0x02, 0x9E, 0x75, 0x14, 0x00, 0x01, 0x00, 0x11, 0x01, 0x01, 0x00, 0x00, 0x0D, 0x01, 0x00, + 0xBD, 0x02, 0x9E, 0x75, 0x14, 0x00, 0x01, 0x00, 0x11, 0x01, 0x01, 0x00, 0x00, 0x0D, 0x01, 0x00, 0x11, 0x01, 0x01, 0x03, 0x00, 0x20, 0x5F, 0x00, 0x11, 0x01, 0x01, 0x03, 0x00, 0x01, 0x04, 0x02, 0x0D, 0x04, 0xFF, 0xFF, 0xF3, 0x03, 0x01, 0x04, 0x04, 0x05, 0x06, 0xFF, 0xFF, 0x0F, 0x01, 0x04, 0x08, 0x0D, 0x0A, 0x12, 0x12, 0x14, 0x7F, 0x7F, 0x24, 0x24, 0x24, 0xFE, 0xFE, 0x28, 0x48, 0x48, diff --git a/fonts/StackFont.cc b/fonts/StackFont.cc index 997372b8..3e6e35d4 100644 --- a/fonts/StackFont.cc +++ b/fonts/StackFont.cc @@ -7,7 +7,7 @@ extern const unsigned char StackFont_sparse_font_data[]; const unsigned char StackFont_sparse_font_data[36409] FONT_QSPI = { - 0xBC, 0x02, 0xB4, 0x9C, 0x02, 0x24, 0x00, 0x01, 0x00, 0x1C, 0x01, 0x01, 0x00, 0x00, 0x0D, 0x01, + 0xBD, 0x02, 0xB4, 0x9C, 0x02, 0x24, 0x00, 0x01, 0x00, 0x1C, 0x01, 0x01, 0x00, 0x00, 0x0D, 0x01, 0x00, 0x1C, 0x01, 0x01, 0x06, 0x00, 0x20, 0x5F, 0x00, 0x1C, 0x01, 0x01, 0x06, 0x00, 0x02, 0x05, 0x03, 0x17, 0x06, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x1F, 0xC0, 0xFF, 0x1F, 0x02, 0x05, 0x08, 0x0A, 0x0C, 0xE7, 0xE7, 0xE7, 0xE7, 0xE7, 0xE7, 0xE7, 0xE7, 0xE7, 0xE7, 0x01, 0x05, 0x0E, 0x17, 0x10, diff --git a/src/command.cc b/src/command.cc index 7cba5c9d..dc181885 100644 --- a/src/command.cc +++ b/src/command.cc @@ -664,6 +664,17 @@ COMMAND_BODY(LastArg) } +COMMAND_BODY(LastX) +// ---------------------------------------------------------------------------- +// Return the last first argument +// ---------------------------------------------------------------------------- +{ + if (!rt.last(0)) + return ERROR; + return OK; +} + + COMMAND_BODY(Undo) // ---------------------------------------------------------------------------- // Return the undo stack diff --git a/src/command.h b/src/command.h index 969940a2..cb45112e 100644 --- a/src/command.h +++ b/src/command.h @@ -146,6 +146,7 @@ COMMAND_DECLARE(SystemSetup); // Select the system menu COMMAND_DECLARE(Version); // Return a version string COMMAND_DECLARE(Help); // Activate online help COMMAND_DECLARE(LastArg); // Return last arguments +COMMAND_DECLARE(LastX); // Return last X argument COMMAND_DECLARE(Undo); // Revert to the Undo stack COMMAND_DECLARE(ToolsMenu); // Automatic selection of the right menu COMMAND_DECLARE(LastMenu); // Return to diff --git a/src/ids.tbl b/src/ids.tbl index 9f82f665..d82a5ceb 100644 --- a/src/ids.tbl +++ b/src/ids.tbl @@ -280,7 +280,6 @@ CMD(ForStep) // // ============================================================================ -NAMED(LastArg, "LastArguments") CMD(Depth) NAMED(ToList, "→List") CMD(Get) @@ -547,6 +546,8 @@ CMD(SaveState) CMD(SystemSetup) CMD(Help) CMD(Undo) +NAMED(LastArg, "LastArguments") +CMD(LastX) CMD(Unimplemented) diff --git a/src/menu.cc b/src/menu.cc index c12e51ce..f33d24ac 100644 --- a/src/menu.cc +++ b/src/menu.cc @@ -948,7 +948,8 @@ MENU(LastThingsMenu, // ---------------------------------------------------------------------------- // Menu with the last things // ---------------------------------------------------------------------------- - "Arg", ID_LastArg, + "Args", ID_LastArg, + "X", ID_LastX, "Stack", ID_Undo, "Menu", ID_LastMenu, "Cmd", ID_Unimplemented); diff --git a/src/runtime.cc b/src/runtime.cc index 7bbc0a48..56658292 100644 --- a/src/runtime.cc +++ b/src/runtime.cc @@ -978,6 +978,26 @@ bool runtime::last() } +bool runtime::last(uint index) +// ---------------------------------------------------------------------------- +// Push back the last argument on the stack +// ---------------------------------------------------------------------------- +{ + size_t nargs = args(); + if (index >= nargs) + { + rt.missing_argument_error(); + return false; + } + size_t sz = sizeof(object_p); + if (available(sz) < sz) + return false; + + *--Stack = Args[index]; + return true; +} + + bool runtime::save() // ---------------------------------------------------------------------------- // Save the stack in the undo area diff --git a/src/runtime.h b/src/runtime.h index 69481bb0..a78f4e09 100644 --- a/src/runtime.h +++ b/src/runtime.h @@ -561,6 +561,11 @@ struct runtime // Push back last arguments // ------------------------------------------------------------------------ + bool last(uint index); + // ------------------------------------------------------------------------ + // Push back last argument + // ------------------------------------------------------------------------ + bool save(); // ------------------------------------------------------------------------