예제 #1
0
    void Collect( VkCommandBuffer cmdbuf )
    {
        ZoneScopedC( Color::Red4 );

        if( m_tail == m_head ) return;

#ifdef TRACY_ON_DEMAND
        if( !s_profiler.IsConnected() )
        {
            vkCmdResetQueryPool( cmdbuf, m_query, 0, QueryCount );
            m_head = m_tail = 0;
            return;
        }
#endif

        unsigned int cnt;
        if( m_oldCnt != 0 )
        {
            cnt = m_oldCnt;
            m_oldCnt = 0;
        }
        else
        {
            cnt = m_head < m_tail ? QueryCount - m_tail : m_head - m_tail;
        }

        int64_t res[QueryCount];
        if( vkGetQueryPoolResults( m_device, m_query, m_tail, cnt, sizeof( res ), res, sizeof( *res ), VK_QUERY_RESULT_64_BIT ) == VK_NOT_READY )
        {
            m_oldCnt = cnt;
            return;
        }

        Magic magic;
        auto& token = s_token.ptr;
        auto& tail = token->get_tail_index();

        for( unsigned int idx=0; idx<cnt; idx++ )
        {
            auto item = token->enqueue_begin<tracy::moodycamel::CanAlloc>( magic );
            MemWrite( &item->hdr.type, QueueType::GpuTime );
            MemWrite( &item->gpuTime.gpuTime, res[idx] );
            MemWrite( &item->gpuTime.queryId, uint16_t( m_tail + idx ) );
            MemWrite( &item->gpuTime.context, m_context );
            tail.store( magic + 1, std::memory_order_release );
        }

        vkCmdResetQueryPool( cmdbuf, m_query, m_tail, cnt );

        m_tail += cnt;
        if( m_tail == QueryCount ) m_tail = 0;
    }
예제 #2
0
/*********************************************************************************
	module		:[EOLデータの書き込み]
	function	:[
		1. 指定されたMHエンコードテーブル配列No.のEOLデータを書き込む.
	]
	return		:[RX_MEM_OVER, OK]
	common		:[]
	condition	:[]
	comment		:[ XX 00 X8 のようにEOLをセットしないとEOLを検出できませんので
	               0のビット数をenc->Wp->Bitのビット調整 96/05/13 S.Wang (requested by Y.Suzuki)
	]
	machine		:[SH7043]
	language	:[SHC]
	keyword		:[SCDC]
	date		:[1995/11/28]
	author		:[S.Wang]
**********************************************************************************/
UBYTE Mem_EOLWrite(UWORD eol, struct CdcBlk_t *point, UBYTE a_color)
{
	UBYTE	mhbits1;
	UWORD		 	mhdata1;

	if (a_color == WHITE) {
		mhdata1 = MH_EC_WhiteTableMain[eol].MHData;
		mhbits1 = MH_EC_WhiteTableMain[eol].BitLength;
	}
	else {
		mhdata1 = MH_EC_BlackTableMain[eol].MHData;
		mhbits1 = MH_EC_BlackTableMain[eol].BitLength;
	}
	switch(point->Wp->Bit) { /* 96/05/13 S.Wang (requested by Y.Suzuki) */
	case 0x01:
		 break;
	case 0x02:
		if (MemWrite(point->Wp, 7, 0x00) == RX_MEM_OVER) {
			return(RX_MEM_OVER);
		}
		break;
	case 0x04:
		if (MemWrite(point->Wp, 6, 0x00) == RX_MEM_OVER) {
			return(RX_MEM_OVER);
		}
		break;
	case 0x08:
		if (MemWrite(point->Wp, 5, 0x00) == RX_MEM_OVER) {
			return(RX_MEM_OVER);
		}
		break;
	case 0x10:
		if (MemWrite(point->Wp, 4, 0x00) == RX_MEM_OVER) {
			return(RX_MEM_OVER);
		}
		break;
	case 0x20:
		if (MemWrite(point->Wp, 3, 0x00) == RX_MEM_OVER) {
			return(RX_MEM_OVER);
		}
		break;
	case 0x40:
		if (MemWrite(point->Wp, 2, 0x00) == RX_MEM_OVER) {
			return(RX_MEM_OVER);
		}
		break;
	case 0x80:
		if (MemWrite(point->Wp, 1, 0x00) == RX_MEM_OVER) {
			return(RX_MEM_OVER);
		}
		break;
	default:
		break;
	}
	if (MemWrite(point->Wp, mhbits1, mhdata1) == RX_MEM_OVER) {
		return(RX_MEM_OVER);
	}
}
예제 #3
0
SCRIPT_EXPORT void Script::Pattern::WriteMem(duint start, duint size, const char* pattern)
{
    Memory<unsigned char*> data(size, "Script::Pattern::WriteMem::data");
    if(!MemRead((void*)start, data(), data.size(), nullptr))
        return;
    patternwrite(data(), data.size(), pattern);
    MemWrite((void*)start, data(), data.size(), nullptr);
}
예제 #4
0
 bool Process::MemWritePattern(ptr data, size_t datasize, const Pattern::WildcardPattern & pattern, bool safe)
 {
     std::vector<uint8> buffer(datasize);
     if (!MemRead(data, buffer.data(), datasize, nullptr, safe))
         return false;
     Pattern::Write(buffer.data(), datasize, pattern);
     return MemWrite(data, buffer.data(), datasize, nullptr, safe);
 }
예제 #5
0
 bool Process::MemSearchAndReplace(ptr data, size_t datasize, const Pattern::WildcardPattern & searchpattern, const Pattern::WildcardPattern & replacepattern, bool safe)
 {
     std::vector<uint8> buffer(datasize);
     if (!MemRead(data, buffer.data(), datasize, nullptr, safe))
         return false;
     if (!Pattern::SearchAndReplace(buffer.data(), datasize, searchpattern, replacepattern))
         return false;
     return MemWrite(data, buffer.data(), datasize, nullptr, safe);
 }
