Example #1
0
static int on26_test_port( PIA *pi)  /* hard reset */

{       int     i, m, d, x, y;

        pi->saved_r0 = r0();
        pi->saved_r2 = r2();

        d = pi->delay;
        m = pi->mode;
        pi->delay = 5;
        pi->mode = 0;

        w2(0xc);

        CCP(0x30); CCP(0); 

        w0(0xfe);w0(0xaa);w0(0x55);w0(0);w0(0xff);
        i = ((r1() & 0xf0) << 4); w0(0x87);
        i |= (r1() & 0xf0); w0(0x78);
        w0(0x20);w2(4);w2(5);
        i |= ((r1() & 0xf0) >> 4);
        w2(4);w0(0xff);

        if (i == 0xb5f) {

            w0(2); P1; w0(0);   P2;
            w0(3); P1; w0(0);   P2;
            w0(2); P1; w0(8);   P2; udelay(100);
            w0(2); P1; w0(0xa); P2; udelay(100);
            w0(2); P1; w0(8);   P2; udelay(1000);
            
            on26_write_regr(pi,0,6,0xa0);

            for (i=0;i<RESET_WAIT;i++) {
                on26_write_regr(pi,0,6,0xa0);
                x = on26_read_regr(pi,0,7);
                on26_write_regr(pi,0,6,0xb0);
                y = on26_read_regr(pi,0,7);
                if (!((x&0x80)||(y&0x80))) break;
                udelay(100000);
            }

	    if (i == RESET_WAIT) 
		printk("on26: Device reset failed (%x,%x)\n",x,y);

            w0(4); P1; w0(4); P1;
        }

        CCP(0x30);

        pi->delay = d;
        pi->mode = m;
        w0(pi->saved_r0);
        w2(pi->saved_r2);

        return 5;
}
Example #2
0
static void epat_connect ( PIA *pi )

{       pi->saved_r0 = r0();
        pi->saved_r2 = r2();
	CCP(0); CCP(0xe0);
	w0(0); w2(1); w2(4);
	if (pi->mode >= 3) {
		w0(0); w2(1); w2(4); w2(0xc);
		w0(0x40); w2(6); w2(7); w2(4); w2(0xc); w2(4);
	}
	WR(8,0x10); WR(0xc,0x14); WR(0xa,0x38); WR(0x12,0x10);
}
Example #3
0
/** context sensitive completion
 *  take current line, give list of completions (both atoms and files)
 *  thanks to Jan for crafting a proper interface wrapping SWI-Prolog available facilities
 */
QString Completion::initialize(int promptPosition, QTextCursor c, QStringList &strings) {

    SwiPrologEngine::in_thread _int;
    QString rets;

    try {
        int p = c.position();
        Q_ASSERT(p >= promptPosition);

        c.setPosition(promptPosition, c.KeepAnchor);
        QString left = c.selectedText();
        PlString Before(left.toStdWString().data());

        c.setPosition(p);
        c.movePosition(c.EndOfLine, c.KeepAnchor);
        QString after = c.selectedText();
        PlString After(after.toStdWString().data());

        PlTerm Completions, Delete, word;
        if (PlCall("prolog", "complete_input", PlTermv(Before, After, Delete, Completions)))
            for (PlTail l(Completions); l.next(word); )
                strings.append(t2w(word));

        c.setPosition(p);
        rets = t2w(Delete);
    }
    catch(PlException e) {
        qDebug() << CCP(e);
    }
    catch(...) {
        qDebug() << "SIGV";
    }

    return rets;
}
Example #4
0
static void k971_connect ( PIA *pi  )

{   pi->saved_r0 = r0();
    pi->saved_r2 = r2();
    CCP(0x20);
    w2(4);
}
Example #5
0
static void on26_disconnect ( PIA *pi )

{       if (pi->mode >= 2) { w3(4); w3(4); w3(4); w3(4); }
	              else { w0(4); P1; w0(4); P1; }
	CCP(0x30);
        w0(pi->saved_r0);
        w2(pi->saved_r2);
} 
/** issue a query filling the model storage
 *  this will change when I will learn how to call SWI-Prolog completion interface
 */
