void add_mines_from_list (const Uint8 *data) { Uint16 mines_no; int i; int mine_x, mine_y, mine_type, my_offset; float x, y, z; int obj_3d_id, mine_id; mines_no = data[0]; if (mines_no > NUM_MINES) { return; // Something nasty happened } for (i = 0; i < mines_no; i++) { my_offset = i * 6 + 1; mine_x = SDL_SwapLE16(*((Uint16 *)(data + my_offset))); mine_y = SDL_SwapLE16(*((Uint16 *)(data + my_offset + 2))); mine_id = *((Uint8 *)(data + my_offset + 4)); mine_type = *((Uint8 *)(data + my_offset + 5)); if (mine_id >= NUM_MINES) { continue; } // Now, get the Z position if (mine_y * tile_map_size_x * 6 + mine_x > tile_map_size_x * tile_map_size_y * 6 * 6) { // Warn about this error! LOG_ERROR("A mine was located OUTSIDE the map!\n"); continue; } z = -2.2f + height_map[mine_y * tile_map_size_x * 6 + mine_x] * 0.2f; // Convert from height values to meters x = (float)mine_x / 2; y = (float)mine_y / 2; // Center the object x = x + 0.25f; y = y + 0.25f; // Now, find the place into the mines list, so we can destroy the mine properly if (mine_list[mine_id].obj_3d_id != -1) { char buf[256]; // Oops, slot already taken! safe_snprintf(buf, sizeof(buf), "Oops, trying to add an existing mine! id=%d\n", mine_id); LOG_ERROR(buf); return; } obj_3d_id = add_e3d(get_mine_e3d(mine_type), x, y, z, 0, 0, 0, 1, 0, 1.0f, 1.0f, 1.0f, 1); mine_list[mine_id].x = mine_x; mine_list[mine_id].y = mine_y; mine_list[mine_id].type = mine_type; mine_list[mine_id].obj_3d_id = obj_3d_id; } }
/** * Update WAV file with current samples */ void WAVFormat_Update(Sint16 pSamples[][2], int Index, int Length) { Sint16 sample[2]; int i; if (bRecordingWav) { /* Output, better if did in two section if wrap */ for(i = 0; i < Length; i++) { /* Convert sample to little endian */ sample[0] = SDL_SwapLE16(pSamples[(Index+i)%MIXBUFFER_SIZE][0]); sample[1] = SDL_SwapLE16(pSamples[(Index+i)%MIXBUFFER_SIZE][1]); /* And store */ if (fwrite(&sample, sizeof(sample), 1, WavFileHndl) != 1) { perror("WAVFormat_Update"); WAVFormat_CloseFile(); return; } } /* Add samples to wav file length counter */ nWavOutputBytes += Length * 4; } }
static int InitMS_ADPCM(WaveFMT *format) { Uint8 *rogue_feel; Uint16 extra_info; int i; /* Set the rogue pointer to the MS_ADPCM specific data */ MS_ADPCM_state.wavefmt.encoding = SDL_SwapLE16(format->encoding); MS_ADPCM_state.wavefmt.channels = SDL_SwapLE16(format->channels); MS_ADPCM_state.wavefmt.frequency = SDL_SwapLE32(format->frequency); MS_ADPCM_state.wavefmt.byterate = SDL_SwapLE32(format->byterate); MS_ADPCM_state.wavefmt.blockalign = SDL_SwapLE16(format->blockalign); MS_ADPCM_state.wavefmt.bitspersample = SDL_SwapLE16(format->bitspersample); rogue_feel = (Uint8 *)format+sizeof(*format); if ( sizeof(*format) == 16 ) { extra_info = ((rogue_feel[1]<<8)|rogue_feel[0]); rogue_feel += sizeof(Uint16); } MS_ADPCM_state.wSamplesPerBlock = ((rogue_feel[1]<<8)|rogue_feel[0]); rogue_feel += sizeof(Uint16); MS_ADPCM_state.wNumCoef = ((rogue_feel[1]<<8)|rogue_feel[0]); rogue_feel += sizeof(Uint16); if ( MS_ADPCM_state.wNumCoef != 7 ) { SDL_SetError("Unknown set of MS_ADPCM coefficients"); return(-1); } for ( i=0; i<MS_ADPCM_state.wNumCoef; ++i ) { MS_ADPCM_state.aCoeff[i][0] = ((rogue_feel[1]<<8)|rogue_feel[0]); rogue_feel += sizeof(Uint16); MS_ADPCM_state.aCoeff[i][1] = ((rogue_feel[1]<<8)|rogue_feel[0]); rogue_feel += sizeof(Uint16); } return(0); }
static void swapEndianness(WavFMT *wavfmt) { wavfmt->Encoding = SDL_SwapLE16(wavfmt->Encoding); wavfmt->Channels = SDL_SwapLE16(wavfmt->Channels); wavfmt->Frequency = SDL_SwapLE32(wavfmt->Frequency); wavfmt->ByteRate = SDL_SwapLE32(wavfmt->ByteRate); wavfmt->SampleSize = SDL_SwapLE16(wavfmt->SampleSize); wavfmt->BitsPerSample = SDL_SwapLE16(wavfmt->BitsPerSample); }
void read_server_book (const char *data, int len) { char buffer[8192]; book *b; page *p; int l = SDL_SwapLE16(*((Uint16*)(data+4))); int idx; if ( l >= sizeof (buffer) ) // Safer l = sizeof (buffer) - 1; memcpy (buffer, data+6, l); buffer[l] = '\0'; b = get_book (SDL_SwapLE16 (*((Uint16*)(data+1)))); if (b == NULL) b = create_book (buffer, data[0], SDL_SwapLE16 (*((Uint16*)(data+1)))); b->server_pages = data[3]; b->have_server_pages++; p=add_page(b);//Will create a page if pages is not found. idx = l + 6; while (idx <= len) { l = SDL_SwapLE16 (*((Uint16*)(&data[idx+1]))); if ( l >= sizeof (buffer) ) // Safer. l = sizeof (buffer) - 1; memcpy (buffer, &data[idx+3], l); buffer[l]=0; switch (data[idx]) { case _TEXT: p=add_str_to_page(buffer,_TEXT,b,p); break; case _AUTHOR: p=add_str_to_page(buffer,_AUTHOR,b,p); break; case _TITLE: p=add_str_to_page(buffer,_TITLE,b,p); break; case _IMAGE: p=add_image_from_server(buffer, b, p); break; case _PAGE: //p=add_page(b); break; } idx += l + 3; } b->active_page += b->pages_to_scroll; b->pages_to_scroll = 0; if (b) display_book_window (b); // Otherwise there's no point... }
static int IsJoystick(int fd, char *namebuf, const size_t namebuflen, SDL_JoystickGUID *guid) { struct input_id inpid; Uint16 *guid16 = (Uint16 *) ((char *) &guid->data); #if !SDL_USE_LIBUDEV /* When udev is enabled we only get joystick devices here, so there's no need to test them */ unsigned long evbit[NBITS(EV_MAX)] = { 0 }; unsigned long keybit[NBITS(KEY_MAX)] = { 0 }; unsigned long absbit[NBITS(ABS_MAX)] = { 0 }; if ((ioctl(fd, EVIOCGBIT(0, sizeof(evbit)), evbit) < 0) || (ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(keybit)), keybit) < 0) || (ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(absbit)), absbit) < 0)) { return (0); } if (!(test_bit(EV_KEY, evbit) && test_bit(EV_ABS, evbit) && test_bit(ABS_X, absbit) && test_bit(ABS_Y, absbit))) { return 0; } #endif if (ioctl(fd, EVIOCGNAME(namebuflen), namebuf) < 0) { return 0; } if (ioctl(fd, EVIOCGID, &inpid) < 0) { return 0; } #ifdef DEBUG_JOYSTICK printf("Joystick: %s, bustype = %d, vendor = 0x%x, product = 0x%x, version = %d\n", namebuf, inpid.bustype, inpid.vendor, inpid.product, inpid.version); #endif SDL_memset(guid->data, 0, sizeof(guid->data)); /* We only need 16 bits for each of these; space them out to fill 128. */ /* Byteswap so devices get same GUID on little/big endian platforms. */ *(guid16++) = SDL_SwapLE16(inpid.bustype); *(guid16++) = 0; if (inpid.vendor && inpid.product && inpid.version) { *(guid16++) = SDL_SwapLE16(inpid.vendor); *(guid16++) = 0; *(guid16++) = SDL_SwapLE16(inpid.product); *(guid16++) = 0; *(guid16++) = SDL_SwapLE16(inpid.version); *(guid16++) = 0; } else { SDL_strlcpy((char*)guid16, namebuf, sizeof(guid->data) - 4); } return 1; }
IndexedTextFile::IndexedTextFile(SDL_RWops* rwop, bool bDecode) { if(rwop == NULL) { throw std::invalid_argument("IndexedTextFile:IndexedTextFile(): rwop == NULL!"); } int indexedTextFilesize = SDL_RWseek(rwop,0,SEEK_END); if(indexedTextFilesize <= 0) { throw std::runtime_error("IndexedTextFile:IndexedTextFile(): Cannot determine size of this file!"); } if(indexedTextFilesize < 2) { throw std::runtime_error("IndexedTextFile:IndexedTextFile(): No valid indexed textfile: File too small!"); } if(SDL_RWseek(rwop,0,SEEK_SET) != 0) { throw std::runtime_error("IndexedTextFile:IndexedTextFile(): Seeking in this indexed textfile failed!"); } unsigned char* pFiledata; if( (pFiledata = (unsigned char*) malloc(indexedTextFilesize)) == NULL) { throw std::bad_alloc(); } if(SDL_RWread(rwop, pFiledata, indexedTextFilesize, 1) != 1) { free(pFiledata); throw std::runtime_error("IndexedTextFile:IndexedTextFile(): Reading this indexed textfile failed!"); } int numIndexedStrings = (SDL_SwapLE16(((Uint16*) pFiledata)[0]))/2 - 1; Uint16* pIndex = (Uint16*) pFiledata; for(int i=0; i <= numIndexedStrings; i++) { pIndex[i] = SDL_SwapLE16(pIndex[i]); } try { for(int i=0; i < numIndexedStrings; i++) { std::string text((const char*) (pFiledata+pIndex[i])); if(bDecode) { indexedStrings.push_back(convertCP850ToISO8859_1(decodeString(text))); } else { indexedStrings.push_back( convertCP850ToISO8859_1(text) ); } } } catch(std::exception&) { delete [] pFiledata; throw; } free(pFiledata); }
/** * Loads the contents of an X-Com SPK image file into * the surface. SPK files are compressed with a custom * algorithm since they're usually full-screen images. * @param filename Filename of the SPK image. * @sa http://www.ufopaedia.org/index.php?title=Image_Formats#SPK */ void Surface::loadSpk(const std::string &filename) { // Load file and put pixels in surface std::ifstream imgFile (filename.c_str(), std::ios::in | std::ios::binary); if (!imgFile) { throw Exception(filename + " not found"); } // Lock the surface lock(); Uint16 flag; Uint8 value; int x = 0, y = 0; while (imgFile.read((char*)&flag, sizeof(flag))) { flag = SDL_SwapLE16(flag); if (flag == 65535) { imgFile.read((char*)&flag, sizeof(flag)); flag = SDL_SwapLE16(flag); for (int i = 0; i < flag * 2; ++i) { setPixelIterative(&x, &y, 0); } } else if (flag == 65534) { imgFile.read((char*)&flag, sizeof(flag)); flag = SDL_SwapLE16(flag); for (int i = 0; i < flag * 2; ++i) { imgFile.read((char*)&value, 1); setPixelIterative(&x, &y, value); } } } // Unlock the surface unlock(); imgFile.close(); }
void print_items(void) { int i; actor *me; me = get_our_actor(); if (me) if(me->fighting) { LOG_TO_CONSOLE(c_red1, "You can't do this during combat!"); return; } /* request the description for each item */ number_to_print = next_item_to_print = 0; printing_category = selected_category; for (i = 0; i < no_storage && i < STORAGE_ITEMS_SIZE; i++) { if (storage_items[i].quantity) { Uint8 str[3]; print_quanities[number_to_print++] = storage_items[i].quantity; str[0]=LOOK_AT_STORAGE_ITEM; *((Uint16*)(str+1))=SDL_SwapLE16(storage_items[i].pos); my_tcp_send(my_socket, str, 3); } } }
/* Better than SDL_ReadLE16, since you can detect i/o errors... */ static __inline__ int read_le16(SDL_RWops *rw, Uint16 *ui16) { int rc = SDL_RWread(rw, ui16, sizeof (Uint16), 1); BAIL_IF_MACRO(rc != 1, ERR_IO_ERROR, 0); *ui16 = SDL_SwapLE16(*ui16); return(1); } /* read_le16 */
void open_book(int id) { book *b=get_book(id); if(!b) { char str[5]; str[0]=SEND_BOOK; *((Uint16*)(str+1))=SDL_SwapLE16((Uint16)id); *((Uint16*)(str+3))=SDL_SwapLE16(0); my_tcp_send(my_socket, (Uint8*)str, 5); } else { display_book_window(b); } }
Uint16 SDL_ReadLE16 (SDL_RWops *src) { Uint16 value; SDL_RWread(src, &value, (sizeof value), 1); return(SDL_SwapLE16(value)); }
void LANGameFinderAndAnnouncer::announceGame() { ENetAddress destinationAddress; destinationAddress.host = ENET_HOST_BROADCAST; destinationAddress.port = LANGAME_ANNOUNCER_PORT; NetworkPacket_AnnounceGame announcePacket; memset(&announcePacket, 0, sizeof(NetworkPacket_AnnounceGame)); announcePacket.magicNumber = SDL_SwapLE32(LANGAME_ANNOUNCER_MAGICNUMBER); announcePacket.type = NETWORKPACKET_ANNOUNCEGAME; strncpy(announcePacket.serverName, serverName.c_str(), LANGAME_ANNOUNCER_MAXGAMENAMESIZE); strncpy(announcePacket.serverVersion, VERSIONSTRING, LANGAME_ANNOUNCER_MAXGAMEVERSIONSIZE); announcePacket.serverPort = SDL_SwapLE16(serverPort); strncpy(announcePacket.mapName, mapName.c_str(), LANGAME_ANNOUNCER_MAXMAPNAMESIZE); announcePacket.numPlayers = numPlayers; announcePacket.maxPlayers = maxPlayers; ENetBuffer enetBuffer; enetBuffer.data = &announcePacket; enetBuffer.dataLength = sizeof(NetworkPacket_AnnounceGame); int err = enet_socket_send(announceSocket, &destinationAddress, &enetBuffer, 1); if(err==0) { // blocked } else if(err < 0) { throw std::runtime_error("LANGameFinderAndAnnouncer: Announcing failed!"); } else { lastAnnounce = SDL_GetTicks(); } }
// endian-swapping fwrite size_t efwrite( void *buffer, size_t size, size_t num, FILE *stream ) { void *swap_buffer; switch (size) { case 2: swap_buffer = malloc(size * num); for (size_t i = 0; i < num; i++) ((Uint16 *)swap_buffer)[i] = SDL_SwapLE16(((Uint16 *)buffer)[i]); break; case 4: swap_buffer = malloc(size * num); for (size_t i = 0; i < num; i++) ((Uint32 *)swap_buffer)[i] = SDL_SwapLE32(((Uint32 *)buffer)[i]); break; case 8: swap_buffer = malloc(size * num); for (size_t i = 0; i < num; i++) ((Uint64 *)swap_buffer)[i] = SDL_SwapLE64(((Uint64 *)buffer)[i]); break; default: swap_buffer = buffer; break; } size_t f = fwrite(swap_buffer, size, num, stream); if (swap_buffer != buffer) free(swap_buffer); return f; }
// does not clip on left or right edges of surface void blit_sprite2_filter( SDL_Surface *surface, int x, int y, Sprite2_array sprite2s, unsigned int index, Uint8 filter ) { assert(surface->format->BitsPerPixel == 8); Uint8 * pixels = (Uint8 *)surface->pixels + (y * surface->pitch) + x; const Uint8 * const pixels_ll = (Uint8 *)surface->pixels, // lower limit * const pixels_ul = (Uint8 *)surface->pixels + (surface->h * surface->pitch); // upper limit const Uint8 *data = sprite2s.data + SDL_SwapLE16(((Uint16 *)sprite2s.data)[index - 1]); for (; *data != 0x0f; ++data) { pixels += *data & 0x0f; // second nibble: transparent pixel count unsigned int count = (*data & 0xf0) >> 4; // first nibble: opaque pixel count if (count == 0) // move to next pixel row { pixels += VGAScreen->pitch - 12; } else { while (count--) { ++data; if (pixels >= pixels_ul) return; if (pixels >= pixels_ll) *pixels = filter | (*data & 0x0f); ++pixels; } } } }
static int voc_check_header(SDL_RWops *src) { /* VOC magic header */ Uint8 signature[20]; /* "Creative Voice File\032" */ Uint16 datablockofs; SDL_RWseek(src, 0, RW_SEEK_SET); if (SDL_RWread(src, signature, sizeof (signature), 1) != 1) return(0); if (memcmp(signature, "Creative Voice File\032", sizeof (signature)) != 0) { SDL_SetError("Unrecognized file type (not VOC)"); return(0); } /* get the offset where the first datablock is located */ if (SDL_RWread(src, &datablockofs, sizeof (Uint16), 1) != 1) return(0); datablockofs = SDL_SwapLE16(datablockofs); if (SDL_RWseek(src, datablockofs, RW_SEEK_SET) != datablockofs) return(0); return(1); /* success! */ } /* voc_check_header */
void SS2() { Uint8 *pSrc, *pDst, *pTmpDst; Sint8 CountData; Uint8 ColumSkip, Fill1, Fill2; Uint16 Lines, Count; pSrc=flc.pChunk+6; pDst=(Uint8*)flc.mainscreen->pixels + flc.offset; ReadU16(&Lines, pSrc); pSrc+=2; while(Lines--) { ReadU16(&Count, pSrc); pSrc+=2; while(Count & 0xc000) { /* Upper bits 11 - Lines skip */ if((Count & 0xc000)==0xc000) { // 0xc000h = 1100000000000000 pDst+=(0x10000-Count)*flc.mainscreen->pitch; } if((Count & 0xc000)==0x4000) { // 0x4000h = 0100000000000000 /* Upper bits 01 - Last pixel */ #ifdef DEBUG printf("Last pixel not implemented"); #endif } ReadU16(&Count, pSrc); pSrc+=2; } if((Count & SDL_SwapLE16(0xc000))==0x0000) { // 0xc000h = 1100000000000000 pTmpDst=pDst; while(Count--) { ColumSkip=*(pSrc++); pTmpDst+=ColumSkip; CountData=*(pSrc++); if(CountData>0) { while(CountData--) { *(pTmpDst++)=*(pSrc++); *(pTmpDst++)=*(pSrc++); } } else { if(CountData<0) { CountData=(0x100-CountData); Fill1=*(pSrc++); Fill2=*(pSrc++); while(CountData--) { *(pTmpDst++)=Fill1; *(pTmpDst++)=Fill2; } } } } pDst+=flc.mainscreen->pitch; } } } /* SS2 */
Uint16 SDL_ReadLE16(SDL_RWops * src) { Uint16 value = 0; SDL_RWread(src, &value, sizeof (value), 1); return SDL_SwapLE16(value); }
void TR_Level::read_tr2_textile16(SDL_RWops * const src, tr2_textile16_t & textile) { for (int i = 0; i < 256; i++) { if (SDL_RWread(src, textile.pixels[i], 2, 256) < 256) Sys_extError("read_tr2_textile16"); for (int j = 0; j < 256; j++) textile.pixels[i][j] = SDL_SwapLE16(textile.pixels[i][j]); } }
void MSG_WriteWord(sizebuf_t * sz, unsigned int value) { if (sz->error || sz->bufferPos + 2 > sz->bufferLen) { sz->error = true; return; } *((Uint16 *)(sz->data + sz->bufferPos)) = SDL_SwapLE16( ((Uint16)value) ); sz->bufferPos += 2; }
//do the flags later on void get_bag_item (const Uint8 *data) { int pos; pos= data[6]; if (pos >= ITEMS_PER_BAG) return; ground_item_list[pos].image_id= SDL_SwapLE16(*((Uint16 *)(data))); ground_item_list[pos].quantity= SDL_SwapLE32(*((Uint32 *)(data+2))); ground_item_list[pos].pos= pos; }
static void read_colors_block(el_file_ptr file, DXTColorBlock *colors) { Uint32 i; el_read(file, sizeof(DXTColorBlock), colors); for (i = 0; i < 2; i++) { colors->m_colors[i] = SDL_SwapLE16(colors->m_colors[i]); } }
static void read_explicit_alphas_block(el_file_ptr file, DXTExplicitAlphaBlock *alphas) { Uint32 i; el_read(file, sizeof(DXTExplicitAlphaBlock), alphas); for (i = 0; i < 4; i++) { alphas->m_alphas[i] = SDL_SwapLE16(alphas->m_alphas[i]); } }
int FlcCheckHeader(const char *filename) { if((flc.file=fopen(filename, "rb"))==NULL) { Log(LOG_ERROR) << "Could not open flx file: " << filename; return -1; } FlcReadFile(128); ReadU32(&flc.HeaderSize, flc.pMembuf); ReadU16(&flc.HeaderCheck, flc.pMembuf+4); ReadU16(&flc.HeaderFrames, flc.pMembuf+6); ReadU16(&flc.HeaderWidth, flc.pMembuf+8); ReadU16(&flc.HeaderHeight, flc.pMembuf+10); ReadU16(&flc.HeaderDepth, flc.pMembuf+12); ReadU16(&flc.HeaderSpeed, flc.pMembuf+16); #ifdef DEBUG printf("flc.HeaderSize: %d\n", flc.HeaderSize); printf("flc.HeaderCheck: %d\n", flc.HeaderCheck); printf("flc.HeaderFrames: %d\n", flc.HeaderFrames); printf("flc.HeaderWidth: %d\n", flc.HeaderWidth); printf("flc.HeaderHeight: %d\n", flc.HeaderHeight); printf("flc.HeaderDepth: %d\n", flc.HeaderDepth); printf("flc.HeaderSpeed: %lf\n", flc.HeaderSpeed); #endif if((flc.HeaderCheck==SDL_SwapLE16(0x0AF12)) || (flc.HeaderCheck==SDL_SwapLE16(0x0AF11))) { flc.screen_w=flc.HeaderWidth; flc.screen_h=flc.HeaderHeight; Log(LOG_INFO) << "Playing flx, " << flc.screen_w << "x" << flc.screen_h << ", " << flc.HeaderFrames << " frames"; flc.screen_depth=8; if(flc.HeaderCheck == SDL_SwapLE16(0x0AF11)){ flc.HeaderSpeed*=1000.0/70.0; } return(0); } return(1); } /* FlcCheckHeader */
void add_teleporters_from_list (const Uint8 *teleport_list) { Uint16 teleporters_no; int i; int teleport_x,teleport_y,my_offset; float x,y,z; teleporters_no=SDL_SwapLE16(*((Uint16 *)(teleport_list))); for (i = 0; i < teleporters_no; i++) { my_offset = i * 5 + 2; teleport_x=SDL_SwapLE16(*((Uint16 *)(teleport_list+my_offset))); teleport_y=SDL_SwapLE16(*((Uint16 *)(teleport_list+my_offset+2))); //later on, maybe we want to have different visual types //now, get the Z position if (!get_tile_valid(teleport_x, teleport_y)) { continue; } z = get_tile_height(teleport_x, teleport_y); //convert from height values to meters x=(float)teleport_x/2; y=(float)teleport_y/2; //center the object x += 0.25f; y += 0.25f; add_particle_sys ("./particles/teleporter.part", x, y, z, 1); engine_add_dynamic_object("./3dobjects/portal1.e3d", x, y, z, 0.0f, 0.0f, 0.0f, 0, 1.0f, 1.0f, 1.0f, engine_get_next_free_dynamic_object_id(), est_detect); //mark the teleporter as an unwalkable so that the pathfinder //won't try to plot a path through it pf_tile_map[teleport_y*tile_map_size_x*6+teleport_x].z = 0; } }
static int InitIMA_ADPCM(WaveFMT *format) { Uint8 *rogue_feel; Uint16 extra_info; /* Set the rogue pointer to the IMA_ADPCM specific data */ IMA_ADPCM_state.wavefmt.encoding = SDL_SwapLE16(format->encoding); IMA_ADPCM_state.wavefmt.channels = SDL_SwapLE16(format->channels); IMA_ADPCM_state.wavefmt.frequency = SDL_SwapLE32(format->frequency); IMA_ADPCM_state.wavefmt.byterate = SDL_SwapLE32(format->byterate); IMA_ADPCM_state.wavefmt.blockalign = SDL_SwapLE16(format->blockalign); IMA_ADPCM_state.wavefmt.bitspersample = SDL_SwapLE16(format->bitspersample); rogue_feel = (Uint8 *)format+sizeof(*format); if ( sizeof(*format) == 16 ) { extra_info = ((rogue_feel[1]<<8)|rogue_feel[0]); rogue_feel += sizeof(Uint16); } IMA_ADPCM_state.wSamplesPerBlock = ((rogue_feel[1]<<8)|rogue_feel[0]); return(0); }
/** * Loads a series of map polar coordinates in X-Com format, * converts them and stores them in a set of polygons. * @param filename Filename of the DAT file. * @sa http://www.ufopaedia.org/index.php?title=WORLD.DAT */ void RuleGlobe::loadDat(const std::string &filename) { // Load file std::ifstream mapFile (filename.c_str(), std::ios::in | std::ios::binary); if (!mapFile) { throw Exception(filename + " not found"); } short value[10]; while (mapFile.read((char*)&value, sizeof(value))) { Polygon* poly; int points; for (int i = 0; i < 10; ++i) { value[i] = SDL_SwapLE16(value[i]); } if (value[6] != -1) { points = 4; } else { points = 3; } poly = new Polygon(points); for (int i = 0, j = 0; i < points; ++i) { // Correct X-Com degrees and convert to radians double lonRad = value[j++] * 0.125 * M_PI / 180; double latRad = value[j++] * 0.125 * M_PI / 180; poly->setLongitude(i, lonRad); poly->setLatitude(i, latRad); } poly->setTexture(value[8]); _polygons.push_back(poly); } if (!mapFile.eof()) { throw Exception("Invalid globe map"); } mapFile.close(); }
static void conv_mix_buf_u16_lsb_mono(void *userdata, Uint8 *_stream, int len) { register Uint32 i; register Uint16 *stream = (Uint16 *) _stream; register Uint16 val; register Uint32 max = len / 2; for (i = 0; i < max; i += 2) { val = (Uint16)((((mixbuf[i]+mixbuf[i+1])*0.5f) * 32767.0f) + 32768.0f); *stream = SDL_SwapLE16(val); stream++; } /* for */ } /* conv_mix_buf_s16_lsb_mono */
static void conv_mix_buf_s16lsb_stereo(void *userdata, Uint8 *_stream, int len) { register Uint32 i; register Sint16 *stream = (Sint16 *) _stream; register Sint16 val; register Uint32 max = len / 2; for (i = 0; i < max; i++) { val = (Sint16) (mixbuf[i] * 32767.0f); *stream = SDL_SwapLE16(val); stream++; } /* for */ } /* conv_mix_buf_s16_lsb_stereo */
/** * Find details of disk image. We need to do this via a function as sometimes the boot-block * is not actually correct with the image - some demos/game disks have incorrect bytes in the * boot sector and this attempts to find the correct values. */ void Floppy_FindDiskDetails(const Uint8 *pBuffer, int nImageBytes, Uint16 *pnSectorsPerTrack, Uint16 *pnSides) { Uint16 nSectorsPerTrack, nSides, nSectorsPerDisk; /* First do check to find number of sectors and bytes per sector */ nSectorsPerTrack = SDL_SwapLE16(*(const Uint16 *)(pBuffer+24)); /* SPT */ nSides = SDL_SwapLE16(*(const Uint16 *)(pBuffer+26)); /* SIDE */ nSectorsPerDisk = pBuffer[19] | (pBuffer[20] << 8); /* total sectors */ /* If the number of sectors announced is incorrect, the boot-sector may * contain incorrect information, eg the 'Eat.st' demo, or wrongly imaged * single/double sided floppies... */ if (nSectorsPerDisk != nImageBytes/512) Floppy_DoubleCheckFormat(nImageBytes, nSectorsPerDisk, &nSides, &nSectorsPerTrack); /* And set values */ if (pnSectorsPerTrack) *pnSectorsPerTrack = nSectorsPerTrack; if (pnSides) *pnSides = nSides; }