/* dvdisaster: Additional error correction for optical media.1* Copyright (C) 2004-2007 Carsten Gnoerlich.2* Project home page: http://www.dvdisaster.com3* Email: [email protected] -or- [email protected]4*5* This program is free software; you can redistribute it and/or modify6* it under the terms of the GNU General Public License as published by7* the Free Software Foundation; either version 2 of the License, or8* (at your option) any later version.9*10* This program is distributed in the hope that it will be useful,11* but WITHOUT ANY WARRANTY; without even the implied warranty of12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the13* GNU General Public License for more details.14*15* You should have received a copy of the GNU General Public License16* along with this program; if not, write to the Free Software17* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA,18* or direct your browser at http://www.gnu.org.19*/2021#ifndef DVDISASTER_H22#define DVDISASTER_H2324/* "Dare to be gorgeous and unique.25* But don't ever be cryptic or otherwise unfathomable.26* Make it unforgettably great."27*28* From "A Final Note on Style",29* Amiga Intuition Reference Manual, 1986, p. 23130*/3132/***33*** I'm too lazy to mess with #include dependencies.34*** Everything #includeable is rolled up herein...35*/3637//#include "../types.h"38#include "emuware/emuware.h"3940#include <ctype.h>41#include <errno.h>42#include <fcntl.h>43#include <math.h>44#include <sys/types.h>45#include <sys/stat.h>46#include <stdarg.h>47#include <stddef.h>48#include <stdio.h>49#include <stdlib.h>50#include <string.h>51//#include <unistd.h>5253/***54*** dvdisaster.c55***/5657void PrepareDeadSector(void);5859void CreateEcc(void);60void FixEcc(void);61void Verify(void);6263uint32 EDCCrc32(const unsigned char*, int);6465/***66*** galois.c67***68* This is currently the hardcoded GF(2**8).69* int32 gives abundant space for the GF.70* Squeezing it down to uint8 won't probably gain much,71* so we implement this defensively here.72*73* Note that some performance critical stuff needs to74* be #included from galois-inlines.h75*/7677/* Galois field parameters for 8bit symbol Reed-Solomon code */7879#define GF_SYMBOLSIZE 880#define GF_FIELDSIZE (1<<GF_SYMBOLSIZE)81#define GF_FIELDMAX (GF_FIELDSIZE-1)82#define GF_ALPHA0 GF_FIELDMAX8384/* Lookup tables for Galois field arithmetic */8586typedef struct _GaloisTables87{ int32 gfGenerator; /* GF generator polynomial */88int32 *indexOf; /* log */89int32 *alphaTo; /* inverse log */90int32 *encAlphaTo; /* inverse log optimized for encoder */91} GaloisTables;9293/* Lookup and working tables for the ReedSolomon codecs */9495typedef struct _ReedSolomonTables96{ GaloisTables *gfTables;/* from above */97int32 *gpoly; /* RS code generator polynomial */98int32 fcr; /* first consecutive root of RS generator polynomial */99int32 primElem; /* primitive field element */100int32 nroots; /* degree of RS generator polynomial */101int32 ndata; /* data bytes per ecc block */102} ReedSolomonTables;103104GaloisTables* CreateGaloisTables(int32);105void FreeGaloisTables(GaloisTables*);106107ReedSolomonTables *CreateReedSolomonTables(GaloisTables*, int32, int32, int);108void FreeReedSolomonTables(ReedSolomonTables*);109110/***111*** l-ec.c112***/113114#define N_P_VECTORS 86 /* 43 16bit p vectors */115#define P_VECTOR_SIZE 26 /* using RS(26,24) ECC */116117#define N_Q_VECTORS 52 /* 26 16bit q vectors */118#define Q_VECTOR_SIZE 45 /* using RS(45,43) ECC */119120#define P_PADDING 229 /* padding values for */121#define Q_PADDING 210 /* shortened RS code */122123int PToByteIndex(int, int);124int QToByteIndex(int, int);125void ByteIndexToP(int, int*, int*);126void ByteIndexToQ(int, int*, int*);127128void GetPVector(unsigned char*, unsigned char*, int);129void SetPVector(unsigned char*, unsigned char*, int);130void FillPVector(unsigned char*, unsigned char, int);131void AndPVector(unsigned char*, unsigned char, int);132void OrPVector(unsigned char*, unsigned char, int);133134void GetQVector(unsigned char*, unsigned char*, int);135void SetQVector(unsigned char*, unsigned char*, int);136void FillQVector(unsigned char*, unsigned char, int);137void AndQVector(unsigned char*, unsigned char, int);138void OrQVector(unsigned char*, unsigned char, int);139140int DecodePQ(ReedSolomonTables*, unsigned char*, int, int*, int);141142int CountC2Errors(unsigned char*);143144/***145*** misc.c146***/147148char* sgettext(char*);149char* sgettext_utf8(char*);150151int64 uchar_to_int64(unsigned char*);152void int64_to_uchar(unsigned char*, int64);153154void CalcSectors(int64, int64*, int*);155156/***157*** recover-raw.c158***/159160#define CD_RAW_SECTOR_SIZE 2352161#define CD_RAW_C2_SECTOR_SIZE (2352+294) /* main channel plus C2 vector */162163int CheckEDC(const unsigned char*, bool);164int CheckMSF(unsigned char*, int);165166167int ValidateRawSector(unsigned char *frame, bool xaMode);168bool Init_LEC_Correct(void);169void Kill_LEC_Correct(void);170171172#endif /* DVDISASTER_H */173174175