void MMXCore::LoadTilesAndPalettes() { // Load Palettes DWORD configPointer = snes2pc(SReadWord(p_palett[type] + level*2 + 0x60) | 0x860000); BYTE colorsToLoad = rom[configPointer++]; if (type==2) pPalette = snes2pc(ReadWord(configPointer++) | 0x8C0000); else pPalette = snes2pc(ReadWord(configPointer++) | 0x850000); for(int i=0; i<colorsToLoad; i++) palCache[i] = Get16Color(pPalette + i*2); for(int i=0; i<(colorsToLoad>>4); i++) palettesOffset[i] = (DWORD)pPalette + i*0x20; memcpy(vram, vrambase, 0x200); if (type==0) // Only MMX1 is able to do this { LoadPaletteDynamic(); LoadGFXs(); LoadTiles(); } for(int i=0; i<0x400; i++) tile4bpp2raw(vram + (i<<5), vramCache + (i<<6)); }
void MMXCore::LoadPaletteDynamic() { WORD iLevel = level & 0xFF; BYTE palSelect = checkpointInfo->palLoad; int baseIndex = ReadWord(0x32260 + iLevel*2) + palSelect*2; int mainIndex = ReadWord(0x32260 + baseIndex); int writeTo = 0; int colorPointer = 0; while(true) { colorPointer = ReadWord(0x32260 + mainIndex); if (colorPointer == 0xFFFF) return; writeTo = (ReadWord(0x32262 + mainIndex) & 0xFF); if (writeTo > 0x7F) { MessageBox(NULL, "Palette overflow.", "Error", MB_ICONERROR); return; } palettesOffset[writeTo>>4] = snes2pc(colorPointer | 0x850000); for(int i=0; i<0x10; i++) { palCache[writeTo + i] = Convert16Color(ReadWord(snes2pc(0x850000 | colorPointer + i*2))); } mainIndex += 3; } }
void MReadKbd() { int ccode,mod; int kbrd_called=0; while(qCharLen()) { asciiChar=charAscii[charHead]; ccode=charBuff[charHead][1]; mod=charBuff[charHead++][0]; if (charHead>=CHAR_BUFF_LEN) charHead=0; /*printf("char %c %d\t ccode %d\n",asciiChar,asciiChar,ccode);*/ reg[1]=ccode; reg[2]=mod; aReg[2]=ReadLong(0x2804c); /* printf("calling subr %d\n",((w16)(uw16)ReadWord(0x150))+0x4000);*/ QLsubr(ReadWord(0x150)+0x4000,2000000); /*printf("result: %d\n",reg[0]);*/ kbrd_called=1; } if (gKeyDown /*&& !MButtonDown /*|| kbrd_called */) { kbrd_called=0; aReg[2]=ReadLong(0x2804c); reg[5]=-1;/*(gKeyDown!=0)<<4;*/ QLsubr(ReadWord(0x152)+0x4000,2000000); } }
bool CBotProgram::RestoreState(FILE* pf) { unsigned short w; std::string s; Stop(); if (!ReadWord( pf, w )) return false; if ( w != CBOTVERSION ) return false; if (!ReadWord( pf, w )) return false; if ( w == 0 ) return true; if (!ReadString( pf, s )) return false; Start(s); // point de reprise if (m_stack != nullptr) { m_stack->Delete(); m_stack = nullptr; } // retrieves the stack from the memory m_stack = CBotStack::AllocateStack(); if (!m_stack->RestoreState(pf, m_stack)) return false; m_stack->SetProgram(this); // bases for routines // restored some states in the stack according to the structure m_entryPoint->RestoreState(nullptr, m_stack, m_thisVar); return true; }
void CPipeServer::FindClass() { void *image=(void *)ReadQword(); WORD length=ReadWord(); char *cn=NULL; char *ns=NULL; void *klass; cn=(char *)malloc(length+1); if (length) Read(cn, length); cn[length]=0; length=ReadWord(); ns=(char *)malloc(length+1); if (length) Read(ns, length); ns[length]=0; klass=mono_class_from_name_case(image, ns, cn); if (cn) free(cn); if (ns) free(ns); WriteQword((UINT_PTR)klass); }
// // ReadStartOfFrame() // void JLSInputStream::ReadStartOfFrame() { _info.bitspersample = ReadByte(); int cline = ReadWord(); int ccol = ReadWord(); _info.width = ccol; _info.height = cline; _info.components= ReadByte(); }
int VICARKeywordHandler::ReadPair( CPLString &osName, CPLString &osValue ) { osName = ""; osValue = ""; if( !ReadWord( osName ) ) { return FALSE;} SkipWhite(); // VICAR has no NULL string termination if( *pszHeaderNext == '\0') { osName="END"; return TRUE; } pszHeaderNext++; SkipWhite(); osValue = ""; if( *pszHeaderNext == '(' && pszHeaderNext[1] == '\'' ) { CPLString osWord; while( ReadWord( osWord ) ) { osValue += osWord; if ( strlen(osWord) < 2 ) continue; if( osWord[strlen(osWord)-1] == ')' && osWord[strlen(osWord)-2] == '\'' ) break; } } else if( *pszHeaderNext == '(' && *pszHeaderNext-1 != '\'' ) { CPLString osWord; while( ReadWord( osWord ) ) { SkipWhite(); osValue += osWord; if( osWord[strlen(osWord)-1] == ')' ) break; } } else { if( !ReadWord( osValue ) ) return FALSE; } SkipWhite(); return TRUE; }
int ScanModPublics(WORD wModule){ BYTE abBuffer[300]; WORD wLen,wPublics; BYTE *pbBuffer,bType; wPublics=0; _tlseek(wLib,alOffsets[wModule],0); if (ReadByte()== THEADR) if (ReadHdrRecord(abBuffer)){ while(TRUE){ bType = ReadByte(); switch(bType){ case PUBDEF: if ((wLen = ReadWord())!=0xffff){ WORD GrpIndex,SegIndex; if ((GrpIndex=ReadByte()) >= 128){ wLen -=2; ReadByte(); } else wLen--; if ((SegIndex=ReadByte()) >= 128){ wLen -=2; ReadByte(); } else wLen--; if (GrpIndex==0 && SegIndex == 0){ ReadWord(); wLen -= 2; } while(wLen > 1){ ReadName(abBuffer); pcStrings[wPublics]=_xgrab(strlen(abBuffer)+1); strcpy(pcStrings[wPublics],abBuffer); wPublics++; ReadWord(); if (ReadByte() >= 128){ wLen -=2; ReadByte(); } else wLen--; wLen -= strlen(abBuffer)+1; wLen -= 2; } ReadByte(); } break; case 0x0: case LIBTRL: case THEADR: return wPublics; default: if (!SkipRecord()){ return 0xffff; } } } } FreeStrings(wPublics); return 0xffff; }
static void i80286_data_descriptor_full(i80286_state *cpustate, int reg, UINT16 selector, int cpl, UINT32 trap, UINT16 offset, int size) { if (PM) { UINT16 desc[3]; UINT8 r; UINT32 addr; /* selector format 15..3 number/address in descriptor table 2: 0 global, 1 local descriptor table 1,0: requested privileg level must be higher or same as current privileg level in code selector */ if ((reg != SS) && !IDXTBL(selector)) { cpustate->sregs[reg]=0; cpustate->limit[reg]=0; cpustate->base[reg]=0; cpustate->rights[reg]=0; cpustate->valid[reg]=0; return; } if ((addr = i80286_selector_address(cpustate,selector)) == -1) throw trap; desc[0] = ReadWord(addr); desc[1] = ReadWord(addr+2); desc[2] = ReadWord(addr+4); r = RIGHTS(desc); if (!SEGDESC(r)) throw trap; if (reg == SS) { if (!IDXTBL(selector)) throw trap; if (DPL(r)!=cpl) throw trap; if (RPL(selector)!=cpl) throw trap; if (!RW(r) || CODE(r)) throw trap; if (!PRES(r)) throw TRAP(STACK_FAULT,(IDXTBL(selector)+(trap&1))); } else { if ((DPL(r) < PMAX(cpl,RPL(selector))) && (!CODE(r) || (CODE(r) && !CONF(r)))) throw trap; if (CODE(r) && !READ(r)) throw trap; if (!PRES(r)) throw TRAP(SEG_NOT_PRESENT,(IDXTBL(selector)+(trap&1))); } if (offset+size) { if ((CODE(r) || !EXPDOWN(r)) && ((offset+size-1) > LIMIT(desc))) throw (reg==SS)?TRAP(STACK_FAULT,(trap&1)):trap; if (!CODE(r) && EXPDOWN(r) && ((offset <= LIMIT(desc)) || ((offset+size-1) > 0xffff))) throw (reg==SS)?TRAP(STACK_FAULT,(trap&1)):trap; } SET_ACC(desc); WriteWord(addr+4, desc[2]); cpustate->sregs[reg]=selector; cpustate->limit[reg]=LIMIT(desc); cpustate->base[reg]=BASE(desc); cpustate->rights[reg]=RIGHTS(desc); } else { cpustate->sregs[reg]=selector; cpustate->base[reg]=selector<<4; } cpustate->valid[reg]=1; }
void MMXCore::LoadGFXs() { DWORD pConfigGfx = snes2pc(SReadWord(p_gfxcfg[type] + level*2 + 4) | 0x86 << 16); BYTE gfxID = rom[pConfigGfx]; tileCmpSize = ReadWord(pConfigGfx+1); tileCmpDest = (ReadWord(pConfigGfx+3)<<1) - 0x2000; tileCmpPos = snes2pc(SReadDWord(p_gfxpos[type] + gfxID * 5 + 2)); tileCmpRealSize = GFXRLE(rom, vram+tileCmpDest, tileCmpPos, tileCmpSize); //GFXRLECmp(vram+tileCmpDest, rom+tileCmpPos, 0, 0x4800); //GFXRLE(rom, vram+tileCmpDest, tileCmpPos, tileCmpSize); }
void FileManager_Model::LoadObj_AddPolygon(string line) { int val[3]; string position = line+2; byte wordBuffer[MAX_FILE_WORD_LENGTH]; ReadWord(&position, wordBuffer); val[0] = atoi(wordBuffer) + vertexOffset; ReadWord(&position, wordBuffer); val[1] = atoi(wordBuffer) + vertexOffset; ReadWord(&position, wordBuffer); val[2] = atoi(wordBuffer) + vertexOffset; scene->addPolygon(val); }
void FileManager_Model::LoadObj_AddVertex(string line) { vec3 vertex; string position = line+2; byte wordBuffer[MAX_FILE_WORD_LENGTH]; ReadWord(&position, wordBuffer); vertex.x = atof(wordBuffer); ReadWord(&position, wordBuffer); vertex.y = atof(wordBuffer); ReadWord(&position, wordBuffer); vertex.z = atof(wordBuffer); scene->addVertex(&vertex); }
void XMLReader::Read() { ReadWord(); if(strncmp(paraula,"<expressions>",11)==0) { // Elimina les expressions antigues i carrega el nou XML int expressions = EManager->getNumExpressions(); for (int i=0; i<expressions; ++i) { EManager->resetExpression((TypeExpression) i); } ReadExpressions(); } else if(strncmp(paraula,"<muscles>",9)==0) { // Elimina els muscles antics i carrega el nou XML int muscles = MManager->getNumMuscles(); for (int i=0; i<muscles;++i) { MManager->ClearMuscle((TypeMuscle) i); } EditorM->ClearVertexs(); ReadMuscles(); } fclose(fitxer); }
int main() { struct avl_table *avltree; struct bst_table *bsttree; struct rb_table *rbtree; avltree = avl_create(Compare_by_lexicographical_order, NULL, NULL); bsttree = bst_create(Compare_by_lexicographical_order, NULL, NULL); rbtree = rb_create(Compare_by_lexicographical_order, NULL, NULL); for (int i = 0; i < 32; i++) { struct word *element = (struct word *)malloc(sizeof(struct word)); ReadWord(element); #ifdef DEBUG printf("Read in word: %s, length = %d\n", element->s, element->length); #endif avl_probe(avltree, element); bst_probe(bsttree, element); rb_probe(rbtree, element); } preorder_avl(avltree->avl_root); puts(""); preorder_bst(bsttree->bst_root); puts(""); preorder_rb(rbtree->rb_root); puts(""); return 0; }
void MEndRep() { aReg[2]=ReadLong(0x2804c); reg[5]=0;/*(gKeyDown!=0)<<4;*/ QLsubr(ReadWord(0x152)+0x4000,2000000); }
// ------------------------------------------------------------------------------------------------ unsigned int ReadString(const char*& sbegin_out, const char*& send_out, const char* input, const char*& cursor, const char* end, bool long_length = false, bool allow_null = false) { const uint32_t len_len = long_length ? 4 : 1; if(Offset(cursor, end) < len_len) { TokenizeError("cannot ReadString, out of bounds reading length",input, cursor); } const uint32_t length = long_length ? ReadWord(input, cursor, end) : ReadByte(input, cursor, end); if (Offset(cursor, end) < length) { TokenizeError("cannot ReadString, length is out of bounds",input, cursor); } sbegin_out = cursor; cursor += length; send_out = cursor; if(!allow_null) { for (unsigned int i = 0; i < length; ++i) { if(sbegin_out[i] == '\0') { TokenizeError("failed ReadString, unexpected NUL character in string",input, cursor); } } } return length; }
void LearnVocabFromTrainFile() { char word[MAX_STRING]; FILE *fin; long long a, i; for (a = 0; a < vocab_hash_size; a++) vocab_hash[a] = -1; fin = fopen(train_file, "rb"); if (fin == NULL) { printf("ERROR: training data file not found!\n"); exit(1); } vocab_size = 0; AddWordToVocab((char *)"</s>"); while (1) { ReadWord(word, fin); if (feof(fin)) break; train_words++; if ((debug_mode > 1) && (train_words % 100000 == 0)) { fprintf(stderr, "%lldK%c", train_words / 1000, 13); } i = SearchVocab(word); if (i == -1) { a = AddWordToVocab(word); vocab[a].cn = 1; } else vocab[i].cn++; if (vocab_size > vocab_hash_size * 0.7) ReduceVocab(); } SortVocab(); if (debug_mode > 0) { fprintf(stderr, "Vocab size: %lld\n", vocab_size); fprintf(stderr, "Words in train file: %lld\n", train_words); } file_size = ftell(fin); fclose(fin); }
void P_ReadDemoWeaponsChunk(BYTE **demo) { int count, i; PClassWeapon *type; const char *s; count = ReadWord(demo); Weapons_ntoh.Resize(count); Weapons_hton.Clear(count); Weapons_ntoh[0] = type = NULL; Weapons_hton[type] = 0; for (i = 1; i < count; ++i) { s = ReadStringConst(demo); type = dyn_cast<PClassWeapon>(PClass::FindClass(s)); // If a demo was recorded with a weapon that is no longer present, // should we report it? Weapons_ntoh[i] = type; if (type != NULL) { Weapons_hton[type] = i; } } }
wxSimpleHtmlTag* wxSimpleHtmlParser::ParseTagHeader() { if (IsTagStartBracket(GetChar(m_pos))) { m_pos ++; EatWhitespace(); wxString word; ReadWord(word, TRUE); EatWhitespace(); wxSimpleHtmlTag* tag = new wxSimpleHtmlTag(word, wxSimpleHtmlTag_Open); ParseAttributes(tag); EatWhitespace(); if (IsTagEndBracket(GetChar(m_pos))) m_pos ++; return tag; } else return NULL; }
void ReadVocab() { long long a, i = 0; char c; char word[MAX_STRING]; FILE *fin = fopen(read_vocab_file, "rb"); if (fin == NULL) { printf("Vocabulary file not found\n"); exit(1); } for (a = 0; a < vocab_hash_size; a++) vocab_hash[a] = -1; vocab_size = 0; while (1) { ReadWord(word, fin); if (feof(fin)) break; a = AddWordToVocab(word); fscanf(fin, "%lld%c", &vocab[a].cn, &c); i++; } SortVocab(); if (debug_mode > 0) { printf("Vocab size: %lld\n", vocab_size); printf("Words in train file: %lld\n", train_words); } fin = fopen(train_file, "rb"); if (fin == NULL) { printf("ERROR: training data file not found!\n"); exit(1); } fseek(fin, 0, SEEK_END); file_size = ftell(fin); fclose(fin); }
dword GetDataSize(byte *header) { if (tapeTzx) return 0; else return ReadWord(header); }
//Get sentence by connecting the words extracted int Reader::GetSentence(int *sentence, int64 &word_count) { int length = 0, word_idx; word_count = 0; while (1) { if (!ReadWord(word_, file_)) break; word_idx = dictionary_->GetWordIdx(word_); if (word_idx == -1) continue; word_count++; if (option_->stopwords && stopwords_table_.count(word_)) continue; if (option_->sample > 0 && !sampler_->WordSampling( dictionary_->GetWordInfo(word_idx)->freq, option_->total_words, option_->sample)) continue; sentence[length++] = word_idx; if (length >= kMaxSentenceLength) break; } return length; }
Reader::Reader(Dictionary *dictionary, Option *option, Sampler *sampler, const char *input_file) { dictionary_ = dictionary; option_ = option; sampler_ = sampler; stopwords_table_.clear(); if (option_->stopwords) { FILE* fid = fopen(option_->sw_file, "r"); if (fid == nullptr) { multiverso::Log::Fatal("Open sw_file failed!\n"); exit(1); } while (ReadWord(word_, fid)) { stopwords_table_.insert(word_); } fclose(fid); } file_ = fopen(input_file, "r"); if (file_ == nullptr) { multiverso::Log::Fatal("Open train_file failed!\n"); exit(1); } }
int SkipRecord( void ){ WORD wLen; if ((wLen=ReadWord())!=0xffff){ _tlseek(wLib,wLen,1); return TRUE; }else return FALSE; }
float ReadTemp(uint8_t deviceAddr){ uint16_t data = ReadWord(deviceAddr,REG_TEMP); if( data == ERROR ){ return 0.0; } uint8_t datal = *((uint8_t*)&data); uint8_t datah = *(((uint8_t*)&data)+1); // Step a bit forward, just like using an array float Temperature = 0; if ((datah & 0x80) == 0x80){ //TA ³ TCRIT } if ((datah & 0x40) == 0x40){ //TA > TUPPER } if ((datah & 0x20) == 0x20){ //TA < TLOWER } datah = datah & 0x1F; //Clear flag bits if ((datah & 0x10) == 0x10){ //TA < 0°C datah = datah & 0x0F; //Clear SIGN Temperature = 256 - (datah * 16.0 + datal / 16.0); }else{ //TA ³ 0°C Temperature = (datah * 16.0 + datal / 16.0); //Temperature = Ambient Temperature (°C) } return Temperature; }
// Reads a word and returns its index in the vocabulary // 从文件流中读取一个词,并返回这个词在词汇表中的位置 int ReadWordIndex(FILE *fin) { char word[MAX_STRING]; ReadWord(word, fin); if (feof(fin)) return -1; return SearchVocab(word); }
/************* * DESCRIPTION: read faces of object * INPUT: - * OUTPUT: - *************/ static void ParsePoints(HANDLER_DATA *data) { VECTOR *p; int i; // read number of points ReadWord(data, (WORD *)&data->pointcount, 1); if (data->pointcount == 0) return; data->points = new VECTOR[data->pointcount]; // Allocate memory if (!data->points) { data->err = ERR_MEM; return; } ReadFloat(data, (float *)data->points, data->pointcount*3); // Read points data->TriList = (TRILIST**)malloc(sizeof(TRILIST*)*data->pointcount); if (!data->TriList) { data->err = ERR_MEM; return; } // apply transformations to the points p = data->points; for (i = 0; i < data->pointcount; i++) { data->TriList[i] = NULL; data->matrix.MultVectMat(p); p++; } }
double wxTextInputStream::ReadDouble() { if(!m_input) return 0; wxString word = ReadWord(); if(word.empty()) return 0; return wxStrtod(word.c_str(), 0); }
int ReadHdrRecord(LPBYTE lpBuffer){ if (ReadWord()!=0xffff) if (ReadName(lpBuffer)){ ReadByte(); return TRUE; } return FALSE; }
static void i80286_pop_seg(i80286_state *cpustate, int reg) { UINT16 sel; if(PM) i80286_check_permission(cpustate, SS, cpustate->regs.w[SP], I80286_WORD, I80286_READ); sel = ReadWord(cpustate->base[SS]+cpustate->regs.w[SP]); i80286_data_descriptor(cpustate, reg, sel); cpustate->regs.w[SP] += 2; }