aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStapleButter <thetotalworm@gmail.com>2018-12-11 19:10:57 +0100
committerStapleButter <thetotalworm@gmail.com>2018-12-11 19:10:57 +0100
commit0579a1cd2e63fe882aed1ac9562a82308cbd1c56 (patch)
tree5bb091b1e14e36889a096fa8e9d7d7a8c5255292
parent4aafdee14d67c0f0732a72442b90c69c599ee667 (diff)
add CRC32 shit
-rw-r--r--CMakeLists.txt1
-rw-r--r--melonDS.cbp2
-rw-r--r--src/CRC32.cpp67
-rw-r--r--src/CRC32.h26
4 files changed, 96 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 7c08b57..132bf5b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -17,6 +17,7 @@ SET(SOURCES
src/ARMInterpreter_LoadStore.cpp
src/Config.cpp
src/CP15.cpp
+ src/CRC32.cpp
src/DMA.cpp
src/GPU.cpp
src/GPU2D.cpp
diff --git a/melonDS.cbp b/melonDS.cbp
index e0bf873..a93b225 100644
--- a/melonDS.cbp
+++ b/melonDS.cbp
@@ -113,6 +113,8 @@
<Unit filename="src/ARMInterpreter_LoadStore.h" />
<Unit filename="src/ARM_InstrTable.h" />
<Unit filename="src/CP15.cpp" />
+ <Unit filename="src/CRC32.cpp" />
+ <Unit filename="src/CRC32.h" />
<Unit filename="src/Config.cpp" />
<Unit filename="src/Config.h" />
<Unit filename="src/DMA.cpp" />
diff --git a/src/CRC32.cpp b/src/CRC32.cpp
new file mode 100644
index 0000000..aa31fb6
--- /dev/null
+++ b/src/CRC32.cpp
@@ -0,0 +1,67 @@
+/*
+ Copyright 2016-2019 StapleButter
+
+ This file is part of melonDS.
+
+ melonDS is free software: you can redistribute it and/or modify it under
+ the terms of the GNU General Public License as published by the Free
+ Software Foundation, either version 3 of the License, or (at your option)
+ any later version.
+
+ melonDS is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with melonDS. If not, see http://www.gnu.org/licenses/.
+*/
+
+#include "CRC32.h"
+
+u32 crctable[256];
+bool tableinited = false;
+
+u32 _reflect(u32 refl, char ch)
+{
+ u32 value = 0;
+
+ for(int i = 1; i < (ch + 1); i++)
+ {
+ if (refl & 1)
+ value |= 1 << (ch - i);
+ refl >>= 1;
+ }
+
+ return value;
+}
+
+void inittable()
+{
+ u32 polynomial = 0x04C11DB7;
+
+ for (int i = 0; i < 0x100; i++)
+ {
+ crctable[i] = _reflect(i, 8) << 24;
+
+ for (int j = 0; j < 8; j++)
+ crctable[i] = (crctable[i] << 1) ^ (crctable[i] & (1 << 31) ? polynomial : 0);
+
+ crctable[i] = _reflect(crctable[i], 32);
+ }
+}
+
+u32 CRC32(u8 *data, int len)
+{
+ if (!tableinited)
+ {
+ _inittable();
+ tableinited = true;
+ }
+
+ u32 crc = 0xFFFFFFFF;
+
+ while (len--)
+ crc = (crc >> 8) ^ crctable[(crc & 0xFF) ^ *data++];
+
+ return (crc ^ 0xFFFFFFFF);
+}
diff --git a/src/CRC32.h b/src/CRC32.h
new file mode 100644
index 0000000..639a8a3
--- /dev/null
+++ b/src/CRC32.h
@@ -0,0 +1,26 @@
+/*
+ Copyright 2016-2019 StapleButter
+
+ This file is part of melonDS.
+
+ melonDS is free software: you can redistribute it and/or modify it under
+ the terms of the GNU General Public License as published by the Free
+ Software Foundation, either version 3 of the License, or (at your option)
+ any later version.
+
+ melonDS is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with melonDS. If not, see http://www.gnu.org/licenses/.
+*/
+
+#ifndef CRC32_H
+#define CRC32_H
+
+#include "types.h"
+
+u32 CRC32(u8* data, int len);
+
+#endif // CRC32_H