예제 #6
0
    tracy_force_inline ~VkCtxScope()
    {
#ifdef TRACY_ON_DEMAND
        if( !m_active ) return;
#endif
        const auto queryId = m_ctx->NextQueryId();
        vkCmdWriteTimestamp( m_cmdbuf, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, m_ctx->m_query, queryId );

        Magic magic;
        auto& token = s_token.ptr;
        auto& tail = token->get_tail_index();
        auto item = token->enqueue_begin<tracy::moodycamel::CanAlloc>( magic );
        MemWrite( &item->hdr.type, QueueType::GpuZoneEnd );
        MemWrite( &item->gpuZoneEnd.cpuTime, Profiler::GetTime() );
        MemWrite( &item->gpuZoneEnd.queryId, uint16_t( queryId ) );
        MemWrite( &item->gpuZoneEnd.context, m_ctx->GetId() );
        tail.store( magic + 1, std::memory_order_release );
    }
예제 #7
0
파일: BPTree.cpp 프로젝트: V756568/MiniSQL
///////////////////////////////////////////////////////////////////////////////////////////////////////////
// write the infomation to the head of the btree index file
void BPTree_Index::writeHeadToFile() {
  // get the start address which store the head
  char address[256];
  strcpy(address,CurLocation);
  strcat(address,CurRelationName);
  strcat(address,".idx");
  _M_File test = Buffer[address];  
  _F_FileAddr ptr = test.GetIdxPoint();

  // write IdxHead
  void* temp = (void*)(&IdxHead);
  _F_FileAddr next;
  next = MemWrite( temp,sizeof(Index_Head),&ptr);
 
  // write Key information
  temp = (void*)KeyInfo;
  
  MemWrite(temp,strlen(KeyInfo) + 1,&next);
}
예제 #8
0
/***************************************************************************
	module		:[MRデータの書き込み]
	function	:[
		1. 指定されたMRエンコードのMRデータを書き込む.
	]
	return		:[RX_MEM_OVER, OK]
	common		:[]
	condition	:[]
	comment		:[]
	machine		:[SH7043]
	language	:[SHC]
	keyword		:[SCDC]
	date		:[1995/11/28]
	author		:[S.Wang]
****************************************************************************/
UBYTE Mem_MRDataWrite(UBYTE code, struct CdcBlk_t *point)	/* MR code */
{
	UBYTE	mrcode;
	UBYTE	mrbits;

	mrcode = MR_EC_TableMain[code].MRData;
	mrbits = MR_EC_TableMain[code].BitLength;
	if (MemWrite(point->Wp, mrbits, mrcode) == RX_MEM_OVER) {
		return(RX_MEM_OVER);
	}
}
예제 #9
0
SCRIPT_EXPORT bool Script::Pattern::SearchAndReplaceMem(duint start, duint size, const char* searchpattern, const char* replacepattern)
{
    Memory<unsigned char*> data(size, "Script::Pattern::SearchAndReplaceMem::data");
    if(!MemRead((void*)start, data(), size, nullptr))
        return false;
    duint found = patternfind(data(), data.size(), searchpattern);
    if(found == -1)
        return false;
    patternwrite(data() + found, data.size() - found, replacepattern);
    MemWrite((void*)(start + found), data() + found, data.size() - found, nullptr);
    return true;
}
예제 #10
0
    tracy_force_inline VkCtxScope( VkCtx* ctx, const SourceLocationData* srcloc, VkCommandBuffer cmdbuf, int depth )
        : m_cmdbuf( cmdbuf )
        , m_ctx( ctx )
#ifdef TRACY_ON_DEMAND
        , m_active( s_profiler.IsConnected() )
#endif
    {
#ifdef TRACY_ON_DEMAND
        if( !m_active ) return;
#endif
        const auto thread = GetThreadHandle();

        const auto queryId = ctx->NextQueryId();
        vkCmdWriteTimestamp( cmdbuf, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, ctx->m_query, queryId );

        Magic magic;
        auto& token = s_token.ptr;
        auto& tail = token->get_tail_index();
        auto item = token->enqueue_begin<tracy::moodycamel::CanAlloc>( magic );
        MemWrite( &item->hdr.type, QueueType::GpuZoneBeginCallstack );
        MemWrite( &item->gpuZoneBegin.cpuTime, Profiler::GetTime() );
        MemWrite( &item->gpuZoneBegin.srcloc, (uint64_t)srcloc );
        MemWrite( &item->gpuZoneBegin.thread, thread );
        MemWrite( &item->gpuZoneBegin.queryId, uint16_t( queryId ) );
        MemWrite( &item->gpuZoneBegin.context, ctx->GetId() );
        tail.store( magic + 1, std::memory_order_release );

        s_profiler.SendCallstack( depth, thread );
    }
