Ejemplo n.º 1
0
void execute()
{
    string command = currentInstruction[0];
    if (command == "add" || command == "sub" || command == "neg" || command == "eq" || command == "gt" ||
        command == "lt" || command == "and" || command == "or" || command == "not")
        executeArithmetic(currentInstruction[0]);
    else if (command == "push")
        executePush(currentInstruction[1], atoi(currentInstruction[2].c_str()));
    else if (command == "pop")
        executePop(currentInstruction[1], atoi(currentInstruction[2].c_str()));
    else if (command == "label")
        executeLabel(currentInstruction[1]);
    else if (command == "goto")
        executeGoto(currentInstruction[1]);
    else if (command == "if-goto")
        executeIf(currentInstruction[1]);
    else if (command == "call")
        executeCall(currentInstruction[1], atoi(currentInstruction[2].c_str()));
    else if (command == "return")
        executeReturn();
    else if (command == "function")
        executeFunction(currentInstruction[1], atoi(currentInstruction[2].c_str()));
    else if (command == "end")
        arriveEnd = true;
}
void PonscripterLabel::timerEvent(void)
{
    timerEventTop:

    int ret;

    if (event_mode & WAIT_TIMER_MODE) {
        int duration = proceedAnimation();

        if (duration == 0
            || (remaining_time >= 0
                && remaining_time - duration <= 0)) {
            bool end_flag  = true;
            bool loop_flag = false;
            if (remaining_time >= 0) {
                remaining_time = -1;
                if (event_mode & WAIT_VOICE_MODE && wave_sample[0]) {
                    end_flag = false;
                    if (duration > 0) {
                        resetRemainingTime(duration);
                        advancePhase(duration);
                    }
                }
                else {
                    loop_flag = true;
                    if (automode_flag || autoclick_time > 0)
                        current_button_state.button = 0;
                    else if (usewheel_flag)
                        current_button_state.button = -5;
                    else
                        current_button_state.button = -2;
                }
            }

            if (end_flag
                && event_mode & (WAIT_INPUT_MODE | WAIT_BUTTON_MODE)
                && (clickstr_state == CLICK_WAIT
                    || clickstr_state == CLICK_NEWPAGE)) {
                playClickVoice();
                stopAnimation(clickstr_state);
            }

            if (end_flag || duration == 0)
                event_mode &= ~WAIT_TIMER_MODE;

            if (loop_flag) goto timerEventTop;
        }
        else {
            if (remaining_time > 0)
                remaining_time -= duration;

            resetRemainingTime(duration);
            advancePhase(duration);
        }
    }
    else if (event_mode & EFFECT_EVENT_MODE) {
        const char* current = script_h.getCurrent();
        ret = this->parseLine();

        if (ret & RET_CONTINUE) {
            if (ret == RET_CONTINUE) {
                readToken(); // skip trailing \0 and mark kidoku
            }

            if (effect_blank == 0 || effect_counter == 0) goto timerEventTop;

            startTimer(effect_blank);
        }
        else {
            script_h.setCurrent(current);
            readToken();
            advancePhase();
        }

        return;
    }
    else {
        if (system_menu_mode != SYSTEM_NULL
            || (event_mode & WAIT_INPUT_MODE
                && volatile_button_state.button == -1)) {
            if (!system_menu_enter_flag)
                event_mode |= WAIT_TIMER_MODE;

            executeSystemCall();
        }
        else
            executeLabel();
    }

    volatile_button_state.button = 0;
}