Skip to content

Commit

Permalink
Version 4.18.0 ; Some protection in replay string parsing ; Implement…
Browse files Browse the repository at this point in the history
…ation of replay string functionality in complx ; some pylc3 fixes
  • Loading branch information
TricksterGuy committed Sep 27, 2018
1 parent 6ca30ca commit 127d4d1
Show file tree
Hide file tree
Showing 17 changed files with 418 additions and 196 deletions.
8 changes: 8 additions & 0 deletions complx/AdvancedLoadDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ extern lc3_state state;
AdvancedLoadDialog::AdvancedLoadDialog(wxWindow* parent, const LoadingOptions& opts) : AdvancedLoadDialogDecl(parent)
{
assemblyFile->SetPath(opts.file);
replayString->SetValue(opts.replay_string);
#ifndef ENABLE_LC3_REPLAY
replayString->Enable(false);
replayString->SetValue("");
#endif
consoleInput->SetValue(opts.console_input);
regInitializer->SetSelection(opts.registers == RANDOMIZE ? 0 : (opts.registers == ZEROED ? 1 : 2));
if (opts.registers != RANDOMIZE && opts.registers != ZEROED)
Expand Down Expand Up @@ -34,6 +39,9 @@ LoadingOptions AdvancedLoadDialog::GetOptions()
return options;

options.file = file;
#ifdef ENABLE_LC3_REPLAY
options.replay_string = replayString->GetValue().ToStdString();
#endif
options.console_input = consoleInput->GetValue().ToStdString();
int ret = -1;
int error;
Expand Down
11 changes: 11 additions & 0 deletions complx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,24 @@ add_executable(
${SRC_COMPLX}
)

if (ENABLE_REPLAY)
add_definitions(-DENABLE_LC3_REPLAY)
include_directories("../replay")
target_link_libraries(
complx
lc3_replay
)
endif (ENABLE_REPLAY)

target_link_libraries(
complx
lc3
${wxWidgets_LIBRARIES}
${GLIB2_LIBRARIES}
)



install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/complx DESTINATION ${CMAKE_INSTALL_BINDIR})

install(FILES ../doc/complx-tools.pdf DESTINATION share/doc/complx-tools)
Expand Down
135 changes: 128 additions & 7 deletions complx/ComplxFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
#include "LC3RunThread.hpp"
#include "version.h"

#ifdef ENABLE_LC3_REPLAY
#include <lc3_replay.hpp>
#endif

lc3_state state;

extern ComplxFrame* complxframe;
Expand Down Expand Up @@ -203,6 +207,8 @@ void ComplxFrame::OnAdvancedLoad(wxCommandEvent& event)
}
reload_options = options;
DoLoadFile(reload_options);
if (!reload_options.replay_string.empty())
DoSetupReplayString(reload_options.replay_string);
}
delete dialog;
}
Expand Down Expand Up @@ -1322,6 +1328,121 @@ void ComplxFrame::OnDestroyView(wxCloseEvent& event)
frame->Destroy();
}

void ComplxFrame::OnSetupReplayString(wxCommandEvent& event)
{
#ifdef ENABLE_LC3_REPLAY
if (Running())
return;

if (reload_options.file.empty())
OnLoad(event);

if (reload_options.file.empty())
{
wxMessageBox("An assembly file must be loaded to perform this operation", "Error");
return;
}

std::string replay_str = DoAskForReplayString();

if (replay_str.empty())
return;

DoSetupReplayString(replay_str);
#else
wxMessageBox("Support for this menu function was not enabled.", "Error");
#endif
}
void ComplxFrame::OnReloadReplayString(wxCommandEvent& event)
{
#ifdef ENABLE_LC3_REPLAY
if (reload_options.replay_string.empty() || reload_options.file.empty())
{
OnSetupReplayString(event);
return;
}

DoSetupReplayString(reload_options.replay_string);
#else
wxMessageBox("Support for this menu function was not enabled.", "Error");
#endif
}
void ComplxFrame::OnDescribeReplayString(wxCommandEvent& event)
{
#ifdef ENABLE_LC3_REPLAY
std::string replay_str = reload_options.replay_string;
if (replay_str.empty())
{
replay_str = DoAskForReplayString();

if (replay_str.empty())
{
wxMessageBox("No replay string given.", "Error");
return;
}
}

try
{
std::string description = lc3_describe_replay(replay_str);
wxMessageBox(description);
}
catch (std::string err)
{
wxMessageBox(err.c_str(), "Error");
return;
}
catch (const char* err)
{
wxMessageBox(err, "Error");
return;
}
#else
wxMessageBox("Support for this menu function was not enabled.", "Error");
#endif
}

