예제 #1
0
void DoConsoleCommand()
{
    // Get command text
    TCHAR command[32];
    GetWindowText(m_hwndConsoleEdit, command, 32);
    SendMessage(m_hwndConsoleEdit, WM_SETTEXT, 0, (LPARAM) _T(""));  // Clear command

    if (command[0] == 0) return;  // Nothing to do

    // Echo command to the log
    TCHAR buffer[36];
    ::GetWindowText(m_hwndConsolePrompt, buffer, 14);
    ConsoleView_Print(buffer);
    wsprintf(buffer, _T(" %s\r\n"), command);
    ConsoleView_Print(buffer);

    BOOL okUpdateAllViews = FALSE;  // Flag - need to update all debug views
    CProcessor* pProc = ConsoleView_GetCurrentProcessor();

    // Execute the command
    switch (command[0])
    {
    case _T('h'):
        ConsoleView_ShowHelp();
        break;
    case _T('c'):  // Clear log
        ClearConsole();
        break;
    case _T('r'):  // Register operations
        if (command[1] == 0)  // Print all registers
        {
            for (int r = 0; r < 8; r++)
            {
                LPCTSTR name = REGISTER_NAME[r];
                WORD value = pProc->GetReg(r);
                PrintRegister(name, value);
            }
            PrintRegister(_T("PS"), pProc->GetPSW());
        }
        else if (command[1] >= _T('0') && command[1] <= _T('7'))  // "r0".."r7"
        {
            int r = command[1] - _T('0');
            LPCTSTR name = REGISTER_NAME[r];
            if (command[2] == 0)  // "rN" - show register N
            {
                WORD value = pProc->GetReg(r);
                PrintRegister(name, value);
            }
            else if (command[2] == _T('=') || command[2] == _T(' '))  // "rN=XXXXXX" - set register N to value XXXXXX
            {
                WORD value;
                if (! ParseOctalValue(command + 3, &value))
                    ConsoleView_Print(MESSAGE_WRONG_VALUE);
                else
                {
                    pProc->SetReg(r, value);
                    PrintRegister(name, value);
                    okUpdateAllViews = TRUE;
                }
            }
            else
                ConsoleView_Print(MESSAGE_UNKNOWN_COMMAND);
        }
        else if (command[1] == _T('p') && command[2] == _T('s'))  // "rps"
        {
            if (command[3] == 0)  // "rps" - show PSW
            {
                WORD value = pProc->GetPSW();
                PrintRegister(_T("PS"), value);
            }
            else if (command[3] == _T('=') || command[3] == _T(' '))  // "rps=XXXXXX" - set PSW to value XXXXXX
            {
                WORD value;
                if (! ParseOctalValue(command + 4, &value))
                    ConsoleView_Print(MESSAGE_WRONG_VALUE);
                else
                {
                    pProc->SetPSW(value);
                    PrintRegister(_T("PS"), value);
                    okUpdateAllViews = TRUE;
                }
            }
            else
                ConsoleView_Print(MESSAGE_UNKNOWN_COMMAND);
        }
        else
            ConsoleView_Print(MESSAGE_UNKNOWN_COMMAND);
        break;
    case _T('s'):  // Step
        if (command[1] == 0)  // "s" - Step Into, execute one instruction
        {
            PrintDisassemble(pProc, pProc->GetPC(), TRUE, FALSE);
            //pProc->Execute();

            g_pBoard->DebugTicks();

            okUpdateAllViews = TRUE;
        }
        else if (command[1] == _T('o'))  // "so" - Step Over
        {
            int instrLength = PrintDisassemble(pProc, pProc->GetPC(), TRUE, FALSE);
            WORD bpaddress = (WORD)(pProc->GetPC() + instrLength * 2);

            Emulator_SetCPUBreakpoint(bpaddress);
            Emulator_Start();
        }
        break;
    case _T('d'):  // Disassemble
    case _T('D'):  // Disassemble, short format
        {
            BOOL okShort = (command[0] == _T('D'));
            if (command[1] == 0)  // "d" - disassemble at current address
                PrintDisassemble(pProc, pProc->GetPC(), FALSE, okShort);
            else if (command[1] >= _T('0') && command[1] <= _T('7'))  // "dXXXXXX" - disassemble at address XXXXXX
            {
                WORD value;
                if (! ParseOctalValue(command + 1, &value))
                    ConsoleView_Print(MESSAGE_WRONG_VALUE);
                else
                {
                    PrintDisassemble(pProc, value, FALSE, okShort);
                }
            }
            else
                ConsoleView_Print(MESSAGE_UNKNOWN_COMMAND);
        }
        break;
    case _T('u'):
        SaveMemoryDump(pProc);
        break;
    case _T('m'):
        if (command[1] == 0)  // "m" - dump memory at current address
        {
            PrintMemoryDump(pProc, pProc->GetPC(), 8);
        }
        else if (command[1] >= _T('0') && command[1] <= _T('7'))  // "mXXXXXX" - dump memory at address XXXXXX
        {
            WORD value;
            if (! ParseOctalValue(command + 1, &value))
                ConsoleView_Print(MESSAGE_WRONG_VALUE);
            else
            {
                PrintMemoryDump(pProc, value, 8);
            }
        }
        else if (command[1] == _T('r') &&
                command[2] >= _T('0') && command[2] <= _T('7'))  // "mrN" - dump memory at address from register N
        {
            int r = command[2] - _T('0');
            WORD address = pProc->GetReg(r);
            PrintMemoryDump(pProc, address, 8);
        }
        else if (command[1] == _T('o'))
        {
            ConsoleView_GotoMonitor();
        }
        else
            ConsoleView_Print(MESSAGE_UNKNOWN_COMMAND);
        break;
        //TODO: "mXXXXXX YYYYYY" - set memory cell at XXXXXX to value YYYYYY
        //TODO: "mrN YYYYYY" - set memory cell at address from rN to value YYYYYY
    case _T('g'):
        if (command[1] == 0)
        {
            Emulator_Start();
        }
        else
        {
            WORD value;
            if (! ParseOctalValue(command + 1, &value))
                ConsoleView_Print(MESSAGE_WRONG_VALUE);
            else
            {
                Emulator_SetCPUBreakpoint(value);
                Emulator_Start();
            }
        }
        break;
#if !defined(PRODUCT)
    case _T('t'):
        {
            BOOL okTrace = !g_pBoard->GetTrace();
            g_pBoard->SetTrace(okTrace);
            if (okTrace)
                ConsoleView_Print(_T("  Trace is ON.\r\n"));
            else
            {
                ConsoleView_Print(_T("  Trace is OFF.\r\n"));
                DebugLogCloseFile();
            }
        }
        break;
#endif
    default:
        ConsoleView_Print(MESSAGE_UNKNOWN_COMMAND);
        break;
    }

    PrintConsolePrompt();

    if (okUpdateAllViews)
    {
        MainWindow_UpdateAllViews();
    }
}
예제 #2
0
void QConsoleView::execConsoleCommand(const QString &command)
{
    if (command.isNull() || command.isEmpty()) return;  // Nothing to do
    if (g_okEmulatorRunning) return;

    // Echo command to the log
    this->printLine(command);

    BOOL okUpdateAllViews = FALSE;  // Flag - need to update all debug views
    BOOL okUpdateMenu = FALSE;  // Flag - need to update main menu
    CProcessor* pProc = g_pBoard->GetCPU();

    // Execute the command
    if (command == _T("h"))
    {
        this->printHelp();
    }
    else if (command == _T("c"))  // Clear log
    {
        this->clear();
    }
    else if (command.startsWith(_T("r")))  // Register operations
    {
        if (command.length() == 1)  // Print all registers
        {
            for (int r = 0; r < 8; r++)
            {
                LPCTSTR name = REGISTER_NAME[r];
                WORD value = pProc->GetReg(r);
                this->printRegister(name, value);
            }
        }
        else if (command[1].toAscii() >= '0' && command[1].toAscii() <= '7')  // "r0".."r7"
        {
            int r = command[1].toAscii() - '0';
            LPCTSTR name = REGISTER_NAME[r];
            if (command.length() == 2)  // "rN" - show register N
            {
                WORD value = pProc->GetReg(r);
                this->printRegister(name, value);
            }
            else if (command[2].toAscii() == '=' || command[2].toAscii() == ' ')  // "rN=XXXXXX" - set register N to value XXXXXX
            {
                WORD value;
                if (! ParseOctalValue(command.mid(3), &value))
                    this->print(MESSAGE_WRONG_VALUE);
                else
                {
                    pProc->SetReg(r, value);
                    this->printRegister(name, value);
                    okUpdateAllViews = TRUE;
                }
            }
            else
                this->print(MESSAGE_UNKNOWN_COMMAND);
        }
        else if (command.length() >= 2 && command[1].toAscii() == 'p' && command[2].toAscii() == 's')  // "rps"
        {
            if (command.length() == 2)  // "rps" - show PSW
            {
                WORD value = pProc->GetPSW();
                this->printRegister(_T("PS"), value);
            }
            else if (command[3].toAscii() == '=' || command[3].toAscii() == ' ')  // "rps=XXXXXX" - set PSW to value XXXXXX
            {
                WORD value;
                if (! ParseOctalValue(command.mid(4), &value))
                    this->print(MESSAGE_WRONG_VALUE);
                else
                {
                    pProc->SetPSW(value);
                    this->printRegister(_T("PS"), value);
                    okUpdateAllViews = TRUE;
                }
            }
            else
                this->print(MESSAGE_UNKNOWN_COMMAND);
        }
        else
            this->print(MESSAGE_UNKNOWN_COMMAND);
    }
    else if (command == _T("s"))  // "s" - Step Into, execute one instruction
    {
        this->printDisassemble(pProc->GetPC(), TRUE, FALSE);

        //pProc->Execute();
        g_pBoard->DebugTicks();

        okUpdateAllViews = TRUE;
    }
    else if (command == _T("so"))  // "so" - Step Over
    {
        int instrLength = this->printDisassemble(pProc->GetPC(), TRUE, FALSE);
        WORD bpaddress = pProc->GetPC() + instrLength * 2;

        Emulator_SetCPUBreakpoint(bpaddress);
        Emulator_Start();

        okUpdateMenu = TRUE;
    }
    else if (command.startsWith(_T("d")) ||  // Disassemble
             command.startsWith(_T("D")))    // Disassemble, short format
    {
        BOOL okShort = (command[0] == _T('D'));
        if (command.length() == 1)  // "d" - disassemble at current address
            this->printDisassemble(pProc->GetPC(), FALSE, okShort);
        else if (command[1].toAscii() >= '0' && command[1].toAscii() <= '7')  // "dXXXXXX" - disassemble at address XXXXXX
        {
            WORD value;
            if (! ParseOctalValue(command.mid(1), &value))
                this->print(MESSAGE_WRONG_VALUE);
            else
                this->printDisassemble(value, FALSE, okShort);
        }
        else
            this->print(MESSAGE_UNKNOWN_COMMAND);
    }
    else if (command.startsWith(_T("m")))
    {
        if (command.length() == 1)  // "m" - dump memory at current address
        {
            this->printMemoryDump(pProc->GetPC(), 8);
        }
        else if (command[1].toAscii() >= '0' && command[1].toAscii() <= '7')  // "mXXXXXX" - dump memory at address XXXXXX
        {
            WORD value;
            if (! ParseOctalValue(command.mid(1), &value))
                this->print(MESSAGE_WRONG_VALUE);
            else
                this->printMemoryDump(value, 8);
        }
        else if (command[1].toAscii() == 'r' && command.length() >= 3 &&
                command[2].toAscii() >= '0' && command[2].toAscii() <= '7')  // "mrN" - dump memory at address from register N
        {
            int r = command[2].toAscii() - '0';
            WORD address = pProc->GetReg(r);
            this->printMemoryDump(address, 8);
        }
        else
            this->print(MESSAGE_UNKNOWN_COMMAND);
        //TODO: "mXXXXXX YYYYYY" - set memory cell at XXXXXX to value YYYYYY
        //TODO: "mrN YYYYYY" - set memory cell at address from rN to value YYYYYY
    }
    else if (command == _T("g"))  // Go
    {
        Emulator_Start();
        okUpdateAllViews = TRUE;
    }
    else if (command.startsWith(_T("g")))  // Go
    {
        WORD value;
        if (! ParseOctalValue(command.mid(1), &value))
            this->print(MESSAGE_WRONG_VALUE);
        else
        {
            Emulator_SetCPUBreakpoint(value);
            Emulator_Start();

            okUpdateMenu = TRUE;
        }
    }
    else
    {
        this->print(MESSAGE_UNKNOWN_COMMAND);
    }

    this->printConsolePrompt();

    if (okUpdateAllViews)
        Global_UpdateAllViews();
    else if (okUpdateMenu)
        Global_UpdateMenu();

}