Code cleanups, warning fixes
[dolphin.git] / Source / Core / Core / Src / Debugger / Dump.cpp
blob52685f867664276331b3338655dc149959539593
1 // Copyright (C) 2003 Dolphin Project.
3 // This program is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, version 2.0.
7 // This program is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 // GNU General Public License 2.0 for more details.
12 // A copy of the GPL 2.0 should have been included with the program.
13 // If not, see http://www.gnu.org/licenses/
15 // Official SVN repository and contact information can be found at
16 // http://code.google.com/p/dolphin-emu/
17 #include <stdio.h>
19 #include "Common.h"
20 #include "Dump.h"
22 CDump::CDump(const char* _szFilename) :
23 m_pData(NULL),
24 m_bInit(false)
26 FILE* pStream = fopen(_szFilename, "rb");
27 if (pStream != NULL)
29 fseek(pStream, 0, SEEK_END);
30 m_size = (size_t) ftell(pStream);
31 fseek(pStream, 0, SEEK_SET);
33 m_pData = new u8[m_size];
35 fread(m_pData, m_size, 1, pStream);
37 fclose(pStream);
41 CDump::~CDump(void)
43 if (m_pData != NULL)
45 delete[] m_pData;
46 m_pData = NULL;
50 int
51 CDump::GetNumberOfSteps(void)
53 return (int)(m_size / STRUCTUR_SIZE);
56 u32
57 CDump::GetGPR(int _step, int _gpr)
59 u32 offset = _step * STRUCTUR_SIZE;
61 if (offset >= m_size)
62 return -1;
64 return Read32(offset + OFFSET_GPR + (_gpr * 4));
67 u32
68 CDump::GetPC(int _step)
70 u32 offset = _step * STRUCTUR_SIZE;
72 if (offset >= m_size)
73 return -1;
75 return Read32(offset + OFFSET_PC);
78 u32
79 CDump::Read32(u32 _pos)
81 u32 result = (m_pData[_pos+0] << 24) |
82 (m_pData[_pos+1] << 16) |
83 (m_pData[_pos+2] << 8) |
84 (m_pData[_pos+3] << 0);
86 return result;