plptools
Loading...
Searching...
No Matches
sistypes.cpp
Go to the documentation of this file.
1/*
2 * This file is part of plptools.
3 *
4 * Copyright (C) 2002 Daniel Brahneborg <basic.chello@se>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * along with this program; if not, see <https://www.gnu.org/licenses/>.
18 */
19#include "config.h"
20
21#include "sistypes.h"
22
23static unsigned int s_crcTable[256];
24
25int logLevel = 0;
26
28 const unsigned int polynomial = 0x1021;
29 unsigned int index;
30 s_crcTable[0] = 0;
31 for (index = 0; index < 128; index++) {
32 unsigned int carry = s_crcTable[index] & 0x8000;
33 unsigned int temp = (s_crcTable[index] << 1) & 0xffff;
34 s_crcTable[index * 2 + (carry ? 0 : 1)] = temp ^ polynomial;
35 s_crcTable[index * 2 + (carry ? 1 : 0)] = temp;
36 }
37}
38
39uint16_t updateCrc(uint16_t crc, uint8_t value) {
40 return (crc << 8) ^ s_crcTable[((crc >> 8) ^ value) & 0xff];
41}
42
43uint16_t calcCRC(uint8_t* data, int len) {
44 uint16_t crc = 0;
45 for (int i = 0; i < len; ++i) {
46 uint8_t value = data[i];
47 crc = (crc << 8) ^ s_crcTable[((crc >> 8) ^ value) & 0xff];
48 }
49 return crc;
50}
51
52uint16_t read16(uint8_t* p) {
53 return p[0] | (p[1] << 8);
54}
55
56uint32_t read32(uint8_t* p) {
57 return p[0] | (p[1] << 8) | (p[2] << 16) | (p[3] << 24);
58}
59
60void write16(uint8_t* p, int val) {
61 p[0] = val & 255;
62 p[1] = (val >> 8) & 255;
63}
64
66 { 0, "", "Test" },
67 { 1, "EN", "UK English" },
68 { 2, "FR", "French" },
69 { 3, "GE", "German" },
70 { 4, "SP", "Spanish" },
71 { 5, "IT", "Italian" },
72 { 6, "SW", "Swedish" },
73 { 7, "DA", "Danish" },
74 { 8, "NO", "Norwegian" },
75 { 9, "FI", "Finnish" },
76 { 10, "AM", "American English" },
77 { 11, "SF", "Swiss French" },
78 { 12, "SG", "Swiss German" },
79 { 13, "PO", "Portuguese" },
80 { 14, "TU", "Turkish" },
81 { 15, "IC", "Icelandic" },
82 { 16, "RU", "Russian" },
83 { 17, "HU", "Hungarian" },
84 { 18, "DU", "Dutch" },
85 { 19, "BL", "Belgian Flemish" },
86 { 20, "AU", "Australian English" },
87 { 21, "BG", "Belgian French" },
88 { 22, "AS", "Austrian German" },
89 { 23, "NZ", "New Zealand" },
90 { 24, "IF", "International French" },
91 { 25, "CS", "Czech" },
92 { 26, "SK", "Slovak" },
93 { 27, "PL", "Polish" },
94 { 28, "SL", "Slovenian" },
95 { 29, "TC", "Taiwan Chinese" },
96 { 30, "HK", "Hong Kong" },
97 { 31, "ZH", "PRC Chinese" },
98 { 32, "JA", "Japanese" },
99 { 33, "TH", "Thai" },
100};
static unsigned int s_crcTable[256]
Definition: sistypes.cpp:23
void createCRCTable()
Definition: sistypes.cpp:27
uint16_t calcCRC(uint8_t *data, int len)
Definition: sistypes.cpp:43
uint16_t updateCrc(uint16_t crc, uint8_t value)
Definition: sistypes.cpp:39
LangTableEntry langTable[]
Definition: sistypes.cpp:65
uint32_t read32(uint8_t *p)
Definition: sistypes.cpp:56
void write16(uint8_t *p, int val)
Definition: sistypes.cpp:60
int logLevel
Definition: sistypes.cpp:25
uint16_t read16(uint8_t *p)
Definition: sistypes.cpp:52
Holder of a language entry, translating from language numbers to names.
Definition: sistypes.h:56