std::string ComplxFrame::DoAskForReplayString()
{
#ifdef ENABLE_LC3_REPLAY
wxString replay = wxGetTextFromUser("Enter Replay String", "Testing");
if (replay.IsEmpty())
{
wxMessageBox("No replay string given", "Error");
return "";
}
return replay.ToStdString();
#else
return "";
#endif
}

void ComplxFrame::DoSetupReplayString(const std::string& replay_string)
{
#ifdef ENABLE_LC3_REPLAY
try
{
std::stringstream input;
lc3_setup_replay(state, reload_options.file, replay_string, input);
console->SetInput(input.str());
reload_options.replay_string = replay_string;
UpdateRegisters();
UpdateMemory();
UpdateStatus();
}
catch (std::string err)
{
wxMessageBox(err.c_str(), "Error");
return;
}
catch (const char* err)
{
wxMessageBox(err, "Error");
return;
}
#endif
}

/** OnAbout
*
* Displays information about this program
Expand All @@ -1332,7 +1453,7 @@ void ComplxFrame::OnAbout(wxCommandEvent& event)
aboutInfo.SetName("Complx");
aboutInfo.SetVersion(Version::FULLVERSION_STRING);
aboutInfo.SetDescription(_("LC-3 Simulator\nBug reports, thanks, and feature requests should be sent to Brandon.\nbwhitehead0308@gmail.com"));
aboutInfo.SetCopyright("(C) 2010-2016");
aboutInfo.SetCopyright("(C) 2010-2018");
aboutInfo.AddDeveloper("Brandon Whitehead bwhitehead0308@gmail.com");
aboutInfo.SetIcon(wxIcon(icon64_xpm));

Expand Down Expand Up @@ -1485,22 +1606,22 @@ void PrintError(int error)
switch(error)
{
case 1:
msg = _("ERROR! Error evaluating expression: Unbalanced parenthesis");
msg = _("Error evaluating expression: Unbalanced parenthesis");
break;
case 2:
msg = _("ERROR! Error evaluating expression: Invalid Operator");
msg = _("Error evaluating expression: Invalid Operator");
break;
case 3:
msg = _("ERROR! Error evaluating expression: Invalid operand");
msg = _("Error evaluating expression: Invalid operand");
break;
case 4:
msg = _("ERROR! Error evaluating expression: Malformed reference");
msg = _("Error evaluating expression: Malformed reference");
break;
case 5:
msg = _("ERROR! Error evaluating expression: Undefined symbol");
msg = _("Error evaluating expression: Undefined symbol");
break;
default:
msg = _("ERROR! Error evaluating expression.");
msg = _("Error evaluating expression.");
break;
}

Expand Down
9 changes: 8 additions & 1 deletion complx/ComplxFrame.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@ class ComplxFrame : public ComplxFrameDecl
void OnAdvancedBreakpoint(wxCommandEvent& event) override;
void OnBlackbox(wxCommandEvent& event) override;

// Test menu event handlers
void OnSetupReplayString(wxCommandEvent& event) override;
void OnReloadReplayString(wxCommandEvent& event) override;
void OnDescribeReplayString(wxCommandEvent& event) override;
std::string DoAskForReplayString();
void DoSetupReplayString(const std::string& replay_string);

// Help menu event handlers
void OnDocs(wxCommandEvent& event) override;
void OnISA(wxCommandEvent& event) override;
Expand Down Expand Up @@ -153,7 +160,7 @@ class ComplxFrame : public ComplxFrameDecl
* Attempts to detect if a subroutine is found in the loaded code
* The way this function works is it will try to find a RET, JSR, or JSRR instruction.
* We do not look at trap instructions since they are black boxed anyway if true traps are disabled,
* however if a custom trap is written then it will of course have a RETY statement.
* however if a custom trap is written then it will of course have a RET statement.
* The usage of this function is for enabling or disabling the Next/Prev Line and Finish control buttons.
* @param ranges Code ranges the file that was loaded touches
* @return True if a subroutine was detected false otherwise
Expand Down
Loading

0 comments on commit 127d4d1

Please sign in to comment.