예제 #11
0
파일: bone.c 프로젝트: umibps/KABURAGI
/*****************************************************
* WriteBoneData関数                                  *
* ボーンの位置と向きの情報を書き出す                 *
* 引数                                               *
* model			: ボーンの位置と向きを書き出すモデル *
* out_data_size	: 書き出したバイト数の格納先         *
* 返り値                                             *
*	書き出したデータ                                 *
*****************************************************/
uint8* WriteBoneData(
	MODEL_INTERFACE* model,
	size_t* out_data_size
)
{
	MEMORY_STREAM *stream = CreateMemoryStream(4096);
	BONE_INTERFACE **bones;
	uint8 *result;
	uint32 data32;
	float float_values[4];
	int num_bones;
	int i;

	bones = (BONE_INTERFACE**)model->get_bones(model, &num_bones);
	data32 = (uint32)num_bones;
	(void)MemWrite(&data32, sizeof(data32), 1, stream);
	for(i=0; i<num_bones; i++)
	{
		BONE_INTERFACE *bone = bones[i];
		data32 = (uint32)strlen(bone->name)+1;
		(void)MemWrite(&data32, sizeof(data32), 1, stream);
		(void)MemWrite(bone->name, 1, data32, stream);
		bone->get_local_translation(bone, float_values);
		(void)MemWrite(float_values, sizeof(*float_values), 3, stream);
		bone->get_local_rotation(bone, float_values);
		(void)MemWrite(float_values, sizeof(*float_values), 4, stream);
	}

	if(out_data_size != NULL)
	{
		*out_data_size = stream->data_point;
	}

	result = stream->buff_ptr;
	MEM_FREE_FUNC(bones);
	MEM_FREE_FUNC(stream);

	return result;
}
예제 #12
0
파일: patches.cpp 프로젝트: 0x4e38/x64dbg
bool PatchDelete(duint Address, bool Restore)
{
    ASSERT_DEBUGGING("Export call");
    EXCLUSIVE_ACQUIRE(LockPatches);

    // Do a list lookup with hash
    auto found = patches.find(ModHashFromAddr(Address));

    if(found == patches.end())
        return false;

    // Restore the original byte at this address
    if(Restore)
        MemWrite((found->second.addr + ModBaseFromAddr(Address)), &found->second.oldbyte, sizeof(char));

    // Finally remove it from the list
    patches.erase(found);
    return true;
}
예제 #13
0
파일: patches.cpp 프로젝트: 0x4e38/x64dbg
void PatchDelRange(duint Start, duint End, bool Restore)
{
    ASSERT_DEBUGGING("Export call");

    // Are all bookmarks going to be deleted?
    // 0x00000000 - 0xFFFFFFFF
    if(Start == 0 && End == ~0)
    {
        EXCLUSIVE_ACQUIRE(LockPatches);
        patches.clear();
    }
    else
    {
        // Make sure 'Start' and 'End' reference the same module
        duint moduleBase = ModBaseFromAddr(Start);

        if(moduleBase != ModBaseFromAddr(End))
            return;

        // VA to RVA in module
        Start -= moduleBase;
        End -= moduleBase;

        EXCLUSIVE_ACQUIRE(LockPatches);
        for(auto itr = patches.begin(); itr != patches.end();)
        {
            const auto & currentPatch = itr->second;
            // [Start, End)
            if(currentPatch.addr >= Start && currentPatch.addr < End)
            {
                // Restore the original byte if necessary
                if(Restore)
                    MemWrite((currentPatch.addr + moduleBase), &currentPatch.oldbyte, sizeof(char));

                itr = patches.erase(itr);
            }
            else
                ++itr;
        }
    }
}
예제 #14
0
void scStream::STRWriteMemText( Bool				addDcr,
								SystemMemoryObject& sysConPBlock )
{
	scContUnit* 	para;
	status			stat = scNoAction;
	MemFileStruct	mfs( &sysConPBlock );
	
	for ( mfs.fTotalSize = 0, para = First(); para; para = para->GetNext( ) )
		mfs.fTotalSize += ( PARAChSize( para ) + 1 );	// for carriage returns
	mfs.fTotalSize++;									// NULL terminator

	sysConPBlock.SetHandleSize( mfs.fTotalSize );
	
	mfs.fBytesWritten	= 0;
	mfs.fDstPtr 		= mfs.fStartMem = (scChar*)sysConPBlock.LockHandle( );

	STRWriteTextFile( (APPCtxPtr)&mfs, MemWrite, addDcr );

	MemWrite( (APPCtxPtr)&mfs, "", 1 ); 	/* NULL terminate */

	sysConPBlock.UnlockHandle( );
}
예제 #15
0
파일: BPTree.cpp 프로젝트: V756568/MiniSQL
///////////////////////////////////////////////////////////////////////////////////////////////////
//--
_F_FileAddr BPTree::createNodeInFile() {
	BPTree_Index idx;
	idx.readHeadFromFile();
	//the index file has no empty block
	if( 0 == idx.IdxHead.FirstEmptyBlock.ulFilePageID ) {
		// firstly,we should check whether the block overflow the current page
		// If so,use the next page 
		void* CheckOverflow = (void*) new char[BTreeNodeSize];
		_F_FileAddr Next = MemWrite(CheckOverflow, BTreeNodeSize, &idx.IdxHead.FirstNewBlock);
		_F_FileAddr temp = idx.IdxHead.FirstNewBlock;
		idx.IdxHead.FirstNewBlock = Next;
		idx.writeHeadToFile();
		return temp;
	}
	else {
		int flag = 0;  
		if(idx.IdxHead.FirstEmptyBlock ==  idx.IdxHead.LastEmptyBlock)
			flag = 1;
		_F_FileAddr temp = idx.IdxHead.FirstEmptyBlock;
		if( 1 == flag) { 
			//there is just one empty block
			idx.IdxHead.FirstEmptyBlock.ulFilePageID = 0;
			idx.IdxHead.FirstEmptyBlock.uiOffset     = 0;
			idx.IdxHead.LastEmptyBlock.ulFilePageID  = 0;
			idx.IdxHead.LastEmptyBlock.uiOffset      = 0;
		}
		else {
			// change FisrtEmptyBlock point to the next block
			BPTreeNode NextNode;
			NextNode.readNodeFromFile(temp);
			idx.IdxHead.FirstEmptyBlock = NextNode.Next_Empty_Block;
		}
		idx.writeHeadToFile();
		return temp;
	}
}
예제 #16
0
    VkCtx( VkPhysicalDevice physdev, VkDevice device, VkQueue queue, VkCommandBuffer cmdbuf )
        : m_device( device )
        , m_queue( queue )
        , m_context( s_gpuCtxCounter.fetch_add( 1, std::memory_order_relaxed ) )
        , m_head( 0 )
        , m_tail( 0 )
        , m_oldCnt( 0 )
    {
        assert( m_context != 255 );

        VkPhysicalDeviceProperties prop;
        vkGetPhysicalDeviceProperties( physdev, &prop );
        const float period = prop.limits.timestampPeriod;

        VkQueryPoolCreateInfo poolInfo = {};
        poolInfo.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
        poolInfo.queryCount = QueryCount;
        poolInfo.queryType = VK_QUERY_TYPE_TIMESTAMP;
        vkCreateQueryPool( device, &poolInfo, nullptr, &m_query );

        VkCommandBufferBeginInfo beginInfo = {};
        beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
        beginInfo.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;

        VkSubmitInfo submitInfo = {};
        submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
        submitInfo.commandBufferCount = 1;
        submitInfo.pCommandBuffers = &cmdbuf;

        vkBeginCommandBuffer( cmdbuf, &beginInfo );
        vkCmdResetQueryPool( cmdbuf, m_query, 0, QueryCount );
        vkEndCommandBuffer( cmdbuf );
        vkQueueSubmit( queue, 1, &submitInfo, VK_NULL_HANDLE );
        vkQueueWaitIdle( queue );

        vkBeginCommandBuffer( cmdbuf, &beginInfo );
        vkCmdWriteTimestamp( cmdbuf, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, m_query, 0 );
        vkEndCommandBuffer( cmdbuf );
        vkQueueSubmit( queue, 1, &submitInfo, VK_NULL_HANDLE );
        vkQueueWaitIdle( queue );

        int64_t tcpu = Profiler::GetTime();
        int64_t tgpu;
        vkGetQueryPoolResults( device, m_query, 0, 1, sizeof( tgpu ), &tgpu, sizeof( tgpu ), VK_QUERY_RESULT_64_BIT | VK_QUERY_RESULT_WAIT_BIT );

        vkBeginCommandBuffer( cmdbuf, &beginInfo );
        vkCmdResetQueryPool( cmdbuf, m_query, 0, 1 );
        vkEndCommandBuffer( cmdbuf );
        vkQueueSubmit( queue, 1, &submitInfo, VK_NULL_HANDLE );
        vkQueueWaitIdle( queue );

        Magic magic;
        auto& token = s_token.ptr;
        auto& tail = token->get_tail_index();
        auto item = token->enqueue_begin<tracy::moodycamel::CanAlloc>( magic );
        MemWrite( &item->hdr.type, QueueType::GpuNewContext );
        MemWrite( &item->gpuNewContext.cpuTime, tcpu );
        MemWrite( &item->gpuNewContext.gpuTime, tgpu );
        memset( &item->gpuNewContext.thread, 0, sizeof( item->gpuNewContext.thread ) );
        MemWrite( &item->gpuNewContext.period, period );
        MemWrite( &item->gpuNewContext.context, m_context );
        MemWrite( &item->gpuNewContext.accuracyBits, uint8_t( 0 ) );

#ifdef TRACY_ON_DEMAND
        s_profiler.DeferItem( *item );
#endif

        tail.store( magic + 1, std::memory_order_release );
    }
