src/Emu/Utility/System/Memory/MemoryUtility.cpp

説明を見る。
00001 // 
00002 // Copyright (c) 2005-2008 Kenichi Watanabe.
00003 // Copyright (c) 2005-2008 Yasuhiro Watari.
00004 // Copyright (c) 2005-2008 Hironori Ichibayashi.
00005 // Copyright (c) 2008-2009 Kazuo Horio.
00006 // Copyright (c) 2009-2013 Naruki Kurata.
00007 // Copyright (c) 2005-2013 Ryota Shioya.
00008 // Copyright (c) 2005-2013 Masahiro Goshima.
00009 // 
00010 // This software is provided 'as-is', without any express or implied
00011 // warranty. In no event will the authors be held liable for any damages
00012 // arising from the use of this software.
00013 // 
00014 // Permission is granted to anyone to use this software for any purpose,
00015 // including commercial applications, and to alter it and redistribute it
00016 // freely, subject to the following restrictions:
00017 // 
00018 // 1. The origin of this software must not be misrepresented; you must not
00019 // claim that you wrote the original software. If you use this software
00020 // in a product, an acknowledgment in the product documentation would be
00021 // appreciated but is not required.
00022 // 
00023 // 2. Altered source versions must be plainly marked as such, and must not be
00024 // misrepresented as being the original software.
00025 // 
00026 // 3. This notice may not be removed or altered from any source
00027 // distribution.
00028 // 
00029 // 
00030 
00031 
00032 #include <pch.h>
00033 #include "Emu/Utility/System/Memory/MemoryUtility.h"
00034 #include "SysDeps/Endian.h"
00035 
00036 using namespace std;
00037 using namespace Onikiri;
00038 using namespace EmulatorUtility;
00039 
00040 // Utility
00041 u64 Onikiri::EmulatorUtility::TargetStrlen(MemorySystem* mem, u64 targetAddr)
00042 {
00043 #if 0
00044     
00045     BlockArray blocks;
00046     // MapUnitSize oCgstrlensDD
00047     SplitAtMapUnitBoundary(targetAddr, m_addrConv.GetMapUnitSize(), back_inserter(blocks) );
00048 
00049     u64 result = 0;
00050     for (BlockArray::iterator e = blocks.begin(); e != blocks.end(); ++e) {
00051         char* p = static_cast<char*>(m_addrConv.TargetToHost(e->addr));
00052         for (int i = 0; i < (int)e->size; i ++, p ++) {
00053             if (*p == '\0')
00054                 return result;
00055             else
00056                 result ++;
00057         }
00058     }
00059 
00060     // MapUnitSizeoCgCMapUnitSizeoCgstrlens
00061     return result + TargetStrlen(targetAddr+m_addrConv.GetMapUnitSize());;
00062 #else
00063     u64 length = 0;
00064     while(true){
00065         EmuMemAccess access( targetAddr + length, 1, false );
00066         mem->ReadMemory( &access );
00067         if( access.value == '\0' ){
00068             break;
00069         }
00070         length++;
00071     };
00072 
00073     return length;
00074 #endif
00075 }
00076 
00077 // Get c string data from the targetAddr.
00078 std::string Onikiri::EmulatorUtility::StrCpyToHost(MemorySystem* mem, u64 targetAddr) 
00079 {
00080     std::string strData;
00081     u64 strAddr = targetAddr;
00082     while(true){
00083         EmuMemAccess access( strAddr, 1, false );
00084         mem->ReadMemory( &access );
00085         if( access.value == '\0' ){
00086             break;
00087         }
00088         strData += (char)access.value;
00089         strAddr++;
00090     };
00091 
00092     return strData;
00093 }
00094 
00095 
00096 
00097 // TargetBuffer
00098 TargetBuffer::TargetBuffer(MemorySystem* memory, u64 targetAddr, size_t bufSize, bool readOnly)
00099     : m_memory(memory), m_targetAddr(targetAddr), m_bufSize(bufSize), m_readOnly(readOnly)
00100 {
00101     // hostARs[
00102     m_buf = new u8[bufSize];
00103     m_memory->MemCopyToHost(m_buf, m_targetAddr, m_bufSize);
00104 }
00105 
00106 TargetBuffer::~TargetBuffer()
00107 {
00108     // 
00109     if (!m_readOnly)
00110         m_memory->MemCopyToTarget(m_targetAddr, m_buf, m_bufSize);
00111     delete[] m_buf;
00112 }
00113 
00114 void* TargetBuffer::Get()
00115 {
00116     return m_buf;
00117 }
00118 
00119 const void* TargetBuffer::Get() const
00120 {
00121     return m_buf;
00122 }
00123 

Onikiri2に対してTue Jun 18 14:34:20 2013に生成されました。  doxygen 1.4.7