Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/psx/mednadisc/cdrom/dvdisaster.h
2 views
1
/* dvdisaster: Additional error correction for optical media.
2
* Copyright (C) 2004-2007 Carsten Gnoerlich.
3
* Project home page: http://www.dvdisaster.com
4
* Email: [email protected] -or- [email protected]
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
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA,
19
* or direct your browser at http://www.gnu.org.
20
*/
21
22
#ifndef DVDISASTER_H
23
#define DVDISASTER_H
24
25
/* "Dare to be gorgeous and unique.
26
* But don't ever be cryptic or otherwise unfathomable.
27
* Make it unforgettably great."
28
*
29
* From "A Final Note on Style",
30
* Amiga Intuition Reference Manual, 1986, p. 231
31
*/
32
33
/***
34
*** I'm too lazy to mess with #include dependencies.
35
*** Everything #includeable is rolled up herein...
36
*/
37
38
//#include "../types.h"
39
#include "emuware/emuware.h"
40
41
#include <ctype.h>
42
#include <errno.h>
43
#include <fcntl.h>
44
#include <math.h>
45
#include <sys/types.h>
46
#include <sys/stat.h>
47
#include <stdarg.h>
48
#include <stddef.h>
49
#include <stdio.h>
50
#include <stdlib.h>
51
#include <string.h>
52
//#include <unistd.h>
53
54
/***
55
*** dvdisaster.c
56
***/
57
58
void PrepareDeadSector(void);
59
60
void CreateEcc(void);
61
void FixEcc(void);
62
void Verify(void);
63
64
uint32 EDCCrc32(const unsigned char*, int);
65
66
/***
67
*** galois.c
68
***
69
* This is currently the hardcoded GF(2**8).
70
* int32 gives abundant space for the GF.
71
* Squeezing it down to uint8 won't probably gain much,
72
* so we implement this defensively here.
73
*
74
* Note that some performance critical stuff needs to
75
* be #included from galois-inlines.h
76
*/
77
78
/* Galois field parameters for 8bit symbol Reed-Solomon code */
79
80
#define GF_SYMBOLSIZE 8
81
#define GF_FIELDSIZE (1<<GF_SYMBOLSIZE)
82
#define GF_FIELDMAX (GF_FIELDSIZE-1)
83
#define GF_ALPHA0 GF_FIELDMAX
84
85
/* Lookup tables for Galois field arithmetic */
86
87
typedef struct _GaloisTables
88
{ int32 gfGenerator; /* GF generator polynomial */
89
int32 *indexOf; /* log */
90
int32 *alphaTo; /* inverse log */
91
int32 *encAlphaTo; /* inverse log optimized for encoder */
92
} GaloisTables;
93
94
/* Lookup and working tables for the ReedSolomon codecs */
95
96
typedef struct _ReedSolomonTables
97
{ GaloisTables *gfTables;/* from above */
98
int32 *gpoly; /* RS code generator polynomial */
99
int32 fcr; /* first consecutive root of RS generator polynomial */
100
int32 primElem; /* primitive field element */
101
int32 nroots; /* degree of RS generator polynomial */
102
int32 ndata; /* data bytes per ecc block */
103
} ReedSolomonTables;
104
105
GaloisTables* CreateGaloisTables(int32);
106
void FreeGaloisTables(GaloisTables*);
107
108
ReedSolomonTables *CreateReedSolomonTables(GaloisTables*, int32, int32, int);
109
void FreeReedSolomonTables(ReedSolomonTables*);
110
111
/***
112
*** l-ec.c
113
***/
114
115
#define N_P_VECTORS 86 /* 43 16bit p vectors */
116
#define P_VECTOR_SIZE 26 /* using RS(26,24) ECC */
117
118
#define N_Q_VECTORS 52 /* 26 16bit q vectors */
119
#define Q_VECTOR_SIZE 45 /* using RS(45,43) ECC */
120
121
#define P_PADDING 229 /* padding values for */
122
#define Q_PADDING 210 /* shortened RS code */
123
124
int PToByteIndex(int, int);
125
int QToByteIndex(int, int);
126
void ByteIndexToP(int, int*, int*);
127
void ByteIndexToQ(int, int*, int*);
128
129
void GetPVector(unsigned char*, unsigned char*, int);
130
void SetPVector(unsigned char*, unsigned char*, int);
131
void FillPVector(unsigned char*, unsigned char, int);
132
void AndPVector(unsigned char*, unsigned char, int);
133
void OrPVector(unsigned char*, unsigned char, int);
134
135
void GetQVector(unsigned char*, unsigned char*, int);
136
void SetQVector(unsigned char*, unsigned char*, int);
137
void FillQVector(unsigned char*, unsigned char, int);
138
void AndQVector(unsigned char*, unsigned char, int);
139
void OrQVector(unsigned char*, unsigned char, int);
140
141
int DecodePQ(ReedSolomonTables*, unsigned char*, int, int*, int);
142
143
int CountC2Errors(unsigned char*);
144
145
/***
146
*** misc.c
147
***/
148
149
char* sgettext(char*);
150
char* sgettext_utf8(char*);
151
152
int64 uchar_to_int64(unsigned char*);
153
void int64_to_uchar(unsigned char*, int64);
154
155
void CalcSectors(int64, int64*, int*);
156
157
/***
158
*** recover-raw.c
159
***/
160
161
#define CD_RAW_SECTOR_SIZE 2352
162
#define CD_RAW_C2_SECTOR_SIZE (2352+294) /* main channel plus C2 vector */
163
164
int CheckEDC(const unsigned char*, bool);
165
int CheckMSF(unsigned char*, int);
166
167
168
int ValidateRawSector(unsigned char *frame, bool xaMode);
169
bool Init_LEC_Correct(void);
170
void Kill_LEC_Correct(void);
171
172
173
#endif /* DVDISASTER_H */
174
175