Debugger 'saverom' and 'saveses' now save to the default save directory.

The 'saveses' command now creates a filename based on the date and time when the command was entered.
This commit is contained in:
Stephen Anthony 2017-09-09 17:20:22 -02:30
parent 84fc62500a
commit 2dc355b0d5
5 changed files with 37 additions and 19 deletions

View File

@ -28,6 +28,11 @@
actually saving the files at all. This has never been reported
before, so I guess it shows how many people use that functionality.
* The debugger 'savedis', 'saverom' and 'saveses' now save files in
a default, user-visible directory (see the documentation for more
information). In the case of 'saveses', the filename is now named
based on the date and time of when the command was entered.
* Added debugger pseudo-register '_fcycles', which gives the number of
CPU cycles that have occurred since the frame started.

View File

@ -1154,10 +1154,9 @@ string CartDebug::saveDisassembly()
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
string CartDebug::saveRom()
{
const string& path = string("~") + BSPF::PATH_SEPARATOR +
myConsole.properties().get(Cartridge_Name) + ".a26";
const string& rom = myConsole.properties().get(Cartridge_Name) + ".a26";
FilesystemNode node(path);
FilesystemNode node(myOSystem.defaultSaveDir() + rom);
ofstream out(node.getPath(), std::ios::binary);
if(out && myConsole.cartridge().saveROM(out))
return "saved ROM as " + node.getShortPath();

View File

@ -1404,10 +1404,20 @@ void DebuggerParser::executeSaverom()
// "saveses"
void DebuggerParser::executeSaveses()
{
if(debugger.prompt().saveBuffer(argStrings[0]))
commandResult << "saved session to file " << argStrings[0];
// Create a file named with the current date and time
time_t currtime;
struct tm* timeinfo;
char buffer[80];
time(&currtime);
timeinfo = localtime(&currtime);
strftime(buffer, 80, "session_%F_%H-%M-%S.txt", timeinfo);
FilesystemNode file(debugger.myOSystem.defaultSaveDir() + buffer);
if(debugger.prompt().saveBuffer(file))
commandResult << "saved " + file.getShortPath() + " OK";
else
commandResult << red("I/O error");
commandResult << "Unable to save session";
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -2213,7 +2223,8 @@ DebuggerParser::Command DebuggerParser::commands[kNumCommands] = {
{
"savedis",
"Save Distella disassembly (with default name)",
"Example: savedis",
"Example: savedis\n"
"NOTE: saves to default save location",
false,
false,
{ kARG_END_ARGS },
@ -2223,7 +2234,8 @@ DebuggerParser::Command DebuggerParser::commands[kNumCommands] = {
{
"saverom",
"Save (possibly patched) ROM (with default name)",
"Example: saverom",
"Example: saverom\n"
"NOTE: saves to default save location",
false,
false,
{ kARG_END_ARGS },
@ -2232,11 +2244,12 @@ DebuggerParser::Command DebuggerParser::commands[kNumCommands] = {
{
"saveses",
"Save console session to file xx",
"Example: saveses session.txt",
true,
"Save console session",
"Example: saveses\n"
"NOTE: saves to default save location",
false,
{ kARG_FILE, kARG_END_ARGS },
false,
{ kARG_END_ARGS },
std::mem_fn(&DebuggerParser::executeSaveses)
},

View File

@ -876,21 +876,21 @@ void PromptWidget::scrollToCurrent()
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool PromptWidget::saveBuffer(string& filename)
bool PromptWidget::saveBuffer(const FilesystemNode& file)
{
ofstream out(filename);
ofstream out(file.getPath());
if(!out.is_open())
return false;
for(int start=0; start<_promptStartPos; start+=_lineWidth)
for(int start = 0; start < _promptStartPos; start += _lineWidth)
{
int end = start+_lineWidth-1;
int end = start + _lineWidth - 1;
// look for first non-space, printing char from end of line
// Look for first non-space, printing char from end of line
while( char(_buffer[end] & 0xff) <= ' ' && end >= start)
end--;
// spit out the line minus its trailing junk.
// Spit out the line minus its trailing junk
// Strip off any color/inverse bits
for(int j = start; j <= end; ++j)
out << char(_buffer[j] & 0xff);

View File

@ -21,6 +21,7 @@
#include <stdarg.h>
class ScrollBarWidget;
class FilesystemNode;
#include "Widget.hxx"
#include "Command.hxx"
@ -38,7 +39,7 @@ class PromptWidget : public Widget, public CommandSender
int vprintf(const char* format, va_list argptr);
void print(const string& str);
void printPrompt();
bool saveBuffer(string& filename);
bool saveBuffer(const FilesystemNode& file);
// Clear screen and erase all history
void clearScreen();