示例#1
0
index_header *
readIndex(const uint8 *buf) {
    index_header *h;
    const uint8 *sizeptr;
    uint32 size, totsize;
    uint32 i;

    if ((uint32) MAKE_DWORD(buf[3], buf[2], buf[1], buf[0]) != 0xffffffff ||
            MAKE_WORD(buf[5], buf[4]) != 0x0000) {
        fprintf(stderr, "File is not a valid STRTAB file.\n");
        exit(EXIT_FAILURE);
    }

    h = malloc(sizeof (index_header));
    h->num_entries = MAKE_WORD(buf[7], buf[6]);
    h->entries = malloc(h->num_entries * sizeof (entry_desc));

    sizeptr = buf + 8;
    if (MAKE_DWORD(sizeptr[3], sizeptr[2], sizeptr[1], sizeptr[0])) {
        fprintf(stderr, "WARNING: Placeholder string entry hasn't got "
                "size 0, but %d.\n",
                MAKE_DWORD(sizeptr[3], sizeptr[2], sizeptr[1], sizeptr[0]));
    }
    sizeptr += 4;

    totsize = 0;
    for (i = 0; i < h->num_entries; i++) {
        size = MAKE_DWORD(sizeptr[3], sizeptr[2], sizeptr[1], sizeptr[0]);
        h->entries[i].size = size;
        h->entries[i].offset = totsize;
        sizeptr += 4;
        totsize += size;
    }
    return h;
}
示例#2
0
文件: png_obj.c 项目: henrycg/mulk
static mulk_type_return_t read_png_dim(const char *filename, int *width, int *height)
{
	unsigned char buffer[PNG_HEADER1_SIZE + PNG_HEADER2_OFFSET + PNG_HEADER2_SIZE + PNG_DIM_SIZE], *ptr;
	mulk_type_return_t ret = MULK_RET_ERR;
	size_t bytestoread;
	FILE *file = NULL;

	if ((file = fopen(filename, "rb")) == NULL)
		return MULK_RET_FILE_ERR;

	bytestoread = PNG_HEADER1_SIZE + PNG_HEADER2_OFFSET + PNG_HEADER2_SIZE + PNG_DIM_SIZE;
	if (fread(buffer, 1, bytestoread, file) != bytestoread)
		goto Exit;

	ptr = buffer;
	if (memcmp(ptr, PNG_HEADER_VAL1, PNG_HEADER1_SIZE))
		goto Exit;

	ptr += PNG_HEADER1_SIZE + PNG_HEADER2_OFFSET;
	if (memcmp(ptr, PNG_HEADER_VAL2, PNG_HEADER2_SIZE))
		goto Exit;

	ptr += PNG_HEADER2_SIZE;
	*width = MAKE_DWORD(ptr[0], ptr[1], ptr[2], ptr[3]);
	*height = MAKE_DWORD(ptr[4], ptr[5], ptr[6], ptr[7]);

	ret = MULK_RET_OK;

Exit:
	fclose(file);
	return ret;
}
示例#3
0
static bool
GenerateDruuge_generatePlanets (SOLARSYS_STATE *solarSys)
{
	COUNT angle;

	GenerateDefault_generatePlanets (solarSys);

	memmove (&solarSys->PlanetDesc[1], &solarSys->PlanetDesc[0],
			sizeof (solarSys->PlanetDesc[0])
			* solarSys->SunDesc[0].NumPlanets);
	++solarSys->SunDesc[0].NumPlanets;

	solarSys->PlanetDesc[0].data_index = DUST_WORLD;
	solarSys->PlanetDesc[0].radius = EARTH_RADIUS * 50L / 100;
	solarSys->PlanetDesc[0].NumPlanets = 0;
	angle = HALF_CIRCLE - OCTANT;
	solarSys->PlanetDesc[0].location.x =
			COSINE (angle, solarSys->PlanetDesc[0].radius);
	solarSys->PlanetDesc[0].location.y =
			SINE (angle, solarSys->PlanetDesc[0].radius);
	solarSys->PlanetDesc[0].rand_seed = MAKE_DWORD (
			solarSys->PlanetDesc[0].location.x,
			solarSys->PlanetDesc[0].location.y);
	ComputeSpeed(&solarSys->PlanetDesc[0], FALSE, 1);

	return true;
}
示例#4
0
static bool
GenerateVux_generatePlanets (SOLARSYS_STATE *solarSys)
{
	COUNT angle;

	GenerateDefault_generatePlanets (solarSys);

	if (CurStarDescPtr->Index == MAIDENS_DEFINED)
	{
		GenerateDefault_generatePlanets (solarSys);
				// XXX: this is the second time that this function is
				// called. Is it safe to remove one, or does this change
				// the RNG so that the outcome is different?
		solarSys->PlanetDesc[0].data_index = REDUX_WORLD;
		solarSys->PlanetDesc[0].radius = EARTH_RADIUS * 212L / 100;
		angle = ARCTAN (solarSys->PlanetDesc[0].location.x,
				solarSys->PlanetDesc[0].location.y);
		solarSys->PlanetDesc[0].location.x =
				COSINE (angle, solarSys->PlanetDesc[0].radius);
		solarSys->PlanetDesc[0].location.y =
				SINE (angle, solarSys->PlanetDesc[0].radius);
		ComputeSpeed(&solarSys->PlanetDesc[0], FALSE, 1);
	}
	else
	{
		if (CurStarDescPtr->Index == VUX_DEFINED)
		{
			solarSys->PlanetDesc[0].data_index = REDUX_WORLD;
			solarSys->PlanetDesc[0].NumPlanets = 1;
			solarSys->PlanetDesc[0].radius = EARTH_RADIUS * 42L / 100;
			angle = HALF_CIRCLE + OCTANT;
			ComputeSpeed(&solarSys->PlanetDesc[0], FALSE, 1);
		}
		else /* if (CurStarDescPtr->Index == VUX_BEAST_DEFINED) */
		{
			memmove (&solarSys->PlanetDesc[1], &solarSys->PlanetDesc[0],
					sizeof (solarSys->PlanetDesc[0])
					* solarSys->SunDesc[0].NumPlanets);
			++solarSys->SunDesc[0].NumPlanets;

			angle = HALF_CIRCLE - OCTANT;
			solarSys->PlanetDesc[0].data_index = WATER_WORLD;
			solarSys->PlanetDesc[0].radius = EARTH_RADIUS * 110L / 100;
			solarSys->PlanetDesc[0].NumPlanets = 0;
			ComputeSpeed(&solarSys->PlanetDesc[0], FALSE, 1);
		}

		solarSys->PlanetDesc[0].location.x =
				COSINE (angle, solarSys->PlanetDesc[0].radius);
		solarSys->PlanetDesc[0].location.y =
				SINE (angle, solarSys->PlanetDesc[0].radius);
		solarSys->PlanetDesc[0].rand_seed = MAKE_DWORD (
				solarSys->PlanetDesc[0].location.x,
				solarSys->PlanetDesc[0].location.y);
	}
	return true;
}
示例#5
0
DECODE_REF
copen (PVOID InStream, STREAM_TYPE SType, STREAM_MODE SMode)
{
	MEM_HANDLE h;
	DWORD StreamLength;

	_StreamType = SType;
	_Stream = InStream;
	if (SMode == STREAM_WRITE) /* writing */
	{
		OutChar (0); /* skip future StreamLength */
		OutChar (0);
		OutChar (0);
		OutChar (0);

		StreamLength = 0;
	}
	else /* reading */
	{
		BYTE lobyte, hibyte;
		UWORD loword, hiword;

		lobyte = (BYTE)InChar ();
		hibyte = (BYTE)InChar ();
		loword = MAKE_WORD (lobyte, hibyte);
		lobyte = (BYTE)InChar ();
		hibyte = (BYTE)InChar ();
		hiword = MAKE_WORD (lobyte, hibyte);

		StreamLength = MAKE_DWORD (loword, hiword);
	}

	h = 0;
	if (StreamLength == 0xFFFFFFFF
			|| (h = AllocCodeDesc ()) == 0
			|| (_lpCurCodeDesc = LockCodeDesc (h)) == 0)
	{
		_lpCurCodeDesc = 0;
		FreeCodeDesc (h);
	}
	else
	{
		_lpCurCodeDesc->fh = h;
		_lpCurCodeDesc->Stream = _Stream;
		_lpCurCodeDesc->StreamType = _StreamType;
		_lpCurCodeDesc->StreamMode = SMode;
		_lpCurCodeDesc->StreamLength = StreamLength;
		_lpCurCodeDesc->buf_index = N - F;
		memset ((PBYTE)&_lpCurCodeDesc->text_buf[0], ' ', N - F);

		StartHuff ();
	}

	return ((DECODE_REF)_lpCurCodeDesc);
}
示例#6
0
static void
dword_convert (DWORD *dword_array, COUNT num_dwords)
{
	BYTE *p = (BYTE*)dword_array;

	do
	{
		*dword_array++ = MAKE_DWORD (
				MAKE_WORD (p[3], p[2]),
				MAKE_WORD (p[1], p[0])
				);
		p += 4;
	} while (--num_dwords);
}
示例#7
0
static void
init_probe (void)
{
	BYTE b0, b1, b2, b3;
	HSTARSHIP hStarShip;

	b0 = GET_GAME_STATE (URQUAN_PROBE_GRPOFFS0);
	b1 = GET_GAME_STATE (URQUAN_PROBE_GRPOFFS1);
	b2 = GET_GAME_STATE (URQUAN_PROBE_GRPOFFS2);
	b3 = GET_GAME_STATE (URQUAN_PROBE_GRPOFFS3);
	GLOBAL (BattleGroupRef) = MAKE_DWORD (
			MAKE_WORD (b0, b1), MAKE_WORD (b2, b3)
			);
	if (GLOBAL (BattleGroupRef) == 0)
	{
		CloneShipFragment (URQUAN_PROBE_SHIP,
				&GLOBAL (npc_built_ship_q), 0);

		GLOBAL (BattleGroupRef) = PutGroupInfo (~0L, 1);
		b0 = LOBYTE (LOWORD (GLOBAL (BattleGroupRef)));
		b1 = HIBYTE (LOWORD (GLOBAL (BattleGroupRef)));
		b2 = LOBYTE (HIWORD (GLOBAL (BattleGroupRef)));
		b3 = HIBYTE (HIWORD (GLOBAL (BattleGroupRef)));
		SET_GAME_STATE (URQUAN_PROBE_GRPOFFS0, b0);
		SET_GAME_STATE (URQUAN_PROBE_GRPOFFS1, b1);
		SET_GAME_STATE (URQUAN_PROBE_GRPOFFS2, b2);
		SET_GAME_STATE (URQUAN_PROBE_GRPOFFS3, b3);
	}

	if (!GET_GAME_STATE (PROBE_MESSAGE_DELIVERED)
			&& GetGroupInfo (GLOBAL (BattleGroupRef), (BYTE)~0)
			&& (hStarShip = GetHeadLink (
					&GLOBAL (npc_built_ship_q)
					)))
	{
		SHIP_FRAGMENTPTR FragPtr;

		FragPtr = (SHIP_FRAGMENTPTR)LockStarShip (
				&GLOBAL (npc_built_ship_q), hStarShip
				);
		SET_GROUP_MISSION (FragPtr, IN_ORBIT);
		SET_GROUP_LOC (FragPtr, 2 + 1); /* orbitting earth */
		SET_GROUP_DEST (FragPtr, 2 + 1); /* orbitting earth */
		FragPtr->ShipInfo.loc.x = FragPtr->ShipInfo.loc.y = 0;
		FragPtr->ShipInfo.group_counter = 0;
		UnlockStarShip (
				&GLOBAL (npc_built_ship_q), hStarShip
				);
	}
}
示例#8
0
    0x01,                                 /* bDefaultFrameIndex : Default frame index is 1. */
    0x00,                                 /* bAspectRatioX : Non-interlaced stream 每 not required. */
    0x00,                                 /* bAspectRatioY : Non-interlaced stream 每 not required. */
    0x00,                                 /* bmInterlaceFlags : Non-interlaced stream */
    0x00,                                 /* bCopyProtect : No restrictions imposed on the duplication of this video stream. */
    /* 27 Bytes, total size 127 */

    /* Class-specific VS Frame Descriptor */
    0x1e,                                 /* bLength */
    0x24,                                 /* bDescriptorType : CS_INTERFACE */
    0x05,                                 /* bDescriptorSubType : VS_FRAME_UNCOMPRESSED */
    0x01,                                 /* bFrameIndex : First (and only) frame descriptor */
    0x02,                                 /* bmCapabilities : Still images using capture method 0 are supported at this frame setting.D1: Fixed frame-rate. */
    MAKE_WORD(WIDTH),                     /* wWidth : Width of frame is 128 pixels. */
    MAKE_WORD(HEIGHT),                    /* wHeight : Height of frame is 64 pixels. */
    MAKE_DWORD(MIN_BIT_RATE),
    MAKE_DWORD(MAX_BIT_RATE),
    //0x00, 0x00, 0x0A, 0x00,               /* dwMinBitRate : Min bit rate in bits/s  */ // 128*64*16*5 = 655360 = 0x000A0000
    //0x00, 0x00, 0x0A, 0x00,               /* dwMaxBitRate : Max bit rate in bits/s  */ // 128*64*16*5 = 655360 = 0x000A0000
    //0x00, 0x00, 0x06, 0x00,
    //0x00, 0x00, 0x06, 0x00,
    MAKE_DWORD(MAX_FRAME_SIZE),             /* dwMaxVideoFrameBufSize : Maximum video or still frame size, in bytes. */ // 128*64*2 = 16384 = 0x00004000
    MAKE_DWORD(INTERVEL),
    //0x80, 0x84, 0x1e, 0x00,               // 5 FPS -> 200ms -> 200,000 us -> 2,000,000 X 100ns = 0x001e8480
    //0x40, 0x42, 0x0f, 0x00,               /* dwDefaultFrameInterval : 1,000,000 * 100ns -> 10 FPS */
    0x01,                                 /* bFrameIntervalType : Continuous frame interval */
    MAKE_DWORD(INTERVEL),
    //0x80, 0x84, 0x1e, 0x00,
    //0x80, 0x84, 0x1e, 0x00,
    //0x80, 0x84, 0x1e, 0x00,
    //0x00, 0x00, 0x00, 0x00,
