diff options
author | Pixel <Pixel> | 2002-09-27 12:17:57 +0000 |
---|---|---|
committer | Pixel <Pixel> | 2002-09-27 12:17:57 +0000 |
commit | bfa5de7eccf4604ff8217f619e9685a09e80d545 (patch) | |
tree | a5be5de750ac611145f459a09bda902c3dbc1a70 | |
parent | 60c1003845035ad4cd0e9ea50862bad7626faf0e (diff) |
The week-without-the-network changes
42 files changed, 712 insertions, 1171 deletions
diff --git a/MegamanX5/Makefile b/MegamanX5/Makefile index 74bec9e..831126c 100755 --- a/MegamanX5/Makefile +++ b/MegamanX5/Makefile @@ -2,12 +2,14 @@ CPPFLAGS=-Wall -g -O3 -mcpu=i686 -pedantic -pedantic-errors -Werror -I../includes CXX=g++ +LIBS=-lz +LDFLAGS=${LIBS} TARGET = unarc all: ${TARGET} -unarc: unarc.o ../includes/fileutils.h ../includes/generic.h Makefile +unarc: unarc.o ../includes/generic.h Makefile ${CXX} ${LDFLAGS} unarc.o ../generic/generic.a -o unarc clean: diff --git a/MegamanX5/unarc.cpp b/MegamanX5/unarc.cpp index c9ab2be..38a6522 100644 --- a/MegamanX5/unarc.cpp +++ b/MegamanX5/unarc.cpp @@ -1,40 +1,40 @@ #include <stdlib.h> #include "generic.h" -#include "fileutils.h" +#include "Input.h" +#include "Output.h" +#include "Main.h" -int main(int argc, char ** argv) { - FILE * f; +CODE_BEGINS +int startup() { + Handle * f, * o; int i = 0; - f = fopen(argv[1], "r"); + f = new Input(argv[1]); int offset = 0; while (1) { int sector, size; - fseek(f, offset, SEEK_SET); - fread(§or, 4, 1, f); - fread(&size, 4, 1, f); + f->seek(offset, SEEK_SET); + f->read(§or, 4); + f->read(&size, 4); offset += 8; if (!sector) break; - fseek(f, sector <<= 9, SEEK_SET); + f->seek(sector <<= 9, SEEK_SET); - char * buffer = (char *) malloc(size); - - fread(buffer, 1, size, f); - - char fname[64]; - sprintf(fname, "unarc-%03i.out", i); - FILE * o = fopen(fname, "w"); - fwrite(buffer, 1, size, o); - fclose(o); + String fname; + fname.set("unarc-%03i.out", i); + o = new Output(fname); + copy(f, o, size); + delete o; i++; - - free(buffer); } - exit(-1); + delete f; + + return -1; } +CODE_ENDS diff --git a/PcsxSrc/Debug.h b/PcsxSrc/Debug.h index 14f94cb..efb426e 100644 --- a/PcsxSrc/Debug.h +++ b/PcsxSrc/Debug.h @@ -33,17 +33,17 @@ FILE *gteLog; //#define LOG_STDOUT
-//#define PAD_LOG __Log
-//#define GTE_LOG __Log
-//#define CDR_LOG __Log("%8.8lx %8.8lx: ", psxRegs.pc, psxRegs.cycle); __Log
+#define PAD_LOG __Log
+#define GTE_LOG __Log
+#define CDR_LOG __Log("%8.8lx %8.8lx: ", psxRegs.pc, psxRegs.cycle); __Log
-//#define PSXHW_LOG __Log("%8.8lx %8.8lx: ", psxRegs.pc, psxRegs.cycle); __Log
-//#define PSXBIOS_LOG __Log("%8.8lx %8.8lx: ", psxRegs.pc, psxRegs.cycle); __Log
-//#define PSXDMA_LOG __Log
-//#define PSXMEM_LOG __Log("%8.8lx %8.8lx: ", psxRegs.pc, psxRegs.cycle); __Log
-//#define PSXCPU_LOG __Log
+#define PSXHW_LOG __Log("%8.8lx %8.8lx: ", psxRegs.pc, psxRegs.cycle); __Log
+#define PSXBIOS_LOG __Log("%8.8lx %8.8lx: ", psxRegs.pc, psxRegs.cycle); __Log
+#define PSXDMA_LOG __Log
+#define PSXMEM_LOG __Log("%8.8lx %8.8lx: ", psxRegs.pc, psxRegs.cycle); __Log
+#define PSXCPU_LOG __Log
-//#define CDRCMD_DEBUG
+#define CDRCMD_DEBUG
#if defined (PSXCPU_LOG) || defined(PSXDMA_LOG) || defined(CDR_LOG) || defined(PSXHW_LOG) || \
defined(PSXBIOS_LOG) || defined(GTE_LOG) || defined(PAD_LOG)
diff --git a/PcsxSrc/Linux/Makefile b/PcsxSrc/Linux/Makefile index bbf1b70..71d47e5 100644 --- a/PcsxSrc/Linux/Makefile +++ b/PcsxSrc/Linux/Makefile @@ -19,7 +19,8 @@ OPTIMIZE = -O2 -fomit-frame-pointer -finline-functions -ffast-math FLAGS = -D__LINUX__ -DPCSX_VERSION=\"${VERSION}\"
# this includes the option -rdynamic and we don't want that
LIBST = $(shell gtk-config --libs)
-LIBS = $(subst -rdynamic, , ${LIBST}) -lz
+#LIBS = $(subst -rdynamic, , ${LIBST}) -lz
+LIBS = ${LIBST} -lz OBJS = ../PsxBios.o ../CdRom.o ../PsxCounters.o ../PsxDma.o ../DisR3000A.o \
../Spu.o ../Sio.o ../PsxHw.o ../Mdec.o ../PsxMem.o ../Misc.o \
@@ -29,7 +30,7 @@ OBJS+= LnxMain.o Plugin.o Config.o GtkGui.o OBJS+= GladeGui.o GladeFuncs.o #GladeCalls.o
ifeq (${CPU}, ix86)
- CC = pgcc
+ CC = gcc
OPTIMIZE = -O4 -fomit-frame-pointer -finline-functions -ffast-math -fno-exceptions -march=pentiumpro
OBJS+= ../ix86/iR3000A.o ../ix86/ix86.o
FLAGS+= -D__i386__
@@ -41,7 +42,7 @@ ASMFLAGS = -f elf ${FLAGS} -i./ -i../ pcsx: ${OBJS}
${CC} ${CFLAGS} ${OBJS} -o pcsx ${LIBS}
- ${STRIP} pcsx
+# ${STRIP} pcsx
.PHONY: clean pcsx
diff --git a/PcsxSrc/Sio.c b/PcsxSrc/Sio.c index 36f09b8..263e556 100644 --- a/PcsxSrc/Sio.c +++ b/PcsxSrc/Sio.c @@ -46,7 +46,18 @@ static unsigned char adrH,adrL; static unsigned long padst;
PadDataS pad;
-
+ +#ifndef strlwr +#include <ctype.h> +char * strlwr(char * string) { + char * r; + for (r = string; *r; r++) { + *r = tolower(*r); + } + return string; +} +#endif
+ char Mcd1Data[MCD_SIZE], Mcd2Data[MCD_SIZE];
// clk cycle byte
diff --git a/VP/Makefile b/VP/Makefile index 27af592..815eb9d 100755 --- a/VP/Makefile +++ b/VP/Makefile @@ -1,9 +1,12 @@ #!/usr/bin/make -f -CPPFLAGS=-Wall -g -O3 -mcpu=i686 -pedantic -pedantic-errors -Werror -I../includes +CPPFLAGS=-Wall -g -O3 -mcpu=i686 -pedantic -pedantic-errors -Werror -I../includes -DHAVE_ZLIB CXX=g++ -TARGET = main_dump VP-CD1.sqr decomp-slz unarc search-script +LIBS=-lz +LDFLAGS=${LIBS} + +TARGET = main_dump VP-CD1.sqr decomp-slz unarc all: ${TARGET} diff --git a/VP/decomp-slz.cpp b/VP/decomp-slz.cpp index fa09411..076d3bd 100644 --- a/VP/decomp-slz.cpp +++ b/VP/decomp-slz.cpp @@ -2,56 +2,62 @@ #include <stdlib.h> #include "lzss.h" -#include "fileutils.h" -#include "generic.h" +#include "Input.h" +#include "Output.h" +#include "Main.h" -int main(int argc, char ** argv) { +CODE_BEGINS +public: +Appli() : lzss_o(new lzss) {} +virtual ~Appli() { + delete lzss_o; +} +private: + +lzss * lzss_o; + +virtual int startup() throw (GeneralException) { int sig, l, d, v; - FILE * fin = stdin, * fout = stdout; + Handle * fin = &Stdin, * fout = &Stdout; switch (argc) { case 3: - if (!(fout = fopen(argv[2], "w"))) { - printm(M_ERROR, "Error opening file %s.\n", argv[3]); - exit(-1); - } + fout = new Output(argv[2]); case 2: - if (!(fin = fopen(argv[1], "r"))) { - printm(M_ERROR, "Error opening file %s.\n", argv[2]); - exit(-1); - } + fin = new Input(argv[1]); break; case 1: break; default: printm(M_BARE, "Usage: %s [filein] [fileout]\n", argv[0]); - exit(-1); + return -1; } verbosity = M_STATUS; - fread(&sig, 1, 4, fin); - fread(&d, 1, 4, fin); - fread(&l, 1, 4, fin); + fin->read(&sig, 4); + fin->read(&d, 4); + fin->read(&l, 4); switch (sig) { case 0x05a4c53: printm(M_STATUS, "Detected a SLZ-type 0 file.\n"); - fread(&v, 1, 4, fin); + fin->read(&v, 4); copy(fin, fout, d); - exit(0); + return 0; case 0x15a4c53: - scheme = schemes[VP_1]; + lzss_o->change_scheme(lzss_o->schemes[lzss_o->VP_1]); printm(M_STATUS, "Detected a SLZ-type 1 file.\n"); break; case 0x25a4c53: - scheme = schemes[VP_2]; + lzss_o->change_scheme(lzss_o->schemes[lzss_o->VP_2]); printm(M_STATUS, "Detected a SLZ-type 2 file.\n"); break; default: printm(M_ERROR, "Not a SLZ file.\n"); - exit(-1); + return -1; } - lzss_decomp(fin, fout, l); - exit(0); + lzss_o->lzss_decomp(fin, fout, l); + return 0; } +CODE_ENDS diff --git a/VP/main_dump.cpp b/VP/main_dump.cpp index 0845e1a..421db66 100644 --- a/VP/main_dump.cpp +++ b/VP/main_dump.cpp @@ -33,8 +33,21 @@ #include "Input.h" #include "Output.h" #include "String.h" +#include "Main.h" +#include "cdabstract.h" + +CODE_BEGINS +public: +Appli() : tourne(0), nb_seqs(0), f_def(0), f_iso(0), f_out(0), cdutil(0) {} +virtual ~Appli() { + delete cdutil; + delete f_def; + delete f_iso; + delete f_out; +} +private: -unsigned int tourne = 0; +unsigned int tourne; struct t_index_tab { unsigned long address; @@ -53,20 +66,15 @@ struct t_sequence { String title, iso_filename, prefix; unsigned long iso_size; -unsigned int nb_records, nb_seqs = 0; +unsigned int nb_records, nb_seqs; struct t_sequence sequences[1000]; - -long check_iso(Handle * f_iso); -void read_files(Handle * f_iso); -void file_dump(Handle * f_iso, unsigned long debut, unsigned long taille, long num, int seq); -int process_def_file(Handle * f_def); +Handle * f_def, * f_iso, * f_out; +cdutils * cdutil; unsigned char user_data[2352]; -int main(int argc, char **argv) +virtual int startup() throw (GeneralException) { - Handle * f_def, * f_iso; - verbosity = M_STATUS; fprintf(stderr, @@ -76,40 +84,41 @@ int main(int argc, char **argv) if (argc != 3) { fprintf(stderr, "Usage: %s <definition_file.sqr> <iso_file_name>\nSee readme.txt for details\n", argv[0]); - exit(-1); + throw Exit(-1); } printm(M_STATUS, "Processing file %s...\n", argv[1]); f_def = new Input(argv[1]); - if (process_def_file(f_def)) { - delete f_def; + if (process_def_file()) { printm(M_ERROR, "Unable to process the definition file \"%s\"...\n", argv[1]); - exit(-1); + throw Exit(-1); } iso_filename = argv[2]; printm(M_STATUS, "Begin processing iso file.\n"); - f_iso = new Input(iso_filename); + f_iso = open_iso(iso_filename); - if (check_iso(f_iso)) { + if (check_iso()) { printm(M_ERROR, "Invalid iso file for " + title + "\n"); printm(M_ERROR, "===> Make sure you are using a Genuine iso file.\n"); } else { printm(M_INFO, "Genuine " + title + " iso detected.\n"); } + + cdutil = new cdutils(f_iso); + printm(M_STATUS, "Entering files read sequence\n"); - read_files(f_iso); - delete f_iso; - exit(0); + read_files(); + throw Exit(0); } /* * Ugly but working... for now */ -int process_def_file(Handle * f_def) +int process_def_file() { String t; unsigned int n, sum = 0; @@ -153,19 +162,23 @@ int process_def_file(Handle * f_def) } } -long check_iso(Handle * f_iso) +long check_iso() { unsigned long length; length = f_iso->GetSize(); - printm(M_INFO, "Filesize of iso file " + iso_filename + " is %ld bytes\n", length); - if (length != iso_size) { - return 1; + if (length < 0) { + printm(M_INFO, "Can not get file size, assuming reading from cd.\n"); + } else { + printm(M_INFO, "Filesize of iso file " + iso_filename + " is %ld bytes\n", length); + if (length != iso_size) { + return 1; + } } return 0; } -void read_files(Handle * f_iso) +void read_files() { t_index_tab index_tab[10000]; unsigned long i; @@ -178,10 +191,10 @@ void read_files(Handle * f_iso) #define INDEXPOS 150 - sector_seek(f_iso, INDEXPOS); + cdutil->sector_seek(INDEXPOS); for (i = INDEXPOS; i < (INDEXPOS + 10); i++) { printm(M_INFO, "Reading fat sector %lu\n", i); - read_sector(f_iso, &fat[2048 * (i - INDEXPOS)], MODE_2_FORM_1); + cdutil->read_sector(&fat[2048 * (i - INDEXPOS)], MODE_2_FORM_1); } memcpy(key, fat + 0x4f00, 256); @@ -197,7 +210,7 @@ void read_files(Handle * f_iso) m = fat[j]; s = fat[j + 1]; f = fat[j + 2]; - index_tab[indexer].address = from_MSF(m, s, f); + index_tab[indexer].address = cdutil->from_MSF(m, s, f); if (m || s || f) { index_tab[indexer].index = j / 4; index_tab[indexer].flags = fat[j + 3]; @@ -224,7 +237,7 @@ void read_files(Handle * f_iso) printm(M_INFO, "%6lu - %02x: ", index_tab[i].address, index_tab[i].flags); size = index_tab[i + 1].address - index_tab[i].address; size *= sec_sizes[index_tab[i].type]; - file_dump(f_iso, index_tab[i].address, size, i, seq); + file_dump(index_tab[i].address, size, i, seq); if (verbosity >= M_INFO) { fprintf(stderr, "\n"); } @@ -233,12 +246,11 @@ void read_files(Handle * f_iso) fprintf(stderr, "\n"); } -void file_dump(Handle * f_iso, unsigned long debut, unsigned long taille, long num, int seq) +void file_dump(unsigned long debut, unsigned long taille, long num, int seq) { long i; long nbsects; String nom; - Handle * f_out; char type = sequences[seq].type; char ptitbidule[] = "-\\|/"; @@ -248,17 +260,17 @@ void file_dump(Handle * f_iso, unsigned long debut, unsigned long taille, long n nom += sequences[seq].prefix + "/"; MKDIR(nom.to_charp()); - nom += String("%04ld.out", num); + nom += String().set("%04ld.out", num); f_out = new Output(nom); nbsects = taille / sec_sizes[type]; if (taille % sec_sizes[type]) nbsects++; - sector_seek(f_iso, debut); + cdutil->sector_seek(debut); for (i = 0; i < nbsects; i++) { if (verbosity < M_INFO) fprintf(stderr, " (%c)\010\010\010\010\010", ptitbidule[((tourne++) >> 8) % 4]); - read_sector(f_iso, user_data, type); + cdutil->read_sector(user_data, type); if (i != (nbsects - 1)) { f_out->write(user_data, sec_sizes[type]); } else { @@ -266,5 +278,7 @@ void file_dump(Handle * f_iso, unsigned long debut, unsigned long taille, long n } } delete f_out; + f_out = 0; printm(M_BARE, " (*) Dumped file number %4ld - type \"" + sequences[seq].name + "\" \r", num); } +CODE_ENDS diff --git a/VP/unarc.cpp b/VP/unarc.cpp index 5699260..7a22c48 100644 --- a/VP/unarc.cpp +++ b/VP/unarc.cpp @@ -2,14 +2,18 @@ #include <stdlib.h> #include <unistd.h> -#include "fileutils.h" +#include "Input.h" +#include "Output.h" #include "generic.h" +#include "Main.h" #define THRESHOLD 2000 -int main(int argc, char ** argv) { - int h, o, n, * index, * sizes, i, d; - char temp[100]; +CODE_BEGINS +int startup() { + int n, * index, * sizes, i, d; + String temp; + Handle * h, * o; verbosity = M_INFO; @@ -18,12 +22,9 @@ int main(int argc, char ** argv) { exit(-1); } - if ((h = open(argv[1], O_RDONLY)) < 0) { - printm(M_ERROR, "Unable to open archive file: %s\n", argv[1]); - exit(-1); - } + h = new Input(argv[1]); - read(h, &n, 4); + h->read(&n, 4); printm(M_STATUS, "Archive claims to have %i files, checking integrity.\n", n); @@ -36,8 +37,8 @@ int main(int argc, char ** argv) { sizes = (int *) malloc(n * sizeof(int)); for (i = 0; i < n; i++) { - lseek(h, (i + 1) * 8 + 4, SEEK_SET); - read(h, &(sizes[i]), 4); + h->seek((i + 1) * 8 + 4, SEEK_SET); + h->read(&(sizes[i]), 4); printm(M_INFO, "File #%i size = %i = 0x%08x\n", i, sizes[i], sizes[i]); } @@ -50,9 +51,9 @@ int main(int argc, char ** argv) { printm(M_INFO, "Index #%i = %i = 0x%08x\n", i, index[i], index[i]); } - d = filesize(h) - index[n - 1] - sizes[n - 1]; + d = h->GetSize() - index[n - 1] - sizes[n - 1]; - printm(M_INFO, "Archive size: %i, last index: %i, last file size: %i, difference = %i\n", filesize(h), index[n - 1], sizes[n - 1], d); + printm(M_INFO, "Archive size: %i, last index: %i, last file size: %i, difference = %i\n", h->GetSize(), index[n - 1], sizes[n - 1], d); if ((d < 0) || (d > 2048)) { printm(M_ERROR, "Archive incoherent.\n"); @@ -62,15 +63,17 @@ int main(int argc, char ** argv) { printm(M_STATUS, "Archive seems to be ok, extracting.\n"); for (i = 0; i < n; i++) { - sprintf(temp, "%04i.out", i); - o = open(temp, O_WRONLY | O_CREAT | O_TRUNC, 0666); + temp.set("%04i.out", i); + o = new Output(temp); - printm(M_INFO, "Extracting %s\n", temp); + printm(M_INFO, "Extracting " + temp + "\n"); - lseek(h, index[i], SEEK_SET); + h->seek(index[i], SEEK_SET); copy(h, o, sizes[i]); - close(o); + delete o; } - exit(0); + delete h; + return 0; } +CODE_ENDS diff --git a/Xenogears/Decrypt.cpp b/Xenogears/Decrypt.cpp index 76289e2..5f606a7 100644 --- a/Xenogears/Decrypt.cpp +++ b/Xenogears/Decrypt.cpp @@ -1,6 +1,8 @@ #include<stdio.h> #include<string.h> +#include "Main.h" +CODE_BEGINS void init_table(long table[5000]) { long i; @@ -467,7 +469,7 @@ int decrypt(FILE * f_source, FILE * f_cible, int room_number) return (0); } -int main(void) +int startup(void) throw (GeneralException) { int i; char file_name[100]; @@ -501,4 +503,7 @@ int main(void) fclose(f_cible); } } + + return 0; } +CODE_ENDS diff --git a/Xenogears/Makefile b/Xenogears/Makefile index 0f4a0bc..61f4486 100755 --- a/Xenogears/Makefile +++ b/Xenogears/Makefile @@ -4,8 +4,10 @@ CPPFLAGS=-Wall -g -O3 -mcpu=i686 -pedantic -pedantic-errors -I../includes -DHAVE CXX=g++ CC=gcc -LIBS=-lz -lefence -LDFLAGS=${LIBS} `pkg-config --libs glib-2.0` +LIBS=-lz +#-lefence +LDFLAGS=${LIBS} +#`pkg-config --libs glib-2.0` TARGET = reinsert main_dump Decrypt script-comp script-dec XenoCD1.sqr XenoCD2.sqr compil compil-2 diff --git a/Xenogears/main_dump.cpp b/Xenogears/main_dump.cpp index e380f7a..4a8cb2e 100644 --- a/Xenogears/main_dump.cpp +++ b/Xenogears/main_dump.cpp @@ -32,8 +32,21 @@ #include "generic.h" #include "Input.h" #include "Output.h" +#include "Main.h" +#include "cdabstract.h" + +CODE_BEGINS +public: +Appli() : tourne(0), nb_seqs(0), f_def(0), f_iso(0), cdutil(0) {} +virtual ~Appli() { + delete cdutil; + delete f_def; + delete f_iso; + delete f_out; +} +private: -unsigned int tourne = 0; +unsigned int tourne; struct t_index_tab { unsigned long address; @@ -52,19 +65,16 @@ struct t_sequence { String title, iso_filename, prefix; unsigned long iso_size; -unsigned int nb_records, nb_seqs = 0; +unsigned int nb_records, nb_seqs; struct t_sequence sequences[100]; +Handle * f_def, * f_iso, * f_out; -long check_iso(Handle * f_iso); -void read_files(Handle * f_iso); -void file_dump(Handle * f_iso, unsigned long debut, unsigned long taille, long num, int seq); -int process_def_file(Handle * f_def); +cdutils * cdutil; Byte user_data[2352]; -int Main(int argc, char **argv) +int startup() { - Handle * f_def, * f_iso; verbosity = 3; @@ -82,8 +92,7 @@ int Main(int argc, char **argv) f_def = new Input(argv[1]); - if (process_def_file(f_def)) { - delete f_def; + if (process_def_file()) { printm(M_ERROR, "Unable to process the definition file \"%s\"...\n", argv[1]); exit(-1); } @@ -91,24 +100,26 @@ int Main(int argc, char **argv) iso_filename = argv[2]; printm(M_STATUS, "Begin processing iso file.\n"); - f_iso = new Input(iso_filename); + f_iso = open_iso(iso_filename); - if (check_iso(f_iso)) { + if (check_iso()) { printm(M_ERROR, "Invalid iso file for " + title + "\n"); printm(M_ERROR, "===> Make sure you are using a Genuine iso file.\n"); } else { printm(M_INFO, "Genuine " + title + " iso detected.\n"); } + + cdutil = new cdutils(f_iso); + printm(M_STATUS, "Entering files read sequence\n"); - read_files(f_iso); - delete f_iso; + read_files(); exit(0); } /* * Ugly but working... for now */ -int process_def_file(Handle * f_def) +int process_def_file() { String t; unsigned int n, sum = 0; @@ -157,19 +168,23 @@ int process_def_file(Handle * f_def) } } -long check_iso(Handle * f_iso) +long check_iso() { unsigned long length; length = f_iso->GetSize(); - printm(M_INFO, "Filesize of iso file " + iso_filename + " is %ld bytes\n", length); - if (length != iso_size) { - return 1; + if (length < 0) { + printm(M_INFO, "Can not get file size, assuming reading from CD.\n"); + } else { + printm(M_INFO, "Filesize of iso file " + iso_filename + " is %ld bytes\n", length); + if (length != iso_size) { + return 1; + } } return 0; } -void read_files(Handle * f_iso) +void read_files() { t_index_tab index_tab[10000]; unsigned char t[8]; @@ -183,10 +198,10 @@ void read_files(Handle * f_iso) #define INDEXPOS 24 - sector_seek(f_iso, INDEXPOS); + cdutil->sector_seek(INDEXPOS); for (i = INDEXPOS; i < (INDEXPOS + 16); i++) { printm(M_INFO, "Reading fat sector %lu\n", i); - read_sector(f_iso, &fat[2048 * (i - INDEXPOS)], MODE_2_FORM_1); + cdutil->read_sector(&fat[2048 * (i - INDEXPOS)], MODE_2_FORM_1); } indexer = 0; @@ -217,7 +232,7 @@ void read_files(Handle * f_iso) printm(M_INFO, "%6lu (%10lu): ignored\n", index_tab[i].address, index_tab[i].size); } else { printm(M_INFO, "%6lu (%10lu): ", index_tab[i].address, index_tab[i].size); - file_dump(f_iso, index_tab[i].address, index_tab[i].size, i, seq); + file_dump(index_tab[i].address, index_tab[i].size, i, seq); if (verbosity >= M_INFO) { fprintf(stderr, "\n"); } @@ -226,14 +241,13 @@ void read_files(Handle * f_iso) fprintf(stderr, "\n"); } -void file_dump(Handle * f_iso, unsigned long debut, unsigned long taille, long num, int seq) +void file_dump(unsigned long debut, unsigned long taille, long num, int seq) { long i; long nbsects; String nom; String extension = ".out"; String nom_t; - Handle * f_out; char type = sequences[seq].type; char ptitbidule[] = "-\\|/"; @@ -252,11 +266,11 @@ void file_dump(Handle * f_iso, unsigned long debut, unsigned long taille, long n nbsects = taille / sec_sizes[type]; if (taille % sec_sizes[type]) nbsects++; - sector_seek(f_iso, debut); + cdutil->sector_seek(debut); for (i = 0; i < nbsects; i++) { if (verbosity < M_INFO) fprintf(stderr, " (%c)\010\010\010\010\010", ptitbidule[((tourne++) >> 8) % 4]); - read_sector(f_iso, user_data, type); + cdutil->read_sector(user_data, type); if (i != (nbsects - 1)) { f_out->write(user_data, sec_sizes[type]); } else { @@ -264,13 +278,8 @@ void file_dump(Handle * f_iso, unsigned long debut, unsigned long taille, long n } } delete f_out; + f_out = 0; printm(M_BARE, " (*) Dumped file number %4ld - type \"" + sequences[seq].name + "\" \r", num); } -int main(int argc, char ** argv) { - try { - Main(argc, argv); - } catch (GeneralException e) { - fprintf(stderr, "Main got an unexpected exception: %s\n", e.GetMsg()); - } -} +} * Application = new Appli(); diff --git a/Xenogears/reinsert.cpp b/Xenogears/reinsert.cpp index 440e444..da23033 100644 --- a/Xenogears/reinsert.cpp +++ b/Xenogears/reinsert.cpp @@ -6,8 +6,21 @@ #include "generic.h" #include "Input.h" #include "Output.h" +#include "Main.h" + +CODE_BEGINS +public: +Appli() : tourne(0), nb_seqs(0), f_def(0), f_iso_r(0), f_iso_w(0), f_in(0), cdutil(0), slus_index(-1), force(0) {} +virtual ~Appli() { + delete cdutil; + delete f_def; + delete f_iso_r; + delete f_iso_w; + delete f_in; +} +private: -unsigned int tourne = 0; +unsigned int tourne; struct t_index_tab { unsigned long address; @@ -26,26 +39,23 @@ struct t_sequence { String title, iso_filename, prefix, in_filename; unsigned long iso_size; -unsigned int nb_records, nb_seqs = 0; +unsigned int nb_records, nb_seqs; struct t_sequence sequences[1000]; +Handle * f_def, * f_iso_r, * f_iso_w, * f_in; +cdutils * cdutil; -int slus_index = -1, force = 0; - -long check_iso(Handle * f_iso); -void write_files(Handle * f_iso_r, Handle * f_iso_w, Handle * f_in, int fileindex); -int process_def_file(Handle * f_def); +int slus_index, force; unsigned char user_data[2352]; -void usage(char ** argv) { +void usage() throw (GeneralException) { printm(M_BARE, "Usage: %s <definition_file.sqr> <iso_file_name> <file_index> <filename> [-f]\nSee readme.txt for details\n", argv[0]); - exit(-1); + throw Exit(-1); } -int main(int argc, char **argv) +virtual int startup() throw (GeneralException) { - Handle * f_def, * f_iso_r, * f_iso_w, * f_in; int fileindex; verbosity = 1; @@ -53,12 +63,12 @@ int main(int argc, char **argv) printm(M_BARE, "Xenogears File Insertor by Nicolas \"Pixel\" Noble\n\n"); if ((argc != 5) && (argc != 6)) { - usage(argv); + usage(); } if (argc == 6) { if (strcmp(argv[5], "-f")) { - usage(argv); + usage(); } else { force = 1; } @@ -69,9 +79,8 @@ int main(int argc, char **argv) f_def = new Input(argv[1]); if (process_def_file(f_def)) { - delete f_def; printm(M_ERROR, "Unable to process the definition file \"%s\"...\n", argv[1]); - exit(-1); + throw Exit(-1); } iso_filename = argv[2]; @@ -81,10 +90,12 @@ int main(int argc, char **argv) f_iso_w = new Output(iso_filename, 0, 0); f_iso_w->seek(0, SEEK_SET); - if (check_iso(f_iso_r)) { + cdutil = new cdutils(f_iso_r, f_iso_w); + + if (check_iso()) { printm(M_ERROR, "Invalid iso file for " + title + "\n"); printm(M_ERROR, "===> Make sure you are using a Genuine iso file.\n"); - exit(-1); + throw Exit(-1); } else { printm(M_INFO, "Genuine " + title + " iso detected.\n"); } @@ -94,10 +105,8 @@ int main(int argc, char **argv) f_in = new Input(in_filename); printm(M_STATUS, "Entering files write sequence\n"); - write_files(f_iso_r, f_iso_w, f_in, fileindex); - delete f_iso_r; - delete f_iso_w; - exit(0); + write_files(fileindex); + return 0; } /* @@ -152,11 +161,11 @@ int process_def_file(Handle * f_def) } } -long check_iso(Handle * f_iso) +long check_iso() { unsigned long length; - length = f_iso->GetSize(); + length = f_iso_r->GetSize(); printm(M_INFO, "Filesize of iso file " + iso_filename + " is %ld bytes\n", length); if (length != iso_size) { return 1; @@ -166,31 +175,31 @@ long check_iso(Handle * f_iso) #define INDEXPOS 24 -void rewrite_fat(Handle * f_iso_r, Handle * f_iso_w, Byte * new_fat) { +void rewrite_fat(Byte * new_fat) { unsigned char old_fat[34816]; int i; - sector_seek(f_iso_w, INDEXPOS); + cdutil->sector_seek(INDEXPOS); for (i = INDEXPOS; i < (INDEXPOS + 16); i++) { printm(M_INFO, "Writing fat sector %lu\n", i); - write_sector(f_iso_r, f_iso_w, &new_fat[2048 * (i - INDEXPOS)], MODE_2_FORM_1); + cdutil->write_sector(&new_fat[2048 * (i - INDEXPOS)], MODE_2_FORM_1); } - sector_seek(f_iso_r, slus_index + 1); + cdutil->sector_seek(slus_index + 1); for (i = slus_index + 1; i < (slus_index + 18); i++) { printm(M_INFO, "Reading SLUS sector %lu\n", i); - read_sector(f_iso_r, &old_fat[2048 * (i - slus_index - 1)], MODE_2_FORM_1); + cdutil->read_sector(&old_fat[2048 * (i - slus_index - 1)], MODE_2_FORM_1); } bcopy((char *) new_fat, (char *) old_fat + 4, 32768); - sector_seek(f_iso_w, slus_index + 1); + cdutil->sector_seek(slus_index + 1); for (i = slus_index + 1; i < (slus_index + 18); i++) { printm(M_INFO, "Writing SLUS sector %lu\n", i); - write_sector(f_iso_r, f_iso_w, &old_fat[2048 * (i - slus_index - 1)], MODE_2_FORM_1); + cdutil->write_sector(&old_fat[2048 * (i - slus_index - 1)], MODE_2_FORM_1); } } -void write_files(Handle * f_iso_r, Handle * f_iso_w, Handle * f_in, int fileindex) +void write_files(int fileindex) throw (GeneralException) { t_index_tab index_tab[10000]; unsigned char t[8]; @@ -203,10 +212,10 @@ void write_files(Handle * f_iso_r, Handle * f_iso_w, Handle * f_in, int fileinde long old_file_size, new_file_size, old_nb_sects, new_nb_sects; unsigned char fat[32768]; - sector_seek(f_iso_r, INDEXPOS); + cdutil->sector_seek(INDEXPOS); for (i = INDEXPOS; i < (INDEXPOS + 16); i++) { printm(M_INFO, "Reading fat sector %lu\n", i); - read_sector(f_iso_r, &fat[2048 * (i - INDEXPOS)], MODE_2_FORM_1); + cdutil->read_sector(&fat[2048 * (i - INDEXPOS)], MODE_2_FORM_1); } indexer = 0; @@ -236,7 +245,7 @@ void write_files(Handle * f_iso_r, Handle * f_iso_w, Handle * f_in, int fileinde if (sequences[seq].prefix == "SLUS") { if (slus_index >= 0) { printm(M_ERROR, "Two SLUS files defined\n"); - exit(-1); + throw Exit(-1); } slus_index = index_tab[i].address; } @@ -244,7 +253,7 @@ void write_files(Handle * f_iso_r, Handle * f_iso_w, Handle * f_in, int fileinde if (slus_index < 0) { printm(M_ERROR, "No SLUS file defined\n"); - exit(-1); + throw Exit(-1); } printm(M_INFO, "SLUS file found at sector %6i\n", slus_index); @@ -266,7 +275,7 @@ void write_files(Handle * f_iso_r, Handle * f_iso_w, Handle * f_in, int fileinde if (new_nb_sects > old_nb_sects) { printm(M_ERROR, "New file too big.\n"); if (!force) { - exit(-1); + throw Exit(-1); } } @@ -275,7 +284,8 @@ void write_files(Handle * f_iso_r, Handle * f_iso_w, Handle * f_in, int fileinde printm(M_INFO, "File address: %6i\n", index_tab[fileindex].address); - write_file(f_iso_r, f_iso_w, f_in, index_tab[fileindex].type, index_tab[fileindex].address); + cdutil->write_file(f_in, index_tab[fileindex].type, index_tab[fileindex].address); *((long *)(&fat[index_tab[fileindex].index * 7 + 3])) = new_file_size; - rewrite_fat(f_iso_r, f_iso_w, fat); + rewrite_fat(fat); } +CODE_ENDS diff --git a/Xenogears/script-comp.cpp b/Xenogears/script-comp.cpp index ee71d8f..76eab1d 100644 --- a/Xenogears/script-comp.cpp +++ b/Xenogears/script-comp.cpp @@ -2,6 +2,15 @@ #include "Input.h" #include "Output.h" #include "generic.h" +#include "Main.h" + +CODE_BEGINS +public: +Appli() : lzss_o(new lzss()) {} +virtual ~Appli() { delete lzss_o; } +private: + +lzss * lzss_o; void process_one_file(Handle * f, Handle * d, int n) { String nom_du_fichier; @@ -38,7 +47,7 @@ void process_one_file(Handle * f, Handle * d, int n) { d->write(&true_length, 4); d->seek(0, SEEK_END); - lzss_comp(f_part, d, &delta); + lzss_o->lzss_comp(f_part, d, &delta); delete f_part; @@ -58,7 +67,7 @@ void process_one_file(Handle * f, Handle * d, int n) { free(datas); } -int main(int argc, char ** argv) +virtual int startup() throw (GeneralException) { Handle * f_script_comp, * f_new_script; int i; @@ -95,4 +104,7 @@ int main(int argc, char ** argv) num++; } printm(M_BARE, "Done !\n"); + + return 0; } +CODE_ENDS diff --git a/Xenogears/script-dec.cpp b/Xenogears/script-dec.cpp index 81dfea3..84e55f0 100644 --- a/Xenogears/script-dec.cpp +++ b/Xenogears/script-dec.cpp @@ -5,6 +5,15 @@ #include "String.h" #include "Input.h" #include "Output.h" +#include "Main.h" + +CODE_BEGINS +public: +Appli() : lzss_o(new lzss()) {} +virtual ~Appli() { delete lzss_o; } +private: + +lzss * lzss_o; void process_one_file(Handle * f, int d, int n) { String nom_du_fichier; @@ -28,7 +37,7 @@ void process_one_file(Handle * f, int d, int n) { f->seek(0x10c + i * 4); f->read(&true_length, 4); f->seek(script_position); - lzss_decomp(f, f_out, true_length); + lzss_o->lzss_decomp(f, f_out, true_length); // if (i == 7) { // fseek(f_out, 0, SEEK_SET); // fread(&true_length, 4, 1, f_out); @@ -38,7 +47,7 @@ void process_one_file(Handle * f, int d, int n) { // } } -int main(void) +int startup() { Handle * f_script_comp; int i; @@ -69,4 +78,6 @@ int main(void) num++; } printm(M_BARE, "Done !\n"); + return 0; } +CODE_ENDS diff --git a/generic/Buffer.cpp b/generic/Buffer.cpp index 940b0a8..36c56a9 100644 --- a/generic/Buffer.cpp +++ b/generic/Buffer.cpp @@ -54,15 +54,15 @@ ssize_t Buffer::read(void *buf, size_t count) throw (GeneralException) { return count; } -bool Buffer::CanRead() { +bool Buffer::CanRead() const { return true; } -bool Buffer::CanWrite() { +bool Buffer::CanWrite() const { return true; } -String Buffer::GetName() { +String Buffer::GetName() const { return "Buffer"; } @@ -81,11 +81,11 @@ Buffer Buffer::operator=(const Buffer & b) { return *this; } -bool Buffer::CanWatch() { +bool Buffer::CanWatch() const { return false; } -ssize_t Buffer::GetSize() { +ssize_t Buffer::GetSize() const { return realsiz; } diff --git a/generic/Exceptions.cpp b/generic/Exceptions.cpp index b7c00a6..510e0a3 100644 --- a/generic/Exceptions.cpp +++ b/generic/Exceptions.cpp @@ -3,7 +3,9 @@ #include <string.h> #include <errno.h> #include <stddef.h> +#ifdef HAVE_GLIB #include <glib.h> +#endif #ifdef DEBUG #include <iostream> #endif @@ -40,7 +42,7 @@ GeneralException::~GeneralException() { TaskNotFound::TaskNotFound() : GeneralException("Task not found") { } -char * GeneralException::GetMsg() { +const char * GeneralException::GetMsg() const { return msg; } @@ -71,6 +73,16 @@ TaskSwitch::TaskSwitch() : GeneralException(_("Switching task in a non-tasked en #endif } +Exit::Exit(int a_code) : GeneralException(_("Exitting with code " + a_code)), code(a_code) { +#ifdef DEBUG + cerr << "Generating an Exit exception: '" << GetMsg() << "'.\n"; +#endif +} + +int Exit::GetCode() { + return code; +} + char * xstrdup(const char * s) { char * r; @@ -108,9 +120,9 @@ void * xrealloc(void * ptr, size_t s) { #endif } -#ifdef OVER_FREE -#undef free -#endif +void xfree(unsigned char *& p) { + xfree(((char *)p)); +} void xfree(void *& p) { xfree(((char *)p)); diff --git a/generic/Handle.cpp b/generic/Handle.cpp index e95a28a..4e318c6 100644 --- a/generic/Handle.cpp +++ b/generic/Handle.cpp @@ -30,6 +30,10 @@ int Handle::GetHandle() { return h; } +int Handle::GetHandle() const { + return h; +} + ssize_t Handle::write(const void *buf, size_t count) throw (GeneralException) { ssize_t r, tr = 0; bool done, full = false; @@ -96,11 +100,11 @@ ssize_t Handle::read(void *buf, size_t count) throw (GeneralException) { return r; } -bool Handle::IsClosed(void) { +bool Handle::IsClosed(void) const { return closed; } -bool Handle::IsNonBlock(void) { +bool Handle::IsNonBlock(void) const { return nonblock; } @@ -177,27 +181,27 @@ void Handle::close() throw (GeneralException) { closed = 1; } -bool Handle::CanRead(void) { +bool Handle::CanRead(void) const { return false; } -bool Handle::CanWrite(void) { +bool Handle::CanWrite(void) const { return false; } -String Handle::GetName(void) { +String Handle::GetName(void) const { return _("Bare Handle - should not happend"); } -ssize_t Handle::GetSize(void) { +ssize_t Handle::GetSize(void) const { return -1; } -time_t Handle::GetModif(void) { +time_t Handle::GetModif(void) const { return -1; } -bool Handle::CanWatch(void) { +bool Handle::CanWatch(void) const { return true; } @@ -241,7 +245,11 @@ ssize_t Handle::uwrite(const void * buf, size_t count) throw (GeneralException) if (z) { itell += count; // cerr << "Performing gzwrite of " << count << " byte for handle " << h << endl; +#ifdef HAVE_CLEAN_ZLIB int err = gzwrite(zfile, buf, count); +#else + int err = gzwrite(zfile, (char *) buf, count); +#endif // cerr << "gzwrite returned " << err << endl; if (err == 0) { const char * m = gzerror(zfile, &err); @@ -286,11 +294,11 @@ ssize_t Handle::uread(void * buf, size_t count) { } } -off_t Handle::tell() { +off_t Handle::tell() const { return itell; } -bool Handle::CanSeek() { +bool Handle::CanSeek() const { return 0; } diff --git a/generic/Image.cpp b/generic/Image.cpp index 1270a6a..b8396b1 100644 --- a/generic/Image.cpp +++ b/generic/Image.cpp @@ -13,11 +13,11 @@ Image::~Image() { free((void *)img); } -bool Image::CanWrite() { +bool Image::CanWrite() const { return false; } -String Image::GetName() { +String Image::GetName() const { return String(_("Image ")) + x + "x" + y; } @@ -27,7 +27,7 @@ void Image::Fill(Color c) { } } -Color Image::GetPixel(unsigned int px, unsigned int py) { +Color Image::GetPixel(unsigned int px, unsigned int py) const { if ((px >= x) || (py >= y)) { return Color(0, 0, 0, 0); } diff --git a/generic/Input.cpp b/generic/Input.cpp index d415279..69d28e7 100644 --- a/generic/Input.cpp +++ b/generic/Input.cpp @@ -38,15 +38,15 @@ Input::Input(const String & no) throw (GeneralException) : Input::Input(const Input & i) : Handle(i), n(i.n), size(i.size), date_modif(i.date_modif) { } -bool Input::CanWrite() { +bool Input::CanWrite() const { return 0; } -bool Input::CanRead() { +bool Input::CanRead() const { return 1; } -bool Input::CanSeek() { +bool Input::CanSeek() const { struct stat s; fstat(GetHandle(), &s); @@ -54,15 +54,15 @@ bool Input::CanSeek() { return S_ISREG(s.st_mode); } -String Input::GetName() { +String Input::GetName() const { return n; } -ssize_t Input::GetSize() { +ssize_t Input::GetSize() const { return size; } -time_t Input::GetModif() { +time_t Input::GetModif() const { return date_modif; } @@ -80,11 +80,11 @@ off_t Input::seek(off_t offset, int whence) throw (GeneralException) { Stdin_t::Stdin_t() { } -bool Stdin_t::CanSeek() { +bool Stdin_t::CanSeek() const { return 0; } -String Stdin_t::GetName() { +String Stdin_t::GetName() const { return "Stdin"; } diff --git a/generic/Makefile b/generic/Makefile index 7107501..1e2b047 100755 --- a/generic/Makefile +++ b/generic/Makefile @@ -1,10 +1,11 @@ #!/usr/bin/make -f -CPPFLAGS=-Wall -g -O3 -mcpu=i686 -pedantic -pedantic-errors -I../includes -DPARANOID_SEEK -DHAVE_ZLIB `pkg-config --cflags glib-2.0` +CPPFLAGS=-Wall -g -O3 -mcpu=i686 -pedantic -pedantic-errors -I../includes -DPARANOID_SEEK -DHAVE_ZLIB +#`pkg-config --cflags glib-2.0` CXX=g++ CC=gcc -OBJECTS = Buffer.o Exceptions.o Handle.o Image.o Input.o Output.o generic.o String.o checkargs.o datecalc.o +OBJECTS = Buffer.o Exceptions.o Handle.o Image.o Input.o Output.o Main.o generic.o String.o checkargs.o datecalc.o TARGET = generic.a all: ${TARGET} Makefile diff --git a/generic/Output.cpp b/generic/Output.cpp index 55ab158..b072236 100644 --- a/generic/Output.cpp +++ b/generic/Output.cpp @@ -14,7 +14,7 @@ #endif Output::Output(String no, int create, int trunc) throw (GeneralException) : - Handle(no.strlen() ? open(no.to_charp(), O_WRONLY | (O_CREAT * (create ? 1 : 0)) | (trunc ? O_TRUNC : O_APPEND) + Handle(no.strlen() ? open(no.to_charp(), O_WRONLY | (O_CREAT * (create ? 1 : 0)) | (O_TRUNC * (trunc ? 1 : 0)) #if defined __linux__ || defined __CYGWIN32__ , 00666 #endif @@ -37,15 +37,15 @@ Output::Output(String no, int create, int trunc) throw (GeneralException) : Output::Output(const Output & o) : Handle(o), n(o.n) { } -bool Output::CanWrite() { +bool Output::CanWrite() const { return 1; } -bool Output::CanRead() { +bool Output::CanRead() const { return 0; } -bool Output::CanSeek() { +bool Output::CanSeek() const { struct stat s; fstat(GetHandle(), &s); @@ -65,35 +65,35 @@ off_t Output::seek(off_t offset, int whence) throw (GeneralException) { return itell; } -String Output::GetName() { +String Output::GetName() const { return n; } Stdout_t::Stdout_t() {} -bool Stdout_t::CanSeek() { +bool Stdout_t::CanSeek() const { return 0; } -String Stdout_t::GetName() { +String Stdout_t::GetName() const { return "Stdout"; } Stderr_t::Stderr_t() : Handle(dup(2)) {} -bool Stderr_t::CanWrite() { +bool Stderr_t::CanWrite() const { return 1; } -bool Stderr_t::CanRead() { +bool Stderr_t::CanRead() const { return 0; } -bool Stderr_t::CanSeek() { +bool Stderr_t::CanSeek() const { return 0; } -String Stderr_t::GetName() { +String Stderr_t::GetName() const { return "Stderr"; } diff --git a/generic/String.cpp b/generic/String.cpp index 24961c5..d879308 100644 --- a/generic/String.cpp +++ b/generic/String.cpp @@ -1,6 +1,7 @@ #include <iostream> #include <string.h> #include <stdarg.h> +#include <ctype.h> #include "String.h" #include "Exceptions.h" #ifdef HAVE_CONFIG_H @@ -27,14 +28,13 @@ String::String(char c) : siz(1) { str = t; } -#if 0 String::String(const char * s) : str(Base::strdup(s)), siz(::strlen(str)) { #ifdef DEBUG fprintf(stderr, "Creating a string with `%s' at %p\n", str, str); #endif } -#endif +#if 0 String::String(const char * s, ...) { va_list ap; @@ -42,14 +42,13 @@ String::String(const char * s, ...) { fprintf(stderr, "Creating a String with s = '%s'\n", s); #endif -/* This causes a warning: cannot pass objects of type `const String' through `...' - but it is not really a problem. */ va_start(ap, s); vsnprintf(t, BUFSIZ, s, ap); str = Base::strdup(t); va_end(ap); siz = ::strlen(str); } +#endif String::String(int hs, const char * s) : str(s ? Base::strdup(s) : Base::strdup("")), siz(hs) { } @@ -389,3 +388,19 @@ bool String::is_time(void) const { String operator+(const char * a, const String & b) { return String(a) + b; } + +String & String::toupper() { + for (int i = 0; i < strlen(); i++) { + str[i] = ::toupper(str[i]); + } + + return *this; +} + +String & String::tolower() { + for (int i = 0; i < strlen(); i++) { + str[i] = ::tolower(str[i]); + } + + return *this; +} diff --git a/includes/Buffer.h b/includes/Buffer.h index 79d0e02..dc4d768 100644 --- a/includes/Buffer.h +++ b/includes/Buffer.h @@ -17,12 +17,12 @@ class Buffer : public Handle { virtual ~Buffer(); virtual ssize_t write(const void *buf, size_t count) throw(GeneralException); virtual ssize_t read(void *buf, size_t count) throw (GeneralException); - virtual bool CanRead(); - virtual bool CanWrite(); - virtual String GetName(); + virtual bool CanRead() const; + virtual bool CanWrite() const; + virtual String GetName() const; virtual Buffer operator=(const Buffer &); - virtual bool CanWatch(); - virtual ssize_t GetSize(); + virtual bool CanWatch() const; + virtual ssize_t GetSize() const; char operator[](size_t) const; char & operator[](size_t); diff --git a/includes/Exceptions.h b/includes/Exceptions.h index ef697e7..49be085 100644 --- a/includes/Exceptions.h +++ b/includes/Exceptions.h @@ -21,6 +21,7 @@ class Base { void operator delete(void * p); static void free(void *& p); static void free(char *& p); + static void free(unsigned char *& p); static int pipe(int * p, int flag = 0); static pid_t fork(); }; @@ -32,7 +33,7 @@ class GeneralException : public Base { GeneralException(String); GeneralException(const GeneralException &); ~GeneralException(); - char * GetMsg(); + const char * GetMsg() const; protected: GeneralException(); @@ -44,6 +45,7 @@ char * xstrdup(const char *); void * xmalloc(size_t) throw (GeneralException); void xfree(void *&); void xfree(char *&); +void xfree(unsigned char *&); void * xrealloc(void *, size_t); int xpipe(int *, int = 0) throw (GeneralException); pid_t xfork() throw (GeneralException); @@ -84,6 +86,10 @@ INLINE void Base::free(char *& p) { xfree(p); } +INLINE void Base::free(unsigned char *& p) { + xfree(p); +} + INLINE int Base::pipe(int * p, int flag) { return xpipe(p, flag); } @@ -129,6 +135,14 @@ class TaskSwitch : public GeneralException { TaskSwitch(); }; +class Exit : public GeneralException { + public: + Exit(int); + int GetCode(); + private: + int code; +}; + #include <String.h> #else diff --git a/includes/Handle.h b/includes/Handle.h index 4bab879..a82aa52 100644 --- a/includes/Handle.h +++ b/includes/Handle.h @@ -19,26 +19,27 @@ class Handle : public Base { virtual ~Handle(); virtual ssize_t read(void *buf, size_t count) throw (GeneralException); virtual ssize_t write(const void *buf, size_t count) throw (GeneralException); - bool IsClosed(void); - bool IsNonBlock(void); + bool IsClosed(void) const; + bool IsNonBlock(void) const; void SetNonBlock(void); - virtual bool CanRead(); - virtual bool CanWrite(); - virtual bool CanSeek(); + virtual bool CanRead() const; + virtual bool CanWrite() const; + virtual bool CanSeek() const; virtual off_t seek(off_t, int = SEEK_SET) throw (GeneralException); - virtual off_t tell(); - virtual String GetName(); - virtual ssize_t GetSize(); - virtual time_t GetModif(); + virtual off_t tell() const; + virtual String GetName() const; + virtual ssize_t GetSize() const; + virtual time_t GetModif() const; void close() throw (GeneralException); int GetHandle(); - virtual bool CanWatch(); + virtual bool CanWatch() const; virtual void Dup(const Handle &); #ifdef HAVE_ZLIB virtual void SetZ(int) throw (GeneralException); #endif protected: Handle(int h); + int GetHandle() const; off_t itell; private: ssize_t uwrite(const void *, size_t) throw (GeneralException); diff --git a/includes/Image.h b/includes/Image.h index fc94a12..09b4cb5 100644 --- a/includes/Image.h +++ b/includes/Image.h @@ -19,12 +19,12 @@ class Image : public Buffer { public: Image(unsigned int, unsigned int); virtual ~Image(); - Color GetPixel(unsigned int, unsigned int); + Color GetPixel(unsigned int, unsigned int) const; void SetPixel(unsigned int, unsigned int, Color); bool Prepare(unsigned int = FORMAT_TGA_BASIC); void Fill(Color = Color(0, 0, 0)); - virtual String GetName(); - virtual bool CanWrite(); + virtual String GetName() const; + virtual bool CanWrite() const; private: typedef unsigned char Byte; diff --git a/includes/Input.h b/includes/Input.h index d1755e7..1fb48c3 100644 --- a/includes/Input.h +++ b/includes/Input.h @@ -12,13 +12,13 @@ class Input : public Handle { Input(const String & = "") throw (GeneralException); Input(const Input &); virtual ~Input() {} - virtual bool CanWrite(); - virtual bool CanRead(); - virtual bool CanSeek(); + virtual bool CanWrite() const; + virtual bool CanRead() const; + virtual bool CanSeek() const; virtual off_t seek(off_t, int) throw (GeneralException); - virtual String GetName(); - virtual ssize_t GetSize(); - virtual time_t GetModif(); + virtual String GetName() const; + virtual ssize_t GetSize() const; + virtual time_t GetModif() const; protected: String n; @@ -30,8 +30,8 @@ class Stdin_t : public Input { public: Stdin_t(); virtual ~Stdin_t() {} - virtual bool CanSeek(); - virtual String GetName(); + virtual bool CanSeek() const; + virtual String GetName() const; }; extern Stdin_t Stdin; diff --git a/includes/Output.h b/includes/Output.h index bce4160..3ec5158 100644 --- a/includes/Output.h +++ b/includes/Output.h @@ -12,11 +12,11 @@ class Output : public Handle { Output(String = "", int create = 1, int trunc = 1) throw (GeneralException); Output(const Output &); virtual ~Output() {} - virtual bool CanWrite(); - virtual bool CanRead(); - virtual bool CanSeek(); + virtual bool CanWrite() const; + virtual bool CanRead() const; + virtual bool CanSeek() const; virtual off_t seek(off_t, int) throw (GeneralException); - virtual String GetName(); + virtual String GetName() const; protected: String n; @@ -28,18 +28,18 @@ class Stdout_t : public Output { public: Stdout_t(); virtual ~Stdout_t() {} - virtual bool CanSeek(); - virtual String GetName(); + virtual bool CanSeek() const; + virtual String GetName() const; }; class Stderr_t : public Handle { public: Stderr_t(); virtual ~Stderr_t() {} - virtual bool CanWrite(); - virtual bool CanRead(); - virtual bool CanSeek(); - virtual String GetName(); + virtual bool CanWrite() const; + virtual bool CanRead() const; + virtual bool CanSeek() const; + virtual String GetName() const; }; extern Stdout_t Stdout; diff --git a/includes/String.h b/includes/String.h index ea501b2..7e2f848 100644 --- a/includes/String.h +++ b/includes/String.h @@ -9,10 +9,10 @@ class String : public Base { public: String(const String &); -#if 0 String(const char * = ""); -#endif +#if 0 String(const char * = "", ...); +#endif String(char); String(int); String(unsigned int); @@ -53,6 +53,8 @@ class String : public Base { bool operator<(const String &) const; bool operator>(const String &) const; char operator[](size_t i) const; + String & toupper(); + String & tolower(); private: String(int hs, const char *); diff --git a/includes/cdreader.h b/includes/cdreader.h index 3991225..ed3bc00 100644 --- a/includes/cdreader.h +++ b/includes/cdreader.h @@ -12,17 +12,17 @@ class cdreader : public Handle { cdreader(const String & = "/dev/cdrom") throw (GeneralException); cdreader(const cdreader &); virtual ~cdreader() {} - virtual bool CanWrite(); - virtual bool CanRead(); - virtual bool CanSeek(); + virtual bool CanWrite() const; + virtual bool CanRead() const; + virtual bool CanSeek() const; virtual ssize_t read(void *buf, size_t count) throw (GeneralException); virtual off_t seek(off_t, int) throw (GeneralException); - virtual String GetName(); - virtual ssize_t GetSize(); + virtual String GetName() const; + virtual ssize_t GetSize() const; virtual void getsector(void *, int = -1) throw (GeneralException); virtual void sectorseek(int); - protected: + private: String n; int sector; }; diff --git a/includes/cdutils.h b/includes/cdutils.h index e3cf8fb..38eb118 100644 --- a/includes/cdutils.h +++ b/includes/cdutils.h @@ -27,62 +27,77 @@ #define GUESS 5 -struct DirEntry { - unsigned char R; - unsigned char NExt; - unsigned long Sector; - unsigned long BESector; - unsigned long Size; - unsigned long BESize; - unsigned char Year; - unsigned char Month; - unsigned char Day; - unsigned char Hour; - unsigned char Minute; - unsigned char Second; - unsigned char Offset; - unsigned char Flags; - unsigned char HandleUnit; - unsigned char HandleGap; - unsigned short VolSeq; - unsigned short BEVolSeq; - unsigned char N; - char id; -} PACKED; +extern const long sec_sizes[]; +extern const long sec_offsts[]; +extern const String sec_modes[]; -extern struct DirEntry rootDir; +class cdutils : public Base { + public: + cdutils(Handle * f_iso_r, Handle * f_iso_w = 0); + virtual ~cdutils(); -extern long sec_sizes[]; -extern long sec_offsts[]; -extern String sec_modes[]; + struct DirEntry { + unsigned char R; + unsigned char NExt; + unsigned long Sector; + unsigned long BESector; + unsigned long Size; + unsigned long BESize; + unsigned char Year; + unsigned char Month; + unsigned char Day; + unsigned char Hour; + unsigned char Minute; + unsigned char Second; + unsigned char Offset; + unsigned char Flags; + unsigned char HandleUnit; + unsigned char HandleGap; + unsigned short VolSeq; + unsigned short BEVolSeq; + unsigned char N; + char id; + } PACKED; -Handle * open_ppf(String ppf, Handle * iso, String comment) throw(GeneralException); -void close_ppf() throw(GeneralException); -unsigned short int swap_word(unsigned short int i); -unsigned long int swap_dword(unsigned long int i); -int guess_type(Handle * f_iso, int number); -void sector_seek(Handle * f_iso, long sector); -long read_sector(Handle * f_iso, Byte * buffer, int type, int number = -1); -void read_datas(Handle * f_iso, Byte * buffer, int type, int number, long size); -void read_file(Handle * f_iso, Handle * Handle, int type, int number, long size); -void write_sector(Handle * f_iso_r, Handle * f_iso_w, Byte * buffer, int type, int number = -1); -void write_datas(Handle * f_iso_r, Handle * f_iso_w, Byte * buffer, int type, int number, long size); -void write_file(Handle * f_iso_r, Handle * f_iso_w, Handle * Handle, int type, int number = -1); -int get_iso_infos(Handle * h); -int show_iso_infos(Handle * h); -int get_pt_infos(Handle * h); -int show_pt_infos(Handle * h); -struct DirEntry find_path(Handle * h, String path); -struct DirEntry find_parent(Handle * h, String path); -void show_head_entry(void); -int show_entry(struct DirEntry * dir); -int show_dir(Handle * h, struct DirEntry * dir); -struct DirEntry find_dir_entry(Handle * h, struct DirEntry * dir, String name); -struct DirEntry * find_dir_entry(Handle * h, Byte ** buffer, struct DirEntry * dir, String name); -unsigned char from_BCD(unsigned char x); -unsigned char to_BCD(unsigned char x); -int is_valid_BCD(unsigned char x); -unsigned long from_MSF(unsigned long msf, unsigned long start = 150); -unsigned long from_MSF(unsigned char m, unsigned char s, unsigned char f, unsigned long start = 150); + + struct DirEntry rootDir; + + Handle * open_ppf(String ppf, String comment) throw(GeneralException); + void close_ppf() throw(GeneralException); + void set_iso_w(Handle *); + unsigned short int swap_word(unsigned short int i); + unsigned long int swap_dword(unsigned long int i); + int guess_type(int number = -1); + void sector_seek(long sector); + long read_sector(Byte * buffer, int type, int number = -1); + void read_datas(Byte * buffer, int type, int number, long size); + void read_file(Handle * Handle, int type, int number, long size); + void write_sector(Byte * buffer, int type, int number = -1); + void write_datas(Byte * buffer, int type, int number, long size); + void write_file(Handle * Handle, int type, int number = -1); + int get_iso_infos(); + int show_iso_infos(); + int get_pt_infos(); + int show_pt_infos(); + struct DirEntry find_path(String path); + struct DirEntry find_parent(String path); + void show_head_entry(void); + int show_entry(struct DirEntry * dir); + int show_dir(struct DirEntry * dir); + struct DirEntry find_dir_entry(struct DirEntry * dir, String name); + struct DirEntry * find_dir_entry(Byte ** buffer, struct DirEntry * dir, String name); + unsigned char from_BCD(unsigned char x); + unsigned char to_BCD(unsigned char x); + int is_valid_BCD(unsigned char x); + unsigned long from_MSF(unsigned long msf, unsigned long start = 150); + unsigned long from_MSF(unsigned char m, unsigned char s, unsigned char f, unsigned long start = 150); + private: + void write_ppf(Byte * old_sec, Byte * new_sec, int sec_num); + String format_date(String input); + yazedc yazedc_o; + + Handle * f_iso_r, * f_iso_w, * ppf_file; + int pt1, pt2, snum, ptl, root; +}; #endif diff --git a/includes/generic.h b/includes/generic.h index 168c9d3..62a9942 100644 --- a/includes/generic.h +++ b/includes/generic.h @@ -79,6 +79,8 @@ typedef Uint32 DWord; #if defined __linux__ || defined __CYGWIN32__ #define PACKED __attribute__((packed)) +#else +#define PACKED #endif extern char verbosity; diff --git a/includes/lzss.h b/includes/lzss.h index 5bfa68a..17f4806 100644 --- a/includes/lzss.h +++ b/includes/lzss.h @@ -24,41 +24,57 @@ #include "generic.h" #include "Handle.h" -#define LZSS_VERSION "3.0.0-pre1" -#define LZSS_NAME "lzss" +#define LZSS_VERSION String("3.0.0-pre1") +#define LZSS_NAME String("lzss") -typedef struct { - char * name; - int one_is_compressed, bitmap_inversed, one_jump, overlap_trick, negative_trick, sixteen_bits, ptrb, filling; - int window_start; - int l_mask_1, l_shft_1, l_mask_2, l_shft_2; - int j_mask_1, j_shft_1, j_mask_2, j_shft_2; - int f_mask_1, f_shft_1, f_mask_2, f_shft_2; - int v_mask_1, v_shft_1, v_mask_2, v_shft_2; -} scheme_t; +class lzss : public Base { + public: + lzss(); + typedef struct { + char * name; + int one_is_compressed, bitmap_inversed, one_jump, overlap_trick, negative_trick, sixteen_bits, ptrb, filling; + int window_start; + int l_mask_1, l_shft_1, l_mask_2, l_shft_2; + int j_mask_1, j_shft_1, j_mask_2, j_shft_2; + int f_mask_1, f_shft_1, f_mask_2, f_shft_2; + int v_mask_1, v_shft_1, v_mask_2, v_shft_2; + } scheme_t; -enum { - XENO = 0, - DBZ, - FF7, - LM, - MM, - OB, - LODOSS, - FF6, - VP_1, - VP_2, - END -}; + enum { + XENO = 0, + DBZ, + FF7, + LM, + MM, + OB, + LODOSS, + FF6, + VP_1, + VP_2, + END + }; -extern scheme_t scheme, schemes[]; + static const scheme_t schemes[]; + int tolerate, blockb; + long blk, bitmap_count; -extern int tolerate, blockb; -extern long blk, bitmap_count; + unsigned long lzss_decomp(Handle * f_source, Handle * f_cible, long true_length = -1); + void lzss_comp(Handle * f_source, Handle * f_cible, long * delta = NULL); -unsigned long lzss_decomp(Handle * f_source, Handle * f_cible, long true_length = -1); -void lzss_comp(Handle * f_source, Handle * f_cible, long * delta = NULL); + Byte swap_bits(Byte); + + void change_scheme(scheme_t); + scheme_t get_scheme(); -char swap_bits(char); + private: + scheme_t scheme; + int lzss_maxsize, lzss_maxptr; + + unsigned int shift(unsigned int, int); + void compute_limits(void); + unsigned char lzss_rd(unsigned char *, long); + long lzss_comp_strstr(unsigned char *, unsigned char *, long *, long); + unsigned char * lzss_memcomp(unsigned char *, long *, long *); +}; #endif diff --git a/includes/yazedc.h b/includes/yazedc.h index b990d3e..298c0eb 100644 --- a/includes/yazedc.h +++ b/includes/yazedc.h @@ -22,6 +22,8 @@ #ifndef __YAZEDC_H__ +#include "Exceptions.h" + #define RS_L12_BITS 8 /* audio sector definitions for CIRC */ @@ -32,17 +34,6 @@ #define L1_Q 4 #define L1_P 4 -/* audio sector Cross Interleaved Reed-Solomon Code (CIRC) encoder (layer 1) */ -/* adds P- and Q- parity information to audio (f2) frames. Also - optionally handles the various delays and permutations. The output with all - stages enabled can be fed into the Eight-Fourteen-Modulator. - On input: 2352 bytes of audio data is given. - On output: 3136 bytes of CIRC enriched audio data are returned. - */ -int do_encode_L1(unsigned char in[L1_RAW*FRAMES_PER_SECTOR], - unsigned char out[(L1_RAW+L1_Q+L1_P)*FRAMES_PER_SECTOR], - int delay1, int delay2, int delay3, int scramble); - /* data sector definitions for RSPC */ /* user data bytes per frame */ #define L2_RAW (1024*2) @@ -57,14 +48,25 @@ int do_encode_L1(unsigned char in[L1_RAW*FRAMES_PER_SECTOR], #define MODE_2_FORM_1 3 #define MODE_2_FORM_2 4 -#ifdef __cplusplus -extern "C" { -#endif +/* r-w sub channel definitions */ +#define RS_SUB_RW_BITS 6 + +#define PACKETS_PER_SUBCHANNELFRAME 4 +#define LSUB_RAW 18 +#define LSUB_QRAW 2 +/* 6 bit */ +#define LSUB_Q 2 +#define LSUB_P 4 + +class yazedc : public Base { + + public: + yazedc(); /* set one of the MODE_* constants for subsequent data sector formatting */ -int set_sector_type(int st); + int set_sector_type(int st); /* get the current sector type setting for data sector formatting */ -int get_sector_type(void); + int get_sector_type(void); /* data sector layer 2 Reed-Solomon Product Code encoder */ /* encode the given data portion depending on sector type (see @@ -88,55 +90,18 @@ int get_sector_type(void); in the inout array. Sync-, header- and edc- fields will be added. */ -int do_encode_L2(unsigned char *inout, int sectortype, unsigned address); -int decode_L2_Q(unsigned char inout[4 + L2_RAW + 12 + L2_Q]); -int decode_L2_P(unsigned char inout[4 + L2_RAW + 12 + L2_Q + L2_P]); -unsigned long int build_edc(unsigned char inout[], int from, int upto); + int do_encode_L2(unsigned char *inout, int sectortype, unsigned address); /* generates f2 frames from otherwise fully formatted sectors (generated by do_encode_L2()). */ -int scramble_L2(unsigned char *inout); + int scramble_L2(unsigned char *inout); -#ifdef __cplusplus -} -#endif - -/* r-w sub channel definitions */ -#define RS_SUB_RW_BITS 6 + unsigned char minute, second, frame; -#define PACKETS_PER_SUBCHANNELFRAME 4 -#define LSUB_RAW 18 -#define LSUB_QRAW 2 -/* 6 bit */ -#define LSUB_Q 2 -#define LSUB_P 4 - -#ifdef __cplusplus -extern "C" { -#endif - -/* R-W subchannel encoder */ -/* On input: 72 bytes packed user data, four frames with each 18 bytes. - On output: per frame: 2 bytes user data, 2 bytes Q parity, - 16 bytes user data, 4 bytes P parity. - Options: - delay1: use low level delay line - scramble: perform low level permutations - */ -int do_encode_sub(unsigned char in[LSUB_RAW*PACKETS_PER_SUBCHANNELFRAME], - unsigned char out[(LSUB_RAW+LSUB_Q+LSUB_P)*PACKETS_PER_SUBCHANNELFRAME], - int delay1, int scramble); -int do_decode_sub(unsigned char in[(LSUB_RAW+LSUB_Q+LSUB_P)*PACKETS_PER_SUBCHANNELFRAME], - unsigned char out[LSUB_RAW*PACKETS_PER_SUBCHANNELFRAME], - int delay1, int scramble); - -int decode_LSUB_Q(unsigned char inout[LSUB_QRAW + LSUB_Q]); -int decode_LSUB_P(unsigned char inout[LSUB_RAW + LSUB_Q + LSUB_P]); - -#ifdef __cplusplus -} -#endif + private: + int sectortype; + int build_address(unsigned char inout[], int sectortype, unsigned address); -extern unsigned char minute, second, frame; +}; #endif diff --git a/lib/Makefile b/lib/Makefile index 101a91e..79aae21 100755 --- a/lib/Makefile +++ b/lib/Makefile @@ -3,7 +3,7 @@ CPPFLAGS=-Wall -g -O3 -mcpu=i686 -Werror -I../includes -DHAVE_ZLIB CXX=g++ -OBJECTS = cdutils.o lzss.o yazedc.o dteutils.o cdreader.o +OBJECTS = cdutils.o lzss.o yazedc.o dteutils.o cdreader.o cdabstract.o TARGET = lib.a all: ${TARGET} diff --git a/lib/cdreader.cpp b/lib/cdreader.cpp index 3459f11..77b14f9 100644 --- a/lib/cdreader.cpp +++ b/lib/cdreader.cpp @@ -14,23 +14,23 @@ #define _(x) x #endif -bool cdreader::CanWrite() { +bool cdreader::CanWrite() const { return 0; } -bool cdreader::CanRead() { +bool cdreader::CanRead() const { return 1; } -bool cdreader::CanSeek() { +bool cdreader::CanSeek() const { return 1; } -String cdreader::GetName() { +String cdreader::GetName() const { return n + " raw reading"; } -ssize_t cdreader::GetSize() { +ssize_t cdreader::GetSize() const { return -1; } diff --git a/lib/cdutils.cpp b/lib/cdutils.cpp index 1049535..0f7aa76 100644 --- a/lib/cdutils.cpp +++ b/lib/cdutils.cpp @@ -26,32 +26,34 @@ #include "cdutils.h" #include "Output.h" -Output * ppf_file = 0; -int pt1 = -1, pt2 = -1, snum = 0, ptl = 0, root = 0; +const long sec_sizes[6] = {0, 2048, 2336, 2048, 2324, 2352}; +const long sec_offsts[6] = {0, 16, 16, 24, 24, 0}; +const String sec_modes[6] = {"MODE 0 (empty)", "MODE 1", "MODE 2", "MODE 2 FORM 1", "MODE 2 FORM 2", "Autodetect"}; -long sec_sizes[5] = {0, 2048, 2336, 2048, 2324}; -long sec_offsts[5] = {0, 16, 16, 24, 24}; -String sec_modes[5] = {"MODE 0 (no mode)", "MODE 1", "MODE 2", "MODE 2 FORM 1", "MODE 2 FORM 2"}; +cdutils::cdutils(Handle * r, Handle * w) : f_iso_r(r), f_iso_w(w), ppf_file(0), pt1(-1), pt2(-1), snum(0), ptl(0), root(0) {} -struct DirEntry rootDir; +cdutils::~cdutils() { + if (ppf_file) + delete ppf_file; +} -unsigned char from_BCD(unsigned char x) { +unsigned char cdutils::from_BCD(unsigned char x) { return ((x & 0xf) + ((x & 0xf0) >> 4) * 10); } -unsigned char to_BCD(unsigned char x) { +unsigned char cdutils::to_BCD(unsigned char x) { return ((x / 10) << 4) | (x % 10); } -int is_valid_BCD(unsigned char x) { +int cdutils::is_valid_BCD(unsigned char x) { return (((x & 15) < 10) && ((x >> 4) < 10)); } -unsigned long from_MSF(unsigned char m, unsigned char s, unsigned char f, unsigned long start) { +unsigned long cdutils::from_MSF(unsigned char m, unsigned char s, unsigned char f, unsigned long start) { return (from_BCD(m) * 60 + from_BCD(s)) * 75 + from_BCD(f) - start; } -unsigned long from_MSF(unsigned long msf, unsigned long start) { +unsigned long cdutils::from_MSF(unsigned long msf, unsigned long start) { unsigned char f = msf & 0xff, s = (msf >> 8) & 0xff, @@ -60,9 +62,8 @@ unsigned long from_MSF(unsigned long msf, unsigned long start) { return from_MSF(m, s, f, start); } -Handle * open_ppf(String ppf, Handle * iso, String comment) throw (GeneralException) { +Handle * cdutils::open_ppf(String ppf, String comment) throw (GeneralException) { int i, l; - Byte buffer[1024]; if (ppf_file) throw GeneralException("Tried to open_ppf() while already opened."); @@ -80,16 +81,15 @@ Handle * open_ppf(String ppf, Handle * iso, String comment) throw (GeneralExcept } } - l = iso->GetSize(); + l = f_iso_r->GetSize(); ppf_file->write(&l, sizeof(l)); - iso->seek(0x9320, SEEK_SET); - iso->read(buffer, 1024); - ppf_file->write(buffer, 1024); + f_iso_r->seek(0x9320, SEEK_SET); + copy(f_iso_r, ppf_file, 1024); return ppf_file; } -void write_ppf(Byte * old_sec, Byte * new_sec, int sec_num) { +void cdutils::write_ppf(Byte * old_sec, Byte * new_sec, int sec_num) { int i, l = 0, o; for (i = 0; i < 2352; i++) { @@ -114,7 +114,7 @@ void write_ppf(Byte * old_sec, Byte * new_sec, int sec_num) { } } -void close_ppf() throw (GeneralException) { +void cdutils::close_ppf() throw (GeneralException) { if (ppf_file) { delete ppf_file; ppf_file = 0; @@ -123,7 +123,12 @@ void close_ppf() throw (GeneralException) { } } -String format_date(String input) { +void cdutils::set_iso_w(Handle * w) { + if (!f_iso_w) + f_iso_w = w; +} + +String cdutils::format_date(String input) { String output; output = input.extract(6, 7) + '/'; @@ -137,23 +142,23 @@ String format_date(String input) { return output; } -Uint16 swap_word(Uint16 i) { +Uint16 cdutils::swap_word(Uint16 i) { return (i >> 8) | (i << 8); } -Uint32 swap_dword(Uint32 i) { +Uint32 cdutils::swap_dword(Uint32 i) { return (i >> 24) | ((i >> 8) & 0x0000ff00) | ((i << 8) & 0x00ff0000) | (i << 24); } -int guess_type(Handle * f_iso, int number) { +int cdutils::guess_type(int number) { Byte header[24]; if (number >= 0) { - sector_seek(f_iso, number); + sector_seek(number); } - f_iso->read(header, 24); - f_iso->seek(-24, SEEK_CUR); + f_iso_r->read(header, 24); + f_iso_r->seek(-24, SEEK_CUR); if (header[15] == 1) { return MODE_1; } else if (header[15] == 2) { @@ -172,136 +177,137 @@ int guess_type(Handle * f_iso, int number) { return MODE_0; } -void sector_seek(Handle * f_iso, long sector) { - f_iso->seek(2352 * sector); +void cdutils::sector_seek(long sector) { + f_iso_r->seek(2352 * sector); + if (f_iso_w) + f_iso_w->seek(2352 * sector); } -long read_sector(Handle * f_iso, Byte * buffer, int type, int number) { +long cdutils::read_sector(Byte * buffer, int type, int number) { if (number >= 0) { - sector_seek(f_iso, number); + sector_seek(number); } if (type == GUESS) { - type = guess_type(f_iso, number); + type = guess_type(); } - f_iso->seek(sec_offsts[type], SEEK_CUR); - f_iso->read(buffer, sec_sizes[type]); - f_iso->seek(2352 - sec_offsts[type] - sec_sizes[type], SEEK_CUR); + f_iso_r->seek(sec_offsts[type], SEEK_CUR); + f_iso_r->read(buffer, sec_sizes[type]); + f_iso_r->seek(2352 - sec_offsts[type] - sec_sizes[type], SEEK_CUR); return sec_sizes[type]; } -void read_datas(Handle * f_iso, Byte * buffer, int type, int number, long size) { +void cdutils::read_datas(Byte * buffer, int type, int number, long size) { Byte sector[2352]; int i, n, reste; if (type == GUESS) { - type = guess_type(f_iso, number); + type = guess_type(number); } n = size / sec_sizes[type]; reste = size - n * sec_sizes[type]; - sector_seek(f_iso, number); + sector_seek(number); for (i = 0; i < n; i++) { - read_sector(f_iso, buffer + i * sec_sizes[type], type); + read_sector(buffer + i * sec_sizes[type], type); } if (reste) { - read_sector(f_iso, sector, type); + read_sector(sector, type); bcopy((char *) sector, (char *) (buffer + n * sec_sizes[type]), reste); } } -void read_file(Handle * f_iso, Handle * file, int type, int number, long size) { +void cdutils::read_file(Handle * file, int type, int number, long size) { Byte sector[2352]; int i, n, reste; if (type == GUESS) { - type = guess_type(f_iso, number); + type = guess_type(number); } n = size / sec_sizes[type]; reste = size - n * sec_sizes[type]; - sector_seek(f_iso, number); + sector_seek(number); for (i = 0; i < n; i++) { - read_sector(f_iso, sector, type); + read_sector(sector, type); file->write(sector, sec_sizes[type]); } if (reste) { - read_sector(f_iso, sector, type); + read_sector(sector, type); file->write(sector, reste); } } -void write_sector(Handle * f_iso_r, Handle * f_iso_w, Byte * buffer, int type, int number) { +void cdutils::write_sector(Byte * buffer, int type, int number) { Byte old_sector[2352], new_sector[2352]; if (type == GUESS) { - type = guess_type(f_iso_r, number); + type = guess_type(number); } if (number >= 0) { - sector_seek(f_iso_r, number); - sector_seek(f_iso_w, number); + sector_seek(number); } f_iso_r->read(old_sector, 2352); - minute = old_sector[12]; - second = old_sector[13]; - frame = old_sector[14]; + yazedc_o.minute = old_sector[12]; + yazedc_o.second = old_sector[13]; + yazedc_o.frame = old_sector[14]; bcopy((char *) old_sector, (char *) new_sector, 2532); bcopy((char *) buffer, (char *) new_sector + sec_offsts[type], sec_sizes[type]); - do_encode_L2(new_sector, type, 0); - if (!ppf_file) { + yazedc_o.do_encode_L2(new_sector, type, 0); + if (f_iso_w) { f_iso_w->write(new_sector, 2352); - } else { + } else if (ppf_file) { write_ppf(old_sector, new_sector, number); + } else { + printm(M_ERROR, "No writing method for iso file"); } } -void write_datas(Handle * f_iso_r, Handle * f_iso_w, Byte * buffer, int type, int number, long size) { +void cdutils::write_datas(Byte * buffer, int type, int number, long size) { long nbsectors, i; unsigned char sector[2352]; if (type == GUESS) { - type = guess_type(f_iso_r, number); + type = guess_type(number); } if (number >= 0) { - sector_seek(f_iso_r, number); - sector_seek(f_iso_w, number); + sector_seek(number); } nbsectors = size / sec_sizes[type]; for (i = 0; i < nbsectors; i++) { - write_sector(f_iso_r, f_iso_w, buffer + i * sec_sizes[type], type, number + i); + write_sector(buffer + i * sec_sizes[type], type, number + i); } if (size % sec_sizes[type]) { memset(sector, 0, 2352); bcopy((char *) (buffer + i * sec_sizes[type]), (char *) sector, size % sec_sizes[type]); - write_sector(f_iso_r, f_iso_w, sector, type, number + i); + write_sector(sector, type, number + i); } } -void write_file(Handle * f_iso_r, Handle * f_iso_w, Handle * file, int type, int number) { +void cdutils::write_file(Handle * file, int type, int number) { long size, nbsectors, i; unsigned char buffer[2352]; if (type == GUESS) { - type = guess_type(f_iso_r, number); + type = guess_type(number); } if (number >= 0) { - sector_seek(f_iso_r, number); - sector_seek(f_iso_w, number); + sector_seek(number); } size = file->GetSize(); @@ -314,15 +320,15 @@ void write_file(Handle * f_iso_r, Handle * f_iso_w, Handle * file, int type, int for (i = 0; i < nbsectors; i++) { memset(buffer, 0, 2352); file->read(buffer, sec_sizes[type]); - write_sector(f_iso_r, f_iso_w, buffer, type); + write_sector(buffer, type); } } -void show_head_entry(void) { +void cdutils::show_head_entry(void) { printm(M_BARE, "Sector - Size - Date - Time - Flags - Name\n"); } -int show_entry(struct DirEntry * dir) { +int cdutils::show_entry(struct DirEntry * dir) { char pbuf[200]; if (!dir->R) { return 1; @@ -338,7 +344,7 @@ int show_entry(struct DirEntry * dir) { return dir->R; } -int show_dir(Handle * f_iso, struct DirEntry * dir) { +int cdutils::show_dir(struct DirEntry * dir) { unsigned int ptr; Byte * buffer; @@ -347,7 +353,7 @@ int show_dir(Handle * f_iso, struct DirEntry * dir) { } buffer = (Byte *) malloc(dir->Size); - read_datas(f_iso, buffer, GUESS, dir->Sector, dir->Size); + read_datas(buffer, GUESS, dir->Sector, dir->Size); ptr = 0; while(ptr < dir->Size) { @@ -358,7 +364,7 @@ int show_dir(Handle * f_iso, struct DirEntry * dir) { return 1; } -struct DirEntry find_dir_entry(Handle * f_iso, struct DirEntry * dir, String name) { +struct cdutils::DirEntry cdutils::find_dir_entry(struct DirEntry * dir, String name) { unsigned int ptr, size; unsigned char * buffer; struct DirEntry r = {0, 0, 0, 0, 0}; @@ -368,7 +374,7 @@ struct DirEntry find_dir_entry(Handle * f_iso, struct DirEntry * dir, String nam } buffer = (unsigned char *) malloc(size = dir->Size); - read_datas(f_iso, buffer, GUESS, dir->Sector, dir->Size); + read_datas(buffer, GUESS, dir->Sector, dir->Size); ptr = 0; while(ptr < size) { @@ -387,7 +393,7 @@ struct DirEntry find_dir_entry(Handle * f_iso, struct DirEntry * dir, String nam return r; } -struct DirEntry * find_dir_entry(Handle * f_iso, Byte ** bufout, struct DirEntry * dir, String name) { +struct cdutils::DirEntry * cdutils::find_dir_entry(Byte ** bufout, struct cdutils::DirEntry * dir, String name) { unsigned int ptr, size; Byte * buffer; struct DirEntry * rdir = 0; @@ -398,7 +404,7 @@ struct DirEntry * find_dir_entry(Handle * f_iso, Byte ** bufout, struct DirEntry } buffer = (Byte *) malloc(size = dir->Size); - read_datas(f_iso, buffer, GUESS, dir->Sector, dir->Size); + read_datas(buffer, GUESS, dir->Sector, dir->Size); ptr = 0; while(ptr < size) { @@ -421,14 +427,14 @@ struct DirEntry * find_dir_entry(Handle * f_iso, Byte ** bufout, struct DirEntry return rdir; } -int show_iso_infos(Handle * f_iso) { +int cdutils::show_iso_infos() { char buffer[2048]; char pbuff[130]; short int s, nogood = 0; - read_sector(f_iso, (Byte *) buffer, GUESS, 16); + read_sector((Byte *) buffer, GUESS, 16); - printm(M_BARE, "Sector guessed mode : " + sec_modes[guess_type(f_iso, 16)] + "\n"); + printm(M_BARE, "Sector guessed mode : " + sec_modes[guess_type(16)] + "\n"); printm(M_BARE, "offset-size-info : contents\n"); printm(M_BARE, " 0 - 1- 1 : %i\n", buffer[0]); memcpy(pbuff, buffer + 1, 5); @@ -481,10 +487,10 @@ int show_iso_infos(Handle * f_iso) { memcpy(pbuff, buffer + 776, 37); pbuff[37] = 0; printm(M_BARE, " 776 - 37- BibFile: %s\n", pbuff); - printm(M_BARE, " 813 - 17- DTCreat: %s\n", format_date(&buffer[813]).to_charp()); - printm(M_BARE, " 830 - 17- DTModif: %s\n", format_date(&buffer[830]).to_charp()); - printm(M_BARE, " 847 - 17- DTExpir: %s\n", format_date(&buffer[847]).to_charp()); - printm(M_BARE, " 864 - 17- DTEffec: %s\n", format_date(&buffer[864]).to_charp()); + printm(M_BARE, " 813 - 17- DTCreat: " + format_date(&buffer[813]) + "\n"); + printm(M_BARE, " 830 - 17- DTModif: " + format_date(&buffer[830]) + "\n"); + printm(M_BARE, " 847 - 17- DTExpir: " + format_date(&buffer[847]) + "\n"); + printm(M_BARE, " 864 - 17- DTEffec: " + format_date(&buffer[864]) + "\n"); printm(M_BARE, "Root record:\n"); show_head_entry(); @@ -493,12 +499,12 @@ int show_iso_infos(Handle * f_iso) { return 1; } -int get_iso_infos(Handle * f_iso) { +int cdutils::get_iso_infos() { unsigned char buffer[2048]; char pbuff[130]; short int s, nogood = 0; - read_sector(f_iso, buffer, GUESS, 16); + read_sector(buffer, GUESS, 16); memcpy(pbuff, buffer + 1, 5); pbuff[5] = 0; @@ -521,11 +527,11 @@ int get_iso_infos(Handle * f_iso) { return 1; } -int get_pt_infos(Handle * f_iso) { +int cdutils::get_pt_infos() { Byte * buffer; if ((pt1 <= 0) && (pt2 <= 0)) - if (!get_iso_infos(f_iso)) + if (!get_iso_infos()) return 0; if ((!pt1) & (!pt2)) { @@ -534,7 +540,7 @@ int get_pt_infos(Handle * f_iso) { } buffer = (Byte *) malloc(ptl); - read_datas(f_iso, buffer, GUESS, !pt1 ? pt2 : pt1, ptl); + read_datas(buffer, GUESS, !pt1 ? pt2 : pt1, ptl); if (buffer[0] == 1) if (buffer[1] == 0) @@ -548,13 +554,13 @@ int get_pt_infos(Handle * f_iso) { return root ? 1 : 0; } -int show_pt_infos(Handle * f_iso) { +int cdutils::show_pt_infos() { Byte * buffer; char pbuf[100]; int i, ptr; if ((pt1 <= 0) && (pt2 <= 0)) - if (!get_iso_infos(f_iso)) + if (!get_iso_infos()) return 0; if ((!pt1) & (!pt2)) { @@ -563,7 +569,7 @@ int show_pt_infos(Handle * f_iso) { } buffer = (Byte *) malloc(ptl); - read_datas(f_iso, buffer, GUESS, !pt1 ? pt2 : pt1, ptl); + read_datas(buffer, GUESS, !pt1 ? pt2 : pt1, ptl); printm(M_BARE, "node^paren@sector : name\n"); for (ptr = 0, i = 1; buffer[ptr]; ptr += ptr & 1, i++) { @@ -577,13 +583,13 @@ int show_pt_infos(Handle * f_iso) { return 1; } -struct DirEntry find_path(Handle * f_iso, String path) { +struct cdutils::DirEntry cdutils::find_path(String path) { char * newpath = path.strdup(); char ** pts = split(newpath, '/'); struct DirEntry dir = {0, 0, 0, 0, 0}; if ((pt1 <= 0) && (pt2 <= 0)) - if (!get_iso_infos(f_iso)) { + if (!get_iso_infos()) { free(newpath); return dir; } @@ -600,7 +606,7 @@ struct DirEntry find_path(Handle * f_iso, String path) { for (dir = rootDir; *pts; pts++) { if (!strlen(*pts)) continue; - dir = find_dir_entry(f_iso, &dir, *pts); + dir = find_dir_entry(&dir, *pts); if (!dir.R) { free(newpath); return dir; @@ -611,7 +617,7 @@ struct DirEntry find_path(Handle * f_iso, String path) { return dir; } -struct DirEntry find_parent(Handle * f_iso, String path) { +struct cdutils::DirEntry cdutils::find_parent(String path) { char * newpath = path.strdup(); char ** pts, * p; struct DirEntry dir = {0, 0, 0, 0, 0}; @@ -626,7 +632,7 @@ struct DirEntry find_parent(Handle * f_iso, String path) { pts = split(newpath, '/'); if ((pt1 <= 0) && (pt2 <= 0)) - if (!get_iso_infos(f_iso)) { + if (!get_iso_infos()) { free(newpath); return dir; } @@ -643,7 +649,7 @@ struct DirEntry find_parent(Handle * f_iso, String path) { for (dir = rootDir; *pts; pts++) { if (!strlen(*pts)) continue; - dir = find_dir_entry(f_iso, &dir, *pts); + dir = find_dir_entry(&dir, *pts); if (!dir.R) { free(newpath); return dir; diff --git a/lib/crctable.out b/lib/crctable.out index 47842cd..f70577e 100644 --- a/lib/crctable.out +++ b/lib/crctable.out @@ -18,7 +18,7 @@ /* */
/*****************************************************************/
-unsigned long EDC_crctable[256] =
+const unsigned long EDC_crctable[256] =
{
0x00000000L, 0x90910101L, 0x91210201L, 0x01B00300L,
0x92410401L, 0x02D00500L, 0x03600600L, 0x93F10701L,
diff --git a/lib/crctables b/lib/crctables index 3dd89c1..0f2a0a3 100644 --- a/lib/crctables +++ b/lib/crctables @@ -1,42 +1,20 @@ -static unsigned char rs_l12_alog[255] = {
+const static unsigned char rs_l12_alog[255] = {
1, 2, 4, 8,16,32,64,128,29,58,116,232,205,135,19,38,76,152,45,90,180,117,234,201,143, 3, 6,12,24,48,96,192,157,39,78,156,37,74,148,53,106,212,181,119,238,193,159,35,70,140, 5,10,20,40,80,160,93,186,105,210,185,111,222,161,95,190,97,194,153,47,94,188,101,202,137,15,30,60,120,240,253,231,211,187,107,214,177,127,254,225,223,163,91,182,113,226,217,175,67,134,17,34,68,136,13,26,52,104,208,189,103,206,129,31,62,124,248,237,199,147,59,118,236,197,151,51,102,204,133,23,46,92,184,109,218,169,79,158,33,66,132,21,42,84,168,77,154,41,82,164,85,170,73,146,57,114,228,213,183,115,230,209,191,99,198,145,63,126,252,229,215,179,123,246,241,255,227,219,171,75,150,49,98,196,149,55,110,220,165,87,174,65,130,25,50,100,200,141, 7,14,28,56,112,224,221,167,83,166,81,162,89,178,121,242,249,239,195,155,43,86,172,69,138, 9,18,36,72,144,61,122,244,245,247,243,251,235,203,139,11,22,44,88,176,125,250,233,207,131,27,54,108,216,173,71,142,};
-static unsigned char rs_l12_log[256] = {
+ +const static unsigned char rs_l12_log[256] = {
0, 0, 1,25, 2,50,26,198, 3,223,51,238,27,104,199,75, 4,100,224,14,52,141,239,129,28,193,105,248,200, 8,76,113, 5,138,101,47,225,36,15,33,53,147,142,218,240,18,130,69,29,181,194,125,106,39,249,185,201,154, 9,120,77,228,114,166, 6,191,139,98,102,221,48,253,226,152,37,179,16,145,34,136,54,208,148,206,143,150,219,189,241,210,19,92,131,56,70,64,30,66,182,163,195,72,126,110,107,58,40,84,250,133,186,61,202,94,155,159,10,21,121,43,78,212,229,172,115,243,167,87, 7,112,192,247,140,128,99,13,103,74,222,237,49,197,254,24,227,165,153,119,38,184,180,124,17,68,146,217,35,32,137,46,55,63,209,91,149,188,207,205,144,135,151,178,220,252,190,97,242,86,211,171,20,42,93,158,132,60,57,83,71,109,65,162,31,45,67,216,183,123,164,118,196,23,73,236,127,12,111,246,108,161,59,82,41,157,85,170,251,96,134,177,187,204,62,90,203,89,95,176,156,169,160,81,11,245,22,235,122,117,44,215,79,174,213,233,230,231,173,232,116,214,244,234,168,80,88,175,};
-static unsigned char rs_sub_rw_alog[63] = {
- 1, 2, 4, 8,16,32, 3, 6,12,24,48,35, 5,10,20,40,19,38,15,30,60,59,53,41,17,34, 7,14,28,56,51,37, 9,18,36,11,22,44,27,54,47,29,58,55,45,25,50,39,13,26,52,43,21,42,23,46,31,62,63,61,57,49,33,};
-static unsigned char rs_sub_rw_log[63] = {
- 0, 0, 1, 6, 2,12, 7,26, 3,32,13,35, 8,48,27,18, 4,24,33,16,14,52,36,54, 9,45,49,38,28,41,19,56, 5,62,25,11,34,31,17,47,15,23,53,51,37,44,55,40,10,61,46,30,50,22,39,43,29,60,42,21,20,59,57,};
-static unsigned char SQ[2][2] = {
-{26,6,},
-{7,1,},
-};
-static unsigned char SP[4][20] = {
-{57,38,44,29,17,57,53,58,60,39,12,38,18,41,6,25,39,37,5,18,},
-{38,62,42,13,30,11,46,5,54,26,12,49,48,46,8,50,28,9,12,39,},
-{32,18,41,49,52,62,38,36,39,58,37,24,34,51,51,27,28,36,22,21,},
-{44,50,35,23,0,59,1,3,45,18,44,24,47,12,31,45,43,11,24,6,},
-};
-static unsigned char AQ[4][24] = {
-{58,152,173,95,88,43,134,205,143,131,163,75,37,109,194,159,168,227,153,59,101,},
-{30,214,148,138,112,154,157,96,49,198,189,249,83,23,70,237,70,41,47,52,125,247,},
-{162,244,13,171,213,236,71,177,253,162,59,78,46,68,238,112,147,197,115,200,117,15,236,},
-{158,179,101,94,49,140,211,149,137,169,81,6,33,30,27,24,21,18,15,12,9,6,3,0,},
-};
-static unsigned char AP[4][32] = {
-{140,143,52,103,249,142,180,197,5,155,153,132,143,244,101,76,102,155,203,104,58,152,173,95,88,43,134,205,143,131,163,75,},
-{104,97,17,162,205,252,218,199,202,41,136,106,119,238,193,103,123,242,83,178,30,214,148,138,112,154,157,96,49,198,189,249,},
-{240,119,29,185,67,11,131,40,7,41,80,147,151,17,245,253,208,66,228,116,162,244,13,171,213,236,71,177,253,162,59,78,},
-{149,58,109,0,148,186,203,11,161,159,138,149,250,107,82,108,161,209,110,64,158,179,101,94,49,140,211,149,137,169,81,6,},
-};
-static unsigned char DQ[2][43] = {
+ +const static unsigned char DQ[2][43] = {
{190,96,250,132,59,81,159,154,200,7,111,245,10,20,41,156,168,79,173,231,229,171,210,240,17,67,215,43,120,8,199,74,102,220,251,95,175,87,166,113,75,198,25,},
{97,251,133,60,82,160,155,201,8,112,246,11,21,42,157,169,80,174,232,230,172,211,241,18,68,216,44,121,9,200,75,103,221,252,96,176,88,167,114,76,199,26,1,},
};
-static unsigned char DP[2][24] = {
+ +const static unsigned char DP[2][24] = {
{231,229,171,210,240,17,67,215,43,120,8,199,74,102,220,251,95,175,87,166,113,75,198,25,},
{230,172,211,241,18,68,216,44,121,9,200,75,103,221,252,96,176,88,167,114,76,199,26,1,},
};
-static unsigned char yellowbook_scrambler[2340] = {
+ +const static unsigned char yellowbook_scrambler[2340] = {
1,128,0,96,0,40,0,30,128,8,96,6,168,2,254,129,128,96,96,40,40,30,158,
136,104,102,174,170,252,127,1,224,0,72,0,54,128,22,224,14,200,4,86,131,126,225,
224,72,72,54,182,150,246,238,198,204,82,213,253,159,1,168,0,126,128,32,96,24,40,
diff --git a/lib/lzss.cpp b/lib/lzss.cpp index b57f325..a991f07 100644 --- a/lib/lzss.cpp +++ b/lib/lzss.cpp @@ -26,12 +26,11 @@ #include "lzss.h" #include "Handle.h" -int lzss_maxsize = 18; -int lzss_maxptr = 0x0fff; -int tolerate = 1; -int blockb = 0; +lzss::lzss() : tolerate(1), blockb(0), scheme(schemes[0]), lzss_maxsize(18), lzss_maxptr(0x0fff) { + compute_limits(); +} -scheme_t schemes[] = { +const lzss::scheme_t lzss::schemes[] = { /* Nom 1 I J O N 16 P F W Lm1 Ls1 Lm2 Ls2 Jm1 Js1 Jm2 Js2 Fm1 Fs1 Fm2 Fs2 Vm1 Vs1 Vm2 Vs2 */ {"Xenogears", 1, 0, 0, 1, 0, 0, 0, 0, 0, 0x00, 0, 0xf0, -4, 0xff, 0, 0x0f, 8, 0x00, 0, 0x00, 0, 0x00, 0, 0x00, 0}, {"DBZ RPG", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x0f, 0, 0x00, 0, 0xf0, -4, 0xff, 4, 0x00, 0, 0x00, 0, 0x00, 0, 0x00, 0}, @@ -46,20 +45,18 @@ scheme_t schemes[] = { {0 , 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x00, 0, 0x00, 0, 0x00, 0, 0x00, 0} }; -scheme_t scheme = schemes[0]; - -char swap_bits(char i) { +Byte lzss::swap_bits(Byte i) { i = ((i >> 1) & 0x55) | ((i << 1) & 0xaa); i = ((i >> 2) & 0x33) | ((i << 2) & 0xcc); i = ((i >> 4) & 0x0f) | ((i << 4) & 0xf0); return i; } -unsigned int shift(unsigned int c, int s) { +unsigned int lzss::shift(unsigned int c, int s) { return s > 0 ? (c << s) : c >> (-s); } -void compute_limits(void) { +void lzss::compute_limits(void) { unsigned char val1, val2; val1 = val2 = 0xff; @@ -95,7 +92,7 @@ void compute_limits(void) { printm(M_INFO, "Computed values: maxsize = %i, maxptr = 0x%06x\n", lzss_maxsize, lzss_maxptr); } -unsigned long lzss_decomp(Handle * f_source, Handle * f_cible, long true_length) +unsigned long lzss::lzss_decomp(Handle * f_source, Handle * f_cible, long true_length) { unsigned char bitmap, fbitmap; unsigned char valeur; @@ -242,11 +239,11 @@ unsigned long lzss_decomp(Handle * f_source, Handle * f_cible, long true_length) return length; } -unsigned char lzss_rd(unsigned char * t, long p) { +unsigned char lzss::lzss_rd(unsigned char * t, long p) { return ((p < 0) ? 0 : (t[p])); } -long lzss_comp_strstr(unsigned char * needle, unsigned char * r, long * l, long sp) { +long lzss::lzss_comp_strstr(unsigned char * needle, unsigned char * r, long * l, long sp) { char redo[256]; long length, i, p, ptr, maxlength; @@ -291,9 +288,7 @@ long lzss_comp_strstr(unsigned char * needle, unsigned char * r, long * l, long return ptr; } -long blk, bitmap_count; - -unsigned char * lzss_memcomp(unsigned char * r, long * l, long * delta) { +unsigned char * lzss::lzss_memcomp(unsigned char * r, long * l, long * delta) { unsigned char bitmap, * comp; long ptr, needle, needle_length, comp_ptr, bitmap_ptr, val1, val2; long jump, farest, remaining; @@ -418,7 +413,7 @@ unsigned char * lzss_memcomp(unsigned char * r, long * l, long * delta) { return comp; } -void lzss_comp(Handle * f_source, Handle * f_cible, long * delta) { +void lzss::lzss_comp(Handle * f_source, Handle * f_cible, long * delta) { long length = f_source->GetSize(), l; unsigned char * r = (unsigned char *) malloc(length), * c; @@ -436,3 +431,12 @@ void lzss_comp(Handle * f_source, Handle * f_cible, long * delta) { free(c); free(r); } + +void lzss::change_scheme(scheme_t new_scheme) { + scheme = new_scheme; + compute_limits(); +} + +lzss::scheme_t lzss::get_scheme() { + return scheme; +} diff --git a/lib/yazedc.cpp b/lib/yazedc.cpp index f4bced0..4f6144c 100644 --- a/lib/yazedc.cpp +++ b/lib/yazedc.cpp @@ -26,199 +26,14 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include "yazedc.h" -#define RS_L12_BITS 8 - -/* audio sector definitions for CIRC */ -#define FRAMES_PER_SECTOR 98 -/* user data bytes per frame */ -#define L1_RAW 24 -/* parity bytes with 8 bit */ -#define L1_Q 4 -#define L1_P 4 - -/* audio sector Cross Interleaved Reed-Solomon Code (CIRC) encoder (layer 1) */ -/* adds P- and Q- parity information to audio (f2) frames. Also - optionally handles the various delays and permutations. The output with all - stages enabled can be fed into the Eight-Fourteen-Modulator. - On input: 2352 bytes of audio data is given. - On output: 3136 bytes of CIRC enriched audio data are returned. - */ -int do_encode_L1(unsigned char in[L1_RAW*FRAMES_PER_SECTOR], - unsigned char out[(L1_RAW+L1_Q+L1_P)*FRAMES_PER_SECTOR], - int delay1, int delay2, int delay3, int scramble); - -/* data sector definitions for RSPC */ -/* user data bytes per frame */ -#define L2_RAW (1024*2) -/* parity bytes for 16 bit units */ -#define L2_Q (26*2*2) -#define L2_P (43*2*2) - -/* known sector types */ -#define MODE_0 0 -#define MODE_1 1 -#define MODE_2 2 -#define MODE_2_FORM_1 3 -#define MODE_2_FORM_2 4 - -#ifdef __cplusplus -extern "C" { -#endif - -/* set one of the MODE_* constants for subsequent data sector formatting */ -int set_sector_type(int st); -/* get the current sector type setting for data sector formatting */ -int get_sector_type(void); - -/* data sector layer 2 Reed-Solomon Product Code encoder */ -/* encode the given data portion depending on sector type (see - get/set_sector_type() functions). Use the given address for the header. - The returned data is __unscrambled__ and not in F2-frame format (for that - see function scramble_L2()). - Supported sector types: - MODE_0: a 12-byte sync field, a header and 2336 zeros are returned. - MODE_1: the user data portion (2048 bytes) has to be given - at offset 16 in the inout array. - Sync-, header-, edc-, spare-, p- and q- fields will be added. - MODE_2: the user data portion (2336 bytes) has to be given - at offset 16 in the inout array. - Sync- and header- fields will be added. - MODE_2_FORM_1: the user data portion (8 bytes subheader followed - by 2048 bytes data) has to be given at offset 16 - in the inout array. - Sync-, header-, edc-, p- and q- fields will be added. - MODE_2_FORM_2: the user data portion (8 bytes subheader followed - by 2324 bytes data) has to be given at offset 16 - in the inout array. - Sync-, header- and edc- fields will be added. -*/ -int do_encode_L2(unsigned char *inout, int sectortype, unsigned address); -int decode_L2_Q(unsigned char inout[4 + L2_RAW + 12 + L2_Q]); -int decode_L2_P(unsigned char inout[4 + L2_RAW + 12 + L2_Q + L2_P]); -unsigned long int build_edc(unsigned char inout[], int from, int upto); - -/* generates f2 frames from otherwise fully formatted sectors (generated by - do_encode_L2()). */ -int scramble_L2(unsigned char *inout); - -#ifdef __cplusplus -} -#endif - -/* r-w sub channel definitions */ -#define RS_SUB_RW_BITS 6 - -#define PACKETS_PER_SUBCHANNELFRAME 4 -#define LSUB_RAW 18 -#define LSUB_QRAW 2 -/* 6 bit */ -#define LSUB_Q 2 -#define LSUB_P 4 - -#ifdef __cplusplus -extern "C" { -#endif - -/* R-W subchannel encoder */ -/* On input: 72 bytes packed user data, four frames with each 18 bytes. - On output: per frame: 2 bytes user data, 2 bytes Q parity, - 16 bytes user data, 4 bytes P parity. - Options: - delay1: use low level delay line - scramble: perform low level permutations - */ -int do_encode_sub(unsigned char in[LSUB_RAW*PACKETS_PER_SUBCHANNELFRAME], - unsigned char out[(LSUB_RAW+LSUB_Q+LSUB_P)*PACKETS_PER_SUBCHANNELFRAME], - int delay1, int scramble); -int do_decode_sub(unsigned char in[(LSUB_RAW+LSUB_Q+LSUB_P)*PACKETS_PER_SUBCHANNELFRAME], - unsigned char out[LSUB_RAW*PACKETS_PER_SUBCHANNELFRAME], - int delay1, int scramble); - -int decode_LSUB_Q(unsigned char inout[LSUB_QRAW + LSUB_Q]); -int decode_LSUB_P(unsigned char inout[LSUB_RAW + LSUB_Q + LSUB_P]); - -#ifdef __cplusplus -} -#endif - -unsigned char minute, second, frame; - -/* these prototypes will become public when the function are implemented */ -#ifdef MAIN -static int do_decode_L2(unsigned char in[(L2_RAW+L2_Q+L2_P)], - unsigned char out[L2_RAW]); -static int do_decode_L1(unsigned char in[(L1_RAW+L1_Q+L1_P)*FRAMES_PER_SECTOR], - unsigned char out[L1_RAW*FRAMES_PER_SECTOR], - int delay1, int delay2, int delay3, int scramble); -#endif +yazedc::yazedc() : minute(0), second(2), frame(0), sectortype(0) {} /* ------------- tables generated by gen_encodes --------------*/ #include "crctables" -static int encode_L1_Q(unsigned char inout[L1_RAW + L1_Q]) -{ - unsigned char *Q; - int i; - - memmove(inout+L1_RAW/2+L1_Q, inout+L1_RAW/2, L1_RAW/2); - Q = inout + L1_RAW/2; - - memset(Q, 0, L1_Q); - for (i = 0; i < L1_RAW + L1_Q; i++) { - unsigned char data; - - if (i == L1_RAW/2) i += L1_Q; - data = inout[i]; - if (data != 0) { - unsigned char base = rs_l12_log[data]; - - Q[0] ^= rs_l12_alog[(base+AQ[0][i]) % ((1 << RS_L12_BITS)-1)]; - Q[1] ^= rs_l12_alog[(base+AQ[1][i]) % ((1 << RS_L12_BITS)-1)]; - Q[2] ^= rs_l12_alog[(base+AQ[2][i]) % ((1 << RS_L12_BITS)-1)]; - Q[3] ^= rs_l12_alog[(base+AQ[3][i]) % ((1 << RS_L12_BITS)-1)]; - } - } - - return 0; -} -static int encode_L1_P(unsigned char inout[L1_RAW + L1_Q + L1_P]) -{ - unsigned char *P; - int i; - - P = inout + L1_RAW + L1_Q; - - memset(P, 0, L1_P); - for (i = 0; i < L2_RAW + L2_Q + L2_P; i++) { - unsigned char data; - - data = inout[i]; - if (data != 0) { - unsigned char base = rs_l12_log[data]; - - P[0] ^= rs_l12_alog[(base+AP[0][i]) % ((1 << RS_L12_BITS)-1)]; - P[1] ^= rs_l12_alog[(base+AP[1][i]) % ((1 << RS_L12_BITS)-1)]; - P[2] ^= rs_l12_alog[(base+AP[2][i]) % ((1 << RS_L12_BITS)-1)]; - P[3] ^= rs_l12_alog[(base+AP[3][i]) % ((1 << RS_L12_BITS)-1)]; - } - } - return 0; -} - -#ifdef MAIN -static int decode_L1_Q(unsigned char inout[L1_RAW + L1_Q]) -{ - return 0; -} - -static int decode_L1_P(unsigned char in[L1_RAW + L1_Q + L1_P]) -{ - return 0; -} -#endif - static int encode_L2_Q(unsigned char inout[4 + L2_RAW + 4 + 8 + L2_P + L2_Q]) { unsigned char *Q; @@ -322,19 +137,10 @@ static int encode_L2_P(unsigned char inout[4 + L2_RAW + 4 + 8 + L2_P]) return 0; } -int decode_L2_Q(unsigned char inout[4 + L2_RAW + 12 + L2_Q]) -{ - return 0; -} -int decode_L2_P(unsigned char inout[4 + L2_RAW + 12 + L2_Q + L2_P]) -{ - return 0; -} - -int scramble_L2(unsigned char *inout) +int yazedc::scramble_L2(unsigned char *inout) { unsigned char *r = inout + 12; - unsigned char *s = yellowbook_scrambler; + const unsigned char *s = yellowbook_scrambler; unsigned int i; unsigned int *f = (unsigned int *)inout; @@ -350,290 +156,7 @@ int scramble_L2(unsigned char *inout) return 0; } -static int encode_LSUB_Q(unsigned char inout[LSUB_RAW + LSUB_Q]) -{ - unsigned char *Q; -/* unsigned char data; */ - int i; - - memmove(inout+LSUB_QRAW+LSUB_Q, inout+LSUB_QRAW, LSUB_RAW-LSUB_QRAW); - Q = inout + LSUB_QRAW; - - memset(Q, 0, LSUB_Q); - -#if 0 - data = inout[0] & 0x3f; - if (data != 0) { - unsigned char base = rs_sub_rw_log[data]; - - Q[0] ^= rs_sub_rw_alog[(base+26) % ((1 << RS_SUB_RW_BITS)-1)]; - Q[1] ^= rs_sub_rw_alog[(base+7) % ((1 << RS_SUB_RW_BITS)-1)]; - } - data = inout[1] & 0x3f; - if (data != 0) { - unsigned char base = rs_sub_rw_log[data]; - - Q[0] ^= rs_sub_rw_alog[(base+6) % ((1 << RS_SUB_RW_BITS)-1)]; - Q[1] ^= rs_sub_rw_alog[(base+1) % ((1 << RS_SUB_RW_BITS)-1)]; - } -#else - for (i = 0; i < LSUB_QRAW; i++) { - unsigned char data; - - data = inout[i] & 0x3f; - if (data != 0) { - unsigned char base = rs_sub_rw_log[data]; - - Q[0] ^= rs_sub_rw_alog[(base+SQ[0][i]) % ((1 << RS_SUB_RW_BITS)-1)]; - Q[1] ^= rs_sub_rw_alog[(base+SQ[1][i]) % ((1 << RS_SUB_RW_BITS)-1)]; - } - } -#endif - return 0; -} - - -static int encode_LSUB_P(unsigned char inout[LSUB_RAW + LSUB_Q + LSUB_P]) -{ - unsigned char *P; - int i; - - P = inout + LSUB_RAW + LSUB_Q; - - memset(P, 0, LSUB_P); - for (i = 0; i < LSUB_RAW + LSUB_Q; i++) { - unsigned char data; - - data = inout[i] & 0x3f; - if (data != 0) { - unsigned char base = rs_sub_rw_log[data]; - - P[0] ^= rs_sub_rw_alog[(base+SP[0][i]) % ((1 << RS_SUB_RW_BITS)-1)]; - P[1] ^= rs_sub_rw_alog[(base+SP[1][i]) % ((1 << RS_SUB_RW_BITS)-1)]; - P[2] ^= rs_sub_rw_alog[(base+SP[2][i]) % ((1 << RS_SUB_RW_BITS)-1)]; - P[3] ^= rs_sub_rw_alog[(base+SP[3][i]) % ((1 << RS_SUB_RW_BITS)-1)]; - } - } - return 0; -} - -int decode_LSUB_Q(unsigned char inout[LSUB_QRAW + LSUB_Q]) -{ - unsigned char Q[LSUB_Q]; - int i; - - memset(Q, 0, LSUB_Q); - for (i = LSUB_QRAW + LSUB_Q -1; i>=0; i--) { - unsigned char data; - - data = inout[LSUB_QRAW + LSUB_Q -1 -i] & 0x3f; - if (data != 0) { - unsigned char base = rs_sub_rw_log[data]; - - Q[0] ^= rs_sub_rw_alog[(base+0*i) % ((1 << RS_SUB_RW_BITS)-1)]; - Q[1] ^= rs_sub_rw_alog[(base+1*i) % ((1 << RS_SUB_RW_BITS)-1)]; - } - } - - return (Q[0] != 0 || Q[1] != 0); -} -int decode_LSUB_P(unsigned char inout[LSUB_RAW + LSUB_Q + LSUB_P]) -{ - unsigned char P[LSUB_P]; - int i; - - memset(P, 0, LSUB_P); - for (i = LSUB_RAW + LSUB_Q + LSUB_P-1; i>=0; i--) { - unsigned char data; - - data = inout[LSUB_RAW + LSUB_Q + LSUB_P -1 -i] & 0x3f; - if (data != 0) { - unsigned char base = rs_sub_rw_log[data]; - - P[0] ^= rs_sub_rw_alog[(base+0*i) % ((1 << RS_SUB_RW_BITS)-1)]; - P[1] ^= rs_sub_rw_alog[(base+1*i) % ((1 << RS_SUB_RW_BITS)-1)]; - P[2] ^= rs_sub_rw_alog[(base+2*i) % ((1 << RS_SUB_RW_BITS)-1)]; - P[3] ^= rs_sub_rw_alog[(base+3*i) % ((1 << RS_SUB_RW_BITS)-1)]; - } - } - - return (P[0] != 0 || P[1] != 0 || P[2] != 0 || P[3] != 0); -} - -/* Layer 1 CIRC en/decoder */ -#define MAX_L1_DEL1 2 -static unsigned char l1_delay_line1[MAX_L1_DEL1][L1_RAW]; -#define MAX_L1_DEL2 108 -static unsigned char l1_delay_line2[MAX_L1_DEL2][L1_RAW+L1_Q]; -#define MAX_L1_DEL3 1 -static unsigned char l1_delay_line3[MAX_L1_DEL3][L1_RAW+L1_Q+L1_P]; -static unsigned l1_del_index; - -int do_encode_L1(unsigned char in[L1_RAW*FRAMES_PER_SECTOR], - unsigned char out[(L1_RAW+L1_Q+L1_P)*FRAMES_PER_SECTOR], - int delay1, int delay2, int delay3, int permute) -{ - int i; - - for (i = 0; i < FRAMES_PER_SECTOR; i++) { - int j; - unsigned char t; - - if (in != out) - memcpy(out, in, L1_RAW); - - if (delay1) { - /* shift through delay line 1 */ - for (j = 0; j < L1_RAW; j++) { - if (((j/4) % MAX_L1_DEL1) == 0) { - t = l1_delay_line1[l1_del_index % (MAX_L1_DEL1)][j]; - l1_delay_line1[l1_del_index % (MAX_L1_DEL1)][j] = out[j]; - out[j] = t; - } - } - } - - if (permute) { - /* permute */ - t = out[2]; out[2] = out[8]; out[8] = out[10]; out[10] = out[18]; - out[18] = out[6]; out [6] = t; - t = out[3]; out[3] = out[9]; out[9] = out[11]; out[11] = out[19]; - out[19] = out[7]; out [7] = t; - t = out[4]; out[4] = out[16]; out[16] = out[20]; out[20] = out[14]; - out[14] = out[12]; out [12] = t; - t = out[5]; out[5] = out[17]; out[17] = out[21]; out[21] = out[15]; - out[15] = out[13]; out [13] = t; - } - - /* build Q parity */ - encode_L1_Q(out); - - if (delay2) { - /* shift through delay line 2 */ - for (j = 0; j < L1_RAW+L1_Q; j++) { - if (j != 0) { - t = l1_delay_line2[(l1_del_index) % MAX_L1_DEL2][j]; - l1_delay_line2[(l1_del_index + j*4) % MAX_L1_DEL2][j] = out[j]; - out[j] = t; - } - } - } - - /* build P parity */ - encode_L1_P(out); - - if (delay3) { - /* shift through delay line 3 */ - for (j = 0; j < L1_RAW+L1_Q+L1_P; j++) { - if (((j) & MAX_L1_DEL3) == 0) { - t = l1_delay_line3[0][j]; - l1_delay_line3[0][j] = out[j]; - out[j] = t; - } - } - } - - /* invert Q and P parity */ - for (j = 0; j < L1_Q; j++) - out[j+12] = ~out[j+12]; - for (j = 0; j < L1_P; j++) - out[j+28] = ~out[j+28]; - - l1_del_index++; - out += L1_RAW+L1_Q+L1_P; - in += L1_RAW; - } - return 0; -} - -#ifdef MAIN -int do_decode_L1(unsigned char in[(L1_RAW+L1_Q+L1_P)*FRAMES_PER_SECTOR], - unsigned char out[L1_RAW*FRAMES_PER_SECTOR], - int delay1, int delay2, int delay3, int permute) -{ - int i; - - for (i = 0; i < FRAMES_PER_SECTOR; i++) { - int j; - unsigned char t; - - if (delay3) { - /* shift through delay line 3 */ - for (j = 0; j < L1_RAW+L1_Q+L1_P; j++) { - if (((j) & MAX_L1_DEL3) != 0) { - t = l1_delay_line3[0][j]; - l1_delay_line3[0][j] = in[j]; - in[j] = t; - } - } - } - - /* invert Q and P parity */ - for (j = 0; j < L1_Q; j++) - in[j+12] = ~in[j+12]; - for (j = 0; j < L1_P; j++) - in[j+28] = ~in[j+28]; - - /* build P parity */ - decode_L1_P(in); - - if (delay2) { - /* shift through delay line 2 */ - for (j = 0; j < L1_RAW+L1_Q; j++) { - if (j != L1_RAW+L1_Q-1) { - t = l1_delay_line2[(l1_del_index) % MAX_L1_DEL2][j]; - l1_delay_line2[(l1_del_index + (MAX_L1_DEL2 - j*4)) % MAX_L1_DEL2][j] = in[j]; - in[j] = t; - } - } - } - - /* build Q parity */ - decode_L1_Q(in); - - if (permute) { - /* permute */ - t = in[2]; in[2] = in[6]; in[6] = in[18]; in[18] = in[10]; - in[10] = in[8]; in [8] = t; - t = in[3]; in[3] = in[7]; in[7] = in[19]; in[19] = in[11]; - in[11] = in[9]; in [9] = t; - t = in[4]; in[4] = in[12]; in[12] = in[14]; in[14] = in[20]; - in[20] = in[16]; in [16] = t; - t = in[5]; in[5] = in[13]; in[13] = in[15]; in[15] = in[21]; - in[21] = in[17]; in [17] = t; - } - - if (delay1) { - /* shift through delay line 1 */ - for (j = 0; j < L1_RAW; j++) { - if (((j/4) % MAX_L1_DEL1) != 0) { - t = l1_delay_line1[l1_del_index % (MAX_L1_DEL1)][j]; - l1_delay_line1[l1_del_index % (MAX_L1_DEL1)][j] = in[j]; - in[j] = t; - } - } - } - - if (in != out) - memcpy(out, in, (L1_RAW)); - - l1_del_index++; - in += L1_RAW+L1_Q+L1_P; - out += L1_RAW; - } - return 0; -} - -#endif - -#if 0 -static unsigned char bin2bcd(unsigned p) -{ - return ((p/10)<<4)|(p%10); -} -#endif - -static int build_address(unsigned char inout[], int sectortype, unsigned address) +int yazedc::build_address(unsigned char inout[], int sectortype, unsigned address) { inout[12] = minute; inout[13] = second; @@ -654,7 +177,6 @@ static int build_address(unsigned char inout[], int sectortype, unsigned address } #include "crctable.out" - unsigned long int build_edc(unsigned char inout[], int from, int upto) { unsigned char *p = inout+from; @@ -667,7 +189,7 @@ unsigned long int build_edc(unsigned char inout[], int from, int upto) } /* Layer 2 Product code en/decoder */ -int do_encode_L2(unsigned char inout[(12 + 4 + L2_RAW+4+8+L2_Q+L2_P)], int sectortype, unsigned address) +int yazedc::do_encode_L2(unsigned char inout[(12 + 4 + L2_RAW+4+8+L2_Q+L2_P)], int sectortype, unsigned address) { unsigned long int result; @@ -728,119 +250,12 @@ int do_encode_L2(unsigned char inout[(12 + 4 + L2_RAW+4+8+L2_Q+L2_P)], int secto return 0; } -#ifdef MAIN -static int do_decode_L2(unsigned char in[(L2_RAW+L2_Q+L2_P)], - unsigned char out[L2_RAW]) -{ - return 0; -} -#endif - - -#define MAX_SUB_DEL 8 -static unsigned char sub_delay_line[MAX_SUB_DEL][LSUB_RAW+LSUB_Q+LSUB_P]; -static unsigned sub_del_index; - -/* R-W Subchannel en/decoder */ -int do_encode_sub(unsigned char in[LSUB_RAW*PACKETS_PER_SUBCHANNELFRAME], - unsigned char out[(LSUB_RAW+LSUB_Q+LSUB_P)*PACKETS_PER_SUBCHANNELFRAME], - int delay1, int permute) -{ - int i; - - if (in == out) return -1; - - for (i = 0; i < PACKETS_PER_SUBCHANNELFRAME; i++) { - int j; - unsigned char t; - - memcpy(out, in, (LSUB_RAW)); - - /* build Q parity */ - encode_LSUB_Q(out); - - /* build P parity */ - encode_LSUB_P(out); - - if (permute) { - /* permute */ - t = out[1]; out[1] = out[18]; out[18] = t; - t = out[2]; out[2] = out[ 5]; out[ 5] = t; - t = out[3]; out[3] = out[23]; out[23] = t; - } - - if (delay1) { - /* shift through delay_line */ - for (j = 0; j < LSUB_RAW+LSUB_Q+LSUB_P; j++) { - if ((j % MAX_SUB_DEL) != 0) { - t = sub_delay_line[(sub_del_index) % MAX_SUB_DEL][j]; - sub_delay_line[(sub_del_index + j) % MAX_SUB_DEL][j] = out[j]; - out[j] = t; - } - } - } - sub_del_index++; - out += LSUB_RAW+LSUB_Q+LSUB_P; - in += LSUB_RAW; - } - return 0; -} - -int -do_decode_sub( - unsigned char in[(LSUB_RAW+LSUB_Q+LSUB_P)*PACKETS_PER_SUBCHANNELFRAME], - unsigned char out[LSUB_RAW*PACKETS_PER_SUBCHANNELFRAME], - int delay1, int permute) -{ - int i; - - if (in == out) return -1; - - for (i = 0; i < PACKETS_PER_SUBCHANNELFRAME; i++) { - int j; - unsigned char t; - - if (delay1) { - /* shift through delay_line */ - for (j = 0; j < LSUB_RAW+LSUB_Q+LSUB_P; j++) { - if ((j % MAX_SUB_DEL) != MAX_SUB_DEL-1) { - t = sub_delay_line[(sub_del_index) % MAX_SUB_DEL][j]; - sub_delay_line[(sub_del_index + (MAX_SUB_DEL - j)) % MAX_SUB_DEL][j] = in[j]; - in[j] = t; - } - } - } - - if (permute) { - /* permute */ - t = in[1]; in[1] = in[18]; in[18] = t; - t = in[2]; in[2] = in[ 5]; in[ 5] = t; - t = in[3]; in[3] = in[23]; in[23] = t; - } - - /* build P parity */ - decode_LSUB_P(in); - - /* build Q parity */ - decode_LSUB_Q(in); - - memcpy(out, in, LSUB_QRAW); - memcpy(out+LSUB_QRAW, in+LSUB_QRAW+LSUB_Q, LSUB_RAW-LSUB_QRAW); - - sub_del_index++; - in += LSUB_RAW+LSUB_Q+LSUB_P; - out += LSUB_RAW; - } - return 0; -} - -static int sectortype = MODE_0; -int get_sector_type(void) +int yazedc::get_sector_type(void) { return sectortype; } -int set_sector_type(int st) +int yazedc::set_sector_type(int st) { switch(st) { case MODE_0: @@ -854,5 +269,3 @@ int set_sector_type(int st) } return 0; } - -/* ------------- --------------*/ |