summaryrefslogtreecommitdiff
path: root/includes/yazedc.h
blob: 298c0eb18096af8deb490b220247548269adf9b5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*  
 *  PSX-Tools Bundle Pack  
 *  Copyright (C) 1998 Heiko Eissfeldt 
 *  portions used& Chris Smith 
 *  First 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  
 */

#ifndef __YAZEDC_H__

#include "Exceptions.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

/* 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

/* 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);
/* 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);

/* generates f2 frames from otherwise fully formatted sectors (generated by
   do_encode_L2()). */
    int scramble_L2(unsigned char *inout);

    unsigned char minute, second, frame;

  private:
    int sectortype;
    int build_address(unsigned char inout[], int sectortype, unsigned address);

};

#endif