コード例 #1
0
ファイル: ComplxFrame.cpp プロジェクト: cchen396/complx
/** OnRandomizeAndLoad
  *
  * Randomizes memory and loads a file
  */
void ComplxFrame::OnRandomizeAndLoad(wxCommandEvent& event)
{
    if (Running()) return;
    wxFileDialog* dialog = new wxFileDialog(NULL, _("Load .asm file"), wxEmptyString, wxEmptyString, _("LC-3 Assembly Files (*.asm)|*.asm"), wxFD_OPEN|wxFD_FILE_MUST_EXIST|wxFD_CHANGE_DIR);
    if (dialog->ShowModal() == wxID_OK)
    {
        wxFileName filename(dialog->GetPath());
        OnInit();
        lc3_randomize(state);
        DoLoadFile(filename);
    }
}
コード例 #2
0
ファイル: ComplxFrame.cpp プロジェクト: cchen396/complx
/** OnRandomizeAndReload
  *
  * Called when the user wants to reload the last file.
  */
void ComplxFrame::OnRandomizeAndReload(wxCommandEvent& event)
{
    if (Running()) return;
    if (currentFile.GetFullName().IsEmpty())
    {
        OnLoad(event);
        return;
    }

    OnInit();
    lc3_randomize(state);
    DoLoadFile(currentFile);
}
コード例 #3
0
/** lc3_init
  *
  * Initializes the state of the lc3
  *
  * @param state An LC3 state
  * @param randomize_registers if true randomizes registers
  * @param randomize_memory if true randomizes memory
  * @param fill_value ignored if randomize_XXX is true otherwise sets registers/memory to this value (except R7).
  */
void lc3_init(lc3_state& state, bool randomize_registers, bool randomize_memory, short fill_value)
{
    // Set Registers
    state.regs[0] = randomize_registers ? lc3_random() : fill_value;
    state.regs[1] = randomize_registers ? lc3_random() : fill_value;
    state.regs[2] = randomize_registers ? lc3_random() : fill_value;
    state.regs[3] = randomize_registers ? lc3_random() : fill_value;
    state.regs[4] = randomize_registers ? lc3_random() : fill_value;
    state.regs[5] = randomize_registers ? lc3_random() : fill_value;
    state.regs[6] = randomize_registers ? lc3_random() : fill_value;
    state.regs[7] = randomize_registers ? lc3_random() : 0x490;

    // PC is initially at address 3000
    state.pc = 0x3000;

    // User mode
    state.privilege = 1;
    state.priority = 0;


    // Set Control Flags
    state.n = 0;
    state.z = 1;
    state.p = 0;

    // Set Additional Flags
    state.halted = 0;
    state.true_traps = 0;
    state.warnings = 0;
    state.executions = 0;
    state.interrupt_enabled = 0;

    // Clear subroutine info
    state.max_call_stack_size = -1;
    state.call_stack.clear();

    // Set Stack Flags
    state.max_stack_size = -1;
    state.undo_stack.clear();

    // Set I/O Stuff
    state.input = &std::cin;
    state.reader = lc3_read_char;
    state.peek = lc3_peek_char;
    state.output = &std::cout;
    state.writer = lc3_do_write_char;
    state.warning = &std::cout;

    // Clear memory
    if (randomize_memory)
    {
        lc3_randomize(state);
    }
    else
    {
        for (unsigned int i = 0; i < 65536; i++)
            state.mem[i] = fill_value;
    }

    // Add LC3 OS
    memcpy(state.mem, lc3_os, LC3_OS_SIZE * sizeof(unsigned short));

    // Clear plugins
    lc3_remove_plugins(state);

    // Clear Symbol Table
    state.symbols.clear();
    state.rev_symbols.clear();

    // Clear Breakpoints and all that jazz
    state.breakpoints.clear();
    state.blackboxes.clear();
    state.comments.clear();
    state.reg_watchpoints.clear();
    state.mem_watchpoints.clear();
    state.subroutines.clear();

    // Clear pending interrupts
    state.interrupts.clear();
    state.interrupt_test.clear();
    state.interrupt_vector = -1;
    state.savedssp = 0x3000;
    state.savedusp = 0xF000;

    state.memory_ops.clear();
    state.total_reads = 0;
    state.total_writes = 0;

    state.in_lc3test = false;
}