Search
lxdream.org :: lxdream/src/gdrom/edc_ecc.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/gdrom/edc_ecc.c
changeset 669:ab344e42bca9
prev644:ccae4bfa5f82
next678:35eb00945316
author nkeynes
date Mon May 12 10:00:13 2008 +0000 (13 years ago)
permissions -rw-r--r--
last change Cleanup most of the -Wall warnings (getting a bit sloppy...)
Convert FP code to use fixed banks rather than indirect pointer
(3-4% faster this way now)
file annotate diff log raw
1.1 --- a/src/gdrom/edc_ecc.c Sun Mar 02 11:38:08 2008 +0000
1.2 +++ b/src/gdrom/edc_ecc.c Mon May 12 10:00:13 2008 +0000
1.3 @@ -1,6 +1,6 @@
1.4 /*
1.5 * Note: This file has been extracted from crkit 1.1.6 and modified to work within
1.6 - * lxdream, but is otherwise unchanged.
1.7 + * lxdream.
1.8 */
1.9 /*
1.10 * This file has been modified for the cdrkit suite.
1.11 @@ -48,13 +48,28 @@
1.12
1.13 #define xaligned(a, s) ((((uintptr_t)(a)) & (s)) == 0 )
1.14
1.15 -/* these prototypes will become public when the function are implemented */
1.16 -static int do_decode_L2(unsigned char in[(L2_RAW+L2_Q+L2_P)],
1.17 - unsigned char out[L2_RAW]);
1.18 +int do_encode_L2(unsigned char inout[(12 + 4 + L2_RAW+4+8+L2_Q+L2_P)],
1.19 + int sectortype, unsigned address);
1.20
1.21 -static int do_decode_L1(unsigned char in[(L1_RAW+L1_Q+L1_P)*FRAMES_PER_SECTOR],
1.22 - unsigned char out[L1_RAW*FRAMES_PER_SECTOR],
1.23 - int delay1, int delay2, int delay3, int scramble);
1.24 +int do_encode_L1(unsigned char in[L1_RAW*FRAMES_PER_SECTOR],
1.25 + unsigned char out[(L1_RAW+L1_Q+L1_P)*FRAMES_PER_SECTOR],
1.26 + int delay1, int delay2, int delay3, int permute);
1.27 +
1.28 +int do_encode_sub(unsigned char in[LSUB_RAW*PACKETS_PER_SUBCHANNELFRAME],
1.29 + unsigned char out[(LSUB_RAW+LSUB_Q+LSUB_P)*PACKETS_PER_SUBCHANNELFRAME],
1.30 + int delay1, int permute);
1.31 +
1.32 +int do_decode_L2(unsigned char in[(L2_RAW+L2_Q+L2_P)],
1.33 + unsigned char out[L2_RAW]);
1.34 +
1.35 +int do_decode_L1(unsigned char in[(L1_RAW+L1_Q+L1_P)*FRAMES_PER_SECTOR],
1.36 + unsigned char out[L1_RAW*FRAMES_PER_SECTOR],
1.37 + int delay1, int delay2, int delay3, int permute);
1.38 +
1.39 +int do_decode_sub(unsigned char in[(LSUB_RAW+LSUB_Q+LSUB_P)*PACKETS_PER_SUBCHANNELFRAME],
1.40 + unsigned char out[LSUB_RAW*PACKETS_PER_SUBCHANNELFRAME],
1.41 + int delay1, int permute);
1.42 +
1.43
1.44
1.45 /* ------------- tables generated by gen_encodes --------------*/
1.46 @@ -240,12 +255,9 @@
1.47 }
1.48
1.49 /* Layer 2 Product code en/decoder */
1.50 +
1.51 int do_encode_L2(unsigned char inout[(12 + 4 + L2_RAW+4+8+L2_Q+L2_P)],
1.52 - int sectortype, unsigned address);
1.53 -
1.54 -int
1.55 -do_encode_L2(unsigned char inout[(12 + 4 + L2_RAW+4+8+L2_Q+L2_P)],
1.56 - int sectortype, unsigned address)
1.57 + int sectortype, unsigned address)
1.58 {
1.59 unsigned int result;
1.60
1.61 @@ -502,10 +514,6 @@
1.62 static unsigned char l1_delay_line3[MAX_L1_DEL3][L1_RAW+L1_Q+L1_P];
1.63 static unsigned l1_del_index;
1.64
1.65 -int do_encode_L1(unsigned char in[L1_RAW*FRAMES_PER_SECTOR],
1.66 - unsigned char out[(L1_RAW+L1_Q+L1_P)*FRAMES_PER_SECTOR],
1.67 - int delay1, int delay2, int delay3, int permute);
1.68 -
1.69 int do_encode_L1(unsigned char in[L1_RAW*FRAMES_PER_SECTOR],
1.70 unsigned char out[(L1_RAW+L1_Q+L1_P)*FRAMES_PER_SECTOR],
1.71 int delay1, int delay2, int delay3, int permute)
1.72 @@ -583,16 +591,9 @@
1.73 return (0);
1.74 }
1.75
1.76 -static
1.77 -int do_decode_L1(unsigned char in[(L1_RAW+L1_Q+L1_P)*FRAMES_PER_SECTOR],
1.78 - unsigned char out[L1_RAW*FRAMES_PER_SECTOR],
1.79 - int delay1, int delay2, int delay3, int permute);
1.80 -
1.81 -static /* XXX should be non static XXX*/
1.82 -
1.83 int do_decode_L1(unsigned char in[(L1_RAW+L1_Q+L1_P)*FRAMES_PER_SECTOR],
1.84 - unsigned char out[L1_RAW*FRAMES_PER_SECTOR],
1.85 - int delay1, int delay2, int delay3, int permute)
1.86 + unsigned char out[L1_RAW*FRAMES_PER_SECTOR],
1.87 + int delay1, int delay2, int delay3, int permute)
1.88 {
1.89 int i;
1.90
1.91 @@ -667,10 +668,7 @@
1.92 return (0);
1.93 }
1.94
1.95 -static int do_decode_L2(unsigned char in[(L2_RAW+L2_Q+L2_P)],
1.96 - unsigned char out[L2_RAW]);
1.97 -
1.98 -static int do_decode_L2(unsigned char in[(L2_RAW+L2_Q+L2_P)],
1.99 +int do_decode_L2(unsigned char in[(L2_RAW+L2_Q+L2_P)],
1.100 unsigned char out[L2_RAW])
1.101 {
1.102 return (0);
1.103 @@ -684,10 +682,6 @@
1.104
1.105 /* R-W Subchannel en/decoder */
1.106
1.107 -int do_encode_sub(unsigned char in[LSUB_RAW*PACKETS_PER_SUBCHANNELFRAME],
1.108 - unsigned char out[(LSUB_RAW+LSUB_Q+LSUB_P)*PACKETS_PER_SUBCHANNELFRAME],
1.109 - int delay1, int permute);
1.110 -
1.111 int do_encode_sub(unsigned char in[LSUB_RAW*PACKETS_PER_SUBCHANNELFRAME],
1.112 unsigned char out[(LSUB_RAW+LSUB_Q+LSUB_P)*PACKETS_PER_SUBCHANNELFRAME],
1.113 int delay1, int permute)
1.114 @@ -732,16 +726,9 @@
1.115 return (0);
1.116 }
1.117
1.118 -int
1.119 -do_decode_sub(
1.120 - unsigned char in[(LSUB_RAW+LSUB_Q+LSUB_P)*PACKETS_PER_SUBCHANNELFRAME],
1.121 - unsigned char out[LSUB_RAW*PACKETS_PER_SUBCHANNELFRAME],
1.122 - int delay1, int permute);
1.123 -
1.124 -int
1.125 -do_decode_sub(unsigned char in[(LSUB_RAW+LSUB_Q+LSUB_P)*PACKETS_PER_SUBCHANNELFRAME],
1.126 - unsigned char out[LSUB_RAW*PACKETS_PER_SUBCHANNELFRAME],
1.127 - int delay1, int permute)
1.128 +int do_decode_sub(unsigned char in[(LSUB_RAW+LSUB_Q+LSUB_P)*PACKETS_PER_SUBCHANNELFRAME],
1.129 + unsigned char out[LSUB_RAW*PACKETS_PER_SUBCHANNELFRAME],
1.130 + int delay1, int permute)
1.131 {
1.132 int i;
1.133
1.134 @@ -812,168 +799,3 @@
1.135 }
1.136 }
1.137
1.138 -/* ------------- --------------*/
1.139 -#ifdef MAIN
1.140 -
1.141 -#define DO_L1 1
1.142 -#define DO_L2 2
1.143 -#define DO_SUB 4
1.144 -
1.145 -static const unsigned sect_size[8][2] = {
1.146 -/* nothing */
1.147 -{0,0},
1.148 -/* Layer 1 decode/encode */
1.149 -{ (L1_RAW+L1_Q+L1_P)*FRAMES_PER_SECTOR, L1_RAW*FRAMES_PER_SECTOR},
1.150 -/* Layer 2 decode/encode */
1.151 -{ 16+L2_RAW+12+L2_Q+L2_P, L2_RAW},
1.152 -/* Layer 1 and 2 decode/encode */
1.153 -{ (L1_RAW+L1_Q+L1_P)*FRAMES_PER_SECTOR, L1_RAW*FRAMES_PER_SECTOR},
1.154 -/* Subchannel decode/encode */
1.155 -{ (LSUB_RAW+LSUB_Q+LSUB_P)*PACKETS_PER_SUBCHANNELFRAME,
1.156 - LSUB_RAW*PACKETS_PER_SUBCHANNELFRAME},
1.157 -/* Layer 1 and subchannel decode/encode */
1.158 -{ (L1_RAW+L1_Q+L1_P)*FRAMES_PER_SECTOR +
1.159 - (LSUB_RAW+LSUB_Q+LSUB_P)*PACKETS_PER_SUBCHANNELFRAME,
1.160 - LSUB_RAW*PACKETS_PER_SUBCHANNELFRAME +
1.161 - L1_RAW*FRAMES_PER_SECTOR},
1.162 -/* Layer 2 and subchannel decode/encode */
1.163 -{ L2_RAW+L2_Q+L2_P+
1.164 - (LSUB_RAW+LSUB_Q+LSUB_P)*PACKETS_PER_SUBCHANNELFRAME,
1.165 - LSUB_RAW*PACKETS_PER_SUBCHANNELFRAME +
1.166 - L2_RAW},
1.167 -/* Layer 1, 2 and subchannel decode/encode */
1.168 -{ (L1_RAW+L1_Q+L1_P)*FRAMES_PER_SECTOR +
1.169 - (LSUB_RAW+LSUB_Q+LSUB_P)*PACKETS_PER_SUBCHANNELFRAME,
1.170 - LSUB_RAW*PACKETS_PER_SUBCHANNELFRAME +
1.171 - L1_RAW*FRAMES_PER_SECTOR},
1.172 -};
1.173 -
1.174 -int main(int argc, char *argv[])
1.175 -{
1.176 - int encode = 1;
1.177 - int mask = DO_L2;
1.178 - FILE *infp;
1.179 - FILE *outfp;
1.180 - unsigned address = 0;
1.181 - unsigned char *l1_inbuf;
1.182 - unsigned char *l1_outbuf;
1.183 - unsigned char *l2_inbuf;
1.184 - unsigned char *l2_outbuf;
1.185 - unsigned char *sub_inbuf;
1.186 - unsigned char *sub_outbuf;
1.187 - unsigned char *last_outbuf;
1.188 - unsigned char inbuf[(LSUB_RAW+LSUB_Q+LSUB_P)*PACKETS_PER_SUBCHANNELFRAME +
1.189 - (L1_RAW+L1_Q+L1_P)*FRAMES_PER_SECTOR];
1.190 - unsigned char outbuf[(LSUB_RAW+LSUB_Q+LSUB_P)*PACKETS_PER_SUBCHANNELFRAME +
1.191 - (L1_RAW+L1_Q+L1_P)*FRAMES_PER_SECTOR];
1.192 - unsigned load_offset;
1.193 -
1.194 - l1_inbuf = l2_inbuf = sub_inbuf = inbuf;
1.195 - l1_outbuf = l2_outbuf = sub_outbuf = last_outbuf = outbuf;
1.196 -
1.197 - infp = fopen("sectors_in", "rb");
1.198 - outfp = fopen("sectors_out", "wb");
1.199 -
1.200 - sectortype= MODE_1;
1.201 - address = 0 + 75*2;
1.202 -
1.203 - switch (sectortype) {
1.204 -
1.205 - case MODE_1:
1.206 - case MODE_2:
1.207 - load_offset = 16;
1.208 - break;
1.209 - case MODE_2_FORM_1:
1.210 - case MODE_2_FORM_2:
1.211 - load_offset = 24;
1.212 - break;
1.213 - default:
1.214 - load_offset = 0;
1.215 - }
1.216 - while(1) {
1.217 -
1.218 - if (1 != fread(inbuf+load_offset,
1.219 - sect_size[mask][encode], 1, infp)) {
1.220 - perror("");
1.221 - break;
1.222 - }
1.223 - if (encode == 1) {
1.224 - if (mask & DO_L2) {
1.225 - switch (sectortype) {
1.226 -
1.227 - case MODE_0:
1.228 - break;
1.229 - case MODE_1:
1.230 - break;
1.231 - case MODE_2:
1.232 - if (1 !=
1.233 - fread(inbuf+load_offset+
1.234 - sect_size[mask][encode],
1.235 - 2336 - sect_size[mask][encode],
1.236 - 1, infp)) { perror(""); break; }
1.237 - break;
1.238 - case MODE_2_FORM_1:
1.239 - break;
1.240 - case MODE_2_FORM_2:
1.241 - if (1 !=
1.242 - fread(inbuf+load_offset+
1.243 - sect_size[mask][encode],
1.244 - 2324 - sect_size[mask][encode],
1.245 - 1, infp)) { perror(""); break; }
1.246 - break;
1.247 - default:
1.248 - if (1 !=
1.249 - fread(inbuf+load_offset+
1.250 - sect_size[mask][encode],
1.251 - 2448 - sect_size[mask][encode],
1.252 - 1, infp)) { perror(""); break; }
1.253 - memset(inbuf,0,16);
1.254 - /*memset(inbuf+16+2048,0,12+272);*/
1.255 - break;
1.256 - }
1.257 - do_encode_L2(l2_inbuf, MODE_1, address);
1.258 - if (0) scramble_L2(l2_inbuf);
1.259 - last_outbuf = l1_inbuf = l2_inbuf;
1.260 - l1_outbuf = l2_inbuf;
1.261 - sub_inbuf = l2_inbuf + L2_RAW;
1.262 - sub_outbuf = l2_outbuf + 12 + 4+ L2_RAW+4+ 8+ L2_Q+L2_P;
1.263 - }
1.264 - if (mask & DO_L1) {
1.265 - do_encode_L1(l1_inbuf, l1_outbuf,1,1,1,1);
1.266 - last_outbuf = l1_outbuf;
1.267 - sub_inbuf = l1_inbuf + L1_RAW*FRAMES_PER_SECTOR;
1.268 - sub_outbuf = l1_outbuf + (L1_RAW+L1_Q+L1_P)*FRAMES_PER_SECTOR;
1.269 - }
1.270 - if (mask & DO_SUB) {
1.271 - do_encode_sub(sub_inbuf, sub_outbuf, 0, 0);
1.272 - }
1.273 - } else {
1.274 - if (mask & DO_L1) {
1.275 - do_decode_L1(l1_inbuf, l1_outbuf,1,1,1,1);
1.276 - last_outbuf = l2_inbuf = l1_outbuf;
1.277 - l2_outbuf = l1_inbuf;
1.278 - sub_inbuf = l1_inbuf + (L1_RAW+L1_Q+L1_P)*FRAMES_PER_SECTOR;
1.279 - sub_outbuf = l1_outbuf + L1_RAW*FRAMES_PER_SECTOR;
1.280 - }
1.281 - if (mask & DO_L2) {
1.282 - do_decode_L2(l2_inbuf, l2_outbuf);
1.283 - last_outbuf = l2_outbuf;
1.284 - sub_inbuf = l2_inbuf + L2_RAW+L2_Q+L2_P;
1.285 - sub_outbuf = l2_outbuf + L2_RAW;
1.286 - }
1.287 - if (mask & DO_SUB) {
1.288 - do_decode_sub(sub_inbuf, sub_outbuf, 1, 1);
1.289 - }
1.290 - }
1.291 - if (1 != fwrite(last_outbuf, sect_size[mask][1 - encode], 1, outfp)) {
1.292 - perror("");
1.293 - break;
1.294 - }
1.295 - address++;
1.296 - }
1.297 -#if 0
1.298 - /* flush the data from the delay lines with zeroed sectors, if necessary */
1.299 -#endif
1.300 - return (0);
1.301 -}
1.302 -#endif
.