// // Info::putChunkMIMP // void Info::putChunkMIMP() { if(!numChunkMIMP) return; Core::Array<IR::Object const *> imps{numChunkMIMP}; auto itr = imps.begin(); for(auto const &obj : prog->rangeObject()) { if(!obj.defin && obj.space.base == IR::AddrBase::MapReg) *itr++ = &obj; } Core::FastU size = numChunkMIMP * 4; for(auto const &imp : imps) size += lenString(imp->glyph); putData("MIMP", 4); putWord(size); for(auto const &imp : imps) { putWord(imp->value); putString(imp->glyph); } }
// // Info::putChunkATAG // void Info::putChunkATAG() { if(!numChunkATAG) return; for(auto const &itr : init) if(itr.first->space.base == IR::AddrBase::MapArr) { auto const &ini = itr.second; if(!ini.needTag || ini.onlyStr) continue; putData("ATAG", 4); putWord(ini.vals.size() + 5); putByte(0); // version putWord(itr.first->value); for(auto const &i : itr.second.vals) switch(i.tag) { case InitTag::Empty: putByte(0); break; case InitTag::Fixed: putByte(0); break; case InitTag::Funct: putByte(2); break; case InitTag::StrEn: putByte(1); break; } } }
bool SimpleProperties::Writer::add(Uint16 key, Uint32 value){ Uint32 head = Uint32Value; head <<= 16; head += key; if(!putWord(htonl(head))) return false; return putWord(htonl(value)); }
// // Info::putChunkSPTR // void Info::putChunkSPTR() { if(!numChunkSPTR) return; putData("SPTR", 4); putWord(numChunkSPTR * (UseFakeACS0 ? 8 : 12)); for(auto const &itr : prog->rangeFunction()) { if(itr.ctype != IR::CallType::Script && itr.ctype != IR::CallType::ScriptI && itr.ctype != IR::CallType::ScriptS) continue; if(!itr.defin) continue; Core::FastU stype, value; // Convert script type. switch(itr.stype) { case IR::ScriptType::None: stype = 0; break; case IR::ScriptType::Death: stype = 3; break; case IR::ScriptType::Disconnect: stype = 14; break; case IR::ScriptType::Enter: stype = 4; break; case IR::ScriptType::Lightning: stype = 12; break; case IR::ScriptType::Open: stype = 1; break; case IR::ScriptType::Respawn: stype = 2; break; case IR::ScriptType::Return: stype = 15; break; case IR::ScriptType::Unloading: stype = 13; break; } // Convert script index. if(itr.ctype == IR::CallType::ScriptS) value = -static_cast<Core::FastI>(itr.valueInt) - 1; else value = itr.valueInt; // Write entry. if(UseFakeACS0) { putHWord(value); putByte(stype); putByte(itr.param); putExpWord(resolveGlyph(itr.label)); } else { putHWord(value); putHWord(stype); putExpWord(resolveGlyph(itr.label)); putWord(itr.param); } } }
// // Info::putChunkMSTR // void Info::putChunkMSTR() { if(!numChunkMSTR) return; putData("MSTR", 4); putWord(numChunkMSTR * 4); auto const &ini = init[&prog->getSpaceMapReg()]; for(std::size_t i = 0, e = ini.vals.size(); i != e; ++i) if(ini.vals[i].tag == InitTag::StrEn) putWord(i); }
bool SimpleProperties::Writer::add(Uint16 key, const void* value, int len){ Uint32 head = BinaryValue; head <<= 16; head += key; if(!putWord(htonl(head))) return false; if(!putWord(htonl(len))) return false; return add((const char*)value, len); }
// // Info::putChunkASTR // void Info::putChunkASTR() { if(!numChunkASTR) return; putData("ASTR", 4); putWord(numChunkASTR * 4); for(auto const &itr : init) if(itr.first->space.base == IR::AddrBase::MapArr) { if(itr.second.needTag && itr.second.onlyStr) putWord(itr.first->value); } }
bool SimpleProperties::Writer::add(Uint16 key, const char * value){ Uint32 head = StringValue; head <<= 16; head += key; if(!putWord(htonl(head))) return false; Uint32 strLen = Uint32(strlen(value) + 1); // Including NULL-byte if(!putWord(htonl(strLen))) return false; return add(value, (int)strLen); }
// // Info::putChunkMINI // void Info::putChunkMINI() { if(!numChunkMINI) return; auto const &ini = init[&prog->getSpaceMapReg()]; for(std::size_t i = 0, e = ini.vals.size(); i != e; ++i) if(ini.vals[i].val) { putData("MINI", 4); putWord(8); putWord(i); putWord(ini.vals[i].val); } }
// // Info::putChunkARAY // void Info::putChunkARAY() { if(!numChunkARAY) return; putData("ARAY", 4); putWord(numChunkARAY * 8); for(auto const &itr : prog->rangeSpaceMapArs()) { if(!itr.defin) continue; putWord(itr.value); putWord(itr.words); } }
// // Info::putChunkAINI // void Info::putChunkAINI() { if(!numChunkAINI) return; for(auto const &itr : init) if(itr.first->space.base == IR::AddrBase::MapArr) { putData("AINI", 4); putWord(itr.second.vals.size() * 4 + 4); putWord(itr.first->value); for(auto const &i : itr.second.vals) putWord(i.val); } }
/* * memoryStage - writes or reads from memory when needed * Updates values for writebackStage * * params - forwardType * forward, statusType* status, bubbleType* bubble * */ void memoryStage(forwardType * forward, statusType* status, bubbleType* bubble) { unsigned int addr = mem_addr(); unsigned int valM = M.valA; bool memError = false; unsigned int stat = M.stat; if(mem_write()) { putWord(addr, valM, &memError); } if(mem_read()) { valM = getWord(addr, &memError); } if(memError) stat = SADR; //forward values forward->M_dstM = M.dstM; forward->M_dstE = M.dstE; forward->m_valM = valM; forward->M_valE = M.valE; forward->M_Cnd = M.Cnd; forward->M_valA = M.valA; forward->M_icode = M.icode; status->m_stat = stat; bubble->M_icode = M.icode; updateWregister(stat, M.icode, M.valE, valM, M.dstE, M.dstM); }
// // Info::putChunkSFLG // void Info::putChunkSFLG() { if(!numChunkSFLG) return; putData("SFLG", 4); putWord(numChunkSFLG * 4); for(auto const &itr : prog->rangeFunction()) { if(itr.ctype != IR::CallType::Script && itr.ctype != IR::CallType::ScriptI && itr.ctype != IR::CallType::ScriptS) continue; if(!itr.defin) continue; Core::FastU flags = 0; if(itr.sflagClS) flags |= 0x0002; if(itr.sflagNet) flags |= 0x0001; if(!flags) continue; putHWord(itr.valueInt); putHWord(flags); } }
// // Info::putChunkCODE // void Info::putChunkCODE() { putData("\0\0\0\0", 4); putWord(numChunkCODE); // Put statements. for(auto &itr : prog->rangeFunction()) putFunc(itr); }
QVector<QPointF> *Visualizer::putText(QStringList wordList, float x, float y, bool isOnTop, QMap<int, QVector<int> > map) { int pos = 0; QVector<QPointF> *points = new QVector<QPointF>; QRectF rect = putWord("___", x, y, isOnTop, pos, map); points->push_back(findPointForConnection(rect, x, y, isOnTop)); x += rect.width() + space; QStringListIterator i(wordList); pos++; while(i.hasNext()) { QString word = i.next(); QRectF rect = putWord(word, x, y, isOnTop, pos, map); points->push_back(findPointForConnection(rect, x, y, isOnTop)); x += rect.width() + space; pos++; } return points; }
// // Info::putChunk // void Info::putChunk(char const *name, Core::Array<Core::String> const &strs, bool junk) { std::size_t base; std::size_t off; // Calculate base offset. base = strs.size() * 4 + 4; if(junk) base += 8; // Calculate size of chunk. off = base; for(auto const &s : strs) off += lenString(s); // Write chunk header. putData(name, 4); putWord(off); // Write string count. if(junk) putWord(0); putWord(strs.size()); if(junk) putWord(0); // Write string offsets. off = base; for(auto const &s : strs) { putWord(off); off += lenString(s); } // Write strings. if(junk && UseChunkSTRE) { off = base; for(auto const &s : strs) { putString(s, off * 157135); off += lenString(s); } } else for(auto const &s : strs) putString(s); }
/** * Function: memCond * This function returns the value to be sent as valM * and reads or writes from memory if needed * Return: value to be used as valM */ unsigned int memCond(unsigned int valE,bool * memError) { bool tempEr = FALSE; unsigned int ret = M.valA; if(memRead()){ ret = getWord(valE,&tempEr); *memError = tempEr; } else if(memWrite()){ putWord(valE,M.valA,&memError); ret = M.valA; } return ret; }
void mFormat(char *string) { char wordBuf[MAXWORD + 8]; int i; for (i = 0; string[i] && (outFlag == OUTOK || outFlag == IMPERVIOUS || outFlag == OUTPARAGRAPH);) { i = getWord(wordBuf, string, i, MAXWORD); putWord(wordBuf); if (mAbort()) return; } }
// // Info::putChunkFUNC // void Info::putChunkFUNC() { if(!numChunkFUNC) return; Core::Array<IR::Function const *> funcs{numChunkFUNC}; for(auto &f : funcs) f = nullptr; for(auto const &itr : prog->rangeFunction()) { if(itr.ctype != IR::CallType::LangACS) continue; funcs[itr.valueInt] = &itr; } putData("FUNC", 4); putWord(numChunkFUNC * 8); for(auto f : funcs) { if(f) { putByte(f->param); putByte(std::max(f->localReg, f->param)); putByte(!!f->retrn); putByte(0); if(f->defin) putExpWord(resolveGlyph(f->label)); else putWord(0); } else putData("\0\0\0\0\0\0\0\0", 8); } }
// // Info::putChunkAIMP // void Info::putChunkAIMP() { if(!numChunkAIMP) return; Core::Array<IR::Space const *> imps{numChunkAIMP}; auto itr = imps.begin(); for(auto const &sp : prog->rangeSpaceMapArs()) if(!sp.defin) *itr++ = &sp; Core::FastU size = numChunkAIMP * 8; for(auto const &imp : imps) size += lenString(imp->glyph); putData("AIMP", 4); putWord(size); for(auto const &imp : imps) { putWord(imp->value); putWord(imp->words); putString(imp->glyph); } }
// // Info::putChunkLOAD // void Info::putChunkLOAD() { numChunkLOAD = prog->sizeImport(); if(!numChunkLOAD) return; Core::FastU size = 0; for(auto const &itr : prog->rangeImport()) size += lenString(itr.glyph); putData("LOAD", 4); putWord(size); for(auto const &itr : prog->rangeImport()) putString(itr.glyph); }
void Speller::addToDictionary() { if (QAction* act = qobject_cast<QAction*>(sender())) { const QString &word = act->data().toString(); putWord(word); if (!m_userDictionary.open(QFile::WriteOnly | QFile::Append)) { qWarning() << "SpellCheck: Cannot open file" << m_userDictionary.fileName() << "for writing!"; return; } QTextStream stream(&m_userDictionary); stream.setCodec("UTF-8"); stream << word << endl; m_userDictionary.close(); } }
void Speller::initialize() { delete m_hunspell; m_hunspell = 0; if (m_dictionaryPath.isEmpty()) { qWarning() << "SpellCheck: Cannot locate dictionary path!"; return; } QString dictionary = m_dictionaryPath + m_language.code; if (!dictionaryExists(dictionary)) { qWarning() << "SpellCheck: Dictionaries for" << dictionary << "doesn't exists!"; return; } const QString dicPath = dictionary + ".dic"; const QString affPath = dictionary + ".aff"; m_hunspell = new Hunspell(affPath.toLocal8Bit().constData(), dicPath .toLocal8Bit().constData()); m_textCodec = QTextCodec::codecForName(m_hunspell->get_dic_encoding()); if (m_userDictionary.exists()) { if (!m_userDictionary.open(QFile::ReadOnly)) { qWarning() << "SpellCheck: Cannot open" << m_userDictionary.fileName() << "for reading!"; } else { QString word; QTextStream stream(&m_userDictionary); stream.setCodec("UTF-8"); while (!stream.atEnd()) { stream >> word; putWord(word); } } m_userDictionary.close(); } qDebug() << "SpellCheck: Language =" << language().code << (m_textCodec ? m_textCodec->name() : "invalid text codec"); }
bool SimpleProperties::Writer::add(const char * value, int len){ const Uint32 valLen = (len + 3) / 4; if ((len % 4) == 0) return putWords((Uint32*)value, valLen); const Uint32 putLen= valLen - 1; if (!putWords((Uint32*)value, putLen)) return false; // Special handling of last bytes union { Uint32 lastWord; char lastBytes[4]; } tmp; tmp.lastWord =0 ; memcpy(tmp.lastBytes, value + putLen*4, len - putLen*4); return putWord(tmp.lastWord); }
// // Info::putChunkSVCT // void Info::putChunkSVCT() { if(!numChunkSVCT) return; putData("SVCT", 4); putWord(numChunkSFLG * 4); for(auto const &itr : prog->rangeFunction()) { if(itr.ctype != IR::CallType::Script && itr.ctype != IR::CallType::ScriptI && itr.ctype != IR::CallType::ScriptS) continue; if(!itr.defin) continue; if(itr.localReg <= 20) continue; putHWord(itr.valueInt); putHWord(itr.localReg); } }
/* memoryStage * Controls the main combinational logic of the memory stage * Params: fwdStruct *fwd - contains a bunch of forwarding info * Returns: void * Modifies: Writeback Register */ void memoryStage(fwdStruct *fwd) { if (M.stat == SINS || M.stat == SADR || M.stat == SHLT) canUpdateMem = FALSE; int valM = M.valA, stat = M.stat; bool readC = FALSE, writeC = FALSE, memError = FALSE; memoryControl(&readC, &writeC); int memAddr = memoryAddr(); if (readC) valM = getWord(memAddr, &memError); if (writeC && canUpdateMem) putWord(memAddr, M.valA, &memError); if (memError) { stat = SADR; canUpdateMem = FALSE; } fwd->M_valE = M.valE; fwd->m_valM = valM; fwd->M_dstE = M.dstE; fwd->M_dstM = M.dstM; fwd->M_Cnd = M.Cnd; fwd->M_icode = M.icode; fwd->M_valA = M.valA; fwd->m_stat = stat; if (!W_stall(fwd)) updateWregister(stat, M.icode, M.valE, valM, M.dstE, M.dstM); }
void executeSDT(struct single_data_transfer_decoded single_data_transfer_instr){ //PREINDEXING if(single_data_transfer_instr.pre_or_post_indexing_bit){ //LOADED FROM MEMORY Rn := [address], LDR PREINDEXING if(single_data_transfer_instr.load_or_store_bit){ //Offset is added to base register if(single_data_transfer_instr.up_bit){ //Memory address is definitely in memory if(machine.registers[single_data_transfer_instr.base_reg] + single_data_transfer_instr.offset < MEMSIZE) { machine.registers[single_data_transfer_instr.src_or_dst_reg] = getWord(machine.registers[single_data_transfer_instr.base_reg] + single_data_transfer_instr.offset); //NOTE: isGPIOPin prints 'Pin accessed..' } else if( isGPIOPin(machine.registers[single_data_transfer_instr.base_reg] + single_data_transfer_instr.offset)) { machine.registers[single_data_transfer_instr.src_or_dst_reg] = machine.registers[single_data_transfer_instr.base_reg] + single_data_transfer_instr.offset; //No print needed here for ldr } else if( isGPIOSetOrClear(machine.registers[single_data_transfer_instr.base_reg] + single_data_transfer_instr.offset)) { //This bit of memory isn't actually in the emulator } else { printf("Error: Out of bounds memory access at address 0x%08x\n", machine.registers[single_data_transfer_instr.base_reg] + single_data_transfer_instr.offset); } } else { if(machine.registers[single_data_transfer_instr.base_reg] - single_data_transfer_instr.offset < MEMSIZE) { machine.registers[single_data_transfer_instr.src_or_dst_reg] = getWord(machine.registers[single_data_transfer_instr.base_reg] - single_data_transfer_instr.offset); //NOTE: isGPIOPin prints 'Pin accessed..' } else if( isGPIOPin(machine.registers[single_data_transfer_instr.base_reg] - single_data_transfer_instr.offset)) { machine.registers[single_data_transfer_instr.src_or_dst_reg] = machine.registers[single_data_transfer_instr.base_reg] - single_data_transfer_instr.offset; //No print needed here for ldr } else if( isGPIOSetOrClear(machine.registers[single_data_transfer_instr.base_reg] - single_data_transfer_instr.offset)) { //This bit of memory isn't actually in the emulator } else { printf("Error: Out of bounds memory access at address 0x%08x\n", machine.registers[single_data_transfer_instr.base_reg] - single_data_transfer_instr.offset); } } //STORING INTO MEMORY [address] := Rn, STR PREINDEXING } else { if(single_data_transfer_instr.up_bit){ if(machine.registers[single_data_transfer_instr.base_reg] + single_data_transfer_instr.offset < MEMSIZE) { putWord(machine.registers[single_data_transfer_instr.base_reg] + single_data_transfer_instr.offset, machine.registers[single_data_transfer_instr.src_or_dst_reg]); //NOTE: isGPIOPin prints 'Pin accessed..' } else if( isGPIOPin(machine.registers[single_data_transfer_instr.base_reg] + single_data_transfer_instr.offset)) { //This bit of memory isn't actually in emulator } else if( isGPIOSetOrClear(machine.registers[single_data_transfer_instr.base_reg] + single_data_transfer_instr.offset)) { if (machine.registers[single_data_transfer_instr.src_or_dst_reg] != 0) { //If output set register, PIN ON, otherwise it is clearing if(machine.registers[single_data_transfer_instr.base_reg] + single_data_transfer_instr.offset == GPIO_OUTPUT_SET_0) { printf("PIN ON\n"); } else { printf("PIN OFF\n"); } } //This bit of memory isn't actually in emulator } else { printf("Error: Out of bounds memory access at address 0x%08x\n", machine.registers[single_data_transfer_instr.base_reg] + single_data_transfer_instr.offset); } } else { if(machine.registers[single_data_transfer_instr.base_reg] - single_data_transfer_instr.offset < MEMSIZE) { putWord(machine.registers[single_data_transfer_instr.base_reg] - single_data_transfer_instr.offset, machine.registers[single_data_transfer_instr.src_or_dst_reg]); //NOTE: isGPIOPin prints 'Pin accessed..' } else if( isGPIOPin(machine.registers[single_data_transfer_instr.base_reg] - single_data_transfer_instr.offset)) { //This bit of memory isn't actually in emulator } else if( isGPIOSetOrClear(machine.registers[single_data_transfer_instr.base_reg] - single_data_transfer_instr.offset)) { if (machine.registers[single_data_transfer_instr.src_or_dst_reg] != 0) { if(machine.registers[single_data_transfer_instr.base_reg] - single_data_transfer_instr.offset == GPIO_OUTPUT_SET_0) { printf("PIN ON\n"); } else { printf("PIN OFF\n"); } } //This bit of memory isn't actually in emulator } else { printf("Error: Out of bounds memory access at address 0x%08x\n", machine.registers[single_data_transfer_instr.base_reg] - single_data_transfer_instr.offset); } } } //POSTINDEXING } else { //LOADED FROM MEMORY, LDR POSTINDEXING (No offset) if(single_data_transfer_instr.load_or_store_bit) { if(machine.registers[single_data_transfer_instr.base_reg] < MEMSIZE){ machine.registers[single_data_transfer_instr.src_or_dst_reg] = getWord(machine.registers[single_data_transfer_instr.base_reg]); //NOTE: isGPIOPin prints 'Pin accessed..' } else if( isGPIOPin(machine.registers[single_data_transfer_instr.base_reg])) { machine.registers[single_data_transfer_instr.src_or_dst_reg] = machine.registers[single_data_transfer_instr.base_reg]; //No print needed here for ldr } else if(isGPIOSetOrClear( machine.registers[single_data_transfer_instr.base_reg])) { //This bit of memory isn't actually in the emulator } else { printf("Error: Out of bounds memory access at address 0x%08x\n", machine.registers[single_data_transfer_instr.base_reg]); } //Adding offset if(single_data_transfer_instr.up_bit) { machine.registers[single_data_transfer_instr.base_reg] += single_data_transfer_instr.offset; //Subtracting offset } else { machine.registers[single_data_transfer_instr.base_reg] -= single_data_transfer_instr.offset; } //STR POSTINDEXING } else { if(machine.registers[single_data_transfer_instr.base_reg] < MEMSIZE){ putWord(machine.registers[single_data_transfer_instr.base_reg], machine.registers[single_data_transfer_instr.src_or_dst_reg]); //NOTE: isGPIOPin prints 'Pin accessed..' } else if(isGPIOPin( machine.registers[single_data_transfer_instr.base_reg])) { //This bit of memory isn't actually in emulator } else if(isGPIOSetOrClear( machine.registers[single_data_transfer_instr.base_reg])) { if (machine.registers[single_data_transfer_instr.src_or_dst_reg] != 0) { if(machine.registers[single_data_transfer_instr.base_reg] == GPIO_OUTPUT_SET_0) { printf("PIN ON\n"); } else { printf("PIN OFF\n"); } } //This bit of memory isn't actually in emulator } else { printf("Error: Out of bounds memory access at address 0x%08x\n", machine.registers[single_data_transfer_instr.base_reg]); } if(single_data_transfer_instr.up_bit){ machine.registers[single_data_transfer_instr.base_reg] += single_data_transfer_instr.offset; } else { machine.registers[single_data_transfer_instr.base_reg] -= single_data_transfer_instr.offset; } } } }
void laydata::TEDfile::putRevision() { putByte(tedf_REVISION); putWord(_revision); putWord(_subrevision); }
Bool OutputControl::CheckInput(Bool Pause) #endif { if (User.Continuous) { Pause = FALSE; } if (User.ControlD) { tw()KBReady(); // for screenblanker SetOutFlag(OUTSKIP); // Auto-Stop everything return (TRUE); } // Cannot abort IMPERVIOUS if (User.GetOutFlag() == IMPERVIOUS) { tw()KBReady(); // for screenblanker return (FALSE); } // Carrier loss and not on Console if (!tw()HaveConnectionToUser()) { SetOutFlag(OUTSKIP); return (TRUE); } Bool toReturn = FALSE; // Check for keypress if (tw()BBSCharReady() || Pause) { int c; if (!Pause) { c = toupper(tw()iCharNE()); } if (Pause || c == 'P' || c == 19) // P or ^S (XOFF) - Pause { if (Pause) { char Buffer[80]; tw()CurrentUser->GetMorePrompt(Buffer, sizeof(Buffer)); if (!tw()outSpeech(TRUE, tw()loggedIn ? Buffer : cfg.moreprompt)) { tw()putWord((uchar *) (tw()loggedIn ? Buffer : cfg.moreprompt)); } } do { // wait to resume c = toupper(tw()iCharNE()); } while (!tw()CurrentUser->IsPUnPauses() && (c == 'P' || c == 19)); if (Pause) { char Buffer[80]; int i, backspace = strlen(tw()loggedIn ? tw()CurrentUser->GetMorePrompt(Buffer, sizeof(Buffer)) : cfg.moreprompt); for (i = 0; i < backspace; i++) { tw()doBS(); } } } if (User.GetOutFlag() == NOSTOP) { return (FALSE); } const Bool WasFormatting = Formatting; Formatting = TRUE; switch (c) { case CTRL_D: { User.ControlD = TRUE; SetOutFlag(OUTSKIP); toReturn = TRUE; break; } case '9': { if (tw()hitSix) { tw()doCR(); tw()termCap(TERM_NORMAL); tw()putWord((const uchar *) getmsg(327)); tw()termCap(TERM_BOLD); if (!tw()outSpeech(TRUE, getmsg(69))) { tw()putWord((uchar *) getmsg(69)); } tw()termCap(TERM_NORMAL); tw()putWord((const uchar *) getmsg(326)); tw()doCR(); } break; } case 'J': // jump paragraph { tw()doCR(); tw()termCap(TERM_NORMAL); tw()putWord((const uchar *) getmsg(327)); tw()termCap(TERM_BOLD); if (!tw()outSpeech(TRUE, getmsg(547))) { tw()putWord((uchar *) getmsg(547)); } tw()termCap(TERM_NORMAL); tw()putWord((const uchar *) getmsg(326)); tw()doCR(); SetOutFlag(OUTPARAGRAPH); break; } case 'K': // kill { if (User.CanK) { tw()MRO.DotoMessage = PULL_IT; tw()doCR(); tw()termCap(TERM_NORMAL); tw()putWord((const uchar *) getmsg(327)); tw()termCap(TERM_BOLD); if (!tw()outSpeech(TRUE, getmsg(546))) { tw()putWord((uchar *) getmsg(546)); } tw()termCap(TERM_NORMAL); tw()putWord((const uchar *) getmsg(326)); SetOutFlag(OUTNEXT); toReturn = TRUE; } break; } case 'M': // mark { if (User.CanM) { tw()MRO.DotoMessage = MARK_IT; tw()doCR(); tw()termCap(TERM_NORMAL); tw()putWord((const uchar *) getmsg(327)); tw()termCap(TERM_BOLD); if (!tw()outSpeech(TRUE, getmsg(543))) { tw()putWord((uchar *) getmsg(543)); } tw()termCap(TERM_NORMAL); tw()putWord((const uchar *) getmsg(326)); SetOutFlag(OUTNEXT); toReturn = TRUE; } break; } case '*': // censor { if (User.CanStar) { tw()MRO.DotoMessage = CENSOR_IT; tw()doCR(); tw()termCap(TERM_NORMAL); tw()putWord((const uchar *) getmsg(327)); tw()termCap(TERM_BOLD); if (!tw()outSpeech(TRUE, getmsg(538))) { tw()putWord((uchar *) getmsg(538)); } tw()termCap(TERM_NORMAL); tw()putWord((const uchar *) getmsg(326)); SetOutFlag(OUTNEXT); toReturn = TRUE; } break; } case 'N': // next { tw()doCR(); tw()termCap(TERM_NORMAL); tw()putWord((const uchar *) getmsg(327)); tw()termCap(TERM_BOLD); if (!tw()outSpeech(TRUE, getmsg(537))) { tw()putWord((uchar *) getmsg(537)); } tw()termCap(TERM_NORMAL); tw()putWord((const uchar *) getmsg(326)); tw()doCR(); SetOutFlag(OUTNEXT); toReturn = TRUE; break; } case 'S': // stop { tw()numLines = 0; // Don't pause for stop! tw()doCR(); tw()termCap(TERM_NORMAL); tw()putWord((const uchar *) getmsg(327)); tw()termCap(TERM_BOLD); if (!tw()outSpeech(TRUE, getmsg(528))) { tw()putWord((uchar *) getmsg(528)); } tw()termCap(TERM_NORMAL); tw()putWord((const uchar *) getmsg(326)); tw()doCR(); SetOutFlag(OUTSKIP); toReturn = TRUE; break; } case 'C': // continuous { tw()doCR(); tw()termCap(TERM_NORMAL); tw()putWord((const uchar *) getmsg(327)); tw()termCap(TERM_BOLD); if (!User.Continuous) { if (!tw()outSpeech(TRUE, getmsg(527))) { tw()putWord((uchar *) getmsg(527)); } } else { if (!tw()outSpeech(TRUE, getmsg(526))) { tw()putWord((uchar *) getmsg(526)); } } tw()termCap(TERM_NORMAL); tw()putWord((const uchar *) getmsg(326)); User.Continuous = !User.Continuous; tw()doCR(); break; } case 'R': { if (User.CanR) { tw()MRO.DotoMessage = REVERSE_READ; SetOutFlag(OUTNEXT); } break; } case 'V': { tw()MRO.Verbose = !tw()MRO.Verbose; tw()doCR(); tw()termCap(TERM_NORMAL); tw()putWord((const uchar *) getmsg(327)); tw()termCap(TERM_BOLD); if (tw()MRO.Verbose) { if (!tw()outSpeech(TRUE, getmsg(524))) { tw()putWord((uchar *) getmsg(524)); } } else { if (!tw()outSpeech(TRUE, getmsg(519))) { tw()putWord((uchar *) getmsg(519)); } } tw()termCap(TERM_NORMAL); tw()putWord((const uchar *) getmsg(326)); tw()doCR(); break; } case '!': { if (User.CanBang) { tw()MRO.Headerscan = !tw()MRO.Headerscan; tw()doCR(); tw()termCap(TERM_NORMAL); tw()putWord((const uchar *) getmsg(327)); tw()termCap(TERM_BOLD); if (tw()MRO.Headerscan) { if (!tw()outSpeech(TRUE, getmsg(517))) { tw()putWord((uchar *) getmsg(517)); } } else { if (!tw()outSpeech(TRUE, getmsg(511))) { tw()putWord((uchar *) getmsg(511)); } } tw()termCap(TERM_NORMAL); tw()putWord((const uchar *) getmsg(326)); tw()doCR(); } break; } case '@': { if (User.CanAt) { tw()MRO.DotoMessage = REPLY; tw()doCR(); tw()termCap(TERM_NORMAL); tw()putWord((const uchar *) getmsg(327)); tw()termCap(TERM_BOLD); if (!tw()outSpeech(TRUE, getmsg(470))) { tw()putWord((uchar *) getmsg(470)); } tw()termCap(TERM_NORMAL); tw()putWord((const uchar *) getmsg(326)); tw()doCR(); } break; } } Formatting = WasFormatting; if (c == '6') { tw()hitSix = TRUE; } else { tw()hitSix = FALSE; } } return (toReturn); }
int main(int argc, char *argv[]) { // for error returns from vm520 functions int errorNumber; // expects the number of processors to be given on the command line if ((argc != 2) || (argv[1][0] == 0)) { fprintf(stderr, "usage: pi numberOfprocessors\n"); exit(-1); } // get the specified number of processors errno = 0; char *p; long int processors = strtol(argv[1], &p, 10); if ((*p != 0) || errno || (processors < 0) || (processors > 16)) { fprintf(stderr, "%s is not a valid number of processors\n", argv[1]); exit(-1); } // load pi.obj if (!loadObjectFile("pi.obj", &errorNumber)) { fprintf(stderr, "loadObjectFile fails with error %d\n", errorNumber); exit(-1); } // get the addresses of the exported labels unsigned int addressFour; unsigned int addressOne; unsigned int addressOneHalf; unsigned int addressWidth; unsigned int addressIntervals; unsigned int addressAnswer; if (!getAddress("four", &addressFour)) { fprintf(stderr, "getAddress fails for four\n"); exit(-1); } if (!getAddress("one", &addressOne)) { fprintf(stderr, "getAddress fails for one\n"); exit(-1); } if (!getAddress("oneHalf", &addressOneHalf)) { fprintf(stderr, "getAddress fails for oneHalf\n"); exit(-1); } if (!getAddress("intervals", &addressIntervals)) { fprintf(stderr, "getAddress fails for intervals\n"); exit(-1); } if (!getAddress("width", &addressWidth)) { fprintf(stderr, "getAddress fails for width\n"); exit(-1); } if (!getAddress("answer", &addressAnswer)) { fprintf(stderr, "getAddress fails for answer\n"); exit(-1); } // put initial values into the exported symbols float x; int intervals = INTERVALS; x = 1.0; if (!putWord(addressOne, * (int *) &x)) { fprintf(stderr, "putWord fails for one (%d)\n", addressOne); exit(-1); } x = 4.0; if (!putWord(addressFour, * (int *) &x)) { fprintf(stderr, "putWord fails for four (%d)\n", addressFour); exit(-1); } x = 0.5; if (!putWord(addressOneHalf, * (int *) &x)) { fprintf(stderr, "putWord fails for oneHalf (%d)\n", addressOneHalf); exit(-1); } if (!putWord(addressIntervals, intervals)) { fprintf(stderr, "putWord fails for intervals (%d)\n", addressIntervals); exit(-1); } x = 1.0 / intervals; if (!putWord(addressWidth, * (int *) &x)) { fprintf(stderr, "putWord fails for width (%d)\n", addressWidth); exit(-1); } // execute the program unsigned int SP[processors]; int status[processors]; int wordAnswer; int i; int nextSP = 1000; for (i = 0; i < processors; i++) // set initial SP values { SP[i] = nextSP; nextSP += 1000; } printf("starting vm520 with %ld processors\n", processors); if (!execute(processors, SP, status, TRACE)) { fprintf(stderr, "execute fails\n"); exit(-1); } for (i = 0; i < processors; i++) { printf("processor %d halted with status %d\n", i, status[i]); } if (!getWord(addressAnswer, &wordAnswer)) { fprintf(stderr, "getWord fails for answer (%u)\n", addressAnswer); exit(-1); } printf("answer is %8.6f\n", * (float *) &wordAnswer); return 0; }