示例#9
0
  u8    dwClockFrequency[4];            // 0x1C
  u8    bmFramingInfo[1];
  u8    bPreferedVersion[1];
  u8    bMinVersion[1];
  u8    bMaxVersion[1];
  
}VideoControl;

u8* VideoCommitControl_Command(u16 Length);
u8* VideoProbeControl_Command(u16 Length);
VideoControl    videoCommitControl = 
{
  {0x01,0x00},                      // bmHint
  {0x01},                           // bFormatIndex
  {0x01},                           // bFrameIndex
  {MAKE_DWORD(INTERVEL),},          // dwFrameInterval
  {0x00,0x00,},                     // wKeyFrameRate
  {0x00,0x00,},                     // wPFrameRate
  {0x00,0x00,},                     // wCompQuality
  {0x00,0x00,},                     // wCompWindowSize
  {0x00,0x00},                      // wDelay
  {MAKE_DWORD(MAX_FRAME_SIZE)},    // dwMaxVideoFrameSize
  {0x00, 0x00, 0x00, 0x00},         // dwMaxPayloadTransferSize
  {0x00, 0x00, 0x00, 0x00},         // dwClockFrequency
  {0x00},                           // bmFramingInfo
  {0x00},                           // bPreferedVersion
  {0x00},                           // bMinVersion
  {0x00},                           // bMaxVersion
};