예제 #17
0
bool cbDebugLoadLib(int argc, char* argv[])
{
    if(argc < 2)
    {
        dputs(QT_TRANSLATE_NOOP("DBG", "Error: you must specify the name of the DLL to load\n"));
        return false;
    }

    LoadLibThreadID = fdProcessInfo->dwThreadId;
    HANDLE LoadLibThread = ThreadGetHandle((DWORD)LoadLibThreadID);

    DLLNameMem = MemAllocRemote(0, strlen(argv[1]) + 1);
    ASMAddr = MemAllocRemote(0, 0x1000);

    if(!DLLNameMem || !ASMAddr)
    {
        dputs(QT_TRANSLATE_NOOP("DBG", "Error: couldn't allocate memory in debuggee"));
        return false;
    }

    if(!MemWrite(DLLNameMem, argv[1], strlen(argv[1])))
    {
        dputs(QT_TRANSLATE_NOOP("DBG", "Error: couldn't write process memory"));
        return false;
    }

    int size = 0;
    int counter = 0;
    duint LoadLibraryA = 0;
    char command[50] = "";
    char error[MAX_ERROR_SIZE] = "";

    GetFullContextDataEx(LoadLibThread, &backupctx);

    if(!valfromstring("kernel32:LoadLibraryA", &LoadLibraryA, false))
    {
        dputs(QT_TRANSLATE_NOOP("DBG", "Error: couldn't get kernel32:LoadLibraryA"));
        return false;
    }

    // Arch specific asm code
#ifdef _WIN64
    sprintf_s(command, "mov rcx, %p", DLLNameMem);
#else
    sprintf_s(command, "push %p", DLLNameMem);
#endif // _WIN64

    assembleat(ASMAddr, command, &size, error, true);
    counter += size;

#ifdef _WIN64
    sprintf_s(command, "mov rax, %p", LoadLibraryA);
    assembleat(ASMAddr + counter, command, &size, error, true);
    counter += size;
    sprintf_s(command, "call rax");
#else
    sprintf_s(command, "call %p", LoadLibraryA);
#endif // _WIN64

    assembleat(ASMAddr + counter, command, &size, error, true);
    counter += size;

    SetContextDataEx(LoadLibThread, UE_CIP, ASMAddr);
    auto ok = SetBPX(ASMAddr + counter, UE_SINGLESHOOT | UE_BREAKPOINT_TYPE_INT3, (void*)cbDebugLoadLibBPX);

    ThreadSuspendAll();
    ResumeThread(LoadLibThread);

    unlock(WAITID_RUN);

    return ok;
}
예제 #18
0
파일: material.c 프로젝트: umibps/KABURAGI
/*******************************************************
* WriteMmdModelMaterials関数                           *
* PMDとPMXのテクスチャ画像データを書き出す             *
* 引数                                                 *
* model			: テクスチャ画像データを書き出すモデル *
* out_data_size	: 書き出したデータのバイト数格納先     *
* 返り値                                               *
*	書き出したデータ                                   *
*******************************************************/
uint8* WriteMmdModelMaterials(
	MODEL_INTERFACE* model,
	size_t* out_data_size
)
{
	// 画像データをまとめて書き出すバッファ
	MEMORY_STREAM *stream = CreateMemoryStream(1024 * 1024);
	// 作成結果のストリーム
	MEMORY_STREAM result_stream = {0};
	// 作成結果データ
	uint8 *result;
	// テクスチャ画像配列へのポインタ
	MATERIAL_INTERFACE **materials;
	// 画像データの格納先
	uint8 *image_data = NULL;
	// 画像データ格納バッファのサイズ
	size_t image_data_buffer_size = 0;
	// UTF-8での画像ファイルへのパス
	char utf8_path[8192];
	// OSでの画像ファイルへのパス
	char *system_path;
	// 画像ファイルの読み込み、ファイルサイズ、存在確認用
	FILE *fp;
	// 画像ファイルの数
	int num_images = 0;
	// テクスチャ画像配列のサイズ
	int num_materials;
	// 32ビット書き出し用
	uint32 data32;
	// 画像データの開始位置
	long image_start = sizeof(data32);
	// 画像データの合計サイズ
	long total_image_size = 0;
	int counter;
	// 書き出す画像ファイルの名前・サイズ配列
	MATERIAL_ARCHIVE_DATA *names;
	// 重複書き出し防止用
	ght_hash_table_t *name_table;
	unsigned int name_length;
	uint32 diff;
	// for文用のカウンタ
	int i;

	// モデルに設定されているテクスチャ画像を取得
	materials = (MATERIAL_INTERFACE**)model->get_materials(model, &num_materials);

	name_table = ght_create(num_materials+1);
	ght_set_hash(name_table, (ght_fn_hash_t)GetStringHash);

	// それぞれの画像ファイルのファイル名サイズを取得
	for(i=0; i<num_materials; i++)
	{
		MATERIAL_INTERFACE *material = materials[i];
		if(material->main_texture != NULL)
		{
			name_length = (unsigned int)strlen(material->main_texture);
			if(ght_get(name_table, name_length, material->main_texture) == NULL)
			{
				(void)ght_insert(name_table, (void*)1, name_length, material->main_texture);
				image_start += (long)name_length+1;
				image_start += sizeof(uint32) + sizeof(uint32) + sizeof(uint32);
				num_images++;
			}
		}
		if(material->sphere_texture != NULL)
		{
			name_length = (unsigned int)strlen(material->sphere_texture);
			if(ght_get(name_table, name_length, material->sphere_texture) == NULL)
			{
				(void)ght_insert(name_table, (void*)1, name_length, material->sphere_texture);
				image_start += (long)name_length+1;
				image_start += sizeof(uint32) + sizeof(uint32) + sizeof(uint32);
				num_images++;
			}
		}
		if(material->toon_texture != NULL)
		{	// トゥーンテクスチャの場合はモデルのディレクトリに画像があるか確認
			(void)sprintf(utf8_path, "%s/%s", model->model_path, material->toon_texture);
			system_path = LocaleFromUTF8(utf8_path);

			if((fp = fopen(system_path, "rb")) != NULL)
			{	// 画像有
				name_length = (unsigned int)strlen(material->toon_texture);
				if(ght_get(name_table, name_length, material->toon_texture) == NULL)
				{
					(void)ght_insert(name_table, (void*)1, name_length, material->toon_texture);
					image_start += (long)name_length+1;
					image_start += sizeof(uint32) + sizeof(uint32) + sizeof(uint32);
					num_images++;
					(void)fclose(fp);
				}
			}

			MEM_FREE_FUNC(system_path);
		}
	}
	ght_finalize(name_table);

	// 画像ファイルを一つのデータにまとめる
	name_table = ght_create(num_materials+1);
	ght_set_hash(name_table, (ght_fn_hash_t)GetStringHash);
	names = (MATERIAL_ARCHIVE_DATA*)MEM_ALLOC_FUNC(sizeof(*names)*num_images);
	counter = 0;
	for(i=0; i<num_materials; i++)
	{
		MATERIAL_INTERFACE *material = materials[i];
		if(material->main_texture != NULL)
		{
			name_length = (unsigned int)strlen(material->main_texture);
			if(ght_get(name_table, name_length, material->main_texture) == NULL)
			{
				(void)ght_insert(name_table, (void*)1, name_length, material->main_texture);
				names[counter].data_start = image_start + total_image_size;
				(void)sprintf(utf8_path, "%s/%s", model->model_path, material->main_texture);
				system_path = LocaleFromUTF8(utf8_path);

				if((fp = fopen(system_path, "rb")) != NULL)
				{
					(void)fseek(fp, 0, SEEK_END);
					names[counter].name = material->main_texture;
					names[counter].data_size = ftell(fp);
					names[counter].data_start = total_image_size + image_start;
					total_image_size += names[counter].data_size;
					rewind(fp);
					if(image_data_buffer_size < names[counter].data_size)
					{
						image_data = (uint8*)MEM_REALLOC_FUNC(image_data, names[counter].data_size);
						image_data_buffer_size = names[counter].data_size;
					}
					(void)fread(image_data, 1, names[counter].data_size, fp);
					(void)MemWrite(image_data, 1, names[counter].data_size, stream);
					counter++;

					(void)fclose(fp);
				}
				else
				{
					char sp_path[8192] = {0};
					char *extention = sp_path;
					char *p = extention;

					(void)strcpy(sp_path, system_path);
					while(*p != '\0')
					{
						if(*p == '.')
						{
							extention = p;
						}
						p++;
					}
					extention[1] = 's';
					extention[2] = 'p';
					extention[3] = 'a';
					extention[4] = '\0';
					if((fp = fopen(sp_path, "rb")) != NULL)
					{
						(void)fseek(fp, 0, SEEK_END);
						names[counter].name = material->main_texture;
						names[counter].data_size = ftell(fp);
						names[counter].data_start = total_image_size + image_start;
						total_image_size += names[counter].data_size;
						rewind(fp);
						if(image_data_buffer_size < names[counter].data_size)
						{
							image_data = (uint8*)MEM_REALLOC_FUNC(image_data, names[counter].data_size);
							image_data_buffer_size = names[counter].data_size;
						}
						(void)fread(image_data, 1, names[counter].data_size, fp);
						(void)MemWrite(image_data, 1, names[counter].data_size, stream);
						counter++;

						(void)fclose(fp);
					}
					else
					{
						extention[3] = 'h';
						if((fp = fopen(sp_path, "rb")) != NULL)
						{
							(void)fseek(fp, 0, SEEK_END);
							names[counter].name = material->main_texture;
							names[counter].data_size = ftell(fp);
							names[counter].data_start = total_image_size + image_start;
							total_image_size += names[counter].data_size;
							rewind(fp);
							if(image_data_buffer_size < names[counter].data_size)
							{
								image_data = (uint8*)MEM_REALLOC_FUNC(image_data, names[counter].data_size);
								image_data_buffer_size = names[counter].data_size;
							}
							(void)fread(image_data, 1, names[counter].data_size, fp);
							(void)MemWrite(image_data, 1, names[counter].data_size, stream);
							counter++;

							(void)fclose(fp);
						}
					}
				}

				MEM_FREE_FUNC(system_path);
			}
		}

		if(material->sphere_texture != NULL)
		{
			name_length = (unsigned int)strlen(material->sphere_texture);
			if(ght_get(name_table, name_length, material->sphere_texture) == NULL)
			{
				(void)ght_insert(name_table, (void*)1, name_length, material->sphere_texture);
				names[counter].data_start = image_start + total_image_size;
				(void)sprintf(utf8_path, "%s/%s", model->model_path, material->sphere_texture);
				system_path = LocaleFromUTF8(utf8_path);

				if((fp = fopen(system_path, "rb")) != NULL)
				{
					(void)fseek(fp, 0, SEEK_END);
					names[counter].name = material->sphere_texture;
					names[counter].data_size = ftell(fp);
					names[counter].data_start = total_image_size + image_start;
					total_image_size += names[counter].data_size;
					rewind(fp);
					if(image_data_buffer_size < names[counter].data_size)
					{
						image_data = (uint8*)MEM_REALLOC_FUNC(image_data, names[counter].data_size);
						image_data_buffer_size = names[counter].data_size;
					}
					(void)fread(image_data, 1, names[counter].data_size, fp);
					(void)MemWrite(image_data, 1, names[counter].data_size, stream);
					counter++;

					(void)fclose(fp);
				}

				MEM_FREE_FUNC(system_path);
			}
		}

		if(material->toon_texture != NULL)
		{	// トゥーンテクスチャの場合はモデルのディレクトリに画像があるか確認
			(void)sprintf(utf8_path, "%s/%s", model->model_path, material->toon_texture);
			system_path = LocaleFromUTF8(utf8_path);

			name_length = (unsigned int)strlen(material->toon_texture);
			if(ght_get(name_table, name_length, material->toon_texture) == NULL)
			{
				if((fp = fopen(system_path, "rb")) != NULL)
				{	// 画像有
					(void)ght_insert(name_table, (void*)1, name_length, material->toon_texture);
					(void)fseek(fp, 0, SEEK_END);
					names[counter].name = material->toon_texture;
					names[counter].data_size = ftell(fp);
					names[counter].data_start = total_image_size + image_start;
					total_image_size += names[counter].data_size;
					rewind(fp);
					if(image_data_buffer_size < names[counter].data_size)
					{
						image_data = (uint8*)MEM_REALLOC_FUNC(image_data, names[counter].data_size);
						image_data_buffer_size = names[counter].data_size;
					}
					(void)fread(image_data, 1, names[counter].data_size, fp);
					(void)MemWrite(image_data, 1, names[counter].data_size, stream);
					counter++;

					(void)fclose(fp);
				}
			}

			MEM_FREE_FUNC(system_path);
		}
	}

	num_images = counter;
	ght_finalize(name_table);

	result = (uint8*)MEM_ALLOC_FUNC(image_start + total_image_size + sizeof(uint32));
	result_stream.buff_ptr = result;
	result_stream.data_size = image_start + total_image_size;
	result_stream.block_size = 1;
	data32 = num_images;
	(void)MemWrite(&data32, sizeof(data32), 1, &result_stream);
	for(i=0; i<num_images; i++)
	{
		data32 = (uint32)strlen(names[i].name)+1;
		(void)MemWrite(&data32, sizeof(data32), 1, &result_stream);
		(void)MemWrite(names[i].name, 1, data32, &result_stream);
		data32 = names[i].data_start;
		(void)MemWrite(&data32, sizeof(data32), 1, &result_stream);
		data32 = names[i].data_size;
		(void)MemWrite(&data32, sizeof(data32), 1, &result_stream);
	}
	if((diff = (uint32)(image_start - result_stream.data_point)) > 0)
	{
		(void)MemSeek(&result_stream, sizeof(data32), SEEK_SET);
		for(i=0; i<num_images; i++)
		{
			data32 = (uint32)strlen(names[i].name)+1;
			(void)MemWrite(&data32, sizeof(data32), 1, &result_stream);
			(void)MemWrite(names[i].name, 1, data32, &result_stream);
			data32 = names[i].data_start - diff;
			(void)MemWrite(&data32, sizeof(data32), 1, &result_stream);
			data32 = names[i].data_start - diff;
			(void)MemWrite(&data32, sizeof(data32), 1, &result_stream);
		}
		image_start -= diff;
	}
	(void)MemWrite(stream->buff_ptr, 1, stream->data_point, &result_stream);

	if(out_data_size != NULL)
	{
		*out_data_size = image_start + total_image_size;
	}

	MEM_FREE_FUNC(image_data);
	MEM_FREE_FUNC(names);
	MEM_FREE_FUNC(materials);
	(void)DeleteMemoryStream(stream);

	return result;
}
예제 #19
0
 bool Process::MemWriteSafe(ptr address, const void* buffer, ptr size, ptr* bytesWritten)
 {
     //TODO: correctly implement this
     return MemWrite(address, buffer, size, bytesWritten);
 }
