2 * Note: This file has been extracted from crkit 1.1.6 and modified to work within
3 * lxdream, but is otherwise unchanged.
6 * This file has been modified for the cdrkit suite.
8 * The behaviour and appearence of the program code below can differ to a major
9 * extent from the version distributed by the original author(s).
11 * For details, see Changelog file distributed with the cdrkit package. If you
12 * received this file from another source then ask the distributing person for
13 * a log of modifications.
17 /* @(#)edc_ecc.c 1.21 03/04/04 Copyright 1998-2002 Heiko Eissfeldt, Joerg Schilling */
20 * Copyright 1998-2002 by Heiko Eissfeldt
21 * Copyright 2002 by Joerg Schilling
23 * This file contains protected intellectual property.
25 * reed-solomon encoder / decoder for compact discs.
29 * This program is free software; you can redistribute it and/or modify
30 * it under the terms of the GNU General Public License version 2
31 * as published by the Free Software Foundation.
33 * This program is distributed in the hope that it will be useful,
34 * but WITHOUT ANY WARRANTY; without even the implied warranty of
35 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36 * GNU General Public License for more details.
38 * You should have received a copy of the GNU General Public License along with
39 * this program; see the file COPYING. If not, write to the Free Software
40 * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
49 #define xaligned(a, s) ((((uintptr_t)(a)) & (s)) == 0 )
51 /* these prototypes will become public when the function are implemented */
52 static int do_decode_L2(unsigned char in[(L2_RAW+L2_Q+L2_P)],
53 unsigned char out[L2_RAW]);
55 static int do_decode_L1(unsigned char in[(L1_RAW+L1_Q+L1_P)*FRAMES_PER_SECTOR],
56 unsigned char out[L1_RAW*FRAMES_PER_SECTOR],
57 int delay1, int delay2, int delay3, int scramble);
60 /* ------------- tables generated by gen_encodes --------------*/
62 #include "edc_scramble.h"
64 #define DO4(a) a;a;a;a;
65 #define DO13(a) a;a;a;a;a;a;a;a;a;a;a;a;a;
68 * Scrambles 2352 - 12 = 2340 bytes
70 int scramble_L2(unsigned char *inout);
72 int scramble_L2(unsigned char *inout)
74 #ifndef EDC_SCRAMBLE_NOSWAP
75 unsigned int *f = (unsigned int *)inout;
78 if (!xaligned(inout + 12, sizeof(uint32_t)-1)) {
80 uint8_t *r = inout + 12;
81 const uint8_t *s = yellowbook_scrambler;
84 for (i = (L2_RAW + L2_Q + L2_P +16)/sizeof(unsigned char)/4; --i >= 0;) {
89 uint32_t *r = (uint32_t *) (inout + 12);
90 const uint32_t *s = yellowbook_scrambler_uint32;
93 for (i = (L2_RAW + L2_Q + L2_P +16)/sizeof(uint32_t)/13; --i >= 0;) {
98 #ifndef EDC_SCRAMBLE_NOSWAP
100 /* generate F1 frames */
101 for (i = 2352/sizeof(unsigned int); i; i--) {
102 *f++ = ((*f & 0xff00ff00UL) >> 8) | ((*f & 0x00ff00ffUL) << 8);
109 #include "edc_l2sq.h"
111 static int encode_L2_Q(unsigned char inout[4 + L2_RAW + 4 + 8 + L2_P + L2_Q]);
113 static int encode_L2_Q(unsigned char inout[4 + L2_RAW + 4 + 8 + L2_P + L2_Q])
121 Q = inout + 4 + L2_RAW + 4 + 8 + L2_P;
124 for (j = 0; j < 26; j++) {
125 register unsigned short a;
126 register unsigned short b;
130 for (i = 0; i < 43; i++) {
139 if (dp >= &inout[(4 + L2_RAW + 4 + 8 + L2_P)]) {
140 dp -= (4 + L2_RAW + 4 + 8 + L2_P);
154 static int encode_L2_P(unsigned char inout[4 + L2_RAW + 4 + 8 + L2_P]);
156 static int encode_L2_P(unsigned char inout[4 + L2_RAW + 4 + 8 + L2_P])
163 P = inout + 4 + L2_RAW + 4 + 8;
165 for (j = 0; j < 43; j++) {
166 register unsigned short a;
167 register unsigned short b;
171 for (i = 19; i < 43; i++) {
192 static unsigned char bin2bcd(unsigned p);
194 static unsigned char bin2bcd(unsigned p)
196 return ((p/10)<<4)|(p%10);
199 int cd_build_address(unsigned char inout[], int sectortype, unsigned address)
201 inout[12] = bin2bcd(address / (60*75));
202 inout[13] = bin2bcd((address / 75) % 60);
203 inout[14] = bin2bcd(address % 75);
204 if (sectortype == MODE_0)
206 else if (sectortype == MODE_1)
208 else if (sectortype == MODE_2)
210 else if (sectortype == MODE_2_FORM_1)
212 else if (sectortype == MODE_2_FORM_2)
219 #include "edc_crctable.h"
222 * Called with 2064, 2056 or 2332 byte difference - all dividable by 4.
224 unsigned int build_edc(unsigned char inout[], int from, int upto);
226 unsigned int build_edc(unsigned char inout[], int from, int upto)
228 unsigned char *p = inout+from;
229 unsigned int result = 0;
233 while (--upto >= 0) {
234 result = EDC_crctable[(result ^ *p++) & 0xffL] ^ (result >> 8);
235 result = EDC_crctable[(result ^ *p++) & 0xffL] ^ (result >> 8);
236 result = EDC_crctable[(result ^ *p++) & 0xffL] ^ (result >> 8);
237 result = EDC_crctable[(result ^ *p++) & 0xffL] ^ (result >> 8);
242 /* Layer 2 Product code en/decoder */
243 int do_encode_L2(unsigned char inout[(12 + 4 + L2_RAW+4+8+L2_Q+L2_P)],
244 int sectortype, unsigned address);
247 do_encode_L2(unsigned char inout[(12 + 4 + L2_RAW+4+8+L2_Q+L2_P)],
248 int sectortype, unsigned address)
252 /* SYNCPATTERN "\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff" */
253 #define SYNCPATTERN "\000\377\377\377\377\377\377\377\377\377\377"
255 /* supply initial sync pattern */
256 memcpy(inout, SYNCPATTERN, sizeof(SYNCPATTERN));
258 if (sectortype == MODE_0) {
259 memset(inout + sizeof(SYNCPATTERN), 0, 4 + L2_RAW + 12 + L2_P + L2_Q);
260 cd_build_address(inout, sectortype, address);
264 switch (sectortype) {
267 cd_build_address(inout, sectortype, address);
268 result = build_edc(inout, 0, 16+2048-1);
269 inout[2064+0] = result >> 0L;
270 inout[2064+1] = result >> 8L;
271 inout[2064+2] = result >> 16L;
272 inout[2064+3] = result >> 24L;
273 memset(inout+2064+4, 0, 8);
274 encode_L2_P(inout+12);
275 encode_L2_Q(inout+12);
278 cd_build_address(inout, sectortype, address);
281 result = build_edc(inout, 16, 16+8+2048-1);
282 inout[2072+0] = result >> 0L;
283 inout[2072+1] = result >> 8L;
284 inout[2072+2] = result >> 16L;
285 inout[2072+3] = result >> 24L;
287 /* clear header for P/Q parity calculation */
292 encode_L2_P(inout+12);
293 encode_L2_Q(inout+12);
294 cd_build_address(inout, sectortype, address);
297 cd_build_address(inout, sectortype, address);
298 result = build_edc(inout, 16, 16+8+2324-1);
299 inout[2348+0] = result >> 0L;
300 inout[2348+1] = result >> 8L;
301 inout[2348+2] = result >> 16L;
302 inout[2348+3] = result >> 24L;
312 /*--------------------------------------------------------------------------*/
313 #include "edc_encoder.h"
315 static int encode_L1_Q(unsigned char inout[L1_RAW + L1_Q]);
317 static int encode_L1_Q(unsigned char inout[L1_RAW + L1_Q])
322 memmove(inout+L1_RAW/2+L1_Q, inout+L1_RAW/2, L1_RAW/2);
323 Q = inout + L1_RAW/2;
326 for (i = 0; i < L1_RAW + L1_Q; i++) {
329 if (i == L1_RAW/2) i += L1_Q;
332 unsigned char base = rs_l12_log[data];
334 Q[0] ^= rs_l12_alog[(base+AQ[0][i]) % (unsigned)((1 << RS_L12_BITS)-1)];
335 Q[1] ^= rs_l12_alog[(base+AQ[1][i]) % (unsigned)((1 << RS_L12_BITS)-1)];
336 Q[2] ^= rs_l12_alog[(base+AQ[2][i]) % (unsigned)((1 << RS_L12_BITS)-1)];
337 Q[3] ^= rs_l12_alog[(base+AQ[3][i]) % (unsigned)((1 << RS_L12_BITS)-1)];
343 static int encode_L1_P(unsigned char inout[L1_RAW + L1_Q + L1_P]);
345 static int encode_L1_P(unsigned char inout[L1_RAW + L1_Q + L1_P])
350 P = inout + L1_RAW + L1_Q;
353 for (i = 0; i < L2_RAW + L2_Q + L2_P; i++) {
358 unsigned char base = rs_l12_log[data];
360 P[0] ^= rs_l12_alog[(base+AP[0][i]) % (unsigned)((1 << RS_L12_BITS)-1)];
361 P[1] ^= rs_l12_alog[(base+AP[1][i]) % (unsigned)((1 << RS_L12_BITS)-1)];
362 P[2] ^= rs_l12_alog[(base+AP[2][i]) % (unsigned)((1 << RS_L12_BITS)-1)];
363 P[3] ^= rs_l12_alog[(base+AP[3][i]) % (unsigned)((1 << RS_L12_BITS)-1)];
369 static int decode_L1_Q(unsigned char inout[L1_RAW + L1_Q]);
371 static int decode_L1_Q(unsigned char inout[L1_RAW + L1_Q])
376 static int decode_L1_P(unsigned char in[L1_RAW + L1_Q + L1_P]);
378 static int decode_L1_P(unsigned char in[L1_RAW + L1_Q + L1_P])
383 int decode_L2_Q(unsigned char inout[4 + L2_RAW + 12 + L2_Q]);
385 int decode_L2_Q(unsigned char inout[4 + L2_RAW + 12 + L2_Q])
390 int decode_L2_P(unsigned char inout[4 + L2_RAW + 12 + L2_Q + L2_P]);
392 int decode_L2_P(unsigned char inout[4 + L2_RAW + 12 + L2_Q + L2_P])
397 static int encode_LSUB_Q(unsigned char inout[LSUB_RAW + LSUB_Q]);
399 static int encode_LSUB_Q(unsigned char inout[LSUB_RAW + LSUB_Q])
404 memmove(inout+LSUB_QRAW+LSUB_Q, inout+LSUB_QRAW, LSUB_RAW-LSUB_QRAW);
405 Q = inout + LSUB_QRAW;
407 memset(Q, 0, LSUB_Q);
409 for (i = 0; i < LSUB_QRAW; i++) {
412 data = inout[i] & 0x3f;
414 unsigned char base = rs_sub_rw_log[data];
416 Q[0] ^= rs_sub_rw_alog[(base+SQ[0][i]) % (unsigned)((1 << RS_SUB_RW_BITS)-1)];
417 Q[1] ^= rs_sub_rw_alog[(base+SQ[1][i]) % (unsigned)((1 << RS_SUB_RW_BITS)-1)];
424 static int encode_LSUB_P(unsigned char inout[LSUB_RAW + LSUB_Q + LSUB_P]);
426 static int encode_LSUB_P(unsigned char inout[LSUB_RAW + LSUB_Q + LSUB_P])
431 P = inout + LSUB_RAW + LSUB_Q;
433 memset(P, 0, LSUB_P);
434 for (i = 0; i < LSUB_RAW + LSUB_Q; i++) {
437 data = inout[i] & 0x3f;
439 unsigned char base = rs_sub_rw_log[data];
441 P[0] ^= rs_sub_rw_alog[(base+SP[0][i]) % (unsigned)((1 << RS_SUB_RW_BITS)-1)];
442 P[1] ^= rs_sub_rw_alog[(base+SP[1][i]) % (unsigned)((1 << RS_SUB_RW_BITS)-1)];
443 P[2] ^= rs_sub_rw_alog[(base+SP[2][i]) % (unsigned)((1 << RS_SUB_RW_BITS)-1)];
444 P[3] ^= rs_sub_rw_alog[(base+SP[3][i]) % (unsigned)((1 << RS_SUB_RW_BITS)-1)];
450 int decode_LSUB_Q(unsigned char inout[LSUB_QRAW + LSUB_Q]);
452 int decode_LSUB_Q(unsigned char inout[LSUB_QRAW + LSUB_Q])
454 unsigned char Q[LSUB_Q];
457 memset(Q, 0, LSUB_Q);
458 for (i = LSUB_QRAW + LSUB_Q -1; i>=0; i--) {
461 data = inout[LSUB_QRAW + LSUB_Q -1 -i] & 0x3f;
463 unsigned char base = rs_sub_rw_log[data];
465 Q[0] ^= rs_sub_rw_alog[(base+0*i) % (unsigned)((1 << RS_SUB_RW_BITS)-1)];
466 Q[1] ^= rs_sub_rw_alog[(base+1*i) % (unsigned)((1 << RS_SUB_RW_BITS)-1)];
469 return (Q[0] != 0 || Q[1] != 0);
472 int decode_LSUB_P(unsigned char inout[LSUB_RAW + LSUB_Q + LSUB_P]);
474 int decode_LSUB_P(unsigned char inout[LSUB_RAW + LSUB_Q + LSUB_P])
476 unsigned char P[LSUB_P];
479 memset(P, 0, LSUB_P);
480 for (i = LSUB_RAW + LSUB_Q + LSUB_P-1; i>=0; i--) {
483 data = inout[LSUB_RAW + LSUB_Q + LSUB_P -1 -i] & 0x3f;
485 unsigned char base = rs_sub_rw_log[data];
487 P[0] ^= rs_sub_rw_alog[(base+0*i) % (unsigned)((1 << RS_SUB_RW_BITS)-1)];
488 P[1] ^= rs_sub_rw_alog[(base+1*i) % (unsigned)((1 << RS_SUB_RW_BITS)-1)];
489 P[2] ^= rs_sub_rw_alog[(base+2*i) % (unsigned)((1 << RS_SUB_RW_BITS)-1)];
490 P[3] ^= rs_sub_rw_alog[(base+3*i) % (unsigned)((1 << RS_SUB_RW_BITS)-1)];
493 return (P[0] != 0 || P[1] != 0 || P[2] != 0 || P[3] != 0);
496 /* Layer 1 CIRC en/decoder */
497 #define MAX_L1_DEL1 2
498 static unsigned char l1_delay_line1[MAX_L1_DEL1][L1_RAW];
499 #define MAX_L1_DEL2 108
500 static unsigned char l1_delay_line2[MAX_L1_DEL2][L1_RAW+L1_Q];
501 #define MAX_L1_DEL3 1
502 static unsigned char l1_delay_line3[MAX_L1_DEL3][L1_RAW+L1_Q+L1_P];
503 static unsigned l1_del_index;
505 int do_encode_L1(unsigned char in[L1_RAW*FRAMES_PER_SECTOR],
506 unsigned char out[(L1_RAW+L1_Q+L1_P)*FRAMES_PER_SECTOR],
507 int delay1, int delay2, int delay3, int permute);
509 int do_encode_L1(unsigned char in[L1_RAW*FRAMES_PER_SECTOR],
510 unsigned char out[(L1_RAW+L1_Q+L1_P)*FRAMES_PER_SECTOR],
511 int delay1, int delay2, int delay3, int permute)
515 for (i = 0; i < FRAMES_PER_SECTOR; i++) {
520 memcpy(out, in, L1_RAW);
523 /* shift through delay line 1 */
524 for (j = 0; j < L1_RAW; j++) {
525 if (((j/4) % MAX_L1_DEL1) == 0) {
526 t = l1_delay_line1[l1_del_index % (MAX_L1_DEL1)][j];
527 l1_delay_line1[l1_del_index % (MAX_L1_DEL1)][j] = out[j];
535 t = out[2]; out[2] = out[8]; out[8] = out[10]; out[10] = out[18];
536 out[18] = out[6]; out [6] = t;
537 t = out[3]; out[3] = out[9]; out[9] = out[11]; out[11] = out[19];
538 out[19] = out[7]; out [7] = t;
539 t = out[4]; out[4] = out[16]; out[16] = out[20]; out[20] = out[14];
540 out[14] = out[12]; out [12] = t;
541 t = out[5]; out[5] = out[17]; out[17] = out[21]; out[21] = out[15];
542 out[15] = out[13]; out [13] = t;
549 /* shift through delay line 2 */
550 for (j = 0; j < L1_RAW+L1_Q; j++) {
552 t = l1_delay_line2[(l1_del_index) % MAX_L1_DEL2][j];
553 l1_delay_line2[(l1_del_index + j*4) % MAX_L1_DEL2][j] = out[j];
563 /* shift through delay line 3 */
564 for (j = 0; j < L1_RAW+L1_Q+L1_P; j++) {
565 if (((j) & MAX_L1_DEL3) == 0) {
566 t = l1_delay_line3[0][j];
567 l1_delay_line3[0][j] = out[j];
573 /* invert Q and P parity */
574 for (j = 0; j < L1_Q; j++)
575 out[j+12] = ~out[j+12];
576 for (j = 0; j < L1_P; j++)
577 out[j+28] = ~out[j+28];
580 out += L1_RAW+L1_Q+L1_P;
587 int do_decode_L1(unsigned char in[(L1_RAW+L1_Q+L1_P)*FRAMES_PER_SECTOR],
588 unsigned char out[L1_RAW*FRAMES_PER_SECTOR],
589 int delay1, int delay2, int delay3, int permute);
591 static /* XXX should be non static XXX*/
593 int do_decode_L1(unsigned char in[(L1_RAW+L1_Q+L1_P)*FRAMES_PER_SECTOR],
594 unsigned char out[L1_RAW*FRAMES_PER_SECTOR],
595 int delay1, int delay2, int delay3, int permute)
599 for (i = 0; i < FRAMES_PER_SECTOR; i++) {
604 /* shift through delay line 3 */
605 for (j = 0; j < L1_RAW+L1_Q+L1_P; j++) {
606 if (((j) & MAX_L1_DEL3) != 0) {
607 t = l1_delay_line3[0][j];
608 l1_delay_line3[0][j] = in[j];
614 /* invert Q and P parity */
615 for (j = 0; j < L1_Q; j++)
616 in[j+12] = ~in[j+12];
617 for (j = 0; j < L1_P; j++)
618 in[j+28] = ~in[j+28];
624 /* shift through delay line 2 */
625 for (j = 0; j < L1_RAW+L1_Q; j++) {
626 if (j != L1_RAW+L1_Q-1) {
627 t = l1_delay_line2[(l1_del_index) % MAX_L1_DEL2][j];
628 l1_delay_line2[(l1_del_index + (MAX_L1_DEL2 - j*4)) % MAX_L1_DEL2][j] = in[j];
639 t = in[2]; in[2] = in[6]; in[6] = in[18]; in[18] = in[10];
640 in[10] = in[8]; in [8] = t;
641 t = in[3]; in[3] = in[7]; in[7] = in[19]; in[19] = in[11];
642 in[11] = in[9]; in [9] = t;
643 t = in[4]; in[4] = in[12]; in[12] = in[14]; in[14] = in[20];
644 in[20] = in[16]; in [16] = t;
645 t = in[5]; in[5] = in[13]; in[13] = in[15]; in[15] = in[21];
646 in[21] = in[17]; in [17] = t;
650 /* shift through delay line 1 */
651 for (j = 0; j < L1_RAW; j++) {
652 if (((j/4) % MAX_L1_DEL1) != 0) {
653 t = l1_delay_line1[l1_del_index % (MAX_L1_DEL1)][j];
654 l1_delay_line1[l1_del_index % (MAX_L1_DEL1)][j] = in[j];
661 memcpy(out, in, (L1_RAW));
664 in += L1_RAW+L1_Q+L1_P;
670 static int do_decode_L2(unsigned char in[(L2_RAW+L2_Q+L2_P)],
671 unsigned char out[L2_RAW]);
673 static int do_decode_L2(unsigned char in[(L2_RAW+L2_Q+L2_P)],
674 unsigned char out[L2_RAW])
681 #define MAX_SUB_DEL 8
682 static unsigned char sub_delay_line[MAX_SUB_DEL][LSUB_RAW+LSUB_Q+LSUB_P];
683 static unsigned sub_del_index;
685 /* R-W Subchannel en/decoder */
687 int do_encode_sub(unsigned char in[LSUB_RAW*PACKETS_PER_SUBCHANNELFRAME],
688 unsigned char out[(LSUB_RAW+LSUB_Q+LSUB_P)*PACKETS_PER_SUBCHANNELFRAME],
689 int delay1, int permute);
691 int do_encode_sub(unsigned char in[LSUB_RAW*PACKETS_PER_SUBCHANNELFRAME],
692 unsigned char out[(LSUB_RAW+LSUB_Q+LSUB_P)*PACKETS_PER_SUBCHANNELFRAME],
693 int delay1, int permute)
697 if (in == out) return -1;
699 for (i = 0; i < PACKETS_PER_SUBCHANNELFRAME; i++) {
703 memcpy(out, in, (LSUB_RAW));
713 t = out[1]; out[1] = out[18]; out[18] = t;
714 t = out[2]; out[2] = out[ 5]; out[ 5] = t;
715 t = out[3]; out[3] = out[23]; out[23] = t;
719 /* shift through delay_line */
720 for (j = 0; j < LSUB_RAW+LSUB_Q+LSUB_P; j++) {
721 if ((j % MAX_SUB_DEL) != 0) {
722 t = sub_delay_line[(sub_del_index) % MAX_SUB_DEL][j];
723 sub_delay_line[(sub_del_index + j) % MAX_SUB_DEL][j] = out[j];
729 out += LSUB_RAW+LSUB_Q+LSUB_P;
737 unsigned char in[(LSUB_RAW+LSUB_Q+LSUB_P)*PACKETS_PER_SUBCHANNELFRAME],
738 unsigned char out[LSUB_RAW*PACKETS_PER_SUBCHANNELFRAME],
739 int delay1, int permute);
742 do_decode_sub(unsigned char in[(LSUB_RAW+LSUB_Q+LSUB_P)*PACKETS_PER_SUBCHANNELFRAME],
743 unsigned char out[LSUB_RAW*PACKETS_PER_SUBCHANNELFRAME],
744 int delay1, int permute)
748 if (in == out) return -1;
750 for (i = 0; i < PACKETS_PER_SUBCHANNELFRAME; i++) {
755 /* shift through delay_line */
756 for (j = 0; j < LSUB_RAW+LSUB_Q+LSUB_P; j++) {
757 if ((j % MAX_SUB_DEL) != MAX_SUB_DEL-1) {
758 t = sub_delay_line[(sub_del_index) % MAX_SUB_DEL][j];
759 sub_delay_line[(sub_del_index + (MAX_SUB_DEL - j)) % MAX_SUB_DEL][j] = in[j];
767 t = in[1]; in[1] = in[18]; in[18] = t;
768 t = in[2]; in[2] = in[ 5]; in[ 5] = t;
769 t = in[3]; in[3] = in[23]; in[23] = t;
778 memcpy(out, in, LSUB_QRAW);
779 memcpy(out+LSUB_QRAW, in+LSUB_QRAW+LSUB_Q, LSUB_RAW-LSUB_QRAW);
782 in += LSUB_RAW+LSUB_Q+LSUB_P;
788 static int sectortype = MODE_0;
790 int get_sector_type(void);
792 int get_sector_type()
797 int set_sector_type(int st);
799 int set_sector_type(int st)
815 /* ------------- --------------*/
822 static const unsigned sect_size[8][2] = {
825 /* Layer 1 decode/encode */
826 { (L1_RAW+L1_Q+L1_P)*FRAMES_PER_SECTOR, L1_RAW*FRAMES_PER_SECTOR},
827 /* Layer 2 decode/encode */
828 { 16+L2_RAW+12+L2_Q+L2_P, L2_RAW},
829 /* Layer 1 and 2 decode/encode */
830 { (L1_RAW+L1_Q+L1_P)*FRAMES_PER_SECTOR, L1_RAW*FRAMES_PER_SECTOR},
831 /* Subchannel decode/encode */
832 { (LSUB_RAW+LSUB_Q+LSUB_P)*PACKETS_PER_SUBCHANNELFRAME,
833 LSUB_RAW*PACKETS_PER_SUBCHANNELFRAME},
834 /* Layer 1 and subchannel decode/encode */
835 { (L1_RAW+L1_Q+L1_P)*FRAMES_PER_SECTOR +
836 (LSUB_RAW+LSUB_Q+LSUB_P)*PACKETS_PER_SUBCHANNELFRAME,
837 LSUB_RAW*PACKETS_PER_SUBCHANNELFRAME +
838 L1_RAW*FRAMES_PER_SECTOR},
839 /* Layer 2 and subchannel decode/encode */
841 (LSUB_RAW+LSUB_Q+LSUB_P)*PACKETS_PER_SUBCHANNELFRAME,
842 LSUB_RAW*PACKETS_PER_SUBCHANNELFRAME +
844 /* Layer 1, 2 and subchannel decode/encode */
845 { (L1_RAW+L1_Q+L1_P)*FRAMES_PER_SECTOR +
846 (LSUB_RAW+LSUB_Q+LSUB_P)*PACKETS_PER_SUBCHANNELFRAME,
847 LSUB_RAW*PACKETS_PER_SUBCHANNELFRAME +
848 L1_RAW*FRAMES_PER_SECTOR},
851 int main(int argc, char *argv[])
857 unsigned address = 0;
858 unsigned char *l1_inbuf;
859 unsigned char *l1_outbuf;
860 unsigned char *l2_inbuf;
861 unsigned char *l2_outbuf;
862 unsigned char *sub_inbuf;
863 unsigned char *sub_outbuf;
864 unsigned char *last_outbuf;
865 unsigned char inbuf[(LSUB_RAW+LSUB_Q+LSUB_P)*PACKETS_PER_SUBCHANNELFRAME +
866 (L1_RAW+L1_Q+L1_P)*FRAMES_PER_SECTOR];
867 unsigned char outbuf[(LSUB_RAW+LSUB_Q+LSUB_P)*PACKETS_PER_SUBCHANNELFRAME +
868 (L1_RAW+L1_Q+L1_P)*FRAMES_PER_SECTOR];
869 unsigned load_offset;
871 l1_inbuf = l2_inbuf = sub_inbuf = inbuf;
872 l1_outbuf = l2_outbuf = sub_outbuf = last_outbuf = outbuf;
874 infp = fopen("sectors_in", "rb");
875 outfp = fopen("sectors_out", "wb");
880 switch (sectortype) {
895 if (1 != fread(inbuf+load_offset,
896 sect_size[mask][encode], 1, infp)) {
902 switch (sectortype) {
910 fread(inbuf+load_offset+
911 sect_size[mask][encode],
912 2336 - sect_size[mask][encode],
913 1, infp)) { perror(""); break; }
919 fread(inbuf+load_offset+
920 sect_size[mask][encode],
921 2324 - sect_size[mask][encode],
922 1, infp)) { perror(""); break; }
926 fread(inbuf+load_offset+
927 sect_size[mask][encode],
928 2448 - sect_size[mask][encode],
929 1, infp)) { perror(""); break; }
931 /*memset(inbuf+16+2048,0,12+272);*/
934 do_encode_L2(l2_inbuf, MODE_1, address);
935 if (0) scramble_L2(l2_inbuf);
936 last_outbuf = l1_inbuf = l2_inbuf;
937 l1_outbuf = l2_inbuf;
938 sub_inbuf = l2_inbuf + L2_RAW;
939 sub_outbuf = l2_outbuf + 12 + 4+ L2_RAW+4+ 8+ L2_Q+L2_P;
942 do_encode_L1(l1_inbuf, l1_outbuf,1,1,1,1);
943 last_outbuf = l1_outbuf;
944 sub_inbuf = l1_inbuf + L1_RAW*FRAMES_PER_SECTOR;
945 sub_outbuf = l1_outbuf + (L1_RAW+L1_Q+L1_P)*FRAMES_PER_SECTOR;
948 do_encode_sub(sub_inbuf, sub_outbuf, 0, 0);
952 do_decode_L1(l1_inbuf, l1_outbuf,1,1,1,1);
953 last_outbuf = l2_inbuf = l1_outbuf;
954 l2_outbuf = l1_inbuf;
955 sub_inbuf = l1_inbuf + (L1_RAW+L1_Q+L1_P)*FRAMES_PER_SECTOR;
956 sub_outbuf = l1_outbuf + L1_RAW*FRAMES_PER_SECTOR;
959 do_decode_L2(l2_inbuf, l2_outbuf);
960 last_outbuf = l2_outbuf;
961 sub_inbuf = l2_inbuf + L2_RAW+L2_Q+L2_P;
962 sub_outbuf = l2_outbuf + L2_RAW;
965 do_decode_sub(sub_inbuf, sub_outbuf, 1, 1);
968 if (1 != fwrite(last_outbuf, sect_size[mask][1 - encode], 1, outfp)) {
975 /* flush the data from the delay lines with zeroed sectors, if necessary */
.