示例#1
0
uInt
coff_length(Environ *e, uByte *load, uInt loadlen)
{
	unsigned char *data = (unsigned char*)load;
	Fileheader *fhdr = (Fileheader*)data;
	Bool swap = (fhdr->magic[0] == COFF_MAGIC_1);
	Optfileheader *ofhdr = (Optfileheader*)(fhdr + 1);
	Sectionheader *scnhdr = (Sectionheader*)((uPtr)ofhdr +
			SWAPSHORT(swap, fhdr->opthdrlen));
	int numsections = SWAPSHORT(swap, fhdr->sections);
	int i, l, len = 0;

	for (i = 0; i < numsections; i++)
	{
		if (SWAPSHORT(swap, scnhdr[i].flags) & (S_BSS | S_NOLOAD))
			continue;
		
		l = SWAPINT(swap, scnhdr[i].rawdata);
		l += SWAPINT(swap, scnhdr[i].size);

		if (l > len)
			len = l;

		if (len > loadlen)
			return 0;
	}

	return len;
}
示例#2
0
void    font_transform_glyph(DviOrientation orient, DviGlyph *g)
{
    BITMAP    *map;
    int    x, y;
    
    map = (BITMAP *)g->data;
    if(MDVI_GLYPH_ISEMPTY(map))
        map = NULL;

    /* put the glyph in the right orientation */
    switch(orient) {
    case MDVI_ORIENT_TBLR:
        break;
    case MDVI_ORIENT_TBRL:
        g->x = g->w - g->x;
        if(map) bitmap_flip_horizontally(map);
        break;
    case MDVI_ORIENT_BTLR:
        g->y = g->h - g->y;
        if(map) bitmap_flip_vertically(map);
        break;
    case MDVI_ORIENT_BTRL:
        g->x = g->w - g->x;
        g->y = g->h - g->y;
        if(map) bitmap_flip_diagonally(map);
        break;
    case MDVI_ORIENT_RP90:
        if(map) bitmap_rotate_counter_clockwise(map);
        y = g->y;
        x = g->w - g->x;
        g->x = y;
        g->y = x;
        SWAPINT(g->w, g->h);
        break;
    case MDVI_ORIENT_RM90: 
        if(map) bitmap_rotate_clockwise(map);
        y = g->h - g->y;
        x = g->x;
        g->x = y;
        g->y = x;
        SWAPINT(g->w, g->h);
        break;
    case MDVI_ORIENT_IRP90:
        if(map) bitmap_flip_rotate_counter_clockwise(map);
        y = g->y;
        x = g->x;
        g->x = y;
        g->y = x;
        SWAPINT(g->w, g->h);
        break;
    case MDVI_ORIENT_IRM90:
        if(map) bitmap_flip_rotate_clockwise(map);
        y = g->h - g->y;
        x = g->w - g->x;
        g->x = y;
        g->y = x;
        SWAPINT(g->w, g->h);
        break;
    }
}
示例#3
0
/* prepare to run the COFF image already verified to be COFF
 */
