summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rwxr-xr-xlib/Makefile2
-rw-r--r--lib/cdreader.cpp10
-rw-r--r--lib/cdutils.cpp194
-rw-r--r--lib/crctable.out2
-rw-r--r--lib/crctables40
-rw-r--r--lib/lzss.cpp38
-rw-r--r--lib/yazedc.cpp603
7 files changed, 145 insertions, 744 deletions
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;
}
-
-/* ------------- --------------*/