Beispiel #1
0
SCRIPTCALL Script::parse()
{
	parse_level++;
	PRINT("[Script::parse()] parse_level = %d -> %d\n", (parse_level - 1), parse_level);

	SCRIPTCALL condition = RETURN_NORMAL;
	while (condition == RETURN_NORMAL) {
		//HACK: take screenshot
		if (input->isCapture()) {
			video->capture();
		}

		//TODO: improve this
		//TODO: debugmode
		animation->show();
		if (input->refresh() == false) {
			condition = RETURN_EXIT;
			break;
		}

		for (int i = 0; i < FRAME_RATE; i++) {
			animation->show();
		}

		video->overlapScreen();

		word reload = memory->b_SystemVariable->queryWord(iwf_Parser_Reload);
		if (reload > 0) {
			PRINT("[Script::parse()] reload\n");

			reload--;
			if (reload > 0) {
				reload = 0;

				word script_offset = memory->b_SystemVariable->queryWord(iwpo_Script);
				MemoryBlock *b_Script = memory->s_Core->get(&script_offset);

				file->open(memory->b_ScriptName->queryString(memory->script_name_entry, SCRIPT_NAME_SIZE));
				file->load(b_Script, script_offset);
				file->close();
			}

			memory->b_SystemVariable->writeWord(iwf_Parser_Reload, reload);
		}

		//TODO: check input disabled status

		byte code = fetch();
		//PRINT("[Script::parse()] code = %2x, offset = %x\n", code, getOffset());
		if (code == 0x00 || code == 0x02) {
			advance();
			condition = RETURN_SUCCESS;
		}
		else if (code == 0x01) {
			word offset = getOffset();
			condition = parseNested();
			setOffset(offset);
			skipScriptBlock();
		}
		else if (code == 0x04) {
			advance();
			code = fetchAdvance();

			code = code - 0x10;
			condition = excuteOpcodeOp4(code);
		}
		else if (code == 0x06) {
			dialogue->putHalfWidthCharacters();
		}
		else if (code > 0x09 && code < 0x20) {
			advance();

			code = code - 0x0A;
			condition = excuteOpcodeOp(code);
		}
		else if (code >= 0x60 && code <= 0x7F) {
			dialogue->putStandardText();
		}
		else if (code >= 0x80) {
			dialogue->putPredefinedText();
		}
		else {
			PRINT_ERROR("[Script::parse()] invalid opcode = %2x, offset = %x\n", code, getOffset());
			condition = RETURN_ERROR;
			break;
		}
	}

	if (condition != RETURN_ERROR) {
		parse_level--;
		PRINT("[Script::parse()] parse_level = %d -> %d, return condition = %x, offset = %x\n", (parse_level + 1), parse_level, condition, getOffset());

		return condition;
	}
	else {
		parse_level--;
		PRINT_ERROR("[Script::parse()] exit with error: parse_level = %d, offset = %x\n", parse_level, getOffset());
		return RETURN_ERROR;
	}
}
SCRIPTCALL Script::op4_displaySelection()
{
	parameter = getParameter();
	if (parameter->getType(0) == PARAMETER_TYPE_BLOCK) {
		memory->b_Procedure->writeWord(iwpo_Selection_List, parameter->get(0));
	}
	else {
		word procedure_index = parameter->get(0) * 2;
		word procedure_offset = memory->b_Procedure->queryWord(procedure_index);
		memory->b_Procedure->writeWord(iwpo_Selection_List, procedure_offset);
	}
	deleteParameter();

	memory->b_SystemVariable->writeWord(iwf_Selection_InUse, INUSE_TRUE);

	word script_offset = getOffset();

	SCRIPTCALL condition = RETURN_NORMAL;

	setOffset(memory->b_Procedure->queryWord(iwpo_Selection_ShowMenu));
	condition = parseNested();
	if ((condition == RETURN_EXIT) || (condition == RETURN_ERROR)) {
		return condition;
	}

	while (true) {
		//TODO: debugmode
		animation->show();
		if (input->refresh() == false) {
			break;
		}

		if (memory->b_SystemVariable->queryWord(iwf_Selection_InUse) == INUSE_FALSE) {
			setOffset(script_offset);
			break;
		}

		setOffset(memory->b_Procedure->queryWord(iwpo_Selection_CheckPosition));
		condition = parseNested();
		if ((condition == RETURN_EXIT) || (condition == RETURN_ERROR)) {
			return condition;
		}

		if (memory->b_SystemVariable->testByte(ibf_Selection_Status, STATUS_OK) && input->check(INPUT_OK)) {
			setOffset(memory->b_Procedure->queryWord(iwpo_Selection_OK));
			condition = parseNested();
			if ((condition == RETURN_EXIT) || (condition == RETURN_ERROR)) {
				return condition;
			}

			if (memory->b_SystemVariable->testByte(ibf_Selection_Status, STATUS_RELEASED) == false) {
				while (input->check(INPUT_OK)) {
					//TODO: debugmode
					animation->show();
					input->refresh();
				}
			}
		}
		else if (memory->b_SystemVariable->testByte(ibf_Selection_Status, STATUS_CANCEL) && input->check(INPUT_CANCEL)) {
			setOffset(memory->b_Procedure->queryWord(iwpo_Selection_Cancel));
			condition = parseNested();
			if ((condition == RETURN_EXIT) || (condition == RETURN_ERROR)) {
				return condition;
			}

			if (memory->b_SystemVariable->testByte(ibf_Selection_Status, STATUS_RELEASED) == false) {
				while (input->check(INPUT_CANCEL)) {
					//TODO: debugmode
					animation->show();
					input->refresh();
				}
			}
		}
		else if (memory->b_SystemVariable->testByte(ibf_Selection_Status, STATUS_UP) && input->check(INPUT_UP)) {
			setOffset(memory->b_Procedure->queryWord(iwpo_Selection_Up));
			condition = parseNested();
			if ((condition == RETURN_EXIT) || (condition == RETURN_ERROR)) {
				return condition;
			}

			if (memory->b_SystemVariable->testByte(ibf_Selection_Status, STATUS_RELEASED) == false) {
				while (input->check(INPUT_UP)) {
					//TODO: debugmode
					animation->show();
					input->refresh();
				}
			}
		}
		else if (memory->b_SystemVariable->testByte(ibf_Selection_Status, STATUS_DOWN) && input->check(INPUT_DOWN)) {
			setOffset(memory->b_Procedure->queryWord(iwpo_Selection_Down));
			condition = parseNested();
			if ((condition == RETURN_EXIT) || (condition == RETURN_ERROR)) {
				return condition;
			}

			if (memory->b_SystemVariable->testByte(ibf_Selection_Status, STATUS_RELEASED) == false) {
				while (input->check(INPUT_DOWN)) {
					//TODO: debugmode
					animation->show();
					input->refresh();
				}
			}
		}
		else if (memory->b_SystemVariable->testByte(ibf_Selection_Status, STATUS_LEFT) && input->check(INPUT_LEFT)) {
			setOffset(memory->b_Procedure->queryWord(iwpo_Selection_Left));
			condition = parseNested();
			if ((condition == RETURN_EXIT) || (condition == RETURN_ERROR)) {
				return condition;
			}

			if (memory->b_SystemVariable->testByte(ibf_Selection_Status, STATUS_RELEASED) == false) {
				while (input->check(INPUT_LEFT)) {
					//TODO: debugmode
					animation->show();
					input->refresh();
				}
			}
		}
		else if (memory->b_SystemVariable->testByte(ibf_Selection_Status, STATUS_RIGHT) && input->check(INPUT_RIGHT)) {
			setOffset(memory->b_Procedure->queryWord(iwpo_Selection_Right));
			condition = parseNested();
			if ((condition == RETURN_EXIT) || (condition == RETURN_ERROR)) {
				return condition;
			}

			if (memory->b_SystemVariable->testByte(ibf_Selection_Status, STATUS_RELEASED) == false) {
				while (input->check(INPUT_RIGHT)) {
					//TODO: debugmode
					animation->show();
					input->refresh();
				}
			}
		}

		//timer->delay();
	}

	return RETURN_NORMAL;
}