void Completion::initialize(QStringList &strings) {

    SwiPrologEngine::in_thread _int;
    try {
        PlTerm p,m,a,l,v;
        PlQuery q("setof",
            PlTermv(p,
                quv(m,
                    quv(a,
                        join(PlCompound("current_predicate", mod(m, arith(p, a))),
                            neg(C("sub_atom", PlTermv(p, zero, one, _V, A("$"))))
                ))),
            l));
        if (q.next_solution())
            for (PlTail x(l); x.next(v); )
                strings.append(CCP(v));
    }
    catch(PlException e) {
        qDebug() << CCP(e);
    }
}
Example #7
0
static int chgprop(Term t, IntlogExec* p, DbEntry::scopemode sc, CCP idbt)
{
	ArgIdArityList i(t, p, idbt);

	while (i.next())
		if (!p->get_db()->ChangeEntryProperty(i.funct, i.arity, sc)) {
			p->BtErr(BTERR_CANT_IMPORT, CCP(i.funct));
			break;
		}

	return i.status;
}
Example #8
0
static void on26_connect ( PIA *pi )

{       int	x;

	pi->saved_r0 = r0();
        pi->saved_r2 = r2();

        CCP(0x20);
	x = 8; if (pi->mode) x = 9;

	w0(2); P1; w0(8); P2;
	w0(2); P1; w0(x); P2;
}
Example #9
0
void EngineObj::show(ostream &s) const
{
	IntlogExec *eng = all_engines->HtoD(handler);

	if (eng) {
		s << '$' << handler << ':';
		DbIntlog *db = eng->get_db();

		kstring dbid = db->GetId();
		if (unsigned(dbid) != MSR_NULL)
			s << CCP(dbid);

		s << ':';
		DbInherIter ii(db);
		while ((db = ii.next()) != 0) {
			dbid = db->GetId();
			if (unsigned(dbid) != MSR_NULL)
				s << CCP(dbid);
			s << ':';
		}
	} else
		s << '~' << handler;
}
Example #10
0
///////////////////////////////////////////////
// i_inherit(i_name*) (+)
//	store references to inherited interfaces
//
BtFImpl(i_inherit, t, p)
{
	ArgIdArityList i(t.getarg(0), p, "i_inherit");

	while (i.next()) {
		DbIntlog *dbi = findint(p->get_db(), i.funct);
		if (!dbi || !p->get_db()->InheritInterface(dbi)) {
			p->BtErr(BTERR_CANT_INHERIT, CCP(i.funct));
			break;
		}
	}

	return i.status;
}
Example #11
0
/////////////////////////////////////////
// i_begin(i_name) (+)
//	insert i_name as local to current DB
//	push empty DB(i_name)
//
BtFImpl(i_begin, a, p)
{
	Term t;
	if (!(t = p->eval_term(a.getarg(0))).type(f_ATOM)) {
		p->BtErr(BTERR_INVALID_ARG_TYPE);
		return 0;
	}

	DbIntlog *db = p->get_db();
	kstring idi = t.kstr();
	if ((db = db->BeginInterface(idi)) == 0) {
		p->BtErr(BTERR_CANT_BEGINTERF, CCP(idi));
		return 0;
	}

	p->set_db(db);
	return 1;
}
Example #12
0
/** initialize and cache all predicates with description
 */
