3#ifdef VIDEO_STANDARD_PAL
13int main(
int argc,
char **argv);
34 static void Create() {
35 sStart = std::make_unique<const unsigned char *>();
36 sEnd = std::make_unique<const unsigned char *>();
37 sExpected = std::make_unique<int>();
38 sCursor = std::make_unique<const unsigned char *>();
39 sCrc = std::make_unique<unsigned int>();
43 static void Destroy() {
60 const int nOffset = pXs->
FindArray(
"offset",
false)->
Int(1);
64 const auto *pStart =
reinterpret_cast<const unsigned char *
>(&main) + (nOffset - nMain);
66 *sEnd = pStart + nSize;
68 if (sTableBuilt == 0) {
75 const unsigned char *pCursor = *sCursor;
76 const unsigned char *pLimit = pCursor + kBytesPerPoll;
77 const unsigned char *pStop = *sEnd < pLimit ? *sEnd : pLimit;
78 unsigned int crc = *sCrc;
79 for (
int nLeft = pStop - pCursor; nLeft-- != 0;) {
80 crc = sTable[(crc ^ *pCursor++) & kByteMask] ^ (crc >> kBitsPerByte);
84 if (pCursor != *sEnd) {
87 if (~crc !=
static_cast<unsigned int>(*sExpected)) {
88 sceSifCallRpc(ezNetCtlGetClient(),
89 EZ_NETCTL_FUNCTION_SET_NET_CHECKED,
104 static std::unique_ptr<const unsigned char *> sStart;
107 static std::unique_ptr<const unsigned char *> sEnd;
110 static std::unique_ptr<const unsigned char *> sCursor;
113 static std::unique_ptr<unsigned int> sCrc;
116 static std::unique_ptr<int> sExpected;
119 static std::unique_ptr<unsigned int[]> sTable;
122 static int sTableBuilt;
124 static constexpr int kTableSize = 256;
125 static constexpr unsigned int kPolynomial = 0x04c11db7;
126 static constexpr unsigned int kTopBit = 0x80000000;
127 static constexpr unsigned int kCrcInitial = 0xffffffff;
128 static constexpr unsigned int kByteMask = 0xff;
129 static constexpr int kBitsPerByte = 8;
130 static constexpr int kBitsPerWord = 32;
131 static constexpr int kBytesPerPoll = 0x100000;
134 static unsigned int Reflect(
unsigned int value,
int nBits) {
135 unsigned int reflected = 0;
136 for (
int bit = 1; bit < nBits + 1; ++bit) {
137 if ((value & 1) != 0) {
138 reflected |= 1 << (nBits - bit);
146 static void BuildTable() {
147 sTable = std::make_unique<unsigned int[]>(kTableSize);
148 for (
int i = 0; i < kTableSize; ++i) {
149 sTable[i] = Reflect(i, kBitsPerByte) << (kBitsPerWord - kBitsPerByte);
150 for (
int bit = 0; bit < kBitsPerByte; ++bit) {
152 (sTable[i] & kTopBit) != 0 ? (sTable[i] << 1) ^ kPolynomial : sTable[i] << 1;
154 sTable[i] = Reflect(sTable[i], kBitsPerWord);
int Int(int nIndex) const
Report a node as an integer.
DataArray * FindArray(const char *pszTag, bool bFail) const
Find the child array whose first node is a tag.
DataArray * SystemConfig()
Report the configuration SystemInit() read.