Skip to content

Commit

Permalink
Fix console input/output not being detected w/ Setup/Switch Test.
Browse files Browse the repository at this point in the history
  • Loading branch information
TricksterGuy committed Mar 3, 2018
1 parent ea71560 commit 744b5c3
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 31 deletions.
71 changes: 41 additions & 30 deletions complx/ComplxFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,6 @@ void ComplxFrame::OnReload(wxCommandEvent& event)
*/
void ComplxFrame::DoLoadFile(const LoadingOptions& opts)
{
static bool first = true;
auto* config = wxConfigBase::Get();

wxFileName filename(opts.file);
Expand All @@ -242,35 +241,7 @@ void ComplxFrame::DoLoadFile(const LoadingOptions& opts)
lc3_init(state, randomize_registers, randomize_memory, fill_registers, fill_memory);
state.pc = opts.pc;

if (console != NULL) delete console;
console = new LC3Console(this);

state.input = &console->inputStream;
state.reader = complx_reader;
state.peek = complx_peek;
state.writer = complx_writer;
// For keyboard interrupts
state.interrupt_test.push_back(complx_step);

console->Show();

int x, y;
GetScreenPosition(&x, &y);
if (first)
{
Move(x + console->GetSize().GetX() / 2, y);
console->Move(x - console->GetSize().GetX() / 2, y);
first = false;
}
else
{
console->Move(x - console->GetSize().GetX(), y);
}

state.max_stack_size = stack_size;
state.max_call_stack_size = call_stack_size;
// Fix for console stealing focus.
SetFocus();
PostInit();

// Now the actual loading
if (opts.file.empty())
Expand Down Expand Up @@ -405,6 +376,44 @@ void ComplxFrame::DoLoadFile(const LoadingOptions& opts)
reload_options = opts;
}

/** PostInit
*
* Called after initializing.
*/
void ComplxFrame::PostInit()
{
static bool first = true;
if (console != NULL) delete console;
console = new LC3Console(this);

state.input = &console->inputStream;
state.reader = complx_reader;
state.peek = complx_peek;
state.writer = complx_writer;
// For keyboard interrupts
state.interrupt_test.push_back(complx_step);

console->Show();

int x, y;
GetScreenPosition(&x, &y);
if (first)
{
Move(x + console->GetSize().GetX() / 2, y);
console->Move(x - console->GetSize().GetX() / 2, y);
first = false;
}
else
{
console->Move(x - console->GetSize().GetX(), y);
}

state.max_stack_size = stack_size;
state.max_call_stack_size = call_stack_size;
// Fix for console stealing focus.
SetFocus();
}

/** OnQuit
*
* Called when the user quits the program.
Expand Down Expand Up @@ -1111,6 +1120,7 @@ void ComplxFrame::OnSetupTest(wxCommandEvent& event)
{
std::stringstream input;
lc3_init_test_case(state, reload_options.file, test, -1, false);
PostInit();
lc3_setup_test_case(state, test, input);
console->SetInput(input.str());
reload_options.tests = filename;
Expand Down Expand Up @@ -1150,6 +1160,7 @@ void ComplxFrame::OnSwitchTest(wxCommandEvent& event)
{
std::stringstream input;
lc3_init_test_case(state, reload_options.file, test, -1, false);
PostInit();
lc3_setup_test_case(state, test, input);
console->SetInput(input.str());
reload_options.tests = filename;
Expand Down
1 change: 1 addition & 0 deletions complx/ComplxFrame.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ class ComplxFrame : public ComplxFrameDecl

void SetupExecution(int run_mode, int runtime = -1);
void DoLoadFile(const LoadingOptions& opts);
void PostInit();
/** DetectSubroutine
*
* Attempts to detect if a subroutine is found in the loaded code
Expand Down
2 changes: 1 addition & 1 deletion complx/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
#define VERSION_H

namespace Version {
static const char FULLVERSION_STRING[] = "4.16.5";
static const char FULLVERSION_STRING[] = "4.16.6";
}
#endif

0 comments on commit 744b5c3

Please sign in to comment.