bool Completion::helpidx() {
    if (helpidx_status == untried) {
        helpidx_status = missing;
        SwiPrologEngine::in_thread _e;
        try {
            if (    PlCall("load_files(library(helpidx), [silent(true)])") &&
                    PlCall("current_module(help_index)"))
            {
                {   PlTerm Name, Arity, Descr, Start, Stop;
                    PlQuery q("help_index", "predicate", V(Name, Arity, Descr, Start, Stop));
                    while (q.next_solution()) {
                        long arity = Arity.type() == PL_INTEGER ? long(Arity) : -1;
                        QString name = t2w(Name);
                        t_pred_docs::iterator x = pred_docs.find(name);
                        if (x == pred_docs.end())
                            x = pred_docs.insert(name, t_decls());
                        x.value().append(qMakePair(int(arity), t2w(Descr)));
                    }
                }

                if (PlCall("load_files(library(console_input), [silent(true)])"))
                    if (PlCall("current_module(prolog_console_input)"))
                        helpidx_status = available;
            }

            /*
            if (!PlCall("current_module(prolog_console_input)")) {
                QString ci = "console_input.pl";
                QFile f(QString(":/%1").arg(ci));
                if (f.open(f.ReadOnly)) {
                    QTextStream s(&f);
                    if (!_e.named_load(ci, s.readAll()))
                        qDebug() << "can't load" << ci;
                }
            }
            */
        }
        catch(PlException e) {
            qDebug() << CCP(e);
        }
    }

    return helpidx_status == available && !pred_docs.isEmpty();
}
Example #13
0
///////////////////////////////////////////////////
// i_end(i_name) (+)
//	pop current DB (interface became instantiable)
//
BtFImpl(i_end, a, p)
{
	Term t;
	if (!(t = p->eval_term(a.getarg(0))).type(f_ATOM)) {
		p->BtErr(BTERR_INVALID_ARG_TYPE);
		return 0;
	}

	DbIntlog *db = p->get_db();
	kstring dbid = db->GetId(), idi = t.kstr();
	if (dbid != idi || (db = db->EndInterface()) == 0) {
		CCP sdb = MemStoreRef(dbid) != MSR_NULL ? dbid : "";
		p->BtErr(BTERR_CANT_ENDINTERF, CCP(idi), sdb);
		return 0;
	}

	p->set_db(db);
	return 1;
}
Example #14
0
bool lqShapesView::loadScript(QString script) {
    scene()->clear();

    SwiPrologEngine::in_thread it;
    try {
        if (consult(A(script))) {
            return true;
        }
        QMessageBox::warning(this,
           tr("Failure"),
           tr("Script '%1' has no proper interface").arg(script));
    }
    catch(PlException &e) {
         QMessageBox::warning(this,
            tr("Error"),
            tr("Script '%1' cannot be loaded:\n%2").arg(script, CCP(e)));
    }
    return false;
}
Example #15
0
//////////////////////////////////////////
// i_create(i_name, HandleEngine)
//	create a new running interface (+, -)
//
BtFImpl(i_create, t, p)
{
	ASSERT(all_engines);

	ArgIdArityList i(t.getarg(0), p, "i_create");

	if (!p->eval_term(t.getarg(1)).type(f_NOTERM)) {
		p->BtErr(BTERR_INVALID_ARG_TYPE);
		return 0;
	}

	EngHandle h = GetEngines()->create(p->get_db());
	if (h == EH_NULL) {
		p->BtErr(BTERR_CANT_CREATE_ENG);
		return 0;
	}

	IntlogExec *pExec = GetEngines()->HtoD(h);
	DbIntlog *engdb = pExec->get_db(), *dbi;

	// scan all interfaces names
	int errc = 0;
	while (i.next()) {

		// search for declared interface (from current to root)
		if ((dbi = findint(p->get_db(), i.funct)) == 0)
			errc = BTERR_CANT_FIND_DB;
		else if (!engdb->InheritInterface(dbi))
			errc = BTERR_CANT_INHERIT;

		if (errc) {
			// on error signal and reset
			p->BtErr(errc, CCP(i.funct));
			all_engines->destroy(h);
			return 0;
		}
	}

	return p->unify(p->save(Term(new EngineObj(h))), t.getarg(1));
}
CommandProcessor::CommandProcessor(StreamManager* smPtr) {
	this->sm = smPtr;
	userCooldownTimer.restart();

	//set up all commands
	cmdMap["!deck"] = CCP(new CommandCallback(0, 0, UL_USER, false, [this](const CommandInfo& ci, std::string& response){
		response = (boost::format(CMD_DECK_FORMAT) % sm->sName % sm->currentDeck.url).str();
	}));
	alias("!deck", "!decklist");

	cmdMap["!deckprogress"] = CCP(new CommandCallback(0, 0, UL_USER, false, [this](const CommandInfo& ci, std::string& response){
		if (sm->currentDeck.cards.size() < 30) {
			response = "Arena draft progress: " + boost::lexical_cast<std::string>(sm->currentDeck.cards.size()) + "/30";
			if (sm->currentDeck.cards.size() != 0) {
				response += ", latest pick: " + sm->currentDeck.cards.back();
			}
		} else {
			response = "Deck complete";
		}
	}));

	cmdMap["!deckforcepublish"] = CCP(new CommandCallback(0, 0, UL_MOD, true, [this](const CommandInfo& ci, std::string& response){
		while (sm->currentDeck.picks.size() < 30) {
			std::vector<std::string> pick;
			pick.push_back("?"); pick.push_back("?"); pick.push_back("?");
			sm->currentDeck.picks.push_back(pick);
		}
		while (sm->currentDeck.cards.size() < 30) sm->currentDeck.cards.push_back("?");
		std::string deckString = sm->createDeckString(sm->currentDeck);
		sm->currentDeck.url = SystemInterface::createHastebin(deckString);
		response = (boost::format(CMD_DECK_FORMAT) % sm->sName % sm->currentDeck.url).str();
	}));

	cmdMap["!setdeck"] = CCP(new CommandCallback(1, -1, UL_MOD, true, [this](const CommandInfo& ci, std::string& response){
		sm->currentDeck.url = ci.allArgs;
		response = (boost::format(CMD_DECK_FORMAT) % sm->sName % sm->currentDeck.url).str();
	}));

	cmdMap["!backupscoring"] = CCP(new CommandCallback(0, 1, UL_MOD, true, [this](const CommandInfo& ci, std::string& response){
		if (ci.toggle) {
			sm->param_backupscoring = ci.toggleEnable;
			if (sm->param_backupscoring) {
				sm->currentDeck.state = RECOGNIZER_GAME_CLASS_SHOW | RECOGNIZER_GAME_END;
			} else {
				sm->currentDeck.state = 0;
			}
		}
		response = "Backup scoring is: ";
		response += (sm->param_backupscoring)? "on" : "off";
	}));

	cmdMap["!strawpolling"] = CCP(new CommandCallback(0, 1, UL_MOD, true, [this](const CommandInfo& ci, std::string& response){
		if (ci.toggle) {
			sm->param_strawpolling = ci.toggleEnable;
		}
		response = "Automated strawpolling is: ";
		response += (sm->param_strawpolling)? "on" : "off";
	}));

	cmdMap["!info"] = CCP(new CommandCallback(1, 1, UL_MOD, false, [this](const CommandInfo& ci, std::string& response){
		if (ci.allArgs != "fortebot") return;
		response = "ForteBot uses OpenCV and perceptual hashing to very quickly compare all card images against the stream image to find a match. "
				"Additionally, SIFT feature detection is used for automated (backup) scoring. "
				"The Bot is written in C++ by ZeForte. "
				"Check out the (poorly commented) source on GitHub: http://bit.ly/1eGgN5g";
	}));

	cmdMap["!fb_debuglevel"] = CCP(new CommandCallback(1, 1, UL_SUPER, true, [this](const CommandInfo& ci, std::string& response){
		sm->param_debug_level = boost::lexical_cast<unsigned int>(ci.allArgs);
	}));

	cmdMap["!fb_state"] = CCP(new CommandCallback(0, 0, UL_SUPER, false, [this](const CommandInfo& ci, std::string& response){
		response = boost::lexical_cast<std::string>(sm->currentDeck.state);
		response += " ";
		response += boost::lexical_cast<std::string>(sm->currentGame.state);
	}));

	cmdMap["!fb_quit"] = CCP(new CommandCallback(0, 0, UL_MOD, false, [this](const CommandInfo& ci, std::string& response){
		raise(SIGINT);
	}));
}
Example #17
0
static void dstr_disconnect ( PIA *pi )

{       CCP(0x30);
        w0(pi->saved_r0);
        w2(pi->saved_r2);
} 
Example #18
0
static void dstr_connect ( PIA *pi  )

{       pi->saved_r0 = r0();
        pi->saved_r2 = r2();
        w2(4); CCP(0xe0); w0(0xff);
}
Example #19
0
ostream& operator<<(ostream& s, kstring k)
{
	return s << (unsigned(k) != MSR_NULL? CCP(k) : "\"\"");
}