Пример #1
0
/** ComplxFrame
  *
  * Constructor
  */
ComplxFrame::ComplxFrame(const ComplxFrame::Options& opts) :
    ComplxFrameDecl(NULL, wxID_ANY, opts.title, wxDefaultPosition, wxSize(opts.width, opts.height)), console(NULL), memoryView(NULL), base_title(opts.title)
{
    InitImages();

    menuViewInstructionHighlighting->Check(opts.highlight);
    menuViewBasic->Check(opts.disassemble == 0);
    menuViewNormal->Check(opts.disassemble == 1);
    menuViewHighLevel->Check(opts.disassemble == 2);

    this->stack_size = opts.stack_size;
    this->call_stack_size = opts.call_stack_size;

    DoLoadFile(opts.loading_options);

    memoryView = new MemoryView();
    memory->SetView(memoryView, opts.exact_column_sizing, opts.column_sizes);
    memory->SetDisassembleLevel(opts.disassemble);
    memory->SetUnsignedMode(false);
    memory->SetHighlight(opts.highlight);

    int widths[5] = {-6, -2, -2, -2, -2};
    int styles[5] = {wxSB_NORMAL, wxSB_NORMAL, wxSB_NORMAL, wxSB_NORMAL, wxSB_NORMAL};
    statusBar->SetStatusWidths(5, widths);
    statusBar->SetStatusStyles(5, styles);

    UpdateMemory();
    UpdateStatus();

    Connect(wxID_ANY, wxEVT_COMMAND_RUNTHREAD_COMPLETED, wxThreadEventHandler(ComplxFrame::OnRunComplete));
    Connect(wxID_ANY, wxEVT_COMMAND_RUNTHREAD_IO, wxThreadEventHandler(ComplxFrame::OnIo));
    Connect(wxID_ANY, wxEVT_COMMAND_RUNTHREAD_NOIO, wxThreadEventHandler(ComplxFrame::OnNoIo));
    Connect(wxID_ANY, wxEVT_COMMAND_RUNTHREAD_OUTPUT, wxThreadEventHandler(ComplxFrame::OnOutput));
}
Пример #2
0
/** DoLoadMachine
  *
  * Handles loading a machine state
  */
void ComplxFrame::DoLoadMachine(const wxFileName& filename)
{
    std::ifstream file(filename.GetFullName().c_str(), std::ios::binary);
    file.read((char*) &state, sizeof(state));
    file.close();
    UpdateRegisters();
    UpdateMemory();
    UpdateStatus();
}
Пример #3
0
void ComplxFrame::OnRunComplete(wxThreadEvent& event)
{
    std::cout.flush();
    console->Update();
    UpdatePlay();
    UpdateRegisters();
    UpdateMemory();
    UpdateStatus();
}
Пример #4
0
/** DoLoadFile
  *
  * Handles loading an assembly file into the simulator
  */
void ComplxFrame::DoLoadFile(const wxFileName& filename)
{
    //CleanUp();
    lc3_state dummy_state;
    lc3_init(dummy_state);

    // Save the symbols
    std::map<std::string, unsigned short> symbol_table = state.symbols;
    std::map<unsigned short, std::string> rev_symbol_table = state.rev_symbols;

    state.symbols.clear();
    state.rev_symbols.clear();
    lc3_remove_plugins(state);

    try
    {
        lc3_assemble(dummy_state, filename.GetFullPath().ToStdString(), false);
        lc3_assemble(state, filename.GetFullPath().ToStdString());

    }
    catch (LC3AssembleException e)
    {
        wxMessageBox(wxString::Format("BAD STUDENT! %s", e.what()), _("Loading ") + filename.GetFullName() + _(" Failed"));
        goto merge;
    }
    catch (std::vector<LC3AssembleException> e)
    {
        std::stringstream oss;
        for (unsigned int i = 0; i < e.size(); i++)
            oss << e[i].what() << std::endl;
        wxMessageBox(wxString::Format("BAD STUDENT! %s", oss.str()), _("Loading ") + filename.GetFullName() + _(" Failed"));
        goto merge;
    }

    //if (DoAssemble(filename)) return;
    currentFile = filename;
    SetTitle(wxString::Format("Complx - %s", filename.GetFullPath()));
    merge:

    std::map<std::string, unsigned short>::const_iterator i;
    std::map<unsigned short, std::string>::const_iterator j;
    for (i = symbol_table.begin(); i != symbol_table.end(); ++i)
    {
        state.symbols[i->first] = i->second;
    }
    for (j = rev_symbol_table.begin(); j != rev_symbol_table.end(); ++j)
    {
        state.rev_symbols[j->first] = j->second;
    }

    //DoLoad(filename);
    UpdateStatus();
    UpdateRegisters();
    UpdateMemory();

}
Пример #5
0
/** @brief OnNoIo
  *
  * @todo: document this function
  */
