void hmp2mid(hmp_file *hmp, unsigned char **midbuf, unsigned int *midlen) { int mi, i, j; short ms, time_div = 0xC0; *midlen = 0; time_div = hmp->tempo*1.6; // write MIDI-header *midbuf = (unsigned char *) malloc(4); memcpy(&(*midbuf)[*midlen], "MThd", 4); *midlen += 4; mi = swapint(6); *midbuf = (unsigned char *) realloc(*midbuf, *midlen + sizeof(mi)); memcpy(&(*midbuf)[*midlen], &mi, sizeof(mi)); *midlen += sizeof(mi); ms = swapshort(1); *midbuf = (unsigned char *) realloc(*midbuf, *midlen + sizeof(ms)); memcpy(&(*midbuf)[*midlen], &ms, sizeof(ms)); *midlen += sizeof(ms); ms = swapshort(hmp->num_trks); *midbuf = (unsigned char *) realloc(*midbuf, *midlen + sizeof(ms)); memcpy(&(*midbuf)[*midlen], &ms, sizeof(ms)); *midlen += sizeof(ms); ms = swapshort(time_div); *midbuf = (unsigned char *) realloc(*midbuf, *midlen + sizeof(ms)); memcpy(&(*midbuf)[*midlen], &ms, sizeof(ms)); *midlen += sizeof(ms); *midbuf = (unsigned char *) realloc(*midbuf, *midlen + sizeof(tempo)); memcpy(&(*midbuf)[*midlen], &tempo, sizeof(tempo)); *midlen += sizeof(tempo); // tracks for (i = 1; i < hmp->num_trks; i++) { int midtrklenpos = 0; *midbuf = (unsigned char *) realloc(*midbuf, *midlen + 4); memcpy(&(*midbuf)[*midlen], "MTrk", 4); *midlen += 4; midtrklenpos = *midlen; mi = 0; *midbuf = (unsigned char *) realloc(*midbuf, *midlen + sizeof(mi)); *midlen += sizeof(mi); mi = hmptrk2mid(hmp->trks[i].data, hmp->trks[i].len, midbuf, midlen, hmp->trks); mi = swapint(mi); memcpy(&(*midbuf)[midtrklenpos], &mi, 4); } }
static void check_swap_targa_header( targahdrs *ptr ) { int hostsex; { int een = 1; char *p = (char*)&een; hostsex = *p; } /* swap bytes of shorts if non PC byte order */ if ( !hostsex ) { ptr->xorg = swapshort( ptr->xorg ); ptr->yorg = swapshort( ptr->yorg ); ptr->imw = swapshort( ptr->imw ); ptr->imh = swapshort( ptr->imh ); } }
// write an optionally compressed PNM image void writePNMimage(const char *filename,unsigned const char *image,unsigned int width,unsigned int height,unsigned int components,int dds) { char str[DDS_MAXSTR]; unsigned char *data; if (width<1 || height<1) ERRORMSG(); switch (components) { case 1: snprintf(str,DDS_MAXSTR,"P5\n%d %d\n255\n",width,height); break; case 2: snprintf(str,DDS_MAXSTR,"P5\n%d %d\n32767\n",width,height); break; case 3: snprintf(str,DDS_MAXSTR,"P6\n%d %d\n255\n",width,height); break; default: ERRORMSG(); } if ((data=(unsigned char *)malloc(strlen(str)+width*height*components))==NULL) ERRORMSG(); memcpy(data,str,strlen(str)); memcpy(data+strlen(str),image,width*height*components); if (DDS_ISINTEL) if (components==2) swapshort(data+strlen(str),width*height); if (dds!=0) writeDDSfile(filename,data,strlen(str)+width*height*components,components,width); else writeRAWfile(filename,data,strlen(str)+width*height*components); }
unsigned char recvBeacon( ob_data* block ) { unsigned long crc; unsigned char ret=0, status; ob_switchRXMode(); if((AT91F_PIO_GetInput(AT91C_BASE_PIOA)&IRQ_PIN)==0) { portENTER_CRITICAL(); status=nRFAPI_GetStatus(); if(status&MASK_RX_DR_FLAG ) { ret=nRFAPI_RX((unsigned char*)block, sizeof(ob_data) ); if(ret>0) { // CRC Check crc = env_crc16(block->payload, sizeof(block->payload) ); if(block->crc == swapshort(crc)) { increment(ob_int_mgmt.rx_beacons, 4); } else { increment(ob_int_mgmt.fail_rx_beacons, 4); ret=0; } } nRFAPI_FlushRX(); } nRFAPI_ClearIRQ(status); portEXIT_CRITICAL (); } return ret; }
static CTL_MSG swapmsg(CTL_MSG req) { CTL_MSG swapreq; if (req.ctl_addr.sin_family == swapshort(AF_INET)) { swapreq = req; swapreq.id_num = swaplong(req.id_num); swapreq.pid = swaplong(req.pid); swapreq.addr.sin_family = swapshort(req.addr.sin_family); swapreq.ctl_addr.sin_family = swapshort(req.ctl_addr.sin_family); return (swapreq); } else { return (req); } }
STATIC_ROUTINE void check_nid(PINO_DATABASE *dblist, NID *nid, int *count) { int bitnum = nid->node; if (!getbit(bitnum)) { NODE *node; NODE *descendent; nid_to_node(dblist, nid, node); if (count) (*count)++; setbit(bitnum); for (descendent = member_of(node); descendent; descendent = brother_of(descendent)) { NID nid; node_to_nid(dblist, descendent, (&nid)); check_nid(dblist, &nid, count); } for (descendent = child_of(node); descendent; descendent = brother_of(descendent)) { NID nid; node_to_nid(dblist, descendent, (&nid)); check_nid(dblist, &nid, count); } if (swapshort((char *)&node->conglomerate_elt)) { NID elt_nid; NODE *elt_node; unsigned short elt_num = 1; elt_nid.node = nid->node - swapshort((char *)&node->conglomerate_elt) + 1; elt_nid.tree = nid->tree; nid_to_node(dblist, (&elt_nid), elt_node); for (; swapshort((char *)&elt_node->conglomerate_elt) == elt_num; elt_nid.node++, elt_num++, elt_node++) check_nid(dblist, &elt_nid, count); } } }
void update_line_count_targa( FILE *fs, int y, evalcontext* ecntxt ) { int hostsex; targahdrs *tgaptr = 0L; int pos; short ys; { int een = 1; char *p = (char*)&een; hostsex = *p; } ys = y; if ( !hostsex ) ys = swapshort( ys ); pos = ftell( fs ); fseek( fs, (int)&tgaptr->imh, 0 ); if ( fwrite( &ys, sizeof( ys ), 1, fs ) != 1 ) ecntxt->cycles->errormsg( 222 ); fseek( fs, pos, 0 ); // fflush( fs ); }
void send_sequence_packet(sequence_packet seq, ubyte *server, ubyte *node, ubyte *net_address) { short tmps; int loc; loc = 0; memset(out_buffer, 0, sizeof(out_buffer)); out_buffer[0] = seq.type; loc++; memcpy(&(out_buffer[loc]), seq.player.callsign, CALLSIGN_LEN+1); loc += CALLSIGN_LEN+1; memcpy(&(out_buffer[loc]), seq.player.server, 4); loc += 4; memcpy(&(out_buffer[loc]), seq.player.node, 6); loc += 6; tmps = swapshort(seq.player.socket); memcpy(&(out_buffer[loc]), &tmps, 2); loc += 2; out_buffer[loc] = seq.player.connected; loc++; out_buffer[loc] = MULTI_PROTO_D1X_MINOR; loc++; if (net_address != NULL) ipx_send_packet_data( out_buffer, loc, server, node, net_address); else if ((server == NULL) && (node == NULL)) ipx_send_broadcast_packet_data( out_buffer, loc ); else ipx_send_internetwork_packet_data( out_buffer, loc, server, node); }
ssize_t load_raster( FILE *in, pixelval_t **raster, ssize_t xsize, ssize_t ysize, ssize_t raster_offset ) { ssize_t i; ssize_t nread; assert( in ); assert( raster ); if( fseek( in, raster_offset, SEEK_SET ) != 0 ) { return -1; } for( i = 0; i < xsize; i++ ) { nread = fread( raster[i], sizeof(raster[0][0]), ysize, in ); if( nread != ysize ) { return i+1; } swapshort( raster[i], ysize ); } return 0; }
signed char sendBeacon( ob_data* block ) { unsigned int i=0; unsigned long crc; ob_switchRXMode(); if( nRFAPI_CarrierDetect()!=STATUS_CD ) { ob_switchTXMode(); crc = env_crc16(block->payload, sizeof(block->payload) ); block->crc = swapshort(crc); // upload data to nRF24L01 nRFAPI_TX((unsigned char*)block, sizeof(ob_data) ); // transmit data nRFLL_CE(1); increment(ob_int_mgmt.tx_beacons, 4); return 0; } increment(ob_int_mgmt.fail_tx_beacons, 4); return -1; }
// read a possibly compressed PNM image unsigned char *readPNMimage(const char *filename,unsigned int *width,unsigned int *height,unsigned int *components) { const int maxstr=100; char str[maxstr]; unsigned char *data,*ptr1,*ptr2; size_t bytes; int pnmtype,maxval; unsigned char *image; if ((data=readDDSfile(filename,&bytes))==NULL) if ((data=readRAWfile(filename,&bytes))==NULL) return(NULL); if (bytes<4) return(NULL); memcpy(str,data,3); str[3]='\0'; if (sscanf(str,"P%1d\n",&pnmtype)!=1) return(NULL); ptr1=data+3; while (*ptr1=='\n' || *ptr1=='#') { while (*ptr1=='\n') if (++ptr1>=data+bytes) ERRORMSG(); while (*ptr1=='#') if (++ptr1>=data+bytes) ERRORMSG(); else while (*ptr1!='\n') if (++ptr1>=data+bytes) ERRORMSG(); } ptr2=ptr1; while (*ptr2!='\n' && *ptr2!=' ') if (++ptr2>=data+bytes) ERRORMSG(); if (++ptr2>=data+bytes) ERRORMSG(); while (*ptr2!='\n' && *ptr2!=' ') if (++ptr2>=data+bytes) ERRORMSG(); if (++ptr2>=data+bytes) ERRORMSG(); while (*ptr2!='\n' && *ptr2!=' ') if (++ptr2>=data+bytes) ERRORMSG(); if (++ptr2>=data+bytes) ERRORMSG(); if (ptr2-ptr1>=maxstr) ERRORMSG(); memcpy(str,ptr1,ptr2-ptr1); str[ptr2-ptr1]='\0'; if (sscanf(str,"%u %u\n%d\n",width,height,&maxval)!=3) ERRORMSG(); if (*width<1 || *height<1) ERRORMSG(); if (pnmtype==5 && maxval==255) *components=1; else if (pnmtype==5 && (maxval==32767 || maxval==65535)) *components=2; else if (pnmtype==6 && maxval==255) *components=3; else ERRORMSG(); if ((image=(unsigned char *)malloc((*width)*(*height)*(*components)))==NULL) ERRORMSG(); if (data+bytes!=ptr2+(*width)*(*height)*(*components)) ERRORMSG(); if (DDS_ISINTEL) if (*components==2) swapshort(ptr2,(*width)*(*height)); memcpy(image,ptr2,(*width)*(*height)*(*components)); free(data); return(image); }
IldaFile *olLoadIlda(const char *filename) { int i; FILE *fd = fopen(filename, "rb"); IldaFile *ild; if (!fd) { return NULL; } ild = malloc(sizeof(*ild)); memset(ild, 0, sizeof(*ild)); ild->min_x = 1.0; ild->min_y = 1.0; ild->min_z = 1.0; ild->max_x = -1.0; ild->max_y = -1.0; ild->max_z = -1.0; while(!ild->count) { struct ilda_hdr hdr; if (fread(&hdr, sizeof(hdr), 1, fd) != 1) { olLog("ILDA: error while reading header\n"); olFreeIlda(ild); fclose(fd); return NULL; } if (hdr.magic != MAGIC) { olLog("ILDA: Invalid magic 0x%08x\n", hdr.magic); olFreeIlda(ild); fclose(fd); return NULL; } hdr.count = swapshort(hdr.count); hdr.frameno = swapshort(hdr.frameno); hdr.framecount = swapshort(hdr.framecount); switch (hdr.format) { case 0: olLog("ILD: Got 3D frame, %d points\n", hdr.count); ild->points = malloc(sizeof(IldaPoint) * hdr.count); struct icoord3d *tmp3d = malloc(sizeof(struct icoord3d) * hdr.count); if (fread(tmp3d, sizeof(struct icoord3d), hdr.count, fd) != hdr.count) { olLog("ILDA: error while reading frame\n"); olFreeIlda(ild); fclose(fd); free(tmp3d); return NULL; } for(i=0; i<hdr.count; i++) { ild->points[i].x = ((int16_t)swapshort(tmp3d[i].x)) / 32768.0f; ild->points[i].y = ((int16_t)swapshort(tmp3d[i].y)) / 32768.0f; ild->points[i].z = ((int16_t)swapshort(tmp3d[i].z)) / 32768.0f; ild->points[i].is_blank = !!(tmp3d[i].state & 0x40); ild->points[i].color = tmp3d[i].color; } free(tmp3d); ild->count = hdr.count; break; case 1: olLog("Got 2D frame, %d points\n", hdr.count); ild->points = malloc(sizeof(IldaPoint) * hdr.count); struct icoord2d *tmp2d = malloc(sizeof(struct icoord2d) * hdr.count); if (fread(tmp2d, sizeof(struct icoord2d), hdr.count, fd) != hdr.count) { olLog("ILDA: error while reading frame\n"); olFreeIlda(ild); fclose(fd); free(tmp2d); return NULL; } for(i=0; i<hdr.count; i++) { ild->points[i].x = ((int16_t)swapshort(tmp2d[i].x)) / 32768.0f; ild->points[i].y = ((int16_t)swapshort(tmp2d[i].y)) / 32768.0f; ild->points[i].z = 0; ild->points[i].is_blank = !!(tmp2d[i].state & 0x40); ild->points[i].color = tmp2d[i].color; } free(tmp2d); ild->count = hdr.count; break; case 2: olLog("ILDA: Got color palette section, %d entries\n", hdr.count); olLog("ILDA: NOT SUPPORTED\n"); olFreeIlda(ild); fclose(fd); return NULL; } } fclose(fd); for(i=0; i<ild->count; i++) { if(ild->points[i].x > ild->max_x) ild->max_x = ild->points[i].x; if(ild->points[i].y > ild->max_y) ild->max_y = ild->points[i].y; if(ild->points[i].z > ild->max_z) ild->max_z = ild->points[i].z; if(ild->points[i].x < ild->min_x) ild->min_x = ild->points[i].x; if(ild->points[i].y < ild->min_y) ild->min_y = ild->points[i].y; if(ild->points[i].z < ild->min_z) ild->min_z = ild->points[i].z; } return ild; }
void send_frameinfo_packet(ubyte *server, ubyte *node, ubyte *address, int short_packet) { int loc, tmpi; short tmps; #ifndef SHAREWARE ushort tmpus; #endif object *pl_obj = &Objects[Players[Player_num].objnum]; loc = 0; memset(out_buffer, 0, IPX_MAX_DATA_SIZE); #ifdef SHAREWARE out_buffer[0] = PID_PDATA; loc++; tmpi = swapint(MySyncPack.numpackets); memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; tmps = swapshort(Players[Player_num].objnum); memcpy(&(out_buffer[loc]), &tmps, 2); loc += 2; out_buffer[loc] = Player_num; loc++; tmps = swapshort(pl_obj->segnum); memcpy(&(out_buffer[loc]), &tmps, 2); loc += 2; tmpi = swapint((int)pl_obj->pos.x); memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; tmpi = swapint((int)pl_obj->pos.y); memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; tmpi = swapint((int)pl_obj->pos.z); memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; tmpi = swapint((int)pl_obj->orient.rvec.x); memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; tmpi = swapint((int)pl_obj->orient.rvec.y); memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; tmpi = swapint((int)pl_obj->orient.rvec.z); memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; tmpi = swapint((int)pl_obj->orient.uvec.x); memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; tmpi = swapint((int)pl_obj->orient.uvec.y); memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; tmpi = swapint((int)pl_obj->orient.uvec.z); memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; tmpi = swapint((int)pl_obj->orient.fvec.x); memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; tmpi = swapint((int)pl_obj->orient.fvec.y); memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; tmpi = swapint((int)pl_obj->orient.fvec.z); memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; tmpi = swapint((int)pl_obj->mtype.phys_info.velocity.x); memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; tmpi = swapint((int)pl_obj->mtype.phys_info.velocity.y); memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; tmpi = swapint((int)pl_obj->mtype.phys_info.velocity.z); memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; tmpi = swapint((int)pl_obj->mtype.phys_info.thrust.x); memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; tmpi = swapint((int)pl_obj->mtype.phys_info.thrust.y); memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; tmpi = swapint((int)pl_obj->mtype.phys_info.thrust.z); memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; tmpi = swapint((int)pl_obj->mtype.phys_info.mass); memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; tmpi = swapint((int)pl_obj->mtype.phys_info.drag); memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; tmpi = swapint((int)pl_obj->mtype.phys_info.brakes); memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; tmpi = swapint((int)pl_obj->mtype.phys_info.rotvel.x); memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; tmpi = swapint((int)pl_obj->mtype.phys_info.rotvel.y); memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; tmpi = swapint((int)pl_obj->mtype.phys_info.rotvel.z); memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; tmpi = swapint((int)pl_obj->mtype.phys_info.rotthrust.x); memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; tmpi = swapint((int)pl_obj->mtype.phys_info.rotthrust.y); memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; tmpi = swapint((int)pl_obj->mtype.phys_info.rotthrust.z); memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; tmps = swapshort((short)pl_obj->mtype.phys_info.turnroll); memcpy(&(out_buffer[loc]), &tmps, 2); loc += 2; tmps = swapshort(pl_obj->mtype.phys_info.flags); memcpy(&(out_buffer[loc]), &tmps, 2); loc += 2; out_buffer[loc] = pl_obj->render_type; loc++; out_buffer[loc] = Current_level_num; loc++; tmps = swapshort(MySyncPack.data_size); memcpy(&(out_buffer[loc]), &tmps, 2); loc += 2; memcpy(&(out_buffer[loc]), MySyncPack.data, MySyncPack.data_size); loc += MySyncPack.data_size; #else if (short_packet == 1) { loc = 0; out_buffer[loc] = PID_SHORTPDATA; loc++; out_buffer[loc] = Player_num; loc++; out_buffer[loc] = pl_obj->render_type; loc++; out_buffer[loc] = Current_level_num; loc++; create_shortpos((shortpos *)(out_buffer + loc), pl_obj); loc += 9+2*3+2+2*3; // go past shortpos structure *(ushort *)(out_buffer + loc) = MySyncPack.data_size; loc += 2; memcpy(out_buffer + loc, MySyncPack.data, MySyncPack.data_size); loc += MySyncPack.data_size; } else if (short_packet == 2) { loc = 0; out_buffer[loc] = PID_PDATA_SHORT2; loc++; out_buffer[loc] = MySyncPack.numpackets & 255; loc++; create_shortpos((shortpos *)(out_buffer + loc), pl_obj); loc += 9+2*3+2+2*3; // go past shortpos structure tmpus = MySyncPack.data_size | (Player_num << 12) | (pl_obj->render_type << 15); *(ushort *)(out_buffer + loc) = tmpus; loc += 2; out_buffer[loc] = Current_level_num; loc++; memcpy(out_buffer + loc, MySyncPack.data, MySyncPack.data_size); loc += MySyncPack.data_size; } else { out_buffer[0] = PID_PDATA; loc++; loc += 3; // skip three for pad byte tmpi = swapint(MySyncPack.numpackets); memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; tmpi = swapint((int)pl_obj->pos.x); memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; tmpi = swapint((int)pl_obj->pos.y); memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; tmpi = swapint((int)pl_obj->pos.z); memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; tmpi = swapint((int)pl_obj->orient.rvec.x); memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; tmpi = swapint((int)pl_obj->orient.rvec.y); memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; tmpi = swapint((int)pl_obj->orient.rvec.z); memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; tmpi = swapint((int)pl_obj->orient.uvec.x); memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; tmpi = swapint((int)pl_obj->orient.uvec.y); memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; tmpi = swapint((int)pl_obj->orient.uvec.z); memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; tmpi = swapint((int)pl_obj->orient.fvec.x); memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; tmpi = swapint((int)pl_obj->orient.fvec.y); memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; tmpi = swapint((int)pl_obj->orient.fvec.z); memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; tmpi = swapint((int)pl_obj->mtype.phys_info.velocity.x); memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; tmpi = swapint((int)pl_obj->mtype.phys_info.velocity.y); memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; tmpi = swapint((int)pl_obj->mtype.phys_info.velocity.z); memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; tmpi = swapint((int)pl_obj->mtype.phys_info.rotvel.x); memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; tmpi = swapint((int)pl_obj->mtype.phys_info.rotvel.y); memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; tmpi = swapint((int)pl_obj->mtype.phys_info.rotvel.z); memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; tmps = swapshort(pl_obj->segnum); memcpy(&(out_buffer[loc]), &tmps, 2); loc += 2; tmps = swapshort(MySyncPack.data_size); memcpy(&(out_buffer[loc]), &tmps, 2); loc += 2; out_buffer[loc] = Player_num; loc++; out_buffer[loc] = pl_obj->render_type; loc++; out_buffer[loc] = Current_level_num; loc++; memcpy(&(out_buffer[loc]), MySyncPack.data, MySyncPack.data_size); loc += MySyncPack.data_size; } #endif #if 0 // adb: not possible (always array passed) if (address == NULL) ipx_send_internetwork_packet_data( out_buffer, loc, server, node ); else #endif ipx_send_packet_data( out_buffer, loc, server, node, address); }
void receive_d1x_netgame_packet(ubyte *data, netgame_info *netgame) { int i, j; int loc = 0; netgame->type = data[loc]; loc++; if (netgame->type == PID_D1X_GAME_LITE) { memset(netgame, 0, sizeof(netgame_info)); netgame->type = PID_D1X_GAME_LITE; } netgame->protocol_version = data[loc]; loc++; netgame->subprotocol = data[loc]; loc++; netgame->required_subprotocol = data[loc]; loc++; memcpy(netgame->game_name, &(data[loc]), NETGAME_NAME_LEN); loc += NETGAME_NAME_LEN; netgame->game_name[NETGAME_NAME_LEN] = 0; memcpy(netgame->mission_name, &(data[loc]), 8); loc += 8; netgame->mission_name[8] = 0; memcpy(netgame->mission_title, &(data[loc]), MISSION_NAME_LEN); loc += MISSION_NAME_LEN; netgame->mission_title[MISSION_NAME_LEN] = 0; netgame->levelnum = ((signed char *)data)[loc]; loc++; netgame->gamemode = data[loc]; loc++; netgame->difficulty = data[loc]; loc++; netgame->game_status = data[loc]; loc++; netgame->game_flags = data[loc]; loc++; netgame->max_numplayers = data[loc]; loc++; netgame->team_vector = data[loc]; loc++; if (netgame->type == PID_D1X_GAME_LITE) { j = netgame->numplayers = data[loc]; loc++; for (i = 0; i < j; i++) netgame->players[i].connected = 1; receive_netplayer_info(&(data[loc]), &(netgame->players[0]), 1);loc += NETPLAYER_D1X_SIZE; //added 4/18/99 Matt Mueller - send .flags as well, so 'I' can show them if (netgame->subprotocol>=1){ memcpy(&netgame->flags, &data[loc], 4); loc += 4; netgame->flags = swapint(netgame->flags); } //end addition -MM } else { netgame->numplayers = data[loc]; loc++; j = data[loc]; loc++; // sizeof netplayer struct if (j > 29) { /* sanity: 304+29*8=536, just below IPX_MAX=542 */ netgame->protocol_version = 0; return; } for (i = 0; i < MAX_PLAYERS; i++) { receive_netplayer_info(&(data[loc]), &(netgame->players[i]), 1); loc += j; } memcpy(netgame->team_name[0], &(data[loc]), CALLSIGN_LEN); loc += CALLSIGN_LEN; netgame->team_name[0][CALLSIGN_LEN] = 0; memcpy(netgame->team_name[1], &(data[loc]), CALLSIGN_LEN); loc += CALLSIGN_LEN; netgame->team_name[1][CALLSIGN_LEN] = 0; for (i = 0; i < MAX_PLAYERS; i++) { netgame->locations[i] = data[loc]; loc++; } for (i = 0; i < MAX_PLAYERS; i++) { for (j = 0; j < MAX_PLAYERS; j++) { memcpy(&(netgame->kills[i][j]), &(data[loc]), 2); loc += 2; // SWAP HERE!!! netgame->kills[i][j] = swapshort(netgame->kills[i][j]); } } memcpy(&(netgame->segments_checksum), &(data[loc]), 2); loc += 2; // SWAP_HERE netgame->segments_checksum = swapshort(netgame->segments_checksum); memcpy(&(netgame->team_kills[0]), &(data[loc]), 2); loc += 2; // SWAP_HERE netgame->team_kills[0] = swapshort(netgame->team_kills[0]); memcpy(&(netgame->team_kills[1]), &(data[loc]), 2); loc += 2; // SWAP_HERE netgame->team_kills[1] = swapshort(netgame->team_kills[1]); for (i = 0; i < MAX_PLAYERS; i++) { memcpy(&(netgame->killed[i]), &(data[loc]), 2); loc += 2; // SWAP HERE!!! netgame->killed[i] = swapshort(netgame->killed[i]); } for (i = 0; i < MAX_PLAYERS; i++) { memcpy(&(netgame->player_kills[i]), &(data[loc]), 2); loc += 2; // SWAP HERE!!! netgame->player_kills[i] = swapshort(netgame->player_kills[i]); } memcpy(&(netgame->level_time), &(data[loc]), 4); loc += 4; // SWAP_HERE netgame->level_time = swapint(netgame->level_time); memcpy(&(netgame->control_invul_time), &(data[loc]), 4); loc += 4; // SWAP_HERE netgame->control_invul_time = swapint(netgame->control_invul_time); memcpy(&(netgame->monitor_vector), &(data[loc]), 4); loc += 4; // SWAP_HERE netgame->monitor_vector = swapint(netgame->monitor_vector); for (i = 0; i < 8; i++) { memcpy(&(netgame->player_score[i]), &(data[loc]), 4); loc += 4; // SWAP_HERE netgame->player_score[i] = swapint(netgame->player_score[i]); } memcpy(netgame->player_flags, &(data[loc]), 8); loc += 8; netgame->packets_per_sec = data[loc]; loc++; memcpy(&netgame->flags, &data[loc], 4); loc += 4; netgame->flags = swapint(netgame->flags); } }
void send_d1x_netgame_packet(ubyte *server, ubyte *node) { uint tmpi; ushort tmps; int i, j; int loc = 0; memset(out_buffer, 0, IPX_MAX_DATA_SIZE); out_buffer[loc] = Netgame.type; loc++; out_buffer[loc] = MULTI_PROTO_D1X_VER; loc++; out_buffer[loc] = Netgame.subprotocol; loc++; out_buffer[loc] = Netgame.required_subprotocol; loc++; memcpy(&(out_buffer[loc]), Netgame.game_name, NETGAME_NAME_LEN); loc += NETGAME_NAME_LEN; memcpy(&(out_buffer[loc]), Netgame.mission_name, 8); loc += 8; memcpy(&(out_buffer[loc]), Netgame.mission_title, MISSION_NAME_LEN); loc += MISSION_NAME_LEN; out_buffer[loc] = Netgame.levelnum; loc++; out_buffer[loc] = Netgame.gamemode; loc++; out_buffer[loc] = Netgame.difficulty; loc++; out_buffer[loc] = Netgame.game_status; loc++; out_buffer[loc] = Netgame.game_flags; loc++; out_buffer[loc] = Netgame.max_numplayers; loc++; out_buffer[loc] = Netgame.team_vector; loc++; if (Netgame.type == PID_D1X_GAME_LITE) { int master = -1; j = 0; for (i = 0; i < Netgame.numplayers; i++) if (Players[i].connected) { if (master == -1) master = i; j++; } out_buffer[loc] = j; loc++; /* numconnected */ if (master == -1) /* should not happen, but... */ master = Player_num; store_netplayer_info(&(out_buffer[loc]), &Netgame.players[master], 1); loc += NETPLAYER_D1X_SIZE; //added 4/18/99 Matt Mueller - send .flags as well, so 'I' can show them tmpi = swapint(Netgame.flags); memcpy(&out_buffer[loc], &tmpi, 4); loc += 4; //end addition -MM } else { out_buffer[loc] = Netgame.numplayers; loc++; out_buffer[loc] = NETPLAYER_D1X_SIZE; loc++; // sizeof netplayer struct for (i = 0; i < MAX_PLAYERS; i++) { store_netplayer_info(&(out_buffer[loc]), &Netgame.players[i], 1); loc += NETPLAYER_D1X_SIZE; } memcpy(&(out_buffer[loc]), Netgame.team_name[0], CALLSIGN_LEN); loc += CALLSIGN_LEN; memcpy(&(out_buffer[loc]), Netgame.team_name[1], CALLSIGN_LEN); loc += CALLSIGN_LEN; for (i = 0; i < MAX_PLAYERS; i++) { out_buffer[loc] = Netgame.locations[i]; loc++; } for (i = 0; i < MAX_PLAYERS; i++) { for (j = 0; j < MAX_PLAYERS; j++) { tmps = swapshort(Netgame.kills[i][j]); memcpy(&(out_buffer[loc]), &tmps, 2); loc += 2; // SWAP HERE!!! } } tmps = swapshort(Netgame.segments_checksum); memcpy(&(out_buffer[loc]), &tmps, 2); loc += 2; // SWAP_HERE tmps = swapshort(Netgame.team_kills[0]); memcpy(&(out_buffer[loc]), &tmps, 2); loc += 2; // SWAP_HERE tmps = swapshort(Netgame.team_kills[1]); memcpy(&(out_buffer[loc]), &tmps, 2); loc += 2; // SWAP_HERE for (i = 0; i < MAX_PLAYERS; i++) { tmps = swapshort(Netgame.killed[i]); memcpy(&(out_buffer[loc]), &tmps, 2); loc += 2; // SWAP HERE!!! } for (i = 0; i < MAX_PLAYERS; i++) { tmps = swapshort(Netgame.player_kills[i]); memcpy(&(out_buffer[loc]), &tmps, 2); loc += 2; // SWAP HERE!!! } tmpi = swapint(Netgame.level_time); memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; // SWAP_HERE tmpi = swapint(Netgame.control_invul_time); memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; // SWAP_HERE tmpi = swapint(Netgame.monitor_vector); memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; // SWAP_HERE for (i = 0; i < 8; i++) { tmpi = swapint(Netgame.player_score[i]); memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; // SWAP_HERE } memcpy(&(out_buffer[loc]), Netgame.player_flags, MAX_PLAYERS); loc += MAX_PLAYERS; out_buffer[loc] = Netgame.packets_per_sec; loc++; tmpi = swapint(Netgame.flags); memcpy(&out_buffer[loc], &tmpi, 4); loc += 4; } if (server == NULL) ipx_send_broadcast_packet_data(out_buffer, loc); else ipx_send_internetwork_packet_data(out_buffer, loc, server, node); }
void receive_netgame_packet(ubyte *data, netgame_info *netgame, int d1x) { int i, j; int loc = 0; #ifndef SHAREWARE if (d1x) { receive_d1x_netgame_packet(data, netgame); return; } #endif netgame->type = data[loc]; loc++; memcpy(netgame->game_name, &(data[loc]), NETGAME_NAME_LEN+1); loc += (NETGAME_NAME_LEN+1); memcpy(netgame->team_name, &(data[loc]), 2*(CALLSIGN_LEN+1)); loc += 2*(CALLSIGN_LEN+1); netgame->gamemode = data[loc]; loc++; netgame->difficulty = data[loc]; loc++; netgame->game_status = data[loc]; loc++; netgame->numplayers = data[loc]; loc++; netgame->max_numplayers = data[loc]; loc++; netgame->game_flags = data[loc]; loc++; for (i = 0; i < MAX_PLAYERS; i++) { receive_netplayer_info(&(data[loc]), &(netgame->players[i]), 0); loc += NETPLAYER_ORIG_SIZE; } #if 0 if (d1x) { for (i = 0; i < MAX_PLAYERS; i++) { netgame->locations[i] = data[loc]; loc++; } } else #endif { for (i = 0; i < MAX_PLAYERS; i++) { memcpy(&(netgame->locations[i]), &(data[loc]), 4); loc += 4; // SWAP HERE!!! netgame->locations[i] = swapint(netgame->locations[i]); } } for (i = 0; i < MAX_PLAYERS; i++) { for (j = 0; j < MAX_PLAYERS; j++) { memcpy(&(netgame->kills[i][j]), &(data[loc]), 2); loc += 2; // SWAP HERE!!! netgame->kills[i][j] = swapshort(netgame->kills[i][j]); } } memcpy(&(netgame->levelnum), &(data[loc]), 4); loc += 4; // SWAP_HERE netgame->levelnum = swapint(netgame->levelnum); netgame->protocol_version = data[loc]; loc++; netgame->team_vector = data[loc]; loc++; memcpy(&(netgame->segments_checksum), &(data[loc]), 2); loc += 2; // SWAP_HERE netgame->segments_checksum = swapshort(netgame->segments_checksum); memcpy(&(netgame->team_kills[0]), &(data[loc]), 2); loc += 2; // SWAP_HERE netgame->team_kills[0] = swapshort(netgame->team_kills[0]); memcpy(&(netgame->team_kills[1]), &(data[loc]), 2); loc += 2; // SWAP_HERE netgame->team_kills[1] = swapshort(netgame->team_kills[1]); for (i = 0; i < MAX_PLAYERS; i++) { memcpy(&(netgame->killed[i]), &(data[loc]), 2); loc += 2; // SWAP HERE!!! netgame->killed[i] = swapshort(netgame->killed[i]); } for (i = 0; i < MAX_PLAYERS; i++) { memcpy(&(netgame->player_kills[i]), &(data[loc]), 2); loc += 2; // SWAP HERE!!! netgame->player_kills[i] = swapshort(netgame->player_kills[i]); } #ifndef SHAREWARE memcpy(&(netgame->level_time), &(data[loc]), 4); loc += 4; // SWAP_HERE netgame->level_time = swapint(netgame->level_time); memcpy(&(netgame->control_invul_time), &(data[loc]), 4); loc += 4; // SWAP_HERE netgame->control_invul_time = swapint(netgame->control_invul_time); memcpy(&(netgame->monitor_vector), &(data[loc]), 4); loc += 4; // SWAP_HERE netgame->monitor_vector = swapint(netgame->monitor_vector); for (i = 0; i < 8; i++) { memcpy(&(netgame->player_score[i]), &(data[loc]), 4); loc += 4; // SWAP_HERE netgame->player_score[i] = swapint(netgame->player_score[i]); } memcpy(netgame->player_flags, &(data[loc]), 8); loc += 8; #if 0 for (i = 0; i < 8; i++) { memcpy(&(netgame->player_flags[i]), &(data[loc]), 1); loc++; } #endif memcpy(netgame->mission_name, &(data[loc]), 9); loc += 9; memcpy(netgame->mission_title, &(data[loc]), MISSION_NAME_LEN+1); loc += (MISSION_NAME_LEN+1); #if 0 if (d1x && netgame->protocol_version == MULTI_PROTO_D1X_VER) { netgame->packets_per_sec = data[loc]; loc++; memcpy(&netgame->flags, &data[loc], 4); loc += 4; netgame->flags = swapint(netgame->flags); } #endif #endif }
void receive_frameinfo_packet(ubyte *data, frame_info *info, int short_packet) { int loc; #ifdef SHAREWARE loc = 0; info->type = data[0]; loc++; memcpy(&(info->numpackets), &(data[loc]), 4); loc += 4; info->numpackets = swapint(info->numpackets); memcpy(&(info->objnum), &(data[loc]), 2); loc += 2; info->objnum = swapshort(info->objnum); info->playernum = data[loc]; loc++; memcpy(&(info->obj_segnum), &(data[loc]), 2); loc += 2; info->obj_segnum = swapshort(info->obj_segnum); memcpy(&(info->obj_pos.x), &(data[loc]), 4); loc += 4; info->obj_pos.x = (fix)swapint((int)info->obj_pos.x); memcpy(&(info->obj_pos.y), &(data[loc]), 4); loc += 4; info->obj_pos.y = (fix)swapint((int)info->obj_pos.y); memcpy(&(info->obj_pos.z), &(data[loc]), 4); loc += 4; info->obj_pos.z = (fix)swapint((int)info->obj_pos.z); memcpy(&(info->obj_orient.rvec.x), &(data[loc]), 4); loc += 4; info->obj_orient.rvec.x = (fix)swapint((int)info->obj_orient.rvec.x); memcpy(&(info->obj_orient.rvec.y), &(data[loc]), 4); loc += 4; info->obj_orient.rvec.y = (fix)swapint((int)info->obj_orient.rvec.y); memcpy(&(info->obj_orient.rvec.z), &(data[loc]), 4); loc += 4; info->obj_orient.rvec.z = (fix)swapint((int)info->obj_orient.rvec.z); memcpy(&(info->obj_orient.uvec.x), &(data[loc]), 4); loc += 4; info->obj_orient.uvec.x = (fix)swapint((int)info->obj_orient.uvec.x); memcpy(&(info->obj_orient.uvec.y), &(data[loc]), 4); loc += 4; info->obj_orient.uvec.y = (fix)swapint((int)info->obj_orient.uvec.y); memcpy(&(info->obj_orient.uvec.z), &(data[loc]), 4); loc += 4; info->obj_orient.uvec.z = (fix)swapint((int)info->obj_orient.uvec.z); memcpy(&(info->obj_orient.fvec.x), &(data[loc]), 4); loc += 4; info->obj_orient.fvec.x = (fix)swapint((int)info->obj_orient.fvec.x); memcpy(&(info->obj_orient.fvec.y), &(data[loc]), 4); loc += 4; info->obj_orient.fvec.y = (fix)swapint((int)info->obj_orient.fvec.y); memcpy(&(info->obj_orient.fvec.z), &(data[loc]), 4); loc += 4; info->obj_orient.fvec.z = (fix)swapint((int)info->obj_orient.fvec.z); memcpy(&(info->obj_phys_info.velocity.x), &(data[loc]), 4); loc += 4; info->obj_phys_info.velocity.x = (fix)swapint((int)info->obj_phys_info.velocity.x); memcpy(&(info->obj_phys_info.velocity.y), &(data[loc]), 4); loc += 4; info->obj_phys_info.velocity.y = (fix)swapint((int)info->obj_phys_info.velocity.y); memcpy(&(info->obj_phys_info.velocity.z), &(data[loc]), 4); loc += 4; info->obj_phys_info.velocity.z = (fix)swapint((int)info->obj_phys_info.velocity.z); memcpy(&(info->obj_phys_info.thrust.x), &(data[loc]), 4); loc += 4; info->obj_phys_info.thrust.x = (fix)swapint((int)info->obj_phys_info.thrust.x); memcpy(&(info->obj_phys_info.thrust.y), &(data[loc]), 4); loc += 4; info->obj_phys_info.thrust.y = (fix)swapint((int)info->obj_phys_info.thrust.y); memcpy(&(info->obj_phys_info.thrust.z), &(data[loc]), 4); loc += 4; info->obj_phys_info.thrust.z = (fix)swapint((int)info->obj_phys_info.thrust.z); memcpy(&(info->obj_phys_info.mass), &(data[loc]), 4); loc += 4; info->obj_phys_info.mass = (fix)swapint((int)info->obj_phys_info.mass); memcpy(&(info->obj_phys_info.drag), &(data[loc]), 4); loc += 4; info->obj_phys_info.drag = (fix)swapint((int)info->obj_phys_info.drag); memcpy(&(info->obj_phys_info.brakes), &(data[loc]), 4); loc += 4; info->obj_phys_info.brakes = (fix)swapint((int)info->obj_phys_info.brakes); memcpy(&(info->obj_phys_info.rotvel.x), &(data[loc]), 4); loc += 4; info->obj_phys_info.rotvel.x = (fix)swapint((int)info->obj_phys_info.rotvel.x); memcpy(&(info->obj_phys_info.rotvel.y), &(data[loc]), 4); loc += 4; info->obj_phys_info.rotvel.y = (fix)swapint((int)info->obj_phys_info.rotvel.y); memcpy(&(info->obj_phys_info.rotvel.z), &(data[loc]), 4); loc += 4; info->obj_phys_info.rotvel.z = (fix)swapint((int)info->obj_phys_info.rotvel.z); memcpy(&(info->obj_phys_info.rotthrust.x), &(data[loc]), 4); loc += 4; info->obj_phys_info.rotthrust.x = (fix)swapint((int)info->obj_phys_info.rotthrust.x); memcpy(&(info->obj_phys_info.rotthrust.y), &(data[loc]), 4); loc += 4; info->obj_phys_info.rotthrust.y = (fix)swapint((int)info->obj_phys_info.rotthrust.y); memcpy(&(info->obj_phys_info.rotthrust.z), &(data[loc]), 4); loc += 4; info->obj_phys_info.rotthrust.z = (fix)swapint((int)info->obj_phys_info.rotthrust.z); memcpy(&(info->obj_phys_info.turnroll), &(data[loc]), 2); loc += 2; info->obj_phys_info.turnroll = (fixang)swapshort((short)info->obj_phys_info.turnroll); memcpy(&(info->obj_phys_info.flags), &(data[loc]), 2); loc += 2; info->obj_phys_info.flags = (ushort)swapshort(info->obj_phys_info.flags); info->obj_render_type = data[loc]; loc++; info->level_num = data[loc]; loc++; memcpy( &(info->data_size), &(data[loc]), 2); loc += 2; info->data_size = swapshort(info->data_size); memcpy(info->data, &(data[loc]), info->data_size); #else if (short_packet == 1) { loc = 0; info->type = data[loc]; loc++; info->playernum = data[loc]; loc++; info->obj_render_type = data[loc]; loc++; info->level_num = data[loc]; loc++; loc += 9+2*3+2+2*3; // skip shortpos structure info->data_size = *(ushort *)(data + loc); loc+=2; memcpy(info->data, &(data[loc]), info->data_size); } else if (short_packet == 2) { ushort tmpus; loc = 0; info->type = data[loc]; loc++; info->numpackets = data[loc]; loc++; loc += 9+2*3+2+2*3; // skip shortpos structure tmpus = *(ushort *)(data + loc); loc+=2; info->data_size = tmpus & 0xfff; info->playernum = (tmpus >> 12) & 7; info->obj_render_type = tmpus >> 15; info->numpackets |= Players[info->playernum].n_packets_got & (~255); if (info->numpackets - Players[info->playernum].n_packets_got > 224) info->numpackets -= 256; else if (Players[info->playernum].n_packets_got - info->numpackets > 128) info->numpackets += 256; info->level_num = data[loc]; loc++; memcpy(info->data, &(data[loc]), info->data_size); } else {
void send_netgame_packet(ubyte *server, ubyte *node) { uint tmpi; ushort tmps; int i, j; int loc = 0; #ifndef SHAREWARE if (Netgame.protocol_version == MULTI_PROTO_D1X_VER) { send_d1x_netgame_packet(server, node); return; } #endif memset(out_buffer, 0, IPX_MAX_DATA_SIZE); out_buffer[loc] = Netgame.type; loc++; memcpy(&(out_buffer[loc]), Netgame.game_name, NETGAME_NAME_LEN+1); loc += (NETGAME_NAME_LEN+1); memcpy(&(out_buffer[loc]), Netgame.team_name, 2*(CALLSIGN_LEN+1)); loc += 2*(CALLSIGN_LEN+1); out_buffer[loc] = Netgame.gamemode; loc++; out_buffer[loc] = Netgame.difficulty; loc++; out_buffer[loc] = Netgame.game_status; loc++; out_buffer[loc] = Netgame.numplayers; loc++; out_buffer[loc] = Netgame.max_numplayers; loc++; out_buffer[loc] = Netgame.game_flags; loc++; for (i = 0; i < MAX_PLAYERS; i++) { memcpy(&(out_buffer[loc]), Netgame.players[i].callsign, CALLSIGN_LEN+1); loc += CALLSIGN_LEN+1; memcpy(&(out_buffer[loc]), Netgame.players[i].server, 4); loc += 4; memcpy(&(out_buffer[loc]), Netgame.players[i].node, 6); loc += 6; memcpy(&(out_buffer[loc]), &(Netgame.players[i].socket), 2); loc += 2; memcpy(&(out_buffer[loc]), &(Netgame.players[i].connected), 1); loc++; } if (Netgame.protocol_version == MULTI_PROTO_D1X_VER) { for (i = 0; i < MAX_PLAYERS; i++) { out_buffer[loc] = Netgame.locations[i]; loc++; } } else { for (i = 0; i < MAX_PLAYERS; i++) { tmpi = swapint(Netgame.locations[i]); memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; // SWAP HERE!!! } } for (i = 0; i < MAX_PLAYERS; i++) { for (j = 0; j < MAX_PLAYERS; j++) { tmps = swapshort(Netgame.kills[i][j]); memcpy(&(out_buffer[loc]), &tmps, 2); loc += 2; // SWAP HERE!!! } } tmpi = swapint(Netgame.levelnum); memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; // SWAP_HERE out_buffer[loc] = Netgame.protocol_version; loc++; out_buffer[loc] = Netgame.team_vector; loc++; tmps = swapshort(Netgame.segments_checksum); memcpy(&(out_buffer[loc]), &tmps, 2); loc += 2; // SWAP_HERE tmps = swapshort(Netgame.team_kills[0]); memcpy(&(out_buffer[loc]), &tmps, 2); loc += 2; // SWAP_HERE tmps = swapshort(Netgame.team_kills[1]); memcpy(&(out_buffer[loc]), &tmps, 2); loc += 2; // SWAP_HERE for (i = 0; i < MAX_PLAYERS; i++) { tmps = swapshort(Netgame.killed[i]); memcpy(&(out_buffer[loc]), &tmps, 2); loc += 2; // SWAP HERE!!! } for (i = 0; i < MAX_PLAYERS; i++) { tmps = swapshort(Netgame.player_kills[i]); memcpy(&(out_buffer[loc]), &tmps, 2); loc += 2; // SWAP HERE!!! } #ifndef SHAREWARE tmpi = swapint(Netgame.level_time); memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; // SWAP_HERE tmpi = swapint(Netgame.control_invul_time); memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; // SWAP_HERE tmpi = swapint(Netgame.monitor_vector); memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; // SWAP_HERE for (i = 0; i < 8; i++) { tmpi = swapint(Netgame.player_score[i]); memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; // SWAP_HERE } for (i = 0; i < 8; i++) { memcpy(&(out_buffer[loc]), &(Netgame.player_flags[i]), 1); loc++; } memcpy(&(out_buffer[loc]), Netgame.mission_name, 9); loc += 9; memcpy(&(out_buffer[loc]), Netgame.mission_title, MISSION_NAME_LEN+1); loc += (MISSION_NAME_LEN+1); if (Netgame.protocol_version == MULTI_PROTO_D1X_VER) { out_buffer[loc] = Netgame.packets_per_sec; loc++; tmpi = swapint(Netgame.flags); memcpy(&out_buffer[loc], &tmpi, 4); loc += 4; } #endif if (server == NULL) ipx_send_broadcast_packet_data(out_buffer, loc); else ipx_send_internetwork_packet_data( out_buffer, loc, server, node ); }
void short_swap(short *s) { *s = swapshort(*s); }
int main(int argc,char **argv) { char reserved[100]; /* buffer to skip reserved bytes */ short f_type; /* MCS file type */ char trigger; /* Trigger Flag */ char dwell_flag; /* External Dwell Flag */ char dwell_units; /* 0=us, 1=ms, 2=sec, 3=ns */ char acq_mode; /* Acquisition mode flag 0=replace, 1=sum */ unsigned long dwell_913; /* Dwell time in old 913 format */ unsigned short pass_length; /* pass length in channels */ unsigned long pass_count; unsigned long pass_count_preset; char acq_time[9]; /* buffer for acquisition time */ char acq_date[9]; /* buffer for acquisition date */ unsigned short mark_chan; /* first marker channel */ char mcs_num; /* 1-8 are valid */ char cal_flag; /* 0=no calibration */ char cal_units[4]; /* calibration units */ float cal_zero; /* calibration zero intercept */ float cal_slope; /* calibration slope */ char id_byte; /* always 0xaa */ char detector_len; /* Detector description length */ char detector[65]; /* detector description */ char sample_len; /* Sample description length */ char sample[65]; /* Sample description */ char disc_sel; /* 0=SCA otherwise Disc */ char disc_edge; /* 0=falling else rising */ float disc; /* disc setting in volts */ float sca_uld; /* sca upper-level in volts */ float sca_lld; /* sca lower-level in volts */ float dwell; /* dwell time in dwell_units */ char consistent; /* settings consistent flag */ char mcs_id[9]; /* MCS ID string "0914-001" */ FILE *fpi; char *input, *output; SDDS_DATASET SDDS_dataset; SCANNED_ARG *scanned; long i, i_arg; char ts1[256], ts2[256], ts3[256], ts4[256]; unsigned long *ucount; long *count, *channel; long ascii; SDDS_RegisterProgramName(argv[0]); argc = scanargs(&scanned, argc, argv); if (argc<3) bomb(NULL, USAGE); input = output = NULL; ascii = 0; for (i_arg=1; i_arg<argc; i_arg++) { if (scanned[i_arg].arg_type==OPTION) { switch (match_string(scanned[i_arg].list[0], option, N_OPTIONS, 0)) { case SET_ASCII: ascii = 1; break; default: bomb("invalid option seen", USAGE); break; } } else { if (!input) input = scanned[i_arg].list[0]; else if (!output) output = scanned[i_arg].list[0]; else bomb("too many filenames", USAGE); } } if (!input) SDDS_Bomb("input file not seen"); if (!output) SDDS_Bomb("output file not seen"); fpi = fopen_e(input, "r", 0); /***************************************************************************/ /* Header Data */ /* Read header info from MCS file */ /***************************************************************************/ /* Read filetype -4 (MCS) */ fread(&f_type,sizeof(short),1,fpi); swapshort(&f_type); if (f_type != MCS) { fprintf(stderr, "Not a valid file: f_type = %hx\n", f_type); exit(1); } fread(&trigger,sizeof(char),1,fpi); /* Read Trigger Flag */ fread(&dwell_flag,sizeof(char),1,fpi); /* Read dwell flag */ fread(&dwell_units,sizeof(char),1,fpi);/* Read dwell units */ fread(&acq_mode,sizeof(char),1,fpi); fread(&dwell_913,sizeof(long),1,fpi); swapulong(&dwell_913); fread(&pass_length,sizeof(short),1,fpi); swapushort(&pass_length); fread(&pass_count,sizeof(long),1,fpi); swapulong(&pass_count); fread(&pass_count_preset,sizeof(long),1,fpi); swapulong(&pass_count_preset); fread(acq_time,sizeof(char),8,fpi); fread(acq_date,sizeof(char),8,fpi); fread(&mark_chan,sizeof(short),1,fpi); swapushort(&mark_chan); fread(&mcs_num,sizeof(char),1,fpi); fread(&cal_flag,sizeof(char),1,fpi); fread(cal_units,sizeof(char),4,fpi); fread(&cal_zero,sizeof(float),1,fpi); swapfloat(&cal_zero); fread(&cal_slope,sizeof(float),1,fpi); swapfloat(&cal_slope); fread(reserved,sizeof(char),10,fpi); fread(&id_byte,sizeof(char),1,fpi); fread(reserved,sizeof(char),1,fpi); fread(&detector_len,sizeof(char),1,fpi); fread(detector,sizeof(char),63,fpi); fread(&sample_len,sizeof(char),1,fpi); fread(sample,sizeof(char),63,fpi); fread(reserved,sizeof(char),16,fpi); /* skip view info & reserved */ fread(&disc_sel,sizeof(char),1,fpi); fread(&disc_edge,sizeof(char),1,fpi); fread(&disc,sizeof(float),1,fpi); swapfloat(&disc); fread(&sca_uld,sizeof(float),1,fpi); swapfloat(&sca_uld); fread(&sca_lld,sizeof(float),1,fpi); swapfloat(&sca_lld); fread(&dwell,sizeof(float),1,fpi); swapfloat(&dwell); fread(&consistent,sizeof(char),1,fpi); fread(reserved,sizeof(char),21,fpi); fread(mcs_id,sizeof(char),8,fpi); mcs_id[8]=0; sprintf(ts1, "%hd", mcs_num+1); sprintf(ts2, "%hd", pass_length); sprintf(ts3, "%ld", pass_count); sprintf(ts4, "%ld", pass_count_preset); if (!SDDS_InitializeOutput(&SDDS_dataset, ascii?SDDS_ASCII:SDDS_BINARY, 1, "Turbo MCS data", "Turbo MCS data", output) || SDDS_DefineParameter(&SDDS_dataset, "MCSNumber", NULL, NULL, "MCS number", NULL, SDDS_SHORT, ts1)<0 || SDDS_DefineParameter(&SDDS_dataset, "MCSID", NULL, NULL, "MCS ID", NULL, SDDS_STRING, mcs_id)<0 || SDDS_DefineParameter(&SDDS_dataset, "PassLength", NULL, NULL, "Pass length", NULL, SDDS_SHORT, ts2)<0 || SDDS_DefineParameter(&SDDS_dataset, "PassCount", NULL, NULL, "Pass count", NULL, SDDS_LONG, ts3)<0 || SDDS_DefineParameter(&SDDS_dataset, "PassCountPreset", NULL, NULL, "Pass count preset", NULL, SDDS_LONG, ts4)<0) SDDS_PrintErrors(stderr, SDDS_EXIT_PrintErrors|SDDS_VERBOSE_PrintErrors); if (dwell_flag == 0) { if (dwell_units==0) dwell *= 1e-6; else if (dwell_units==1) dwell *= 1e-3; else if (dwell_units==3) dwell *= 1e-9; } else dwell = -1; sprintf(ts1, "%15.8e", dwell); sprintf(ts2, "%8s %8s", acq_time,acq_date); if (SDDS_DefineParameter(&SDDS_dataset, "DwellTime", NULL, "s", "Dwell time", NULL, SDDS_DOUBLE, ts1)<0 || SDDS_DefineParameter(&SDDS_dataset, "TriggerMode", NULL, NULL, "Trigger mode", NULL, SDDS_STRING, trigger?"external":"internal")<0 || SDDS_DefineParameter(&SDDS_dataset, "AcquisitionMode", NULL, NULL, "Acquisition mode", NULL, SDDS_STRING, acq_mode?"sum":"replace")<0 || SDDS_DefineParameter(&SDDS_dataset, "TimeStamp", NULL, NULL, "Time at which data collection started", NULL, SDDS_STRING, ts2)<0) SDDS_PrintErrors(stderr, SDDS_EXIT_PrintErrors|SDDS_VERBOSE_PrintErrors); sprintf(ts1, "%15.8e", cal_slope); sprintf(ts2, "%15.8e", cal_zero); if (cal_flag && (SDDS_DefineParameter(&SDDS_dataset, "CalibrationSlope", NULL, cal_units, "Spectrum calibration slope", NULL, SDDS_DOUBLE, ts1)<0 || SDDS_DefineParameter(&SDDS_dataset, "CalibrationOffset", NULL, cal_units, "Spectrum calibration slope", NULL, SDDS_DOUBLE, ts2)<0)) SDDS_PrintErrors(stderr, SDDS_EXIT_PrintErrors|SDDS_VERBOSE_PrintErrors); if (detector_len) { detector[(unsigned)detector_len] = 0; if (SDDS_DefineParameter(&SDDS_dataset, "HardwareDescription", NULL, NULL, NULL, NULL, SDDS_DOUBLE, detector)<0) SDDS_PrintErrors(stderr, SDDS_EXIT_PrintErrors|SDDS_VERBOSE_PrintErrors); } if (sample_len) { sample[(unsigned)sample_len] = 0; if (SDDS_DefineParameter(&SDDS_dataset, "DataDescription", NULL, NULL, NULL, NULL, SDDS_STRING, sample)<0 || SDDS_DefineParameter(&SDDS_dataset, "mplTitle", NULL, NULL, NULL, NULL, SDDS_STRING, sample)<0) SDDS_PrintErrors(stderr, SDDS_EXIT_PrintErrors|SDDS_VERBOSE_PrintErrors); } if (disc_sel == 0) { sprintf(ts1, "%15.8e", sca_lld); sprintf(ts2, "%15.8e", sca_uld); if (SDDS_DefineParameter(&SDDS_dataset, "SCA-LLD", NULL, "V", "SCA Lower-Level Discriminator Setting", NULL, SDDS_DOUBLE, ts1)<0 || SDDS_DefineParameter(&SDDS_dataset, "SCA-ULD", NULL, "V", "SCA Upper-Level Discriminator Setting", NULL, SDDS_DOUBLE, ts2)<0) SDDS_PrintErrors(stderr, SDDS_EXIT_PrintErrors|SDDS_VERBOSE_PrintErrors); } else { sprintf(ts1, "%15.8e", disc); if (SDDS_DefineParameter(&SDDS_dataset, "DiscrimLevel", NULL, "V", "Discriminator Level", NULL, SDDS_DOUBLE, ts1)<0 || SDDS_DefineParameter(&SDDS_dataset, "DiscrimSlope", NULL, NULL, "Discriminator Slope", NULL, SDDS_LONG, disc_edge?"+1":"-1")<0) SDDS_PrintErrors(stderr, SDDS_EXIT_PrintErrors|SDDS_VERBOSE_PrintErrors); } if (consistent==0) { if (SDDS_DefineParameter(&SDDS_dataset, "Inconsistent", NULL, NULL, "Flag indicating whether data and settings are inconsistent", NULL, SDDS_LONG, "1")<0) SDDS_PrintErrors(stderr, SDDS_EXIT_PrintErrors|SDDS_VERBOSE_PrintErrors); fprintf(stderr, "WARNING: Settings are not consistent with data\n"); } if (SDDS_DefineColumn(&SDDS_dataset, "ChannelNumber", NULL, NULL, "Channel number", NULL, SDDS_LONG, 0)<0 || SDDS_DefineColumn(&SDDS_dataset, "EventCount", NULL, NULL, "Number of events", NULL, SDDS_LONG, 0)<0 || !SDDS_WriteLayout(&SDDS_dataset) || !SDDS_StartPage(&SDDS_dataset, (long)pass_length)) SDDS_PrintErrors(stderr, SDDS_EXIT_PrintErrors|SDDS_VERBOSE_PrintErrors); /***************************************************************************/ /* Channel Data */ /* Output channel data from MCS file */ /***************************************************************************/ channel = tmalloc(sizeof(*channel)*pass_length); count = tmalloc(sizeof(*count)*pass_length); ucount = tmalloc(sizeof(*ucount)*pass_length); if (fread(ucount, sizeof(*ucount), pass_length, fpi)!=pass_length) SDDS_Bomb("unable to read channel data"); for (i=0; i<(long)pass_length; i++) { swapulong(ucount+i); count[i] = (long)ucount[i]; channel[i] = i; } if (!SDDS_SetColumn(&SDDS_dataset, SDDS_SET_BY_NAME, channel, (long)pass_length, "ChannelNumber") || !SDDS_SetColumn(&SDDS_dataset, SDDS_SET_BY_NAME, count, (long)pass_length, "EventCount") || !SDDS_WritePage(&SDDS_dataset) || !SDDS_Terminate(&SDDS_dataset)) SDDS_PrintErrors(stderr, SDDS_EXIT_PrintErrors|SDDS_VERBOSE_PrintErrors); fclose(fpi); return(0); }