Exemplo n.º 1
0
void Operation::variable_set(ScenarioRunner* sr)
{
    Parameter id = sr->getParameter();
    uint32_t value = sr->getDWORD();
    sr->setLogicVar(static_cast<uint8_t>(id.type),id.value.dword,value);
    std::cout << "VAR(" << hexString(static_cast<uint8_t>(id.type)) << ";" << hexString(id.value.dword) << ") = " << hexString(sr->getLogicVar(static_cast<uint8_t>(id.type),id.value.dword)) << std::endl;
}
Exemplo n.º 2
0
//Variable
void Operation::string_variable_set(ScenarioRunner* sr)
{
    uint32_t id = sr->getDWORD();
    Parameter value = sr->getParameter();
    sr->setStringVar(id, (value.type == p_type::STRING ? value.value.string : sr->getStringVar(value.value.dword)));
    LOG("STR_VAR(" + hexString(id) + ") = " + (value.type == p_type::STRING ? value.value.string : "VAR("+hexString(value.value.dword)+") = "+sr->getStringVar(value.value.dword)));
}
Exemplo n.º 3
0
void CtrlrMidiBufferStatus::update(const int x, const int y)
{
	size.setText(STR(owner.getDataSize()/3));

	status.setFont (statusFont);
	status.setText ("Byte: ");
	CodeDocument::Position pos = owner.getCodeEditor().getPositionAt (x,y);

	status.append (STR(pos.getPosition()/3), statusFont.boldened());
	status.append ("/"+STR(pos.getPosition()), statusFont);
	status.append (" "+currentByte(pos), statusFont);

	Range<int> sel = owner.getCodeEditor().getHighlightedRegion();
	if (!sel.isEmpty())
	{
		const int end   = sel.getEnd() / 3;
		const int start = sel.getStart() / 3;
		String selection = owner.getCodeEditor().getTextInRange (Range<int> (sel.getStart(),sel.getEnd())).trim();

		status.append (" Selected("+STR((end - start)+1)+"): ", statusFont);
		status.append (STR(start), statusFont.boldened());
		status.append (" - ", statusFont);
		status.append (STR(end), statusFont.boldened());
		status.append (" "+hexString(selection), statusFont);
	}

	repaint();
}
Exemplo n.º 4
0
const String CtrlrMidiBufferStatus::currentByte(const CodeDocument::Position &pos)
{
	const String current 	= owner.getCodeEditor().getTextInRange(Range<int>(pos.getPosition(), pos.getPosition()+1));
	const String next 		= owner.getCodeEditor().getTextInRange(Range<int>(pos.getPosition()+1, pos.getPosition()+2));
	const String previous 	= owner.getCodeEditor().getTextInRange(Range<int>(pos.getPosition()-1, pos.getPosition()));
	String byte;
	String ret;

	if (next.trim().isEmpty())
	{
        byte << previous << current;
	}

	if (previous.trim().isEmpty())
	{
		byte << current << next;
	}

	if (!byte.isEmpty())
	{
		return (hexString(byte));
	}

	return (String::empty);
}
Exemplo n.º 5
0
bool ledPresets::saveXML() {
    printf("SAVING XML: %s", xmlName.c_str() );
//    XML.addTag("PRESETS");
//    XML.pushTag("PRESETS");
    unsigned int ct = 0;
    ofxXmlSettings TMP;
    
    for (int i=0; i<presetsNum; i++){
//        XML.addTag("PRESET");
//        XML.pushTag("PRESET", i);
//        XML.addTag("GENERATORS");
//        XML.pushTag("GENERATORS");

        for (int j=0; j<4; j++){
            int lastTagNumber = TMP.addTag("GENERATOR");
//            XML.pushTag("GENERATOR", lastTagNumber);
            if (presets[i].is_active) {
                TMP.setValue("GENERATOR:att", presets[i].generators[j].att, lastTagNumber);
                TMP.setValue("GENERATOR:dec", presets[i].generators[j].dec, lastTagNumber);
                TMP.setValue("GENERATOR:rel", presets[i].generators[j].rel, lastTagNumber);
                TMP.setValue("GENERATOR:quant", (int)presets[i].generators[j].quant, lastTagNumber);
                TMP.setValue("GENERATOR:isActive", 1, lastTagNumber);
                string strmat((char *) presets[i].generators[j].matrix, ledsW*ledsH*3);
                printf("strmat = %s\n", strmat.c_str());
                TMP.setValue("GENERATOR:bitmap", strmat, lastTagNumber);
//                TMP.setValue(
                string strseq = hexString(presets[i].generators[j].sequence, 16*3);
                printf("\nSEQ = ");
                for (int z=0; z<16*3; z++) printf("%02X", presets[i].generators[j].sequence[i]);
                printf("\nstrseq = %s\n", strseq.c_str());
                TMP.setValue("GENERATOR:seq", strseq, lastTagNumber);
            } else {
                TMP.setValue("GENERATOR:att", 0, lastTagNumber);
                TMP.setValue("GENERATOR:dec", 0, lastTagNumber);
                TMP.setValue("GENERATOR:rel", 0, lastTagNumber);
                TMP.setValue("GENERATOR:quant", 0, lastTagNumber);
            }
            printf("GEN %d\n", lastTagNumber);
            ct++;
            TMP.popTag();
        }
//        XML.popTag();
//        XML.popTag();
//        XML.popTag();  
    }
//    XML.popTag();
    
    TMP.saveFile(xmlName);
    
    return true;
}
void ZLStatisticsXMLReader::startElementHandler(const char *tag, const char **attributes) {
	if (STATISTICS_TAG == tag) {
		size_t volume = atoi(attributeValue(attributes, "volume"));
		unsigned long long squaresVolume = atoll(attributeValue(attributes, "squaresVolume"));
		//std::cerr << "XMLReader: frequencies sum & ^2: " << volume << ":" << squaresVolume << "\n";
		myStatisticsPtr = new ZLArrayBasedStatistics( atoi(attributeValue(attributes, "charSequenceSize")), atoi(attributeValue(attributes, "size")), volume, squaresVolume);
	} else if (ITEM_TAG == tag) {
		const char *sequence = attributeValue(attributes, "sequence");
		const char *frequency = attributeValue(attributes, "frequency");
		if ((sequence != 0) && (frequency != 0)) {
			std::string hexString(sequence);
			myStatisticsPtr->insert(ZLCharSequence(hexString), atoi(frequency));
		}
	}
}
Exemplo n.º 7
0
void Operation::jump_conditinal(ScenarioRunner* sr)
{
    bool verbose = !!sr->getResourceManager()->getConfigVar("DEBUGGER.VERBOSE_CONDITINAL_JUMP", 0);
    Parameter a = sr->getParameter();
    uint32_t opr = sr->getDWORD(), b = sr->getDWORD();bool cond=false;
    if (verbose) std::cout << sr->getLogicVar(static_cast<uint8_t>(a.type), a.value.dword) << "(VAR " << hexString(static_cast<uint8_t>(a.type)) << ";" << hexString(a.value.dword) << ") ";
    switch (opr)
    {
        case 0x0: //!=
            if (verbose) std::cout << "!=";
            cond = (sr->getLogicVar(static_cast<uint8_t>(a.type), a.value.dword) != b);
            break;
        case 0x1: //<=
            if (verbose) std::cout << "<=";
            cond = (sr->getLogicVar(static_cast<uint8_t>(a.type), a.value.dword) <= b);
            break;
        case 0x2: //>=
            if (verbose) std::cout << ">=";
            cond = (sr->getLogicVar(static_cast<uint8_t>(a.type), a.value.dword) >= b);
            break;
        case 0x3: //<
            if (verbose) std::cout << "<";
            cond = (sr->getLogicVar(static_cast<uint8_t>(a.type), a.value.dword) < b);
            break;
        case 0x4: //>
            std::cout << ">";
            cond = (sr->getLogicVar(static_cast<uint8_t>(a.type),a.value.dword) > b);
            break;
        case 0x5: //=
            if (verbose) std::cout << "=";
            cond = (sr->getLogicVar(static_cast<uint8_t>(a.type), a.value.dword) == b);
            break;
        default:
            if (!sr->exitRequested())
            {
                 ERROR("Unknown Jump Code: "+std::to_string(opr));
            }
            else { return; }
    };
    if (verbose) std::cout << " " << hexString(b) << std::endl;
    if (cond || sr->getResourceManager()->getConfigVar("ASSERT.JUMP_"+sr->getCurrentScenario()->name+"_"+hexString(static_cast<uint8_t>(a.type))+"."+hexString(a.value.dword)+"_"+hexString(opr)+"_"+hexString(b),0)) {Operation::jump(sr); } else { sr->getDWORD(); };
    if (verbose) std::cout << (cond || sr->getResourceManager()->getConfigVar("ASSERT.JUMP_" + sr->getCurrentScenario()->name + "_" + hexString(static_cast<uint8_t>(a.type)) + "." + hexString(a.value.dword) + "_" + hexString(opr) + "_" + hexString(b), 0) ? "Jumped" : "Didn't jump") << std::endl;
}
Exemplo n.º 8
0
Parameter ScenarioRunner::getParameter()
{
    Parameter p;
    if (terminated) return p; //Don't get parameter if termination was requested
    p.type = *reinterpret_cast<p_type*>(&buffer[pc++]);
    switch (p.type)
    {
        case p_type::STRING:
        {
            uint16_t str_size = *reinterpret_cast<uint16_t*>(&buffer[pc]);
            for (uint16_t i = 0;i < str_size;i++)
            {
                if (buffer[pc+2+i] == '\0')
                    {p.value.string.resize(i);break;}
                else
                {p.value.string += buffer[pc+2+i];}
            }
            pc+=2+str_size;
            p.value.string = toUTF8(p.value.string);
            std::cout << "\"" << p.value.string << "\"" << "; ";
        }
        break;
        case p_type::DWORD_0:
        case p_type::DWORD_3:
        case p_type::DWORD_5:
        case p_type::DWORD_6:
            p.value.dword = *reinterpret_cast<uint32_t*>(&buffer[pc]);
            std::cout << p.value.dword << "; ";
            pc+=4;
            break;
        case p_type::ADDR:
            p.value.dword = *reinterpret_cast<uint32_t*>(&buffer[pc]);
            std::cout << "(ADDR)" << hexString(p.value.dword) << "; ";
            pc+=4;
            break;
            default:
            ERROR("Unknown Parametercode; This indicates a parsing error");
            break;
    }
    if (debuggingEnabled()) debugger->onParameter(p);
    return p;
}
Exemplo n.º 9
0
void IntlTestCollator::backAndForth(CollationElementIterator &iter)
{
    // Run through the iterator forwards and stick it into an array
    int32_t orderLength = 0;
    LocalArray<Order> orders(getOrders(iter, orderLength));
    UErrorCode status = U_ZERO_ERROR;

    // Now go through it backwards and make sure we get the same values
    int32_t index = orderLength;
    int32_t o;

    // reset the iterator
    iter.reset();

    while ((o = iter.previous(status)) != CollationElementIterator::NULLORDER)
    {
        /*int32_t offset = */iter.getOffset();

        if (index == 0) {
          if(o == 0) {
            continue;
          } else { // this is an error, orders exhausted but there are non-ignorable CEs from
            // going backwards
            errln("Backward iteration returned a non ignorable after orders are exhausted");
            break;
          }
        }

        index -= 1;
        if (o != orders[index].order) {
            if (o == 0)
                index += 1;
            else {
                while (index > 0 && orders[--index].order == 0) {
                  // nothing...
                }

                if (o != orders[index].order) {
                    errln("Mismatched order at index %d: 0x%0:8X vs. 0x%0:8X", index,
                    orders[index].order, o);
                //break;
                  return;
                }
            }
        }

#if TEST_OFFSETS
        if (offset != orders[index].offset) {
          errln("Mismatched offset at index %d: %d vs. %d", index,
            orders[index].offset, offset);
       //break;
         return;
        }
#endif

    }

    while (index != 0 && orders[index - 1].order == 0)
    {
      index --;
    }

    if (index != 0)
    {
        UnicodeString msg("Didn't get back to beginning - index is ");
        errln(msg + index);

        iter.reset();
        err("next: ");
        while ((o = iter.next(status)) != CollationElementIterator::NULLORDER)
        {
            UnicodeString hexString("0x");

            appendHex(o, 8, hexString);
            hexString += " ";
            err(hexString);
        }
        errln("");

        err("prev: ");
        while ((o = iter.previous(status)) != CollationElementIterator::NULLORDER)
        {
            UnicodeString hexString("0x");

            appendHex(o, 8, hexString);
            hexString += " ";
             err(hexString);
        }
        errln("");
    }
}
Exemplo n.º 10
0
void hexString::operator -= (const char Right[]){
	intValue -= hexString(Right).toInt();
	setHexValue();
}
Exemplo n.º 11
0
bool operator >= ( hexString Left,  std::string Right){return (Left.toInt() >= hexString(Right).toInt());}
Exemplo n.º 12
0
uint32_t ScenarioRunner::getLogicVar(uint8_t scope,uint32_t key)
{
    if (exitRequested()) return 0;
    if (scope != 0x03 && scope != 0x06) ERROR("Invalid scope "+std::to_string(scope));
    return reg_logic[hexString(scope)+":"+hexString(key)];
}
Exemplo n.º 13
0
ScenarioRunner::ScenarioRunner(std::string path, bool force_debug) : file(path)
{
    uint32_t hs_files,hs_total,ss_size;
    hs_files=0;
    hs_total=0;

    fsize = bintools::filesize(path);
    buffer = new char[static_cast<uint32_t>(fsize)];
    file.read(buffer, static_cast<uint32_t>(fsize));
    if (fsize < 0x14) //Filesize check (Static header contents)
    ERROR("File to small");

    //Check Signature
    if (*reinterpret_cast<uint32_t*>(&buffer[0x0]) != 0x204C5348) ERROR("Invalid signature: "+hexString(*reinterpret_cast<uint32_t*>(&buffer[0x4])));

    //Check Version
    if (*reinterpret_cast<uint16_t*>(&buffer[0x4]) != 0x64) ERROR("Invalid version");

    hs_files = *reinterpret_cast<uint32_t*>(&buffer[0xA]); //Read filename header size
    hs_total = *reinterpret_cast<uint32_t*>(&buffer[0xE]); 	//Read total header size
    ss_size = *reinterpret_cast<uint16_t*>(&buffer[0x12]); //Read start scenario name

    if (hs_files > hs_total)
        ERROR("Value error (hs_files > hs_total)");
    if (fsize < hs_total)
        ERROR("File to small (fsize < hs_total)");

    if (fsize < 0x18+ss_size) //Filesize check
        ERROR("File to small (fsize < 0x18+ss_size)");

    //Read start scenario name
    for (uint32_t i = 0;i < ss_size;i++)
    {
        if (buffer[0x14+i] == '\0')
            {ss_name.resize(i);break;}
        else
            {ss_name += buffer[0x14+i];}
    }

    //Read scenario count
    uint32_t s_count = *reinterpret_cast<uint32_t*>(&buffer[0x14+ss_size]); 	//Read scenario count

    pc = 0x18+ss_size;

    if (fsize < pc+s_count*2)
        ERROR("File to small (fsize < pc+s_count)");
    //Read scenario names
    for (uint32_t i=0;i < s_count;i++)
    {
        Scenario s;

        uint16_t size = *reinterpret_cast<uint16_t*>(&buffer[pc]); //Read scenario name

        for (int j = 0;j < size;j++)
        {
            if (buffer[pc+2+j] == '\0')
                {s.name.resize(j);break;}
            else
                {s.name += buffer[pc+2+j];}
        }

        s.offset = *reinterpret_cast<uint32_t*>(&buffer[hs_files+i*4]); //Read scenario offset

        scenarios.push_back(s);
        pc+=2+size;
    }

    LOG("Loaded "+path)

    //Initalize components
    r_manager = new ResourceManager(this);
    this->debug = r_manager->getConfigVar("DEBUGGER.ENABLE") || force_debug;
    debugger = new Debugger(this);
    audio = new Audio(this);
}
Exemplo n.º 14
0
bool operator != ( hexString Left,  const char Right[]){return (Left.toInt() != hexString(Right).toInt());}
Exemplo n.º 15
0
hexString operator - (const char * Left, const hexString Right){
	hexString RetVal;
	RetVal.intValue = hexString(Left).toInt() - Right.intValue;
	return RetVal;
}
Exemplo n.º 16
0
hexString operator - (const hexString Left, const unsigned long long int Right){
	hexString RetVal;
	RetVal.intValue = hexString(Left).toInt() - Right;
	return RetVal;
}
Exemplo n.º 17
0
hexString operator + (const hexString Left,  const char * Right){
	hexString RetVal;
	RetVal.intValue = hexString(Left).toInt() + hexString(Right).toInt();
	return RetVal;
}
Exemplo n.º 18
0
hexString operator + (const hexString Left, const hexString Right){
	hexString RetVal;
	RetVal.intValue = hexString(Left).toInt() + Right.intValue;
	return RetVal;
}
Exemplo n.º 19
0
bool operator != ( const char Left[],  hexString Right){return (hexString(Left).toInt() != Right.toInt());}
Exemplo n.º 20
0
void hexString::operator -= (const std::string Right){
	intValue -= hexString(Right).toInt();
	setHexValue();
}
Exemplo n.º 21
0
void ScenarioRunner::run()
{
    Scenario scenario;
    for (Scenario s : scenarios) if (s.name == ss_name) scenario = s;
    if (scenario.name=="")
        ERROR("Couldn't find start scenario '"+ss_name+"'");

    c_scenario = scenario;

    //List of operations
    std::map<uint16_t,void(*)(ScenarioRunner* sr)> opcodes =
    {
        {0x0001,Operation::jump},
        {0x0003,Operation::opcode_0003},
        {0x0005,Operation::jump_conditinal},
        {0x0080,Operation::message_show},
        {0x0081,Operation::archive_graphics},
        {0x0082,Operation::archive_music},
        {0x0083,Operation::archive_sound},
        {0x0084,Operation::scale_down},
        {0x0085,Operation::window_init},
        {0x0086,Operation::window_icon},
        {0x0087,Operation::window_title},
        {0x0088,Operation::scenario_title_set},
        {0x0089,Operation::messagebox_init},
        {0x008A,Operation::messagebox_bounds_init},
        {0x008B,Operation::choicebox_init},
        {0x008E,Operation::namebox_init},
        {0x008F,Operation::namebox_bounds_init},
        {0x0090,Operation::choicebox_on_init},
        {0x0098,Operation::string_variable_set},
        {0x0096,Operation::variable_set},
        {0x0099,Operation::variable_add},
        {0x009C,Operation::variable_sub},
        {0x009E,Operation::variable_mul},
        {0x00A0,Operation::variable_dev},
        {0x00A2,Operation::variable_mod},
        {0x00A3,Operation::scenario_enter},
        {0x00C8,Operation::layer_set},
        {0x00C9,Operation::layer_remove},
        {0x00CA,Operation::layer_flush},
        {0x00D4,Operation::layer_shake},
        {0x00FA,Operation::play_bgm},
        {0x00FB,Operation::stop_bgm},
        {0x00FC,Operation::play_uncategorized},
        {0x00FE,Operation::play_sfx},
        {0x0107,Operation::message_clear},
        {0x0104,Operation::message_hide},
        {0x0109,Operation::avatar_set},
        {0x010A,Operation::avatar_remove},
        {0x0111,Operation::choice_add},
        {0x0112,Operation::choices_show},
        {0x012F,Operation::sleep},
        {0x0131,Operation::sgf_load},
        {0x0132,Operation::sgf_check_position},
        {0x0133,Operation::sgf_check_click},
        {0xFFFF,Operation::scenario_return}
    };

    //Set PC
    pc = c_scenario.offset+4;

    //Start debugger, if enabled
    if (debuggingEnabled()) debugger->onStart();

    for (;pc < c_scenario.offset+4+*reinterpret_cast<uint32_t*>(&buffer[c_scenario.offset]);)
    {
        if (terminated)
        {
            LOG("Termination requested.");
            return;
        }
        uint16_t opcode = *reinterpret_cast<uint16_t*>(&buffer[pc]);

        //Update title
        if (window != nullptr)
        {
            window->setTitle("HadakaVM | Scenario: "+c_scenario.name+(debuggingEnabled() ? "@"+hexString(pc) : "")+(window->getFastmode()?" | Fast":""));
            if (window->update().type==UpdateEventType::EXIT) Operation::exit(this);
        }

        pc+=2;

        if (debuggingEnabled()) debugger->onInstruction(opcode);

        if (opcodes.find(opcode)!=opcodes.end())
        {
            uint32_t old_pc = pc;
            opcodes[opcode](this);
            if (terminated)
            {
                LOG("Termination requested.");
                return;
            }
            if (old_pc != pc) std::cout << std::endl;
            continue;
        }

        //Stub handling
        uint16_t p_count;
        switch (opcode)
        {
            case 0x0085: case 0x00CB: case 0x0102: case 0x010A: case 0x012D: case 0x012E:
            case 0x0134: case 0x0135: case 0x0136: case 0x0137: case 0x0162: case 0xFFFF:
            case 0x0132:
                p_count = 0; break;

            case 0x0001: case 0x0081: case 0x0082: case 0x0083: case 0x0084: case 0x0086:
            case 0x0087: case 0x0088: case 0x008C: case 0x0093: case 0x0094: case 0x0095:
            case 0x00A3: case 0x00FB: case 0x00FF: case 0x0103: case 0x0112: case 0x0116:
            case 0x0127: case 0x0129: case 0x0133: case 0x0138: case 0x0161:
                p_count = 1; break;

            case 0x0002: case 0x0003: case 0x008D: case 0x0090: case 0x0096: case 0x0098:
            case 0x0099: case 0x009C: case 0x009E: case 0x00A0: case 0x00A2: case 0x00A6:
            case 0x00CA: case 0x00D6: case 0x00D9: case 0x00FA: case 0x0104: case 0x0107:
            case 0x0111: case 0x011D: case 0x0121: case 0x012F: case 0x015E: case 0x0190:
                p_count = 2; break;

            case 0x00C9: case 0x00D5: case 0x00D7: case 0x00DA: case 0x00FC: case 0x00FE:
            case 0x0109: case 0x0126: case 0x0131:
                p_count = 3; 	break;

            case 0x0004: case 0x0005: case 0x0089: case 0x008A: case 0x008E: case 0x008F:
            case 0x00A4: case 0x00D4: case 0x0110: case 0x0118: case 0x0120: case 0x0123:
            case 0x015F: case 0x0160:
                p_count = 4; break;

            case 0x0092:
                p_count = 5;	break;

            case 0x008B: case 0x0100: case 0x011C:
                p_count = 6; break;

            case 0x00C8: case 0x00D0: case 0x010E: case 0x0113: case 0x0119: case 0x011A:
            case 0x011B: case 0x0128:
                p_count = 7; break;

            case 0x011E: case 0x011F: case 0x012A: case 0x012B:
                p_count = 8; break;
            default:
                ERROR("Unimplemented Operation: "+hexString(opcode));
        };
        WARN("Stub Operation: "+hexString(opcode)+"; Length = "+hexString(p_count));
        for (uint16_t i=0;i < p_count;i++)
        {
            getParameter();
        }
        if (p_count > 0) std::cout << std::endl;
    }
    if (c_scenario.name == ss_name)
        ERROR("Reached end of start scenario, this shouldn't happen :/");
}
Exemplo n.º 22
0
hexString operator - (const hexString Left, const std::string Right){
	hexString RetVal;
	RetVal.intValue = hexString(Left).toInt() - hexString(Right).toInt();
	return RetVal;
}
Exemplo n.º 23
0
bool operator >= ( std::string Left,  hexString Right){return (hexString(Left).toInt() >= Right.toInt());}