Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/ClusterM/famicom-dumper.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/crc.c
diff options
context:
space:
mode:
authorAlexey 'Cluster' Avdyukhin <clusterrr@clusterrr.com>2020-11-26 14:46:15 +0300
committerAlexey 'Cluster' Avdyukhin <clusterrr@clusterrr.com>2020-11-26 14:46:15 +0300
commite6278f825d1c8763fc5bc7b1e509c175f935878f (patch)
tree1c8bea627cf1566458442008ae60c25186e46ccb /crc.c
parent03128e8ef53bea42187f87c3846c368c56b02618 (diff)
Moved CRC tables to PGM space
Diffstat (limited to 'crc.c')
-rw-r--r--crc.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/crc.c b/crc.c
index 1588e41..1788b53 100644
--- a/crc.c
+++ b/crc.c
@@ -1,6 +1,7 @@
#include <inttypes.h>
+#include <avr/pgmspace.h>
-const uint8_t crc8_table[] = { 0, 94, 188, 226, 97, 63, 221, 131, 194, 156, 126, 32, 163, 253, 31, 65, 157, 195, 33, 127, 252, 162, 64, 30, 95, 1,
+uint8_t PROGMEM crc8_table[] = { 0, 94, 188, 226, 97, 63, 221, 131, 194, 156, 126, 32, 163, 253, 31, 65, 157, 195, 33, 127, 252, 162, 64, 30, 95, 1,
227, 189, 62, 96, 130, 220, 35, 125, 159, 193, 66, 28, 254, 160, 225, 191, 93, 3, 128, 222, 60, 98, 190, 224, 2, 92, 223, 129, 99, 61, 124, 34,
192, 158, 29, 67, 161, 255, 70, 24, 250, 164, 39, 121, 155, 197, 132, 218, 56, 102, 229, 187, 89, 7, 219, 133, 103, 57, 186, 228, 6, 88, 25, 71,
165, 251, 120, 38, 196, 154, 101, 59, 217, 135, 4, 90, 184, 230, 167, 249, 27, 69, 198, 152, 122, 36, 248, 166, 68, 26, 153, 199, 37, 123, 58,
@@ -10,7 +11,7 @@ const uint8_t crc8_table[] = { 0, 94, 188, 226, 97, 63, 221, 131, 194, 156, 126,
212, 149, 203, 41, 119, 244, 170, 72, 22, 233, 183, 85, 11, 136, 214, 52, 106, 43, 117, 151, 201, 74, 20, 246, 168, 116, 42, 200, 150, 21, 75,
169, 247, 182, 232, 10, 84, 215, 137, 107, 53 };
-const uint16_t crc16_table[] = { 0x0000, 0xC0C1, 0xC181, 0x0140, 0xC301, 0x03C0, 0x0280, 0xC241, 0xC601, 0x06C0, 0x0780, 0xC741, 0x0500, 0xC5C1,
+uint16_t PROGMEM crc16_table[] = { 0x0000, 0xC0C1, 0xC181, 0x0140, 0xC301, 0x03C0, 0x0280, 0xC241, 0xC601, 0x06C0, 0x0780, 0xC741, 0x0500, 0xC5C1,
0xC481, 0x0440, 0xCC01, 0x0CC0, 0x0D80, 0xCD41, 0x0F00, 0xCFC1, 0xCE81, 0x0E40, 0x0A00, 0xCAC1, 0xCB81, 0x0B40, 0xC901, 0x09C0, 0x0880, 0xC841,
0xD801, 0x18C0, 0x1980, 0xD941, 0x1B00, 0xDBC1, 0xDA81, 0x1A40, 0x1E00, 0xDEC1, 0xDF81, 0x1F40, 0xDD01, 0x1DC0, 0x1C80, 0xDC41, 0x1400, 0xD4C1,
0xD581, 0x1540, 0xD701, 0x17C0, 0x1680, 0xD641, 0xD201, 0x12C0, 0x1380, 0xD341, 0x1100, 0xD1C1, 0xD081, 0x1040, 0xF001, 0x30C0, 0x3180, 0xF141,
@@ -28,10 +29,10 @@ const uint16_t crc16_table[] = { 0x0000, 0xC0C1, 0xC181, 0x0140, 0xC301, 0x03C0,
uint8_t calc_crc8(uint8_t old_crc, uint8_t inbyte)
{
- return crc8_table[old_crc ^ inbyte];
+ return pgm_read_byte(&crc8_table[old_crc ^ inbyte]);
}
uint16_t calc_crc16(uint16_t old_crc, uint8_t inbyte)
{
- return (old_crc >> 8) ^ crc16_table[((old_crc ^ inbyte) & 0x00FF) & 0xFF];
+ return (old_crc >> 8) ^ pgm_read_word(&crc16_table[((old_crc ^ inbyte) & 0x00FF) & 0xFF]);
}