~ppsspp/ppsspp/ppsspp_1.3.0

« back to all changes in this revision

Viewing changes to ext/armips/Commands/CDirectiveArea.cpp

  • Committer: Sérgio Benjamim
  • Date: 2017-01-02 00:12:05 UTC
  • Revision ID: sergio_br2@yahoo.com.br-20170102001205-cxbta9za203nmjwm
1.3.0 source (from ppsspp_1.3.0-r160.p5.l1762.a165.t83~56~ubuntu16.04.1.tar.xz).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "stdafx.h"
 
2
#include "Commands/CDirectiveArea.h"
 
3
#include "Core/Common.h"
 
4
#include "Core/FileManager.h"
 
5
#include <algorithm>
 
6
 
 
7
CDirectiveArea::CDirectiveArea(Expression& size)
 
8
{
 
9
        this->areaSize = 0;
 
10
        this->contentSize = 0;
 
11
        this->fillValue = 0;
 
12
 
 
13
        this->sizeExpression = size;
 
14
        this->content = nullptr;
 
15
}
 
16
 
 
17
CDirectiveArea::~CDirectiveArea()
 
18
{
 
19
        delete content;
 
20
}
 
21
 
 
22
void CDirectiveArea::setFillExpression(Expression& exp)
 
23
{
 
24
        fillExpression = exp;
 
25
}
 
26
 
 
27
bool CDirectiveArea::Validate()
 
28
{
 
29
        size_t oldAreaSize = areaSize;
 
30
        size_t oldContentSize = contentSize;
 
31
 
 
32
        position = g_fileManager->getVirtualAddress();
 
33
 
 
34
        if (sizeExpression.evaluateInteger(areaSize) == false)
 
35
        {
 
36
                Logger::queueError(Logger::Error,L"Invalid size expression");
 
37
                return false;
 
38
        }
 
39
 
 
40
        if (fillExpression.isLoaded())
 
41
        {
 
42
                if (fillExpression.evaluateInteger(fillValue) == false)
 
43
                {
 
44
                        Logger::queueError(Logger::Error,L"Invalid fill expression");
 
45
                        return false;
 
46
                }
 
47
        }
 
48
 
 
49
        content->applyFileInfo();
 
50
        bool result = content->Validate();
 
51
        contentSize = g_fileManager->getVirtualAddress()-position;
 
52
 
 
53
        // restore info of this command
 
54
        applyFileInfo();
 
55
 
 
56
        if (areaSize < contentSize)
 
57
        {
 
58
                Logger::queueError(Logger::Error,L"Area overflowed");
 
59
        }
 
60
 
 
61
        if (fillExpression.isLoaded())
 
62
                g_fileManager->advanceMemory(areaSize-contentSize);
 
63
 
 
64
        if (areaSize != oldAreaSize || contentSize != oldContentSize)
 
65
                result = true;
 
66
 
 
67
        return result;
 
68
}
 
69
 
 
70
void CDirectiveArea::Encode() const
 
71
{
 
72
        content->Encode();
 
73
 
 
74
        if (fillExpression.isLoaded())
 
75
        {
 
76
                unsigned char buffer[64];
 
77
                memset(buffer,fillValue,64);
 
78
                
 
79
                size_t writeSize = areaSize-contentSize;
 
80
                while (writeSize > 0)
 
81
                {
 
82
                        size_t part = std::min<size_t>(64,writeSize);
 
83
                        g_fileManager->write(buffer,part);
 
84
                        writeSize -= part;
 
85
                }
 
86
        }
 
87
}
 
88
 
 
89
void CDirectiveArea::writeTempData(TempData& tempData) const
 
90
{
 
91
        tempData.writeLine(position,formatString(L".area 0x%08X",areaSize));
 
92
        content->applyFileInfo();
 
93
        content->writeTempData(tempData);
 
94
 
 
95
        if (fillExpression.isLoaded())
 
96
        {
 
97
                std::wstring fillString = formatString(L".fill 0x%08X,0x%02X",areaSize-contentSize,fillValue);
 
98
                tempData.writeLine(position+contentSize,fillString);
 
99
                tempData.writeLine(position+areaSize,L".endarea");
 
100
        } else {
 
101
                tempData.writeLine(position+contentSize,L".endarea");
 
102
        }
 
103
}
 
104
 
 
105
void CDirectiveArea::writeSymData(SymbolData& symData) const
 
106
{
 
107
        content->writeSymData(symData);
 
108
 
 
109
        if (fillExpression.isLoaded())
 
110
                symData.addData(position+contentSize,areaSize-contentSize,SymbolData::Data8);
 
111
}