Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/psx/octoshock/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 "octoshock.h"
39
#include <ctype.h>
40
#include <errno.h>
41
#include <fcntl.h>
42
#include <math.h>
43
#include <sys/types.h>
44
#include <sys/stat.h>
45
#include <stdarg.h>
46
#include <stddef.h>
47
#include <stdio.h>
48
#include <stdlib.h>
49
#include <string.h>
50
51
/***
52
*** dvdisaster.c
53
***/
54
55
void PrepareDeadSector(void);
56
57
void CreateEcc(void);
58
void FixEcc(void);
59
void Verify(void);
60
61
uint32 EDCCrc32(const unsigned char*, int);
62
63
/***
64
*** galois.c
65
***
66
* This is currently the hardcoded GF(2**8).
67
* int32 gives abundant space for the GF.
68
* Squeezing it down to uint8 won't probably gain much,
69
* so we implement this defensively here.
70
*
71
* Note that some performance critical stuff needs to
72
* be #included from galois-inlines.h
73
*/
74
75
/* Galois field parameters for 8bit symbol Reed-Solomon code */
76
77
#define GF_SYMBOLSIZE 8
78
#define GF_FIELDSIZE (1<<GF_SYMBOLSIZE)
79
#define GF_FIELDMAX (GF_FIELDSIZE-1)
80
#define GF_ALPHA0 GF_FIELDMAX
81
82
/* Lookup tables for Galois field arithmetic */
83
84
typedef struct _GaloisTables
85
{ int32 gfGenerator; /* GF generator polynomial */
86
int32 *indexOf; /* log */
87
int32 *alphaTo; /* inverse log */
88
int32 *encAlphaTo; /* inverse log optimized for encoder */
89
} GaloisTables;
90
91
/* Lookup and working tables for the ReedSolomon codecs */
92
93
typedef struct _ReedSolomonTables
94
{ GaloisTables *gfTables;/* from above */
95
int32 *gpoly; /* RS code generator polynomial */
96
int32 fcr; /* first consecutive root of RS generator polynomial */
97
int32 primElem; /* primitive field element */
98
int32 nroots; /* degree of RS generator polynomial */
99
int32 ndata; /* data bytes per ecc block */
100
} ReedSolomonTables;
101
102
GaloisTables* CreateGaloisTables(int32);
103
void FreeGaloisTables(GaloisTables*);
104
105
ReedSolomonTables *CreateReedSolomonTables(GaloisTables*, int32, int32, int);
106
void FreeReedSolomonTables(ReedSolomonTables*);
107
108
/***
109
*** l-ec.c
110
***/
111
112
#define N_P_VECTORS 86 /* 43 16bit p vectors */
113
#define P_VECTOR_SIZE 26 /* using RS(26,24) ECC */
114
115
#define N_Q_VECTORS 52 /* 26 16bit q vectors */
116
#define Q_VECTOR_SIZE 45 /* using RS(45,43) ECC */
117
118
#define P_PADDING 229 /* padding values for */
119
#define Q_PADDING 210 /* shortened RS code */
120
121
int PToByteIndex(int, int);
122
int QToByteIndex(int, int);
123
void ByteIndexToP(int, int*, int*);
124
void ByteIndexToQ(int, int*, int*);
125
126
void GetPVector(unsigned char*, unsigned char*, int);
127
void SetPVector(unsigned char*, unsigned char*, int);
128
void FillPVector(unsigned char*, unsigned char, int);
129
void AndPVector(unsigned char*, unsigned char, int);
130
void OrPVector(unsigned char*, unsigned char, int);
131
132
void GetQVector(unsigned char*, unsigned char*, int);
133
void SetQVector(unsigned char*, unsigned char*, int);
134
void FillQVector(unsigned char*, unsigned char, int);
135
void AndQVector(unsigned char*, unsigned char, int);
136
void OrQVector(unsigned char*, unsigned char, int);
137
138
int DecodePQ(ReedSolomonTables*, unsigned char*, int, int*, int);
139
140
int CountC2Errors(unsigned char*);
141
142
/***
143
*** misc.c
144
***/
145
146
char* sgettext(char*);
147
char* sgettext_utf8(char*);
148
149
int64 uchar_to_int64(unsigned char*);
150
void int64_to_uchar(unsigned char*, int64);
151
152
void CalcSectors(int64, int64*, int*);
153
154
/***
155
*** recover-raw.c
156
***/
157
158
#define CD_RAW_SECTOR_SIZE 2352
159
#define CD_RAW_C2_SECTOR_SIZE (2352+294) /* main channel plus C2 vector */
160
161
int CheckEDC(const unsigned char*, bool);
162
int CheckMSF(unsigned char*, int);
163
164
165
int ValidateRawSector(unsigned char *frame, bool xaMode);
166
bool Init_LEC_Correct(void);
167
void Kill_LEC_Correct(void);
168
169
170
#endif /* DVDISASTER_H */
171
172