void NetworkMessage::AddItem(const Item* item) { const ItemType &it = Item::items[item->getID()]; AddU16(it.clientId); if(it.stackable || it.isRune()) AddByte(item->getSubType()); else if(it.isSplash() || it.isFluidContainer()) AddByte(fluidMap[item->getSubType() % 8]); }
static void TakeUpSlack( type_length size ) /*****************************************/ { for( ; size >= 2; size -= 2 ) { if( _IsTargetModel( USE_32 ) ) AddByte( M_OPND_SIZE ); AddByte( M_MOVSW ); } for( ; size >= 1; --size ) { AddByte( M_MOVSB ); } }
void NetworkMessage::AddItem(uint16_t id, uint8_t count) { const ItemType &it = Item::items[id]; AddU16(it.clientId); if(it.stackable || it.isRune()) AddByte(count); else if(it.isSplash() || it.isFluidContainer()) { uint32_t fluidIndex = (count % 8); AddByte(fluidMap[fluidIndex]); } }
void NetworkMessage::AddItem(uint16_t id, uint8_t count) { const ItemType &it = Item::items[id]; AddU16(it.clientId); if(it.stackable){ AddByte(count); } else if(it.isSplash() || it.isFluidContainer()){ AddByte(Item::items.getClientFluidType(FluidTypes_t(count))); } }
void NetworkMessage::AddItem(const Item* item) { const ItemType &it = Item::items[item->getID()]; AddU16(it.clientId); if(it.stackable){ AddByte(item->getSubType()); } else if(it.isSplash() || it.isFluidContainer()){ AddByte(Item::items.getClientFluidType(FluidTypes_t(item->getSubType()))); } }
void NetworkMessage::AddItem(const Item* item) { const ItemType &it = Item::items[item->getID()]; AddU16(it.clientId); if(it.stackable){ AddByte(item->getSubType()); } else if(it.isSplash() || it.isFluidContainer()){ uint32_t fluidIndex = item->getSubType() % 8; AddByte(fluidMap[fluidIndex].value()); } }
int main(int argc, char ** argv) { if (argc != 2) { return 1; } #if defined(_MSC_VER) && defined(_WIN32) if (_setmode(_fileno(stdin), _O_BINARY) == -1) { return 1; } #elif defined(__CYGWIN__) if (setmode(fileno(stdin), O_BINARY) == -1) { return 1; } #endif OpenArray(argv[1]); size_t n; while ((n = fread(buf, 1, sizeof(buf), stdin)) > 0) { for (size_t i = 0; i < n; ++i) { AddByte(buf[i]); } } CloseArray(); return 0; }
static byte Displacement( signed_32 val, hw_reg_set regs ) /************************************************************/ { HW_CTurnOff( regs, HW_SEGS ); if( val == 0 && !HW_CEqual( regs, HW_BP ) ) return( D0 ); if( val <= 127 && val >= -128 ) { AddByte( val & 0xff ); return( D8 ); } else { val &= 0xffff; AddByte( val ); AddByte( val >> 8 ); return( D16 ); } }
void NetworkMessage::AddItem(uint16_t id, uint8_t count) { const ItemType& it = Item::items[id]; AddU16(it.clientId); if (it.stackable) { AddByte(count); } else if (it.isSplash() || it.isFluidContainer()) { uint32_t fluidIndex = count % 8; AddByte(fluidMap[fluidIndex]); } if (it.isAnimation) { AddByte(0xFE); // random phase (0xFF for async) } }
void NetworkMessage::AddItem(const Item* item) { const ItemType& it = Item::items[item->getID()]; AddU16(it.clientId); if (it.stackable) { AddByte(std::min<uint16_t>(0xFF, item->getItemCount())); } else if (it.isSplash() || it.isFluidContainer()) { uint32_t fluidIndex = item->getFluidType() % 8; AddByte(fluidMap[fluidIndex]); } if (it.isAnimation) { AddByte(0xFE); // random phase (0xFF for async) } }
static Stream *ReadFile(FILE *fin) { int c; Stream *in = NewStream(fin); while ((c = ReadChar(in)) >= 0) AddByte(in, (uint)c); return in; }
static byte DoScaleIndex( hw_reg_set base_reg, hw_reg_set idx_reg, int scale ) /***********************************************************/ { byte sib; sib = scale << 6; sib |= DoIndex( base_reg ) >> S_RMR_RM; sib |= ( DoIndex( idx_reg ) >> S_RMR_RM ) << S_RMR_REG; AddByte( sib ); return( RMR_MOD_SIB ); }
static byte Displacement( signed_32 val, hw_reg_set regs ) /************************************************************/ { if( val == 0 && !HW_COvlap( regs, HW_BP ) ) return( D0 ); if( val <= 127 && val >= -128 ) { AddByte( val & 0xff ); return( D8 ); } else { Add32Displacement( val ); return( D32 ); } }
extern void DoRepOp( instruction *ins ) /*****************************************/ { type_length size; bool first; size = ins->result->n.size; first = true; if( ins->head.opcode == OP_MOV && !UseRepForm( size ) ) { for( ; size >= 4; size -= 4 ) { if( first ) { LayOpbyte( M_MOVSW ); OpndSizeIf( false ); first = false; } else { if( _IsntTargetModel( USE_32 ) ) AddByte( M_OPND_SIZE ); AddByte( M_MOVSW ); } } TakeUpSlack( size ); } else { LayOpbyte( M_REPE ); if( ins->head.opcode == OP_MOV ) { if( ( size & ( 4 - 1 ) ) == 0 || OptForSize <= 50 ) { if( _IsntTargetModel( USE_32 ) ) AddByte( M_OPND_SIZE ); AddByte( M_MOVSW ); TakeUpSlack( size & ( 4 - 1 ) ); } else { AddByte( M_MOVSB ); } } else { if( ins->operands[1]->n.size & 1 ) { AddByte( M_CMPSB ); } else { AddByte( M_CMPSW ); if( _IsntTargetModel( USE_32 ) ) AddByte( M_OPND_SIZE ); } } } }
void tNetStatistic::AddByteRecv(float cnt) { AddByte(cnt); ++recv; }
void tNetStatistic::AddByteSend(float cnt) { AddByte(cnt); ++send; }
LWorkItem& LWorkItem::operator<<(unsigned char ucData) { AddByte(ucData); return *this; }
int MakeJedecBuff(struct ActBuffer buff, int galtype, struct Config *cfg) { UBYTE mystrng[16]; struct ActBuffer buff2; int n, m, bitnum, bitnum2, flag; int MaxFuseAdr = 0, RowSize = 0, XORSize = 0; switch (galtype) { case GAL16V8: MaxFuseAdr = MAX_FUSE_ADR16; /* This variables are defined */ RowSize = ROW_SIZE_16V8; /* both globally AND locally! */ XORSize = 8; /* All assignments concern to */ break; /* the locale variables!!!! */ case GAL20V8: MaxFuseAdr = MAX_FUSE_ADR20; RowSize = ROW_SIZE_20V8; XORSize = 8; break; case GAL22V10: MaxFuseAdr = MAX_FUSE_ADR22V10; RowSize = ROW_SIZE_22V10; XORSize = 10; break; case GAL20RA10: MaxFuseAdr = MAX_FUSE_ADR20RA10; RowSize = ROW_SIZE_20RA10; XORSize = 10; break; } buff2 = buff; if (!cfg->JedecFuseChk) if (AddString(&buff, (UBYTE *)"\2\n")) /* <STX> */ return(-1); /*** make header of JEDEC file ***/ if (AddString(&buff, (UBYTE *)"Used Program: GALasm 2.1\n")) return(-1); if (AddString(&buff, (UBYTE *)"GAL-Assembler: GALasm 2.1\n")) return(-1); if (galtype == GAL16V8) { if (AddString(&buff, (UBYTE *)"Device: GAL16V8\n\n")) return(-1); } if (galtype == GAL20V8) { if (AddString(&buff, (UBYTE *)"Device: GAL20V8\n\n")) return(-1); } if (galtype == GAL20RA10) { if (AddString(&buff, (UBYTE *)"Device: GAL20RA10\n\n")) return(-1); } if (galtype == GAL22V10) { if (AddString(&buff, (UBYTE *)"Device: GAL22V10\n\n")) return(-1); } if (AddString(&buff, (UBYTE *)"*F0\n")) /* default value of fuses */ return(-1); if (cfg->JedecSecBit) { /* Security-Bit */ if (AddString(&buff, (UBYTE *)"*G1\n")) return(-1); } else if (AddString(&buff, (UBYTE *)"*G0\n")) return(-1); if (galtype == GAL16V8) /* number of fuses */ if (AddString(&buff, (UBYTE *)"*QF2194\n")) return(-1); if (galtype == GAL20V8) if (AddString(&buff, (UBYTE *)"*QF2706\n")) return(-1); if (galtype == GAL20RA10) if (AddString(&buff, (UBYTE *)"*QF3274\n")) return(-1); if (galtype == GAL22V10) if (AddString(&buff, (UBYTE *)"*QF5892\n")) return(-1); /*** make fuse-matrix ***/ bitnum = bitnum2 = flag = 0; for (m = 0; m < RowSize; m++) { flag = 0; bitnum2 = bitnum; for (n = 0; n <= MaxFuseAdr; n++) { if (Jedec.GALLogic[bitnum2]) { flag = 1; break; } bitnum2++; } if (flag) { sprintf((char *)&mystrng[0], "*L%04d ", bitnum); if (AddString(&buff, (UBYTE *)&mystrng[0])) return(-1); for (n=0; n<=MaxFuseAdr; n++) { if (AddByte(&buff, (UBYTE)(Jedec.GALLogic[bitnum] + '0'))) return(-1); bitnum++; } if (AddByte(&buff, (UBYTE)'\n')) return(-1); } else bitnum = bitnum2; } if (!flag) bitnum = bitnum2; /*** XOR-Bits ***/ sprintf((char *)&mystrng[0], "*L%04d ", bitnum); /* add fuse adr. */ if (AddString(&buff, (UBYTE *)&mystrng[0])) return(-1); for (n = 0; n < XORSize; n++) { if (AddByte(&buff, (UBYTE)(Jedec.GALXOR[n] + '0'))) return(-1); bitnum++; if (galtype == GAL22V10) { /*** S1 of 22V10 ***/ if (AddByte(&buff, (UBYTE)(Jedec.GALS1[n] + '0'))) return(-1); bitnum++; } } if (AddByte(&buff, (UBYTE)'\n')) return(-1); /*** Signature ***/ sprintf((char *)&mystrng[0], "*L%04d ", bitnum); if (AddString(&buff, (UBYTE *)&mystrng[0])) return(-1); for (n = 0; n < SIG_SIZE; n++) { if (AddByte(&buff, (UBYTE)(Jedec.GALSig[n] + '0'))) return(-1); bitnum++; } if (AddByte(&buff, (UBYTE)'\n')) return(-1); if ((galtype == GAL16V8) || (galtype == GAL20V8)) { /*** AC1-Bits ***/ sprintf((char *)&mystrng[0], "*L%04d ", bitnum); if (AddString(&buff, (UBYTE *)&mystrng[0])) return(-1); for (n = 0; n < AC1_SIZE; n++) { if (AddByte(&buff, (UBYTE)(Jedec.GALAC1[n] + '0'))) return(-1); bitnum++; } if (AddByte(&buff, (UBYTE)'\n')) return(-1); /*** PT-Bits ***/ sprintf((char *)&mystrng[0], "*L%04d ", bitnum); if (AddString(&buff, (UBYTE *)&mystrng[0])) return(-1); for (n = 0; n < PT_SIZE; n++) { if (AddByte(&buff, (UBYTE)(Jedec.GALPT[n] + '0'))) return(-1); bitnum++; } if (AddByte(&buff, (UBYTE)'\n')) return(-1); /*** SYN-Bit ***/ sprintf((char *)&mystrng[0], "*L%04d ", bitnum); if (AddString(&buff, (UBYTE *)&mystrng[0])) return(-1); if (AddByte(&buff, (UBYTE)(Jedec.GALSYN + '0'))) return(-1); if (AddByte(&buff, (UBYTE)'\n')) return(-1); bitnum++; /*** AC0-Bit ***/ sprintf((char *)&mystrng[0], "*L%04d ", bitnum); if (AddString(&buff, (UBYTE *)&mystrng[0])) return(-1); if (AddByte(&buff, (UBYTE)(Jedec.GALAC0 + '0'))) return(-1); if (AddByte(&buff, (UBYTE)'\n')) return(-1); } /* if (cfg->JedecFuseChk) {*/ /* add fuse-checksum */ sprintf((char *)&mystrng[0], "*C%04x\n", FuseChecksum(galtype)); if (AddString(&buff, (UBYTE *)&mystrng[0])) return(-1); /* }*/ if (AddString(&buff, (UBYTE *)"*\n")) /* closing '*' */ return(-1); if(!cfg->JedecFuseChk) { if (AddByte(&buff, (UBYTE)0x3)) /* <ETX> */ return(-1); sprintf((char *)&mystrng[0], "%04x\n", FileChecksum(buff2)); if (AddString(&buff, (UBYTE *)&mystrng[0])) return(-1); } return(0); }
void NetworkMessage::AddDouble(double value, uint8_t precision/* = 2*/) { AddByte(precision); AddU32((value * std::pow((float)10, precision)) + INT_MAX); }
QByteArray TransparentOperation::FormByteCommand(QByteArray temp_byte,WirelessRobot* robot) { temp_byte.clear(); RobotParamters robot_parameters = robot->robot_parameters(); char temp_char=robot_parameters.index; if (robot_parameters.kick) { temp_char|=COM_KICK;//(1<<3) } else if(robot_parameters.chipkick) { temp_char|=COM_CHIPKICK;//(1<<4) } AddByte(temp_byte, temp_char); // first time adding byte temp_char=0; int temp_x_velocity = robot_parameters.x_velocity; int temp_y_velocity = robot_parameters.y_velocity; int temp_rotate_velocity = robot_parameters.rotate_velocity; int dribbler_speed=robot_parameters.dribble ; if(dribbler_speed!=0) { dribbler_speed=10; temp_char=(dribbler_speed<<4)|COM_DRIBBLER_DIR; } if(temp_x_velocity>0) { temp_char |= COM_VXSIGN; } if(temp_x_velocity<0) { temp_x_velocity = ~temp_x_velocity +1; } if(temp_y_velocity>0) { temp_char |= COM_VYSIGN; } if(temp_y_velocity<0) { temp_y_velocity = ~temp_y_velocity +1; } if(temp_rotate_velocity<0) { temp_char |= COM_VZSIGN; temp_rotate_velocity = temp_rotate_velocity; } temp_rotate_velocity *=10; AddByte (temp_byte,temp_char); // second time adding byte AddByte (temp_byte,char(temp_y_velocity>OVERALLVELOCITYLIMIT?OVERALLVELOCITYLIMIT:temp_y_velocity)); // third time adding //printf("Velocity: %d\n",char(temp_x_velocity)); AddByte (temp_byte,char(temp_x_velocity>OVERALLVELOCITYLIMIT?OVERALLVELOCITYLIMIT:temp_x_velocity)); // forth time adding AddByte (temp_byte,char(temp_rotate_velocity>255?255:temp_rotate_velocity)); //fifth time adding if (robot_parameters.kick) // sixth time adding { AddByte(temp_byte, robot_parameters.kick); } else if(robot_parameters.chipkick) { AddByte(temp_byte, robot_parameters.chipkick); } else { AddByte(temp_byte, 0); } if (temp_byte.size()>=6) { temp_char=0; int j=0; char* cs = temp_byte.data(); while (j<temp_byte.size()) { temp_char+=*cs; cs++; j++; } temp_char+=0x15;//??? temp_byte.append(temp_char); // seven'th time adding } int temp_size = temp_byte.size(); unsigned char *temp_pointer = new unsigned char(temp_size); memcpy(temp_pointer, temp_byte.data(), temp_size); qDebug()<<"Vx1="<<robot_parameters.x_velocity<<", vy="<<robot_parameters.y_velocity; qDebug()<<temp_pointer; return temp_byte; }
void NetworkMessage::AddPosition(const Position& pos) { AddU16(pos.x); AddU16(pos.y); AddByte(pos.z); }
void HtiStifMsg::AddParameterSeparator() { AddByte('|'); }