void printf(char *fmt, ...) { unsigned short bp; char **cp; char *fmtStr; int *ip; char tmp; bp = getbp(); //printf("bp = %x\n", bp); // For testing cp = (char**)(bp+4); //printf("cp = %x, *cp = %c\n", cp, **cp); // For testing fmtStr = *cp; //printf("fmtStr = %s", fmtStr); ip = (uint16_t *)(bp+6); //printf("ip = %x\n", ip); // For testing while(*fmtStr != 0) { if(*fmtStr == '%') { fmtStr++; switch(*fmtStr) { case 'c': tmp = (char)*ip; putc(tmp); break; case 's': prints((char *)(*ip)); break; case 'd': printd((int)*ip); break; case 'x': printx((uint16_t)*ip); break; case 'u': printu((uint16_t)*ip); break; case 'l': ip++; printu((uint32_t)*ip); break; default: prints(" Invalid format specifier "); break; } //fflush(stdout); ip++; } else { putc(*fmtStr); //fflush(stdout); if(*fmtStr == '\n') { putc('\r'); } } fmtStr++; } }
int sdSendCommand( unsigned int commandNum, unsigned int arg ) { EMMCCommand currentCommand = sdCommandTable[commandNum]; printu(currentCommand.name); return 0; }
int printf(char *fmt, ...) { char *cp = fmt; //cp points to the fmt string u16 *ip = (u16 *) &fmt + 1; //ip points to the first item u32 *up; while(*cp){ if(*cp != '%'){ putc(*cp); if(*cp=='\n') putc('\r'); cp++; continue; } cp++; switch(*cp){ case 'c' : putc(*ip); break; case 's' : prints(*ip); break; case 'u' : printu(*ip); break; case 'd' : printd(*ip); break; case 'x' : printx(*ip); break; } cp++; ip++; } }
//======================================================== //显示汉字 //======================================================== void putstring(char a,char b,char *n) //汉字 { idata char i,*p; printu(n); while(*n!=0) { p=q+12*(*n-32); setpage(a+1); setaddr(b); for(i=0;i<6;i++) {x(*p); p++;} setpage(a); setaddr(b); for(i=6;i<12;i++) {x(*p); p++;} b = b+7; if((b + 7) > 127) { b = 0; if(a < 2 ) break; else a -= 2; } n++; } }
main(int argc, char* argv[]){ int k,n,i,j; std::string op=argv[1], prob=argv[3]; std::istringstream tin(argv[2]); val t; tin>>t; val dx=1.0/K, dt=(val)T/N, xk, tn, tmp; val R=NU*dt/dx; // R = NU*dt/dx val alpha, beta; static banded_matrix<val> U(K+2, K+2, 2, 4); vector<fortran_int_t> p(K+2); static vec u(K+2), w(K+2), z(K+2), v(K+2); if(prob=="a"){ // Tridiagonal Matrix U for(i=0; i<U.size1(); i++){ U(i,i)=1.0-R-2*r; k=std::max(i-1,0); U(k,k+1)=r; U(k+1,k)=R+r; } // Boundary Conditions U(0,0)+=r; U(K+1,K+1)+=(R+r); w(0)=1.0; w(K+1)=-1.0; z(0)=r; z(K+1)=-(R+r); // Sherman-Morrison } // Test Boundary Conditions if(op=="test"){ mat wzt = outer_prod(w, z); mat B = U - wzt; printf("Matrix Q1\n"); matprintf(B); printf("Matrix B\n"); matprintf(U); printf("Matrix wz^T\n"); matprintf(wzt); } // Initial conditions for(k=0;k<u.size();k++){ xk=k*dx; u(k)=f(xk); } lapack::gbtrf(U, p); // LU-decompostion lapack::gbtrs(U, p, w); //B^-1w alpha=1.0/(1.0-inner_prod(z, w)); // alpha = 1/(1-z^T(b^-1w)) for(n=0;n<=N;n++){ tn=n*dt; lapack::gbtrs(U, p, u); // B^-1u beta=alpha*inner_prod(z, u); // beta = alpha*z^T(B^-1u) u+=beta*w; if(op=="pipe") plotu(u, tn, K); if(op=="approx" && tn==t) printu(u, tn, K); } return 0; }
void printf(char * frmt,...){ int i; char *p, *s, buf[1024]; va_list argp; va_start(argp, frmt); for(p=frmt; *p!='\0';p++) if(*p=='%'){ p++; //skip the first % sign switch(*p){ case 'c': putc(va_arg(argp,char)); break; case 's': prints(va_arg(argp,char *)); break; case 'o': printo(va_arg(argp,u16)); break; case 'u': printu(va_arg(argp,u16)); break; case 'x': printx(va_arg(argp,u16)); break; case 'd': printd(va_arg(argp,int)); break; case 'l': printl(va_arg(argp,u32)); break; case '%': putc('%'); break; } } else{ switch(*p){ case '\n': putc(*p);putc('\r'); break; case '\t': for(i=0;i<TAB_SPACE_COUNT;i++)putc(' '); break; default: putc(*p); break; } } va_end(argp); }
int printf(char *fmt) { char *cp; u16 *ip; u32 *up; cp = fmt; ip = (int *)&fmt + 1; while (*cp){ if (*cp != '%'){ putc(*cp); if (*cp=='\n') putc('\r'); cp++; continue; } cp++; switch(*cp){ case 'c' : putc (*ip); break; case 's' : prints(*ip); break; case 'u' : printu(*ip); break; case 'd' : printd(*ip); break; case 'x' : printx(*ip); break; case 'l' : printl(*(u32 *)ip++); break; // print long value in decimal case 'X' : printX(*(u32 *)ip++); break; // print long value in hex } cp++; ip++; } }
void printf(char * fmt, ...){ char *cp = fmt; // let cp point at the fmt string u16 *ip = (int *)&fmt + 1; // ip points at first item to be printed on stack u32 *up; // for getting LONG parameter off stack char flag; while(*cp != '\0'){ if(*cp == '%'){ // We need to format print flag = *(cp+1); // Now switch on the flag character to see what type of variable we are printing switch(flag){ case 'c': putc(*ip); break; case 's': prints(*ip); break; case 'u': if(*ip >= 0){ printu(*ip); }else{ prints("The %d format must be SIGNED\n\r"); } break; case 'd': printd(*ip); break; case 'x': BASE = 16; printd(*ip); BASE = 10; break; case 'l': up = (u32 *)ip; // Since this is a long, we cast it as a u32 printd(*up); // Increment an extra 2 bytes for LONGS ip++; break; } ip = (u16 *)ip + 1; // Increment the stack watcher by 2-bytes every time cp++; }else if(*cp == '\n'){ putc(*cp); putc('\r'); }else{ putc(*cp); // Just print the raw character } cp++; // Advance to the next character in fmt } return; }
int printd(int x) { if (x<0){ putc('-'); x = -x; } printu(x); }
void myprintf(char *fmt, ...) { // char *cp = fmt; int *ip; char *cp; cp=fmt; /*while(cp != '\0') // iterate through fmt string until end of string { cp++; } cp++; // step over null character */ asm("movl %ebp, FP"); // assign ip to the next parameter after fmt string // ip = FP + 3; // moves the ip pointer over the fp, pc, and fmt ip = FP + 2; while(*cp != '\0') { if(*cp == '%') { cp++; ip++; if(*cp == 'c') { putchar(*ip); } else if(*cp == 's') { prints((char *)(*ip)); } else if(*cp == 'u') { printu(*ip); } else if(*cp == 'd') { printd(*ip); } else if (*cp == 'o') { printo(*ip); } else if(*cp == 'x') printx(*ip); } else if(*cp == '\n') putchar('\n'); putchar('\r'); else { putchar(*cp); } cp++; }
void printu(unsigned int n, unsigned int b) { unsigned int a; a = n / b; if (a != 0) { printu(a, b); } putchar("0123456789ABCDEF"[n % b]); }
int printf(char *fmt, ...) { char *c = fmt; int *param = &fmt + 1; while(*c) { if(*c != '%') { putc(*c); if(*c == '\n') putc('\r'); } else { c++; switch(*c) { case 'd': printd(*param++); //param++; break; case 's': prints(*param++); //param++; break; case 'c': putc(*param++); //param++; break; case 'o': printo(*param++); //param++; break; case 'x': printx(*param++); break; case 'u': printu(*param++); break; default: c--; putc(*c); } } c++; } }
/* * Output a number in a given base. */ static void printu(unsigned long n, unsigned long b, Bool upperCase) { unsigned long a; a = n / b; if (a != 0) { printu(a, b, upperCase); } if (upperCase) { charOut("0123456789ABCDEF"[n % b]); } else { charOut("0123456789abcdef"[n % b]); } }
int myprintf(char *fmt, ...) // SOME C compiler requires the 3 DOTsint a, int b, int c, int d { int *ip; char *cp; printf("&cp = %8x\n", &cp); cp = fmt; printf("adress of fmt=%8x\n", &fmt); ip =(&fmt)+1; /*printf("&cp = %8x\n", &cp); printf("*cp = %c\n", *cp); printf("ip = %8x\n", ip); */ printf("*ip = %d\n", *ip); for (cp ;*cp != '\0'; cp++){ if (*cp != '%'){ putchar(*cp); continue; } if(*cp == '\n'){ putchar(*cp); putchar('\r'); continue; } else{ switch(*++cp){ case 'c' : putchar(*ip); break; case 's' : putchar(*ip); break; case 'u' : printu(*ip); break; case 'd' : printd(*ip); break; case 'o' : printo(*ip); break; case 'x' : printx(*ip); break; } } ip--; } printf("\n"); }
/* Put all your code here */ void main(void) { /* Initialize the 8bpp graphics */ gfx_Begin( gfx_8bpp ); gfx_FillScreen( gfx_black ); /* Setup the colors */ gfx_SetTextFGColor( gfx_white ); /* Set the transparent text background color */ gfx_SetTextBGColor( TRANSPARENT_COLOR ); gfx_SetTextTransparentColor( TRANSPARENT_COLOR ); gfx_SetMonospaceFont( FONT_WIDTH ); /* Print some upside down text */ printu(my_str, (LCD_WIDTH - gfx_GetStringWidth(my_str)) / 2, (LCD_HEIGHT - gfx_FontHeight()) / 2); /* Wait for key */ while(!os_GetCSC()); /* Usual cleanup */ gfx_End(); prgm_CleanUp(); }
/*-----------------------------------------------------------------------------------*/ int main(void) { idata u8_t i, arptimer; idata u16_t j; // idata int i; InitGraphic();//putchar(0,62,0); //while(1) for(i=0;i<100;i++) { putstring(6,0, "Welcome to http://shop34480016.taobao.com www.dianshijin.cn"); } init_uart(); printu("starting......\r\n"); /* Initialize the device driver. */ // rtl8019as_init(); dev_init(); uip_arp_init(); /* Initialize the uIP TCP/IP stack. */ uip_init(); printu("11111111111111111111111\r\n"); /* Initialize the HTTP server. */ // httpd_init(); tcp_server_init(); arptimer = 0; printu("222222222222222222222222222\r\n"); while(1) { /* Let the tapdev network device driver read an entire IP packet into the uip_buf. If it must wait for more than 0.5 seconds, it will return with the return value 0. If so, we know that it is time to call upon the uip_periodic(). Otherwise, the tapdev has received an IP packet that is to be processed by uIP. */ uip_len = dev_poll(); for(j=0;j<500;j++); /* if(uip_len > 0) { printuf("--------------- uip_len = 0x%x", uip_len); printuf("%x ----------\r\n", uip_len); for(i=0;i<uip_len;i++) { printuf("%x ", uip_buf[i]); if((i+1)%16==0) printu("\r\n"); } printu("\r\n"); } */ if(uip_len == 0) { for(i = 0; i < UIP_CONNS; i++) { uip_periodic(i); /* If the above function invocation resulted in data that should be sent out on the network, the global variable uip_len is set to a value > 0. */ if(uip_len > 0) { uip_arp_out(); dev_send(); } } #if UIP_UDP for(i = 0; i < UIP_UDP_CONNS; i++) { uip_udp_periodic(i); /* If the above function invocation resulted in data that should be sent out on the network, the global variable uip_len is set to a value > 0. */ if(uip_len > 0) { uip_arp_out(); dev_send(); } } #endif /* UIP_UDP */ /* Call the ARP timer function every 10 seconds. */ if(++arptimer == 20) { uip_arp_timer(); arptimer = 0; } } else { if(BUF->type == htons(UIP_ETHTYPE_IP)) { uip_arp_ipin(); uip_input(); /* If the above function invocation resulted in data that should be sent out on the network, the global variable uip_len is set to a value > 0. */ if(uip_len > 0) { uip_arp_out(); dev_send(); } } else if(BUF->type == htons(UIP_ETHTYPE_ARP)) { uip_arp_arpin(); /* If the above function invocation resulted in data that should be sent out on the network, the global variable uip_len is set to a value > 0. */ if(uip_len > 0) { dev_send(); } } } } return 0; }
int printx(u16 x) { BASE = 16; printu(x); BASE = 10; }
int myprintf(char *fmt, ...) { //for most instructions that reference memory you must move it to/from a register, since we have an offset of 4 bytes we move into ecx //ecx is called the counter register. It is used as a loop counter and for shifts, in this case shift. //asm("movl 8(%ebp), %ecx"); //asm("movl %ecx, cp"); //^ can do it either way asm("movl %ebp, ip"); ip += 2; cp = (char *) *ip; asm("movl %ebp, ip"); ip += 3; // + 12 bytes to get to first parameter while(*cp != 0){ if(*cp == '%' && *(cp+1) != 0){ //check that cp+1 isn't the end of the string. i.e if you have a string "you got 100%" switch(*(cp + 1)){ case 'c': putchar(*ip); cp += 2; ip++; break; case 's': prints((char *)*ip); cp += 2; ip++; break; case 'u': printu(*ip); cp += 2; ip++; break; case 'd': printd(*ip); cp += 2; ip++; break; case 'o': printo(*ip); cp += 2; ip++; break; case 'x': printx(*ip); cp += 2; ip++; break; default: putchar(*cp++); //incase it's some other letter like %m or %a } } else if(*cp == '\n'){ putchar('\n'); putchar('\r'); cp++; } else{ putchar(*cp++); } } }
// Formatted Printing int myprintf(char *fmt, ...) { // 12 8 4 0 // ... d | c | b | a | fmt | retPC | ebp | locals ... int *ebp = (int*)get_ebp(); char *cp = fmt; // each int ptr increment = 4 bytes // 12 / 4 = 3 int *ip = ebp + 3; while(*cp) { if (*cp != '%') { // for each \n, spit out an extra \r if (putchar(*cp) == '\n') putchar('\r'); } else { cp++; // bypass % switch (*cp) // *cp = char after % { case 'c': // char putchar(*ip); ip++; break; case 's': // string prints((char*)(*ip)); ip++; break; case 'd': // int printd(*ip); ip++; break; case 'o': // OCTAL printo(*ip); ip++; break; case 'x': // HEX printx(*ip); ip++; break; case 'u': // unsigned int printu(*ip); ip++; break; case '%': // %% -> % putchar('%'); break; default: // unknown specifier putchar('%'); putchar(*cp); break; }// switch(*cp) }// if(%) cp++; } // while(cp) } // myprintf()
int processServerPacket(unsigned char *b,int len) { int i=0; unsigned char type; char s[256]; unsigned char dbuf[2048]; int dlen=0; int i_start=0; int timestamp; timestamp=_GetTickCount(); while(i<len) { type=b[i++]; /* * 0x01 - Muzzleflash */ if(type==0x01) { i+=3; /* * 0x02 - Monster Muzzleflash */ } else if(type==0x02) { i+=3; /* * 0x03 - Temporary Entity */ } else if(type==0x03) { int entity_type=b[i++]; switch(entity_type) { case 5: case 6: case 7: case 8: case 17: case 18: case 20: case 21: case 22: case 28: i+=6; break; case 0: case 1: case 2: case 4: case 9: case 12: case 13: case 14: case 27: i+=7; break; case 3: case 11: case 23: case 26: i+=12; break; case 10: i+=9; break; case 15: case 25: case 29: i+=9; break; case 16: case 19: i+=14; break; case 24: i+=20; break; default: qbLog("*** Unrecognized temp_entity type: %02Xh ***",entity_type); hexdump(b,len); return 0; } /* * 0x04 - Layout */ } else if(type==0x04) { while(b[i++]); /* * 0x05 - Inventory */ } else if(type==0x05) { int j; for(j=0;j<256;j++) { inventory[j]=*((short *)(b+i)); i+=2; } lastInvenTime=_GetTickCount(); /* * 0x06 - NOOP */ } else if(type==0x06) { ; /* * 0x07 - Disconnect */ } else if(type==0x07) { return 1; /* * 0x08 - Reconnect */ } else if(type==0x08) { return 1; /* * 0x09 - Sound */ } else if(type==0x09) { unsigned int mask; mask=b[i++]; i++; if(mask&0x01) i++; if(mask&0x02) i++; if(mask&0x10) i++; if(mask&0x08) i+=2; if(mask&0x04) i+=6; /* * 0x0a - Print */ } else if(type==0x0a) { int j=0; i++; while(b[i++]) { s[j++]=b[i-1]&0x7f; } s[j++]=0; printu("%s",s); /* * 0x0b - StuffText */ } else if(type==0x0b) { char *cmd; int j=0; memcpy(dbuf+dlen,b+i_start,i-i_start-1); dlen+=(i-i_start-1); while(b[i++]) { s[j++]=b[i-1]; } s[j++]=0; // print("StuffText: %s",s); cmd=strstr(s,"precache"); if(cmd) { online=true; qbLog("Precache completed"); dbuf[dlen++]=0x0b; memcpy(dbuf+dlen,"precache\n",9); dlen+=9; dbuf[dlen++]=0x00; } else { cmd=strstr(s,"cmd"); if(cmd) { int x=strlen((char *)(cmd+4)); *((char *)(cmd+x+3))='\0'; qbAsynchConsole((char *)(cmd+4)); // print("%s\n",cmd+4); } else { dbuf[dlen++]=0x0b; memcpy(dbuf+dlen,s,j); dlen+=j; } } i_start=i; /* * 0x0c - Serverinfo */ } else if(type==0x0c) { int version; version=*((int *)(b+i)); i+=4; qbLog("Protocol version: %d",version); login_key=*((int *)(b+i)); i+=4; qbLog("Login key: %d",login_key); b[i++]=1; while(b[i++]); player_num=*((short *)(b+i))+1; i+=2; qbLog("Player Number: %d",player_num); while(b[i++]); /* * 0x0d - ConfigStrings */ } else if(type==0x0d) { int num; int j=0; num=*((short *)(b+i)); i+=2; while(b[i]) { cstrings[num][j++]=b[i++]; } cstrings[num][j++]=b[i++]; cstrings[num][63]=0; // print("Configstring %d: %s\n",num,cstrings[num]); if(num==30) { max_players=atoi(cstrings[num]); } /* * 0x0e - Spawn Entity */ } else if(type==0x0e) { unsigned int mask; int entity; mask=b[i++]; if(mask&0x00000080) mask|=(b[i++]<<8); if(mask&0x00008000) mask|=(b[i++]<<16); if(mask&0x00800000) mask|=(b[i++]<<24); if(mask&0x00000100) { entity=*((short *)(b+i)); i+=2; } else { entity=b[i++]; } if(entity>=1024) { qbLog("Entity > 1024"); return 1; } spawn->entities[entity].modelindex=(mask&0x00000800) ? b[i++] : 0; spawn->entities[entity].modelindex2=(mask&0x00100000) ? b[i++] : 0; spawn->entities[entity].modelindex3=(mask&0x00200000) ? b[i++] : 0; spawn->entities[entity].modelindex4=(mask&0x00400000) ? b[i++] : 0; spawn->entities[entity].framenum=0; if(mask&0x00000010) spawn->entities[entity].framenum=b[i++]; if(mask&0x00020000) { spawn->entities[entity].framenum=*((short *)(b+i)); i+=2; } if(mask&0x00010000) { if(mask&0x02000000) { i+=4; } else { i++; } } else { if(mask&0x02000000) { i+=2; } } if(mask&0x00004000) { if(mask&0x00080000) { i+=4; } else { i++; } } else { if(mask&0x00080000) i+=2; } if(mask&0x00001000) { if(mask&0x00040000) { spawn->entities[entity].renderfx=*((int *)(b+i)); i+=4; } else { spawn->entities[entity].renderfx=b[i++]; } } else { if(mask&0x00040000) { spawn->entities[entity].renderfx=*((short *)(b+i)); i+=2; } else { spawn->entities[entity].renderfx=0; } } if(mask&0x00000001) { spawn->entities[entity].origin[0]=0.125*((float)*((short *)(b+i))); i+=2; } else { spawn->entities[entity].origin[0]=0; } if(mask&0x00000002) { spawn->entities[entity].origin[1]=0.125*((float)*((short *)(b+i))); i+=2; } else { spawn->entities[entity].origin[1]=0; } if(mask&0x00000200) { spawn->entities[entity].origin[2]=0.125*((float)*((short *)(b+i))); i+=2; } else { spawn->entities[entity].origin[2]=0; } spawn->entities[entity].angles[0]=(mask&0x00000400) ? (PI/128.0*(float)b[i++]) : 0; spawn->entities[entity].angles[1]=(mask&0x00000004) ? (PI/128.0*(float)b[i++]) : 0; spawn->entities[entity].angles[2]=(mask&0x00000008) ? (PI/128.0*(float)b[i++]) : 0; if(mask&0x01000000) i+=6; if(mask&0x04000000) i++; if(mask&0x00000020) i++; if(mask&0x08000000) i+=2; spawn->entities[entity].updated=false; data_points[entity].timestamp=timestamp; data_points[entity].origin[0]=spawn->entities[entity].origin[0]; data_points[entity].origin[1]=spawn->entities[entity].origin[1]; data_points[entity].origin[2]=spawn->entities[entity].origin[2]; /* * 0x0f - CenterPrint */ } else if(type==0x0f) { while(b[i++]); /* * 0x10 - Download */ } else if(type==0x0f) { int size; int percent; size=*((unsigned short *)(b+i)); i+=2; percent=b[i++]; if(size>-1) { i+=size; } /* * 0x11 - Playerinfo */ } else if(type==0x11) { unsigned int mask; int j; mask=*((unsigned short *)(b+i)); i+=2; if(mask&0x0001) i++; if(mask&0x0002) { cs->player.origin[0]=0.125*((float)*((short *)(b+i))); i+=2; cs->player.origin[1]=0.125*((float)*((short *)(b+i))); i+=2; cs->player.origin[2]=0.125*((float)*((short *)(b+i))); i+=2; } if(mask&0x0004) { cs->player.velocity[0]=0.0125*((float)*((short *)(b+i))); i+=2; cs->player.velocity[1]=0.0125*((float)*((short *)(b+i))); i+=2; cs->player.velocity[2]=0.0125*((float)*((short *)(b+i))); i+=2; } if(mask&0x0008) i++; if(mask&0x0010) i++; if(mask&0x0020) i+=2; if(mask&0x0040) { cs->player.angles[0]=PI/32768.0*((float)*((short *)(b+i))); i+=2; cs->player.angles[1]=PI/32768.0*((float)*((short *)(b+i))); i+=2; cs->player.angles[2]=PI/32768.0*((float)*((short *)(b+i))); i+=2; } if(mask&0x0080) i+=3; if(mask&0x0100) i+=6; if(mask&0x0200) i+=3; if(mask&0x1000) cs->player.gunindex=b[i++]; if(mask&0x2000) i+=7; if(mask&0x0400) i+=4; if(mask&0x0800) i++; if(mask&0x4000) i++; mask=*((unsigned long *)(b+i)); i+=4; for(j=0;j<32;j++) { if(mask & (0x00000001 << j)) { if(j==13) { *((short *)(b+i))=0; } cs->player.stats[j]=*((short *)(b+i)); i+=2; } } /* * 0x12 - Entity Update */ } else if(type==0x12) { unsigned int mask; int entity; vec3_t oldorigin; float f; while(1) { mask=b[i++]; if(mask&0x00000080) mask|=(b[i++]<<8); if(mask&0x00008000) mask|=(b[i++]<<16); if(mask&0x00800000) mask|=(b[i++]<<24); if(mask&0x00000100) { entity=*((unsigned short *)(b+i)); i+=2; } else { entity=b[i++]; } if(!entity) break; if(entity>=1024) { qbLog("Entity > 1024"); return 1; } cs->entities[entity].updated=true; if(mask&0x00000800) cs->entities[entity].modelindex=b[i++]; if(mask&0x00100000) cs->entities[entity].modelindex2=b[i++]; if(mask&0x00200000) cs->entities[entity].modelindex3=b[i++]; if(mask&0x00400000) cs->entities[entity].modelindex4=b[i++]; if(mask&0x00000010) cs->entities[entity].framenum=b[i++]; if(mask&0x00020000) { cs->entities[entity].framenum=*((short *)(b+i)); i+=2; } if(mask&0x00010000) { if(mask&0x02000000) { i+=4; } else { i++; } } else { if(mask&0x02000000) { i+=2; } } if(mask&0x00004000) { if(mask&0x00080000) { i+=4; } else { i++; } } else { if(mask&0x00080000) i+=2; } if(mask&0x00001000) { if(mask&0x00040000) { cs->entities[entity].renderfx=*((int *)(b+i)); i+=4; } else { cs->entities[entity].renderfx=b[i++]; } } else { if(mask&0x00040000) { cs->entities[entity].renderfx=*((short *)(b+i)); i+=2; } } if(mask&0x00000001) { cs->entities[entity].origin[0]=0.125*((float)*((short *)(b+i))); i+=2; } if(mask&0x00000002) { cs->entities[entity].origin[1]=0.125*((float)*((short *)(b+i))); i+=2; } if(mask&0x00000200) { cs->entities[entity].origin[2]=0.125*((float)*((short *)(b+i))); i+=2; } f=0.01*(float)(timestamp-data_points[entity].timestamp); if(f>0.0 && f<=10.0) { cs->entities[entity].velocity[0]=(cs->entities[entity].origin[0]-data_points[entity].origin[0])/f; cs->entities[entity].velocity[1]=(cs->entities[entity].origin[1]-data_points[entity].origin[1])/f; cs->entities[entity].velocity[2]=(cs->entities[entity].origin[2]-data_points[entity].origin[2])/f; } else { cs->entities[entity].velocity[0]=0; cs->entities[entity].velocity[1]=0; cs->entities[entity].velocity[2]=0; } data_points[entity].timestamp=timestamp; data_points[entity].origin[0]=cs->entities[entity].origin[0]; data_points[entity].origin[1]=cs->entities[entity].origin[1]; data_points[entity].origin[2]=cs->entities[entity].origin[2]; if(mask&0x00000004) cs->entities[entity].angles[0]=(PI/128.0*(float)b[i++]); if(mask&0x00000400) cs->entities[entity].angles[1]=(PI/128.0*(float)b[i++]); if(mask&0x00000008) cs->entities[entity].angles[2]=(PI/128.0*(float)b[i++]); if(mask&0x01000000) i+=6; if(mask&0x04000000) i++; if(mask&0x00000020) i++; if(mask&0x08000000) i+=2; if(mask&0x00000040) { cs->entities[entity].updated=false; } } /* * 0x14 - Frame Update */ } else if(type==0x14) { int count; last_frame=current_frame; current_frame=*((unsigned long *)(b+i)); i+=4; delta_frame=*((unsigned long *)(b+i)); i+=4; i+=1; count=b[i++]; i+=count; if((current_frame-last_frame)>12) { current_state=0; } else { current_state=(current_state+current_frame-last_frame)%16; } if(delta_frame==0xffffffff) { ds=&(states[16]); packet_loss=0; } else if((current_frame-delta_frame)>12) { qbLog("*** Too much packet loss ***"); packet_loss=0x80000000; return 0; } else { ds=&(states[(current_state+delta_frame-current_frame+16)%16]); packet_loss=0; } cs=&(states[current_state]); memcpy(cs,ds,sizeof(igamestate_t)); /* * 0x?? - Undefined */ } else { qbLog("*** BAD server packet type: %02Xh ***",type); hexdump(b,len); return 0; } } if(i>len) { qbLog("*** Server Packet Misalignment Error ***"); hexdump(b,len); return 0; } memcpy(dbuf+dlen,b+i_start,i-i_start); dlen+=(i-i_start); i_start=i; if(recording) { write(demo_handle,&dlen,4); write(demo_handle,dbuf,dlen); } return 0; }
/**************** Union of two relations *******************/ extern RC union_of(Schema *s1,Schema *s2) { int i,j,flag=0,flag1=0; RID rel1; RID rel2; Value *v1,*v2; // Check if same number of attributes if(s1->numAttr == s2->numAttr) { flag1=0; for(i=0;i<s1->numAttr;i++) { { // Check if the datatypes are matching if(s1->dataTypes[i] != s2->dataTypes[i]) flag1=1; } } } else { return RC_UNION_NOT_POSSIBLE; } if(flag1==1) { return RC_UNION_NOT_POSSIBLE; } // Initialize the pointers Record *r1= (Record*) malloc(sizeof(Record)); Record *r2= (Record*) malloc(sizeof(Record)); int tc1= mgmtinfo->Tuplescount; rel1.page=mgmtinfo->FirstPage; rel1.slot=0; int tc2= mgmtinfo2->Tuplescount; rel2.page=mgmtinfo->FirstPage; rel2.slot=0; printf("\n Union tuples are: \n"); // Compute the union and print on console for(i=0;i<tc1;i++) { getRecord(table,rel1,r1); getAttr(r1,s1,0,&v1); rel2.page=mgmtinfo2->FirstPage; rel2.slot=0; flag=0; for(j=0;j<tc2;j++) { getRecord(table2,rel2,r2); getAttr(r2,s2,0,&v2); //printf("\n 2nd tuple"); if( v2->dt==DT_INT) { if(v2->v.intV == v1->v.intV) { flag=1; //printf("\n 2nd tuple twice"); printu(s1,r1,v1); printf("\n"); printu(s2,r2,v2); printf("\n"); } } if(rel2.slot < (mgmtinfo2->maxSlots-1)) { //printf("\n Increase slot"); rel2.slot++; } else { rel2.page++; rel2.slot=0; } } if(flag==0) { printu(s1,r1,v1); printf("\n"); } if(rel1.slot < (mgmtinfo->maxSlots-1)) { //printf("\n Increasing slots for r1"); rel1.slot++; } else { rel1.page++; rel1.slot=0; } } // For the second half of the relation rel1.page=mgmtinfo->FirstPage; rel1.slot=0; rel2.page=mgmtinfo->FirstPage; rel2.slot=0; for(i=0;i<tc2;i++) { getRecord(table2,rel2,r2); getAttr(r2,s2,0,&v2); rel1.page=mgmtinfo->FirstPage; rel1.slot=0; flag=0; for(j=0;j<tc1;j++) { getRecord(table,rel1,r1); getAttr(r1,s1,0,&v1); //printf("\n 2nd tuple"); if( v2->dt==DT_INT) { if(v2->v.intV == v1->v.intV) { flag=1; } } if(rel1.slot < (mgmtinfo->maxSlots-1)) { //printf("\n Increasing slots for r1"); rel1.slot++; } else { rel1.page++; rel1.slot=0; } } if(flag==0) { printu(s2,r2,v2); printf("\n"); } if(rel2.slot < (mgmtinfo2->maxSlots-1)) { //printf("\n Increase slot"); rel2.slot++; } else { rel2.page++; rel2.slot=0; } } free(r1); free(r2); free(v1); free(v2); return RC_OK; }
void myprintf(char *fmt, ...) { int i = 0; char *cp; int *bp; int *ip; int retPC; cp = fmt; bp = (int *)getbp(); ip = bp; retPC = *(ip++); // To make ip point to first argument, we have to iterate it by 2 ip += 2; i = 0; // We loop through the string. while(fmt[i] != '\0') { if(fmt[i] == '\n') // Case where character is a newline { putc('\n'); putc('\r'); } else if(fmt[i] == '%') // User wants to print either a char, string, int, etc. { char *cPtr = 0; switch(fmt[++i]) { case 's': cPtr = (char *)*ip; prints(cPtr); break; case 'u': printu(*ip); break; case 'd': printd(*ip); break; case 'o': printo(*ip); break; case 'x': printx(*ip); break; case 'c': putc(*ip); break; default: break; } ip++; } else { putc(fmt[i]); // Case where just a regular character } i++; } return; }