void ComplxFrame::OnNoIo(wxThreadEvent& event)
{
    //printf("There is no time\n");
    wxCriticalSectionLocker enter(threadCS);
    if (thread != NULL && !thread->IsPaused()) thread->Pause();
    if (!refreshednoio)
    {
        UpdatePhrase("&NO IO");
        UpdateRegisters();
        UpdateMemory();
        UpdateStatus();
        refreshednoio = true;
    }
}
Пример #6
0
void ComplxFrame::SetupExecution(int run_mode, int runtime)
{
    wxCriticalSectionLocker enter(threadCS);
    changed = false;
    if (thread != NULL)
    {
        if (thread->IsPaused()) return;
        if (thread->IsRunning())
        {
            //printf("Deleting thread\n");
            thread->Delete();
            //delete thread;
            thread = NULL;
            changed = true;
            std::cout.flush();
            console->Update();
            UpdatePlay();
            UpdateRegisters();
            UpdateMemory();
            UpdateStatus();
            return;
        }
        else
        {
//            //printf("Deleting and Creating thread\n");
            thread->Delete();
            thread = NULL;
            //delete thread;
            //thread = new LC3RunThread(this, run_mode);
            //thread->Create();
            //UpdateStop();
            return;
        }
    }
    else
    {
        //printf("Creating thread\n");
        thread = new LC3RunThread(this, run_mode, runtime);
        thread->Create();
        //UpdateStop();
    }

    thread->SetPriority(0);
    thread->Run();
}
Пример #7
0
/** ComplxFrame
  *
  * Constructor
  */
ComplxFrame::ComplxFrame(long decimal, long disassemble, long stack_size, long true_traps, long interrupts, long highlight,
                         wxString address_str, wxString state_file, wxArrayString files) : ComplxFrameDecl(NULL), console(NULL), memoryView(NULL)
{
    InitImages();

    menuStateTrueTraps->Check(true_traps == 1);
    menuStateInterrupts->Check(interrupts == 1);
    menuViewInstructionHighlighting->Check(highlight != 0);
    menuViewUnsignedDecimal->Check(decimal == 1);

    this->stack_size = stack_size;
    OnInit();

    if (!address_str.IsEmpty())
    {
        int addr;
        lc3_calculate(state, address_str.ToStdString(), addr);
        state.pc = addr;
    }

    if (!state_file.IsEmpty()) DoLoadMachine(wxFileName(state_file));
    if (files.size() > 0) DoLoadFile(wxFileName(files[0]));

    memoryView = new MemoryView();
    memory->SetView(memoryView);
    memory->SetDisassembleLevel(disassemble > 2 ? 2 : disassemble);
    memory->SetUnsignedMode(decimal > 1 ? 0 : decimal);
    memory->SetHighlight(highlight > 1 ? 1 : highlight);

    int widths[3] = {-7, -3, -3};
    int styles[3] = {wxSB_NORMAL, wxSB_NORMAL, wxSB_NORMAL};
    statusBar->SetStatusWidths(3, widths);
    statusBar->SetStatusStyles(3, styles);

    UpdateMemory();
    UpdateStatus();

    Connect(wxID_ANY, wxEVT_COMMAND_RUNTHREAD_COMPLETED, wxThreadEventHandler(ComplxFrame::OnRunComplete));
    Connect(wxID_ANY, wxEVT_COMMAND_RUNTHREAD_UPDATE, wxThreadEventHandler(ComplxFrame::OnRunUpdate));
    Connect(wxID_ANY, wxEVT_COMMAND_RUNTHREAD_IO, wxThreadEventHandler(ComplxFrame::OnIo));
    Connect(wxID_ANY, wxEVT_COMMAND_RUNTHREAD_NOIO, wxThreadEventHandler(ComplxFrame::OnNoIo));
    Connect(wxID_ANY, wxEVT_COMMAND_RUNTHREAD_OUTPUT, wxThreadEventHandler(ComplxFrame::OnOutput));
}
Пример #8
0
void ComplxFrame::SetupExecution(int run_mode, int runtime)
{
    wxCriticalSectionLocker enter(threadCS);
    if (run_mode != RUNMODE_STEP && run_mode != RUNMODE_BACK)
        UpdatePhrase("&Stop");
    if (thread != NULL)
    {
        if (thread->IsPaused()) return;
        if (thread->IsRunning())
        {
            thread->Delete();
            thread = NULL;
            std::cout.flush();
            console->Update();
            UpdatePlay();
            UpdateRegisters();
            UpdateMemory();
            UpdateStatus();
            return;
        }
        else
        {
            thread->Delete();
            thread = NULL;
            return;
        }
    }
    else
    {
        thread = new LC3RunThread(this, run_mode, runtime);
        thread->Create();
    }

    thread->SetPriority(0);
    thread->Run();
}
Пример #9
0
void CBaseMonster::net_Relcase(CObject *O)
{
	inherited::net_Relcase(O);

	StateMan->remove_links			(O);

	com_man().remove_links			(O);

	// TODO: do not clear, remove only object O
	if (g_Alive()) {
		EnemyMemory.remove_links	(O);
		SoundMemory.remove_links	(O);
		HitMemory.remove_hit_info	(O);

		EnemyMan.remove_links		(O);
		CorpseMan.remove_links		(O);

		UpdateMemory				();
		
		monster_squad().remove_links(O);
	}
	CorpseMemory.remove_links		(O);
	m_pPhysics_support->in_NetRelcase(O);
}
Пример #10
0
/** OnInterrupts
  *
  * Turns on/off interrupts.
  */