VideoControl    videoProbeControl = 
示例#10
0
文件: orbits.c 项目: intgr/sc2-uqm
void
FillOrbits (SOLARSYS_STATE *system, BYTE NumPlanets,
		PLANET_DESC *pBaseDesc, BOOLEAN TypesDefined)
{ /* Generate Planets in orbit around star */
	BYTE StarColor, PlanetCount, MaxPlanet;
	BOOLEAN GeneratingMoons;
	COUNT StarSize;
	PLANET_DESC *pPD;
	struct
	{
		COUNT MinRockyDist, MinGasGDist;
	} Suns[] =
	{
		{DWARF_ROCK_DIST, DWARF_GASG_DIST},
		{GIANT_ROCK_DIST, GIANT_GASG_DIST},
		{SUPERGIANT_ROCK_DIST, SUPERGIANT_GASG_DIST},
	};
#ifdef DEBUG_ORBITS
UNICODE buf[256];
char stype[] = {'D', 'G', 'S'};
char scolor[] = {'B', 'G', 'O', 'R', 'W', 'Y'};
#endif /* DEBUG_ORBITS */

	pPD = pBaseDesc;
	StarSize = system->SunDesc[0].data_index;
	StarColor = STAR_COLOR (CurStarDescPtr->Type);

	if (NumPlanets == (BYTE)~0)
	{
#define MAX_GENERATED_PLANETS 9
		// XXX: This is pretty funny. Instead of calling RNG once, like so:
		//     1 + Random % MAX_GENERATED_PLANETS
		//   we spin in a loop until the result > 0.
		//   Note that this behavior must be kept to preserve the universe.
		do
			NumPlanets = LOWORD (RandomContext_Random (SysGenRNG))
					% (MAX_GENERATED_PLANETS + 1);
		while (NumPlanets == 0);
		system->SunDesc[0].NumPlanets = NumPlanets;
	}

#ifdef DEBUG_ORBITS
	GetClusterName (CurStarDescPtr, buf);
	log_add (log_Debug, "cluster name = %s  color = %c type = %c", buf,
			scolor[STAR_COLOR (CurStarDescPtr->Type)],
			stype[STAR_TYPE (CurStarDescPtr->Type)]);
#endif /* DEBUG_ORBITS */
	GeneratingMoons = (BOOLEAN) (pBaseDesc == system->MoonDesc);
	if (GeneratingMoons)
		MaxPlanet = FIRST_LARGE_ROCKY_WORLD;
	else
		MaxPlanet = NUMBER_OF_PLANET_TYPES;
	PlanetCount = NumPlanets;
	while (NumPlanets--)
	{
		BYTE chance;
		DWORD rand_val;
		COUNT min_radius, angle;
		SIZE delta_r;
		PLANET_DESC *pLocPD;

		do
		{
			rand_val = RandomContext_Random (SysGenRNG);
			if (TypesDefined)
				rand_val = 0;
			else
				pPD->data_index =
						(BYTE)(HIBYTE (LOWORD (rand_val)) % MaxPlanet);

			chance = PLANET_NEVER;
			switch (StarColor)
			{
				case BLUE_BODY:
					chance = BlueDistribution (pPD->data_index);
					break;
				case GREEN_BODY:
					chance = GreenDistribution (pPD->data_index);
					break;
				case ORANGE_BODY:
					chance = OrangeDistribution (pPD->data_index);
					break;
				case RED_BODY:
					chance = RedDistribution (pPD->data_index);
					break;
				case WHITE_BODY:
					chance = WhiteDistribution (pPD->data_index);
					break;
				case YELLOW_BODY:
					chance = YellowDistribution (pPD->data_index);
					break;
			}
		} while (LOBYTE (LOWORD (rand_val)) >= chance);

		if (pPD->data_index < FIRST_GAS_GIANT)
			min_radius = Suns[StarSize].MinRockyDist;
		else
			min_radius = Suns[StarSize].MinGasGDist;
RelocatePlanet:
		rand_val = RandomContext_Random (SysGenRNG);
		if (GeneratingMoons)
		{
			pPD->radius = MIN_MOON_RADIUS
					+ ((LOWORD (rand_val) % MAX_MOONS) * MOON_DELTA);
			for (pLocPD = pPD - 1; pLocPD >= pBaseDesc; --pLocPD)
			{
				if (pPD->radius == pLocPD->radius)
					goto RelocatePlanet;
			}
			pPD->NumPlanets = 0;
		}
		else
		{
			pPD->radius =
					(LOWORD (rand_val) % (MAX_PLANET_RADIUS - min_radius))
					+ min_radius;
			for (pLocPD = pPD - 1; pLocPD >= pBaseDesc; --pLocPD)
			{
				delta_r = UNSCALE_RADIUS (pLocPD->radius) / 5
						- UNSCALE_RADIUS (pPD->radius) / 5;
				if (delta_r < 0)
					delta_r = -delta_r;
				if (delta_r <= 1)
					goto RelocatePlanet;
			}
		}

		rand_val = RandomContext_Random (SysGenRNG);
		angle = NORMALIZE_ANGLE (LOWORD (rand_val));
		pPD->location.x = COSINE (angle, pPD->radius);
		pPD->location.y = SINE (angle, pPD->radius);
		pPD->rand_seed = MAKE_DWORD (pPD->location.x, pPD->location.y);

		++pPD;
	}

	{
		BYTE i;

		for (i = 0; i < PlanetCount; ++i)
		{
			BYTE j;

			for (j = (BYTE)(PlanetCount - 1); j > i; --j)
			{
				if (pBaseDesc[i].radius > pBaseDesc[j].radius)
				{
					PLANET_DESC temp;

					temp = pBaseDesc[i];
					pBaseDesc[i] = pBaseDesc[j];
					pBaseDesc[j] = temp;
				}
			}
		}
	}
}