예제 #1
0
파일: unself.cpp 프로젝트: notoknight/rpcs3
void Elf64_Ehdr::Load(vfsStream& f)
{
	e_magic = Read32(f);
	e_class = Read8(f);
	e_data = Read8(f);
	e_curver = Read8(f);
	e_os_abi = Read8(f);
	e_abi_ver = Read64(f);
	e_type = Read16(f);
	e_machine = Read16(f);
	e_version = Read32(f);
	e_entry = Read64(f);
	e_phoff = Read64(f);
	e_shoff = Read64(f);
	e_flags = Read32(f);
	e_ehsize = Read16(f);
	e_phentsize = Read16(f);
	e_phnum = Read16(f);
	e_shentsize = Read16(f);
	e_shnum = Read16(f);
	e_shstrndx = Read16(f);
}
예제 #2
0
void W47DE() // W47DE
{
  Push(Read16(cc_ES)); // ES
  Store(); // !
  Push(Read16(regsp)); // DUP
  Push(Read16(cc_BX)); // BX
  Store(); // !
  Push(0x004a);
  DOSCALL(); // DOSCALL
  Push(Read16(Read16(cc_PSW)) & 1); // PSW @ 1 AND
  if (Pop() != 0)
  {
    Pop(); // DROP
    Push(Read16(Read16(cc_BX))); // BX @
    Push(1);
  } else
  {
    Push(0);
  }
  _ro_CS_ask__rc_(); // (CS?)
  Push(Read16(cc_ES)); // ES
  Store(); // !
}
예제 #3
0
bool RarVolume::ReadRar3File(DiskFile& file, RarBlock& block, RarFile& innerFile)
{
	innerFile.m_splitBefore = block.flags & RAR3_FILE_SPLITBEFORE;
	innerFile.m_splitAfter = block.flags & RAR3_FILE_SPLITAFTER;

	uint16 namelen;

	uint32 size;
	if (!Read32(file, &block, &size)) return false;
	innerFile.m_size = size;

	if (!Skip(file, &block, 1)) return false;
	if (!Skip(file, &block, 4)) return false;
	if (!Read32(file, &block, &innerFile.m_time)) return false;
	if (!Skip(file, &block, 2)) return false;
	if (!Read16(file, &block, &namelen)) return false;
	if (!Read32(file, &block, &innerFile.m_attr)) return false;

	if (block.flags & RAR3_FILE_ADDSIZE)
	{
		uint32 highsize;
		if (!Read32(file, &block, &highsize)) return false;
		block.trailsize += (uint64)highsize << 32;

		if (!Read32(file, &block, &highsize)) return false;
		innerFile.m_size += (uint64)highsize << 32;
	}

	if (namelen > 8192) return false; // an error
	CharBuffer name;
	name.Reserve(namelen + 1);
	if (!Read(file, &block, (char*)name, namelen)) return false;
	name[namelen] = '\0';
	innerFile.m_filename = name;
	debug("%i, %i, %s", (int)block.trailsize, (int)namelen, (const char*)name);

	return true;
}
예제 #4
0
bool emGifFileModel::TryContinueLoading() throw(emString)
{
	char * p;
	Render * r;
	Render * * pr;
	char tmp[256];
	int b,i;

	errno=0;

	if (InLoadingRenderData) {
		r=RenderArray[RenderCount-1];
		b=Read8();
		if (b) {
			if (r->DataFill+b>r->DataSize) {
				r->DataSize+=65536;
				p=new char[r->DataSize];
				if (r->Data) {
					memcpy(p,r->Data,r->DataFill);
					delete [] r->Data;
				}
				r->Data=p;
			}
			if (fread(r->Data+r->DataFill,1,b,File)!=(size_t)b) goto Err;
			r->DataFill+=b;
		}
		else {
			if (r->DataFill<=0) goto Err;
			if (r->DataFill<r->DataSize) {
				p=new char[r->DataFill];
				memcpy(p,r->Data,r->DataFill);
				delete [] r->Data;
				r->Data=p;
				r->DataSize=r->DataFill;
			}
			InLoadingRenderData=false;
		}
		if (ferror(File) || feof(File)) goto Err;
		return false;
	}

	b=Read8();
	if (ferror(File)) {
		goto Err;
	}
	else if (feof(File) || b==0x3B) {
		fclose(File);
		File=NULL;
		if (!PostProcess()) goto Err;
		return true;
	}
	else if (b==0x2c) {
		r=new Render;
		r->Disposal=NextDisposal;
		r->Delay=NextDelay;
		r->Transparent=NextTransparent;
		r->UserInput=NextUserInput;
		r->Interlaced=false;
		r->X=Read16();
		r->Y=Read16();
		r->Width=Read16();
		r->Height=Read16();
		r->ColorCount=0;
		r->DataSize=0;
		r->DataFill=0;
		r->Colors=NULL;
		r->Data=NULL;
		if (RenderCount>=RenderArraySize) {
			RenderArraySize+=64;
			pr=new Render*[RenderArraySize];
			if (RenderArray) {
				for (i=0; i<RenderCount; i++) pr[i]=RenderArray[i];
				delete [] RenderArray;
			}
			RenderArray=pr;
		}
		RenderArray[RenderCount++]=r;
		b=Read8();
		if (ferror(File) || feof(File)) goto Err;
		if ((b&0x40)!=0) r->Interlaced=true;
		if ((b&0x80)!=0) {
			r->ColorCount=2<<(b&7);
			r->Colors=new emColor[r->ColorCount];
			for (i=0; i<r->ColorCount; i++) {
				r->Colors[i].SetRed((emByte)Read8());
				r->Colors[i].SetGreen((emByte)Read8());
				r->Colors[i].SetBlue((emByte)Read8());
				r->Colors[i].SetAlpha(255);
			}
			if (ferror(File) || feof(File)) goto Err;
		}
		else {
			if (ColorCount<=0) goto Err;
		}
		r->MinCodeSize=Read8();
		if (r->MinCodeSize<1 || r->MinCodeSize>8) goto Err;
		NextDisposal=0;
		NextUserInput=false;
		NextDelay=0;
		NextTransparent=-1;
		InLoadingRenderData=true;
	}
	else if (b==0x21) {
		b=Read8();
		if (b==0xfe) {
			if (Comment.GetLen()>=65536) goto Err;
			for (i=0;;) {
				b=Read8();
				if (ferror(File) || feof(File)) goto Err;
				if (!b) break;
				i+=b;
				if (i>=65536) goto Err;
				if (fread(tmp,1,b,File)!=(size_t)b) goto Err;
				tmp[b]=0;
				Comment+=tmp;
			}
		}
		else if (b==0xf9) {
			if (Read8()!=4) goto Err;
			b=Read8();
			NextDelay=Read16();
			NextTransparent=Read8();
			Read8();
			if (ferror(File) || feof(File)) goto Err;
			NextDisposal=(b>>2)&7;
			if (NextDisposal==4) NextDisposal=3;
			if (NextDisposal>3) goto Err;
			NextUserInput=(b&0x02) ? true : false;
			if ((b&0x01)==0) NextTransparent=-1;
		}
		else if (b==0x01) {
예제 #5
0
파일: BASIC.cpp 프로젝트: HankG/ciderpress
/*
 * Reformat an Applesoft BASIC program into a text format that mimics the
 * output of the "LIST" command (with POKE 33,73 to suppress CRs).
 */
int ReformatApplesoft::Process(const ReformatHolder* pHolder,
    ReformatHolder::ReformatID id, ReformatHolder::ReformatPart part,
    ReformatOutput* pOutput)
{
    const uint8_t* srcPtr = pHolder->GetSourceBuf(part);
    long srcLen = pHolder->GetSourceLen(part);
    long length = srcLen;
    int retval = -1;

    if (srcLen > 65536)
        fUseRTF = false;
    if (fUseRTF) {
        if (id != ReformatHolder::kReformatApplesoft_Hilite)
            fUseRTF = false;
    }

    RTFBegin(kRTFFlagColorTable);

    /*
     * Make sure there's enough here to get started.  We want to return an
     * "okay" result because we want this treated like a reformatted empty
     * BASIC program rather than a non-Applesoft file.
     */
    if (length < 2) {
        LOGI("  BAS truncated?");
        //fExpBuf.CreateWorkBuf();
        BufPrintf("\r\n");
        goto done;
    }

    while (length > 0) {
        uint16_t nextAddr;
        uint16_t lineNum;
        bool inQuote = false;
        bool inRem = false;

        nextAddr = Read16(&srcPtr, &length);
        if (nextAddr == 0) {
            /* ProDOS sticks an extra byte on the end? */
            if (length > 1) {
                LOGI("  BAS ended early; len is %d", length);
            }
            break;
        }

        /* print line number */
        RTFSetColor(kLineNumColor);
        lineNum = Read16(&srcPtr, &length);
        BufPrintf(" %u ", lineNum);

        RTFSetColor(kDefaultColor);

        assert(kTokenLen == 8);     // we do "<< 3" below, so this must hold

        /* print a line */
        while (*srcPtr != 0 && length > 0) {
            if (*srcPtr & 0x80) {
                /* token */
                //RTFBoldOn();
                RTFSetColor(kKeywordColor);
                BufPrintf(" %s ", &gApplesoftTokens[((*srcPtr) & 0x7f) << 3]);
                //RTFBoldOff();
                RTFSetColor(kDefaultColor);

                if (*srcPtr == 0xb2) {
                    // REM -- do rest of line in green
                    RTFSetColor(kCommentColor);
                    inRem = true;
                }
            } else {
                /* simple character */
                if (fUseRTF) {
                    if (*srcPtr == '"' && !inRem) {
                        if (!inQuote) {
                            RTFSetColor(kStringColor);
                            RTFPrintChar(*srcPtr);
                        } else {
                            RTFPrintChar(*srcPtr);
                            RTFSetColor(kDefaultColor);
                        }
                        inQuote = !inQuote;
                    } else if (*srcPtr == ':' && !inRem && !inQuote) {
                        RTFSetColor(kColonColor);
                        RTFPrintChar(*srcPtr);
                        RTFSetColor(kDefaultColor);
                    } else if (inRem && *srcPtr == '\r') {
                        RTFNewPara();
                    } else {
                        RTFPrintChar(*srcPtr);
                    }
                } else {
                    if (inRem && *srcPtr == '\r') {
                        BufPrintf("\r\n");
                    } else {
                        BufPrintf("%c", *srcPtr);
                    }
                }
            }

            srcPtr++;
            length--;
        }

        if (inQuote || inRem)
            RTFSetColor(kDefaultColor);
        inQuote = inRem = false;

        srcPtr++;
        length--;

        if (!length) {
            LOGI("  BAS truncated in mid-line");
            break;
        }

        RTFNewPara();
    }

done:
    RTFEnd();

    SetResultBuffer(pOutput);
    retval = 0;

//bail:
    return retval;
}
예제 #6
0
int SidFile::Parse(string file)
{
	FILE *f = fopen(file.c_str(), "rb");
	
	if(f == NULL)
	{
		return SIDFILE_ERROR_FILENOTFOUND;
	}
	
	uint8_t header[PSID_MAX_HEADER_LENGTH];
	memset(header, 0, PSID_MAX_HEADER_LENGTH);
	
	size_t read = fread(header, 1, PSID_MAX_HEADER_LENGTH, f);
	
	if(read < PSID_MIN_HEADER_LENGTH || !IsPSIDHeader(header))
	{
		fclose(f);
		return SIDFILE_ERROR_MALFORMED;
	}

	numOfSongs = Read16(header, SIDFILE_PSID_NUMBER);
	
	if(numOfSongs == 0)
	{
		numOfSongs = 1;
	}
	
	firstSong = Read16(header, SIDFILE_PSID_DEFSONG);
	if(firstSong)
	{
		firstSong--;
	}
	if (firstSong >= numOfSongs)
	{
		firstSong = 0;
	}

	initAddr = Read16(header, SIDFILE_PSID_INIT);
	playAddr = Read16(header, SIDFILE_PSID_MAIN);
	speedFlags = Read32(header, SIDFILE_PSID_SPEED);

	moduleName = (char *)(header + SIDFILE_PSID_NAME);
	
	authorName = (char *)(header + SIDFILE_PSID_AUTHOR);
	
	string copyrightInfo = (char *)(header + SIDFILE_PSID_COPYRIGHT);

	// Seek to start of module data
	fseek(f, Read16(header, SIDFILE_PSID_LENGTH), SEEK_SET);

	// Find load address
	loadAddr = Read16(header, SIDFILE_PSID_START);
	if(loadAddr == 0)
	{
		uint8_t lo = fgetc(f);
		uint8_t hi = fgetc(f);
		loadAddr = (hi << 8) | lo;
	}
	
	if(initAddr == 0)
	{
		initAddr = loadAddr;
	}

	// Load module data
	dataLength = fread(dataBuffer, 1, 0x10000, f);
	
	fclose(f);

	return SIDFILE_OK;
}
예제 #7
0
void CURBLK() // CURBLK
{
  Push(Read16(pp__i_FCB) + 0x000c); // 'FCB @ 0x000c +
}
예제 #8
0
void FILESIZE() // FILESIZE
{
  Push(Read16(pp__i_FCB) + 0x0010); // 'FCB @ 0x0010 +
}
예제 #9
0
int GameState::FrameCount() {
  UpdateAddress(11);
  return Read16(11);
}
예제 #10
0
u32 Read16_ZX(const VAddr addr) {
    return (u32)Read16(addr);
}
예제 #11
0
tTJSVariant* tTJSBinarySerializer::ReadBasicType( const tjs_uint8* buff, const tjs_uint size, tjs_uint& index ) {
	if( index > size ) return NULL;
	tjs_uint8 type = buff[index];
	index++;
	switch( type  ) {
	case TYPE_NIL:
		return new tTJSVariant((iTJSDispatch2*)NULL);
	case TYPE_VOID:
		return new tTJSVariant();
	case TYPE_TRUE:
		return new tTJSVariant((tjs_int)1);
	case TYPE_FALSE:
		return new tTJSVariant((tjs_int)0);
	case TYPE_STRING8: {
		if( (index+sizeof(tjs_uint8)) > size ) TJS_eTJSError( TJSReadError );
		tjs_uint8 len = buff[index]; index++;
		if( (index+(len*sizeof(tjs_char))) > size ) TJS_eTJSError( TJSReadError );
		return ReadStringVarint( buff, len, index );
	}
	case TYPE_STRING16: {
		if( (index+sizeof(tjs_uint16)) > size ) TJS_eTJSError( TJSReadError );
		tjs_uint16 len = Read16( buff, index );
		if( (index+(len*sizeof(tjs_char))) > size ) TJS_eTJSError( TJSReadError );
		return ReadStringVarint( buff, len, index );
	}
	case TYPE_STRING32: {
		if( (index+sizeof(tjs_uint32)) > size ) TJS_eTJSError( TJSReadError );
		tjs_uint32 len = Read32( buff, index );
		if( (index+(len*sizeof(tjs_char))) > size ) TJS_eTJSError( TJSReadError );
		return ReadStringVarint( buff, len, index );
	}
	case TYPE_FLOAT: {
			if( (index+sizeof(float)) > size ) TJS_eTJSError( TJSReadError );
			tjs_uint32 t = Read32( buff, index );
			return new tTJSVariant(*(float*)&t);
		}
	case TYPE_DOUBLE: {
			if( (index+sizeof(double)) > size ) TJS_eTJSError( TJSReadError );
			tjs_uint64 t = Read64( buff, index );
			return new tTJSVariant(*(double*)&t);
		}
	case TYPE_UINT8: {
			if( (index+sizeof(tjs_uint8)) > size ) TJS_eTJSError( TJSReadError );
			tjs_uint8 t = buff[index]; index++;
			return new tTJSVariant( t );
		}
	case TYPE_UINT16: {
			if( (index+sizeof(tjs_uint16)) > size ) TJS_eTJSError( TJSReadError );
			tjs_uint16 t = Read16( buff, index );
			return new tTJSVariant( t );
		}
	case TYPE_UINT32: {
			if( (index+sizeof(tjs_uint32)) > size ) TJS_eTJSError( TJSReadError );
			tjs_uint32 t = Read32( buff, index );
			return new tTJSVariant( (tjs_int64)t );
		}
	case TYPE_UINT64: {
			if( (index+sizeof(tjs_uint64)) > size ) TJS_eTJSError( TJSReadError );
			tjs_uint64 t = Read64( buff, index );
			return new tTJSVariant( (tjs_int64)t );
		}
	case TYPE_INT8: {
			if( (index+sizeof(tjs_uint8)) > size ) TJS_eTJSError( TJSReadError );
			tjs_uint8 t = buff[index]; index++;
			return new tTJSVariant( (tjs_int8)t );
		}
	case TYPE_INT16: {
			if( (index+sizeof(tjs_uint16)) > size ) TJS_eTJSError( TJSReadError );
			tjs_uint16 t = Read16( buff, index );
			return new tTJSVariant( (tjs_int16)t );
		}
	case TYPE_INT32: {
			if( (index+sizeof(tjs_uint32)) > size ) TJS_eTJSError( TJSReadError );
			tjs_uint32 t = Read32( buff, index );
			return new tTJSVariant( (tjs_int32)t );
		}
	case TYPE_INT64: {
			if( (index+sizeof(tjs_uint64)) > size ) TJS_eTJSError( TJSReadError );
			tjs_uint64 t = Read64( buff, index );
			return new tTJSVariant( (tjs_int64)t );
		}
	case TYPE_RAW16: {
		if( (index+sizeof(tjs_uint16)) > size ) TJS_eTJSError( TJSReadError );
		tjs_uint16 len = Read16( buff, index );
		if( (index+len) > size ) TJS_eTJSError( TJSReadError );
		return ReadOctetVarint( buff, len, index );
	}
	case TYPE_RAW32: {
		if( (index+sizeof(tjs_uint32)) > size ) TJS_eTJSError( TJSReadError );
		tjs_uint32 len = Read32( buff, index );
		if( (index+len) > size ) TJS_eTJSError( TJSReadError );
		return ReadOctetVarint( buff, len, index );
	}
	case TYPE_ARRAY16: {
		if( (index+sizeof(tjs_uint16)) > size ) TJS_eTJSError( TJSReadError );
		tjs_uint16 count = Read16( buff, index );
		return ReadArray( buff, size, count, index );
	}
	case TYPE_ARRAY32: {
		if( (index+sizeof(tjs_uint32)) > size ) TJS_eTJSError( TJSReadError );
		tjs_uint32 count = Read32( buff, index );
		return ReadArray( buff, size, count, index );
	}
	case TYPE_MAP16: {
		if( (index+sizeof(tjs_uint16)) > size ) TJS_eTJSError( TJSReadError );
		tjs_uint16 count = Read16( buff, index );
		return ReadDictionary( buff, size, count, index );
	}
	case TYPE_MAP32: {
		if( (index+sizeof(tjs_uint32)) > size ) TJS_eTJSError( TJSReadError );
		tjs_uint32 count = Read32( buff, index );
		return ReadDictionary( buff, size, count, index );
	}
	default: {
		if( type >= TYPE_POSITIVE_FIX_NUM_MIN && type <= TYPE_POSITIVE_FIX_NUM_MAX ) {
			tjs_int value = type;
			return new tTJSVariant(value);
		} else if( type >= TYPE_NEGATIVE_FIX_NUM_MIN && type <= TYPE_NEGATIVE_FIX_NUM_MAX ) {
			tjs_int value = type;
			return new tTJSVariant(value);
		} else if( type >= TYPE_FIX_RAW_MIN && type <= TYPE_FIX_RAW_MAX ) { // octet
			tjs_int len = type - TYPE_FIX_RAW_MIN;
			if( (len*sizeof(tjs_uint8)+index) > size ) TJS_eTJSError( TJSReadError );
			return ReadOctetVarint( buff, len, index );
		} else if( type >= TYPE_FIX_STRING_MIN && type <= TYPE_FIX_STRING_MAX ) {
			tjs_int len = type - TYPE_FIX_STRING_MIN;
			if( (len*sizeof(tjs_char)+index) > size ) TJS_eTJSError( TJSReadError );
			return ReadStringVarint( buff, len, index );
		} else if( type >= TYPE_FIX_ARRAY_MIN && type <= TYPE_FIX_ARRAY_MAX ) {
			tjs_int count = type - TYPE_FIX_ARRAY_MIN;
			return ReadArray( buff, size, count, index );
		} else if( type >= TYPE_FIX_MAP_MIN && type <= TYPE_FIX_MAP_MAX ) {
			tjs_int count = type - TYPE_FIX_MAP_MIN;
			return ReadDictionary( buff, size, count, index );
		} else {
			TJS_eTJSError( TJSReadError );
			return NULL;
		}
	}
	}
}
예제 #12
0
void W454E() // W454E
{
  Push(0x0019);
  DOSCALL(); // DOSCALL
  Push((Read16(Read16(cc_AX))&0xFF) + 1); // AX C@ 1+
}
void setWildPokemonfromAddress(	u32 pokemonAddress,
								u32 pokemonVariation,
								u32 pokemonLevel,
								bool enableObtainedCheck,
								bool updatePokeRadar)
{
	if (PointerOffset != 0x00)
	{
		unsigned int ZOOffset = Read32(PointerOffset);

		//Check for valid pointer
		if ((ZOOffset >= 0x08000000) && (ZOOffset < 0x08DF0000))
		{
			//Check if ZO File contains encounter data
			if (Read32(ZOOffset + 0x10) != Read32(ZOOffset + 0x14))
			{
				unsigned int EncOffset = ZOOffset + Read32(ZOOffset + 0x10) + ByteJump;
				int i;
				int pokemon=1;
				u32 currentEncOffset;
				for (i = 0; i < EncDataLength; i += 4)
				{
					if (Read8(EncOffset + i + 2) != 0x01)
					{
						currentEncOffset=EncOffset+i;
						//setPokemon
						if(pokemonAddress>1)
							pokemon=Read16(pokemonAddress);
						else if(pokemonAddress==1)
							pokemon=GetRandomPokemon(enableObtainedCheck);
						else
							pokemon=Read16(currentEncOffset);
						//setPokemonVariation
						if(pokemonVariation>1)
							pokemon+=0x800 *(Read16(pokemonVariation)-1);
						else if(pokemonVariation==1)
							pokemon=getRandomVariation(pokemon);
						
						//setPokemonLevel
						if(pokemonLevel>1)
						{
							u8 level=Read8(pokemonLevel);
							if(level<2)
								level=2;
							Write8(currentEncOffset+2, level);
						}
						else if(pokemonLevel==1)
							Write8(currentEncOffset+2, RandMinMax(2,100));
						//Write8(EncOffset + i+3, 1); //maybefiller?

						Write16(currentEncOffset, pokemon);
					}
				}

				//Update DexNav
				if(updatePokeRadar&&curEdition==ORAS)
				{
					int j;
					for (i = 0; i < 96; i++)
					{
						for (j = 0; j < EncDataLength; j += 4)
						{
							Write32(0x16B3E7B6 + (0x104 * i) + j, Read32(EncOffset + j));
						}
					}
				}
			}
		}
	}
}	
예제 #14
0
void SETFCB() // SETFCB
{
  CLRFCB(); // CLRFCB
  Push(Read16(cc_BL)); // BL
  Exec("WORD"); // call of word 0x1f06 '(WORD)'
  Push(Pop() + 1); //  1+
  Push(Read16(cc_SI)); // SI
  Store(); // !
  Push(Read16(pp__i_FCB)); // 'FCB @
  Push(Read16(cc_DI)); // DI
  Store(); // !
  _ro_CS_ask__rc_(); // (CS?)
  Push(Read16(regsp)); // DUP
  Push(Read16(cc_DS)); // DS
  Store(); // !
  Push(Read16(cc_ES)); // ES
  Store(); // !
  Push(5);
  Push(Read16(cc_AX)); // AX
  Store(); // !
  Push(0x0029);
  DOSCALL(); // DOSCALL
  Push(((Read16(Read16(cc_AX))&0xFF)==0x00ff?1:0) | ((Read16(Read16(Read16(cc_DI)) + 1)&0xFF)==Read16(cc_BL)?1:0)); // AX C@ 0x00ff = DI @ 1+ C@ BL = OR
}
예제 #15
0
void RELREC() // RELREC
{
  Push(Read16(pp__i_FCB) + 0x0021); // 'FCB @ 0x0021 +
}
예제 #16
0
void CURREC() // CURREC
{
  Push(Read16(pp__i_FCB) + 0x0020); // 'FCB @ 0x0020 +
}
예제 #17
0
파일: BASIC.cpp 프로젝트: HankG/ciderpress
/*
 * Reformat an Integer BASIC program into a text format that mimics the
 * output of the "LIST" command.
 */
int ReformatInteger::Process(const ReformatHolder* pHolder,
    ReformatHolder::ReformatID id, ReformatHolder::ReformatPart part,
    ReformatOutput* pOutput)
{
    const uint8_t* srcPtr = pHolder->GetSourceBuf(part);
    long srcLen = pHolder->GetSourceLen(part);
    long length = srcLen;
    int retval = -1;

    //srcPtr += 0xff0; //0x228e;
    //srcLen -= 0xff0; //0x228e;

    if (srcLen > 65536)
        fUseRTF = false;
    if (fUseRTF) {
        if (id != ReformatHolder::kReformatInteger_Hilite)
            fUseRTF = false;
    }

    RTFBegin(kRTFFlagColorTable);

    /*
     * Make sure there's enough here to get started.  We want to return an
     * "okay" result because we want this treated like a reformatted empty
     * BASIC program rather than a non-Integer file.
     */
    if (length < 2) {
        LOGI("  INT truncated?");
        BufPrintf("\r\n");
        goto done;
    }

    while (length > 0) {
        uint8_t lineLen;
        uint16_t lineNum;
        bool trailingSpace;
        bool newTrailingSpace = false;

        /* pull the length byte, which we sanity-check */
        lineLen = *srcPtr++;
        length--;
        if (lineLen == 0) {
            LOGI("  INT found zero-length line?");
            break;
        }

        /* line number */
        RTFSetColor(kLineNumColor);
        lineNum = Read16(&srcPtr, &length);
        BufPrintf("%5u ", lineNum);
        RTFSetColor(kDefaultColor);

        trailingSpace = true;
        while (*srcPtr != 0x01 && length > 0) {
            if (*srcPtr == 0x28) {
                /* start of quoted text */
                RTFSetColor(kStringColor);
                BufPrintf("\"");
                length--;
                while (*++srcPtr != 0x29 && length > 0) {
                    /* escape chars, but let Ctrl-D and Ctrl-G through */
                    if (fUseRTF && *srcPtr != 0x84 && *srcPtr != 0x87)
                        RTFPrintChar(*srcPtr & 0x7f);
                    else
                        BufPrintf("%c", *srcPtr & 0x7f);
                    length--;
                }
                if (*srcPtr != 0x29) {
                    LOGI("  INT ended while in a string constant");
                    break;
                }
                BufPrintf("\"");
                RTFSetColor(kDefaultColor);
                srcPtr++;
                length--;
            } else if (*srcPtr == 0x5d) {
                /* start of REM statement, run to EOL */
                //RTFBoldOn();
                RTFSetColor(kKeywordColor);
                BufPrintf("%sREM ", trailingSpace ? "" : " ");
                //RTFBoldOff();
                RTFSetColor(kCommentColor);
                length--;
                while (*++srcPtr != 0x01) {
                    if (fUseRTF)
                        RTFPrintChar(*srcPtr & 0x7f);
                    else
                        BufPrintf("%c", *srcPtr & 0x7f);
                    length--;
                }
                RTFSetColor(kDefaultColor);
                if (*srcPtr != 0x01) {
                    LOGI("  INT ended while in a REM statement");
                    break;
                }
            } else if (*srcPtr >= 0xb0 && *srcPtr <= 0xb9) {
                /* start of integer constant */
                srcPtr++;
                length--;
                if (length < 2) {
                    LOGI("  INT ended while in an integer constant");
                    break;
                }
                int val;
                val = Read16(&srcPtr, &length);
                BufPrintf("%d", val);
            } else if (*srcPtr >= 0xc1 && *srcPtr <= 0xda) {
                /* start of variable name */
                while ((*srcPtr >= 0xc1 && *srcPtr <= 0xda) ||
                       (*srcPtr >= 0xb0 && *srcPtr <= 0xb9))
                {
                    /* note no RTF-escaped chars in this range */
                    BufPrintf("%c", *srcPtr & 0x7f);
                    srcPtr++;
                    length--;
                }
            } else if (*srcPtr < 0x80) {
                /* found a token; try to get the whitespace right */
                /* (maybe should've left whitespace on the ends of tokens
                    that are always followed by whitespace...?) */
                const char* token;
                token = gIntegerTokens[*srcPtr];
                //RTFBoldOn();
                if (*srcPtr == 0x03)    // colon
                    RTFSetColor(kColonColor);
                else
                    RTFSetColor(kKeywordColor);
                if (token[0] >= 0x21 && token[0] <= 0x3f || *srcPtr < 0x12) {
                    /* does not need leading space */
                    BufPrintf("%s", token);
                } else {
                    /* needs leading space; combine with prev if it exists */
                    if (trailingSpace)
                        BufPrintf("%s", token);
                    else
                        BufPrintf(" %s", token);
                }
                if (token[strlen(token)-1] == ' ')
                    newTrailingSpace = true;
                //RTFBoldOff();
                RTFSetColor(kDefaultColor);
                srcPtr++;
                length--;
            } else {
                /* should not happen */
                LOGI("  INT unexpected value 0x%02x at byte %d",
                    *srcPtr, srcPtr - pHolder->GetSourceBuf(part));

                /* skip past it and keep trying */
                srcPtr++;
                length--;
            }

            trailingSpace = newTrailingSpace;
            newTrailingSpace = false;
        } /*while line*/

        /* skip past EOL token */
        if (*srcPtr != 0x01 && length > 0) {
            LOGI("bailing");     // must've failed during processing
            goto bail;
        }
        srcPtr++;
        length--;

        RTFNewPara();
    }

done:
    RTFEnd();

    SetResultBuffer(pOutput);
    retval = 0;

bail:
    return retval;
}
예제 #18
0
파일: script.c 프로젝트: xdanieldzd/ozmav
int ExecuteGeoScript(bool IsObject)
{
	#ifdef DEBUG
	if(IsObject) {
		printf("\nExecuting object geometry script for level area 0x%02X...\n\n", LevelArea);
	} else {
		printf("\nExecuting level geometry script for level area 0x%02X...\n\n", LevelArea);
	}
	#endif

	bool EndOfGeoScript = false;
	JumpInGeoScript = false;
	unsigned int CurrentGeoCmd = 0, CurrentGeoCmdLength = 0;

	//emulate a stack for jumps
	unsigned int TempGeoScriptSegment_Backup[4] = {0, 0, 0, 0};
	unsigned int TempGeoScriptPos_Backup[4] = {0, 0, 0, 0};
	int TargetSeg=0, TargetPos=0;
	int StackCount = 0;
	while (!(EndOfGeoScript) && ((TempGeoScriptPos + LvlScript_Start) < ROMFilesize)) {
		CurrentGeoCmd = Read16(RAMSegment[TempGeoScriptSegment].Data, TempGeoScriptPos);
		CurrentGeoCmdLength = 0;
		JumpInGeoScript = false;

		switch(CurrentGeoCmd) {
			case 0x0100:
				// end
				EndOfGeoScript = true;
				break;

			case 0x0201:
				// jump
				TargetSeg = RAMSegment[TempGeoScriptSegment].Data[TempGeoScriptPos + 4];
				TargetPos = Read24(RAMSegment[TempGeoScriptSegment].Data, TempGeoScriptPos + 5);

				if(!RAMSegment[TargetSeg].IsSet)
					break;

				//Backup old seg/pos
				TempGeoScriptPos_Backup[StackCount] = TempGeoScriptPos + 8;
				TempGeoScriptSegment_Backup[StackCount] = TempGeoScriptSegment;

				//Set new seg/pos
				TempGeoScriptPos = TargetPos;
				TempGeoScriptSegment = TargetSeg;

				JumpInGeoScript = true;
				StackCount++;
				break;

			case 0x0300:
				// return
				StackCount--;
				TempGeoScriptPos = TempGeoScriptPos_Backup[StackCount];
				TempGeoScriptSegment = TempGeoScriptSegment_Backup[StackCount];
				break;

			case 0x0400:
			case 0x0500:
			case 0x0900:
			case 0x0B00:
			case 0x0C00:
			case 0x0C01:
				CurrentGeoCmdLength = 0x04;
				break;
			case 0x0E00:
			case 0x1600:
			case 0x1800:
			case 0x1900:
			case 0x1D00:
				CurrentGeoCmdLength = 0x08;
				break;
			case 0x0800:
			case 0x0A01:
			case 0x1700:
			case 0x1770:
				CurrentGeoCmdLength = 0x0C;
				break;
			case 0x0F00:
				CurrentGeoCmdLength = 0x14;
				break;

			case 0x1501:
			case 0x1502:
			case 0x1503:
			case 0x1504:
			case 0x1505:
			case 0x1506:
				// Display Lists
				CurrentGeoCmdLength = 0x08;
				unsigned int TempDLSegment = RAMSegment[TempGeoScriptSegment].Data[TempGeoScriptPos + 4];
				unsigned int TempDLOffset = Read24(RAMSegment[TempGeoScriptSegment].Data, TempGeoScriptPos + 5);
				DListOffsets[DLCount] = TempDLOffset + ZMAP_HEADERGAP;
				DLCount++;

				ConvertDList(TempDLSegment, TempDLOffset, false);
				DListHasEnded = false;
				break;
			default:
				CurrentGeoCmdLength = 0x04;
				break;
		}

		if(!JumpInGeoScript) TempGeoScriptPos += CurrentGeoCmdLength;
	}

	dmsg("\n");

	return 0;
}
예제 #19
0
파일: BASIC.cpp 프로젝트: HankG/ciderpress
/*
 * Reformat an Apple /// Business BASIC program into a text format that
 * mimics the output of the "LIST" command.
 */
int ReformatBusiness::Process(const ReformatHolder* pHolder,
    ReformatHolder::ReformatID id, ReformatHolder::ReformatPart part,
    ReformatOutput* pOutput)
{
    const uint8_t* srcPtr = pHolder->GetSourceBuf(part);
    long srcLen = pHolder->GetSourceLen(part);
    long length = srcLen;
    int retval = -1;
    int nestLevels = 0;

    if (srcLen > 65536)
        fUseRTF = false;
    if (fUseRTF) {
        if (id != ReformatHolder::kReformatBusiness_Hilite)
            fUseRTF = false;
    }

    RTFBegin(kRTFFlagColorTable);

    /*
     * Make sure there's enough here to get started.  We want to return an
     * "okay" result because we want this treated like a reformatted empty
     * BASIC program rather than a non-BASIC file.
     */
    if (length < 2) {
        LOGI("  BA3 truncated?");
        //fExpBuf.CreateWorkBuf();
        BufPrintf("\r\n");
        goto done;
    }

    uint16_t fileLength;
    fileLength = Read16(&srcPtr, &length);
    LOGI("  BA3 internal file length is: %d", fileLength);

    while (length > 0) {
        uint16_t increment;
        uint16_t extendedToken;
        uint16_t lineNum;
        bool inQuote = false;
        bool inRem = false;
        bool firstData = true;
        bool literalYet = false;

        increment = Read8(&srcPtr, &length);
        LOGI("  BA3 increment to next line is: %d", increment);
        if (increment == 0) {
            /* ProDOS sticks an extra byte on the end? */
            if (length > 1) {
                LOGI("  BA3 ended early; len is %d", length);
            }
            break;
        }

        /* print line number */
        RTFSetColor(kLineNumColor);
        lineNum = Read16(&srcPtr, &length);
        LOGI("  BA3 line number: %d", lineNum);
        BufPrintf(" %u   ", lineNum);

        RTFSetColor(kDefaultColor);
        if (nestLevels > 0) {
            for (int i =0; i < nestLevels; i++)
                BufPrintf("  ");
        }

        /* print a line */
        while (*srcPtr != 0 && length > 0) {
            if (*srcPtr & 0x80) {
                /* token */
                //RTFBoldOn();
                literalYet = false;
                RTFSetColor(kKeywordColor);
                if (*srcPtr == 0x81) {
                    // Token is FOR - indent
                    nestLevels ++;
                }
                else if (*srcPtr == 0x82) {
                    // Token is NEXT - outdent
                    nestLevels --;
                }
                if (!firstData)
                    BufPrintf(" ");
                if (((*srcPtr) & 0x7f) == 0x7f)
                {
                    extendedToken = Read8(&srcPtr, &length);
                    BufPrintf("%s", &gExtendedBusinessTokens[((*srcPtr) & 0x7f) * 10]);
                    // We need to have some tokens NOT add a space after them.
                    if ((*srcPtr == 0x80) ||    // TAB(
                        (*srcPtr == 0x82) ||    // SPC(
                        (*srcPtr == 0x9d) ||    // SGN(
                        (*srcPtr == 0x9e) ||    // INT(
                        (*srcPtr == 0x9f) ||    // ABS(
                        (*srcPtr == 0xa1) ||    // TYP(
                        (*srcPtr == 0xa2) ||    // REC(
                        (*srcPtr == 0xad) ||    // PDL(
                        (*srcPtr == 0xae) ||    // BUTTON(
                        (*srcPtr == 0xaf) ||    // SQR(
                        (*srcPtr == 0xb0) ||    // RND(
                        (*srcPtr == 0xb1) ||    // LOG(
                        (*srcPtr == 0xb2) ||    // EXP(
                        (*srcPtr == 0xb3) ||    // COS(
                        (*srcPtr == 0xb4) ||    // SIN(
                        (*srcPtr == 0xb5) ||    // TAN(
                        (*srcPtr == 0xb6) ||    // ATN(
                        (*srcPtr == 0xc3) ||    // STR$(
                        (*srcPtr == 0xc4) ||    // HEX$(
                        (*srcPtr == 0xc5) ||    // CHR$(
                        (*srcPtr == 0xc6) ||    // LEN(
                        (*srcPtr == 0xc7) ||    // VAL(
                        (*srcPtr == 0xc8) ||    // ASC(
                        (*srcPtr == 0xc9) ||    // TEN(
                        (*srcPtr == 0xcc) ||    // CONV(
                        (*srcPtr == 0xcd) ||    // CONV&(
                        (*srcPtr == 0xce) ||    // CONV$(
                        (*srcPtr == 0xcf) ||    // CONV%(
                        (*srcPtr == 0xd0) ||    // LEFT$(
                        (*srcPtr == 0xd1) ||    // RIGHT$(
                        (*srcPtr == 0xd2) ||    // MID$(
                        (*srcPtr == 0xd3))      // INSTR$(
                        firstData = true;
                    else
                        firstData = false;
                }
                else {
                    BufPrintf("%s", &gBusinessTokens[((*srcPtr) & 0x7f) * 10]);
                    // We need to have some tokens NOT add a space after them.
                    if ((*srcPtr == 0x99) ||    // HPOS
                        (*srcPtr == 0x9a) ||    // VPOS
                        (*srcPtr == 0x9f) ||    // TIME$
                        (*srcPtr == 0xa0) ||    // DATE$
                        (*srcPtr == 0xa1) ||    // PREFIX$
                        (*srcPtr == 0xa2) ||    // EXFN.
                        (*srcPtr == 0xa3) ||    // EXFN%.
                        (*srcPtr == 0xb0) ||    // SUB$(.
                        (*srcPtr == 0xb6) ||    // SCALE(
                        (*srcPtr == 0xc0) ||    // REM
                        (*srcPtr == 0xe3))      // SPC(
                        firstData = true;
                    else
                        firstData = false;
                }
                //RTFBoldOff();
                RTFSetColor(kDefaultColor);

                if (*srcPtr == 0xc0) {
                    // REM -- do rest of line in green
                    RTFSetColor(kCommentColor);
                    inRem = true;
                }
            } else {
                /* simple chracter */
                if (*srcPtr == ':') // Reset line if we have a colon
                    firstData = true;
                if (!firstData) {
                    if (!literalYet) {
                        BufPrintf(" ");
                        literalYet = true;
                    }
                }
                if (fUseRTF) {
                    if (*srcPtr == '"' && !inRem) {
                        if (!inQuote) {
                            RTFSetColor(kStringColor);
                            RTFPrintChar(*srcPtr);
                        } else {
                            RTFPrintChar(*srcPtr);
                            RTFSetColor(kDefaultColor);
                        }
                        inQuote = !inQuote;
                    } else if (*srcPtr == ':' && !inRem && !inQuote) {
                        RTFSetColor(kColonColor);
                        RTFPrintChar(*srcPtr);
                        RTFSetColor(kDefaultColor);
                    } else {
                        RTFPrintChar(*srcPtr);
                    }
                } else {
                    BufPrintf("%c", *srcPtr);
                }
            }

            srcPtr++;
            length--;
        }

        if (inQuote || inRem)
            RTFSetColor(kDefaultColor);
        inQuote = inRem = false;

        srcPtr++;
        length--;

        if (!length) {
            LOGI("  BA3 truncated in mid-line");
            break;
        }

        RTFNewPara();
    }

done:
    RTFEnd();

    SetResultBuffer(pOutput);
    retval = 0;

//bail:
    return retval;
}
예제 #20
0
int GameState::Percent(int player) { 
  UpdateAddress(2 + (player - 1));
  return Read16(2 + (player - 1));
}
예제 #21
0
파일: script.c 프로젝트: xdanieldzd/ozmav
int ExecuteCollisionScript(unsigned int ColScriptSeg, unsigned int ColScriptPos)
{
	/* SM64 Collision format
	[command][...data...][command][...data...][command][...data...] etc

	COMMAND[16bits]	DATA				DESC
	0x0000-0x003F	xxxx[aaaabbbbcccc[vvvv*]]	Polygons, type is command, number of tris is x, each tri is 6 bytes, two for each tri
							 v is variable for certain types of polygons, making each poly 8 bytes. see list below
	0x0040		xxxx[aaaabbbbcccc]		Load x number of verts, each vertex being 6 bytes (3 signed 16 bit x/y/z)
	0x0041						NOP
	0x0042						End collision data
	0x0043		????				?
	0x0044		xxxx[aaaabbbbccccddddeeeeffff]	Water
	0x004D		aaaabbbbccccdddd		?
	0x0045-0x0064	?				?
	0x0065-0x00F8					See Polygons above.

	* these polygon types are 8 bytes each: 000E, 002C, 0024, 0025, 0027, 002D

	if you don't understand this just breakpoint the start of the collision data, the routines explain it all.

	*/
	dmsg("\nExecuting collision script for level area 0x%02X...\n", LevelArea);

	bool EndOfColScript = false;
	bool _0x40read = false;
	unsigned int CurrentColCmd = 0;
	unsigned int VtxCount;

	unsigned short WaterCount;
	signed short x1, x2, y, z1, z2;

	int i;

	while (!(EndOfColScript))
	{
		CurrentColCmd = Read16(RAMSegment[ColScriptSeg].Data, ColScriptPos);
		switch(CurrentColCmd)
		{
			case 0x0041:	// "nop"
				ColScriptPos+=2;
				break;
			case 0x0042:	// End marker
				ColScriptEnd:
				EndOfColScript = true;
				break;
			case 0x0043:	// Special objects?
			{
				unsigned short CollisionSpecialCount = Read16(RAMSegment[ColScriptSeg].Data, ColScriptPos + 2);
				dmsg("- %i Special collision objects [ignored]\n", CollisionSpecialCount);
				ColScriptPos += (CollisionSpecialCount << 3) + 2;
				// hackish code gtfo
				unsigned short CurrHalfWord = 0;
				while (1)
				{
					CurrHalfWord = Read16(RAMSegment[ColScriptSeg].Data, ColScriptPos);
					if(CurrHalfWord == 0x0044)
						goto ColScriptWater;
					if(CurrHalfWord == 0x0042)
						goto ColScriptEnd;
					ColScriptPos+=2;
				}
				break;
			}
			case 0x0044:	// Water
			{
				ColScriptWater:

				WaterCount = Read16(RAMSegment[ColScriptSeg].Data, ColScriptPos + 2);
				ColScriptPos+=4;

				ZWaterCount += WaterCount;

				dmsg("- %i Water boxes\n", WaterCount);
				for (i = 0; i < WaterCount; i++)
				{
					ColScriptPos+=2; // ID of mesh
					x1	= Read16(RAMSegment[ColScriptSeg].Data, ColScriptPos); ColScriptPos+=2;
					z1	= Read16(RAMSegment[ColScriptSeg].Data, ColScriptPos); ColScriptPos+=2;
					x2	= Read16(RAMSegment[ColScriptSeg].Data, ColScriptPos); ColScriptPos+=2;
					z2	= Read16(RAMSegment[ColScriptSeg].Data, ColScriptPos); ColScriptPos+=2;
					y	= Read16(RAMSegment[ColScriptSeg].Data, ColScriptPos); ColScriptPos+=2;

					x1 /= SCALE;
					z1 /= SCALE;
					x2 /= SCALE;
					z2 /= SCALE;
					y /= SCALE;

					x2 -= x1;
					z2 -= z1;

					Write16(ZWaterBuffer, ZWaterOffset, x1);
					Write16(ZWaterBuffer, ZWaterOffset+2, y);
					Write16(ZWaterBuffer, ZWaterOffset+4, z1);
					Write16(ZWaterBuffer, ZWaterOffset+6, x2);
					Write16(ZWaterBuffer, ZWaterOffset+8, z2);
					ZWaterOffset += 0x10;

					dmsg(" - Water Box %d: X1 %5i, X2 %5i, Y %5i, Z1 %5i, Z2 %5i\n", i, x1, x2, y, z1, z2);
				}

				break;
			}
			case 0x004D:
				ColScriptPos+=0xA;
				break;
			case 0x0040:	// Verts
			{
				if (_0x40read) ColVtxCount += _ColVtxCount;
				_0x40read = true;
				VtxCount = Read16(RAMSegment[ColScriptSeg].Data, ColScriptPos + 2);
				_ColVtxCount = VtxCount;

				unsigned int BufferSize = VtxCount * 6;
				memcpy(&ColVtxBuffer[ColVtxCount], &RAMSegment[ColScriptSeg].Data[ColScriptPos + 4], BufferSize);
				dmsg("- VtxCount %i ColVtxCount %i\n",VtxCount,ColVtxCount);
				// scale verts
				for (i=ColVtxCount; i<(ColVtxCount+BufferSize); i+=6)
				{
					/* Read */
					x1	= Read16(ColVtxBuffer, i);
					y	= Read16(ColVtxBuffer, i+2);
					z1	= Read16(ColVtxBuffer, i+4);
					/* Scale */
					x1	/= SCALE;
					y	/= SCALE;
					z1	/= SCALE;
					/* Write */
					Write16(ColVtxBuffer, i+0, x1);
					Write16(ColVtxBuffer, i+2, y);
					Write16(ColVtxBuffer, i+4, z1);
				}

				ColScriptPos += BufferSize + 4;
				break;
			}
			default:
			{
				if ((CurrentColCmd < 0x40)||(CurrentColCmd >= 0x65))
				{
					unsigned short ColType = CurrentColCmd & 0xFFFF;
					unsigned short TriCount = Read16(RAMSegment[ColScriptSeg].Data, ColScriptPos + 2);

					ColScriptPos += 4;
					ColTriCount += TriCount;

					unsigned short p1, p2, p3;

					int _inc = ((ColType == 0x000E) ||
						(ColType == 0x002C) ||
						(ColType == 0x0024) ||
						(ColType == 0x0025) ||
						(ColType == 0x0027) ||
						(ColType == 0x002D)) ? 8 : 6;
					dmsg("- ColType: 0x%04X ZTriOffset 0x%04X TriCount %04i ColTriCount %04i\n",ColType,ZTriOffset,TriCount,ColTriCount);

					for(i = 0; i < TriCount; i++)
					{

						p1 = ColVtxCount + (Read16(RAMSegment[ColScriptSeg].Data, ColScriptPos));
						p2 = ColVtxCount + (Read16(RAMSegment[ColScriptSeg].Data, ColScriptPos + 2));
						p3 = ColVtxCount + (Read16(RAMSegment[ColScriptSeg].Data, ColScriptPos + 4));
						if((p1>ColVtxCount+_ColVtxCount)||(p2>ColVtxCount+_ColVtxCount)||(p3>ColVtxCount+_ColVtxCount))
						{
							msg(1, "WARNING: Collision vertex overflow!!!: %04i/%04i/%04i;max %04i", p1, p2, p3, ColVtxCount+_ColVtxCount);
							EndOfColScript = true;
							return -1; /* i hope this raises an error */
						}
						Write16(ColTriBuffer, ZTriOffset+2, p1);
						Write16(ColTriBuffer, ZTriOffset+4, p2);
						Write16(ColTriBuffer, ZTriOffset+6, p3);

						ZTriOffset += 16;
						ColScriptPos += _inc;
					}
				}
				else
				{
					dmsg("Unknown collision command: %04X\n", CurrentColCmd);
					EndOfColScript= true;
				}
				break;
			}
		}
	}
	ColVtxCount += _ColVtxCount;
	return 0;
}
예제 #22
0
void RECSIZE() // RECSIZE
{
  Push(Read16(pp__i_FCB) + 0x000e); // 'FCB @ 0x000e +
}
예제 #23
0
파일: script.c 프로젝트: xdanieldzd/ozmav
int ExecuteLevelScript()
{
	dmsg(" - Level layout script: 0x%06X to 0x%06X (0x%X bytes)\n - Entry point at 0x%06X\n\n", LvlScript_Start, LvlScript_End, LvlScript_Length, LvlScript_Entry);

	unsigned int ObjGeoOffset[256];
	memset(ObjGeoOffset, 0x00, sizeof(ObjGeoOffset));

	bool EndOfScript = false;
	ColVtxBuffer = (unsigned char *) malloc (sizeof(char) * 0x8000);
	ColTriBuffer = (unsigned char *) malloc (sizeof(char) * 0x10000);
	ZWaterBuffer = (unsigned char *) malloc (sizeof(char) * 0x400);	/* Room for 64 water boxes */
	memset(ColTriBuffer, 0x10000, 0x0);
	memset(ZWaterBuffer, 0x400, 0x0);
	ZWaterOffset = 0;
	#ifdef DEBUG
	int i;
	#endif

	while (!(EndOfScript) && (TempScriptPos < ROMFilesize)) {
		CurrentCmd = Read16(RAMSegment[TempScriptSegment].Data, TempScriptPos);
		CurrentCmdLength = RAMSegment[TempScriptSegment].Data[TempScriptPos + 1];
		JumpInScript = false;

		if(CurrentCmdLength == 0x00) EndOfScript = true;

		switch(CurrentCmd)
		{
			case 0x0204:
			case 0x1E04:
				// end
				EndOfScript = true;
				break;

			case 0x0608: {
				// jump
				unsigned int TargetSeg = RAMSegment[TempScriptSegment].Data[TempScriptPos + 4];

				if(RAMSegment[TargetSeg].IsSet) {
					TempScriptPos_Backup = TempScriptPos;
					TempScriptSegment_Backup = TempScriptSegment;
					TempScriptPos = Read24(RAMSegment[TempScriptSegment].Data, TempScriptPos + 5);
					TempScriptSegment = TargetSeg;
					JumpInScript = true;
				}
				break; }

			case 0x0704:
				// return
				TempScriptPos = (TempScriptPos_Backup + 4);
				TempScriptSegment = TempScriptSegment_Backup;
				break;

			case 0x170C: {
				// setup ram segment
				unsigned int TempSeg = RAMSegment[TempScriptSegment].Data[TempScriptPos + 3];
				dmsg("- Segment loader: 0x%02X\n", TempSeg);

				unsigned int ROMData_Start = Read32(RAMSegment[TempScriptSegment].Data, TempScriptPos + 4);
				unsigned int ROMData_End = Read32(RAMSegment[TempScriptSegment].Data, TempScriptPos + 8);
				unsigned int ROMData_Length = ROMData_End - ROMData_Start;

				RAMSegment[TempSeg].Data = (unsigned char *) malloc (sizeof(char) * ROMData_Length);
				memcpy(RAMSegment[TempSeg].Data, &ROMBuffer[ROMData_Start], ROMData_Length);
				RAMSegment[TempSeg].IsSet = true;
				RAMSegment[TempSeg].Length = ROMData_Length;

				dmsg("[ROM] RAM segment 0x%02X: 0x%08X to 0x%08X (0x%X bytes)\n", TempSeg, ROMData_Start, ROMData_End, ROMData_Length);
				break; }

			case 0x1A0C: {
				// textures
				unsigned int TempSeg = RAMSegment[TempScriptSegment].Data[TempScriptPos + 3];
				dmsg("- Texture loader: 0x%02X\n", TempSeg);
				if(TempSeg == 0x09) {
					unsigned int TexData_Start = Read32(RAMSegment[TempScriptSegment].Data, TempScriptPos + 4);
					unsigned int TexData_End = Read32(RAMSegment[TempScriptSegment].Data, TempScriptPos + 8);
					TexData_Start += Read32(ROMBuffer, TexData_Start + 8);
					TexData_Start += 2;
					unsigned int TexData_Length = TexData_End - TexData_Start;

					RAMSegment[TempSeg].Data = (unsigned char *) malloc (sizeof(char) * TexData_Length);
					memcpy(RAMSegment[TempSeg].Data, &ROMBuffer[TexData_Start], TexData_Length);
					RAMSegment[TempSeg].IsSet = true;
					RAMSegment[TempSeg].Length = TexData_Length;

					dmsg("[ROM] External texture data: 0x%08X to 0x%08X (0x%X bytes)\n", TexData_Start, TexData_End, TexData_Length);
				}
				break; }

			case 0x1D04: {
				// end of segment loading sequence
				// generate initial zmap data

				// only generate when segment 0x07 is already set, if it's not we're still executing segment 0x15
				if(RAMSegment[0x07].IsSet == false) break;

				msg(3, " - Generating initial Zelda map data...\n");

				ZMapFilesize = RAMSegment[0x07].Length + ZMAP_HEADERGAP;
				int PadSize = GetPaddingSize(ZMapFilesize, 0x08);
				TextureSize = RAMSegment[0x09].Length;

				dmsg("  - Size of main data:\t\t\t\t\t0x%06X\n", ZMapFilesize);
				dmsg("  - Size of padding:\t\t\t\t\t0x%04X\n", PadSize);
				dmsg("  - Size of external texture data:\t\t0x%06X\n", TextureSize);

				ZMapFilesize += PadSize;
				ZMapFilesize += TextureSize;

				dmsg("  - Total data size:\t\t\t\t\t0x%06X\n", ZMapFilesize);
				msg(3, " - Allocating and clearing map buffer...\n");
				ZMapBuffer = (unsigned char*) malloc (sizeof(char) * ZMapFilesize);
				memset(ZMapBuffer, 0x00, ZMapFilesize);

				msg(3, " - Copying main data and external texture data...\n");

				memcpy(&ZMapBuffer[ZMAP_HEADERGAP], RAMSegment[0x07].Data, RAMSegment[0x07].Length);
				memcpy(&ZMapBuffer[ZMapFilesize - TextureSize], RAMSegment[0x09].Data, TextureSize);

				msg(3, " - Done, resuming conversion.\n");
				break; }

			case 0x1F08: {
				// execute geometry script
				TempGeoScriptSegment = RAMSegment[TempScriptSegment].Data[TempScriptPos + 4];
				TempGeoScriptPos = Read24(RAMSegment[TempScriptSegment].Data, TempScriptPos + 5);
				TempGeoScriptSegment_Backup = 0x00, TempGeoScriptPos_Backup = 0x00;

				CurrentLevelArea = RAMSegment[TempScriptSegment].Data[TempScriptPos + 2];

				dmsg("\nCurrent level area set to 0x%02X (wanted 0x%02X)\n", CurrentLevelArea, LevelArea);

				if(LevelArea != CurrentLevelArea) break;

				ExecuteGeoScript(false);

				break; }

			case 0x2E08: // execute collision script
			{
				if(LevelArea != CurrentLevelArea) break;

				unsigned int ColScriptSeg = RAMSegment[TempScriptSegment].Data[TempScriptPos + 4];
				unsigned int ColScriptPos = Read24(RAMSegment[TempScriptSegment].Data, TempScriptPos + 5);

				if (RAMSegment[ColScriptSeg].IsSet == true)
					ExecuteCollisionScript(ColScriptSeg, ColScriptPos);

				break;
			}
			case 0x2208: {
				// load object w/ geo layout
				unsigned char ObjID = RAMSegment[TempScriptSegment].Data[TempScriptPos + 3];
				if(RAMSegment[TempScriptSegment].Data[TempScriptPos + 4] == 0x0E) {
					unsigned int GeoOffset = Read32(RAMSegment[TempScriptSegment].Data, TempScriptPos + 4);
					ObjGeoOffset[ObjID] = GeoOffset;
					InsertSpecialObjects(ObjID, GeoOffset);
				}
				break; }
			case 0x2418: {
				if(TempScriptSegment == 0x0E)
					SM64_Behavior_To_OoT(TempScriptSegment, TempScriptPos, 0);
				break; }
			case 0x3908: {
				dmsg("\nAdding macro objects for level area 0x%02X...\n", LevelArea);

				unsigned int MacroSeg = RAMSegment[TempScriptSegment].Data[TempScriptPos + 4];
				unsigned int MacroPos = Read24(RAMSegment[TempScriptSegment].Data, TempScriptPos + 5);

				bool EndOfObjects = false;
				while(!EndOfObjects) {
					unsigned int Preset = Read16(RAMSegment[MacroSeg].Data, MacroPos);
					Preset &= 0x01FF;
					unsigned int Behav = Read32(ROMBuffer, MacroPreset_Offset + ((Preset - 0x01F) << 3));

					if((Preset == 0x01E) || (Preset == 0x000)) {
						EndOfObjects = true;
					} else {
						SM64_Behavior_To_OoT(MacroSeg, MacroPos, Behav);
						MacroPos += 0x0A;
					}
				}

				break; }

			default:
				#ifdef DEBUG
				printf("Unknown: %04X:", CurrentCmd);
				for (i=TempScriptPos+2;i<TempScriptPos+CurrentCmdLength; i++)
					printf("%02X",RAMSegment[TempScriptSegment].Data[i]);
				printf("\n");
				#endif
				break;
		}

		if(!JumpInScript) TempScriptPos += CurrentCmdLength;
	}

	return 0;
}
예제 #24
0
파일: PSD2TGA.cpp 프로젝트: viticm/pap2
HRESULT CPSD2TGA::PSD2TGA(LPSTR pPSDFileNane, LPSTR pTGAFileName)
{
	DWORD dwWidth, dwHeight; // 宽高
	//long lSurfWidth = m_Rect.right - m_Rect.left;
	//long lSurfHeight = m_Rect.bottom - m_Rect.top;
	WORD CompressionType; // 压缩类型
	//HDC hDC;
	FILE *fpPSD;
	WORD ChannelCount; // 通道数
	BYTE* m_pbAlphaMask = NULL;
	
	// 打开PSD文件
	if ( ( fpPSD = fopen ( pPSDFileNane, "rb" ) ) == NULL )
	{
		TCHAR ErrorInfo[1024];
		sprintf(ErrorInfo, "文件%s不存在", pPSDFileNane );
		MessageBox(NULL, ErrorInfo, "错误", MB_OK);
		return E_FAIL;
	}
	// 头四个字节为"8BPS"
	char signature[5];
	signature[0] = fgetc( fpPSD );
	signature[1] = fgetc( fpPSD );
	signature[2] = fgetc( fpPSD );
	signature[3] = fgetc( fpPSD );
	signature[4] = '\0';
	if ( strcmp( signature,"8BPS" ) != 0 )
	{
		return E_FAIL;
	}
	
	// 版本必须为1
	if ( Read16( fpPSD ) != 1 ) 
	{
		return E_FAIL;
	}
	
	// 跳过一些数据 (总是0)
	Read32( fpPSD );
	Read16( fpPSD );
	
	// 读取通道数
	ChannelCount = Read16( fpPSD );
	
	// 确定至少有一个通道
	if ( ( ChannelCount < 0 ) || ( ChannelCount > MAX_PSD_CHANNELS ) ) 
	{
		return E_FAIL;
	}
	
	// 读入宽和高
	dwHeight = Read32( fpPSD );
	dwWidth = Read32( fpPSD );
	
	// 只读入8位通道
	if ( Read16( fpPSD ) != 8 ) 
	{
		return E_FAIL;
	}
	
	// 确定模式为RGB.
	// 可能值:
	// 0: 位图
	// 1: 灰阶
	// 2: 索引
	// 3: RGB
	// 4: CMYK
	// 7: Multichannel
	// 8: Duotone
	// 9: Lab
	if ( Read16( fpPSD ) != 3 )
	{
		return E_FAIL;
	}

		
	// 跳过数据(如调色板)
	int ModeDataCount = Read32( fpPSD );
	if ( ModeDataCount )
		fseek( fpPSD, ModeDataCount, SEEK_CUR );
	
	// 跳过数据(如:pen tool paths, etc)
	int ResourceDataCount = Read32( fpPSD );
	if ( ResourceDataCount )
		fseek( fpPSD, ResourceDataCount, SEEK_CUR );
	
	// 条过layer and mask数据
	int ReservedDataCount = Read32( fpPSD );
	if ( ReservedDataCount )
		fseek( fpPSD, ReservedDataCount, SEEK_CUR );
	
	// 0: 非压缩
	// 1: RLE压缩
	CompressionType = Read16( fpPSD );
	if ( CompressionType > 1 )
	{
		return E_FAIL;
	}
	int length ;
	length = ftell(fpPSD);
	fseek(fpPSD, 0, SEEK_END);
	length = ftell(fpPSD) - length;
	fseek(fpPSD, -length, SEEK_END);
	
	
	BYTE* PSDPixels = new BYTE[ ( dwHeight * dwWidth ) * 4 ];
	
	// 解包数据
	UnPackPSD( fpPSD, dwWidth, dwHeight, PSDPixels, ChannelCount, CompressionType );
	fclose( fpPSD );
	
	Reverse(PSDPixels,  dwWidth,dwHeight);
	Save2Tga(pTGAFileName,dwWidth,dwHeight,PSDPixels);
	SAFE_DELETE_ARRAY(PSDPixels);
	
	return S_OK;
}
예제 #25
0
int GameState::StageID() {
  UpdateAddress(10);
  return Read16(10);
}
예제 #26
0
파일: o65.c 프로젝트: Aliandrana/snesdev
static void ReadO65RelocInfo (FILE* F, const O65Data* D, Collection* Reloc)
/* Read relocation data for one segment */
{
    /* Relocation starts at (start address - 1) */
    unsigned long Offs = (unsigned long) -1L;

    while (1) {

        O65Reloc* R;

        /* Read the next relocation offset */
        unsigned char C = Read8 (F);
        if (C == 0) {
            /* End of relocation table */
            break;
        }

        /* Create a new relocation entry */
        R = xmalloc (sizeof (*R));

        /* Handle overflow bytes */
        while (C == 0xFF) {
            Offs += 0xFE;
            C = Read8 (F);
        }

        /* Calculate the final offset */
        R->Offs = (Offs += C);

        /* Read typebyte and segment id */
        C = Read8 (F);
        R->Type   = (C & O65_RTYPE_MASK);
        R->SegID  = (C & O65_SEGID_MASK);

        /* Read an additional relocation value if there is one */
        R->SymIdx = (R->SegID == O65_SEGID_UNDEF)? ReadO65Size (F, &D->Header) : 0;
        switch (R->Type) {

            case O65_RTYPE_HIGH:
                if ((D->Header.mode & O65_RELOC_MASK) == O65_RELOC_BYTE) {
                    /* Low byte follows */
                    R->Val = Read8 (F);
                } else {
                    /* Low byte is zero */
                    R->Val = 0;
                }
                break;

            case O65_RTYPE_SEG:
                /* Low 16 byte of the segment address follow */
                R->Val = Read16 (F);
                break;

            default:
                R->Val = 0;
                break;
        }

        /* Insert this relocation entry into the collection */
        CollAppend (Reloc, R);
    }
}
예제 #27
0
bool SidFile::IsPSIDHeader(const uint8_t *p)
{
	uint32_t id = Read32(p, SIDFILE_PSID_ID);
	uint16_t version = Read16(p, SIDFILE_PSID_VERSION);
	return id == 0x50534944 && (version == 1 || version == 2);
}
예제 #28
0
u32 TestEnvironment::TestMemory::Read32(VAddr addr) {
    return Read16(addr) | static_cast<u32>(Read16(addr + 2)) << 16;
}
예제 #29
0
static void read_frame_controller_data(bool addFrame)
{
	int i;

	// one sample of all 1 bits = reset code
	// (the SNES controller doesn't have enough buttons to possibly generate this sequence)
	// (a single bit indicator was not used, to avoid having to special-case peripheral recording here)
	if(Movie.InputBufferPtr[0] == 0xFF)
	{
		bool reset = true;
		for(i=1; i<(int)Movie.BytesPerSample; i++)
		{
			if(Movie.InputBufferPtr[i] != 0xFF)
			{
				reset = false;
				break;
			}
		}
		if(reset)
		{
			Movie.InputBufferPtr += Movie.BytesPerSample;
			S9xSoftReset();
			return;
		}
	}

	for(i=0; i<8; ++i)
	{
		if(Movie.ControllersMask & (1<<i))
		{
			MovieSetJoypad(i, Read16(Movie.InputBufferPtr));
		}
		else
		{
			MovieSetJoypad(i, 0);		// pretend the controller is disconnected
		}
	}
#ifdef PERIPHERAL_SUPPORT
	for(int port=0;port<2;port++)
	{
		if(Movie.PortType[port] == CTL_MOUSE)
		{
			uint8 buf [MOUSE_DATA_SIZE];
			memcpy(buf, Movie.InputBufferPtr, MOUSE_DATA_SIZE); Movie.InputBufferPtr += MOUSE_DATA_SIZE;
			MovieSetMouse(port, buf, !addFrame);
		}
		if(Movie.PortType[port] == CTL_SUPERSCOPE)
		{
			uint8 buf [SCOPE_DATA_SIZE];
			memcpy(buf, Movie.InputBufferPtr, SCOPE_DATA_SIZE); Movie.InputBufferPtr += SCOPE_DATA_SIZE;
			MovieSetScope(port, buf);
		}
		if(Movie.PortType[port] == CTL_JUSTIFIER)
		{
			uint8 buf [JUSTIFIER_DATA_SIZE];
			memcpy(buf, Movie.InputBufferPtr, JUSTIFIER_DATA_SIZE); Movie.InputBufferPtr += JUSTIFIER_DATA_SIZE;
			MovieSetJustifier(port, buf);
		}
	}
#endif
}
예제 #30
0
/**
 *	Reads and returns a 16-bit value from the stream without advancing the stream's position
 */
UInt16 IDataStream::Peek16(void)
{
	IDataStream_PositionSaver	saver(this);

	return Read16();
}