void ComplxFrame::OnInterrupts(wxCommandEvent& event)
{
    state.interrupt_enabled = ~state.interrupt_enabled;
    UpdateMemory();
}
Пример #11
0
/** OnTrueTraps
  *
  * Turns on/off true traps.
  */
void ComplxFrame::OnTrueTraps(wxCommandEvent& event)
{
    lc3_set_true_traps(state, ~state.true_traps);
    UpdateMemory();
}
Пример #12
0
/** OnIdle
  *
  * Called once when the app starts.
  */
void ComplxFrame::OnIdle(wxIdleEvent& event)
{
    this->Disconnect(wxEVT_IDLE, wxIdleEventHandler(ComplxFrame::OnIdle));
    UpdateRegisters();
    UpdateMemory();
}
Пример #13
0
/** DoLoadFile
  *
  * Handles loading an assembly file into the simulator
  */
void ComplxFrame::DoLoadFile(const LoadingOptions& opts)
{
    auto* config = wxConfigBase::Get();

    wxFileName filename(opts.file);
    bool randomize_registers = opts.registers == RANDOMIZE;
    bool randomize_memory = opts.memory == RANDOMIZE;
    short fill_registers = opts.registers;
    short fill_memory = opts.memory;

    lc3_init(state, randomize_registers, randomize_memory, fill_registers, fill_memory);
    state.pc = opts.pc;

    PostInit();

    // Now the actual loading
    if (opts.file.empty())
        return;

    lc3_state dummy_state;
    lc3_init(dummy_state);

    // Save the symbols
    std::map<std::string, unsigned short> symbol_table = state.symbols;
    std::map<unsigned short, std::string> rev_symbol_table = state.rev_symbols;

    state.symbols.clear();
    state.rev_symbols.clear();
    lc3_remove_plugins(state);

    bool tvt_modification = false;
    bool ivt_modification = false;
    bool subroutine_found = false;

    try
    {
        ///TODO should only make one call to lc3_assemble.
        std::vector<code_range> ranges;
        LC3AssembleOptions options;
        options.multiple_errors = false;
        lc3_assemble(dummy_state, filename.GetFullPath().ToStdString(), options);
        options.multiple_errors = true;
        options.warnings_as_errors = false;
        options.process_debug_comments = true;
        options.enable_warnings = false;
        options.disable_plugins = false;
        lc3_assemble(state, filename.GetFullPath().ToStdString(), ranges, options);

        // Update list of addresses modified for Show only Code/Data option.
        modified_addresses.clear();
        for (const auto& code_range : ranges)
            modified_addresses.push_back(ViewRange(code_range.location, code_range.location + code_range.size));
        /// TODO Automatically determine state of true traps and interrupts via the code ranges.
        // Dummy call to update hidden addresses.
        wxCommandEvent event;
        OnUpdateHideAddresses(event);
        // Check for TVT and IVT modification
        for (const auto& code_range : ranges)
        {
            if ((code_range.location >= 0 && code_range.location <= 0xFF) || (code_range.location + code_range.size >= 0 && code_range.location + code_range.size <= 0xFF))
                tvt_modification = true;
            if ((code_range.location >= 0x100 && code_range.location <= 0x1FF) || (code_range.location + code_range.size >= 0x100 && code_range.location + code_range.size <= 0x1FF))
                ivt_modification = true;
        }
        subroutine_found = DetectSubroutine(ranges);
    }
    catch (LC3AssembleException e)
    {
        wxMessageBox(wxString::Format("ERROR! %s", e.what()), wxString::Format("Loading %s failed", filename.GetFullName()));
        goto merge;
    }
    catch (std::vector<LC3AssembleException> e)
    {
        std::stringstream oss;
        for (unsigned int i = 0; i < e.size(); i++)
            oss << e[i].what() << std::endl;
        wxMessageBox(wxString::Format("ERROR! %s", oss.str()), wxString::Format("Loading %s failed", filename.GetFullName()));
        goto merge;
    }

    lc3_set_true_traps(state, opts.true_traps || tvt_modification);
    state.interrupt_enabled = opts.interrupts || ivt_modification;
    console->SetInput(opts.console_input);
    state.strict_execution = opts.strict_execution;
    // Update menus
    menuStateTrueTraps->Check(opts.true_traps || tvt_modification);
    menuStateInterrupts->Check(opts.interrupts || ivt_modification);
    menuStateStrictExecution->Check(opts.strict_execution);

    if (tvt_modification)
    {
        bool tvt_popup = config->Read("/firsttimetrap", "").IsEmpty();
        if (tvt_popup)
        {
            wxMessageBox("Pardon the interruption!\n"
                         "It appears you have loaded a file with a custom trap.\n"
                         "This will automatically enable true traps mode.\n"
                         "This will allow you to step into the code for the standard traps (IN,OUT,GETC,PUTS,HALT) and your own custom trap.\n"
                         "This notice to to remind you of the above, executing HALT will jump to some random code, but I assure you this random code is the code to HALT the LC-3.\n"
                         "If you'd rather stop the execution right at the HALT statement then put a breakpoint on your HALT statement.\n",
                         "Notice");
            config->Write("/firsttimetrap", "1");
        }
    }

    if (subroutine_found)
    {
        wxCommandEvent event;
        OnControlModeAdvanced(event);
        bool subroutine_popup = config->Read("/firsttimesubroutine", "").IsEmpty();
        if (subroutine_popup)
        {
            wxMessageBox("Pardon the interruption!\n"
                         "It appears you have loaded a file with a custom trap or subroutine.\n"
                         "You may notice 3 new buttons in the control area.\n"
                         "Next Line\n    Allows you to STEP OVER a subroutine or trap, meaning it will skip over it (but still execute it).\n"
                         "Prev Line\n    Allows you to BACK STEP OVER a subroutine or trap.\n"
                         "Finish\n    Allows you to STEP OUT of a subroutine, it finishes execution of it.\n\n"
                         "Another thing to note if you want to always step over/out a subroutine to select the subroutine label and select mark as blackbox.\n"
                         "If you use step on a JSR/JSRR/TRAP instruction that is blackboxed it will never step into it.\n"
                         "For more information Read The Manual :)\n"
                         , "Notice");
            config->Write("/firsttimesubroutine", "1");
        }
    }

    SetTitle(wxString::Format("%s - %s", base_title, filename.GetFullPath()));

merge:
    std::map<std::string, unsigned short>::const_iterator i;
    std::map<unsigned short, std::string>::const_iterator j;
    for (i = symbol_table.begin(); i != symbol_table.end(); ++i)
    {
        state.symbols[i->first] = i->second;
    }
    for (j = rev_symbol_table.begin(); j != rev_symbol_table.end(); ++j)
    {
        state.rev_symbols[j->first] = j->second;
    }

    UpdateStatus();
    UpdateRegisters();
    UpdateMemory();

    // Save in reload options
    reload_options = opts;

    // Update timestamps
    wxFileName file_loaded(reload_options.file);
    reload_options.file_modification_time = file_loaded.GetModificationTime();
}
Пример #14
0
/** OnStrictExecution
  *
  * Toggles strict execution mode.
  */
void ComplxFrame::OnStrictExecution(wxCommandEvent& event)
{
    state.strict_execution = ~state.strict_execution;
    UpdateMemory();
}
Пример #15
0
	MemInfo* MemoryTracker::GetProcessMemInfo()
	{
		UpdateMemory();
		return &m_memInfo;
	}
Пример #16
0
	void MemoryTracker::LogProcessMemoryInfo() 
	{
		UpdateMemory();
		m_logger->LogText(LogTag::GENERAL, LogLevel::DEBUG_PRINT,  "Working set size: %d MiB, %d KiB, %d B", m_memInfo.m_workingSetMiB, m_memInfo.m_workingSetKiB, m_memInfo.m_workingSetB);
		m_logger->LogText(LogTag::GENERAL, LogLevel::DEBUG_PRINT, "Peak working set size: %d MiB, %d KiB, %d B", m_memInfo.m_peakSetMiB, m_memInfo.m_peakSetKiB, m_memInfo.m_peakSetB);
	}