本文整理汇总了C++中BSWAP32函数的典型用法代码示例。如果您正苦于以下问题:C++ BSWAP32函数的具体用法?C++ BSWAP32怎么用?C++ BSWAP32使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了BSWAP32函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CopyLineQwordsSwap
static void CopyLineQwordsSwap(void * dst, const void * src, u32 qwords)
{
#ifdef FAST_TMEM_COPY
u32* src32 = (u32*)src;
u32* dst32 = (u32*)dst;
DAEDALUS_ASSERT( ((uintptr_t)src32&0x3 )==0, "src is not aligned!");
while(qwords--)
{
dst32[1] = BSWAP32(src32[0]);
dst32[0] = BSWAP32(src32[1]);
dst32 += 2;
src32 += 2;
}
#else
u8* src8 = (u8*)src;
u8* dst8 = (u8*)dst;
u32 bytes = qwords * 8;
while(bytes--)
{
*(u8*)((uintptr_t)dst8++ ^ 0x4) = *(u8*)((uintptr_t)src8++ ^ U8_TWIDDLE);
}
#endif
}
示例2: IsGoodGRFConfigList
/** Check if all GRFs in the GRF config from a savegame can be loaded.
* @param grfconfig GrfConfig to check
* @return will return any of the following 3 values:<br>
* <ul>
* <li> GLC_ALL_GOOD: No problems occured, all GRF files were found and loaded
* <li> GLC_COMPATIBLE: For one or more GRF's no exact match was found, but a
* compatible GRF with the same grfid was found and used instead
* <li> GLC_NOT_FOUND: For one or more GRF's no match was found at all
* </ul> */
GRFListCompatibility IsGoodGRFConfigList(GRFConfig *grfconfig)
{
GRFListCompatibility res = GLC_ALL_GOOD;
for (GRFConfig *c = grfconfig; c != NULL; c = c->next) {
const GRFConfig *f = FindGRFConfig(c->ident.grfid, c->ident.md5sum);
if (f == NULL) {
char buf[256];
/* If we have not found the exactly matching GRF try to find one with the
* same grfid, as it most likely is compatible */
f = FindGRFConfig(c->ident.grfid);
if (f != NULL) {
md5sumToString(buf, lastof(buf), c->ident.md5sum);
DEBUG(grf, 1, "NewGRF %08X (%s) not found; checksum %s. Compatibility mode on", BSWAP32(c->ident.grfid), c->filename, buf);
if (!HasBit(c->flags, GCF_COMPATIBLE)) {
/* Preserve original_md5sum after it has been assigned */
SetBit(c->flags, GCF_COMPATIBLE);
memcpy(c->original_md5sum, c->ident.md5sum, sizeof(c->original_md5sum));
}
/* Non-found has precedence over compatibility load */
if (res != GLC_NOT_FOUND) res = GLC_COMPATIBLE;
goto compatible_grf;
}
/* No compatible grf was found, mark it as disabled */
md5sumToString(buf, lastof(buf), c->ident.md5sum);
DEBUG(grf, 0, "NewGRF %08X (%s) not found; checksum %s", BSWAP32(c->ident.grfid), c->filename, buf);
c->status = GCS_NOT_FOUND;
res = GLC_NOT_FOUND;
} else {
compatible_grf:
DEBUG(grf, 1, "Loading GRF %08X from %s", BSWAP32(f->ident.grfid), f->filename);
/* The filename could be the filename as in the savegame. As we need
* to load the GRF here, we need the correct filename, so overwrite that
* in any case and set the name and info when it is not set already.
* When the GCF_COPY flag is set, it is certain that the filename is
* already a local one, so there is no need to replace it. */
if (!HasBit(c->flags, GCF_COPY)) {
free(c->filename);
c->filename = strdup(f->filename);
memcpy(c->ident.md5sum, f->ident.md5sum, sizeof(c->ident.md5sum));
if (c->name == NULL && f->name != NULL) c->name = strdup(f->name);
if (c->info == NULL && f->info != NULL) c->info = strdup(f->info);
c->error = NULL;
}
}
}
return res;
}
示例3: CopyLine
static inline void CopyLine(void * dst, const void * src, u32 bytes)
{
#ifdef FAST_TMEM_COPY
u32* src32 = (u32*)src;
u32* dst32 = (u32*)dst;
DAEDALUS_ASSERT((bytes&0x3)==0, "CopyLine: Remaning bytes! (%d)",bytes);
u32 size32 = bytes >> 2;
u32 src_alignment = (uintptr_t)src32&0x3;
if(src_alignment == 0)
{
while (size32--)
{
*dst32++ = BSWAP32(src32[0]);
src32++;
}
}
else
{
// Zelda and DK64 have unaligned copies. so let's optimize 'em
src32 = (u32*)((uintptr_t)src & ~0x3);
u32 src_tmp = *src32++;
u32 dst_tmp = 0;
// calculate offset 3..1..2
u32 offset = 4-src_alignment;
u32 lshift = src_alignment<<3;
u32 rshift = offset<<3;
while(size32--)
{
dst_tmp = src_tmp << lshift;
src_tmp = *src32++;
dst_tmp|= src_tmp >> rshift;
*dst32++ = BSWAP32(dst_tmp);
}
src32 -= offset;
}
#else
u8* src8 = (u8*)src;
u8* dst8 = (u8*)dst;
while(bytes--)
{
*dst8++ = *(u8*)((uintptr_t)src8++ ^ U8_TWIDDLE);
}
#endif
}
示例4: memnew
void EditorExportPlatformOSX::_make_icon(const Image& p_icon,Vector<uint8_t>& icon) {
Ref<ImageTexture> it = memnew( ImageTexture );
int size=512;
Vector<uint8_t> data;
data.resize(8);
data[0]='i';
data[1]='c';
data[2]='n';
data[3]='s';
const char *name[]={"ic09","ic08","ic07","icp6","icp5","icp4"};
int index=0;
while(size>=16) {
Image copy = p_icon;
copy.convert(Image::FORMAT_RGBA);
copy.resize(size,size);
it->create_from_image(copy);
String path = EditorSettings::get_singleton()->get_settings_path()+"/tmp/icon.png";
ResourceSaver::save(path,it);
FileAccess *f = FileAccess::open(path,FileAccess::READ);
ERR_FAIL_COND(!f);
int ofs = data.size();
uint32_t len = f->get_len();
data.resize(data.size()+len+8);
f->get_buffer(&data[ofs+8],len);
memdelete(f);
len+=8;
len=BSWAP32(len);
copymem(&data[ofs],name[index],4);
encode_uint32(len,&data[ofs+4]);
index++;
size/=2;
}
uint32_t total_len = data.size();
total_len = BSWAP32(total_len);
encode_uint32(total_len,&data[4]);
icon=data;
}
示例5: global_user_list_cb
static void
global_user_list_cb (USER * user, struct guldata *data)
{
ASSERT (validate_user (user));
ASSERT (data != 0);
if (data->flags)
{
/* selectively display users based on user level/muzzle/cloak */
if (!
(((data->flags & ON_GFLAG_ADMIN) && user->level == LEVEL_ADMIN)
|| ((data->flags & ON_GFLAG_ELITE) && user->level == LEVEL_ELITE)
|| ((data->flags & ON_GFLAG_MODERATOR)
&& user->level == LEVEL_MODERATOR)
|| ((data->flags & ON_GFLAG_USERS) && user->level == LEVEL_USER)
|| ((data->flags & ON_GFLAG_LEECH) && user->level == LEVEL_LEECH)
|| ((data->flags & ON_GFLAG_MUZZLED) && user->muzzled)
|| ((data->flags & ON_GFLAG_CLOAKED) && user->cloaked)
|| ((data->flags & ON_GFLAG_USERIP) && (user->ip & data->mask) == (data->ip & data->mask))))
return;
}
if (data->server && *data->server != '*' &&
strcasecmp (data->server, user->server) != 0)
return; /* no match */
send_cmd (data->con, MSG_SERVER_GLOBAL_USER_LIST, "%s %s", user->nick,
my_ntoa (BSWAP32 (user->ip)));
}
示例6: BSWAP32
int DumpScan::process(DumpDataList::iterator startDump, unsigned long startByte)
{
unsigned long min = m_address - m_maxOffset;
unsigned long max = m_address;
if (m_maxOffset > m_address)
min = 0;
m_counter = 0;
for (DumpDataList::iterator it = startDump; it!= m_dumps.end(); ++it)
{
char *data = (*it)->data;
CHECK_CANCEL;
for (unsigned long i=startByte; i<((*it)->header.end - (*it)->header.begin)-3; ++i)
{
unsigned long currentAddress = BSWAP32(*(unsigned long*)(&data[i]));
CHECK_CANCEL;
if ( currentAddress >= min && currentAddress <= max) //we want this
{
PointerOffsets po = m_offsets;
po.push_front(m_address - currentAddress);
m_results.push_back(ScanResult(i+(*it)->header.begin, po));
if (++m_counter >= m_maxResults)
{
m_counter = 0;
m_currentDump = it;
m_currentByte = i+1;
return DUMP_SCAN_STATUS_CONTINUE;
}
}
}
}
return DUMP_SCAN_STATUS_DONE;
}
示例7: cmd_page_erase
void cmd_page_erase()
{
int adrs=BSWAP32(PacketFromPC.adrs);
if( check_flash_adrs(adrs)) {
FLASH_ErasePage(adrs);
}
}
示例8: cmd_page_write
/********************************************************************
* FLASHのページ単位書き込み. (引数は書き込みadrsとsize)
********************************************************************
STM32では、word単位で書き込みが可能. (flush動作不要)
他のマイコン(LPCなど)では、
実際にはRAM上のページバッファにword単位でためておいて、
最後にsize=0を指定してページバッファを一発書き込みする実装になることもある.
*/
void cmd_page_write()
{
int *p = PacketFromPC.data;
int i;
int size = BSWAP16(PacketFromPC.size);
int adr = BSWAP32(PacketFromPC.adrs);
// ここでbyte数をword数に変換している.
size = (size+3) >> 2; // size は4byte単位に限る.
//#if defined(LPC1343)||defined(LPC2388)
if(size==0) { // size が 0 のときは書き込みflush動作をする.
FLASH_ProgramPage(adr); // これはSTM32に限り不要(ダミー関数)
return ;
}
//#endif
for(i=0; i<size; i++) {
if( check_flash_adrs(adr) ) {
FLASH_ProgramWord(adr, *p); // STM32では直接FLUSHに書く.
} // 他のマイコンでは、ページバッファに記録.
p++;
adr+=4;
}
}
示例9: cmd_echo
/********************************************************************
* 接続テストの返答
********************************************************************
*/
void cmd_echo(void)
{
int *fl_stat = (int*) &PacketToPC.rawint[2];
PacketToPC.raw[1]=DEVID; // PIC25/14K
PacketToPC.raw[2]=VER_L; // version.L
PacketToPC.raw[3]=VER_H; // version.H
PacketToPC.raw[4]=DEV_LOADER; // bootloader
PacketToPC.raw[5]=PacketFromPC.raw[1]; // ECHOBACK
fl_stat[0] = BSWAP32(FLASH_END_ADR);
fl_stat[1] = BSWAP32(search_flash_end(FLASH_END_ADR));
fl_stat[2] = BSWAP32(total_errs);
total_errs=0;
ToPcRdy = 1;
}
示例10: cmd_page_write
void cmd_page_write()
{
int i;
int size = BSWAP16(PacketFromPC.size);
int adr = BSWAP32(PacketFromPC.adrs);
int *p = PacketFromPC.data;
size = (size+3) >> 2;
#if defined(LPC1343)||defined(LPC2388)
if(size==0) {
FLASH_ProgramPage(adr);
return ;
}
#endif
if( size <= (48) ) {
total_errs += flash_write(adr,size,p);
return;
}
while(size>0) {
int buf[64/4];
int len = size;
if( len >= BLK_SIZE ) {len = BLK_SIZE;}
USBgetpacket((uchar*)buf,len);
total_errs += flash_write(adr, len ,buf);
size -= len;
adr += len;
}
}
示例11: memnew
void EditorExportPlatformOSX::_make_icon(const Ref<Image> &p_icon, Vector<uint8_t> &p_data) {
Ref<ImageTexture> it = memnew(ImageTexture);
int size = 512;
Vector<uint8_t> data;
data.resize(8);
data[0] = 'i';
data[1] = 'c';
data[2] = 'n';
data[3] = 's';
const char *name[] = { "ic09", "ic08", "ic07", "icp6", "icp5", "icp4" };
int index = 0;
while (size >= 16) {
Ref<Image> copy = p_icon; // does this make sense? doesn't this just increase the reference count instead of making a copy? Do we even need a copy?
copy->convert(Image::FORMAT_RGBA8);
copy->resize(size, size);
it->create_from_image(copy);
String path = EditorSettings::get_singleton()->get_cache_dir().plus_file("icon.png");
ResourceSaver::save(path, it);
FileAccess *f = FileAccess::open(path, FileAccess::READ);
ERR_FAIL_COND(!f);
int ofs = data.size();
uint32_t len = f->get_len();
data.resize(data.size() + len + 8);
f->get_buffer(&data[ofs + 8], len);
memdelete(f);
len += 8;
len = BSWAP32(len);
copymem(&data[ofs], name[index], 4);
encode_uint32(len, &data[ofs + 4]);
index++;
size /= 2;
}
uint32_t total_len = data.size();
total_len = BSWAP32(total_len);
encode_uint32(total_len, &data[4]);
p_data = data;
}
示例12: byteswap_msg
static void
byteswap_msg (ossmix_commad_packet_t * msg)
{
BSWAP32 (msg->cmd);
BSWAP32 (msg->p1);
BSWAP32 (msg->p2);
BSWAP32 (msg->p3);
BSWAP32 (msg->p4);
BSWAP32 (msg->p5);
BSWAP32 (msg->ack_rq);
BSWAP32 (msg->unsolicited);
BSWAP32 (msg->payload_size);
}
示例13: try_connect
static void
try_connect (server_auth_t * auth)
{
int f;
CONNECTION *cli;
unsigned int ip;
/* attempt a connection. we do this nonblocking so that the server
doesn't halt if it takes a long time to connect */
f = make_tcp_connection (auth->name, auth->port, &ip);
if (f == -1)
return;
cli = new_connection ();
if (!cli)
goto error;
cli->fd = f;
cli->host = STRDUP (auth->alias ? auth->alias : auth->name);
if (!cli->host)
{
OUTOFMEMORY ("try_connect");
goto error;
}
cli->server_login = 1;
if ((cli->opt.auth = CALLOC (1, sizeof (AUTH))) == 0)
{
OUTOFMEMORY ("try_connect");
goto error;
}
cli->opt.auth->nonce = generate_nonce ();
if (!cli->opt.auth->nonce)
{
log_message ("try_connect: could not generate nonce, closing connection");
goto error;
}
cli->ip = BSWAP32 (ip);
cli->port = auth->port;
if (add_client (cli, 1/* server connection */))
goto error;
return;
error:
log_message ("try_connect: closing connection");
if (cli)
{
CLOSE (cli->fd);
if (cli->host)
FREE (cli->host);
if (cli->opt.auth)
{
if (cli->opt.auth->nonce)
FREE (cli->opt.auth->nonce);
FREE (cli->opt.auth);
}
FREE (cli);
}
}
示例14: BSWAP32
void StreamPeer::put_32(int32_t p_val) {
if (big_endian) {
p_val = BSWAP32(p_val);
}
uint8_t buf[4];
encode_uint32(p_val, buf);
put_data(buf, 4);
}
示例15: get_data
int32_t StreamPeer::get_32() {
uint8_t buf[4];
get_data(buf, 4);
uint32_t r = decode_uint32(buf);
if (big_endian) {
r = BSWAP32(r);
}
return r;
}