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{
29 const unsigned int polynomial = 0x1021;
30 unsigned int index;
31 s_crcTable[0] = 0;
32 for (index = 0; index < 128; index++)
33 {
34 unsigned int carry = s_crcTable[index] & 0x8000;
35 unsigned int temp = (s_crcTable[index] << 1) & 0xffff;
36 s_crcTable[index * 2 + (carry ? 0 : 1)] = temp ^ polynomial;
37 s_crcTable[index * 2 + (carry ? 1 : 0)] = temp;
38 }
39}
40
41uint16_t updateCrc(uint16_t crc, uint8_t value)
42{
43 return (crc << 8) ^ s_crcTable[((crc >> 8) ^ value) & 0xff];
44}
45
46uint16_t calcCRC(uint8_t* data, int len)
47{
48 uint16_t crc = 0;
49 for (int i = 0; i < len; ++i)
50 {
51 uint8_t value = data[i];
52 crc = (crc << 8) ^ s_crcTable[((crc >> 8) ^ value) & 0xff];
53 }
54 return crc;
55}
56
57uint16_t read16(uint8_t* p)
58{
59 return p[0] | (p[1] << 8);
60}
61
62uint32_t read32(uint8_t* p)
63{
64 return p[0] | (p[1] << 8) | (p[2] << 16) | (p[3] << 24);
65}
66
67void write16(uint8_t* p, int val)
68{
69 p[0] = val & 255;
70 p[1] = (val >> 8) & 255;
71}
72
74{
75 { 0, "", "Test" },
76 { 1, "EN", "UK English" },
77 { 2, "FR", "French" },
78 { 3, "GE", "German" },
79 { 4, "SP", "Spanish" },
80 { 5, "IT", "Italian" },
81 { 6, "SW", "Swedish" },
82 { 7, "DA", "Danish" },
83 { 8, "NO", "Norwegian" },
84 { 9, "FI", "Finnish" },
85 { 10, "AM", "American English" },
86 { 11, "SF", "Swiss French" },
87 { 12, "SG", "Swiss German" },
88 { 13, "PO", "Portuguese" },
89 { 14, "TU", "Turkish" },
90 { 15, "IC", "Icelandic" },
91 { 16, "RU", "Russian" },
92 { 17, "HU", "Hungarian" },
93 { 18, "DU", "Dutch" },
94 { 19, "BL", "Belgian Flemish" },
95 { 20, "AU", "Australian English" },
96 { 21, "BG", "Belgian French" },
97 { 22, "AS", "Austrian German" },
98 { 23, "NZ", "New Zealand" },
99 { 24, "IF", "International French" },
100 { 25, "CS", "Czech" },
101 { 26, "SK", "Slovak" },
102 { 27, "PL", "Polish" },
103 { 28, "SL", "Slovenian" },
104 { 29, "TC", "Taiwan Chinese" },
105 { 30, "HK", "Hong Kong" },
106 { 31, "ZH", "PRC Chinese" },
107 { 32, "JA", "Japanese" },
108 { 33, "TH", "Thai" },
109};
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:46
uint16_t updateCrc(uint16_t crc, uint8_t value)
Definition: sistypes.cpp:41
LangTableEntry langTable[]
Definition: sistypes.cpp:73
uint32_t read32(uint8_t *p)
Definition: sistypes.cpp:62
void write16(uint8_t *p, int val)
Definition: sistypes.cpp:67
int logLevel
Definition: sistypes.cpp:25
uint16_t read16(uint8_t *p)
Definition: sistypes.cpp:57
Holder of a language entry, translating from language numbers to names.
Definition: sistypes.h:59