예제 #20
0
int main(int argc, char* argv[])
{
    tPvErr errCode;
    int err = 0;

    // initialize the PvAPI
    if((errCode = PvInitialize()) != ePvErrSuccess)
    {
        printf("PvInitialize err: %u\n", errCode);
    }
    else
    {
        int c;
        unsigned long uid = 0;
        unsigned long addr = 0;
        bool bGet = false;
        bool bSet = false;

        while ((c = getopt (argc, argv, "u:i:gs:h?")) != -1)
        {
            switch(c)
            {
            case 'u':
            {
                if(optarg)
                    uid = atol(optarg);

                break;
            }
            case 'i':
            {
                if(optarg)
                    addr = inet_addr(optarg);

                break;
            }
            case 'g':
            {
                bGet = true;
                break;
            }
            case 's':
            {
                bSet = true;
                break;
            }
            case '?':
            case 'h':
            {
                ShowUsage();
                break;
            }
            default:
                break;
            }
        }

        if(uid || ((addr != INADDR_NONE) && (addr != INADDR_ANY)))
        {
            tPvHandle       Camera;
            tPvAccessFlags  Flags = (bSet ? ePvAccessMaster : ePvAccessMonitor);

            if(uid)
            {
                // wait a bit to leave some time to the API to detect any camera
                Sleep(500);
                // and open the camera
                errCode = PvCameraOpen(uid,Flags,&Camera);
            }
            else
                errCode = PvCameraOpenByAddr(addr,Flags,&Camera);

            if(errCode == ePvErrSuccess)
            {
                if(bGet) // get value
                    errCode = MemRead(Camera);
                else if(bSet) // set value
                    errCode = MemWrite(Camera,argv[argc-1]);

                if(errCode != ePvErrSuccess)
                    fprintf(stderr,"Error: %u\n",errCode);

                err = 1;

                // close the camera
                PvCameraClose(Camera);
            }
            else
            {
                if(errCode == ePvErrNotFound || errCode == ePvErrUnplugged)
                    fprintf(stderr,"No camera detected.\n");
                else if(errCode == ePvErrAccessDenied)
                    fprintf(stderr,"Camera already in use.\n");
                else
                    fprintf(stderr,"PvCameraOpen fail: %u\n", errCode);

                err = 1;
            }
        }
        else
        {
            ShowUsage();
            err = 1;
        }

        PvUnInitialize();
    }

    return err;
}
예제 #21
0
파일: BPTree.cpp 프로젝트: V756568/MiniSQL
///////////////////////////////////////////////////////////////////////////////////////////////
// write the separate space into one block
// MemPtr is the first address of the block
void BPTreeNode::writeNodeToFile(_F_FileAddr ptr) {
  void* MemPtr;
  MemPtr = ptr.MemAddr();
  
  // write Next_Empty_Block into the block
  MemWrite((void*)(&Next_Empty_Block),sizeof(_F_FileAddr),&ptr);
  // move to the first address of IsLeaf
  MemPtr = (void*)((char*)MemPtr + sizeof(_F_FileAddr));
  
  // write IsLeaf into the block
  bool* pIsLeaf = (bool*)MemPtr;
  *pIsLeaf      = IsLeaf;
       
  // move to the first address of ItemNode in the block
  MemPtr = (void*)((char*)MemPtr + sizeof(bool));

  // write ItemOnNode into the block
  int *pItemOnNode = (int*)MemPtr;
  *pItemOnNode     = ItemOnNode;

  // move the the first address of p[o] in the block
  MemPtr = (void*)((char*)MemPtr + sizeof(int));

  int i;
  for(i=0;i<ItemOnNode;i++)
  {
    // write the p[i]
    _F_FileAddr* pp    = (_F_FileAddr*)MemPtr;
    pp->ulFilePageID = p[i].ulFilePageID;
    pp->uiOffset     = p[i].uiOffset;

    // move to the first address of k[i] in the block
    MemPtr = (void*)((char*)MemPtr + sizeof(_F_FileAddr));
    
    // write the k[i]
    pKey_Attr pField = k[i];
    for(int j=0;KeyInfo[j]!=0;j++)
    {
      switch(KeyInfo[j])
      {
        
        case 'i'   :  // int value
                      int *pIntValue;
                      pIntValue = (int*)MemPtr;
                      *pIntValue     = pField->value.IntValue;
                      pField         = pField->next;
                      MemPtr = (void*)((char*)MemPtr + sizeof(int));
                      break;
        case 'f'   :  // float value
                      float *pFloatValue; 
                      pFloatValue = (float*)MemPtr;
                      *pFloatValue       = pField->value.FloatValue;
                      pField             = pField->next;
                      MemPtr = (void*)((char*)MemPtr + sizeof(float));
                      break;
        case 'c'   :  // string
                      int num = 0;
                      for(j=j+1; isdigit(KeyInfo[j]);j++)
                      {
                        num = num * 10 + KeyInfo[j] - '0';
                      }
                      j--;        // move the index back
                      num++;      // for '\0' which is the end of a string
                      char* pCharValue = (char*)MemPtr;
                      strcpy(pCharValue,pField->value.pCharValue);
                      pField = pField->next;
                      MemPtr = (void*)((char*)MemPtr + num);
                      break;                      
      }
    }// KeyInfo[i] = '\0'
  }// i = ItemOnNode

  if( 0 == IsLeaf) // not a leaf
  {
    //Write the p[ItemOnNode]
    _F_FileAddr* pp = (_F_FileAddr*)MemPtr;
    pp->ulFilePageID = p[i].ulFilePageID;
    pp->uiOffset     = p[i].uiOffset;
  }
  else // is is a leaf
  {
    // move to the address of p[MaxItem]
    MemPtr = (void*)( (char*)MemPtr + (MaxItem - ItemOnNode) * (KeySize + sizeof(_F_FileAddr)) );
    //Write the p[MaxItem] into the block
    _F_FileAddr* pp = (_F_FileAddr*)MemPtr;
    pp->ulFilePageID = p[MaxItem].ulFilePageID;
    pp->uiOffset     = p[MaxItem].uiOffset;
  }
}
예제 #22
0
void
CPersCtl::PersCtl()
{
	if (PR_htValid) {
#ifndef _HTV
		static const char *instructions[] = { "CTL_ENTRY", "CTL_RUN", "CTL_RTN" };
		if (0 || (PR_htInst == CTL_ENTRY))
			fprintf(stderr, "CTL: cmd=%s PR_cmd=%s S_rqAddr=%llx @ %lld\n",
				instructions[(int)PR_htInst],
				(PR_cmd == CMD_LD) ? "LD" : "ST",
				(long long)S_rqAddr,
				HT_CYCLE());
#endif

		switch (PR_htInst) {
		case CTL_ENTRY: {
			P_rqIdx = 0;
			P_rqCnt = 0;

			HtContinue(CTL_RUN);
		}
		break;
		case CTL_RUN: {
			if (MemReadBusy() || MemWriteBusy()) {
				HtRetry();
				break;
			}

			// Memory request
			MemAddr_t memAddr = S_rqAddr + (P_rqIdx << 3);

			if (PR_cmd == CMD_LD)
				MemRead_memRsp(memAddr);
			else
				MemWrite(memAddr, 0x600dbeef);

			P_rqCnt = P_rqCnt + 1;

			if ((P_rqIdx + 1) >= S_arrayLen)
				P_rqIdx = 0;
			else
				P_rqIdx = P_rqIdx + 1;

			if (P_rqCnt >= P_numReqs)
				HtContinue(CTL_RTN);
			else
				HtContinue(CTL_RUN);
		}
		break;
		case CTL_RTN: {
			if (ReturnBusy_htmain()) {
				HtRetry();
				break;
			}

			Return_htmain(P_rqCnt);
		}
		break;
		default:
			assert(0);
		}
	}
}
예제 #23
0
extern "C" DLL_EXPORT bool _dbg_memwrite(duint addr, const unsigned char* src, duint size, duint* written)
{
    return MemWrite(addr, src, size, written);
}
예제 #24
0
/***************************************************************************
	module		:[MHデータの書き込み]
	function	:[
		1. 指定されたRLはMHエンコードテーブル配列No.を求めてMHデータの書き込み]
		2.2560以上のRLがきた場合の処理追加 By Y.Suzuki 1996/12/03

	return		:[RX_MEM_OVER, OK]
	comment		:[]
	machine		:[SH7043]
	language	:[SHC]
	keyword		:[SCDC]
	date		:[1995/11/28]
	author		:[S.Wang]
***************************************************************************/
UBYTE Mem_RLToMHWrite(UWORD rl, struct CdcBlk_t *point, UBYTE a_color)
{
	UBYTE	mhbits1;
	UBYTE	mhbits2;
	UWORD 			mhdata1;
	UWORD 			mhdata2;

	while (1) {
		if (rl < 64) {				/* MH符号データはターミネイティング時ターミネイティングテーブルで求める */
			if (a_color == WHITE) {
				mhdata1 = MH_EC_WhiteTableMain[rl].MHData;
				mhbits1 = MH_EC_WhiteTableMain[rl].BitLength;
			}
			else {
				mhdata1 = MH_EC_BlackTableMain[rl].MHData;
				mhbits1 = MH_EC_BlackTableMain[rl].BitLength;
			}
			if (MemWrite(point->Wp, mhbits1, mhdata1) == RX_MEM_OVER) {
				return(RX_MEM_OVER);
			}
			return(OK);
		}
		else if ((rl < MH_MAKEUP_MAX) && (rl <= point->Img_Size)) { /* MH符号データメイクアップのとき */
		/*	By Y.Suzuki 1997/01/23	*/
			if (a_color == WHITE) {
				mhdata1 = MH_EC_WhiteTableMain[rl/64+63].MHData;
				mhdata2 = MH_EC_WhiteTableMain[rl%64].MHData;
				mhbits1 = MH_EC_WhiteTableMain[rl/64+63].BitLength;
				mhbits2 = MH_EC_WhiteTableMain[rl%64].BitLength;
			}
			else {
				mhdata1 = MH_EC_BlackTableMain[rl/64+63].MHData;
				mhdata2 = MH_EC_BlackTableMain[rl%64].MHData;
				mhbits1 = MH_EC_BlackTableMain[rl/64+63].BitLength;
				mhbits2 = MH_EC_BlackTableMain[rl%64].BitLength;
			}
			if (MemWrite(point->Wp, mhbits1, mhdata1) == RX_MEM_OVER) {  /* 最初のMH符号データを求める */
				return(RX_MEM_OVER);
			}
			if (MemWrite(point->Wp, mhbits2, mhdata2) == RX_MEM_OVER) {  /* 最後のMH符号データをターミネートテーブルで求める */
				return(RX_MEM_OVER);
			}
			return(OK);
		}
		else if ((rl >= MH_MAKEUP_MAX) && (rl <= point->Img_Size)) { /* RL > 2560の場合 */
			do {
				rl -= MH_MAKEUP_MAX;
				if (a_color == WHITE) {
					mhdata1 = MH_EC_WhiteTableMain[MH_MAKEUP_MAX/64+63].MHData;
					mhdata2 = MH_EC_WhiteTableMain[MH_MAKEUP_MAX%64].MHData;
					mhbits1 = MH_EC_WhiteTableMain[MH_MAKEUP_MAX/64+63].BitLength;
					mhbits2 = MH_EC_WhiteTableMain[MH_MAKEUP_MAX%64].BitLength;
				}
				else {
					mhdata1 = MH_EC_BlackTableMain[MH_MAKEUP_MAX/64+63].MHData;
					mhdata2 = MH_EC_BlackTableMain[MH_MAKEUP_MAX%64].MHData;
					mhbits1 = MH_EC_BlackTableMain[MH_MAKEUP_MAX/64+63].BitLength;
					mhbits2 = MH_EC_BlackTableMain[MH_MAKEUP_MAX%64].BitLength;
				}
				if (MemWrite(point->Wp, mhbits1, mhdata1) == RX_MEM_OVER) {  /* 最初のMH符号データを求める */
					return(RX_MEM_OVER);
				}
				if (rl == 0) {
					if (MemWrite(point->Wp, mhbits2, mhdata2) == RX_MEM_OVER) {  /* 最後のMH符号データをターミネイティングテーブルで求める */
						return(RX_MEM_OVER);
					}
					return(OK);
				}
			}while (rl >= MH_MAKEUP_MAX);
		}
		else {/*	ここにきたらNG By Y.Suzuki 1997/01/30	*/
			SCD_DBG_ENC_RLSIZE = 2;
			break;
		}
	}	/* while (1) */
}