const void Cpu::executeRegOp(const uInt op){ #if DEBUGLEVEL > 2 printf("R-op, func:%x, r%d, r%d, r%d\n", ROP_FUNC(op), OP_DST_REG(op), OP_SRC_REG(op), OP_ADD_REG(op)); #endif uInt* const dst = &mips->r[OP_DST_REG(op)]; const uInt* const add = &mips->r[OP_ADD_REG(op)]; const uInt* const src = &mips->r[OP_SRC_REG(op)]; switch (ROP_FUNC(op)){ case OPFUNC_SLL: *dst = *add << ROP_SHAM(op); break; case OPFUNC_SRL: *dst = *add >> ROP_SHAM(op); break; case OPFUNC_SRA: *dst = uInt(sInt(*add) >> ROP_SHAM(op)); break; case OPFUNC_JR: mips->pc = *src; break; case OPFUNC_MFHI: case OPFUNC_MFLO: case OPFUNC_MULT: case OPFUNC_DIV: case OPFUNC_DIVU: fatalError("Unimplemented R-op\n"); case OPFUNC_ADD: //TODO throw overflow exception case OPFUNC_ADDU: *dst = *src + *add; break; case OPFUNC_SUB: //TODO throw some exception case OPFUNC_SUBU: *dst = *src - *add; break; case OPFUNC_AND: *dst = *src & *add; break; case OPFUNC_OR: *dst = *src | *add; break; case OPFUNC_NOR: *dst = ~(*src | *add); break; case OPFUNC_SLT: *dst = (sInt(*src) < sInt(*add)) ? 1 : 0; break; case OPFUNC_SLTU: *dst = (*src < *add) ? 1 : 0; break; default: fatalError("Unknown function for R-format instruction (opcode 0)\n"); } };
void sSoundHandlerTest(sS16 *data,sInt count) { for(sInt i=0;i<count;i++) { data[0] = sInt(sFSin(((phase0)&0xffff)/65536.0f*sPI2F)*12000); data[1] = sInt(sFSin(((phase1)&0xffff)/65536.0f*sPI2F)*12000); phase0 += (mod+(mod/50))/16; phase1 += (mod+(mod/50))/16; // mod = mod+4; if(mod>0x40000) mod = 0x1000; data+=2; } }
int ArgumentParser::parseFromArgs(int argc, char* argv[]){ int cnt = 0; while(cnt < argc){ if(strcmp(argv[cnt], "--serverPort") == 0){ if(cnt + 1 < argc){ std::string sInt(argv[cnt+1]); serverPort = atoi(sInt.c_str()); Logging::getInstance()->Log(Logging::INFO, "Parsed serverPort = %d", serverPort); }else{ Logging::getInstance()->Log(Logging::ERROR, "Error parsing serverPort!"); return Error::ERROR_PARSING; } } if(strcmp(argv[cnt], "--spawnerPort") == 0){ if(cnt + 1 < argc){ this->spawnerServerPort = atoi(argv[cnt+1]); Logging::getInstance()->Log(Logging::INFO, "Parsed spawnerPort=%d", this->spawnerServerPort); }else{ Logging::getInstance()->Log(Logging::ERROR, "Error parsing spawnerPort!"); return Error::ERROR_PARSING; } } cnt++; } return Error::NO_ERROR; }
void RangeCoder::Decode(sU32 cumfreq,sU32 freq) { Low += cumfreq * Range; Range *= freq; while((Low ^ Low+Range)<sRANGETOP || Range<sRANGEBOT && ((Range = -sInt(Low) & sRANGEBOT-1),1)) { Code = (Code<<8) + Buffer[Bytes++]; Range <<= 8; Low <<= 8; } }
void TestFloat(sF32 null=0) { sCheckModule(L"Float Stuff"); CHECK(sInt(0.9f)==0); CHECK(sInt(1.0f)==1); CHECK(sInt(1.1f)==1); CHECK(sInt(1.5f)==1); CHECK(sInt(1.7f)==1); CHECK(sInt(-0.9f)==0); CHECK(sInt(-1.0f)==-1); CHECK(sInt(-1.1f)==-1); CHECK(sInt(-1.5f)==-1); CHECK(sInt(-1.7f)==-1); CHECK(!sIsInf(1.0f)); CHECK(!sIsInf(0.0f)); CHECK(!sIsNan(1.0f)); CHECK(!sIsNan(0.0f)); CHECK(sIsInf(1.0f/null)); CHECK(sIsNan(sSqrt(-1+null))); }
void RangeCoder::Encode(sU32 cumfreq,sU32 freq,sU32 totfreq) { Range /= totfreq; Low += cumfreq * Range; Range *= freq; while ((Low ^ Low+Range)<sRANGETOP || Range<sRANGEBOT && ((Range = -sInt(Low) & sRANGEBOT-1),1)) { Buffer[Bytes++] = Low>>24; Low <<= 8; Range <<= 8; } }
static void evalRangeRecurse(const frAnimationClip *clip, sInt clipStart, sInt start, sInt end, std::vector<evalItem> &evalList) { for (frAnimationClip::elementListCIt it = clip->m_elements.begin(); it != clip->m_elements.end(); ++it) { const sInt stime = fr::maximum(sInt(start) - it->relStart, 0); const sInt etime = fr::minimum(sInt(end) - it->relStart, it->len); const sInt cStart = clipStart + it->relStart; if (stime < etime) { switch (it->type) { case 0: // fcurve (evaluate last value in range) evalList.push_back(evalItem(cStart + etime, etime, it->id, it->curveID)); break; case 1: // clip (evaluate clipped range) evalRangeRecurse(g_graph->m_clips->getClip(it->id), cStart, stime, etime, evalList); break; } } } }
void sResourceManager_::SetLogFont(sInt family,const sChar *name,sInt basesize) { FontFamilies[family].Name = name; FontFamilies[family].Sizes[0] = sInt(basesize*0.70f+0.5f); FontFamilies[family].Sizes[1] = sInt(basesize*0.80f+0.5f); FontFamilies[family].Sizes[2] = basesize; FontFamilies[family].Sizes[3] = sInt(basesize*1.20f+0.5f); FontFamilies[family].Sizes[4] = sInt(basesize*1.40f+0.5f); FontFamilies[family].Sizes[5] = sInt(basesize*1.80f+0.5f); FontFamilies[family].Sizes[6] = sInt(basesize*2.50f+0.5f); }
void Wz4ChannelPerFrame::Evaluate(sF32 time,Wz4AnimKey &result) { result = Start; if(Keys>1) { time = (time / MaxTime) * (Keys-1); sInt key = sClamp<sInt>(sInt(sRoundDown(time*1024)),0,Keys*1024-1025); sF32 f = (key&1023)/1024.0f; key = key/1024; if(Scale) result.Scale.Fade(f,Scale[key+0],Scale[key+1]); if(Rot) result.Rot.Fade(f,Rot[key+0],Rot[key+1]); if(Trans) result.Trans.Fade(f,Trans[key+0],Trans[key+1]); } }
void Settings::setAccount( QString _grid, QString _name, QString _icon, QString _jid, QString _pass, bool _connectOnStart, QString _resource, QString _host, QString _port, bool manuallyHostPort) //Q_INVOKABLE { bool isNew = false; beginGroup( "accounts" ); QVariant retList = value( "accounts", QStringList() ); QStringList sl = retList.toStringList(); if( sl.indexOf(_grid) < 0 ) isNew = true; endGroup(); sStr(_name,_grid,"name"); sStr(_icon,_grid,"icon"); sStr(_jid,_grid,"jid"); sStr(_pass,_grid,"passwd"); sStr(_resource,_grid,"resource"); sStr(_host,_grid,"host"); sBool(manuallyHostPort,_grid,"use_host_port"); sBool(_connectOnStart,_grid,"connectOnStart"); bool ok = false; int p = _port.toInt(&ok); if( ok ) { sInt( p, _jid, "port" ); } if (isNew) addAccount(_grid); else { initListOfAccounts(); emit accountEdited(_grid); } }
// 检测整数 BOOL CStringChecker::CheckIntNumber(CString cStr) { char str[] = "^[\\-]?([1-9]\\d*)|0$"; CString strTemp(cStr); strTemp.Trim(' '); BOOL b = RegexMatch(strTemp, str); //BOOL b = RegexMatch(cStr, str); if(!b) { SetLastErr(TYPE_INT); return FALSE;//"整数不合规则"; } CString sInt(cStr); if (sInt == "-0") { SetLastErr(TYPE_INT); return FALSE; } return TRUE;//""; }
MyApp::MyApp() { sImage *img; Painter = new sPainter; // perlin texture sInt xs = 256; sInt ys = 256; img = new sImage; img->Init(xs,ys); for(sInt y=0;y<ys;y++) { for(sInt x=0;x<xs;x++) { sF32 p = sPerlin2D(x*(0x100000/xs),y*(0x100000/ys),3,0)*2.0f + sPerlin2D(x*(0x200000/xs),y*(0x200000/ys),7,0)*1.5f + sPerlin2D(x*(0x400000/xs),y*(0x400000/ys),15,0)*1.0f ; sInt c = sInt(128+127*sClamp(p,-1.0f,1.0f)); img->Data[y*xs+x] = c|(c<<8)|(c<<16)|0xff000000; } } Tex = sLoadTexture2D(img,sTEX_ARGB8888); delete img; CreateTorus(); // materials TorusMtrl = new TorusShader; TorusMtrl->Texture[0] = Tex; TorusMtrl->Texture[1] = Tex; TorusMtrl->TBind[1] = sMTB_VS|0; TorusMtrl->Flags = sMTRL_ZON|sMTRL_CULLOFF; TorusMtrl->Prepare(TorusFormat); }
void CAnimMixer::processMove(sInt cursorX, sInt cursorY) { updateThisClip(); if (m_thisClip && m_moveElement != -1) { sInt nsFrame = fr::maximum(0.0f, m_baseRelStart + (cursorX - m_dragPoint.x) / m_frameStep); sInt nTrack = fr::clamp(m_baseTrack + sInt(cursorY - m_dragPoint.y) / 22, 0, m_maxTrack); frAnimationClip::element& elem = m_thisClip->m_elements[m_moveElement]; nsFrame = performSnap(m_moveElement, nsFrame); if (nsFrame != elem.relStart || nTrack != elem.trackID) { elem.updateLen(); CRect rc1, rc2; getElemRect(m_moveElement, rc1); elem.relStart = nsFrame; elem.trackID = nTrack; getElemRect(m_moveElement, rc2); CRgn rgn1, rgn2; rgn1.CreateRectRgnIndirect(&rc1); rgn2.CreateRectRgnIndirect(&rc2); rgn1.CombineRgn(rgn1, rgn2, RGN_DIFF); InvalidateRgn(rgn1, TRUE); UpdateWindow(); // erasebackground is a per-region flag, so we need to paint twice InvalidateRect(&rc2, FALSE); UpdateWindow(); clipChanged(); } } }
void sFont2D::PrintMarked(sInt flags,const sRect *rc,sInt x,sInt y,const sChar *text,sInt len,sPrintInfo *pi) { if(len==-1) len=sGetStringLen(text); sVERIFY(rc); sVERIFY(pi); sRect r(*rc); const sChar *ot = text; sInt ol = len; sInt ox = x; sBool nocull = 0; switch(pi->Mode) { case sPIM_PRINT: nocull = pi->CullRect.IsEmpty() || rc->IsInside(pi->CullRect); if(pi->SelectStart<len && pi->SelectEnd>0 && pi->SelectEnd>pi->SelectStart) { sInt i = pi->SelectStart; if(i>0) { r.x1 = x + GetWidth(text,i); PrintBasic(flags,&r,x,y,text,i); r.x0 = x = r.x1; len -= i; pi->SelectEnd -= i; pi->SelectStart -= i; text += i; } sU32 oldbackcolor=prv->BackColor; if (pi->SelectBackColor!=~0) prv->BackColor=BrushColor[pi->SelectBackColor]; else sSwap(prv->TextColor,prv->BackColor); i = sMin(pi->SelectEnd,len); r.x1 = x + GetWidth(text,i); if(nocull) PrintBasic(flags,&r,x,y,text,i); r.x0 = x = r.x1; len -= i; pi->SelectEnd -= i; pi->SelectStart -= i; text += i; if (pi->SelectBackColor!=~0) prv->BackColor=oldbackcolor; else sSwap(prv->TextColor,prv->BackColor); } if(nocull) { r.x1 = x + GetWidth(text,len); PrintBasic(flags,&r,x,y,text,len); if(flags & sF2P_OPAQUE) { r.x0 = x = r.x1; r.x1 = rc->x1; if(pi->HintLine && pi->HintLine>=r.x0 && pi->HintLine+2<=r.x1) { r.x1 = pi->HintLine; sRect2D(r,prv->BackPen); r.x0 = r.x1; r.x1 = r.x0+2; sRect2D(r,pi->HintLineColor); r.x0 = r.x1; r.x1 = rc->x1; } sRect2D(r,prv->BackPen); } } if(pi->CursorPos>=0 && pi->CursorPos<=ol && pi->Mode==sPIM_PRINT) { sInt t = GetWidth(ot,pi->CursorPos); sInt w = 2; if(pi->Overwrite) { if(pi->CursorPos<ol) w = GetWidth(ot+pi->CursorPos,1); else w = GetWidth(L" ",1); } sRectInvert2D(ox+t,rc->y0,ox+t+w,rc->y1); } break; case sPIM_POINT2POS: if(pi->QueryY>=rc->y0 && pi->QueryY<rc->y1) { x = ox; sInt i; for(i=0;i<len;i++) { x += GetWidth(ot+i,1); if(pi->QueryX < x) break; } pi->QueryPos = ot+i; pi->Mode = sPIM_QUERYDONE; } break; case sPIM_POS2POINT: if(pi->QueryPos>=ot && pi->QueryPos<=ot+len) { pi->QueryY = rc->y0; pi->QueryX = ox+GetWidth(ot,sInt(pi->QueryPos-ot)); } break; } }
void RNFR067_IsoSplash::Prepare(Wz4RenderContext *ctx) { for(sInt i=0;i<4;i++) { if(Mtrl[i]) Mtrl[i]->BeforeFrame(Para.LightEnv); } SphereEnable = (Para.SphereAmp!=0.0f); SphereAmp.x = 1.0f / Para.SphereDirections.x; SphereAmp.y = 1.0f / Para.SphereDirections.y; SphereAmp.z = 1.0f / Para.SphereDirections.z; SphereAmp = SphereAmp * SphereAmp; CubeEnable = (Para.CubeAmp!=0.0f); CubeAmp.x = 1.0f / Para.CubeDirections.x; CubeAmp.y = 1.0f / Para.CubeDirections.y; CubeAmp.z = 1.0f / Para.CubeDirections.z; NoiseEnable = (Para.NoiseAmp1!=0.0f) || (Para.NoiseAmp2!=0.0f); NoiseFreq1 = Para.NoiseFreq1*0x10000; NoisePhase1 = Para.NoisePhase1*0x10000; NoiseAmp1 = Para.NoiseAmp1; NoiseFreq2 = Para.NoiseFreq2*0x10000; NoisePhase2 = Para.NoisePhase2*0x10000; NoiseAmp2 = Para.NoiseAmp2; RotEnable = 0; RubberEnable = 0; if(Para.Rot.x!=0 || Para.Rot.y!=0 || Para.Rot.z!=0) RotEnable = 1; if(Para.Rubber.x!=0 || Para.Rubber.y!=0 || Para.Rubber.z!=0) RotEnable = RubberEnable = 1; PolarEnable = (Para.PolarAmp!=0.0f); for(sInt i=0;i<Size;i++) { sF32 py = sF32(i-1)/sF32((1<<Para.OctreeDivisions)*8); RubberMat[i].EulerXYZ((Para.Rot.x+Para.Rubber.x*py)*sPI2F, (Para.Rot.y+Para.Rubber.y*py)*sPI2F, (Para.Rot.z+Para.Rubber.z*py)*sPI2F); } sF32 f = 1.0f/((1<<Para.OctreeDivisions)*8); for(sInt y=0;y<Size;y++) { for(sInt x=0;x<Size;x++) { sF32 px = (x-1)*f*2-1; sF32 py = (y-1)*f*2-1; NoiseXY[Size*y+x] = NoiseAmp1*sPerlin2D(sInt(px*NoiseFreq1.x+NoisePhase1.x), sInt(py*NoiseFreq1.y+NoisePhase1.y),255,Para.NoiseSeed1) + NoiseAmp2*sPerlin2D(sInt(px*NoiseFreq2.x+NoisePhase2.x), sInt(py*NoiseFreq2.y+NoisePhase2.y),255,Para.NoiseSeed2); NoiseYZ[Size*y+x] = NoiseAmp1*sPerlin2D(sInt(px*NoiseFreq1.y+NoisePhase1.y), sInt(py*NoiseFreq1.z+NoisePhase1.z),255,Para.NoiseSeed1) + NoiseAmp2*sPerlin2D(sInt(px*NoiseFreq2.y+NoisePhase2.y), sInt(py*NoiseFreq2.z+NoisePhase2.z),255,Para.NoiseSeed2); NoiseZX[Size*y+x] = NoiseAmp1*sPerlin2D(sInt(px*NoiseFreq1.z+NoisePhase1.z), sInt(py*NoiseFreq1.x+NoisePhase1.x),255,Para.NoiseSeed1) + NoiseAmp2*sPerlin2D(sInt(px*NoiseFreq2.z+NoisePhase2.z), sInt(py*NoiseFreq2.x+NoisePhase2.x),255,Para.NoiseSeed2); PolarPhi[Size*y+x] = sFSin(sATan2(px,py)*Para.PolarXZ*0.5f); } } // do it MakeNodes(); March(); sAABBoxC box; sF32 s = Para.GridSize/2.0f; box.Radius.Init(s,s,s); box.Center.Init(0,0,0); for(sInt i=0;i<4;i++) if(Mtrl[i]) Mtrl[i]->BeforeFrame(Para.LightEnv,1,&box,Matrices.GetCount(),Matrices.GetData()); }
void MyApp::OnPaint3D() { sRandom rnd; sVertexSingle *vp; // set rendertarget sSetRendertarget(0,sCLEAR_ALL,0xff405060); // get timing Timer.OnFrame(sGetTime()); sInt time = Timer.GetTime(); // set camera View.SetTargetCurrent(); View.SetZoom(1.7f); // View.Model.EulerXYZ(time*0.0011f,time*0.0013f,time*0.0015f); View.Model.l.Init(0,0,0); View.Camera.l.Init(0,0,-4); View.Prepare(); View.Set(); // set material sCBuffer<sSimpleMaterialEnvPara> cb; cb.Data->Set(Env); // begin for(sInt i=0;i<4;i++) Geo[i]->BeginQuadrics(); // grid Geo[0]->BeginGrid((void **) &vp,65,65); for(sInt y=-32;y<=32;y++) { for(sInt x=-32;x<=32;x++) { sF32 px,py,fx,fy; fx = x/32.0f; fy = y/32.0f; px = x/16.0f + sFSin(x*0.10f+y*0.12f+time*0.0011f)*0.1f; py = y/16.0f + sFSin(x*0.11f+y*0.13f+time*0.0011f)*0.1f; vp->Init(px,py,0,0xff808080,fx,fy); vp++; } } Geo[0]->EndGrid(); // some random quads sInt max = sInt((sFSin(time*0.004f)+2)*64); for(sInt i=0;i<max;i++) { sF32 x,y,s; sInt r; x = sFSin(i*0.10f+time*0.0011f); y = sFCos(i*0.12f+time*0.0014f); s = 0.1f; r = rnd.Int(4); Geo[r]->BeginQuad((void **) &vp,1); vp[0].Init(x-s,y-s,0, ~0, 0,0); vp[1].Init(x+s,y-s,0, ~0, 1,0); vp[2].Init(x+s,y+s,0, ~0, 1,1); vp[3].Init(x-s,y+s,0, ~0, 0,1); Geo[r]->EndQuad(); } // end and draw for(sInt i=0;i<4;i++) Geo[i]->EndQuadrics(); for(sInt i=0;i<4;i++) { Mtrl[i]->Set(&cb); Geo[i]->Draw(); } // debug output sF32 avg = Timer.GetAverageDelta(); Painter->SetTarget(); Painter->Begin(); Painter->SetPrint(0,~0,2); Painter->PrintF(10,10,L"%5.2ffps %5.3fms",1000/avg,avg); Painter->End(); }
sChar *DebugInfo::WriteReport() { sChar *Report; sInt i,j; sU32 size; sF32 pSize; Report = ReportBuffer; sSPrintF(Report,512,sAPPNAME " " sVERSION " >> pack ratio report\n\n"); Report += sGetStringLen(Report); sSPrintF(Report,512,"Functions by packed size:\n"); Report += sGetStringLen(Report); std::sort(&Symbols[0],&Symbols[Symbols.Count],symPackedSizeComp); for(i=0;i<Symbols.Count;i++) { if(Symbols[i].Class == DIC_CODE) { sSPrintF(Report,512,"%5d.%02d/%8d: %-50s %s\n", (sInt) Symbols[i].PackedSize,sInt(Symbols[i].PackedSize*100)%100, Symbols[i].Size,Symbols[i].Name,Files[Symbols[i].FileNum].Name); Report += sGetStringLen(Report); } } sSPrintF(Report,512,"\nData by packed size:\n"); Report += sGetStringLen(Report); for(i=0;i<Symbols.Count;i++) { if(Symbols[i].Class == DIC_DATA) { sSPrintF(Report,512,"%5d.%02d/%8d: %-50s %s\n", (sInt) Symbols[i].PackedSize,sInt(Symbols[i].PackedSize*100)%100, Symbols[i].Size,Symbols[i].Name,Files[Symbols[i].FileNum].Name); Report += sGetStringLen(Report); } } sSPrintF(Report,512,"\nFunctions by object file and packed size:\n"); Report += sGetStringLen(Report); for(i=1;i<Symbols.Count;i++) for(j=i;j>0;j--) { sInt f1 = Symbols[j].FileNum; sInt f2 = Symbols[j-1].FileNum; if(f1 == -1 || f2 != -1 && sCmpStringI(Files[f1].Name.String,Files[f2].Name.String) < 0) sSwap(Symbols[j],Symbols[j-1]); } for(i=0;i<Symbols.Count;i++) { if(Symbols[i].Class == DIC_CODE) { sSPrintF(Report,512,"%5d.%02d/%8d: %-50s %s\n", (sInt) Symbols[i].PackedSize,sInt(Symbols[i].PackedSize*100)%100, Symbols[i].Size,Symbols[i].Name,Files[Symbols[i].FileNum].Name); Report += sGetStringLen(Report); } } sSPrintF(Report,512,"\nClasses/Namespaces by packed size:\n"); Report += sGetStringLen(Report); std::sort(&NameSps[0],&NameSps[NameSps.Count],namePackedSizeComp); for(i=0;i<NameSps.Count;i++) { sSPrintF(Report,512,"%5d.%02d/%8d: %s\n",sInt(NameSps[i].PackedSize), sInt(NameSps[i].PackedSize*100)%100,NameSps[i].Size,NameSps[i].Name); Report += sGetStringLen(Report); } sSPrintF(Report,512,"\nObject files by packed size:\n"); Report += sGetStringLen(Report); std::sort(&Files[0],&Files[Files.Count],filePackedSizeComp); for(i=0;i<Files.Count;i++) { sSPrintF(Report,512,"%5d.%02d/%8d: %s\n",sInt(Files[i].PackedSize), sInt(Files[i].PackedSize*100)%100,Files[i].Size,Files[i].Name); Report += sGetStringLen(Report); } size = 0; pSize = 0.0f; for(i=0;i<Symbols.Count;i++) { if(Symbols[i].Class == DIC_CODE) { size += Symbols[i].Size; pSize += Symbols[i].PackedSize; } } sSPrintF(Report,512,"\nOverall code: %5d.%02d/%8d\n",sInt(pSize), sInt(pSize*100)%100,size); Report += sGetStringLen(Report); size = 0; pSize = 0.0f; for(i=0;i<Symbols.Count;i++) { if(Symbols[i].Class == DIC_DATA) { size += Symbols[i].Size; pSize += Symbols[i].PackedSize; } } sSPrintF(Report,512,"Overall data: %5d.%02d/%8d\n",sInt(pSize), sInt(pSize*100)%100,size); Report += sGetStringLen(Report); return sDupString(ReportBuffer,1); }
sINLINE sInt sDivShift12(sInt var_a,sInt var_b) { return sInt((sS64(var_a) << 12) / var_b); }
void Init(sF32 PX,sF32 PY,sF32 PZ,sF32 NX,sF32 NY,sF32 NZ) { px=PX; py=PY; pz=PZ; n[0]=sInt((NX+1)*127); n[1]=sInt((NY+1)*127); n[2]=sInt((NZ+1)*127); n[3]=0; }
void s3DWindow::CmdGearShift(sDInt n) { GearShift = sClamp(GearShift+sInt(n),-40,40); GearShiftDisplay = sGetTime()+500; }
const void Cpu::executeImmOp(const uInt op){ #if DEBUGLEVEL > 2 printf("I-op, op:%x, r%d, r%d, imm:%x\n", GET_OPCODE(op), OP_SRC_REG(op), OP_ADD_REG(op), GET_IMM(op)); #endif uInt* const add = &mips->r[OP_ADD_REG(op)]; const uInt* const src = &mips->r[OP_SRC_REG(op)]; const uInt pmem = *src + GET_IMMSGN(op); switch (GET_OPCODE(op)){ case OPCODE_BEQ: mips->pc += (*src == *add) ? GET_IMMSGN(op)*4 : 0; break; case OPCODE_BNE: mips->pc += (*src != *add) ? GET_IMMSGN(op)*4 : 0; break; case OPCODE_ADDI: //TODO throw overflow exception case OPCODE_ADDIU: *add = *src + GET_IMMSGN(op); break; case OPCODE_MFC: fatalError("Unimplemented I-op\n"); case OPCODE_FP: fatalError("In executeImmOp, but found FP-op!\n"); case OPCODE_SLTI: *add = (sInt(*src) < GET_IMMSGN(op)) ? 1 : 0; break; case OPCODE_SLTIU: *add = (*src < GET_IMMSGN(op)) ? 1 : 0; break; case OPCODE_ANDI: *add = *src & GET_IMM(op); break; case OPCODE_ORI: *add = *src | GET_IMM(op); break; case OPCODE_LUI: *add = GET_IMM(op); break; case OPCODE_LW: *add = mem->get<uInt>(pmem); break; case OPCODE_LD: fatalError("Unimplemented I-op\n"); case OPCODE_LBU: *add = mem->get<uChar>(pmem); break; case OPCODE_LHU: *add = mem->get<uShort>(pmem); break; case OPCODE_SB: mem->set(pmem, uChar(*add)); break; case OPCODE_SH: mem->set(pmem, uShort(*add)); break; case OPCODE_LL: fatalError("Unimplemented I-op\n"); case OPCODE_SW: mem->set(pmem, *add); break; default: fatalError("Unknown I-op instruction\n"); } };
void RPCServer::ThreadFunc(sThread *t) { while (t->CheckTerminate()) { sTCPSocket *reads[100], *writes[100], *newconn; sInt nReads = 0, nWrites = 0; Connection *conn; sFORALL_LIST(Connections, conn) { reads[nReads++] = conn->Socket; if (!conn->OutBuffers.IsEmpty()) writes[nWrites++] = conn->Socket; } if (Socket.WaitForEvents(nReads,reads,nWrites,writes,&newconn,100)) { if (newconn) { conn = new Connection; conn->Socket = newconn; Connections.AddTail(conn); } // handle incoming data for (int i=0; i<nReads; i++) { sFORALL_LIST(Connections,conn) if (conn->Socket == reads[i]) { sDInt read; Buffer *buf = conn->InBuffers.IsEmpty()?0:conn->InBuffers.GetTail(); if (!buf || buf->Count == Buffer::SIZE) { buf = new Buffer; conn->InBuffers.AddTail(buf); } sBool ret = conn->Socket->Read(buf->Data+buf->Count,Buffer::SIZE-buf->Count,read); // close connection? if (!ret || read==0) { Connections.Rem(conn); sDelete(conn); break; } else { // add to in buffer buf->Count+=(sInt)read; // seach for end marker const sU8 *patptr = (const sU8*)"\n\r\n\r"; const sU8 *bufptr = buf->Data+buf->Count; for (;;) { if (*--bufptr != *patptr) break; if (!*++patptr) break; if (bufptr == buf->Data) { if (buf == conn->InBuffers.GetHead()) break; buf = conn->InBuffers.GetPrev(buf); bufptr = buf->Data+buf->Count; } } if (!*patptr) { OnMessage(conn, buf, bufptr); sDeleteAll(conn->InBuffers); } } break; } } // handle outgoing data for (int i=0; i<nWrites; i++) { sFORALL_LIST(Connections,conn) if (conn->Socket == writes[i]) { Buffer *buf = conn->OutBuffers.GetHead(); sDInt written = 0; sBool ret = conn->Socket->Write(buf->Data, buf->Count, written); // close connection? if (!ret) { Connections.Rem(conn); sDelete(conn); break; } else { if (written<buf->Count) sMoveMem(buf->Data, buf->Data+written, sInt(buf->Count-written)); buf->Count-=(sInt)written; if (!buf->Count) { conn->OutBuffers.RemHead(); delete buf; } // close connection after sending it all out if (conn->OutBuffers.IsEmpty()) { Connections.Rem(conn); sDelete(conn); } } break; } } } }
sInt sFont2D::Print(sInt flags,const sRect &r,const sChar *text,sInt len,sInt margin,sInt xo,sInt yo,sPrintInfo *pi) { if(len==-1) len=sGetStringLen(text); sInt x,y; sPrintInfo pil; const sChar *textstart=text; sInt result; sRect r2(r); pil.Init(); if(pi) { pil = *pi; } pil.CursorPos = -1; pil.Overwrite = 0; pil.SelectStart = -1; pil.SelectEnd = -1; r2.Extend(-margin); x = r2.x0 + xo; y = r2.y0 + yo; sInt xs = r2.SizeX(); sInt h = GetHeight(); sRect rs(r); result = rs.y0; if(pil.Mode==sPIM_POINT2POS && pil.QueryY<y) { pi->Mode = sPIM_QUERYDONE; pi->QueryPos = text; return result; } if(flags & sF2P_MULTILINE) { const sChar *textend = text+len; for(;;) { sInt i=0; sInt best = 0; if(pi) { pil.CursorPos = pi->CursorPos - sInt(text-textstart); pil.Overwrite = pi->Overwrite; pil.SelectStart = pi->SelectStart - sInt(text-textstart); pil.SelectEnd = pi->SelectEnd - sInt(text-textstart); } for(;;) { while(text+i<textend && text[i]!=' ' && text[i]!='\n') i++; if(GetWidth(text,i)>xs) break; best = i; if(text[i]=='\n') break; if(text+i>=textend) break; i++; } if(best==0) { i = 0; while(text+i<textend && text[i]!=' ' && text[i]!='\n' && GetWidth(text,i)<=xs) i++; best = i-1; if(best<1 && text<textend && text[0]!=' ' && text[0]!='\n') best = 1; if(best<0) best = 0; else if(pil.CursorPos>=best) pil.CursorPos = -1; } rs.y1 = y + h; sRect rclip = rs; rclip.And(r); PrintMarked(flags,&rclip,x,y,text,best,&pil); rs.y0 = rs.y1; text+=best; if(text>=textend) break; y+=h; if(text[0]==' ' || text[0]=='\n') text++; } if(pil.Mode == sPIM_POS2POINT && pil.QueryPos == text) // query was to end of document? { pil.QueryX = x; pil.QueryY = y; } result = y+h+margin; rs.y1 = r.y1; if(rs.y1>rs.y0 && pil.Mode==sPIM_PRINT && (flags & sF2P_OPAQUE)) { sRect r(rs); if(pil.HintLine && pil.HintLine>=r.x0 && pil.HintLine+2<=r.x1) { r.x1 = pil.HintLine; sRect2D(r,prv->BackPen); r.x0 = r.x1; r.x1 = r.x0+2; sRect2D(r,pil.HintLineColor); r.x0 = r.x1; r.x1 = rs.x1; } sRect2D(r,prv->BackPen); } if(pi) { pi->QueryPos = pil.QueryPos; pi->QueryX = pil.QueryX; pi->QueryY = pil.QueryY; pi->Mode = pil.Mode; } } else { sInt space=0; if(flags & sF2P_SPACE) space = GetWidth(L" "); if(flags & sF2P_LEFT) { x = r2.x0 + space; } else if(flags & sF2P_RIGHT) { x = r2.x1 - GetWidth(text,len) - space; } else { x = (r2.x0 + r2.x1 - GetWidth(text,len))/2; } if(flags & sF2P_TOP) { y = r2.y0; } else if(flags & sF2P_BOTTOM) { y = r2.y1 - h; } else { y = (r2.y0 + r2.y1 - h)/2; } if(pi) { sPrintInfo pi2 = *pi; PrintMarked(flags,&r,x+xo,y+yo,text,len,&pi2); if(pi->Mode) { pi->QueryPos = pi2.QueryPos; pi->QueryX = pi2.QueryX; pi->QueryY = pi2.QueryY; } } else { PrintBasic(flags,&r,x,y,text,len); } result = y+h; } return result; }