summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--dtemain.cpp68
-rw-r--r--lzss-main.cpp384
-rw-r--r--yazedc-main.cpp314
3 files changed, 766 insertions, 0 deletions
diff --git a/dtemain.cpp b/dtemain.cpp
new file mode 100644
index 0000000..404f52f
--- /dev/null
+++ b/dtemain.cpp
@@ -0,0 +1,68 @@
+/*
+ * PSX-Tools Bundle Pack
+ * Copyright (C) 2002 Nicolas "Pixel" Noble
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include "fileutils.h"
+#include "generic.h"
+
+int main(int argc, char ** argv) {
+ FILE * f, * t;
+ long old_size;
+ int i;
+
+ verbosity = M_INFO;
+
+ printm(M_STATUS, "Reading thingy table\n");
+ t = fopen(argv[2], "r");
+ read_thingy(t);
+ fclose(t);
+
+ f = fopen(argv[1], "r");
+ dte_text_size = filesize(f);
+ dte_text = (char *) calloc(dte_text_size + 4, 1);
+ printm(M_STATUS, "Reading file, size = %li\n", dte_text_size);
+ read_thingy_file(f);
+ fclose(f);
+
+ printm(M_STATUS, "True size = %li\n", old_size = dte_text_size);
+
+ printm(M_STATUS, "Compressing file.\n");
+ dte_compress();
+
+ printm(M_STATUS, "Rereading file.\n");
+ f = fopen(argv[1], "r");
+ dte_text_size = filesize(f);
+ dte_text = (char *) calloc(dte_text_size + 4, 1);
+ read_thingy_file(f);
+ fclose(f);
+
+ printm(M_STATUS, "True size = %li, real gain = %li\n", dte_text_size, old_size - dte_text_size);
+
+ printm(M_INFO, "DTE Usage:\n");
+ for (i = 0; i < 256; i++) {
+ printm(M_INFO, "Entry %i ('%s') used at %i\n", i, things[i], dte_usage[i]);
+ }
+
+ printm(M_INFO, "Number of couples: %i\n", tnb_dte);
+
+ free(dte_text);
+}
diff --git a/lzss-main.cpp b/lzss-main.cpp
new file mode 100644
index 0000000..0d08cba
--- /dev/null
+++ b/lzss-main.cpp
@@ -0,0 +1,384 @@
+/*
+ * PSX-Tools Bundle Pack
+ * Copyright (C) 2002 Nicolas "Pixel" Noble
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <getopt.h>
+#include <iostream>
+#include "fileutils.h"
+#include "generic.h"
+#include "lzss.h"
+
+char * fn1, * fn2, * pname;
+
+int lga = 0;
+int compress = 1;
+
+struct option long_options[] = {
+ {"1iscomp", 1, &lga, 1 },
+ {"overlap", 1, &lga, 2 },
+ {"16bits", 1, &lga, 11 },
+ {"negative", 1, &lga, 12 },
+ {"ptrb", 1, &lga, 13 },
+ {"filling", 1, &lga, 14 },
+ {"inverse", 1, &lga, 23 },
+ {"onejump", 1, &lga, 24 },
+ {"window", 1, &lga, 25 },
+ {"lmask1", 1, &lga, 3 },
+ {"lshft1", 1, &lga, 4 },
+ {"lmask2", 1, &lga, 5 },
+ {"lshft2", 1, &lga, 6 },
+ {"jmask1", 1, &lga, 7 },
+ {"jshft1", 1, &lga, 8 },
+ {"jmask2", 1, &lga, 9 },
+ {"jshft2", 1, &lga, 10 },
+ {"fmask1", 1, &lga, 15 },
+ {"fshft1", 1, &lga, 16 },
+ {"fmask2", 1, &lga, 17 },
+ {"fshft2", 1, &lga, 18 },
+ {"vmask1", 1, &lga, 19 },
+ {"vshft1", 1, &lga, 20 },
+ {"vmask2", 1, &lga, 21 },
+ {"vshft2", 1, &lga, 22 },
+ {"help", 0, NULL, 'h'},
+ {"scheme", 1, NULL, 's'},
+ {"length", 1, NULL, 'l'},
+ {"version", 0, NULL, 'V'},
+ {"verbose", 0, NULL, 'v'},
+ {"show", 0, NULL, 'S'},
+ {"dump", 0, NULL, 'D'},
+ {"compress", 0, NULL, 'c'},
+ {"decompress", 0, NULL, 'd'},
+ {"blocks", 0, NULL, 'b'},
+ {0, 0, NULL, 0 }
+};
+
+void showhelp(void) {
+ printm(M_BARE,
+"Usages:\n"
+" %s <--help|-h|-H|-?> Show this help and exit.\n"
+" %s <--dump> Show the built-in schemes and exit.\n"
+" %s <--version|-V> Show the version and copyrights and exit.\n"
+" %s [-c|-d] [-s <scheme>] [-l <length>] [-S] [-v] <infile> <outfile>\n"
+"\n"
+"-c --compress Compress <infile> to <outfile>\n"
+"-d --decompress Decompress <infile> to <outfile>\n"
+"-s <scheme> --scheme=<scheme> Loads the built-in scheme number <scheme>\n"
+"-l <length> --length=<length> Specify the true length for decompression,\n"
+" or enable the padding behavior for compression.\n"
+"-S --show Show the actual scheme before processing.\n"
+"-v --verbose Display a *LOT* of informations.\n"
+"-b --blocks Switch to blocks decompression behaviour\n"
+"\n"
+"Additionnaly you have the scheme manipulation options:\n"
+"--1iscomp --overlap --negative --16bits --ptrb\n"
+"--filling --inverse --onejump --window\n"
+"--lmask1 --lshft1 --lmask2 --lshft2 --jmask1 --jshft1 --jmask2 --jshft2\n"
+"--vmask1 --vshft1 --vmask2 --vshft2 --fmask1 --fshft1 --fmask2 --fshft2\n"
+"\n"
+"If you don't know what they are, forget them.\n"
+"\n"
+"Default behavior is to %scompress.\n"
+"\n", pname, pname, pname, pname, compress ? "" : "de");
+}
+
+void showscheme(void) {
+ printm(M_BARE,
+"Actual scheme:\n"
+"--1iscomp %i\n"
+"--overlap %i\n"
+"--negative %i\n"
+"--16bits %i\n"
+"--ptrb %i\n"
+"--filling %i\n"
+"--inverse %i\n"
+"--onejump %i\n"
+"--window %i\n"
+"--lmask1 0x%02x\n"
+"--lshft1 %i\n"
+"--lmask2 0x%02x\n"
+"--lshft2 %i\n"
+"--jmask1 0x%02x\n"
+"--jshft1 %i\n"
+"--jmask2 0x%02x\n"
+"--jshft2 %i\n"
+"--fmask1 0x%02x\n"
+"--fshft1 %i\n"
+"--fmask2 0x%02x\n"
+"--fshft2 %i\n"
+"--vmask1 0x%02x\n"
+"--vshft1 %i\n"
+"--vmask2 0x%02x\n"
+"--vshft2 %i\n"
+"\n", scheme.one_is_compressed, scheme.overlap_trick, scheme.negative_trick, scheme.sixteen_bits,
+scheme.ptrb, scheme.filling, scheme.bitmap_inversed, scheme.one_jump, scheme.window_start,
+scheme.l_mask_1, scheme.l_shft_1, scheme.l_mask_2, scheme.l_shft_2,
+scheme.j_mask_1, scheme.j_shft_1, scheme.j_mask_2, scheme.j_shft_2,
+scheme.f_mask_1, scheme.f_shft_1, scheme.f_mask_2, scheme.f_shft_2,
+scheme.v_mask_1, scheme.v_shft_1, scheme.v_mask_2, scheme.v_shft_2);
+}
+
+void dump(void) {
+ int i;
+
+ printm(M_BARE, "Built-in schemes:\n");
+ for (i = 0; schemes[i].name; i++) {
+ printm(M_BARE, "%2i - %s\n", i, schemes[i].name);
+ }
+}
+
+int main(int argc, char ** argv) {
+ long length = -1;
+ FILE * f1, * f2;
+ int p, show = 0;
+ int c, s, t;
+
+ pname = strdup(argv[0]);
+ p = strlen(pname) - 5;
+
+ verbosity = M_STATUS;
+
+ if (!strcasecmp(pname + p, "dlzss")) {
+ compress = 0;
+ }
+
+ printm(M_BARE, /*
+LZSS_MAIN " compressor/decompressor version " LZSS_VERSION ",\n" */
+"Copyright (C) 2002 Nicolas \"Pixel\" Noble\n"
+"This software comes with ABSOLUTELY NO WARRANTY; see COPYING for details\n"
+"Thanks to Czar Dragon, for his little 'lzss' schemes FAQ.\n"
+"Special thanks to Yazoo, who taught me PSX hacking.\n"
+"\n");
+
+ while ((c = getopt_long(argc, argv, "Hhs:l:vVScdb", long_options, NULL)) != EOF) {
+ switch (c) {
+ case 0:
+ switch (lga) {
+ case 1:
+ t = atoi(optarg);
+ if ((t != 1) && (t != 0)) {
+ printm(M_ERROR, "Invalid value for boolean: %s\n", optarg);
+ } else {
+ scheme.one_is_compressed = t;
+ }
+ break;
+ case 2:
+ t = atoi(optarg);
+ if ((t != 1) && (t != 0)) {
+ printm(M_ERROR, "Invalid value for boolean: %s\n", optarg);
+ } else {
+ scheme.overlap_trick = t;
+ }
+ break;
+ case 3:
+ sscanf(optarg, "%i", &scheme.l_mask_1);
+ break;
+ case 4:
+ scheme.l_shft_1 = atoi(optarg);
+ break;
+ case 5:
+ sscanf(optarg, "%i", &scheme.l_mask_2);
+ break;
+ case 6:
+ scheme.l_shft_2 = atoi(optarg);
+ break;
+ case 7:
+ sscanf(optarg, "%i", &scheme.j_mask_1);
+ break;
+ case 8:
+ scheme.j_shft_1 = atoi(optarg);
+ break;
+ case 9:
+ sscanf(optarg, "%i", &scheme.j_mask_2);
+ break;
+ case 10:
+ scheme.j_mask_2 = atoi(optarg);
+ break;
+ case 11:
+ t = atoi(optarg);
+ if ((t != 1) && (t != 0)) {
+ printm(M_ERROR, "Invalid value for boolean: %s\n", optarg);
+ } else {
+ scheme.sixteen_bits = t;
+ }
+ break;
+ case 12:
+ t = atoi(optarg);
+ if ((t != 1) && (t != 0)) {
+ printm(M_ERROR, "Invalid value for boolean: %s\n", optarg);
+ } else {
+ scheme.negative_trick = t;
+ }
+ break;
+ case 13:
+ t = atoi(optarg);
+ if ((t != 2) && (t != 1) && (t != 0)) {
+ printm(M_ERROR, "Invalid value for ter: %s\n", optarg);
+ } else {
+ scheme.ptrb = t;
+ }
+ break;
+ case 14:
+ t = atoi(optarg);
+ if ((t != 2) && (t != 1) && (t != 0)) {
+ printm(M_ERROR, "Invalid value for ter: %s\n", optarg);
+ } else {
+ scheme.filling = t;
+ }
+ break;
+ case 15:
+ sscanf(optarg, "%i", &scheme.f_mask_1);
+ break;
+ case 16:
+ scheme.f_shft_1 = atoi(optarg);
+ break;
+ case 17:
+ sscanf(optarg, "%i", &scheme.f_mask_2);
+ break;
+ case 18:
+ scheme.f_shft_2 = atoi(optarg);
+ break;
+ case 19:
+ sscanf(optarg, "%i", &scheme.v_mask_1);
+ break;
+ case 20:
+ scheme.v_shft_1 = atoi(optarg);
+ break;
+ case 21:
+ sscanf(optarg, "%i", &scheme.v_mask_2);
+ break;
+ case 22:
+ scheme.v_mask_2 = atoi(optarg);
+ break;
+ case 23:
+ t = atoi(optarg);
+ if ((t != 1) && (t != 0)) {
+ printm(M_ERROR, "Invalid value for boolean: %s\n", optarg);
+ } else {
+ scheme.bitmap_inversed = t;
+ }
+ break;
+ case 24:
+ t = atoi(optarg);
+ if ((t != 1) && (t != 0)) {
+ printm(M_ERROR, "Invalid value for boolean: %s\n", optarg);
+ } else {
+ scheme.one_jump = t;
+ }
+ break;
+ case 25:
+ t = sscanf(optarg, "%i", &scheme.window_start);
+ break;
+ default:
+ showhelp();
+ printm(M_ERROR, "Unknow option.\n");
+ exit(-1);
+ }
+ break;
+ case '?':
+ case 'H':
+ case 'h':
+ showhelp();
+ exit(0);
+ case 's':
+ s = atoi(optarg);
+ scheme = schemes[s];
+ break;
+ case 'l':
+ length = atoi(optarg);
+ break;
+ case 'v':
+ verbosity = M_INFO;
+ break;
+ case 'V':
+ exit(0);
+ case 'S':
+ show = 1;
+ break;
+ case 'D':
+ dump();
+ exit(0);
+ break;
+ case 'd':
+ compress = 0;
+ break;
+ case 'c':
+ compress = 1;
+ break;
+ case 'b':
+ blockb = 1;
+ break;
+ default:
+ showhelp();
+ printm(M_ERROR, "Unknow option.\n");
+ exit(-1);
+ }
+ }
+
+ if (show) showscheme();
+
+ if (optind != (argc - 2)) {
+ if (optind > (argc - 2)) {
+ printm(M_ERROR, "Not enough filenames\n");
+ exit(-1);
+ } else {
+ printm(M_ERROR, "Too much arguments\n");
+ exit(-1);
+ }
+ }
+
+ fn1 = argv[optind++];
+ fn2 = argv[optind++];
+
+ if (!(f1 = fopen(fn1, "r"))) {
+ printm(M_ERROR, "Error opening file %s for reading.\n", fn1);
+ }
+
+ if (!(f2 = fopen(fn2, "w"))) {
+ printm(M_ERROR, "Error opening file %s for writing.\n", fn2);
+ }
+
+ if (compress) {
+ printm(M_STATUS, "Compressing `%s' to `%s'...\n", fn1, fn2);
+ } else {
+ printm(M_STATUS, "Decompressing `%s' to `%s'...\n", fn1, fn2);
+ }
+
+ if (compress) {
+ if (length == -1) {
+ lzss_comp(f1, f2);
+ } else {
+ lzss_comp(f1, f2, &length);
+ }
+ } else {
+ length = lzss_decomp(f1, f2, length);
+ }
+
+ printm(M_STATUS, "Done, filesize changed from %i to %i.\n", filesize(f1), filesize(f2));
+ if (!bitmap_count)
+ bitmap_count = 8;
+ if (compress)
+ printm(M_STATUS, "Compressed %i = 0x%08x blocs, containing %i = 0x%08x chunks.\n", blk + 1, blk + 1, blk * 8 + bitmap_count, blk * 8 + bitmap_count);
+
+ fclose(f1);
+ fclose(f2);
+
+ exit(0);
+}
diff --git a/yazedc-main.cpp b/yazedc-main.cpp
new file mode 100644
index 0000000..533567c
--- /dev/null
+++ b/yazedc-main.cpp
@@ -0,0 +1,314 @@
+/*
+ * PSX-Tools Bundle Pack
+ * Copyright (C) 1998 Heiko Eissfeldt
+ * portions used& Chris Smith
+ * Modified by Yazoo, then by
+ * Nicolas "Pixel" Noble
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+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)
+{
+ return sectortype;
+}
+
+int set_sector_type(int st)
+{
+ switch(st) {
+ case MODE_0:
+ case MODE_1:
+ case MODE_2:
+ case MODE_2_FORM_1:
+ case MODE_2_FORM_2:
+ sectortype = st;
+ default:
+ return -1;
+ }
+ return 0;
+}
+
+/* ------------- --------------*/
+#ifdef MAIN
+
+#define DO_L1 1
+#define DO_L2 2
+#define DO_SUB 4
+
+static const unsigned sect_size[8][2] = {
+/* nothing */
+{0,0},
+/* Layer 1 decode/encode */
+{ (L1_RAW+L1_Q+L1_P)*FRAMES_PER_SECTOR, L1_RAW*FRAMES_PER_SECTOR},
+/* Layer 2 decode/encode */
+{ 16+L2_RAW+12+L2_Q+L2_P, L2_RAW},
+/* Layer 1 and 2 decode/encode */
+{ (L1_RAW+L1_Q+L1_P)*FRAMES_PER_SECTOR, L1_RAW*FRAMES_PER_SECTOR},
+/* Subchannel decode/encode */
+{ (LSUB_RAW+LSUB_Q+LSUB_P)*PACKETS_PER_SUBCHANNELFRAME,
+ LSUB_RAW*PACKETS_PER_SUBCHANNELFRAME},
+/* Layer 1 and subchannel decode/encode */
+{ (L1_RAW+L1_Q+L1_P)*FRAMES_PER_SECTOR +
+ (LSUB_RAW+LSUB_Q+LSUB_P)*PACKETS_PER_SUBCHANNELFRAME,
+ LSUB_RAW*PACKETS_PER_SUBCHANNELFRAME +
+ L1_RAW*FRAMES_PER_SECTOR},
+/* Layer 2 and subchannel decode/encode */
+{ L2_RAW+L2_Q+L2_P+
+ (LSUB_RAW+LSUB_Q+LSUB_P)*PACKETS_PER_SUBCHANNELFRAME,
+ LSUB_RAW*PACKETS_PER_SUBCHANNELFRAME +
+ L2_RAW},
+/* Layer 1, 2 and subchannel decode/encode */
+{ (L1_RAW+L1_Q+L1_P)*FRAMES_PER_SECTOR +
+ (LSUB_RAW+LSUB_Q+LSUB_P)*PACKETS_PER_SUBCHANNELFRAME,
+ LSUB_RAW*PACKETS_PER_SUBCHANNELFRAME +
+ L1_RAW*FRAMES_PER_SECTOR},
+};
+
+int main(int argc, char **argv)
+{
+ int encode = 1;
+ int mask = DO_L2;
+ FILE * infp;
+ FILE * outfp;
+ unsigned address = 0;
+ unsigned char *l1_inbuf;
+ unsigned char *l1_outbuf;
+ unsigned char *l2_inbuf;
+ unsigned char *l2_outbuf;
+ unsigned char *sub_inbuf;
+ unsigned char *sub_outbuf;
+ unsigned char *last_outbuf;
+ unsigned char inbuf[(LSUB_RAW+LSUB_Q+LSUB_P)*PACKETS_PER_SUBCHANNELFRAME +
+ (L1_RAW+L1_Q+L1_P)*FRAMES_PER_SECTOR];
+ unsigned char outbuf[(LSUB_RAW+LSUB_Q+LSUB_P)*PACKETS_PER_SUBCHANNELFRAME +
+ (L1_RAW+L1_Q+L1_P)*FRAMES_PER_SECTOR];
+ unsigned load_offset;
+
+ l1_inbuf = l2_inbuf = sub_inbuf = inbuf;
+ l1_outbuf = l2_outbuf = sub_outbuf = last_outbuf = outbuf;
+
+ infp = fopen("sectors_in", "rb");
+ outfp = fopen("sectors_out", "wb");
+
+ sectortype= MODE_2_FORM_1;
+ address = 0 + 75*2;
+
+ switch (sectortype) {
+ case MODE_1:
+ case MODE_2:
+ load_offset = 16;
+ break;
+ case MODE_2_FORM_1:
+ case MODE_2_FORM_2:
+ load_offset = 24;
+ break;
+ default:
+ load_offset = 0;
+ }
+ while(1) {
+
+ if (1 != fread(inbuf+load_offset,
+ sect_size[mask][encode], 1, infp)) { perror(""); break; }
+ if (encode == 1) {
+ if (mask & DO_L2) {
+ switch (sectortype) {
+ case MODE_0:
+ break;
+ case MODE_1:
+ break;
+ case MODE_2:
+ if (1 !=
+ fread(inbuf+load_offset+
+ sect_size[mask][encode],
+ 2336 - sect_size[mask][encode],
+ 1, infp)) { perror(""); break; }
+ break;
+ case MODE_2_FORM_1:
+ break;
+ case MODE_2_FORM_2:
+ if (1 !=
+ fread(inbuf+load_offset+
+ sect_size[mask][encode],
+ 2324 - sect_size[mask][encode],
+ 1, infp)) { perror(""); break; }
+ break;
+ default:
+ if (1 !=
+ fread(inbuf+load_offset+
+ sect_size[mask][encode],
+ 2448 - sect_size[mask][encode],
+ 1, infp)) { perror(""); break; }
+ memset(inbuf,0,16);
+ /*memset(inbuf+16+2048,0,12+272);*/
+ break;
+ }
+ do_encode_L2(l2_inbuf, MODE_1, address);
+ if (0) scramble_L2(l2_inbuf);
+ last_outbuf = l1_inbuf = l2_inbuf;
+ l1_outbuf = l2_inbuf;
+ sub_inbuf = l2_inbuf + L2_RAW;
+ sub_outbuf = l2_outbuf + 12 + 4+ L2_RAW+4+ 8+ L2_Q+L2_P;
+ }
+ if (mask & DO_L1) {
+ do_encode_L1(l1_inbuf, l1_outbuf,1,1,1,1);
+ last_outbuf = l1_outbuf;
+ sub_inbuf = l1_inbuf + L1_RAW*FRAMES_PER_SECTOR;
+ sub_outbuf = l1_outbuf + (L1_RAW+L1_Q+L1_P)*FRAMES_PER_SECTOR;
+ }
+ if (mask & DO_SUB) {
+ do_encode_sub(sub_inbuf, sub_outbuf, 0, 0);
+ }
+ } else {
+ if (mask & DO_L1) {
+ do_decode_L1(l1_inbuf, l1_outbuf,1,1,1,1);
+ last_outbuf = l2_inbuf = l1_outbuf;
+ l2_outbuf = l1_inbuf;
+ sub_inbuf = l1_inbuf + (L1_RAW+L1_Q+L1_P)*FRAMES_PER_SECTOR;
+ sub_outbuf = l1_outbuf + L1_RAW*FRAMES_PER_SECTOR;
+ }
+ if (mask & DO_L2) {
+ do_decode_L2(l2_inbuf, l2_outbuf);
+ last_outbuf = l2_outbuf;
+ sub_inbuf = l2_inbuf + L2_RAW+L2_Q+L2_P;
+ sub_outbuf = l2_outbuf + L2_RAW;
+ }
+ if (mask & DO_SUB) {
+ do_decode_sub(sub_inbuf, sub_outbuf, 1, 1);
+ }
+ }
+ if (1 != fwrite(last_outbuf, sect_size[mask][1 - encode], 1, outfp)) {
+ perror("");
+ break;
+ }
+ address++;
+ }
+#if 0
+ /* flush the data from the delay lines with zeroed sectors, if necessary */
+#endif
+ return 0;
+}