Retcode
coff_load(Environ *e, uByte *load, uInt loadlen, uLong *entrypoint)
{
	unsigned char *data = (unsigned char*)load;
	Fileheader *fhdr = (Fileheader*)data;
	Bool swap = (fhdr->magic[0] == COFF_MAGIC_1);
	Optfileheader *ofhdr;
	Sectionheader *scnhdr;
	int numsections = SWAPSHORT(swap, fhdr->sections);
	unsigned char *from, *to;
	int len, i;

	/* sanity check */
	if (!coff_is_exec(e, load, loadlen))
		return E_BAD_IMAGE;

	/* copy the headers into a temp-buffer to support overlapping loads */
	len = sizeof *fhdr + SWAPSHORT(swap, fhdr->opthdrlen) +
			sizeof *scnhdr * numsections;
	fhdr = (Fileheader*)malloc(len);

	if (fhdr == NULL)
	{
		cprintf(e, "Cannot allocate enough memory for COFF headers?!?\n");
		return E_OUT_OF_MEMORY;
	}

	memcpy(fhdr, data, len);
	ofhdr = (Optfileheader*)(fhdr + 1);
	scnhdr = (Sectionheader*)((uPtr)ofhdr + SWAPSHORT(swap, fhdr->opthdrlen));

	*entrypoint = SWAPINT(swap, ofhdr->entrypoint);
	DPRINTF(("entrypoint=%#x\n", *entrypoint));

	/* copy the sections to the right addresses */
	for (i = 0; i < numsections; i++)
	{
		from = (unsigned char*)data + SWAPINT(swap, scnhdr[i].rawdata);
		to = (unsigned char*)(uPtr)SWAPINT(swap, scnhdr[i].physaddr);
		len = SWAPINT(swap, scnhdr[i].size);
		DPRINTF(("section %d from=%#x, to=%#x len=%d\n", i, from, to, len));

		if (len == 0)
			continue;

		if (SWAPSHORT(swap, scnhdr[i].flags) & S_BSS)
			memset(to, 0, len);
		else if (from)
			memmove(to, from, len);

	#ifdef MACHINE_CLAIM_MEMORY
		/* claim/map this area if requested */
		MACHINE_CLAIM_MEMORY(e, (char*)to, len);
	#endif /* MACHINE_CLAIM_MEMORY */
	}

	free(fhdr);
	return NO_ERROR;
}
示例#4
0
文件: wall.c 项目: CDarrow/DXX-Retro
void wall_swap(wall *w, int swap)
{
	if (!swap)
		return;
	
	w->segnum = SWAPINT(w->segnum);
	w->sidenum = SWAPINT(w->sidenum);
	w->hps = SWAPINT(w->hps);
	w->linked_wall = SWAPINT(w->linked_wall);
}
示例#5
0
文件: wall.c 项目: CDarrow/DXX-Retro
void active_door_swap(active_door *ad, int swap)
{
	if (!swap)
		return;
	
	ad->n_parts = SWAPINT(ad->n_parts);
	ad->front_wallnum[0] = SWAPSHORT(ad->front_wallnum[0]);
	ad->front_wallnum[1] = SWAPSHORT(ad->front_wallnum[1]);
	ad->back_wallnum[0] = SWAPSHORT(ad->back_wallnum[0]);
	ad->back_wallnum[1] = SWAPSHORT(ad->back_wallnum[1]);
	ad->time = SWAPINT(ad->time);
}
示例#6
0
Bool
coff_is_exec(Environ *e, uByte *load, uInt loadlen)
{
	Fileheader *fhdr = (Fileheader*)load;
	Optfileheader *ofhdr = (Optfileheader*)(fhdr + 1);
	Bool swap = (fhdr->magic[0] == COFF_MAGIC_1);

	DPRINTF(("loading: magic=%#x.%x flags=%#x ctime=%#x opthdrlen=%#x\n", 
			fhdr->magic[0], fhdr->magic[1], SWAPSHORT(swap, fhdr->flags),
			SWAPINT(swap, fhdr->ctime), SWAPSHORT(swap, fhdr->opthdrlen)));

	if (loadlen < sizeof *fhdr)
		return FALSE;

	if (swap)
	{
		uByte b = fhdr->magic[0];
		fhdr->magic[0] = fhdr->magic[1];
		fhdr->magic[1] = b;
	}

	/* verify that it is the right COFF file format */
	if (fhdr->magic[0] == COFF_MAGIC_0 &&
			fhdr->magic[1] == COFF_MAGIC_1 &&
			(SWAPSHORT(swap, fhdr->flags) & F_EXEC) &&
			ofhdr->magic[0] == COFF_OPT_MAGIC_0 &&
			ofhdr->magic[1] == COFF_OPT_MAGIC_1)
		return TRUE;

	return FALSE;
}
示例#7
0
文件: wall.c 项目: CDarrow/DXX-Retro
void cloaking_wall_swap(cloaking_wall *cw, int swap)
{
	int i;
	
	if (!swap)
		return;
	
	cw->front_wallnum = SWAPSHORT(cw->front_wallnum);
	cw->back_wallnum = SWAPSHORT(cw->back_wallnum);
	for (i = 0; i < 4; i++)
	{
		cw->front_ls[i] = SWAPINT(cw->front_ls[i]);
		cw->back_ls[i] = SWAPINT(cw->back_ls[i]);
	}
	cw->time = SWAPINT(cw->time);
}
示例#8
0
int
main(int argc, char *argv[])
{
	FILE *hogfile, *writefile;
	int len;
	char filename[13];
	char *buf;
	struct stat statbuf;
	int v = 0;

	if (argc > 1 && !strcmp(argv[1], "v")) {
		v = 1;
		argc--;
		argv++;
	}

	if (argc < 2) {
		printf("Usage: hogextract [v] hogfile [filename]\n"
		       "extracts all the files in hogfile into the current directory\n"
			   "Options:\n"
			   "  v    View files, don't extract\n");
		exit(0);
	}
	hogfile = fopen(argv[1], "rb");
	stat(argv[1], &statbuf);
	printf("%i\n", (int)statbuf.st_size);
	buf = (char *)malloc(3);
	fread(buf, 3, 1, hogfile);
	printf("Extracting from: %s\n", argv[1]);
	free(buf);
	while(ftell(hogfile)<statbuf.st_size) {
		fread(filename, 13, 1, hogfile);
		fread(&len, 1, 4, hogfile);
#ifdef WORDS_BIGENDIAN
		len = SWAPINT(len);
#endif
		if (argc > 2 && strcmp(argv[2], filename))
			fseek(hogfile, len, SEEK_CUR);
		else {
			printf("Filename: %s \tLength: %i\n", filename, len);
			if (v)
				fseek(hogfile, len, SEEK_CUR);
			else {
				buf = (char *)malloc(len);
				if (buf == NULL) {
					printf("Unable to allocate memory\n");
				} else {
					fread(buf, len, 1, hogfile);
					writefile = fopen(filename, "wb");
					fwrite(buf, len, 1, writefile);
					fclose(writefile);
					free(buf);
				}
			}
		}
	}
	fclose(hogfile);

	return 0;
}
示例#9
0
int CMovieLib::SetupMVL (CFile& cf)
{
	int			nFiles, offset;
	int			i, len;

	//read movie file header

nFiles = cf.ReadInt ();        //get number of files
if (nFiles > 255) {
	gameStates.app.bLittleEndian = 0;
	nFiles = SWAPINT (nFiles);
	}
if (!m_movies.Create (nFiles))
	return 0;
m_nMovies = nFiles;
offset = 4 + 4 + nFiles * (13 + 4);	//id + nFiles + nFiles * (filename + size)
for (i = 0; i < nFiles; i++) {
	if (cf.Read (m_movies [i].m_name, 13, 1) != 1)
		break;		//end of file (probably)
	len = cf.ReadInt ();
	m_movies [i].m_len = len;
	m_movies [i].m_offset = offset;
	offset += m_movies [i].m_len;
	}
cf.Close ();
m_flags = 0;
return nFiles;
}
void getPivot(int nsize, int currow)
{
    int i,irow;
    double big;
    double tmp;
    
    big = matrix[currow][currow];
    irow = currow;
    
    if (big == 0.0) {
        for(i = currow ; i < nsize; i++){
            tmp = matrix[i][currow];
            if (tmp != 0.0){
                big = tmp;
                irow = i;
                break;
            }
        }
    }
    
    if (big == 0.0){
        printf("The matrix is singular\n");
        exit(-1);
    }
    
    if (irow != currow){
        for(i = currow; i < nsize ; i++){
            SWAP(matrix[irow][i],matrix[currow][i]);
        }
        SWAP(B[irow],B[currow]);
        SWAPINT(swap[irow],swap[currow]);
    }
    
    
    {
        double pivotVal;
        pivotVal = matrix[currow][currow];
        
        if (pivotVal != 1.0){
            matrix[currow][currow] = 1.0;
            for(i = currow + 1; i < nsize; i++){
                matrix[currow][i] /= pivotVal;
            }
            B[currow] /= pivotVal;
        }
    }
}
示例#11
0
void Functions::sortElementsInt(vector<int> &array1, RefArrayXd array2)
{
    for (int i = 0; i < array1.size(); i++)
    {
        for (int j = 1; j < (array1.size()-i); j++)
        {
            if (array1[j-1] > array1[j])
            {
                SWAPINT(array1[j-1], array1[j]);         // SWAP array1 elements in increasing order
                SWAPDOUBLE(array2(j-1), array2(j));      // SWAP array2 elements accordingly
            }
            else
                if (array1[j-1] == array1[j])
                    continue;
        }
    }
    
}
static int auserver_process_client(int client_name, int fd)
{
    /* Gets called for each client */
    snd_header header;
    int r;

    printf("client %d connected, ",client_name);
    fflush(stdout);
    /* Get header */
    r = read(fd,&header,sizeof(header));
    if (r != sizeof(header))
    {
	cst_errmsg("socket: connection didn't give a header\n");
	return -1;
    }
    if (CST_LITTLE_ENDIAN)
    {
	header.magic = SWAPINT(header.magic);
	header.hdr_size = SWAPINT(header.hdr_size);
	header.data_size = SWAPINT(header.data_size);
	header.encoding = SWAPINT(header.encoding);
	header.sample_rate = SWAPINT(header.sample_rate);
	header.channels = SWAPINT(header.channels);
    }

    if (header.magic != CST_SND_MAGIC)
    {
	cst_errmsg("socket: client something other than snd waveform\n");
	return -1;
    }

    printf("%d bytes at %d rate, ", header.data_size, header.sample_rate);
    fflush(stdout);

    if (play_wave_from_socket(&header,fd) == CST_OK_FORMAT)
	printf("successful\n");
    else
	printf("unsuccessful\n");
    
    return 0;
}
示例#13
0
void fix_swap(fix *f)
{
	*f = (fix)SWAPINT((int)*f);
}
示例#14
0
文件: hogcreate.c 项目: btb/d2x
int
main(int argc, char *argv[])
{
	FILE *hogfile, *readfile;
	DIR *dp;
	struct dirent *ep;
	char filename[13];
	char *buf;
	struct stat statbuf;
	int tmp;

	if (argc != 2) {
		printf("Usage: hogcreate hogfile\n"
		       "creates hogfile using all the files in the current directory\n");
		exit(0);
	}
	hogfile = fopen(argv[1], "wb");
	buf = (char *)malloc(3);
	strncpy(buf, "DHF", 3);
	fwrite(buf, 3, 1, hogfile);
	printf("Creating: %s\n", argv[1]);
	free(buf);
	dp = opendir("./");
	if (dp != NULL) {
		while ((ep = readdir(dp))) {
			if (strlen(ep->d_name) > 12) {
				fprintf(stderr, "error: filename %s too long! (12 chars max!)\n", ep->d_name);
				return 1;
			}
			memset(filename, 0, 13);
			strcpy(filename, ep->d_name);
			stat(filename, &statbuf);
			if(! S_ISDIR(statbuf.st_mode)) {
				printf("Filename: %s \tLength: %i\n", filename, (int)statbuf.st_size);
				readfile = fopen(filename, "rb");
				buf = (char *)malloc(statbuf.st_size);
				if (buf == NULL) {
					printf("Unable to allocate memery\n");
				} else {
					fwrite(filename, 13, 1, hogfile);
					tmp = (int)statbuf.st_size;
#ifdef WORDS_BIGENDIAN
					tmp = SWAPINT(tmp);
#endif
					fwrite(&tmp, 4, 1, hogfile);
					if ( fread(buf, statbuf.st_size, 1, readfile) != 1 ) {
						printf("Error reading %s\n", filename);
						fclose(readfile);
						exit(EXIT_FAILURE);
					}
					fwrite(buf, statbuf.st_size, 1, hogfile);
				}
				fclose(readfile);

			}
		}
		closedir(dp);
	}
	fclose(hogfile);

	return 0;
}
示例#15
0
// Handle RDM Requests and send response
// see http://www.opendmx.net/index.php/RDM_Discovery
// see http://www.enttec.com/docs/sniffer_manual.pdf
void DMXSerialClass2::tick(void)
{
  if ((_dmxState == IDLE) && (_rdmAvailable)) {
    // never process twice.
    _rdmAvailable = false;

    // respond to RDM commands now.
    bool8 packetIsForMe = false;
    bool8 packetIsForGroup = false;
    bool8 packetIsForAll = false;
    bool8 isHandled = false;

    struct RDMDATA *rdm = &_rdm.packet;
    
    byte     CmdClass  = rdm->CmdClass;  // command class
    uint16_t Parameter = rdm->Parameter; // parameter ID

    // in the ISR only some global conditions are checked: DestID
    if (DeviceIDCmp(rdm->DestID, _devIDAll) == 0) {
      packetIsForAll = true;
    } else if (DeviceIDCmp(rdm->DestID, _devIDGroup) == 0) {
      packetIsForGroup = true;
    } else if (DeviceIDCmp(rdm->DestID, _devID) == 0) {
      packetIsForMe = true;
    } // if

      if ((! packetIsForMe) && (! packetIsForGroup) && (! packetIsForAll)) {
        // ignore this packet

      } else if (CmdClass == E120_DISCOVERY_COMMAND) { // 0x10
        // handle all Discovery commands locally 
        if (Parameter == SWAPINT(E120_DISC_UNIQUE_BRANCH)) { // 0x0001
          // not tested here for pgm space reasons: rdm->Length must be 24+6+6 = 36
          // not tested here for pgm space reasons: rdm->_DataLength must be 6+6 = 12
          
          if (! _isMute) {
            // check if my _devID is in the discovery range
            if ((DeviceIDCmp(rdm->Data, _devID) <= 0) && (DeviceIDCmp(_devID, rdm->Data+6) <= 0)) {
              
              // respond a special discovery message !
              struct DISCOVERYMSG *disc = &_rdm.discovery;
              _rdmCheckSum = 6 * 0xFF;
              
              // fill in the _rdm.discovery response structure
              for (byte i = 0; i < 7; i++)
                disc->headerFE[i] = 0xFE;
              disc->headerAA = 0xAA;  
              for (byte i = 0; i < 6; i++) {
                disc->maskedDevID[i+i]   = _devID[i] | 0xAA;
                disc->maskedDevID[i+i+1] = _devID[i] | 0x55;
                _rdmCheckSum += _devID[i];
              }
              disc->checksum[0] = (_rdmCheckSum >> 8)   | 0xAA;
              disc->checksum[1] = (_rdmCheckSum >> 8)   | 0x55;
              disc->checksum[2] = (_rdmCheckSum & 0xFF) | 0xAA;
              disc->checksum[3] = (_rdmCheckSum & 0xFF) | 0x55;
            
              // disable all interrupt routines and send the _rdm.discovery packet 
              // now send out the _rdm.buffer without a starting BREAK.
              _DMXSerialBaud(Calcprescale(DMXSPEED), DMXFORMAT); 
              UCSRnB = (1<<TXENn); // no interrupts !
              
              // delayMicroseconds(50);  // ??? 180
              digitalWrite(_dmxModePin, _dmxModeOut); // data Out direction

              unsigned int _rdmBufferLen = sizeof(_rdm.discovery);
              for (unsigned int i = 0; i < _rdmBufferLen; i++) {
                UDRn = _rdm.buffer[i];
                UCSRnA= (1<<TXCn);
                loop_until_bit_is_set(UCSRnA, TXCn);
              } // for
            
              digitalWrite(_dmxModePin, _dmxModeIn); // data Out direction
            
              // Re-enable receiver and Receive interrupt
              _dmxState= IDLE; // initial state
              UCSRnB = (1<<RXENn) | (1<<RXCIEn);
              _DMXSerialBaud(Calcprescale(DMXSPEED), DMXFORMAT); // Enable serial reception with a 250k rate
            } // if
          } // if 

        } else if (Parameter == SWAPINT(E120_DISC_UN_MUTE)) { // 0x0003
          isHandled = true;
          if (packetIsForMe) { // 05.12.2013
            if (_rdm.packet.DataLength > 0) {
              // Unexpected data
              // Do nothing
            } else {
              _isMute = false;
              // Control field
              _rdm.packet.Data[0] = 0b00000000;
              _rdm.packet.Data[1] = 0b00000000;
              _rdm.packet.DataLength = 2;
              respondMessage(true); // 21.11.2013
            }
          }
          
        } else if (Parameter == SWAPINT(E120_DISC_MUTE)) { // 0x0002
          isHandled = true;
          if (packetIsForMe) { // 05.12.2013
            if (_rdm.packet.DataLength > 0) {
              // Unexpected data
              // Do nothing
            } else {
              _isMute = true;
              // Control field
              _rdm.packet.Data[0] = 0b00000000;
              _rdm.packet.Data[1] = 0b00000000;
              _rdm.packet.DataLength = 2;
              respondMessage(true); // 21.11.2013
            }
          }

        } // if

      } else {
示例#16
0
文件: interp.c 项目: paud/d2x-xl
inline void FixSwap (fix *f)
{
*f = (fix)SWAPINT ((int)*f);
}
示例#17
0
void inline quicksort(unsigned long n, int arr[]){
	if(n>1){
	unsigned long i,ir=n,j,k,l=1,*istack;
	int jstack=0;
	int a,temp;
	istack=lvector(1,NSTACK);
	for (;;) {
		//Insertion sort when subarray small enough.
		if (ir-l < M) {
			for (j=l+1;j<=ir;j++) {
				a=arr[j];
				for (i=j-1;i>=l;i--) {
					if (arr[i] <= a) break;
					arr[i+1]=arr[i];
				}
				arr[i+1]=a;
			}
			if (jstack == 0) break;
			ir=istack[jstack--];
			//Pop stack and begin a new round of parti-
			l=istack[jstack--];
			//tioning.
		} else {
			k=(l+ir) >> 1;
			//Choose median of left, center, and right el-
			SWAPINT(arr[k],arr[l+1]);
			//ements as partitioning element a. Also
			if (arr[l] > arr[ir]) {
				//rearrange so that a[l] ≤ a[l+1] ≤ a[ir].
				SWAPINT(arr[l],arr[ir]);
			}
			if (arr[l+1] > arr[ir]) {
				SWAPINT(arr[l+1],arr[ir]);
			}
			if (arr[l] > arr[l+1]) {
				SWAPINT(arr[l],arr[l+1]);
			}
			i=l+1;
			//Initialize pointers for partitioning.
			j=ir;
			a=arr[l+1];
			//Partitioning element.
			for (;;) {
				//Beginning of innermost loop.
				do i++; while (arr[i] < a);
				//Scan up to find element > a.
				do j--; while (arr[j] > a);
				//Scan down to find element < a.
				if (j < i) break;
				//Pointers crossed. Partitioning complete.
				SWAPINT(arr[i],arr[j]);
				//Exchange elements.
			}
			//End of innermost loop.
			arr[l+1]=arr[j];
			//Insert partitioning element.
			arr[j]=a;
			jstack += 2;
			//Push pointers to larger subarray on stack, process smaller subarray immediately.
			if (jstack > NSTACK) nrerror("NSTACK too small in sort.");
			if (ir-i+1 >= j-l) {
				istack[jstack]=ir;
				istack[jstack-1]=i;
				ir=j-1;
			} else {
				istack[jstack]=j-1;
				istack[jstack-1]=l;
				l=i;
			}
		}
	}
	free_lvector(istack,1,NSTACK);
	}else{
示例#18
0
static void drawLine(imImage* image, int theta, int rho)
{
  int xsize, ysize, xstart, xstop, ystart, ystop, xhalf, yhalf;
  float a, b;
  imbyte *map = (imbyte*)image->data[0];  // gray or red plane

  xsize = image->width;
  ysize = image->height;
  xhalf = xsize/2;
  yhalf = ysize/2;

  if (theta == 0)  /* vertical line */
  {
    int y;
    if (rho+xhalf < 0 || rho+xhalf > xsize-1) return;
    for (y=0; y < ysize; y++)
      map[y*xsize + rho+xhalf]=254;

    return;
  }

  if (theta == 90)  /* horizontal line */
  {
    int x;
    if (rho+yhalf < 0 || rho+yhalf > ysize-1) return;
    for (x=0; x < xsize; x++)
      map[(rho+yhalf)*xsize + x]=254;

    return;
  }

  a = (float)(-costab[theta]/sintab[theta]);
  b = (float)((rho + xhalf*costab[theta] + yhalf*sintab[theta])/sintab[theta]);

  {
    int x[2];
    int y[2];
    int c = 0;
    int y1 = imRound(b);              /* x = 0 */
    int y2 = imRound(a*(xsize-1)+b);  /* x = xsize-1 */

    int x1 = imRound(-b/a);           /* y = 0 */
    int x2 = imRound((ysize-1-b)/a);  /* y = ysize-1 */

    if (y1 >= 0 && y1 < ysize)
    {
      y[c] = y1;
      x[c] = 0;
      c++;
    }

    if (y2 >= 0 && y2 < ysize)
    {
      y[c] = y2;
      x[c] = xsize-1;
      c++;
    }

    if (c < 2 && x1 >= 0 && x1 < xsize)
    {
      x[c] = x1;
      y[c] = 0;
      c++;
    }

    if (c < 2 && x2 >= 0 && x2 < xsize)
    {
      x[c] = x2;
      y[c] = ysize-1;
      c++;
    }

    if (c < 2) return;

    ystart = y[0];
    xstart = x[0];
    ystop = y[1];
    xstop = x[1];
  }

  {
    int x, y;
    if (45 <= theta && theta <= 135)
    {
      if (xstart > xstop)
        SWAPINT(xstart, xstop);

      for (x=xstart; x <= xstop; x++)
      {
        y = imRound(a*x + b);
        if (y < 0) continue;
        if (y > ysize-1) continue;
        map[y*xsize + x]=254;
      }
    }
    else
    {
      if (ystart > ystop)
        SWAPINT(ystart, ystop);

      for (y=ystart; y <= ystop; y++)
      {
        x = imRound((y-b)/a);
        if (x < 0) continue;
        if (x > xsize-1) continue;
        map[y*xsize + x]=254;
      }
    }
  }
}
示例#19
0
static void * ogg_player_thread(private_data_ogg * priv)
{
	int		first_time = 1;
	long	ret;

	int		offs;
	u_int	*buff;

	//init
	LWP_InitQueue(&oggplayer_queue);

	priv[0].vi = ov_info(&priv[0].vf, -1);

	ASND_Pause(0);

	priv[0].pcm_indx = 0;
	priv[0].pcmout_pos = 0;
	priv[0].eof = 0;
	priv[0].flag = 0;
	priv[0].current_section = 0;

	ogg_thread_running = 1;

	while (!priv[0].eof && ogg_thread_running)
	{
		if (priv[0].flag)
			LWP_ThreadSleep(oggplayer_queue); // wait only when i have samples to send

		if (priv[0].flag == 0) // wait to all samples are sent
		{
			if (ASND_TestPointer(0, priv[0].pcmout[priv[0].pcmout_pos])
					&& ASND_StatusVoice(0) != SND_UNUSED)
			{
				priv[0].flag |= 64;
				continue;
			}
			if (priv[0].pcm_indx < READ_SAMPLES)
			{
				priv[0].flag = 3;

				if (priv[0].seek_time >= 0)
				{
					ov_time_seek(&priv[0].vf, priv[0].seek_time);
					priv[0].seek_time = -1;
				}

				ret
						= ov_read(
								&priv[0].vf,
								(void*)&priv[0].pcmout[priv[0].pcmout_pos][priv[0].pcm_indx],
								MAX_PCMOUT,/*0,2,1,*/&priv[0].current_section);

				priv[0].flag &= 192;
				if (ret == 0)
				{
					/* EOF */
					if (priv[0].mode & 1)
						ov_pcm_seek(&priv[0].vf, ogg_loop_start); // repeat
					else
						priv[0].eof = 1; // stops
				}
				else if (ret < 0)
				{
					/* error in the stream.  Not a problem, just reporting it in
					 case we (the app) cares.  In this case, we don't. */
					if (ret != OV_HOLE)
					{
						if (priv[0].mode & 1)
							ov_time_seek(&priv[0].vf, 0); // repeat
						else
							priv[0].eof = 1; // stops
					}
				}
				else
				{
					/* we don't bother dealing with sample rate changes, etc, but you'll have to*/

					// Reverse stereo fix added by Lameguy64/TheCodingBrony
					if (priv[0].vi->channels == 2) {
						buff=(u_int*)&priv[0].pcmout[priv[0].pcmout_pos][priv[0].pcm_indx];
						for(offs=0; offs<ret/4; offs+=1) {
							buff[offs] = SWAPINT(buff[offs]);
						}
					}

					priv[0].pcm_indx += ret >> 1; //get 16 bits samples

				}
			}
			else
				priv[0].flag = 1;
		}
示例#20
0
int main(int argc, char *argv[])
{
	int i, filehandle;
	char *mvlfile = NULL, *mvefile = NULL;

	for (i = 1; i < argc; i++) {
		if (!strcmp(argv[i], "-h"))
			usage();

		if (!strcmp(argv[i], "-f"))
			g_sdlVidFlags |= SDL_FULLSCREEN;

		if (!strcmp(argv[i], "-l"))
			g_loop = 1;

		if (!strcmp(argv[i], "-s")) {
			if (argc < i + 2)
				usage();
			g_spdFactorNum = atoi(argv[i + 1]);
			i++;
		}

		if (strchr(argv[i], '.') && !strcasecmp(strchr(argv[i], '.'), ".mvl"))
			mvlfile = argv[i];

		if (strchr(argv[i], '.') && !strcasecmp(strchr(argv[i], '.'), ".mve"))
			mvefile = argv[i];
	}

	if (mvlfile) {
		int nfiles;
		char filename[MAX_FILES][13];
		int filesize[MAX_FILES];
		char sig[4];

#ifdef O_BINARY
		filehandle = open(mvlfile, O_RDONLY | O_BINARY);
#else
		filehandle = open(mvlfile, O_RDONLY);
#endif
		if (filehandle == -1) {
			fprintf(stderr, "Error opening %s\n", mvlfile);
			exit(1);
		}
		if ((read(filehandle, sig, 4) < 4) ||
			(strncmp(sig, "DMVL", 4)) ||
			(read(filehandle, &nfiles, 4) < 4)) {
			fprintf(stderr, "Error reading %s\n", mvlfile);
			exit(1);
		}
#ifdef WORDS_BIGENDIAN
		nfiles = SWAPINT(nfiles);
#endif
		if (nfiles > MAX_FILES) {
			fprintf(stderr, "Error reading %s: nfiles = %d, MAX_FILES = %d\n",
					mvlfile, nfiles, MAX_FILES);
		}
		for (i = 0; i < nfiles; i++) {
			if ((read(filehandle, filename[i], 13) < 13) ||
				(read(filehandle, &filesize[i], 4) < 4) ||
				(strlen(filename[i]) > 12))	{
				fprintf(stderr, "Error reading %s\n", mvlfile);
				exit(1);
			}
#ifdef WORDS_BIGENDIAN
			filesize[i] = SWAPINT(filesize[i]);
#endif
		}

		for (i = 0; i < nfiles; i++) {
			if (mvefile) {
				if (!strcasecmp(filename[i], mvefile))
					break;
				else
					lseek(filehandle, filesize[i], SEEK_CUR);
			} else
				printf("%13s\t%d\n", filename[i], filesize[i]);
		}
		if (!mvefile)
			exit(0);

	} else if (mvefile) {
#ifdef O_BINARY
		filehandle = open(mvefile, O_RDONLY | O_BINARY);
#else
		filehandle = open(mvefile, O_RDONLY);
#endif
	} else
		usage();

    if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0)
    {
        fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
        exit(1);
    }
    atexit(SDL_Quit);

	doPlay(filehandle);

	return 0;
}
示例#21
0
int play_wave_client(cst_wave *w,const char *servername,int port,
		     const char *encoding)
{
    int audiofd,q,i,n,r;
    int sample_width;
    unsigned char bytes[CST_AUDIOBUFFSIZE];
    short shorts[CST_AUDIOBUFFSIZE];
    snd_header header;

    if (!w)
	return CST_ERROR_FORMAT;

    if ((audiofd = cst_socket_open(servername,port)) == 0)
	return CST_ERROR_FORMAT;

    header.magic = (unsigned int)0x2e736e64;
    header.hdr_size = sizeof(header);
    if (cst_streq(encoding,"ulaw"))
    {
	sample_width = 1;
	header.encoding = 1; /* ulaw */
    }
    else if (cst_streq(encoding,"uchar"))
    {
	sample_width = 1;
	header.encoding = 2; /* unsigned char */
    }
    else 
    {
	sample_width = 2;
	header.encoding = 3; /* short */
    }
    header.data_size = sample_width * w->num_samples * w->num_channels;
    header.sample_rate = w->sample_rate;
    header.channels = w->num_channels;
    if (CST_LITTLE_ENDIAN)
    {   /* If I'm intel etc swap things, so "network byte order" */
	header.magic = SWAPINT(header.magic);
	header.hdr_size = SWAPINT(header.hdr_size);
	header.data_size = SWAPINT(header.data_size);
	header.encoding = SWAPINT(header.encoding);
	header.sample_rate = SWAPINT(header.sample_rate);
	header.channels = SWAPINT(header.channels);
    }

    if (write(audiofd, &header, sizeof(header)) != sizeof(header))
    {
	cst_errmsg("auclinet: failed to write header to server\n");
	return CST_ERROR_FORMAT;
    }

    for (i=0; i < w->num_samples; i += r)
    {
	if (w->num_samples > i+CST_AUDIOBUFFSIZE)
	    n = CST_AUDIOBUFFSIZE;
	else
	    n = w->num_samples-i;
	if (cst_streq(encoding,"ulaw"))
	{
	    for (q=0; q<n; q++)
		bytes[q] = cst_short_to_ulaw(w->samples[i+q]);
	    r = write(audiofd,bytes,n);
	}
	else 
	{
	    for (q=0; q<n; q++)
		if (CST_LITTLE_ENDIAN)
		    shorts[q] = SWAPSHORT(w->samples[i+q]);
		else
		    shorts[q] = w->samples[i+q];
	    r = write(audiofd,shorts,n*2);
	    r /= 2;
	}
	if (r <= 0)
	    cst_errmsg("failed to write %d samples\n",n);
    }

    cst_socket_close(audiofd);

    return CST_OK_FORMAT;
}
示例#22
0
Sym_table *
coff_symbols(Environ *e, uByte *load, uInt loadlen)
{
	uByte *image = load;
	Fileheader *fhdr;
	Bool swap;
	Optfileheader *ofhdr;
	Sectionheader *scnhdr;
	Syment *sym;
	char *strtab;
	int i, nsyms, num, sect, numsections;
	Sym_table *tab;

	/* sanity check */
	if (!coff_is_exec(e, load, loadlen))
		return NULL;

	fhdr = (Fileheader*)image;
	swap = (fhdr->magic[0] == COFF_MAGIC_1);
	ofhdr = (Optfileheader*)(fhdr + 1);
	scnhdr = (Sectionheader*)((uPtr)ofhdr + SWAPSHORT(swap, fhdr->opthdrlen));
	nsyms = SWAPINT(swap, fhdr->nsyms);
	image += SWAPINT(swap, fhdr->symtab);
	strtab = (char*)(image + nsyms * SYMESZ);
	numsections = SWAPSHORT(swap, fhdr->sections);
	num = 0;
	DPRINTF((
		"coff_symbols: fhdr=%#x swap=%d nsyms=%d strtab=%#x numsections=%d\n",
			fhdr, swap, nsyms, strtab, numsections));

	/* first count the number of symbols we need */
    for (i = 0; i < nsyms; i++)
	{
		/* sym may be mis-sized by the compiler */
		sym = (struct syment*)(image);
		DPRINTF(("coff_symbols: i=%d sym=%#x", i, sym));
		sect = SWAPSHORT(swap, sym->n_scnum);
		DPRINTF((" scnum=%d", sect));

		if (sect >= 0 && sect < numsections)
			num++;

		DPRINTF((" num=%d\n", num));
		image += SYMESZ * (sym->n_numaux + 1);
	}

	DPRINTF(("coff_symbols: num=%d\n", num));

	/* allocate space for the symbols */
	tab = (Sym_table*)malloc(sizeof *tab);

	if (tab == NULL)
		return NULL;

	memset(tab, 0, sizeof *tab);
	tab->list = (Sym_ent*)malloc(sizeof *tab->list * num);

	if (tab->list == NULL)
	{
		free(tab);
		return NULL;
	}

	num = 0;
	image = load + SWAPINT(swap, fhdr->symtab);

    for (i = 0; i < nsyms; i++)
	{
		/* sym may be mis-sized by the compiler */
		sym = (struct syment*)(image);
		sect = SWAPSHORT(swap, sym->n_scnum);

		if (sect >= 0 && sect < numsections)
		{
			if (sym->n_zeroes)		/* old-style symbol */
			{
				tab->list[num].name = lstrdup(sym->n_name,
						sym->n_name[7] ?  8 : strlen(sym->n_name));
			}
			else					/* symbol is in string table */
			{
				tab->list[num].name = strtab + SWAPINT(swap, sym->n_offset);
				tab->list[num].name = cstrdup(tab->list[num].name);
			}

			tab->list[num].addr = SWAPINT(swap, sym->n_value);
			tab->list[num].type = (SWAPSHORT(swap, scnhdr[sect].flags) & S_TEXT)
					? SYM_TEXT : SYM_DATA;
			DPRINTF(("tab %d: name=%P addr=%#x type=%#x\n", num,
					tab->list[num].name,
					tab->list[num].addr, tab->list[num].type));

			if (*tab->list[num].name)
				num++;
			else
				free(tab->list[num].name);
		}

		image += SYMESZ * (sym->n_numaux + 1);
	}

	tab->num = num;
	return tab;
}
示例#23
0
void player_rw_swap(player_rw *p, int swap)
{
	int i;

	if (!swap)
		return;

	p->objnum = SWAPINT(p->objnum);
	p->n_packets_got = SWAPINT(p->n_packets_got);
	p->n_packets_sent = SWAPINT(p->n_packets_sent);
	p->flags = SWAPINT(p->flags);
	p->energy = SWAPINT(p->energy);
	p->shields = SWAPINT(p->shields);
	p->killer_objnum = SWAPSHORT(p->killer_objnum);
	p->primary_weapon_flags = SWAPSHORT(p->primary_weapon_flags);
	p->secondary_weapon_flags = SWAPSHORT(p->secondary_weapon_flags);
	for (i = 0; i < MAX_PRIMARY_WEAPONS; i++)
		p->primary_ammo[i] = SWAPSHORT(p->primary_ammo[i]);
	for (i = 0; i < MAX_SECONDARY_WEAPONS; i++)
		p->secondary_ammo[i] = SWAPSHORT(p->secondary_ammo[i]);
	p->last_score = SWAPINT(p->last_score);
	p->score = SWAPINT(p->score);
	p->time_level = SWAPINT(p->time_level);
	p->time_total = SWAPINT(p->time_total);
	p->cloak_time = SWAPINT(p->cloak_time);
	p->invulnerable_time = SWAPINT(p->invulnerable_time);
	p->KillGoalCount = SWAPSHORT(p->KillGoalCount);
	p->net_killed_total = SWAPSHORT(p->net_killed_total);
	p->net_kills_total = SWAPSHORT(p->net_kills_total);
	p->num_kills_level = SWAPSHORT(p->num_kills_level);
	p->num_kills_total = SWAPSHORT(p->num_kills_total);
	p->num_robots_level = SWAPSHORT(p->num_robots_level);
	p->num_robots_total = SWAPSHORT(p->num_robots_total);
	p->hostages_rescued_total = SWAPSHORT(p->hostages_rescued_total);
	p->hostages_total = SWAPSHORT(p->hostages_total);
	p->homing_object_dist = SWAPINT(p->homing_object_dist);
}