# HG changeset patch # User nkeynes # Date 1204457888 0 # Node ID ccae4bfa5f82b0f3ea060eb5fc91b8c8975d69d0 # Parent 653b0a70f173615c29c874e108019e809db204f3 Bug #59: Add provisional support for all CD read modes (not validated) --- a/src/Makefile.am Tue Feb 26 01:10:48 2008 +0000 +++ b/src/Makefile.am Sun Mar 02 11:38:08 2008 +0000 @@ -25,6 +25,8 @@ syscall.c syscall.h bios.c dcload.c \ gdrom/ide.c gdrom/ide.h gdrom/packet.h gdrom/gdimage.c \ gdrom/gdrom.c gdrom/gdrom.h gdrom/nrg.c gdrom/cdi.c gdrom/gdi.c \ + gdrom/edc_ecc.c gdrom/ecc.h gdrom/edc_crctable.h gdrom/edc_encoder.h \ + gdrom/edc_l2sq.h gdrom/scramble.h \ dreamcast.c dreamcast.h eventq.c eventq.h \ sh4/sh4.c sh4/intc.c sh4/intc.h sh4/sh4mem.c sh4/timer.c sh4/dmac.c \ sh4/mmu.c sh4/sh4core.c sh4/sh4core.h sh4/sh4dasm.c sh4/sh4dasm.h \ --- a/src/Makefile.in Tue Feb 26 01:10:48 2008 +0000 +++ b/src/Makefile.in Sun Mar 02 11:38:08 2008 +0000 @@ -222,6 +222,8 @@ syscall.c syscall.h bios.c dcload.c \ gdrom/ide.c gdrom/ide.h gdrom/packet.h gdrom/gdimage.c \ gdrom/gdrom.c gdrom/gdrom.h gdrom/nrg.c gdrom/cdi.c gdrom/gdi.c \ + gdrom/edc_ecc.c gdrom/ecc.h gdrom/edc_crctable.h gdrom/edc_encoder.h \ + gdrom/edc_l2sq.h gdrom/scramble.h \ dreamcast.c dreamcast.h eventq.c eventq.h \ sh4/sh4.c sh4/intc.c sh4/intc.h sh4/sh4mem.c sh4/timer.c sh4/dmac.c \ sh4/mmu.c sh4/sh4core.c sh4/sh4core.h sh4/sh4dasm.c sh4/sh4dasm.h \ @@ -280,6 +282,8 @@ watch.c asic.c asic.h syscall.c syscall.h bios.c dcload.c \ gdrom/ide.c gdrom/ide.h gdrom/packet.h gdrom/gdimage.c \ gdrom/gdrom.c gdrom/gdrom.h gdrom/nrg.c gdrom/cdi.c gdrom/gdi.c \ + gdrom/edc_ecc.c gdrom/ecc.h gdrom/edc_crctable.h \ + gdrom/edc_encoder.h gdrom/edc_l2sq.h gdrom/scramble.h \ dreamcast.c dreamcast.h eventq.c eventq.h sh4/sh4.c sh4/intc.c \ sh4/intc.h sh4/sh4mem.c sh4/timer.c sh4/dmac.c sh4/mmu.c \ sh4/sh4core.c sh4/sh4core.h sh4/sh4dasm.c sh4/sh4dasm.h \ @@ -322,22 +326,23 @@ watch.$(OBJEXT) asic.$(OBJEXT) syscall.$(OBJEXT) bios.$(OBJEXT) \ dcload.$(OBJEXT) ide.$(OBJEXT) gdimage.$(OBJEXT) \ gdrom.$(OBJEXT) nrg.$(OBJEXT) cdi.$(OBJEXT) gdi.$(OBJEXT) \ - dreamcast.$(OBJEXT) eventq.$(OBJEXT) sh4.$(OBJEXT) \ - intc.$(OBJEXT) sh4mem.$(OBJEXT) timer.$(OBJEXT) dmac.$(OBJEXT) \ - mmu.$(OBJEXT) sh4core.$(OBJEXT) sh4dasm.$(OBJEXT) \ - sh4mmio.$(OBJEXT) scif.$(OBJEXT) sh4stat.$(OBJEXT) \ - xltcache.$(OBJEXT) armcore.$(OBJEXT) armdasm.$(OBJEXT) \ - armmem.$(OBJEXT) aica.$(OBJEXT) audio.$(OBJEXT) pvr2.$(OBJEXT) \ - pvr2mem.$(OBJEXT) tacore.$(OBJEXT) render.$(OBJEXT) \ - rendcore.$(OBJEXT) rendbkg.$(OBJEXT) rendsort.$(OBJEXT) \ - texcache.$(OBJEXT) yuv.$(OBJEXT) rendsave.$(OBJEXT) \ - maple.$(OBJEXT) controller.$(OBJEXT) kbd.$(OBJEXT) \ - mouse.$(OBJEXT) loader.$(OBJEXT) bootstrap.$(OBJEXT) \ - util.$(OBJEXT) display.$(OBJEXT) audio_null.$(OBJEXT) \ - video_null.$(OBJEXT) gl_common.$(OBJEXT) gl_fbo.$(OBJEXT) \ - gl_sl.$(OBJEXT) gl_slsrc.$(OBJEXT) $(am__objects_1) \ - $(am__objects_2) $(am__objects_3) $(am__objects_4) \ - $(am__objects_5) $(am__objects_6) $(am__objects_7) + edc_ecc.$(OBJEXT) dreamcast.$(OBJEXT) eventq.$(OBJEXT) \ + sh4.$(OBJEXT) intc.$(OBJEXT) sh4mem.$(OBJEXT) timer.$(OBJEXT) \ + dmac.$(OBJEXT) mmu.$(OBJEXT) sh4core.$(OBJEXT) \ + sh4dasm.$(OBJEXT) sh4mmio.$(OBJEXT) scif.$(OBJEXT) \ + sh4stat.$(OBJEXT) xltcache.$(OBJEXT) armcore.$(OBJEXT) \ + armdasm.$(OBJEXT) armmem.$(OBJEXT) aica.$(OBJEXT) \ + audio.$(OBJEXT) pvr2.$(OBJEXT) pvr2mem.$(OBJEXT) \ + tacore.$(OBJEXT) render.$(OBJEXT) rendcore.$(OBJEXT) \ + rendbkg.$(OBJEXT) rendsort.$(OBJEXT) texcache.$(OBJEXT) \ + yuv.$(OBJEXT) rendsave.$(OBJEXT) maple.$(OBJEXT) \ + controller.$(OBJEXT) kbd.$(OBJEXT) mouse.$(OBJEXT) \ + loader.$(OBJEXT) bootstrap.$(OBJEXT) util.$(OBJEXT) \ + display.$(OBJEXT) audio_null.$(OBJEXT) video_null.$(OBJEXT) \ + gl_common.$(OBJEXT) gl_fbo.$(OBJEXT) gl_sl.$(OBJEXT) \ + gl_slsrc.$(OBJEXT) $(am__objects_1) $(am__objects_2) \ + $(am__objects_3) $(am__objects_4) $(am__objects_5) \ + $(am__objects_6) $(am__objects_7) lxdream_OBJECTS = $(am_lxdream_OBJECTS) lxdream_DEPENDENCIES = lxdream_LDFLAGS = @@ -378,36 +383,36 @@ @AMDEP_TRUE@ ./$(DEPDIR)/dis-buf.Po ./$(DEPDIR)/dis-init.Po \ @AMDEP_TRUE@ ./$(DEPDIR)/display.Po ./$(DEPDIR)/dmac.Po \ @AMDEP_TRUE@ ./$(DEPDIR)/dreamcast.Po ./$(DEPDIR)/dump_win.Po \ -@AMDEP_TRUE@ ./$(DEPDIR)/eventq.Po ./$(DEPDIR)/gdi.Po \ -@AMDEP_TRUE@ ./$(DEPDIR)/gdimage.Po ./$(DEPDIR)/gdrom.Po \ -@AMDEP_TRUE@ ./$(DEPDIR)/gdrom_menu.Po ./$(DEPDIR)/gendec.Po \ -@AMDEP_TRUE@ ./$(DEPDIR)/genglsl.Po ./$(DEPDIR)/gl_common.Po \ -@AMDEP_TRUE@ ./$(DEPDIR)/gl_fbo.Po ./$(DEPDIR)/gl_sl.Po \ -@AMDEP_TRUE@ ./$(DEPDIR)/gl_slsrc.Po ./$(DEPDIR)/gtkcb.Po \ -@AMDEP_TRUE@ ./$(DEPDIR)/gtkui.Po ./$(DEPDIR)/i386-dis.Po \ -@AMDEP_TRUE@ ./$(DEPDIR)/ide.Po ./$(DEPDIR)/insparse.Po \ -@AMDEP_TRUE@ ./$(DEPDIR)/intc.Po ./$(DEPDIR)/joy_linux.Po \ -@AMDEP_TRUE@ ./$(DEPDIR)/kbd.Po ./$(DEPDIR)/loader.Po \ -@AMDEP_TRUE@ ./$(DEPDIR)/main.Po ./$(DEPDIR)/main_win.Po \ -@AMDEP_TRUE@ ./$(DEPDIR)/maple.Po ./$(DEPDIR)/mem.Po \ -@AMDEP_TRUE@ ./$(DEPDIR)/mmio_win.Po ./$(DEPDIR)/mmu.Po \ -@AMDEP_TRUE@ ./$(DEPDIR)/mouse.Po ./$(DEPDIR)/nrg.Po \ -@AMDEP_TRUE@ ./$(DEPDIR)/path_dlg.Po ./$(DEPDIR)/pvr2.Po \ -@AMDEP_TRUE@ ./$(DEPDIR)/pvr2mem.Po ./$(DEPDIR)/rendbkg.Po \ -@AMDEP_TRUE@ ./$(DEPDIR)/rendcore.Po ./$(DEPDIR)/render.Po \ -@AMDEP_TRUE@ ./$(DEPDIR)/rendsave.Po ./$(DEPDIR)/rendsort.Po \ -@AMDEP_TRUE@ ./$(DEPDIR)/scif.Po ./$(DEPDIR)/sh4.Po \ -@AMDEP_TRUE@ ./$(DEPDIR)/sh4core.Po ./$(DEPDIR)/sh4dasm.Po \ -@AMDEP_TRUE@ ./$(DEPDIR)/sh4mem.Po ./$(DEPDIR)/sh4mmio.Po \ -@AMDEP_TRUE@ ./$(DEPDIR)/sh4stat.Po ./$(DEPDIR)/sh4trans.Po \ -@AMDEP_TRUE@ ./$(DEPDIR)/sh4x86.Po ./$(DEPDIR)/syscall.Po \ -@AMDEP_TRUE@ ./$(DEPDIR)/tacore.Po ./$(DEPDIR)/testsh4x86.Po \ -@AMDEP_TRUE@ ./$(DEPDIR)/testxlt.Po ./$(DEPDIR)/texcache.Po \ -@AMDEP_TRUE@ ./$(DEPDIR)/timer.Po ./$(DEPDIR)/util.Po \ -@AMDEP_TRUE@ ./$(DEPDIR)/video_glx.Po ./$(DEPDIR)/video_gtk.Po \ -@AMDEP_TRUE@ ./$(DEPDIR)/video_null.Po ./$(DEPDIR)/watch.Po \ -@AMDEP_TRUE@ ./$(DEPDIR)/x86dasm.Po ./$(DEPDIR)/xltcache.Po \ -@AMDEP_TRUE@ ./$(DEPDIR)/yuv.Po +@AMDEP_TRUE@ ./$(DEPDIR)/edc_ecc.Po ./$(DEPDIR)/eventq.Po \ +@AMDEP_TRUE@ ./$(DEPDIR)/gdi.Po ./$(DEPDIR)/gdimage.Po \ +@AMDEP_TRUE@ ./$(DEPDIR)/gdrom.Po ./$(DEPDIR)/gdrom_menu.Po \ +@AMDEP_TRUE@ ./$(DEPDIR)/gendec.Po ./$(DEPDIR)/genglsl.Po \ +@AMDEP_TRUE@ ./$(DEPDIR)/gl_common.Po ./$(DEPDIR)/gl_fbo.Po \ +@AMDEP_TRUE@ ./$(DEPDIR)/gl_sl.Po ./$(DEPDIR)/gl_slsrc.Po \ +@AMDEP_TRUE@ ./$(DEPDIR)/gtkcb.Po ./$(DEPDIR)/gtkui.Po \ +@AMDEP_TRUE@ ./$(DEPDIR)/i386-dis.Po ./$(DEPDIR)/ide.Po \ +@AMDEP_TRUE@ ./$(DEPDIR)/insparse.Po ./$(DEPDIR)/intc.Po \ +@AMDEP_TRUE@ ./$(DEPDIR)/joy_linux.Po ./$(DEPDIR)/kbd.Po \ +@AMDEP_TRUE@ ./$(DEPDIR)/loader.Po ./$(DEPDIR)/main.Po \ +@AMDEP_TRUE@ ./$(DEPDIR)/main_win.Po ./$(DEPDIR)/maple.Po \ +@AMDEP_TRUE@ ./$(DEPDIR)/mem.Po ./$(DEPDIR)/mmio_win.Po \ +@AMDEP_TRUE@ ./$(DEPDIR)/mmu.Po ./$(DEPDIR)/mouse.Po \ +@AMDEP_TRUE@ ./$(DEPDIR)/nrg.Po ./$(DEPDIR)/path_dlg.Po \ +@AMDEP_TRUE@ ./$(DEPDIR)/pvr2.Po ./$(DEPDIR)/pvr2mem.Po \ +@AMDEP_TRUE@ ./$(DEPDIR)/rendbkg.Po ./$(DEPDIR)/rendcore.Po \ +@AMDEP_TRUE@ ./$(DEPDIR)/render.Po ./$(DEPDIR)/rendsave.Po \ +@AMDEP_TRUE@ ./$(DEPDIR)/rendsort.Po ./$(DEPDIR)/scif.Po \ +@AMDEP_TRUE@ ./$(DEPDIR)/sh4.Po ./$(DEPDIR)/sh4core.Po \ +@AMDEP_TRUE@ ./$(DEPDIR)/sh4dasm.Po ./$(DEPDIR)/sh4mem.Po \ +@AMDEP_TRUE@ ./$(DEPDIR)/sh4mmio.Po ./$(DEPDIR)/sh4stat.Po \ +@AMDEP_TRUE@ ./$(DEPDIR)/sh4trans.Po ./$(DEPDIR)/sh4x86.Po \ +@AMDEP_TRUE@ ./$(DEPDIR)/syscall.Po ./$(DEPDIR)/tacore.Po \ +@AMDEP_TRUE@ ./$(DEPDIR)/testsh4x86.Po ./$(DEPDIR)/testxlt.Po \ +@AMDEP_TRUE@ ./$(DEPDIR)/texcache.Po ./$(DEPDIR)/timer.Po \ +@AMDEP_TRUE@ ./$(DEPDIR)/util.Po ./$(DEPDIR)/video_glx.Po \ +@AMDEP_TRUE@ ./$(DEPDIR)/video_gtk.Po ./$(DEPDIR)/video_null.Po \ +@AMDEP_TRUE@ ./$(DEPDIR)/watch.Po ./$(DEPDIR)/x86dasm.Po \ +@AMDEP_TRUE@ ./$(DEPDIR)/xltcache.Po ./$(DEPDIR)/yuv.Po COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) CCLD = $(CC) @@ -509,6 +514,7 @@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dmac.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dreamcast.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dump_win.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/edc_ecc.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eventq.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gdi.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gdimage.Po@am__quote@ @@ -811,6 +817,28 @@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o gdi.obj `if test -f 'gdrom/gdi.c'; then $(CYGPATH_W) 'gdrom/gdi.c'; else $(CYGPATH_W) '$(srcdir)/gdrom/gdi.c'; fi` +edc_ecc.o: gdrom/edc_ecc.c +@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT edc_ecc.o -MD -MP -MF "$(DEPDIR)/edc_ecc.Tpo" \ +@am__fastdepCC_TRUE@ -c -o edc_ecc.o `test -f 'gdrom/edc_ecc.c' || echo '$(srcdir)/'`gdrom/edc_ecc.c; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/edc_ecc.Tpo" "$(DEPDIR)/edc_ecc.Po"; \ +@am__fastdepCC_TRUE@ else rm -f "$(DEPDIR)/edc_ecc.Tpo"; exit 1; \ +@am__fastdepCC_TRUE@ fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='gdrom/edc_ecc.c' object='edc_ecc.o' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ depfile='$(DEPDIR)/edc_ecc.Po' tmpdepfile='$(DEPDIR)/edc_ecc.TPo' @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o edc_ecc.o `test -f 'gdrom/edc_ecc.c' || echo '$(srcdir)/'`gdrom/edc_ecc.c + +edc_ecc.obj: gdrom/edc_ecc.c +@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT edc_ecc.obj -MD -MP -MF "$(DEPDIR)/edc_ecc.Tpo" \ +@am__fastdepCC_TRUE@ -c -o edc_ecc.obj `if test -f 'gdrom/edc_ecc.c'; then $(CYGPATH_W) 'gdrom/edc_ecc.c'; else $(CYGPATH_W) '$(srcdir)/gdrom/edc_ecc.c'; fi`; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/edc_ecc.Tpo" "$(DEPDIR)/edc_ecc.Po"; \ +@am__fastdepCC_TRUE@ else rm -f "$(DEPDIR)/edc_ecc.Tpo"; exit 1; \ +@am__fastdepCC_TRUE@ fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='gdrom/edc_ecc.c' object='edc_ecc.obj' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ depfile='$(DEPDIR)/edc_ecc.Po' tmpdepfile='$(DEPDIR)/edc_ecc.TPo' @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o edc_ecc.obj `if test -f 'gdrom/edc_ecc.c'; then $(CYGPATH_W) 'gdrom/edc_ecc.c'; else $(CYGPATH_W) '$(srcdir)/gdrom/edc_ecc.c'; fi` + sh4.o: sh4/sh4.c @am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT sh4.o -MD -MP -MF "$(DEPDIR)/sh4.Tpo" \ @am__fastdepCC_TRUE@ -c -o sh4.o `test -f 'sh4/sh4.c' || echo '$(srcdir)/'`sh4/sh4.c; \ --- a/src/drivers/cd_linux.c Tue Feb 26 01:10:48 2008 +0000 +++ b/src/drivers/cd_linux.c Sun Mar 02 11:38:08 2008 +0000 @@ -127,7 +127,6 @@ } disc->read_sector = linux_read_sector; disc->drive_status = linux_drive_status; - ((gdrom_image_t)disc)->disc_type = IDE_DISC_CDROM; return disc; } @@ -167,7 +166,7 @@ int last_track = -1; int leadout = -1; int len = (buf[0] << 8) | buf[1]; - int session_type = GDROM_MODE1; + int session_type = -1; int i; for( i = 4; idisc_type = session_type; + break; case 0x1A2: /* leadout */ leadout = MSFTOLBA(buf[i+8], buf[i+9], buf[i+10]); break; @@ -256,7 +257,20 @@ cmd[6] = 0; cmd[7] = 0; cmd[8] = 1; - cmd[9] = 0x10; + + if( READ_CD_RAW(mode) ) { + cmd[9] = 0xF0; + } else { + if( READ_CD_HEADER(mode) ) { + cmd[9] = 0xA0; + } + if( READ_CD_SUBHEAD(mode) ) { + cmd[9] |= 0x40; + } + if( READ_CD_DATA(mode) ) { + cmd[9] |= 0x10; + } + } gdrom_error_t status = linux_send_command( fd, cmd, buf, §or_size, CGC_DATA_READ ); if( status != 0 ) { @@ -285,7 +299,7 @@ cgc.sense = &sense; cgc.data_direction = direction; - if( ioctl(fd, CDROM_SEND_PACKET, &cgc) == -1 ) { + if( ioctl(fd, CDROM_SEND_PACKET, &cgc) < 0 ) { if( sense.sense_key == 0 ) { return -1; } else { --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/gdrom/README.LIBEDC Sun Mar 02 11:38:08 2008 +0000 @@ -0,0 +1,123 @@ +This describes the program as shipped with cdrkit, a spinoff from the +cdrtools project. However, the cdrtools developers are no longer +involved in the development of this spinoff and therefore shall not +be made responsible for any problem caused by it. Do not try to get +support for this program by contacting the original authors. + +This is a small description for the Reed-Solomon library intended for +CD sector formatting. + +Basics: +It is assumed that you have a basic knowledge of cd sector formats. + +The library can handle three types of sector data: + data sectors, + audio sectors, and + sub channel r-w sectors + +Currently only encoding is implemented. Decoding and optionally +error correction is planned for later. + +Stages: + +The process of sector formatting has several stages. Beginning with +a data sector (2048, 2324, or 2336 bytes) a sector of 2352 bytes is +built. This format can be read raw by SCSI MMC-2 and ATAPI drives and +is accepted by cd burners. The additions are an optionally 32 bit CRC +checksum and two layers of Reed-Solomon codes (called Reed-Solomon +Product Code RSPC). +This sector is then scrambled (exor'ed with a bitstream). +The result is called F1 frames. Afterwards even and odd bytes are +swapped, this is called F2 frames. The result is equivalent to an +audio sector and is treated as such by the cd burner. +So, if we wrote a series of sectors (F2 frames) into a CDR file and +later burned them as 'audio', they would turn up as perfect data sectors. + +So, now we are at the level of audio sectors. Audio sectors get their +own error correction data (called CIRC). Sector size goes up to +3136 bytes (that is 4/3 times 2352 bytes). Furthermore different +words get delayed differently and swap positions. The result is ready +to be fed into the so-called EightFourteenModulator (when subchannels +have been added). + +Now, only sub channels are missing. While the p and q sub +channels have to be generated elsewhere, any supplied r-w subchannel +user data is protected by two levels of error correction +codes. This format is read by cd burners when burning cd+graphics. +The cdimage is a sequence of sectors, each containing audio data and +after that subchannel data. +Similar to audio sectors delaying and permutation of words +takes place. After that the cd burner would mix sub channel data with +the formatted audio sectors to feed the EFModulator. + +NOTE: Most of the described stages need not to be done in order to +prepare sectors for burning, since all cd burners do at least CIRC, +delaying and swaps. For data sectors they also do scrambling and f2 +frame generation. + +Encoding routines: + +For data sectors + int do_encode_L2(unsigned char *inout, int sectortype, unsigned address); + + encodes data sectors. The returned data is __unscrambled__ and not in + F2-frame format. + +Parameters are: + inout pointer to an array of at least 2352 bytes. + sectortype One of the MODE_* constants from ecc.h. This defines + how to format the sector. + address The logical address to be used in the header + (150 = 0:2.0 MSF). + +NOTE: the data portion has be to aligned properly for performance +reasons (see ecc.h for details). So, no moves are necessary here. + +Generating f2 frames to be used like audio sectors + int scramble_L2(unsigned char *inout) + + generates f2 frames in place from sectors generated by do_encode_L2(). + +Parameters are: + inout pointer to an array of at least 2352 bytes. + + + +For sub channels + 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); + + repack user data and add error correction data. P and q subchannels +should be added later, since all bytes are in place then. + +Parameters are: + in pointer to an array of at least 72 bytes. It contains + the user data for one frame. + out pointer to an array of at least 96 bytes. Here is + output frame is placed. + delay1 do low level delaying, when set to 1. + permute do low level permutations, when set to 1. + +NOTE: Probably both options need either to be set on (1) or off (0) together. + +There is more, but that is seldomly used. + +Tests: +The library is accompanied by small verify programs, that compare real +raw sectors with the formatted results. They are also intended as demo +applications (how to use the library). In order to be able to feed +real raw sectors into them, the package read2448 is recommended/needed. +You can only verify sector streams of one sector type, currently no mix. + +For more information have a look into ecc.h + +recommended Documents: +Yellow Book or ISO 10149 +Appendix Red Book +Red Book or IEC 908 + +Source: libedc/README from cdrtools package +Edited for cdrkit by Christian Fromme + --- a/src/gdrom/cdi.c Tue Feb 26 01:10:48 2008 +0000 +++ b/src/gdrom/cdi.c Sun Mar 02 11:38:08 2008 +0000 @@ -171,11 +171,11 @@ image->track[total_tracks].flags = 0x41; switch( trk.sector_size ) { case 0: - image->track[total_tracks].mode = GDROM_MODE2_XA1; + image->track[total_tracks].mode = GDROM_MODE2_FORM1; image->track[total_tracks].sector_size = 2048; break; case 1: - image->track[total_tracks].mode = GDROM_MODE2; + image->track[total_tracks].mode = GDROM_SEMIRAW_MODE2; image->track[total_tracks].sector_size = 2336; break; case 2: --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/gdrom/ecc.h Sun Mar 02 11:38:08 2008 +0000 @@ -0,0 +1,136 @@ +/* + * This file has been modified for the cdrkit suite. + * + * The behaviour and appearence of the program code below can differ to a major + * extent from the version distributed by the original author(s). + * + * For details, see Changelog file distributed with the cdrkit package. If you + * received this file from another source then ask the distributing person for + * a log of modifications. + * + */ + +/* @(#)ecc.h 1.4 02/10/19 Copyright 1998-2002 Heiko Eissfeldt, Joerg Schilling */ + +/* + * compact disc reed-solomon routines + * + * (c) 1998-2002 by Heiko Eissfeldt, heiko@colossus.escape.de + * (c) 2002 by Joerg Schilling + */ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 + * as published by the Free Software Foundation. + * + * 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; see the file COPYING. If not, write to the Free Software + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#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 + +int cd_build_address(unsigned char inout[], int sectortype, unsigned address); + +/* 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 GDROM_MODE0 +#define MODE_1 GDROM_MODE1 +#define MODE_2 GDROM_MODE2_FORMLESS +#define MODE_2_FORM_1 GDROM_MODE2_FORM1 +#define MODE_2_FORM_2 GDROM_MODE2_FORM2 + +/* 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 int build_edc(unsigned char inout[], int from, int upto); + +/* generates f2 frames from otherwise fully formatted sectors (generated by + do_encode_L2()). */ +#define EDC_SCRAMBLE_NOSWAP 1 /* Do not swap bytes while scrambling */ +int scramble_L2(unsigned char *inout); + +/* 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 + +/* 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]); --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/gdrom/edc_crctable.h Sun Mar 02 11:38:08 2008 +0000 @@ -0,0 +1,171 @@ +/* @(#)crctable.out 1.2 02/10/17 joerg */ + +/*****************************************************************/ +/* */ +/* CRC LOOKUP TABLE */ +/* ================ */ +/* The following CRC lookup table was generated automagically */ +/* by the Rocksoft^tm Model CRC Algorithm Table Generation */ +/* Program V1.0 using the following model parameters: */ +/* */ +/* Width : 4 bytes. */ +/* Poly : 0x8001801BL */ +/* Reverse : TRUE. */ +/* */ +/* For more information on the Rocksoft^tm Model CRC Algorithm, */ +/* see the document titled "A Painless Guide to CRC Error */ +/* Detection Algorithms" by Ross Williams */ +/* (ross@guest.adelaide.edu.au.). This document is likely to be */ +/* in the FTP archive "ftp.adelaide.edu.au/pub/rocksoft". */ +/* */ +/*****************************************************************/ + +#ifdef PROTOTYPES + +static unsigned int EDC_crctable[256] = +{ + 0x00000000U, 0x90910101U, 0x91210201U, 0x01B00300U, + 0x92410401U, 0x02D00500U, 0x03600600U, 0x93F10701U, + 0x94810801U, 0x04100900U, 0x05A00A00U, 0x95310B01U, + 0x06C00C00U, 0x96510D01U, 0x97E10E01U, 0x07700F00U, + 0x99011001U, 0x09901100U, 0x08201200U, 0x98B11301U, + 0x0B401400U, 0x9BD11501U, 0x9A611601U, 0x0AF01700U, + 0x0D801800U, 0x9D111901U, 0x9CA11A01U, 0x0C301B00U, + 0x9FC11C01U, 0x0F501D00U, 0x0EE01E00U, 0x9E711F01U, + 0x82012001U, 0x12902100U, 0x13202200U, 0x83B12301U, + 0x10402400U, 0x80D12501U, 0x81612601U, 0x11F02700U, + 0x16802800U, 0x86112901U, 0x87A12A01U, 0x17302B00U, + 0x84C12C01U, 0x14502D00U, 0x15E02E00U, 0x85712F01U, + 0x1B003000U, 0x8B913101U, 0x8A213201U, 0x1AB03300U, + 0x89413401U, 0x19D03500U, 0x18603600U, 0x88F13701U, + 0x8F813801U, 0x1F103900U, 0x1EA03A00U, 0x8E313B01U, + 0x1DC03C00U, 0x8D513D01U, 0x8CE13E01U, 0x1C703F00U, + 0xB4014001U, 0x24904100U, 0x25204200U, 0xB5B14301U, + 0x26404400U, 0xB6D14501U, 0xB7614601U, 0x27F04700U, + 0x20804800U, 0xB0114901U, 0xB1A14A01U, 0x21304B00U, + 0xB2C14C01U, 0x22504D00U, 0x23E04E00U, 0xB3714F01U, + 0x2D005000U, 0xBD915101U, 0xBC215201U, 0x2CB05300U, + 0xBF415401U, 0x2FD05500U, 0x2E605600U, 0xBEF15701U, + 0xB9815801U, 0x29105900U, 0x28A05A00U, 0xB8315B01U, + 0x2BC05C00U, 0xBB515D01U, 0xBAE15E01U, 0x2A705F00U, + 0x36006000U, 0xA6916101U, 0xA7216201U, 0x37B06300U, + 0xA4416401U, 0x34D06500U, 0x35606600U, 0xA5F16701U, + 0xA2816801U, 0x32106900U, 0x33A06A00U, 0xA3316B01U, + 0x30C06C00U, 0xA0516D01U, 0xA1E16E01U, 0x31706F00U, + 0xAF017001U, 0x3F907100U, 0x3E207200U, 0xAEB17301U, + 0x3D407400U, 0xADD17501U, 0xAC617601U, 0x3CF07700U, + 0x3B807800U, 0xAB117901U, 0xAAA17A01U, 0x3A307B00U, + 0xA9C17C01U, 0x39507D00U, 0x38E07E00U, 0xA8717F01U, + 0xD8018001U, 0x48908100U, 0x49208200U, 0xD9B18301U, + 0x4A408400U, 0xDAD18501U, 0xDB618601U, 0x4BF08700U, + 0x4C808800U, 0xDC118901U, 0xDDA18A01U, 0x4D308B00U, + 0xDEC18C01U, 0x4E508D00U, 0x4FE08E00U, 0xDF718F01U, + 0x41009000U, 0xD1919101U, 0xD0219201U, 0x40B09300U, + 0xD3419401U, 0x43D09500U, 0x42609600U, 0xD2F19701U, + 0xD5819801U, 0x45109900U, 0x44A09A00U, 0xD4319B01U, + 0x47C09C00U, 0xD7519D01U, 0xD6E19E01U, 0x46709F00U, + 0x5A00A000U, 0xCA91A101U, 0xCB21A201U, 0x5BB0A300U, + 0xC841A401U, 0x58D0A500U, 0x5960A600U, 0xC9F1A701U, + 0xCE81A801U, 0x5E10A900U, 0x5FA0AA00U, 0xCF31AB01U, + 0x5CC0AC00U, 0xCC51AD01U, 0xCDE1AE01U, 0x5D70AF00U, + 0xC301B001U, 0x5390B100U, 0x5220B200U, 0xC2B1B301U, + 0x5140B400U, 0xC1D1B501U, 0xC061B601U, 0x50F0B700U, + 0x5780B800U, 0xC711B901U, 0xC6A1BA01U, 0x5630BB00U, + 0xC5C1BC01U, 0x5550BD00U, 0x54E0BE00U, 0xC471BF01U, + 0x6C00C000U, 0xFC91C101U, 0xFD21C201U, 0x6DB0C300U, + 0xFE41C401U, 0x6ED0C500U, 0x6F60C600U, 0xFFF1C701U, + 0xF881C801U, 0x6810C900U, 0x69A0CA00U, 0xF931CB01U, + 0x6AC0CC00U, 0xFA51CD01U, 0xFBE1CE01U, 0x6B70CF00U, + 0xF501D001U, 0x6590D100U, 0x6420D200U, 0xF4B1D301U, + 0x6740D400U, 0xF7D1D501U, 0xF661D601U, 0x66F0D700U, + 0x6180D800U, 0xF111D901U, 0xF0A1DA01U, 0x6030DB00U, + 0xF3C1DC01U, 0x6350DD00U, 0x62E0DE00U, 0xF271DF01U, + 0xEE01E001U, 0x7E90E100U, 0x7F20E200U, 0xEFB1E301U, + 0x7C40E400U, 0xECD1E501U, 0xED61E601U, 0x7DF0E700U, + 0x7A80E800U, 0xEA11E901U, 0xEBA1EA01U, 0x7B30EB00U, + 0xE8C1EC01U, 0x7850ED00U, 0x79E0EE00U, 0xE971EF01U, + 0x7700F000U, 0xE791F101U, 0xE621F201U, 0x76B0F300U, + 0xE541F401U, 0x75D0F500U, 0x7460F600U, 0xE4F1F701U, + 0xE381F801U, 0x7310F900U, 0x72A0FA00U, 0xE231FB01U, + 0x71C0FC00U, 0xE151FD01U, 0xE0E1FE01U, 0x7070FF00U, +}; + +/*****************************************************************/ +/* End of CRC Lookup Table */ +/*****************************************************************/ + +#else /* PROTOTYPES */ + +static unsigned int EDC_crctable[256] = +{ + 0x00000000, 0x90910101, 0x91210201, 0x01B00300, + 0x92410401, 0x02D00500, 0x03600600, 0x93F10701, + 0x94810801, 0x04100900, 0x05A00A00, 0x95310B01, + 0x06C00C00, 0x96510D01, 0x97E10E01, 0x07700F00, + 0x99011001, 0x09901100, 0x08201200, 0x98B11301, + 0x0B401400, 0x9BD11501, 0x9A611601, 0x0AF01700, + 0x0D801800, 0x9D111901, 0x9CA11A01, 0x0C301B00, + 0x9FC11C01, 0x0F501D00, 0x0EE01E00, 0x9E711F01, + 0x82012001, 0x12902100, 0x13202200, 0x83B12301, + 0x10402400, 0x80D12501, 0x81612601, 0x11F02700, + 0x16802800, 0x86112901, 0x87A12A01, 0x17302B00, + 0x84C12C01, 0x14502D00, 0x15E02E00, 0x85712F01, + 0x1B003000, 0x8B913101, 0x8A213201, 0x1AB03300, + 0x89413401, 0x19D03500, 0x18603600, 0x88F13701, + 0x8F813801, 0x1F103900, 0x1EA03A00, 0x8E313B01, + 0x1DC03C00, 0x8D513D01, 0x8CE13E01, 0x1C703F00, + 0xB4014001, 0x24904100, 0x25204200, 0xB5B14301, + 0x26404400, 0xB6D14501, 0xB7614601, 0x27F04700, + 0x20804800, 0xB0114901, 0xB1A14A01, 0x21304B00, + 0xB2C14C01, 0x22504D00, 0x23E04E00, 0xB3714F01, + 0x2D005000, 0xBD915101, 0xBC215201, 0x2CB05300, + 0xBF415401, 0x2FD05500, 0x2E605600, 0xBEF15701, + 0xB9815801, 0x29105900, 0x28A05A00, 0xB8315B01, + 0x2BC05C00, 0xBB515D01, 0xBAE15E01, 0x2A705F00, + 0x36006000, 0xA6916101, 0xA7216201, 0x37B06300, + 0xA4416401, 0x34D06500, 0x35606600, 0xA5F16701, + 0xA2816801, 0x32106900, 0x33A06A00, 0xA3316B01, + 0x30C06C00, 0xA0516D01, 0xA1E16E01, 0x31706F00, + 0xAF017001, 0x3F907100, 0x3E207200, 0xAEB17301, + 0x3D407400, 0xADD17501, 0xAC617601, 0x3CF07700, + 0x3B807800, 0xAB117901, 0xAAA17A01, 0x3A307B00, + 0xA9C17C01, 0x39507D00, 0x38E07E00, 0xA8717F01, + 0xD8018001, 0x48908100, 0x49208200, 0xD9B18301, + 0x4A408400, 0xDAD18501, 0xDB618601, 0x4BF08700, + 0x4C808800, 0xDC118901, 0xDDA18A01, 0x4D308B00, + 0xDEC18C01, 0x4E508D00, 0x4FE08E00, 0xDF718F01, + 0x41009000, 0xD1919101, 0xD0219201, 0x40B09300, + 0xD3419401, 0x43D09500, 0x42609600, 0xD2F19701, + 0xD5819801, 0x45109900, 0x44A09A00, 0xD4319B01, + 0x47C09C00, 0xD7519D01, 0xD6E19E01, 0x46709F00, + 0x5A00A000, 0xCA91A101, 0xCB21A201, 0x5BB0A300, + 0xC841A401, 0x58D0A500, 0x5960A600, 0xC9F1A701, + 0xCE81A801, 0x5E10A900, 0x5FA0AA00, 0xCF31AB01, + 0x5CC0AC00, 0xCC51AD01, 0xCDE1AE01, 0x5D70AF00, + 0xC301B001, 0x5390B100, 0x5220B200, 0xC2B1B301, + 0x5140B400, 0xC1D1B501, 0xC061B601, 0x50F0B700, + 0x5780B800, 0xC711B901, 0xC6A1BA01, 0x5630BB00, + 0xC5C1BC01, 0x5550BD00, 0x54E0BE00, 0xC471BF01, + 0x6C00C000, 0xFC91C101, 0xFD21C201, 0x6DB0C300, + 0xFE41C401, 0x6ED0C500, 0x6F60C600, 0xFFF1C701, + 0xF881C801, 0x6810C900, 0x69A0CA00, 0xF931CB01, + 0x6AC0CC00, 0xFA51CD01, 0xFBE1CE01, 0x6B70CF00, + 0xF501D001, 0x6590D100, 0x6420D200, 0xF4B1D301, + 0x6740D400, 0xF7D1D501, 0xF661D601, 0x66F0D700, + 0x6180D800, 0xF111D901, 0xF0A1DA01, 0x6030DB00, + 0xF3C1DC01, 0x6350DD00, 0x62E0DE00, 0xF271DF01, + 0xEE01E001, 0x7E90E100, 0x7F20E200, 0xEFB1E301, + 0x7C40E400, 0xECD1E501, 0xED61E601, 0x7DF0E700, + 0x7A80E800, 0xEA11E901, 0xEBA1EA01, 0x7B30EB00, + 0xE8C1EC01, 0x7850ED00, 0x79E0EE00, 0xE971EF01, + 0x7700F000, 0xE791F101, 0xE621F201, 0x76B0F300, + 0xE541F401, 0x75D0F500, 0x7460F600, 0xE4F1F701, + 0xE381F801, 0x7310F900, 0x72A0FA00, 0xE231FB01, + 0x71C0FC00, 0xE151FD01, 0xE0E1FE01, 0x7070FF00, +}; + +#endif /* PROTOTYPES */ + +/*****************************************************************/ +/* End of CRC Lookup Table */ +/*****************************************************************/ --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/gdrom/edc_ecc.c Sun Mar 02 11:38:08 2008 +0000 @@ -0,0 +1,979 @@ +/* + * Note: This file has been extracted from crkit 1.1.6 and modified to work within + * lxdream, but is otherwise unchanged. + */ +/* + * This file has been modified for the cdrkit suite. + * + * The behaviour and appearence of the program code below can differ to a major + * extent from the version distributed by the original author(s). + * + * For details, see Changelog file distributed with the cdrkit package. If you + * received this file from another source then ask the distributing person for + * a log of modifications. + * + */ + +/* @(#)edc_ecc.c 1.21 03/04/04 Copyright 1998-2002 Heiko Eissfeldt, Joerg Schilling */ + +/* + * Copyright 1998-2002 by Heiko Eissfeldt + * Copyright 2002 by Joerg Schilling + * + * This file contains protected intellectual property. + * + * reed-solomon encoder / decoder for compact discs. + * + */ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 + * as published by the Free Software Foundation. + * + * 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; see the file COPYING. If not, write to the Free Software + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include +#include +#include +#include "gdrom.h" +#include "ecc.h" + +#define xaligned(a, s) ((((uintptr_t)(a)) & (s)) == 0 ) + +/* these prototypes will become public when the function are implemented */ +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); + + +/* ------------- tables generated by gen_encodes --------------*/ + +#include "edc_scramble.h" + +#define DO4(a) a;a;a;a; +#define DO13(a) a;a;a;a;a;a;a;a;a;a;a;a;a; + +/* + * Scrambles 2352 - 12 = 2340 bytes + */ +int scramble_L2(unsigned char *inout); + +int scramble_L2(unsigned char *inout) +{ +#ifndef EDC_SCRAMBLE_NOSWAP + unsigned int *f = (unsigned int *)inout; +#endif + + if (!xaligned(inout + 12, sizeof(uint32_t)-1)) { + + uint8_t *r = inout + 12; + const uint8_t *s = yellowbook_scrambler; + register int i; + + for (i = (L2_RAW + L2_Q + L2_P +16)/sizeof(unsigned char)/4; --i >= 0;) { + DO4(*r++ ^= *s++); + } + + } else { + uint32_t *r = (uint32_t *) (inout + 12); + const uint32_t *s = yellowbook_scrambler_uint32; + register int i; + + for (i = (L2_RAW + L2_Q + L2_P +16)/sizeof(uint32_t)/13; --i >= 0;) { + DO13(*r++ ^= *s++); + } + } + +#ifndef EDC_SCRAMBLE_NOSWAP + + /* generate F1 frames */ + for (i = 2352/sizeof(unsigned int); i; i--) { + *f++ = ((*f & 0xff00ff00UL) >> 8) | ((*f & 0x00ff00ffUL) << 8); + } +#endif + + return (0); +} + +#include "edc_l2sq.h" + +static int encode_L2_Q(unsigned char inout[4 + L2_RAW + 4 + 8 + L2_P + L2_Q]); + +static int encode_L2_Q(unsigned char inout[4 + L2_RAW + 4 + 8 + L2_P + L2_Q]) +{ + unsigned char *dps; + unsigned char *dp; + unsigned char *Q; + register int i; + int j; + + Q = inout + 4 + L2_RAW + 4 + 8 + L2_P; + + dps = inout; + for (j = 0; j < 26; j++) { + register unsigned short a; + register unsigned short b; + a = b = 0; + + dp = dps; + for (i = 0; i < 43; i++) { + + /* LSB */ + a ^= L2sq[i][*dp++]; + + /* MSB */ + b ^= L2sq[i][*dp]; + + dp += 2*44-1; + if (dp >= &inout[(4 + L2_RAW + 4 + 8 + L2_P)]) { + dp -= (4 + L2_RAW + 4 + 8 + L2_P); + } + } + Q[0] = a >> 8; + Q[26*2] = a; + Q[1] = b >> 8; + Q[26*2+1] = b; + + Q += 2; + dps += 2*43; + } + return (0); +} + +static int encode_L2_P(unsigned char inout[4 + L2_RAW + 4 + 8 + L2_P]); + +static int encode_L2_P(unsigned char inout[4 + L2_RAW + 4 + 8 + L2_P]) +{ + unsigned char *dp; + unsigned char *P; + register int i; + int j; + + P = inout + 4 + L2_RAW + 4 + 8; + + for (j = 0; j < 43; j++) { + register unsigned short a; + register unsigned short b; + + a = b = 0; + dp = inout; + for (i = 19; i < 43; i++) { + + /* LSB */ + a ^= L2sq[i][*dp++]; + + /* MSB */ + b ^= L2sq[i][*dp]; + + dp += 2*43 -1; + } + P[0] = a >> 8; + P[43*2] = a; + P[1] = b >> 8; + P[43*2+1] = b; + + P += 2; + inout += 2; + } + return (0); +} + +static unsigned char bin2bcd(unsigned p); + +static unsigned char bin2bcd(unsigned p) +{ + return ((p/10)<<4)|(p%10); +} + +int cd_build_address(unsigned char inout[], int sectortype, unsigned address) +{ + inout[12] = bin2bcd(address / (60*75)); + inout[13] = bin2bcd((address / 75) % 60); + inout[14] = bin2bcd(address % 75); + if (sectortype == MODE_0) + inout[15] = 0; + else if (sectortype == MODE_1) + inout[15] = 1; + else if (sectortype == MODE_2) + inout[15] = 2; + else if (sectortype == MODE_2_FORM_1) + inout[15] = 2; + else if (sectortype == MODE_2_FORM_2) + inout[15] = 2; + else + return (-1); + return (0); +} + +#include "edc_crctable.h" + +/* + * Called with 2064, 2056 or 2332 byte difference - all dividable by 4. + */ +unsigned int build_edc(unsigned char inout[], int from, int upto); + +unsigned int build_edc(unsigned char inout[], int from, int upto) +{ + unsigned char *p = inout+from; + unsigned int result = 0; + + upto -= from-1; + upto /= 4; + while (--upto >= 0) { + result = EDC_crctable[(result ^ *p++) & 0xffL] ^ (result >> 8); + result = EDC_crctable[(result ^ *p++) & 0xffL] ^ (result >> 8); + result = EDC_crctable[(result ^ *p++) & 0xffL] ^ (result >> 8); + result = EDC_crctable[(result ^ *p++) & 0xffL] ^ (result >> 8); + } + return (result); +} + +/* 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 +do_encode_L2(unsigned char inout[(12 + 4 + L2_RAW+4+8+L2_Q+L2_P)], + int sectortype, unsigned address) +{ + unsigned int result; + +/* SYNCPATTERN "\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff" */ +#define SYNCPATTERN "\000\377\377\377\377\377\377\377\377\377\377" + + /* supply initial sync pattern */ + memcpy(inout, SYNCPATTERN, sizeof(SYNCPATTERN)); + + if (sectortype == MODE_0) { + memset(inout + sizeof(SYNCPATTERN), 0, 4 + L2_RAW + 12 + L2_P + L2_Q); + cd_build_address(inout, sectortype, address); + return (0); + } + + switch (sectortype) { + + case MODE_1: + cd_build_address(inout, sectortype, address); + result = build_edc(inout, 0, 16+2048-1); + inout[2064+0] = result >> 0L; + inout[2064+1] = result >> 8L; + inout[2064+2] = result >> 16L; + inout[2064+3] = result >> 24L; + memset(inout+2064+4, 0, 8); + encode_L2_P(inout+12); + encode_L2_Q(inout+12); + break; + case MODE_2: + cd_build_address(inout, sectortype, address); + break; + case MODE_2_FORM_1: + result = build_edc(inout, 16, 16+8+2048-1); + inout[2072+0] = result >> 0L; + inout[2072+1] = result >> 8L; + inout[2072+2] = result >> 16L; + inout[2072+3] = result >> 24L; + + /* clear header for P/Q parity calculation */ + inout[12] = 0; + inout[12+1] = 0; + inout[12+2] = 0; + inout[12+3] = 0; + encode_L2_P(inout+12); + encode_L2_Q(inout+12); + cd_build_address(inout, sectortype, address); + break; + case MODE_2_FORM_2: + cd_build_address(inout, sectortype, address); + result = build_edc(inout, 16, 16+8+2324-1); + inout[2348+0] = result >> 0L; + inout[2348+1] = result >> 8L; + inout[2348+2] = result >> 16L; + inout[2348+3] = result >> 24L; + break; + default: + return (-1); + } + + return (0); +} + + +/*--------------------------------------------------------------------------*/ +#include "edc_encoder.h" + +static int encode_L1_Q(unsigned char inout[L1_RAW + L1_Q]); + +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]) % (unsigned)((1 << RS_L12_BITS)-1)]; + Q[1] ^= rs_l12_alog[(base+AQ[1][i]) % (unsigned)((1 << RS_L12_BITS)-1)]; + Q[2] ^= rs_l12_alog[(base+AQ[2][i]) % (unsigned)((1 << RS_L12_BITS)-1)]; + Q[3] ^= rs_l12_alog[(base+AQ[3][i]) % (unsigned)((1 << RS_L12_BITS)-1)]; + } + } + return (0); +} + +static int encode_L1_P(unsigned char inout[L1_RAW + L1_Q + L1_P]); + +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]) % (unsigned)((1 << RS_L12_BITS)-1)]; + P[1] ^= rs_l12_alog[(base+AP[1][i]) % (unsigned)((1 << RS_L12_BITS)-1)]; + P[2] ^= rs_l12_alog[(base+AP[2][i]) % (unsigned)((1 << RS_L12_BITS)-1)]; + P[3] ^= rs_l12_alog[(base+AP[3][i]) % (unsigned)((1 << RS_L12_BITS)-1)]; + } + } + return (0); +} + +static int decode_L1_Q(unsigned char inout[L1_RAW + L1_Q]); + +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]); + +static int decode_L1_P(unsigned char in[L1_RAW + L1_Q + L1_P]) +{ + return (0); +} + +int decode_L2_Q(unsigned char inout[4 + L2_RAW + 12 + L2_Q]); + +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]); + +int decode_L2_P(unsigned char inout[4 + L2_RAW + 12 + L2_Q + L2_P]) +{ + return (0); +} + +static int encode_LSUB_Q(unsigned char inout[LSUB_RAW + LSUB_Q]); + +static int encode_LSUB_Q(unsigned char inout[LSUB_RAW + LSUB_Q]) +{ + unsigned char *Q; + int i; + + memmove(inout+LSUB_QRAW+LSUB_Q, inout+LSUB_QRAW, LSUB_RAW-LSUB_QRAW); + Q = inout + LSUB_QRAW; + + memset(Q, 0, LSUB_Q); + + 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]) % (unsigned)((1 << RS_SUB_RW_BITS)-1)]; + Q[1] ^= rs_sub_rw_alog[(base+SQ[1][i]) % (unsigned)((1 << RS_SUB_RW_BITS)-1)]; + } + } + return (0); +} + + +static int encode_LSUB_P(unsigned char inout[LSUB_RAW + LSUB_Q + LSUB_P]); + +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]) % (unsigned)((1 << RS_SUB_RW_BITS)-1)]; + P[1] ^= rs_sub_rw_alog[(base+SP[1][i]) % (unsigned)((1 << RS_SUB_RW_BITS)-1)]; + P[2] ^= rs_sub_rw_alog[(base+SP[2][i]) % (unsigned)((1 << RS_SUB_RW_BITS)-1)]; + P[3] ^= rs_sub_rw_alog[(base+SP[3][i]) % (unsigned)((1 << RS_SUB_RW_BITS)-1)]; + } + } + return (0); +} + +int decode_LSUB_Q(unsigned char inout[LSUB_QRAW + LSUB_Q]); + +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) % (unsigned)((1 << RS_SUB_RW_BITS)-1)]; + Q[1] ^= rs_sub_rw_alog[(base+1*i) % (unsigned)((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]); + +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) % (unsigned)((1 << RS_SUB_RW_BITS)-1)]; + P[1] ^= rs_sub_rw_alog[(base+1*i) % (unsigned)((1 << RS_SUB_RW_BITS)-1)]; + P[2] ^= rs_sub_rw_alog[(base+2*i) % (unsigned)((1 << RS_SUB_RW_BITS)-1)]; + P[3] ^= rs_sub_rw_alog[(base+3*i) % (unsigned)((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 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); +} + +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 permute); + +static /* XXX should be non static XXX*/ + +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); +} + +static int do_decode_L2(unsigned char in[(L2_RAW+L2_Q+L2_P)], + unsigned char out[L2_RAW]); + +static int do_decode_L2(unsigned char in[(L2_RAW+L2_Q+L2_P)], + unsigned char out[L2_RAW]) +{ + return (0); +} + + + +#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 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 +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 get_sector_type() +{ + return (sectortype); +} + +int set_sector_type(int st); + +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; + return 0; + default: + return -1; + } +} + +/* ------------- --------------*/ +#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_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); +} +#endif --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/gdrom/edc_encoder.h Sun Mar 02 11:38:08 2008 +0000 @@ -0,0 +1,47 @@ +/* @(#)encoder_tables 1.4 02/10/19 */ + +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 + * as published by the Free Software Foundation. + * + * 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; see the file COPYING. If not, write to the Free Software + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +static const 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 const 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 const 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 const 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 const unsigned char SQ[2][2] = { +{26,6,}, +{7,1,}, +}; +static const 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 const 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 const 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,}, +}; --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/gdrom/edc_l2sq.h Sun Mar 02 11:38:08 2008 +0000 @@ -0,0 +1,1180 @@ +/* @(#)l2sq_table 1.2 02/10/19 Copyright 2002 J. Schilling */ + +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 + * as published by the Free Software Foundation. + * + * 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; see the file COPYING. If not, write to the Free Software + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +static const unsigned short L2sq[43][256] = { +{0,44719,16707,61420,33414,11305,50117,28010,6417,47038, + 22610,63229,39831,13624,56020,29819,12834,40077,29537,56782, + 45220,7691,61927,24392,11059,34204,27248,50399,43445,1818, + 59638,18009,25668,51947,9479,35752,59074,18541,42881,2350, + 32085,54266,15382,37561,65491,20860,48784,4159,22118,63689, + 5925,47498,54496,31311,38307,15116,20343,57816,3636,41115, + 52721,25438,36018,8733,51336,26151,35275,10084,18958,58529, + 2893,42466,53657,32566,37082,15989,21279,64944,4700,48371, + 64170,21509,48105,5446,30764,54915,14703,38848,58299,19732, + 41720,3159,24893,53138,8318,36561,44236,611,60815,17184, + 11850,32997,28425,49574,46557,7026,62622,23089,14171,39412, + 30232,55479,40686,12353,57261,28930,7272,45767,23851,62340, + 34815,10576,50876,26643,1401,43990,17466,60053,36109,9122, + 52302,25313,3979,41252,20168,57447,37916,15027,54623,31728, + 5786,47157,22489,63862,48943,4480,65132,20675,15785,37638, + 31978,53829,42558,2193,59261,18898,9400,35351,26107,52052, + 59721,18406,43018,1701,27599,50528,10892,33827,61528,24311, + 45339,8116,29406,56433,13213,40242,56171,30148,39464,13447, + 23021,63298,6318,46593,49786,27861,33593,11670,16636,61011, + 447,44816,17797,60202,1222,43625,50947,27052,34368,10479, + 23700,62011,7639,45944,56850,28861,40785,12798,30631,55560, + 14052,38987,62753,23438,46178,6861,28342,49177,12277,33114, + 60464,17055,44403,988,8641,36718,24706,52781,41799,3560, + 57860,19627,14544,38527,31123,55100,47702,5369,64277,21946, + 5091,48460,21152,64527,37221,16330,53286,32393,2802,42077, + 19377,58654,34932,9947,51511,26520, +}, +{0,55768,44973,30325,17223,39583,60650,13618,34446,24406, + 10531,61691,50633,7185,27236,46012,4353,51417,48812,26484, + 21062,35742,65003,9267,38799,20055,14370,57850,54472,3344, + 31589,41661,8706,64474,36271,21623,24901,47261,52968,5936, + 42124,32084,2849,54009,59339,15891,18534,37310,13059,60123, + 40110,17782,28740,43420,57321,1585,46477,27733,6688,50168, + 63178,12050,22887,32959,17412,40412,60329,12913,1859,56987, + 43246,28982,49802,6994,27943,46335,33229,22549,11872,63416, + 21765,36061,64168,9072,5698,53146,47599,24631,54155,2643, + 31782,42494,37068,18708,16225,59065,26118,49118,51627,4211, + 9537,64665,35564,21300,57480,14672,20261,38653,41935,31255, + 3170,54714,30471,44767,55466,370,13376,60824,39917,16949, + 61833,10321,24100,34812,45774,27414,7523,50363,34824,20944, + 10149,65149,52047,4759,25826,48442,3718,55134,41259,30963, + 19905,37913,57964,15284,39177,16593,13988,61308,55886,918, + 30179,44091,8071,50783,45098,27122,23744,34072,62317,10933, + 43530,29650,1447,56447,59725,12437,18144,40760,11396,62812, + 33577,23281,28611,46619,49262,6582,47883,25299,5286,52606, + 63564,8596,22497,36409,15749,58461,37416,19440,32450,42778, + 53615,2231,52236,5588,25505,47737,36683,22163,8422,63806, + 19074,37722,58671,15607,2501,53277,42600,32688,56589,1237, + 29344,43896,40522,18322,12775,59455,23427,33371,62510,11766, + 6340,49436,46953,28337,60942,14294,16803,39035,44361,29841, + 740,56124,26752,45400,50989,7925,11207,61983,33898,23986, + 65295,9943,20642,35194,48200,26000,5093,51773,31105,41049, + 54828,4084,15046,58142,38251,19635, +}, +{0,27757,55514,46263,44457,49604,30067,6430,18255,11042, + 40853,62456,60134,34443,12860,24145,36510,58099,22084,14889, + 9015,20314,64493,38784,51665,42428,4363,32102,25720,2069, + 48290,53455,289,27980,55803,46486,44168,49381,29778,6207, + 18030,10755,40628,62169,60359,34730,13085,24432,36799,58322, + 22373,15112,8726,20091,64204,38561,51440,42141,4138,31815, + 25945,2356,48515,53742,578,28207,55960,46837,45035,50054, + 30513,7004,17677,10592,40407,61882,59556,33993,12414,23571, + 36060,57521,21510,14443,8565,19736,63919,38338,52115,43006, + 4937,32548,26170,2647,48864,53901,867,28430,56249,47060, + 44746,49831,30224,6781,17452,10305,40182,61595,59781,34280, + 12639,23858,36349,57744,21799,14666,8276,19513,63630,38115, + 51890,42719,4712,32261,26395,2934,49089,54188,1156,26857, + 56414,45107,43309,50496,29175,7578,17355,12198,39697,63356, + 61026,33295,14008,23253,35354,58999,21184,16045,10163,19422, + 65385,37636,52565,41272,5519,31202,24828,3217,47142,54347, + 1445,27080,56703,45330,43020,50273,28886,7355,17130,11911, + 39472,63069,61251,33582,14233,23540,35643,59222,21473,16268, + 9874,19199,65096,37413,52340,40985,5294,30915,25053,3504, + 47367,54634,1734,27307,56860,45681,43887,50946,29621,8152, + 16777,11748,39251,62782,60448,32845,13562,22679,34904,58421, + 20610,15599,9713,18844,64811,37190,53015,41850,6093,31648, + 25278,3795,47716,54793,2023,27530,57149,45904,43598,50723, + 29332,7929,16552,11461,39026,62495,60673,33132,13787,22966, + 35193,58644,20899,15822,9424,18621,64522,36967,52790,41563, + 5868,31361,25503,4082,47941,55080, +}, +{0,47289,28015,54742,56030,25191,47025,3848,43425,4376, + 50382,31863,29567,52166,7696,42665,20319,63462,8752,39561, + 38273,11576,63726,16471,59134,24135,35729,13096,15392,33945, + 20815,59894,40638,9735,62417,19304,17504,64729,10511,37302, + 14111,36774,23152,58057,60865,21880,32942,14359,53729,26968, + 48270,1079,2879,45958,26192,57065,30784,49401,5423,44438, + 41630,6695,53233,30536,8545,39384,19470,62647,64447,17158, + 38608,11881,35008,12409,58799,23830,21022,60071,16241,34760, + 28222,54919,849,48104,46304,3161,55695,24886,51103,32550, + 43760,4681,7489,42488,28718,51351,49119,1894,53936,27145, + 25857,56760,2158,45271,5758,44743,31505,50088,52384,29721, + 41423,6518,61568,18489,40431,9558,10846,37607,18225,65416, + 22817,57752,13390,36087,33791,15174,61072,22057,17090,64123, + 12205,38676,38940,8357,62835,19914,60259,21466,34316,16053, + 12733,35076,23762,58475,3485,46372,24818,55371,55107,28666, + 47660,661,42044,7301,51539,29162,32482,50779,5005,43828, + 56444,25797,45331,2474,1698,48667,27597,54132,30173,52580, + 6322,40971,44803,6074,49772,31445,37667,11162,65100,18165, + 18941,61764,9362,39979,14978,33339,22509,61268,57436,22757, + 36147,13706,25507,56090,3788,46709,47485,452,54290,27819, + 51714,29371,42861,8148,4316,43109,32179,50442,11516,37957, + 16787,63786,63010,20123,39757,9204,34141,15844,59442,20619, + 24451,59194,13036,35413,64797,17828,36978,10443,10179,40826, + 19116,61973,21692,60421,14803,33130,36450,14043,58125,23476, + 45634,2811,57133,26516,26780,53285,1523,48458,7139,41818, + 30348,52789,49469,31108,44114,5355, +}, +{0,53971,47547,27496,28523,48568,54992,1027,57046,3077, + 26477,46526,45501,25454,2054,56021,41393,29538,6154,51929, + 52954,7177,30561,42418,32615,44468,50908,5135,4108,49887, + 43447,31588,24447,36268,59076,13335,12308,58055,35247,23420, + 33193,21370,14354,60097,61122,15377,22393,34218,65230,11293, + 18293,38310,37285,17270,10270,64205,8216,62155,39331,19312, + 20339,40352,63176,9243,48894,27693,1861,54678,53653,838, + 26670,47869,24616,45819,55699,2880,3907,56720,46840,25643, + 8015,52636,42740,29735,28708,41719,51615,6988,49561,4938, + 30754,43761,44786,31777,5961,50586,57729,13138,22586,35561, + 36586,23609,14161,58754,16215,60804,34540,21567,20540,33519, + 59783,15188,16432,37603,63883,11096,12123,64904,38624,17459, + 40678,19509,10077,62862,61837,9054,18486,39653,25057,45874, + 55386,2697,3722,56409,46897,26082,48951,28132,1676,54367, + 53340,655,27111,47924,49232,4739,31211,43832,44859,32232, + 5760,50259,7814,52309,42813,30190,29165,41790,51286,6789, + 16030,60493,34597,22006,20981,33574,59470,15005,57416,12955, + 23027,35616,36643,24048,13976,58443,40751,19964,9876,62535, + 61508,8855,18943,39724,16889,37674,63554,10897,11922,64577, + 38697,17914,57119,3532,26276,46199,45172,25255,2511,56092, + 457,54042,47218,27297,28322,48241,55065,1482,32430,44157, + 50965,5574,4549,49942,43134,31405,41080,29355,6595,51984, + 53011,7616,30376,42107,32864,21171,14811,60168,61195,15832, + 22192,33891,24246,35941,59149,13790,12765,58126,34918,23221, + 8657,62210,39018,19129,20154,40041,63233,9682,65287,11732, + 18108,37999,36972,17087,10711,64260, +}, +{0,59366,54225,13367,48063,23641,26734,36744,27491,35973, + 47282,24404,53468,14138,781,58603,54982,12576,1303,58097, + 28025,35487,48808,22862,48549,23107,28276,35218,1562,57852, + 54731,12845,45457,22135,25152,34214,2606,60872,55807,15897, + 56050,15636,2339,61125,24909,34475,45724,21882,26455,32945, + 46214,21344,56552,15118,3897,59615,3124,60370,57317,14339, + 46987,20589,25690,33724,32575,39129,44270,19208,50304,9062, + 5969,61623,5212,62394,51085,8299,45027,18437,31794,39892, + 43513,19999,31272,40398,4678,62880,49559,9841,49818,9596, + 4427,63149,31013,40643,43764,19730,52910,10568,7551,64153, + 29969,37623,42688,16678,42445,16939,30236,37370,7794,63892, + 52643,10821,6248,65422,52153,11359,41943,17457,28678,38880, + 29451,38125,41178,18236,51380,12114,7013,64643,65150,6552, + 11695,51785,17857,41511,38416,29174,38173,29435,18124,41258, + 11938,51524,64883,6805,10424,53086,64361,7311,37639,29921, + 16598,42800,17371,42045,36874,30700,63588,8066,11189,52307, + 20463,43017,39998,31704,62544,5046,10113,49255,9356,50026, + 63325,4283,40755,30933,19682,43780,39209,32463,19192,44318, + 8854,50544,61767,5793,62026,5548,8603,50813,18933,44563, + 39460,32194,33089,26279,21136,46454,15102,56600,59695,3785, + 59938,3524,14835,56853,20893,46715,33356,26026,22407,45153, + 33878,25520,60472,3038,16361,55311,15588,56066,61237,2259, + 34651,24765,21642,45932,12496,55094,58113,1255,35695,27785, + 22718,48984,23475,48213,34914,28548,57356,2026,13277,54331, + 58902,496,13767,53793,23977,47695,36472,27038,36213,27283, + 24228,47426,14026,53548,58651,765, +}, +{0,29554,59108,38294,53717,41639,14129,17475,49079,52421, + 22867,10785,28258,7440,34950,64500,25459,4097,34199,63205, + 45734,49620,21570,10032,56516,44982,14880,18770,3345,32355, + 60405,39047,50918,46484,8194,21360,5939,25665,61911,33445, + 31057,2595,40885,60615,43140,56310,20064,15634,42389,55015, + 17265,12291,29760,1842,37540,57814,6690,26960,64710,36788, + 52215,47237,11539,24161,37329,58019,30517,1095,16388,13174, + 42720,54674,11878,23828,51330,48112,65459,36033,6487,27173, + 62114,33232,5190,26420,9079,20485,50579,46817,19733,15975, + 44017,55427,40128,61362,31268,2390,22327,9285,45523,49825, + 34530,62864,24582,4980,59520,39922,3684,32022,14677,18983, + 57265,44227,13380,18230,53920,41426,58769,38627,885,28679, + 35827,63617,27927,7781,23078,10580,48322,53168,16319,19661, + 55643,43561,61034,40216,2190,31740,32776,62330,26348,5534, + 20957,8879,46905,50251,23756,12222,47656,51546,36121,65131, + 27645,6287,58235,36873,1439,30445,12974,16860,54346,42808, + 63833,35371,8125,27855,10380,23550,52840,48410,18158,13724, + 40970,54136,38715,58441,29151,685,39466,59736,31950,4028, + 19455,14477,44315,56937,9629,22255,50041,45067,62536,34618, + 4780,25054,44654,56604,18570,15352,32699,3273,39263,59949, + 4569,25259,63293,33871,49164,45950,9960,21914,52509,48751, + 11257,22667,7368,28602,64044,35166,29354,472,37966,59196, + 41855,53261,17819,14057,26760,7162,36460,64798,47453,51759, + 24505,11467,55103,42061,12763,17065,1770,30104,57358,37756, + 3067,30857,60703,40557,55854,43356,15562,20408,46156,51006, + 21160,8666,26009,5867,33661,61455, +}, +{0,14648,29296,19272,58592,56792,38544,44968,54749,60645, + 42925,40597,12605,2053,17229,31349,47015,36511,50647,64751, + 21319,27263,8503,6159,25210,23362,4106,10546,34458,49058, + 62698,52690,29523,19051,291,14363,38835,44683,58819,56571, + 42638,40886,54526,60870,17006,31574,12318,2342,50420,64972, + 46724,36796,8212,6444,21092,27484,4393,10257,25433,23137, + 62921,52465,34745,48769,59046,57246,38102,44526,582,15230, + 28726,18702,13179,2627,16651,30771,55195,61091,42475,40147, + 20737,26681,9073,6729,46561,36057,51089,65193,34012,48612, + 63148,53140,24636,22788,4684,11124,38389,44237,59269,57021, + 28949,18477,869,14941,16424,30992,12888,2912,42184,40432, + 54968,61312,8786,7018,20514,26906,50866,65418,46274,36346, + 63375,52919,34303,48327,4975,10839,24863,22567,53585,59497, + 41761,39449,13745,3209,18369,32505,1164,15796,30460,20420, + 57452,55636,37404,43812,26358,24526,5254,11710,33302,47918, + 61542,51550,45867,35347,49499,63587,22475,28403,9659,7299, + 41474,39738,53362,59722,18146,32730,13458,3498,30687,20199, + 1455,15511,37695,43527,57679,55415,5541,11421,26581,24301, + 61765,51325,33589,47629,49272,63808,45576,35632,9368,7584, + 22248,28624,14327,3791,17799,31935,54039,59951,41319,39007, + 57898,56082,36954,43362,1738,16370,29882,19842,32848,47464, + 61984,51992,25776,23944,5824,12280,21901,27829,10237,7877, + 45421,34901,49949,64037,17572,32156,14036,4076,41028,39292, + 53812,60172,37241,43073,58121,55857,30105,19617,2025,16081, + 62211,51771,33139,47179,6115,11995,26003,23723,9950,8166, + 21678,28054,49726,64262,45134,35190, +}, +{0,7197,14394,9255,28788,27753,18510,21587,57576,64757, + 55506,50383,37020,35969,43174,46267,56781,49616,58871,63978, + 44473,45476,38275,35230,15653,8504,1311,6402,19793,20812, + 30059,26998,42887,48026,40893,33696,55283,52206,61385,62420, + 18287,23410,32597,25416,14107,11014,3873,4924,31306,26199, + 17008,24173,2622,5667,12804,11801,39586,34495,41624,48773, + 60118,63179,53996,52977,21267,20238,27433,30516,9063,16250, + 7005,1856,46075,45030,35777,38876,50063,57234,64437,59304, + 36574,37571,46820,43769,65194,58039,50832,55949,28214,29227, + 22028,18961,7746,607,9848,14949,62612,59529,52398,53427, + 34016,39165,48346,41159,5244,2145,11334,12379,25608,30741, + 23602,16431,10585,13636,4451,3454,22829,17712,24855,32010, + 51633,54700,61835,60822,47557,42456,33279,40418,42534,47675, + 40476,33281,54866,51791,61032,62069,18126,23251,32500,25321, + 14010,10919,3712,4765,31723,26614,17361,24524,2975,6018, + 13221,12216,39683,34590,41785,48932,60279,63338,54093,53072, + 417,7612,14747,9606,29141,28104,18927,22002,57673,64852, + 55667,50542,37181,36128,43271,46362,56428,49265,58454,63563, + 44056,45061,37922,34879,15492,8345,1214,6307,19696,20717, + 29898,26839,62773,59688,52495,53522,34113,39260,48507,41318, + 5597,2496,11751,12794,26025,31156,23955,16782,10488,13541, + 4290,3295,22668,17553,24758,31915,51216,54285,61482,60471, + 47204,42105,32862,40003,21170,20143,27272,30357,8902,16091, + 6908,1761,45658,44615,35424,38525,49710,56883,64020,58889, + 36735,37730,46917,43864,65291,58134,50993,56108,28567,29578, + 22445,19376,8163,1022,10201,15300, +}, +{0,32897,7455,40350,14910,47807,10017,42912,29820,62717, + 26979,59874,20034,52931,21341,54236,59640,26745,62951,30054, + 53958,21063,53209,20312,40068,7173,33179,282,42682,9787, + 48037,15140,52717,19820,53490,20595,63443,30546,60108,27213, + 47505,14608,42126,9231,33711,814,40624,7729,9493,42388, + 14346,47243,7979,40874,564,33461,20841,53736,19574,52471, + 27479,60374,30280,63177,34759,1862,39640,6745,48633,15736, + 41190,8295,62395,29498,61092,28197,51589,18692,54426,21531, + 28479,61374,29216,62113,21761,54656,18462,51359,6979,39874, + 1628,34525,8573,41468,15458,48355,18986,51883,22325,55220, + 28692,61589,27915,60810,15958,48855,9033,41928,1128,34025, + 6519,39414,41682,8787,49101,16204,39148,6253,34291,1394, + 54958,22063,52145,19248,60560,27665,61839,28942,5011,37650, + 3724,36365,10669,43308,13490,46131,26607,59246,31472,64113, + 24017,56656,16590,49231,64363,31722,58996,26357,49493,16852, + 56394,23755,36631,3990,37384,4745,46377,13736,43062,10423, + 56958,24319,50017,17376,58432,25793,63839,31198,43522,10883, + 46877,14236,36924,4285,36131,3490,13958,46599,11161,43800, + 3256,35897,4519,37158,17146,49787,24549,57188,30916,63557, + 26075,58714,37972,5333,35147,2506,44650,12011,45941,13300, + 57384,24745,64823,32182,55830,23191,50953,18312,31916,64557, + 25011,57650,18066,50707,23437,56076,2256,34897,5583,38222, + 13038,45679,12273,44912,22969,55608,17574,50215,25479,58118, + 32408,65049,11717,44356,12506,45147,6139,38778,2788,35429, + 45377,12736,44126,11487,35711,3070,38496,5857,50493,17852, + 55330,22691,65283,32642,57884,25245, +}, +{0,52943,33155,20300,7963,53716,40600,20567,15926,61689, + 49077,29050,8493,61410,41134,28257,31852,45731,65007,13088, + 25463,44472,58100,11323,16986,35989,50137,3350,23873,37774, + 56514,4621,63704,13847,31067,46996,59331,10508,26176,43151, + 50926,2081,18285,35234,55797,5946,22646,38585,33972,19067, + 1335,52216,39855,21856,6700,54499,47746,29773,15105,62926, + 42393,27478,9242,60117,60845,9058,27694,41697,62134,15481, + 29493,48634,54171,7508,21016,40151,52352,591,19715,33740, + 37313,24334,4162,56973,36570,16405,3929,49558,45047,24888, + 11892,57531,45292,32291,12655,65440,5493,56250,38134,23097, + 2670,50337,35821,17698,11075,58764,43712,25615,13400,64151, + 46555,31508,26905,42966,59546,9813,30210,47309,63361,14670, + 22319,39392,54956,6243,18484,34555,51639,1912,51015,2440, + 18116,34827,55388,5779,23007,38672,63857,14270,30962,46653, + 58986,10405,26601,43302,47915,30180,15016,62567,42032,27391, + 9651,60284,34077,19410,1182,51793,39430,21705,7045,54602, + 16287,61776,48668,28883,8324,61003,41223,28616,425,53094, + 32810,20197,7858,53373,40753,20990,17395,36156,49776,3263, + 23784,37415,56683,5028,32197,45834,64582,12937,25310,44049, + 58205,11666,10986,58405,43881,26022,13809,64318,46194,31421, + 5340,55827,38239,23440,3015,50440,35396,17547,22150,38985, + 55045,6602,18845,34642,51230,1745,26800,42623,59699,10236, + 30635,47460,63016,14567,53810,7421,21425,40318,52521,998, + 19626,33381,60420,8907,28039,41800,62239,15824,29340,48211, + 44638,24721,12253,57618,45381,32650,12486,65033,36968,24231, + 4587,57124,36723,16828,3824,49215, +}, +{0,59880,53197,9765,33671,27247,19530,42402,6931,62203, + 54494,15670,39060,29052,22361,48817,13862,57294,63979,4099, + 46497,23625,31340,37764,11573,50397,58104,2832,44722,18266, + 24959,34967,27724,34212,41857,19049,61387,1571,8198,51694, + 30559,40631,47250,20858,62680,7472,15125,54013,23146,45954, + 38311,31823,55789,12293,5664,65480,16761,43153,36532,26460, + 49918,11030,3379,58587,55448,12656,5973,65213,23327,45815, + 38098,32058,50059,10851,3142,58798,16396,43492,36801,26153, + 61118,1878,8563,51355,27961,34001,41716,19228,62893,7237, + 14944,54152,30250,40898,47591,20495,46292,23868,31513,37617, + 14163,57019,63646,4470,44999,17967,24586,35298,11328,50600, + 58253,2661,33522,27418,19775,42199,373,59549,52920,10064, + 39393,28681,22060,49092,6758,62350,54699,15427,44333,17605, + 25312,35592,11946,51010,57703,2191,46654,24534,31219,36891, + 13753,56401,64116,5020,39691,29411,21702,48430,6284,61796, + 55105,16041,32792,27120,20437,42557,927,60023,52306,9658, + 49505,10377,3756,59204,17126,43790,36139,25795,55922,13210, + 5567,64599,23029,45085,38456,32720,63303,7855,14474,53602, + 29888,40232,47885,21221,60500,1468,9113,51825,28627,34363, + 40990,18934,30133,40029,47736,21392,63026,8154,14847,53271, + 28326,34638,41323,18563,60705,1225,8940,51972,17299,43643, + 35934,26038,49172,10748,4057,58929,22656,45416,38733,32421, + 56071,13039,5322,64802,6649,61457,54836,16348,39550,29590, + 21939,48219,746,60162,52519,9423,33133,26757,20128,42824, + 12255,50743,57362,2554,44120,17840,25493,35453,13516,56612, + 64257,4841,46923,24227,30854,37230, +}, +{0,29813,59626,40095,52681,47548,9507,20822,34703,62458, + 28517,6928,19014,15923,41644,55001,4867,26486,64489,36764, + 57034,43711,13856,16981,38028,57593,31846,2067,22853,11568, + 45487,50650,9734,21107,52972,47769,60367,40890,805,30544, + 41353,54780,18787,15638,27712,6197,33962,61663,13573,16752, + 56815,43418,63692,36025,4134,25683,45706,50943,23136,11797, + 32579,2870,38825,58332,19468,14457,42214,53395,33221,62896, + 26927,7514,52099,49142,9065,22300,1610,29247,61088,39637, + 24335,11130,47077,50064,37574,59059,31276,3673,55424,44277, + 12394,17439,5449,24892,64931,35286,27146,7807,33504,63125, + 42947,54198,20265,15196,60805,39408,1391,28954,8268,21561, + 51366,48339,30985,3452,37347,58774,46272,49333,23594,10335, + 65158,35571,5740,25113,13135,18234,56229,45008,38936,60525, + 28914,1159,21969,8612,48443,51534,8087,27618,63357,33544, + 53854,42539,15028,20161,35611,65390,25585,6020,18130,12967, + 44600,55885,3220,30945,58494,36875,49501,46376,10679,24002, + 48670,51819,22260,8833,29655,1954,39741,61256,14737,19940, + 53627,42254,62552,32813,7346,26823,44317,55656,17911,12674, + 24788,5281,34878,64587,10898,24295,49784,46605,59227,37678, + 4017,31684,54292,41057,15614,18571,6621,28072,61751,34114, + 21403,10222,47985,52996,40530,59943,30392,717,50967,45922, + 12285,23432,2782,32427,57908,38465,16536,13549,43122,56327, + 36177,63780,26043,4558,61970,34407,6904,28301,16347,19374, + 55089,41796,30109,488,40311,59650,47188,52257,20670,9419, + 57617,38244,2555,32142,11480,22701,50226,45127,26270,4843, + 36468,64001,43863,57122,17341,14280, +}, +{0,46261,30071,49602,60142,24155,40857,11052,51649,32116, + 48310,2051,9007,38810,22104,58093,36767,15146,64232,20061, + 25969,53700,4102,42163,18014,62187,13097,34716,44208,6149, + 55751,28018,803,46998,30292,49889,59853,23928,40122,10255, + 51938,32343,49045,2848,8204,38073,21883,57806,36028,14345, + 63947,19838,26194,53991,4901,42896,17789,61896,12298,33983, + 44947,6950,56036,28241,1606,45811,29489,51076,60584,22557, + 39391,11626,53127,31538,47856,3653,9577,37340,20510,58539, + 35289,15724,64686,18459,25399,55170,5696,41717,16408,62637, + 13679,33242,43766,7747,57217,27444,1381,45520,28690,50343, + 61323,23358,39676,11849,52388,30737,47571,3430,9802,37631, + 21309,59272,35578,15951,65421,19256,24596,54433,5475,41430, + 17211,63374,13900,33529,43477,7520,56482,26647,3212,47161, + 31227,52558,58978,21207,37653,10144,50509,29176,45114,1167, + 12195,39702,23252,61025,33555,14246,63076,17105,27133,56648, + 7306,43071,19154,65127,16293,35600,41020,5257,54603,25086, + 4015,47898,31448,52845,58689,20980,36918,9347,50798,29403, + 45849,1964,11392,38965,23031,60738,32816,13445,62791,16882, + 27358,56939,8105,43804,18929,64836,15494,34867,41759,6058, + 54888,25309,2762,48767,32701,51976,57380,21649,38227,8678, + 49931,30654,46716,713,10725,40272,23698,59431,34133,12768, + 61474,17559,28603,56078,6860,44665,19604,63521,14819,36182, + 42618,4815,54029,26552,2537,48476,31902,51243,58119,22450, + 38512,8901,49192,29853,46431,490,10950,40563,24497,60164, + 34422,12995,62209,18356,27800,55341,6639,44378,20407,64258, + 15040,36469,42329,4588,53294,25755, +}, +{0,54485,46519,24930,30579,41894,49860,5649,61158,14899, + 23377,36740,39317,19776,11298,63735,49617,5380,29798,41139, + 46754,25207,789,55232,12087,64482,39552,20053,22596,35985, + 60915,14630,40895,19306,10760,65245,59596,15385,23931,35246, + 29017,42380,50414,4155,1578,54015,45981,26440,24174,35515, + 60377,16140,10525,64968,40106,18559,45192,25693,1343,53738, + 51195,4910,29260,42649,9059,63414,38612,16897,21520,32965, + 57767,13682,52613,6480,30770,44263,47862,28195,3905,56212, + 58034,13927,22277,33744,38337,16660,8310,62627,3156,55425, + 47587,27958,31527,45042,52880,6725,48348,26633,2411,56766, + 52143,8058,32280,43725,21050,34543,59277,13144,9545,61852, + 37118,17451,32013,43480,51386,7279,2686,57003,49097,27420, + 37867,18238,9820,62089,58520,12365,20783,34298,18118,37395, + 62321,10148,12725,58720,33794,20695,43040,31989,7575,51522, + 57171,2950,27364,48689,34583,21442,12960,58997,61540,9393, + 17875,37126,27121,48420,56390,2195,7810,51799,43829,32736, + 55673,3500,27854,47131,44554,31455,7101,53096,14239,58186, + 33320,22269,16620,37945,62811,8590,6312,52349,44319,31178, + 28635,47886,55916,3769,63054,8859,17401,38700,33085,21992, + 13450,57439,26021,45424,53266,1223,4822,50691,42849,29620, + 35651,24470,16116,59937,64560,10469,18823,40274,42100,28833, + 4547,50454,54023,2002,26288,45669,19090,40519,65317,11248, + 15841,59700,34902,23683,64026,11983,20397,39800,36201,22972, + 14558,60427,5372,49193,41291,30110,25487,46938,54840,749, + 15307,61214,36476,23209,19640,39021,63759,11738,54573,504, + 24730,46159,41566,30347,6121,49980, +}, +{0,58597,54743,12594,47027,21334,25188,34433,29563,38814, + 42668,16969,50376,8237,4383,62970,59126,531,13089,55236, + 20805,46496,33938,24695,38285,29032,16474,42175,8766,50907, + 63465,4876,53745,13588,1062,57539,26178,33447,45973,22384, + 41610,18031,30557,37816,5433,61916,49390,9227,14087,54242, + 58064,1589,32948,25681,21859,45446,17532,41113,37291,30030, + 62415,5930,9752,49917,49151,23322,27176,36557,2124,60585, + 56731,14718,52356,10337,6483,64950,31543,40914,44768,18949, + 22793,48620,36062,26683,61114,2655,15213,57224,10866,52887, + 65445,6976,40385,31012,18454,44275,28174,35563,48089,24380, + 55741,15704,3178,59535,7541,63888,51362,11335,43718,20003, + 32529,39924,35064,27677,23855,47562,16203,56238,60060,3705, + 64387,8038,11860,51889,19504,43221,39399,32002,25571,34566, + 46644,21201,54352,12469,391,58722,4248,62589,50511,8618, + 42795,17358,29436,38425,34069,25072,20674,46119,12966,54851, + 59249,916,63086,4747,9145,51036,16861,42296,37898,28911, + 45586,22263,26565,33568,1441,57668,53366,13459,49513,9612, + 5310,61531,30426,37439,41741,18408,21732,45057,33075,26070, + 58199,1970,13952,53861,10143,50042,62024,5805,36908,29897, + 17915,41246,56348,14585,2507,60718,27567,36682,48760,23197, + 44903,19330,31408,40533,6356,64561,52483,10726,15082,56847, + 61245,3032,36185,27068,22670,48235,18833,44404,40006,30883, + 65058,6855,11253,53008,3565,59656,55354,15583,47710,24251, + 28553,35692,32406,39539,43841,20388,51493,11712,7410,63511, + 60187,4094,16076,55849,23720,47181,35199,28058,39008,31877, + 19895,43346,12243,52022,64004,7905, +}, +{0,64765,58855,6426,55251,11054,12852,52937,46011,20294, + 22108,43681,25704,39061,33167,32114,31595,34710,40588,25201, + 44216,20549,18783,46498,51408,13357,11575,53706,7939,58366, + 64228,1561,63190,2603,4913,61388,8453,56824,50402,14367, + 17773,47504,41098,23671,37566,28227,30553,35748,36285,28992, + 26714,38055,23150,42643,49033,17268,15878,49915,56289,10012, + 59861,5416,3122,61647,61873,3404,5206,59563,9826,55967, + 50053,16248,16906,48887,42989,23312,38361,26916,28734,36035, + 35546,30247,28477,37824,23817,41460,47342,17427,14689,50588, + 56454,8315,61106,4687,2901,63400,1895,64410,57984,7805, + 53428,11337,13651,51630,46300,18465,20795,44486,25359,40946, + 34536,31253,31756,33009,39403,25878,43999,22306,20024,45765, + 53175,13130,10832,54957,6244,58521,64899,382,65407,898, + 6808,58981,10412,54353,52555,12726,19652,45113,43299,21982, + 39703,26602,32496,33293,33812,30953,25075,40206,21447,44858, + 46624,19165,14255,52050,53832,11957,57468,7297,1435,63846, + 2473,62804,60494,4275,56954,8839,15261,51040,47634,18159, + 24565,41736,28097,37180,34854,29915,29378,36415,38693,27608, + 42257,23020,16630,48139,49529,15748,9374,55395,5802,59991, + 62285,4016,3790,62003,60201,6100,55581,9696,15610,49159, + 48501,16776,22674,42095,27302,38491,36673,29628,30117,35160, + 36930,27839,41590,24203,18321,47980,50718,15075,9209,57092, + 4557,60720,62506,2263,63512,1253,7679,57602,12235,54070, + 51756,14033,19363,46942,44612,21177,40048,24717,31127,34154, + 33651,32654,26260,39529,21664,43101,45383,19898,12488,52277, + 54575,10706,59163,7142,764,65025, +}, +{0,61681,65023,3342,59363,5906,6684,60141,54235,9002, + 11812,57045,13368,50377,51655,14646,48043,19290,18004,46757, + 23624,44217,41399,20806,26736,39041,38287,25982,36755,32610, + 29292,33437,27467,39866,38580,26181,36008,31833,29015,33190, + 47248,18529,17775,46494,24435,44930,41612,21117,53472,8209, + 11551,56814,14083,51186,51964,14861,827,62410,65220,3637, + 58584,5161,6439,59862,54934,9831,11113,56216,12661,49540, + 52362,15483,1357,62908,63666,2115,58030,4703,8017,61344, + 27965,40396,37058,24627,35550,31279,30497,34768,48870,19991, + 17177,46056,22789,43508,42234,21515,48605,19756,16418,45267, + 23102,43727,42945,22320,28166,40695,37881,25352,35301,30996, + 29722,34027,1654,63111,64393,2936,57749,4452,7274,60571, + 54701,9564,10322,55459,12878,49855,53169,16192,45361,16832, + 19662,48191,22226,42531,43821,23516,25322,37403,40725,28644, + 34057,30200,30966,34823,2714,64107,63333,1940,60793,7560, + 4230,57463,55617,10672,9406,54351,16034,52819,50013,13228, + 55930,10891,10117,55156,15769,52584,49254,12439,2465,63824, + 62558,1199,60994,7859,5053,58188,25041,37152,39982,27871, + 34354,30403,31693,35644,45578,17147,20469,48900,21993,42264, + 43030,22759,26535,38742,39512,27305,32836,28853,32187,36170, + 46204,17549,18819,47474,21407,41838,44640,24209,56332,11517, + 8691,53506,15343,51998,50704,14049,4055,65318,61992,729, + 59444,6341,5579,58682,3308,64541,61715,482,60175,7166, + 5872,58881,57143,12230,8904,53817,14548,51237,50475,13786, + 46919,18358,19128,47689,20644,41045,44379,23978,25756,37997, + 39267,27026,33663,29582,32384,36465, +}, +{0,63223,61939,1796,65531,2316,3592,63743,58347,5404, + 4632,58607,7184,60135,60899,6932,56267,11580,10808,56527, + 9264,53959,54723,9012,14368,52951,51667,16164,51163,12588, + 13864,49375,43915,23932,23160,44175,21616,41607,42371,21364, + 18528,48791,47507,20324,47003,16748,18024,45215,28736,34487, + 33203,30532,36795,31052,32328,35007,37803,25948,25176,38063, + 27728,39591,40355,27476,19211,48636,47864,19471,46320,16903, + 17667,46068,43232,24087,22803,45028,22299,41452,42728,20511, + 37056,26167,24883,38852,28475,39372,40648,26687,29483,34268, + 33496,29743,36048,31271,32035,35796,57472,5751,4467,59268, + 8059,59788,61064,6271,875,62876,62104,1135,64656,2663, + 3427,64404,15179,52668,51896,15439,50352,12871,13635,50100, + 55456,11863,10579,57252,10075,53676,54952,8287,38422,24801, + 26597,37138,27117,40730,38942,28393,30205,33546,33806,29433, + 35334,31985,31733,36098,19933,47914,48174,19161,45606,17617, + 17365,46370,44598,22721,24517,43314,20941,42810,41022,22217, + 15773,52074,52334,15001,49766,13457,13205,50530,56950,10369, + 12165,55666,8589,55162,53374,9865,58966,4257,6053,57682, + 6573,61274,59486,7849,1469,62282,62542,697,64070,3249, + 2997,64834,56605,11242,11502,55833,8934,54289,54037,9698, + 16118,51201,52997,14834,49421,14330,12542,50697,1750,61473, + 63269,466,63789,4058,2270,65065,58685,5066,5326,57913, + 6854,60465,60213,7618,30358,32865,34661,29074,35181,32666, + 30878,36457,38269,25482,25742,37497,27270,40049,39797,28034, + 44381,23466,23726,43609,21158,42065,41813,21922,20150,47169, + 48965,18866,45389,18362,16574,46665, +}, +{0,62964,63477,513,62455,1539,1026,61942,64499,3591, + 3078,63986,2052,65008,65521,2565,60411,7695,7182,59898, + 6156,60920,61433,6669,4104,58876,59389,4617,58367,5643, + 5130,57854,52203,15903,15390,51690,14364,52712,53225,14877, + 12312,50668,51181,12825,50159,13851,13338,49646,8208,54756, + 55269,8721,54247,9747,9234,53734,56291,11799,11286,55778, + 10260,56800,57313,10773,35787,32319,31806,35274,30780,36296, + 36809,31293,28728,34252,34765,29241,33743,30267,29754,33230, + 24624,38340,38853,25137,37831,26163,25650,37318,39875,28215, + 27702,39362,26676,40384,40897,27189,16416,46548,47061,16929, + 46039,17955,17442,45526,48083,20007,19494,47570,18468,48592, + 49105,18981,43995,24111,23598,43482,22572,44504,45017,23085, + 20520,42460,42973,21033,41951,22059,21546,41438,2955,65151, + 64638,2442,63612,3464,3977,64125,61560,1420,1933,62073, + 911,63099,62586,398,57456,5508,6021,57969,4999,58995, + 58482,4486,7043,61047,60534,6530,59508,7552,8065,60021, + 49248,13716,14229,49761,13207,50787,50274,12694,15251,52839, + 52326,14738,51300,15760,16273,51813,11163,56943,56430,10650, + 55404,11672,12185,55917,53352,9628,10141,53865,9119,54891, + 54378,8606,32832,30132,30645,33345,29623,34371,33858,29110, + 31667,36423,35910,31154,34884,32176,32689,35397,27579,40527, + 40014,27066,38988,28088,28601,39501,36936,26044,26557,37449, + 25535,38475,37962,25022,19371,48735,48222,18858,47196,19880, + 20393,47709,45144,17836,18349,45657,17327,46683,46170,16814, + 41040,21924,22437,41553,21415,42579,42066,20902,23459,44631, + 44118,22946,43092,23968,24481,43605, +}, +{0,31355,62710,36493,62961,36746,263,31612,63487,36228, + 777,31090,526,30837,63224,35971,62435,35224,1813,32110, + 1554,31849,62180,34975,1052,32359,61674,35473,61933,35734, + 1307,32608,64475,33184,3885,30038,3626,29777,64220,32935, + 3108,30303,63698,33449,63957,33710,3363,30552,2104,29251, + 64718,34485,64969,34738,2367,29508,65479,34236,2865,29002, + 2614,28749,65216,33979,60331,37328,8029,25894,7770,25633, + 60076,37079,7252,26159,59554,37593,59813,37854,7507,26408, + 6216,25139,60606,38597,60857,38850,6479,25396,61367,38348, + 6977,24890,6726,24637,61104,38091,4208,27147,58502,40701, + 58753,40954,4471,27404,59279,40436,4985,26882,4734,26629, + 59016,40179,58259,39400,5989,27934,5730,27673,58004,39151, + 5228,28183,57498,39649,57757,39910,5483,28432,52043,45360, + 16317,17862,16058,17601,51788,45111,15540,18127,51266,45625, + 51525,45886,15795,18376,14504,17107,52318,46629,52569,46882, + 14767,17364,53079,46380,15265,16858,15014,16605,52816,46123, + 12432,19179,50278,48669,50529,48922,12695,19436,51055,48404, + 13209,18914,12958,18661,50792,48147,50035,47368,14213,19966, + 13954,19705,49780,47119,13452,20215,49274,47617,49533,47878, + 13707,20464,8416,23195,54294,44653,54545,44906,8679,23452, + 55071,44388,9193,22930,8942,22677,54808,44131,54019,43384, + 10229,23950,9970,23689,53764,43135,9468,24199,53258,43633, + 53517,43894,9723,24448,56123,41280,12237,21942,11978,21681, + 55868,41031,11460,22207,55346,41545,55605,41806,11715,22456, + 10456,21155,56366,42581,56617,42834,10719,21412,57127,42332, + 11217,20906,10966,20653,56864,42075, +}, +{0,46002,31609,51403,63218,17728,36235,15929,61945,16971, + 35456,14642,1803,46265,31858,53184,65519,19549,33942,14116, + 2333,47791,29284,49622,3606,48548,30063,50909,63716,19286, + 33693,12335,58307,20593,39098,11016,5425,42627,28232,56826, + 4666,41352,26947,56049,58568,22394,40881,11267,7212,44958, + 26453,54503,60126,22892,37287,8725,60885,24167,38572,9502, + 6951,43157,24670,54252,56219,26665,41186,4944,11625,40667, + 22032,58786,10850,39376,20763,58025,56464,28450,42985,5211, + 9332,38854,24333,60607,53894,24884,43519,6733,54669,26175, + 44788,7494,9087,37069,22534,60340,14424,35818,17185,61587, + 52906,32024,46547,1633,51617,31251,45784,362,16211,36065, + 17450,63384,51127,29701,48334,3964,12613,33527,19004,63886, + 13902,34300,19767,65157,49340,29454,48069,2167,43819,6297, + 53330,25568,24025,61035,9888,38162,23250,59744,8619,37401, + 44064,8082,55129,25835,21700,59254,12221,39951,41526,4484, + 55631,27389,42301,5775,56900,28150,21455,57469,10422,39684, + 18664,64346,13201,32803,48666,3496,50531,30417,47377,2723, + 49768,29146,20451,64593,13466,34600,46855,1205,52350,32716, + 16885,62023,14988,35134,18174,62796,15751,36405,45068,958, + 52085,30919,28848,49922,3017,47227,34370,13808,64827,20105, + 33097,13051,64048,18818,30651,50185,3266,49008,36703,15597, + 62502,18324,31149,51743,724,45414,32422,52500,1503,46701, + 34900,15334,62253,16543,37747,8385,59402,23480,25985,54835, + 7928,44362,25226,53560,6643,43585,38008,10186,61185,23731, + 27804,57134,6117,42071,39534,10716,57623,21157,40293,11991, + 58908,21934,27543,55333,4334,41820, +}, +{0,22872,45744,60392,31101,8229,52173,37525,62202,43938, + 16458,6418,35719,53983,14647,24687,63977,41137,19289,4609, + 32916,55756,12836,27516,2835,21067,47523,57595,29294,11062, + 49374,39302,61391,46743,23935,1063,38578,53226,9218,32090, + 7477,17517,44933,63197,25672,15632,55032,36768,5670,20350, + 42134,64974,28507,13827,56811,33971,58588,48516,22124,3892, + 40353,50425,12049,30281,50051,39643,28979,10347,47870,58278, + 2126,20758,12665,26657,33737,55953,18436,4444,64180,41964, + 14954,25394,35034,53634,17175,6735,61863,43263,51344,37320, + 31264,9080,45549,59573,861,23045,11340,29972,40700,51108, + 21809,3177,59265,48857,57014,34798,27654,13662,42955,65171, + 5499,19491,54693,36093,26389,15949,44248,62848,7784,18224, + 10079,32263,38383,52407,24098,1914,60562,46538,39707,49731, + 10667,28915,57958,47934,20694,2446,27105,12473,56145,33289, + 4252,18884,41516,64372,25330,15274,53314,35098,7055,17111, + 43327,61543,36872,51536,8888,31712,59765,45101,23493,669, + 29908,11660,50788,40764,3497,21745,48921,58945,34350,57206, + 13470,28102,65363,42507,19939,5307,36157,54373,16269,26325, + 62528,44312,18160,8104,32711,9887,52599,37935,1722,24546, + 46090,60754,22680,448,59944,45936,8677,30909,37717,51725, + 43618,62266,6354,16778,54047,35399,25007,14583,41329,63529, + 5057,19097,55308,33108,27324,13284,21387,2771,57659,47203, + 10998,29614,38982,49438,46935,60943,1511,23743,52778,38770, + 31898,9666,17837,7413,63261,44613,15568,25992,36448,55096, + 20158,6118,64526,42326,14275,28315,34163,56363,48196,58652, + 3828,22444,50489,40033,30601,11985, +}, +{0,11309,22618,29815,45236,40089,59630,50371,32117,20824, + 9519,2306,52673,57836,38299,47542,64234,54983,41648,36509, + 19038,26227,4612,15913,34719,43954,57285,62440,14123,6918, + 28529,17244,59849,50660,45459,40382,22909,30032,295,11530, + 38076,47249,52454,57547,9224,2085,31826,20607,4899,16142, + 19321,26452,41879,36794,64461,55264,28246,17019,13836,6689, + 57058,62159,34488,43669,53135,58274,38869,48120,32571,21270, + 10081,2892,45818,40663,60064,50829,590,11875,23060,30265, + 13669,6472,27967,16658,34257,43516,56715,61862,18448,25661, + 4170,15463,63652,54409,41214,36051,9798,2667,32284,21041, + 38642,47839,52904,57989,23347,30494,873,12100,60295,51114, + 46045,40944,56492,61569,34038,43227,27672,16437,13378,6255, + 41433,36340,63875,54702,4461,15680,18743,25882,33539,44846, + 56153,63348,13239,8090,27629,18368,65142,53851,42540,35329, + 20162,25327,5784,15029,31209,21956,8627,3486,51549,58736, + 37127,48426,1180,10417,23750,28907,46120,38917,60530,49247, + 27338,18151,12944,7869,55934,63059,33316,44553,6079,15250, + 20453,25544,42763,35622,65361,54140,36896,48141,51322,58455, + 8340,3257,30926,21731,60757,49528,46351,39202,24033,29132, + 1467,10646,19596,24737,5334,14587,64568,53269,42082,34895, + 12793,7636,27043,17806,33101,44384,55575,62778,46694,39499, + 60988,49681,1746,11007,24200,29349,51987,59198,37705,48996, + 31655,22410,9213,4048,42309,35176,64799,53554,5617,14812, + 19883,24966,55344,62493,32874,44103,26756,17577,12510,7411, + 24495,29570,2037,11224,61211,49974,46913,39788,8922,3831, + 31360,22189,37486,48707,51764,58905, +}, +{0,39065,11567,46518,23134,49863,30577,61416,46268,11301, + 39315,266,61154,30331,50125,23380,30053,60924,22602,49363, + 12091,47010,532,39565,49625,22848,60662,29807,39815,798, + 46760,11825,60106,29267,51173,24444,45204,10253,40379,1314, + 24182,50927,29529,60352,1064,40113,10503,45470,40879,1846, + 45696,10777,50673,23912,59614,28743,11027,45962,1596,40613, + 29005,59860,23650,50427,51593,20752,58534,31807,37847,2894, + 48888,9825,32053,58796,20506,51331,10091,49138,2628,37597, + 48364,9333,37315,2394,59058,32299,52125,21252,2128,37065, + 9599,48614,21006,51863,32545,59320,9027,48090,3692,38645, + 31005,57732,21554,52395,38911,3942,47824,8777,52641,21816, + 57486,30743,22054,52927,31497,58256,3192,38113,8535,47566, + 58010,31235,53173,22316,47300,8285,38379,3442,36623,6038, + 41504,15033,54609,19912,63614,24807,15283,41770,5788,36357, + 25069,63860,19650,54363,64106,25331,55109,20444,41012,14509, + 36123,5506,20182,54863,25593,64352,5256,35857,14759,41278, + 26053,64860,18666,53363,16283,42754,4788,35373,53625,18912, + 64598,25807,35623,5054,42504,16017,4256,34873,15759,42262, + 19198,53863,26577,65352,42012,15493,35123,4522,65090,26331, + 54125,19444,18054,56863,27561,62256,7384,33857,12791,43374, + 62010,27299,57109,18316,43108,12541,34123,7634,13283,43898, + 7884,34389,27069,61732,17554,56331,34655,8134,43632,13033, + 56577,17816,61486,26807,44108,13525,33123,6650,62994,28299, + 56125,17316,6384,32873,13791,44358,17070,55863,28545,63256, + 55593,16816,62470,27807,33655,7150,44632,14017,28053,62732, + 16570,55331,14283,44882,6884,33405, +}, +{0,49859,39323,23384,12075,60904,46768,29811,24150,40085, + 51149,1294,29053,46014,59622,10789,48300,32367,9527,59380, + 37767,20804,2588,51423,58106,8249,31585,47522,52689,3858, + 21578,38537,25925,42886,64734,15901,19054,34989,54261,4406, + 15123,63952,41608,24651,5176,55035,36259,20320,55785,6954, + 16498,33457,63170,13313,28505,44442,34751,17788,7716,56551, + 43156,27223,12559,62412,51850,2121,21265,37330,58785,10082, + 31802,48889,38108,22047,3399,53124,48119,31028,8812,57519, + 30246,46309,61373,11646,22797,39886,49302,597,10352,60083, + 45547,29480,1883,50584,40640,23555,45007,27916,13908,62615, + 32996,16935,6527,56252,61849,13146,26626,43713,57010,7281, + 18217,34282,4963,53664,35576,18491,15432,65163,42451,26384, + 19765,36854,54446,5741,25118,41181,64389,14662,35081,19402, + 4242,53841,42530,25825,16313,64890,55135,5532,20164,35847, + 63604,15031,25071,41772,13733,63334,44094,28413,6798,55373, + 33557,16854,27635,43312,62056,12459,17624,34331,56643,8064, + 60492,11919,30167,46868,50023,420,23292,38975,45594,28889, + 11137,59714,40241,24562,1194,50793,20704,37411,51579,3000, + 32715,48392,58960,9363,3766,52341,38701,21998,8605,58206, + 47110,31429,17283,33088,55832,6363,27816,44651,62771,14320, + 7637,57110,33870,18061,13054,61501,43877,27046,65327,15852, + 26292,42103,53252,4807,18847,35676,41337,25530,14562,64033, + 36434,19601,6089,54538,9926,58373,48989,32158,2541,52014, + 36982,21173,30864,47699,57611,9160,22459,38264,52768,3299, + 39530,22697,1009,49458,46401,30594,11482,60953,50236,1791, + 23975,40804,60183,10708,29324,45135, +}, +{0,61422,50113,11311,39839,29809,22622,47024,11043,50381, + 59618,1804,45244,24402,29565,40083,22086,47528,38279,31337, + 52697,8759,3608,57846,32101,37515,48804,20810,59130,2324, + 9531,51925,44172,17250,28493,32931,14099,55549,62674,6972, + 34735,26689,17518,43904,7216,62430,57329,12319,64202,5412, + 14603,55013,24917,36539,41620,19834,53737,15879,4648,64966, + 19062,42392,35255,26201,17669,43755,34500,26922,56986,12660, + 7515,62133,28198,33224,44519,16905,62905,6743,13944,55702, + 4931,64685,53378,16236,35036,26418,19229,42227,14432,55182, + 64417,5199,41983,19473,24638,36816,59785,1639,10824,50598, + 29206,40440,45527,24121,49834,11588,363,61061,22837,46811, + 39668,29978,49103,20513,31758,37856,9296,52158,59281,2175, + 38124,31490,22317,47299,3955,57501,52402,9052,35338,26084, + 18891,42533,4501,65147,53844,15802,41257,20167,25320,36102, + 15030,54616,63863,5785,56396,13218,8077,61539,18387,43069, + 33810,27644,63343,6273,13486,56128,27888,33566,44849,16607, + 9862,51560,58695,2729,48409,21239,32472,37174,3493,57931, + 52836,8586,38458,31188,22011,47637,28864,40750,45825,23791, + 60255,1201,10398,51056,23523,46093,38946,30668,49276,12178, + 957,60499,53007,8417,3278,58144,21648,47998,38737,30911, + 58412,3010,10221,51203,32691,36957,48242,21404,39241,30375, + 23176,46438,726,60728,49431,12025,45674,23940,29099,40517, + 10741,50715,59956,1498,25475,35949,41026,20396,63516,6130, + 15325,54323,18592,42830,35681,25743,54079,15569,4350,65296, + 13765,55851,62980,6634,44634,16820,28059,33397,7910,61704, + 56615,13001,34169,27287,18104,43350, +}, +{0,30582,61164,39322,49605,46771,12073,22623,40855,59617, + 29051,1549,24146,10532,45246,51144,9011,21573,52703,47785, + 58102,38272,3098,31596,48292,52178,21064,9534,32097,2583, + 37773,58619,18022,12560,43146,57340,34723,61653,26959,7737, + 55793,44679,14109,16491,6196,28482,63192,33198,25941,4643, + 35769,64719,42128,54246,19068,15626,64194,36276,5166,25432, + 15111,19569,54763,41629,36044,64442,25120,5462,19721,14975, + 41957,54419,4955,25645,64951,35521,53918,42472,15474,19204, + 45055,55433,16659,13925,28218,6476,32982,63392,12392,18206, + 56964,43506,61869,34523,8001,26679,51882,48604,9286,21296, + 2927,31769,58755,37621,21821,8779,48081,52391,38136,58254, + 31252,3426,59801,40687,1909,28675,10332,24362,50864,45510, + 30222,376,39138,61332,47051,49341,22823,11857,1413,29427, + 60265,39967,50240,45878,10924,24026,39442,60772,29950,904, + 23511,11425,46395,49741,9910,20928,51290,48940,59251,36869, + 2463,32489,47393,52823,22477,8379,30948,3986,38408,57726, + 17379,13461,44303,55929,33318,62800,27850,7100,56436,43778, + 12952,17902,7601,27335,62301,33835,24784,6054,36412,63818, + 41237,54883,20473,14479,65351,34865,4523,26333,16002,18932, + 53358,42776,35145,65087,26533,4307,18572,16378,42592,53526, + 5854,25000,63538,36676,55067,41069,14839,20097,43642,56588, + 17558,13280,27583,7369,34131,61989,13805,17051,56065,44151, + 62504,33630,6852,28082,53039,47193,8643,22197,3818,31132, + 57350,38768,20664,10190,48724,51490,37245,58891,32657,2279, + 60444,39786,752,30086,11737,23215,49973,46147,29579,1277, + 40295,59921,45646,50488,23714,11220, +}, +{0,15162,30324,19790,60648,55250,39580,41382,50637,65271, + 46009,34947,10533,4639,24401,25707,38791,44221,57843,56009, + 31599,16469,3355,13857,21066,26992,9278,7940,48802,34200, + 51414,62444,13075,2089,17767,32349,57339,58561,43407,37557, + 63198,52708,32938,48016,6710,8460,27714,22392,42132,40878, + 53984,59866,18556,29510,15880,1330,24921,23139,5933,11287, + 36273,46731,64453,49407,26150,23836,4178,11112,35534,45556, + 64698,51072,41963,39121,54687,61093,20227,29753,14711,589, + 61857,51867,34773,48367,7497,9843,27453,20487,13420,3926, + 16920,31010,55428,58302,44784,38346,21813,28175,9025,6267, + 47581,33511,53161,62611,37112,43970,59020,56758,31760,18218, + 2660,12638,49842,63880,46278,36860,11866,5472,22574,25364, + 1919,15429,28939,18993,60311,53421,40419,42713,52300,63350, + 47672,33026,8356,7070,22224,28138,2433,12987,32757,17615, + 58729,56915,37661,43047,23499,24817,11711,5765,46883,35865, + 49495,64109,40454,42300,59506,54088,29422,18900,1178,16288, + 65375,50277,35115,45585,5047,10381,26051,24313,14994,424, + 19686,30684,54906,60736,40974,39732,26840,21474,7852,9622, + 33840,48906,62020,51582,44309,38447,56161,57435,16893,31431, + 14217,3251,43626,37200,56350,59172,18050,32184,12534,3020, + 28583,21661,6611,8937,33615,47221,62779,52737,15853,1751, + 19353,28835,53509,59967,42865,40011,63520,49946,36436,46446, + 5320,12274,25276,22918,39289,41539,61197,54327,30097,20139, + 997,14559,23732,26510,10944,4602,45148,35686,50728,64786, + 3838,13764,30858,17328,57878,55596,37986,44888,52019,61449, + 48455,34429,10203,7393,20911,27285, +}, +{0,7452,14904,10020,29808,26988,20040,21332,59616,62972, + 53976,53188,40080,33164,42664,48052,52701,53441,63461,60153, + 47533,42161,33685,40585,9533,14369,7941,537,20813,19537, + 27509,30313,34727,39611,48543,41091,62423,61131,51695,54515, + 28487,29275,21887,18531,6967,1579,8463,15379,19066,22374, + 28738,27998,15882,8982,1074,6446,41626,49030,39074,34238, + 55018,52214,60626,61902,4947,3663,10603,13431,26403,31295, + 23835,16391,64435,59055,49547,56471,36803,37599,46587,43239, + 56974,50066,58550,63914,43774,47074,37062,36314,13934,11122, + 3158,4426,16926,24322,30758,25914,38132,35304,44748,46032, + 57476,64920,55996,51104,31764,24840,17964,23344,2148,5496, + 12892,12096,22825,17461,25361,32269,11609,12357,5985,2685, + 45513,44245,35825,38637,50617,55461,65409,58013,9894,15290, + 7326,386,21206,20426,26862,30194,52806,54106,62590,59746, + 47670,42794,32782,40210,60283,63079,53571,52319,40715,33303, + 42291,47151,923,7815,14755,9407,30699,27383,19923,20687, + 41217,48157,39737,34341,54641,51309,61257,62037,18913,21757, + 29657,28357,15761,8333,1961,6837,27868,29120,22244,19448, + 6316,1456,8852,16264,33852,39200,48644,41752,61516,60752, + 51828,55144,13813,10473,4045,4817,16773,23705,31677,26273, + 56597,49161,59181,64049,43365,46201,37725,36417,63528,58676, + 49680,57100,35928,37188,46688,43900,4296,3540,10992,14316, + 25784,31140,24192,17308,45650,44878,34922,38262,50722,56126, + 64538,57606,23218,18350,24714,32150,11970,13278,5370,2534, + 32655,25235,17847,22699,3071,5859,12743,11483,38767,35443, + 44375,45131,58143,65027,55591,50235, +}, +{0,3599,7198,4625,14396,13875,9250,10797,28792,32375, + 27750,25193,18500,17995,21594,23125,57584,61183,64750,62177, + 55500,54979,50386,51933,37000,40583,35990,33433,43188,42683, + 46250,47781,56829,54258,49635,53228,58817,60366,63967,63440, + 44421,41866,45467,49044,38329,39862,35239,34728,15629,13058, + 8467,12060,1329,2878,6447,5920,19829,17274,20843,24420, + 30025,31558,26967,26456,42983,43496,48121,46582,40923,37332, + 33733,36298,55199,55696,52097,50574,61347,57772,62397,64946, + 18199,18712,23305,21766,32555,28964,25397,27962,14191,14688, + 11121,9598,3923,348,4941,7490,31258,29717,26116,26635, + 16934,19497,24120,20535,2658,1133,5756,6259,12894,15441, + 11840,8271,39658,38117,34548,35067,41686,44249,48840,45255, + 60050,58525,63116,63619,53934,56481,52912,49343,21459,24028, + 20429,16834,27631,26080,30705,31230,9131,11684,16309,12730, + 7063,5528,1929,2438,45859,48428,44861,41266,35615,34064, + 38657,39182,50011,52564,57157,53578,64359,62824,59257,59766, + 36398,32801,37424,39999,46610,47133,43532,41987,65110,61529, + 57928,60487,50794,51301,55924,54395,28382,24785,29376,31951, + 22242,22765,19196,17651,7846,4265,696,3255,9882,10389, + 14980,13451,62516,64059,59434,58917,52232,49671,53270,56857, + 33868,35395,38994,38493,48240,45695,41070,44641,5316,6859, + 2266,1749,11512,8951,12518,16105,25788,27315,30882,30381, + 23680,21135,16542,20113,10697,10182,13783,15320,4597,8186, + 3563,996,22961,22462,17839,19360,24973,28546,32147,29596, + 51513,50998,54567,56104,61701,65290,60699,58132,47425,46926, + 42335,43856,33149,36722,40291,37740, +}, +{0,35208,3853,34437,7706,38802,4375,39071,15412,46524, + 13113,47793,8750,43942,11555,42155,30824,61920,30565,65261, + 26226,61434,27007,57591,17500,52692,19281,49881,23110,54222, + 21835,56515,61648,31064,65501,30293,61130,26434,57799,26703, + 52452,17772,50153,19041,54014,23414,56819,21627,35000,304, + 34741,3645,38562,7978,39343,4135,46220,15620,48001,12809, + 43670,8990,42395,11283,64957,29749,62128,31544,58279,27183, + 60586,25890,49545,18433,52868,18188,57235,22043,53406,22806, + 34261,3165,35544,848,39887,4679,38082,7498,47585,12393, + 46828,16228,43003,11891,43254,8574,3437,34021,608,35816, + 4983,39679,7290,38386,12633,47313,15956,47068,12099,42699, + 8270,43462,29957,64653,31240,62336,27423,58007,25618,60826, + 18737,49337,17980,53172,22315,56995,22566,53678,59239,28399, + 59498,25058,63869,28917,63088,32760,56147,21211,54366,24022, + 50505,19649,51780,17356,40719,5767,36866,6538,33045,2205, + 36376,1936,41787,10931,44086,9662,48417,13481,45612,15268, + 6071,40511,6330,37170,2477,32805,1696,36648,11139,41483, + 9358,44294,13721,48145,14996,45852,28639,58967,24786,59738, + 29125,63565,32456,63296,21483,55907,23782,54638,19953,50297, + 17148,52084,6874,37714,5591,40031,1216,36168,3021,33349, + 9966,44902,10723,41067,14580,45436,14329,48753,25266,60218, + 28095,58423,31912,62752,29605,64045,24198,55054,20875,55299, + 16540,51476,20369,50713,59914,25474,58631,27791,62480,32152, + 64285,29333,54846,24502,55603,20667,51236,16812,50985,20129, + 37474,7146,40303,5351,35960,1520,33653,2813,44630,10206, + 41307,10451,45132,14788,48961,14025, +}, +{0,17477,34954,52431,3337,18764,34179,49606,6674,24151, + 37528,55005,5915,21342,40849,56276,13348,28769,48302,63723, + 14637,32104,45479,62946,11830,27251,42684,58105,9023,26490, + 43957,61424,26696,11277,57538,42119,25921,8452,60875,43406, + 29274,13855,64208,48789,32595,15126,63449,45980,23660,6185, + 54502,37027,20837,5408,55791,40362,18046,571,52980,35505, + 19319,3890,50173,34744,53392,38101,22554,7263,56729,39388, + 21779,4438,51842,36551,16904,1613,51083,33742,20225,2884, + 58548,41201,27710,10363,59837,44536,24887,9586,65190,47843, + 30252,12905,62383,47082,31525,16224,47320,64669,12370,29719, + 46545,61844,15707,31006,41674,59023,10816,28165,44995,60294, + 10057,25356,36092,51385,1142,16435,33269,50608,2431,19770, + 38638,53931,7780,23073,39911,57250,4973,22312,48445,63864, + 13751,29170,45108,62577,14526,31995,42799,58218,12197,27616, + 43558,61027,8876,26345,35097,52572,403,17878,33808,49237, + 3226,18655,37643,55118,7041,24516,40450,55879,5768,21197, + 54645,37168,24063,6586,55420,39993,20726,5299,53095,35618, + 18413,936,49774,34347,19172,3745,57681,42260,27099,11678, + 60504,43037,25810,8343,64323,48902,29641,14220,63050,45583, + 32448,14981,28077,10728,58663,41314,24740,9441,59438,44139, + 30655,13306,65333,47984,31414,16115,62012,46713,22921,7628, + 53507,38214,21632,4293,56330,38991,17307,2014,51985,36692, + 20114,2775,50712,33373,1509,16800,36207,51498,2284,19625, + 32870,50211,8183,23474,38781,54072,4862,22203,39540,56881, + 12737,30084,47435,64782,15560,30861,46146,61447,11219,28566, + 41817,59164,9946,25247,44624,59925, +}, +{0,44205,17735,59882,35470,9763,53193,25444,2305,42412, + 19526,57579,33679,12066,50888,27237,4610,48815,22341,64488, + 39052,13345,56779,29030,6915,47022,24132,62185,37261,15648, + 54474,30823,9220,34985,24899,52718,44682,551,60365,18272, + 11525,33192,26690,50415,42891,2854,58060,20065,13830,39595, + 29505,57324,48264,4133,63951,21858,16135,37802,31296,55021, + 46473,6436,61646,23651,18440,58533,3407,41442,49798,28203, + 34753,11116,16649,60836,1102,43235,52103,26410,36544,8813, + 23050,63143,8013,46048,53380,31785,38339,14702,21259,65446, + 5708,47841,55685,29992,40130,12399,27660,49313,10571,34278, + 59010,18991,41925,3944,25869,51616,8266,36071,61315,17198, + 43716,1641,32270,53923,15177,38884,62592,22573,45511,7530, + 30479,56226,12872,40677,64897,20780,47302,5227,36880,15549, + 54615,31226,6814,46643,24537,62324,39185,13756,56406,28923, + 5023,48946,22232,64117,33298,11967,51029,27640,2204,42033, + 19931,57718,35603,10174,52820,25337,413,44336,17626,59511, + 46100,6329,61779,24062,16026,37431,31709,55152,48405,4536, + 63570,21759,14235,39734,29404,56945,42518,2747,58193,20476, + 11416,32821,27103,50546,44823,954,59984,18173,9625,35124, + 24798,52339,55320,29877,40287,12786,21142,65083,6097,47996, + 53529,32180,37982,14579,23447,63290,7888,45693,51738,26295, + 36701,9200,16532,60473,1491,43390,49947,28598,34396,10993, + 18837,58680,3282,41087,64540,20657,47451,5622,30354,55871, + 13269,40824,62749,22960,45146,7415,32659,54078,15060,38521, + 60958,17075,43865,2036,25744,51261,8663,36218,59167,19378, + 41560,3829,28049,49468,10454,33915, +}, +{0,55513,44463,30070,18243,40858,60140,12853,36486,22111, + 9001,64496,51653,4380,25706,48307,273,55752,44222,29799, + 18002,40587,60413,13092,36759,22350,8760,64225,51412,4109, + 25979,48546,546,56059,44941,30548,17761,40376,59598,12311, + 36004,21629,8459,63954,52199,4926,26184,48785,819,56298, + 44700,30277,17520,40105,59871,12550,36277,21868,8218,63683, + 51958,4655,26457,49024,1092,56477,43499,28978,17159,39902, + 61096,13937,35522,21019,10093,65460,52609,5464,24622,47351, + 1365,56716,43258,28707,16918,39631,61369,14176,35795,21258, + 9852,65189,52368,5193,24895,47590,1638,57023,43977,29456, + 16677,39420,60554,13395,35040,20537,9551,64918,53155,6010, + 25100,47829,1911,57262,43736,29185,16436,39149,60827,13634, + 35313,20776,9310,64647,52914,5739,25373,48068,2184,53329, + 42279,32254,20427,38674,57956,15037,34318,24279,11169,62328, + 49485,6548,27874,46139,2457,53568,42038,31983,20186,38403, + 58229,15276,34591,24518,10928,62057,49244,6277,28147,46378, + 2730,53875,42757,32732,19945,38192,57414,14495,33836,23797, + 10627,61786,50031,7094,28352,46617,3003,54114,42516,32461, + 19704,37921,57687,14734,34109,24036,10386,61515,49790,6823, + 28625,46856,3276,54293,41315,31162,19343,37718,58912,16121, + 33354,23187,12261,63292,50441,7632,26790,45183,3549,54532, + 41074,30891,19102,37447,59185,16360,33627,23426,12020,63021, + 50200,7361,27063,45422,3822,54839,41793,31640,18861,37236, + 58370,15579,32872,22705,11719,62750,50987,8178,27268,45661, + 4095,55078,41552,31369,18620,36965,58643,15818,33145,22944, + 11478,62479,50746,7907,27541,45900, +}, +{0,58083,55771,15160,44971,19784,30320,38035,17227,41384, + 39568,30835,60640,3587,13627,55256,34454,25717,24397,48558, + 10557,52190,61670,4613,50653,10046,7174,65253,27254,34965, + 45997,20814,4401,62418,51434,10761,48794,23673,26433,34210, + 21114,45209,35745,26946,64977,7986,9226,50921,38823,30020, + 20092,44191,14348,56047,57815,820,54508,13839,3383,61396, + 31559,39332,41628,16511,8802,49281,64441,6490,36297,28458, + 21522,46833,24873,33738,47346,23057,52866,11361,5977,62906, + 42228,17943,32047,40908,2911,59836,53892,12391,59327,1372, + 15972,56455,18452,43767,37327,29484,13139,53680,60040,2155, + 40184,32283,17699,42944,28696,37627,43459,19232,57267,15696, + 1640,58507,46533,22310,27678,36605,6766,63629,50101,8534, + 63118,5229,12117,52662,22821,48070,33022,25117,17604,42535, + 40223,32764,60271,2444,12980,53335,1935,58732,56916,15543, + 43044,19143,29183,37660,49746,8369,7049,63850,28153,36634, + 46114,22209,33049,25594,22722,47649,11954,52305,63337,5514, + 22005,46870,35886,28365,64094,6333,9093,49510,5822,62557, + 53093,11654,47381,23542,24782,33325,54115,12672,2744,59483, + 31944,40491,42259,18416,36904,29387,18931,43792,16259,56672, + 58968,1211,26278,33861,49021,23966,51469,11246,4310,62005, + 9709,50958,64566,7893,35398,26789,21405,45438,57392,723, + 14827,56072,20379,44408,38464,29859,41851,16792,31392,38979, + 3280,60979,54539,14312,30615,38260,44620,19631,55356,15071, + 487,58116,13532,54847,60679,4068,39799,31124,17068,41039, + 61697,5090,10458,51769,24234,48201,34673,26002,45642,20649, + 27537,35186,7649,65282,50234,9945, +}, +{0,65534,58337,7199,56287,9249,14398,51136,43939,21597, + 18498,47036,28796,36738,37789,27747,19291,46245,43194,22340, + 36996,28538,29541,35995,57592,7942,793,64743,15143,50393, + 55494,10040,38582,26952,30039,35497,19817,45719,44680,20854, + 15637,49899,57076,8458,59082,6452,1323,64213,56813,8723, + 15884,49650,1586,63948,58835,6701,30286,35248,38319,27217, + 44433,21103,20080,45454,12657,52879,53904,11630,60078,5456, + 2383,63153,39634,25900,31027,34509,16653,48883,41708,23826, + 31274,34260,39371,26165,41461,24075,16916,48618,53641,11895, + 12904,52630,2646,62888,59831,5705,42951,22585,17446,48088, + 31768,33766,40953,24583,3172,62362,61317,4219,55227,10309, + 13402,52132,60572,4962,3965,61571,14147,51389,54434,11100, + 18239,47297,42206,23328,40160,25374,32513,33023,25314,40220, + 33027,32509,47421,18115,23260,42274,51521,14015,10912,54622, + 4766,60768,61823,3713,10681,54855,51800,13734,62054,3480, + 4487,61049,33306,32228,25083,40453,22981,42555,47652,17882, + 62548,2986,6069,59467,12171,53365,52330,13204,24567,40969, + 48150,17384,33832,31702,26569,38967,48911,16625,23790,41744, + 25808,39726,34609,30927,5292,60242,63309,2227,53107,12429, + 11410,54124,21395,44141,45170,20364,34892,30642,27565,37971, + 63536,1998,7121,58415,9199,56337,49166,16368,6344,59190, + 64297,1239,49943,15593,8438,57096,45931,19605,20618,44916, + 26804,38730,35669,29867,50469,15067,9924,55610,7930,57604, + 64795,741,28294,37240,36199,29337,46425,19111,22200,43334, + 36478,29056,28063,37473,21921,43615,46656,18878,9693,55843, + 50748,14786,65026,508,7651,57885, +}, +{0,32638,65276,33154,57829,40603,7961,24679,57303,41129, + 8491,24149,15922,16716,49358,49072,41907,56525,23887,8753, + 16982,15656,48298,50132,31844,794,33432,64998,40321,58111, + 25469,7171,23419,9221,42375,56057,47774,50656,17506,15132, + 33964,64466,31312,1326,25929,6711,39861,58571,63688,34742, + 1588,31050,6445,26195,59345,39087,10015,22625,55779,42653, + 50938,47492,14342,18296,46838,51592,18442,14196,22291,10349, + 43503,54929,26913,5727,38877,59555,35012,63418,30264,2374, + 5445,27195,60345,38087,62624,35806,2652,29986,51858,46572, + 13422,19216,11127,21513,54667,43765,60813,37619,4977,27663, + 3176,29462,62100,36330,12890,19748,52390,46040,54207,44225, + 11587,21053,20030,12608,45250,53180,45019,53413,20775,11865, + 37353,61079,28437,4203,28684,3954,36592,61838,29169,3727, + 36621,61555,36884,61290,28392,4502,44582,53592,20698,12196, + 20419,12477,45375,52801,53826,44348,11454,21440,13223,19673, + 52571,45605,3477,29419,62313,35863,60528,37646,4748,28146, + 10890,22004,54390,43784,52079,46097,13715,19181,62813,35363, + 2977,29919,5304,27590,59972,38202,35129,63047,30661,2235, + 26844,6050,38432,59742,22254,10640,43026,55148,46859,51317, + 18935,13961,50951,47225,14843,18053,9954,22940,55326,42848, + 6352,26542,58924,39250,63797,34379,1993,30903,25780,7114, + 39496,58678,34129,64047,31661,1235,47971,50205,17823,15073, + 23174,9720,42106,56068,40060,58114,25216,7678,32153,743, + 33637,64539,17323,15573,48471,49705,41550,56624,23730,9164, + 16335,16561,49459,48717,56874,41300,8406,24488,57368,40806, + 7908,24986,509,32387,65281,32895, +}, +{0,16190,32380,16706,64760,50118,33412,48570,58861,56019, + 39825,42159,6421,9771,26473,22615,55239,59641,43451,38533, + 11071,5121,21827,27261,12842,3348,19542,29544,52946,61932, + 45230,36752,45971,36013,52719,62161,20331,28757,12567,3625, + 22142,26944,10242,5948,43654,38328,54522,60356,25684,23402, + 6696,9494,39084,42898,59088,55790,33209,48775,65477,49403, + 32065,17023,829,15363,31547,17413,1351,14969,34755,47357, + 63935,50817,40662,41448,57514,57236,25134,23824,7250,9068, + 44284,37826,53888,60862,20484,28474,11896,4422,18705,30255, + 14189,2131,46569,35543,52117,62635,51368,63382,46804,35306, + 13392,2926,18988,29970,11589,4731,21305,27655,53693,61059, + 44993,37119,8047,8273,24851,24109,58263,56489,40427,41685, + 64130,50620,34046,48064,1658,14660,30726,18232,63094,51528, + 34826,46900,2702,13744,29938,19404,5019,11429,28135,21209, + 61283,53341,37151,44577,8625,7823,24525,24819,56649,57975, + 41781,39947,50268,64354,47648,34078,14500,1946,18136,31206, + 17893,31451,15257,1191,47389,34339,51041,63583,40968,40758, + 56948,57674,23792,25550,8844,7602,37410,44316,60510,54112, + 28378,20964,4262,12184,30671,18673,2483,13965,35639,46089, + 62795,51829,36173,45683,62257,52239,29109,20107,4041,12535, + 26784,22430,5852,10722,37976,43878,59940,54554,23178,26036, + 9462,7112,42610,39244,55310,59184,48999,32857,49435,65061, + 17311,31905,15843,733,16094,480,16546,32668,49702,64792, + 48218,33636,56115,58381,42319,39537,10187,6389,22967,26249, + 59673,54823,38757,43099,5601,10975,27549,21667,3316,13258, + 29320,19894,61452,53042,36464,45390, +}, +{0,7966,15932,8482,31864,25446,16964,23898,63728,59374, + 50892,55762,33928,39830,47796,42410,60925,62179,54209,52447, + 37253,36507,44985,45223,5389,2579,11057,13359,26997,30315, + 22345,18519,51175,55545,63963,59077,48031,42113,34211,39613, + 16151,8201,299,7733,17263,23665,32083,25165,10778,13572, + 5158,2872,22114,18812,26718,30528,53994,52724,60630,62408, + 44690,45452,37038,36784,37843,36045,44527,45809,61355,61621, + 53655,52873,27427,29757,21791,18945,5979,2117,10599,13945, + 32302,24880,16402,24332,598,7496,15466,9076,34526,39360, + 47330,43004,64166,58808,50330,56196,21556,19242,27144,29974, + 10316,14162,5744,2414,44228,46042,37624,36326,53436,53154, + 61056,61854,47561,42711,34805,39147,50609,55983,64397,58515, + 16697,24103,32517,24603,15681,8799,893,7267,15291,9381, + 1415,6809,18371,22749,31231,26337,49995,56405,64887,57961, + 48947,41005,33039,40465,54854,51544,59514,63332,43582,46368, + 37890,35612,11958,12712,4234,3988,21198,19920,27890,29676, + 64604,58178,49760,56702,32804,40762,48664,41222,1196,7090, + 14992,9614,30932,26570,18152,23030,4513,3775,12189,12419, + 28121,29383,21477,19707,59729,63055,55149,51315,38185,35383, + 43797,46091,43112,46966,38484,35146,54288,51982,59948,62770, + 20632,20358,28324,29114,11488,13310,4828,3522,17813,23179, + 31657,25783,14829,9971,2001,6351,48485,41595,33625,40007, + 49437,56835,65313,57407,28559,28817,20915,20141,5111,3305, + 11723,13013,38783,34913,43331,46685,60167,62489,54587,51749, + 33394,40300,48206,41808,65034,57620,49206,57128,31362,26012, + 17598,23456,1786,6628,14534,10200, +}, +{0,3854,7708,4370,15416,13110,8740,11562,30832,30590, + 26220,26978,17480,19270,23124,21850,61664,65518,61180,57842, + 52440,50134,53956,56778,34960,34718,38540,39298,46248,48038, + 43700,42426,64989,62163,58305,60623,49637,52971,57337,53495, + 34221,35491,39857,38079,47509,46747,42889,43143,3389,563, + 4897,7215,12549,15883,12057,8215,30029,31299,27473,25695, + 18805,18043,22377,22631,59303,59561,63931,63157,56223,54417, + 50563,51853,40919,37081,33227,36549,41967,44257,48627,45821, + 5959,6217,2395,1621,11135,9329,13667,14957,28471,24633, + 28971,32293,21263,23553,19731,16925,6778,5492,1126,2920, + 9794,10572,14430,14160,25098,27908,31766,29464,24114,20796, + 16430,20256,60058,58772,62598,64392,54946,55724,51390,51120, + 37610,40420,36086,33784,44754,41436,45262,49088,54099,56413, + 52559,49729,61291,57445,61815,65145,43811,42029,46399,47665, + 38683,38933,35079,34313,9139,11453,15791,12961,8075,4229, + 407,3737,23491,21709,17887,19153,26619,26869,31207,30441, + 11918,8576,12434,16284,4790,7608,3242,932,22270,23024, + 18658,18412,27334,26056,29914,31700,56942,53600,49266,53116, + 57942,60760,64586,62276,42526,43280,47106,46860,39462,38184, + 33850,35636,13556,15354,10984,9702,2252,1986,5840,6622, + 19588,17290,21144,23958,28860,32690,28320,25006,50196,51994, + 55816,54534,63532,63266,58928,59710,48228,45930,41592,44406, + 32860,36690,40512,37198,51497,50727,55093,55355,62737,64031, + 60173,58371,45401,48727,44869,41035,36193,33391,37757,40051, + 14793,14023,10197,10459,1521,2815,7149,5347,16825,20151, + 24485,20651,32129,29327,25501,27795, +}, +{0,1798,3596,2314,7192,6942,4628,5394,14384,16182, + 13884,12602,9256,9006,10788,11554,28768,30566,32364,31082, + 27768,27518,25204,25970,18512,20310,18012,16730,21576,21326, + 23108,23874,57536,59334,61132,59850,64728,64478,62164,62930, + 55536,57334,55036,53754,50408,50158,51940,52706,37024,38822, + 40620,39338,36024,35774,33460,34226,43152,44950,42652,41370, + 46216,45966,47748,48514,56733,55963,54161,54423,49541,50819, + 53129,51343,58797,58027,60321,60583,63925,65203,63417,61631, + 44541,43771,41969,42231,45541,46819,49129,47343,38349,37579, + 39873,40135,35285,36563,34777,32991,15709,14939,13137,13399, + 8517,9795,12105,10319,1389,619,2913,3175,6517,7795, + 6009,4223,19773,19003,17201,17463,20773,22051,24361,22575, + 29965,29195,31489,31751,26901,28179,26393,24607,42791,40993, + 43307,44589,47935,48185,46387,45621,40727,38929,37147,38429, + 33551,33801,36099,35333,55111,53313,55627,56909,52063,52313, + 50515,49749,61303,59505,57723,59005,62319,62569,64867,64101, + 18407,16609,18923,20205,23551,23801,22003,21237,32727,30929, + 29147,30429,25551,25801,28099,27333,14215,12417,14731,16013, + 11167,11417,9619,8853,4023,2225,443,1725,5039,5289, + 7587,6821,31418,32188,29878,29616,26274,24996,26798,28584, + 17034,17804,19590,19328,24210,22932,20638,22424,2778,3548, + 1238,976,5826,4548,6350,8136,13034,13804,15590,15328, + 12018,10740,8446,10232,39546,40316,38006,37744,34402,33124, + 34926,36712,41546,42316,44102,43840,48722,47444,45150,46936, + 59930,60700,58390,58128,62978,61700,63502,65288,53802,54572, + 56358,56096,52786,51508,49214,51000, +}, +{0,770,1540,1286,3080,3850,2572,2318,6160,6930, + 7700,7446,5144,5914,4636,4382,12320,13090,13860,13606, + 15400,16170,14892,14638,10288,11058,11828,11574,9272,10042, + 8764,8510,24640,25410,26180,25926,27720,28490,27212,26958, + 30800,31570,32340,32086,29784,30554,29276,29022,20576,21346, + 22116,21862,23656,24426,23148,22894,18544,19314,20084,19830, + 17528,18298,17020,16766,49280,50050,50820,50566,52360,53130, + 51852,51598,55440,56210,56980,56726,54424,55194,53916,53662, + 61600,62370,63140,62886,64680,65450,64172,63918,59568,60338, + 61108,60854,58552,59322,58044,57790,41152,41922,42692,42438, + 44232,45002,43724,43470,47312,48082,48852,48598,46296,47066, + 45788,45534,37088,37858,38628,38374,40168,40938,39660,39406, + 35056,35826,36596,36342,34040,34810,33532,33278,40221,40479, + 39705,38939,37141,37399,38673,37907,34061,34319,33545,32779, + 35077,35335,36609,35843,44349,44607,43833,43067,41269,41527, + 42801,42035,46381,46639,45865,45099,47397,47655,48929,48163, + 64861,65119,64345,63579,61781,62039,63313,62547,58701,58959, + 58185,57419,59717,59975,61249,60483,52605,52863,52089,51323, + 49525,49783,51057,50291,54637,54895,54121,53355,55653,55911, + 57185,56419,23965,24223,23449,22683,20885,21143,22417,21651, + 17805,18063,17289,16523,18821,19079,20353,19587,28093,28351, + 27577,26811,25013,25271,26545,25779,30125,30383,29609,28843, + 31141,31399,32673,31907,15837,16095,15321,14555,12757,13015, + 14289,13523,9677,9935,9161,8395,10693,10951,12225,11459, + 3581,3839,3065,2299,501,759,2033,1267,5613,5871, + 5097,4331,6629,6887,8161,7395, +}, +}; --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/gdrom/edc_scramble.h Sun Mar 02 11:38:08 2008 +0000 @@ -0,0 +1,621 @@ +/* @(#)scramble_table 1.2 02/10/19 */ + +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 + * as published by the Free Software Foundation. + * + * 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; see the file COPYING. If not, write to the Free Software + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +static const 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, + 10,158,135,40,98,158,169,168,126,254,160,64,120,48,34,148,25,175,74,252,55,1,214, + 128,94,224,56,72,18,182,141,182,229,182,203,54,215,86,222,190,216,112,90,164,59,59, + 83,83,125,253,225,129,136,96,102,168,42,254,159,0,104,0,46,128,28,96,9,232,6, + 206,130,212,97,159,104,104,46,174,156,124,105,225,238,200,76,86,181,254,247,0,70,128, + 50,224,21,136,15,38,132,26,227,75,9,247,70,198,178,210,245,157,135,41,162,158,249, + 168,66,254,177,128,116,96,39,104,26,174,139,60,103,81,234,188,79,49,244,20,71,79, + 114,180,37,183,91,54,187,86,243,126,197,224,83,8,61,198,145,146,236,109,141,237,165, + 141,187,37,179,91,53,251,87,3,126,129,224,96,72,40,54,158,150,232,110,206,172,84, + 125,255,97,128,40,96,30,168,8,126,134,160,98,248,41,130,158,225,168,72,126,182,160, + 118,248,38,194,154,209,171,28,127,73,224,54,200,22,214,142,222,228,88,75,122,183,99, + 54,169,214,254,222,192,88,80,58,188,19,49,205,212,85,159,127,40,32,30,152,8,106, + 134,175,34,252,25,129,202,224,87,8,62,134,144,98,236,41,141,222,229,152,75,42,183, + 95,54,184,22,242,142,197,164,83,59,125,211,97,157,232,105,142,174,228,124,75,97,247, + 104,70,174,178,252,117,129,231,32,74,152,55,42,150,159,46,232,28,78,137,244,102,199, + 106,210,175,29,188,9,177,198,244,82,199,125,146,161,173,184,125,178,161,181,184,119,50, + 166,149,186,239,51,12,21,197,207,19,20,13,207,69,148,51,47,85,220,63,25,208,10, + 220,7,25,194,138,209,167,28,122,137,227,38,201,218,214,219,30,219,72,91,118,187,102, + 243,106,197,239,19,12,13,197,197,147,19,45,205,221,149,153,175,42,252,31,1,200,0, + 86,128,62,224,16,72,12,54,133,214,227,30,201,200,86,214,190,222,240,88,68,58,179, + 83,53,253,215,1,158,128,104,96,46,168,28,126,137,224,102,200,42,214,159,30,232,8, + 78,134,180,98,247,105,134,174,226,252,73,129,246,224,70,200,50,214,149,158,239,40,76, + 30,181,200,119,22,166,142,250,228,67,11,113,199,100,82,171,125,191,97,176,40,116,30, + 167,72,122,182,163,54,249,214,194,222,209,152,92,106,185,239,50,204,21,149,207,47,20, + 28,15,73,196,54,211,86,221,254,217,128,90,224,59,8,19,70,141,242,229,133,139,35, + 39,89,218,186,219,51,27,85,203,127,23,96,14,168,4,126,131,96,97,232,40,78,158, + 180,104,119,110,166,172,122,253,227,1,137,192,102,208,42,220,31,25,200,10,214,135,30, + 226,136,73,166,182,250,246,195,6,209,194,220,81,153,252,106,193,239,16,76,12,53,197, + 215,19,30,141,200,101,150,171,46,255,92,64,57,240,18,196,13,147,69,173,243,61,133, + 209,163,28,121,201,226,214,201,158,214,232,94,206,184,84,114,191,101,176,43,52,31,87, + 72,62,182,144,118,236,38,205,218,213,155,31,43,72,31,118,136,38,230,154,202,235,23, + 15,78,132,52,99,87,105,254,174,192,124,80,33,252,24,65,202,176,87,52,62,151,80, + 110,188,44,113,221,228,89,139,122,231,99,10,169,199,62,210,144,93,172,57,189,210,241, + 157,132,105,163,110,249,236,66,205,241,149,132,111,35,108,25,237,202,205,151,21,174,143, + 60,100,17,235,76,79,117,244,39,7,90,130,187,33,179,88,117,250,167,3,58,129,211, + 32,93,216,57,154,146,235,45,143,93,164,57,187,82,243,125,133,225,163,8,121,198,162, + 210,249,157,130,233,161,142,248,100,66,171,113,191,100,112,43,100,31,107,72,47,118,156, + 38,233,218,206,219,20,91,79,123,116,35,103,89,234,186,207,51,20,21,207,79,20,52, + 15,87,68,62,179,80,117,252,39,1,218,128,91,32,59,88,19,122,141,227,37,137,219, + 38,219,90,219,123,27,99,75,105,247,110,198,172,82,253,253,129,129,160,96,120,40,34, + 158,153,168,106,254,175,0,124,0,33,192,24,80,10,188,7,49,194,148,81,175,124,124, + 33,225,216,72,90,182,187,54,243,86,197,254,211,0,93,192,57,144,18,236,13,141,197, + 165,147,59,45,211,93,157,249,169,130,254,225,128,72,96,54,168,22,254,142,192,100,80, + 43,124,31,97,200,40,86,158,190,232,112,78,164,52,123,87,99,126,169,224,126,200,32, + 86,152,62,234,144,79,44,52,29,215,73,158,182,232,118,206,166,212,122,223,99,24,41, + 202,158,215,40,94,158,184,104,114,174,165,188,123,49,227,84,73,255,118,192,38,208,26, + 220,11,25,199,74,210,183,29,182,137,182,230,246,202,198,215,18,222,141,152,101,170,171, + 63,63,80,16,60,12,17,197,204,83,21,253,207,1,148,0,111,64,44,48,29,212,9, + 159,70,232,50,206,149,148,111,47,108,28,45,201,221,150,217,174,218,252,91,1,251,64, + 67,112,49,228,20,75,79,119,116,38,167,90,250,187,3,51,65,213,240,95,4,56,3, + 82,129,253,160,65,184,48,114,148,37,175,91,60,59,81,211,124,93,225,249,136,66,230, + 177,138,244,103,7,106,130,175,33,188,24,113,202,164,87,59,126,147,96,109,232,45,142, + 157,164,105,187,110,243,108,69,237,243,13,133,197,163,19,57,205,210,213,157,159,41,168, + 30,254,136,64,102,176,42,244,31,7,72,2,182,129,182,224,118,200,38,214,154,222,235, + 24,79,74,180,55,55,86,150,190,238,240,76,68,53,243,87,5,254,131,0,97,192,40, + 80,30,188,8,113,198,164,82,251,125,131,97,161,232,120,78,162,180,121,183,98,246,169, + 134,254,226,192,73,144,54,236,22,205,206,213,148,95,47,120,28,34,137,217,166,218,250, + 219,3,27,65,203,112,87,100,62,171,80,127,124,32,33,216,24,90,138,187,39,51,90, + 149,251,47,3,92,1,249,192,66,208,49,156,20,105,207,110,212,44,95,93,248,57,130, + 146,225,173,136,125,166,161,186,248,115,2,165,193,187,16,115,76,37,245,219,7,27,66, + 139,113,167,100,122,171,99,63,105,208,46,220,28,89,201,250,214,195,30,209,200,92,86, + 185,254,242,192,69,144,51,44,21,221,207,25,148,10,239,71,12,50,133,213,163,31,57, + 200,18,214,141,158,229,168,75,62,183,80,118,188,38,241,218,196,91,19,123,77,227,117, + 137,231,38,202,154,215,43,30,159,72,104,54,174,150,252,110,193,236,80,77,252,53,129, + 215,32,94,152,56,106,146,175,45,188,29,177,201,180,86,247,126,198,160,82,248,61,130, + 145,161,172,120,125,226,161,137,184,102,242,170,197,191,19,48,13,212,5,159,67,40,49, + 222,148,88,111,122,172,35,61,217,209,154,220,107,25,239,74,204,55,21,214,143,30,228, + 8,75,70,183,114,246,165,134,251,34,195,89,145,250,236,67,13,241,197,132,83,35,125, + 217,225,154,200,107,22,175,78,252,52,65,215,112,94,164,56,123,82,163,125,185,225,178, + 200,117,150,167,46,250,156,67,41,241,222,196,88,83,122,189,227,49,137,212,102,223,106, + 216,47,26,156,11,41,199,94,210,184,93,178,185,181,178,247,53,134,151,34,238,153,140, + 106,229,239,11,12,7,69,194,179,17,181,204,119,21,230,143,10,228,7,11,66,135,113, + 162,164,121,187,98,243,105,133,238,227,12,73,197,246,211,6,221,194,217,145,154,236,107, + 13,239,69,140,51,37,213,219,31,27,72,11,118,135,102,226,170,201,191,22,240,14,196, + 4,83,67,125,241,225,132,72,99,118,169,230,254,202,192,87,16,62,140,16,101,204,43, + 21,223,79,24,52,10,151,71,46,178,156,117,169,231,62,202,144,87,44,62,157,208,105, + 156,46,233,220,78,217,244,90,199,123,18,163,77,185,245,178,199,53,146,151,45,174,157, + 188,105,177,238,244,76,71,117,242,167,5,186,131,51,33,213,216,95,26,184,11,50,135, + 85,162,191,57,176,18,244,13,135,69,162,179,57,181,210,247,29,134,137,162,230,249,138, + 194,231,17,138,140,103,37,234,155,15,43,68,31,115,72,37,246,155,6,235,66,207,113, + 148,36,111,91,108,59,109,211,109,157,237,169,141,190,229,176,75,52,55,87,86,190,190, + 240,112,68,36,51,91,85,251,127,3,96,1,232,0,78,128,52,96,23,104,14,174,132, + 124,99,97,233,232,78,206,180,84,119,127,102,160,42,248,31,2,136,1,166,128,122,224, + 35,8,25,198,138,210,231,29,138,137,167,38,250,154,195,43,17,223,76,88,53,250,151, + 3,46,129,220,96,89,232,58,206,147,20,109,207,109,148,45,175,93,188,57,177,210,244, + 93,135,121,162,162,249,185,130,242,225,133,136,99,38,169,218,254,219,0,91,64,59,112, + 19,100,13,235,69,143,115,36,37,219,91,27,123,75,99,119,105,230,174,202,252,87,1, + 254,128,64,96,48,40,20,30,143,72,100,54,171,86,255,126,192,32,80,24,60,10,145, + 199,44,82,157,253,169,129,190,224,112,72,36,54,155,86,235,126,207,96,84,40,63,94, + 144,56,108,18,173,205,189,149,177,175,52,124,23,97,206,168,84,126,191,96,112,40,36, + 30,155,72,107,118,175,102,252,42,193,223,16,88,12,58,133,211,35,29,217,201,154,214, + 235,30,207,72,84,54,191,86,240,62,196,16,83,76,61,245,209,135,28,98,137,233,166, + 206,250,212,67,31,113,200,36,86,155,126,235,96,79,104,52,46,151,92,110,185,236,114, + 205,229,149,139,47,39,92,26,185,203,50,215,85,158,191,40,112,30,164,8,123,70,163, + 114,249,229,130,203,33,151,88,110,186,172,115,61,229,209,139,28,103,73,234,182,207,54, + 212,22,223,78,216,52,90,151,123,46,163,92,121,249,226,194,201,145,150,236,110,205,236, + 85,141,255,37,128,27,32,11,88,7,122,130,163,33,185,216,114,218,165,155,59,43,83, + 95,125,248,33,130,152,97,170,168,127,62,160,16,120,12,34,133,217,163,26,249,203,2, + 215,65,158,176,104,116,46,167,92,122,185,227,50,201,213,150,223,46,216,28,90,137,251, + 38,195,90,209,251,28,67,73,241,246,196,70,211,114,221,229,153, +}; + +#ifdef PROTOTYPES + +# if !defined WORDS_BIGENDIAN +/* little endian */ +static const uint32_t yellowbook_scrambler_uint32[2340/4] = { + 0x60008001UL,0x1E002800UL,0x06600880UL,0x81FE02A8UL,0x28606080UL, + 0x889E1E28UL,0xAAAE6668UL,0xE0017FFCUL,0x36004800UL,0x0EE01680UL, + 0x835604C8UL,0x48E0E17EUL,0x96B63648UL,0xCCC6EEF6UL,0x9FFDD552UL, + 0x7E00A801UL,0x18602080UL,0x879E0A28UL,0xA99E6228UL,0xA0FE7EA8UL, + 0x22307840UL,0x4AAF1994UL,0xD60137FCUL,0x38E05E80UL,0x8DB61248UL, + 0xCBB6E5B6UL,0xDE56D736UL,0x5A70D8BEUL,0x533B3BA4UL,0xE1FD7D53UL, + 0x66608881UL,0x9FFE2AA8UL,0x2E006800UL,0x09601C80UL,0x82CE06E8UL, + 0x689F61D4UL,0x9CAE2E68UL,0xEEE1697CUL,0xB5564CC8UL,0x4600F7FEUL, + 0x15E03280UL,0x84260F88UL,0x094BE31AUL,0xB2C646F7UL,0x879DF5D2UL, + 0xF99EA229UL,0xB1FE42A8UL,0x27607480UL,0x8BAE1A68UL,0xEA51673CUL, + 0xF4314FBCUL,0x724F4714UL,0x5BB725B4UL,0xF356BB36UL,0x53E0C57EUL, + 0x91C63D08UL,0x8D6DEC92UL,0xBB8DA5EDUL,0x355BB325UL,0x7E0357FBUL, + 0x4860E081UL,0x969E3628UL,0xACCE6EE8UL,0x61FF7D54UL,0x1E602880UL, + 0x867E08A8UL,0x29F862A0UL,0xA8E19E82UL,0xA0B67E48UL,0xC226F876UL, + 0x1CABD19AUL,0x36E0497FUL,0x8ED616C8UL,0x4B58E4DEUL,0x3663B77AUL, + 0xDEFED6A9UL,0x3A5058C0UL,0xCD3113BCUL,0x7F9F55D4UL,0x981E2028UL, + 0xAF866A08UL,0x8119FC22UL,0x0857E0CAUL,0x6290863EUL,0xDE8D29ECUL, + 0x2A4B98E5UL,0xB8365FB7UL,0xC58EF216UL,0x7D3B53A4UL,0xE89D61D3UL, + 0xE4AE8E69UL,0xF7614B7CUL,0xB2AE4668UL,0xE78175FCUL,0x37984A20UL, + 0x2E9F962AUL,0x894E1CE8UL,0x6AC766F4UL,0xBC1DAFD2UL,0xF4C6B109UL, + 0x927DC752UL,0x7DB8ADA1UL,0xB8B5A1B2UL,0x95A63277UL,0x0C33EFBAUL, + 0x13CFC515UL,0x45CF0D14UL,0x552F3394UL,0xD0193FDCUL,0x1907DC0AUL, + 0xA7D18AC2UL,0xE3897A1CUL,0xD6DAC926UL,0x48DB1EDBUL,0x66BB765BUL, + 0xEFC56AF3UL,0xC50D0C13UL,0x2D1393C5UL,0x9995DDCDUL,0x1FFC2AAFUL, + 0x5600C801UL,0x10E03E80UL,0x85360C48UL,0xC91EE3D6UL,0xBED656C8UL, + 0x4458F0DEUL,0x3553B33AUL,0x9E01D7FDUL,0x2E606880UL,0x897E1CA8UL, + 0x2AC866E0UL,0xE81E9FD6UL,0xB4864E08UL,0x8669F762UL,0x49FCE2AEUL, + 0x46E0F681UL,0x95D632C8UL,0x4C28EF9EUL,0x77C8B51EUL,0xFA8EA616UL, + 0x710B43E4UL,0xAB5264C7UL,0xB061BF7DUL,0xA71E7428UL,0xA3B67A48UL, + 0xC2D6F936UL,0x5C98D1DEUL,0x32EFB96AUL,0xCF9515CCUL,0x0F1C142FUL, + 0xD336C449UL,0xD9FEDD56UL,0x3BE05A80UL,0x8D461308UL,0x8B85E5F2UL, + 0xDA592723UL,0x1B33DBBAUL,0x177FCB55UL,0x04A80E60UL,0x6160837EUL, + 0x9E4E28E8UL,0x6E7768B4UL,0xFD7AACA6UL,0xC08901E3UL,0xDC2AD066UL, + 0x0AC8191FUL,0xE21E87D6UL,0xB6A64988UL,0x06C3F6FAUL,0x51DCC2D1UL, + 0xC16AFC99UL,0x0C4C10EFUL,0x13D7C535UL,0x65C88D1EUL,0xFF2EAB96UL, + 0xF039405CUL,0x930DC412UL,0x3DF3AD45UL,0x1CA3D185UL,0xD6E2C979UL, + 0xE8D69EC9UL,0x54B8CE5EUL,0xB065BF72UL,0x571F342BUL,0x90B63E48UL, + 0xCD26EC76UL,0x1F9BD5DAUL,0x761F482BUL,0x9AE62688UL,0x0F17EBCAUL, + 0x6334844EUL,0xAEFE6957UL,0x21507CC0UL,0xCA4118FCUL,0x3E3457B0UL, + 0xBC6E5097UL,0xE4DD712CUL,0xE77A8B59UL,0xC7A90A63UL,0x5D90D23EUL, + 0xD2BD39ACUL,0x69849DF1UL,0xECF96EA3UL,0x95F1CD42UL,0x6C236F84UL, + 0xCDCAED19UL,0x8FAE1597UL,0xEB11643CUL,0xF4754F4CUL,0x825A0727UL, + 0x58B321BBUL,0x03A7FA75UL,0x20D3813AUL,0x9A39D85DUL,0x8F2DEB92UL, + 0xBB39A45DUL,0x857DF352UL,0x7908A3E1UL,0xF9D2A2C6UL,0xA1E9829DUL, + 0x4264F88EUL,0x64BF71ABUL,0x1F642B70UL,0x762F486BUL,0xDAE9269CUL, + 0x5B14DBCEUL,0x23747B4FUL,0xBAEA5967UL,0x151433CFUL,0x34144FCFUL, + 0x3E44570FUL,0xFC7550B3UL,0x80DA0127UL,0x583B205BUL,0xE38D7A13UL, + 0x26DB8925UL,0x7BDB5ADBUL,0x694B631BUL,0xACC66EF7UL,0x81FDFD52UL, + 0x7860A081UL,0x999E2228UL,0xAFFE6AA8UL,0x21007C00UL,0x0A5018C0UL, + 0xC23107BCUL,0x7CAF5194UL,0xD8E1217CUL,0xBBB65A48UL,0xC556F336UL, + 0x5D00D3FEUL,0x129039C0UL,0xC58D0DECUL,0x2D3B93A5UL,0xF99D5DD3UL, + 0xE1FE82A9UL,0x36604880UL,0x8EFE16A8UL,0x2B5064C0UL,0xC8611F7CUL, + 0xBE9E5628UL,0xA44E70E8UL,0x63577B34UL,0x7EE0A97EUL,0x985620C8UL, + 0x4F90EA3EUL,0xD71D342CUL,0xE8B69E49UL,0xD4A6CE76UL,0x1863DF7AUL, + 0xD79ECA29UL,0xB89E5E28UL,0xA5AE7268UL,0xE3317BBCUL,0x76FF4954UL, + 0x1AD026C0UL,0xC7190BDCUL,0x1DB7D24AUL,0xE6B689B6UL,0xD7C6CAF6UL, + 0x988DDE12UL,0x3FABAA65UL,0x3C10503FUL,0xCCC5110CUL,0xCFFD1553UL, + 0x6F009401UL,0x1D302C40UL,0x469F09D4UL,0x95CE32E8UL,0x6C2F6F94UL, + 0xDDC92D1CUL,0xDAAED996UL,0xFB015BFCUL,0x31704340UL,0x4F4B14E4UL, + 0xA7267477UL,0x03BBFA5AUL,0xF0D54133UL,0x0338045FUL,0xA0FD8152UL, + 0x7230B841UL,0x5BAF2594UL,0xD3513B3CUL,0xF9E15D7CUL,0xB1E64288UL, + 0x0767F48AUL,0x21AF826AUL,0xCA7118BCUL,0x7E3B57A4UL,0xE86D6093UL, + 0xA49D8E2DUL,0xF36EBB69UL,0xF3ED456CUL,0xA3C5850DUL,0xD2CD3913UL, + 0x299F9DD5UL,0x88FE1EA8UL,0x2AB06640UL,0x48071FF4UL,0xB681B602UL, + 0x26C876E0UL,0xEBDE9AD6UL,0xB44A4F18UL,0x96563737UL,0x4CF0EEBEUL, + 0x57F33544UL,0x0083FE05UL,0x5028C061UL,0x7108BC1EUL,0xFB52A4C6UL, + 0xA161837DUL,0xA24E78E8UL,0x62B779B4UL,0xFE86A9F6UL,0x9049C0E2UL, + 0xCD16EC36UL,0x5F94D5CEUL,0x221C782FUL,0xDAA6D989UL,0x1B03DBFAUL, + 0x5770CB41UL,0x50AB3E64UL,0x21207C7FUL,0x8A5A18D8UL,0x5A3327BBUL, + 0x032FFB95UL,0xC0F9015CUL,0x9C31D042UL,0x6ECF6914UL,0x5D5F2CD4UL, + 0x928239F8UL,0x7D88ADE1UL,0xF8BAA1A6UL,0xC1A50273UL,0x4C7310BBUL, + 0x07DBF525UL,0x718B421BUL,0xAB7A64A7UL,0xD0693F63UL,0x591CDC2EUL, + 0xC3D6FAC9UL,0x5CC8D11EUL,0xF2FEB956UL,0x339045C0UL,0xCFDD152CUL, + 0xEF0A9419UL,0x85320C47UL,0x391FA3D5UL,0x8DD612C8UL,0x4BA8E59EUL, + 0x7650B73EUL,0xDAF126BCUL,0x7B135BC4UL,0x8975E34DUL,0x9ACA26E7UL, + 0x9F1E2BD7UL,0xAE366848UL,0xC16EFC96UL,0xFC4D50ECUL,0x20D78135UL, + 0x6A38985EUL,0xBC2DAF92UL,0xB4C9B11DUL,0xC67EF756UL,0x3DF852A0UL, + 0xACA19182UL,0xA1E27D78UL,0xF266B889UL,0x13BFC5AAUL,0x05D40D30UL, + 0x3128439FUL,0x6F5894DEUL,0x3D23AC7AUL,0xDC9AD1D9UL,0x4AEF196BUL, + 0xD61537CCUL,0x08E41E8FUL,0x72B7464BUL,0xFB86A5F6UL,0x9159C322UL, + 0x0D43ECFAUL,0x5384C5F1UL,0xE1D97D23UL,0x166BC89AUL,0x34FC4EAFUL, + 0x5E70D741UL,0x527B38A4UL,0xE1B97DA3UL,0x9675C8B2UL,0x9CFA2EA7UL, + 0xDEF12943UL,0x7A5358C4UL,0x8931E3BDUL,0x6ADF66D4UL,0x9C1A2FD8UL, + 0x5EC7290BUL,0xB25DB8D2UL,0xF7B2B5B9UL,0x22978635UL,0x6A8C99EEUL, + 0x0C0BEFE5UL,0xB3C24507UL,0x77CCB511UL,0x0A8FE615UL,0x420B07E4UL, + 0xA4A27187UL,0xF362BB79UL,0xE3EE8569UL,0xF6C5490CUL,0xC2DD06D3UL, + 0xEC9A91D9UL,0x45EF0D6BUL,0xD525338CUL,0x481B1FDBUL,0x6687760BUL, + 0xBFC9AAE2UL,0xC40EF016UL,0x7D435304UL,0x4884E1F1UL,0xE6A97663UL, + 0x57C0CAFEUL,0x108C3E10UL,0x152BCC65UL,0x34184FDFUL,0x2E47970AUL, + 0xA9759CB2UL,0x90CA3EE7UL,0x9D3E2C57UL,0x2E9C69D0UL,0xD94EDCE9UL, + 0x7BC75AF4UL,0xB94DA312UL,0x35C7B2F5UL,0xAE2D9792UL,0xB169BC9DUL, + 0x474CF4EEUL,0x05A7F275UL,0x213383BAUL,0x1A5FD8D5UL,0x87320BB8UL, + 0x39BFA255UL,0x0DF412B0UL,0xB3A24587UL,0xF7D2B539UL,0xA289861DUL, + 0xC28AF9E6UL,0x8C8A11E7UL,0x9BEA2567UL,0x1F442B0FUL,0xF6254873UL, + 0x42EB069BUL,0x249471CFUL,0x3B6C5B6FUL,0x9D6DD36DUL,0xBE8DA9EDUL, + 0x344BB0E5UL,0xBE565737UL,0x4470F0BEUL,0x555B3324UL,0x60037FFBUL, + 0x4E00E801UL,0x17603480UL,0x84AE0E68UL,0xE961637CUL,0xB4CE4EE8UL, + 0x667F7754UL,0x1FF82AA0UL,0xA6018802UL,0x23E07A80UL,0x8AC61908UL, + 0x8A1DE7D2UL,0xFA26A789UL,0x112BC39AUL,0x35584CDFUL,0x2E0397FAUL, + 0x5960DC81UL,0x93CE3AE8UL,0x6DCF6D14UL,0x5DAF2D94UL,0xD2B139BCUL, + 0x79875DF4UL,0xB9F9A2A2UL,0x85E1F282UL,0xA9266388UL,0x00DBFEDAUL, + 0x703B405BUL,0xEB0D6413UL,0x24738F45UL,0x1B5BDB25UL,0x77634B7BUL, + 0xCAAEE669UL,0xFE0157FCUL,0x30604080UL,0x8F1E1428UL,0xAB366448UL, + 0xC07EFF56UL,0x3C185020UL,0x2CC7910AUL,0xA9FD9D52UL,0x70E0BE81UL, + 0x9B362448UL,0xCF7EEB56UL,0x3F285460UL,0x6C38905EUL,0xBDCDAD12UL, + 0x34AFB195UL,0xCE61177CUL,0xBF7E54A8UL,0x24287060UL,0x6B489B1EUL, + 0xFC66AF76UL,0x10DFC12AUL,0x853A0C58UL,0xD91D23D3UL,0xEBD69AC9UL, + 0x5448CF1EUL,0xF056BF36UL,0x5310C43EUL,0xD1F53D4CUL,0x89621C87UL, + 0xFACEA6E9UL,0x711F43D4UL,0x9B5624C8UL,0x4F60EB7EUL,0x972E3468UL, + 0xECB96E5CUL,0x95E5CD72UL,0x5C272F8BUL,0x32CBB91AUL,0xBF9E55D7UL, + 0xA41E7028UL,0xA3467B08UL,0x82E5F972UL,0x589721CBUL,0x73ACBA6EUL, + 0x8BD1E53DUL,0xEA49671CUL,0xD436CFB6UL,0xD84EDF16UL,0x7B975A34UL, + 0x795CA32EUL,0xC9C2E2F9UL,0x6EEC9691UL,0x8D55ECCDUL,0x1B8025FFUL, + 0x07580B20UL,0x21A3827AUL,0xDA72D8B9UL,0x2B3B9BA5UL,0xF87D5F53UL, + 0x61988221UL,0x3E7FA8AAUL,0x0C7810A0UL,0xA3D98522UL,0x02CBF91AUL, + 0xB09E41D7UL,0xA72E7468UL,0xE3B97A5CUL,0x96D5C932UL,0x1CD82EDFUL, + 0x26FB895AUL,0xFBD15AC3UL,0xF149431CUL,0xD346C4F6UL,0x99E5DD72UL, + +}; +# endif +# if defined WORDS_BIGENDIAN +/* big endian */ +static const uint32_t yellowbook_scrambler_uint32[2340/4] = { + 0x01800060UL,0x0028001EUL,0x80086006UL,0xA802FE81UL,0x80606028UL, + 0x281E9E88UL,0x6866AEAAUL,0xFC7F01E0UL,0x00480036UL,0x8016E00EUL, + 0xC8045683UL,0x7EE1E048UL,0x4836B696UL,0xF6EEC6CCUL,0x52D5FD9FUL, + 0x01A8007EUL,0x80206018UL,0x280A9E87UL,0x28629EA9UL,0xA87EFEA0UL, + 0x40783022UL,0x9419AF4AUL,0xFC3701D6UL,0x805EE038UL,0x4812B68DUL, + 0xB6E5B6CBUL,0x36D756DEUL,0xBED8705AUL,0xA43B3B53UL,0x537DFDE1UL, + 0x81886066UL,0xA82AFE9FUL,0x0068002EUL,0x801C6009UL,0xE806CE82UL, + 0xD4619F68UL,0x682EAE9CUL,0x7C69E1EEUL,0xC84C56B5UL,0xFEF70046UL, + 0x8032E015UL,0x880F2684UL,0x1AE34B09UL,0xF746C6B2UL,0xD2F59D87UL, + 0x29A29EF9UL,0xA842FEB1UL,0x80746027UL,0x681AAE8BUL,0x3C6751EAUL, + 0xBC4F31F4UL,0x14474F72UL,0xB425B75BUL,0x36BB56F3UL,0x7EC5E053UL, + 0x083DC691UL,0x92EC6D8DUL,0xEDA58DBBUL,0x25B35B35UL,0xFB57037EUL, + 0x81E06048UL,0x28369E96UL,0xE86ECEACUL,0x547DFF61UL,0x8028601EUL, + 0xA8087E86UL,0xA062F829UL,0x829EE1A8UL,0x487EB6A0UL,0x76F826C2UL, + 0x9AD1AB1CUL,0x7F49E036UL,0xC816D68EUL,0xDEE4584BUL,0x7AB76336UL, + 0xA9D6FEDEUL,0xC058503AUL,0xBC1331CDUL,0xD4559F7FUL,0x28201E98UL, + 0x086A86AFUL,0x22FC1981UL,0xCAE05708UL,0x3E869062UL,0xEC298DDEUL, + 0xE5984B2AUL,0xB75F36B8UL,0x16F28EC5UL,0xA4533B7DUL,0xD3619DE8UL, + 0x698EAEE4UL,0x7C4B61F7UL,0x6846AEB2UL,0xFC7581E7UL,0x204A9837UL, + 0x2A969F2EUL,0xE81C4E89UL,0xF466C76AUL,0xD2AF1DBCUL,0x09B1C6F4UL, + 0x52C77D92UL,0xA1ADB87DUL,0xB2A1B5B8UL,0x7732A695UL,0xBAEF330CUL, + 0x15C5CF13UL,0x140DCF45UL,0x94332F55UL,0xDC3F19D0UL,0x0ADC0719UL, + 0xC28AD1A7UL,0x1C7A89E3UL,0x26C9DAD6UL,0xDB1EDB48UL,0x5B76BB66UL, + 0xF36AC5EFUL,0x130C0DC5UL,0xC593132DUL,0xCDDD9599UL,0xAF2AFC1FUL, + 0x01C80056UL,0x803EE010UL,0x480C3685UL,0xD6E31EC9UL,0xC856D6BEUL, + 0xDEF05844UL,0x3AB35335UL,0xFDD7019EUL,0x8068602EUL,0xA81C7E89UL, + 0xE066C82AUL,0xD69F1EE8UL,0x084E86B4UL,0x62F76986UL,0xAEE2FC49UL, + 0x81F6E046UL,0xC832D695UL,0x9EEF284CUL,0x1EB5C877UL,0x16A68EFAUL, + 0xE4430B71UL,0xC76452ABUL,0x7DBF61B0UL,0x28741EA7UL,0x487AB6A3UL, + 0x36F9D6C2UL,0xDED1985CUL,0x6AB9EF32UL,0xCC1595CFUL,0x2F141C0FUL, + 0x49C436D3UL,0x56DDFED9UL,0x805AE03BUL,0x0813468DUL,0xF2E5858BUL, + 0x232759DAUL,0xBADB331BUL,0x55CB7F17UL,0x600EA804UL,0x7E836061UL, + 0xE8284E9EUL,0xB468776EUL,0xA6AC7AFDUL,0xE30189C0UL,0x66D02ADCUL, + 0x1F19C80AUL,0xD6871EE2UL,0x8849A6B6UL,0xFAF6C306UL,0xD1C2DC51UL, + 0x99FC6AC1UL,0xEF104C0CUL,0x35C5D713UL,0x1E8DC865UL,0x96AB2EFFUL, + 0x5C4039F0UL,0x12C40D93UL,0x45ADF33DUL,0x85D1A31CUL,0x79C9E2D6UL, + 0xC99ED6E8UL,0x5ECEB854UL,0x72BF65B0UL,0x2B341F57UL,0x483EB690UL, + 0x76EC26CDUL,0xDAD59B1FUL,0x2B481F76UL,0x8826E69AUL,0xCAEB170FUL, + 0x4E843463UL,0x5769FEAEUL,0xC07C5021UL,0xFC1841CAUL,0xB057343EUL, + 0x97506EBCUL,0x2C71DDE4UL,0x598B7AE7UL,0x630AA9C7UL,0x3ED2905DUL, + 0xAC39BDD2UL,0xF19D8469UL,0xA36EF9ECUL,0x42CDF195UL,0x846F236CUL, + 0x19EDCACDUL,0x9715AE8FUL,0x3C6411EBUL,0x4C4F75F4UL,0x27075A82UL, + 0xBB21B358UL,0x75FAA703UL,0x3A81D320UL,0x5DD8399AUL,0x92EB2D8FUL, + 0x5DA439BBUL,0x52F37D85UL,0xE1A30879UL,0xC6A2D2F9UL,0x9D82E9A1UL, + 0x8EF86442UL,0xAB71BF64UL,0x702B641FUL,0x6B482F76UL,0x9C26E9DAUL, + 0xCEDB145BUL,0x4F7B7423UL,0x6759EABAUL,0xCF331415UL,0xCF4F1434UL, + 0x0F57443EUL,0xB35075FCUL,0x2701DA80UL,0x5B203B58UL,0x137A8DE3UL, + 0x2589DB26UL,0xDB5ADB7BUL,0x1B634B69UL,0xF76EC6ACUL,0x52FDFD81UL, + 0x81A06078UL,0x28229E99UL,0xA86AFEAFUL,0x007C0021UL,0xC018500AUL, + 0xBC0731C2UL,0x9451AF7CUL,0x7C21E1D8UL,0x485AB6BBUL,0x36F356C5UL, + 0xFED3005DUL,0xC0399012UL,0xEC0D8DC5UL,0xA5933B2DUL,0xD35D9DF9UL, + 0xA982FEE1UL,0x80486036UL,0xA816FE8EUL,0xC064502BUL,0x7C1F61C8UL, + 0x28569EBEUL,0xE8704EA4UL,0x347B5763UL,0x7EA9E07EUL,0xC8205698UL, + 0x3EEA904FUL,0x2C341DD7UL,0x499EB6E8UL,0x76CEA6D4UL,0x7ADF6318UL, + 0x29CA9ED7UL,0x285E9EB8UL,0x6872AEA5UL,0xBC7B31E3UL,0x5449FF76UL, + 0xC026D01AUL,0xDC0B19C7UL,0x4AD2B71DUL,0xB689B6E6UL,0xF6CAC6D7UL, + 0x12DE8D98UL,0x65AAAB3FUL,0x3F50103CUL,0x0C11C5CCUL,0x5315FDCFUL, + 0x0194006FUL,0x402C301DUL,0xD4099F46UL,0xE832CE95UL,0x946F2F6CUL, + 0x1C2DC9DDUL,0x96D9AEDAUL,0xFC5B01FBUL,0x40437031UL,0xE4144B4FUL, + 0x777426A7UL,0x5AFABB03UL,0x3341D5F0UL,0x5F043803UL,0x5281FDA0UL, + 0x41B83072UL,0x9425AF5BUL,0x3C3B51D3UL,0x7C5DE1F9UL,0x8842E6B1UL, + 0x8AF46707UL,0x6A82AF21UL,0xBC1871CAUL,0xA4573B7EUL,0x93606DE8UL, + 0x2D8E9DA4UL,0x69BB6EF3UL,0x6C45EDF3UL,0x0D85C5A3UL,0x1339CDD2UL, + 0xD59D9F29UL,0xA81EFE88UL,0x4066B02AUL,0xF41F0748UL,0x02B681B6UL, + 0xE076C826UL,0xD69ADEEBUL,0x184F4AB4UL,0x37375696UL,0xBEEEF04CUL, + 0x4435F357UL,0x05FE8300UL,0x61C02850UL,0x1EBC0871UL,0xC6A452FBUL, + 0x7D8361A1UL,0xE8784EA2UL,0xB479B762UL,0xF6A986FEUL,0xE2C04990UL, + 0x36EC16CDUL,0xCED5945FUL,0x2F781C22UL,0x89D9A6DAUL,0xFADB031BUL, + 0x41CB7057UL,0x643EAB50UL,0x7F7C2021UL,0xD8185A8AUL,0xBB27335AUL, + 0x95FB2F03UL,0x5C01F9C0UL,0x42D0319CUL,0x1469CF6EUL,0xD42C5F5DUL, + 0xF8398292UL,0xE1AD887DUL,0xA6A1BAF8UL,0x7302A5C1UL,0xBB10734CUL, + 0x25F5DB07UL,0x1B428B71UL,0xA7647AABUL,0x633F69D0UL,0x2EDC1C59UL, + 0xC9FAD6C3UL,0x1ED1C85CUL,0x56B9FEF2UL,0xC0459033UL,0x2C15DDCFUL, + 0x19940AEFUL,0x470C3285UL,0xD5A31F39UL,0xC812D68DUL,0x9EE5A84BUL, + 0x3EB75076UL,0xBC26F1DAUL,0xC45B137BUL,0x4DE37589UL,0xE726CA9AUL, + 0xD72B1E9FUL,0x486836AEUL,0x96FC6EC1UL,0xEC504DFCUL,0x3581D720UL, + 0x5E98386AUL,0x92AF2DBCUL,0x1DB1C9B4UL,0x56F77EC6UL,0xA052F83DUL, + 0x8291A1ACUL,0x787DE2A1UL,0x89B866F2UL,0xAAC5BF13UL,0x300DD405UL, + 0x9F432831UL,0xDE94586FUL,0x7AAC233DUL,0xD9D19ADCUL,0x6B19EF4AUL, + 0xCC3715D6UL,0x8F1EE408UL,0x4B46B772UL,0xF6A586FBUL,0x22C35991UL, + 0xFAEC430DUL,0xF1C58453UL,0x237DD9E1UL,0x9AC86B16UL,0xAF4EFC34UL, + 0x41D7705EUL,0xA4387B52UL,0xA37DB9E1UL,0xB2C87596UL,0xA72EFA9CUL, + 0x4329F1DEUL,0xC458537AUL,0xBDE33189UL,0xD466DF6AUL,0xD82F1A9CUL, + 0x0B29C75EUL,0xD2B85DB2UL,0xB9B5B2F7UL,0x35869722UL,0xEE998C6AUL, + 0xE5EF0B0CUL,0x0745C2B3UL,0x11B5CC77UL,0x15E68F0AUL,0xE4070B42UL, + 0x8771A2A4UL,0x79BB62F3UL,0x6985EEE3UL,0x0C49C5F6UL,0xD306DDC2UL, + 0xD9919AECUL,0x6B0DEF45UL,0x8C3325D5UL,0xDB1F1B48UL,0x0B768766UL, + 0xE2AAC9BFUL,0x16F00EC4UL,0x0453437DUL,0xF1E18448UL,0x6376A9E6UL, + 0xFECAC057UL,0x103E8C10UL,0x65CC2B15UL,0xDF4F1834UL,0x0A97472EUL, + 0xB29C75A9UL,0xE73ECA90UL,0x572C3E9DUL,0xD0699C2EUL,0xE9DC4ED9UL, + 0xF45AC77BUL,0x12A34DB9UL,0xF5B2C735UL,0x92972DAEUL,0x9DBC69B1UL, + 0xEEF44C47UL,0x75F2A705UL,0xBA833321UL,0xD5D85F1AUL,0xB80B3287UL, + 0x55A2BF39UL,0xB012F40DUL,0x8745A2B3UL,0x39B5D2F7UL,0x1D8689A2UL, + 0xE6F98AC2UL,0xE7118A8CUL,0x6725EA9BUL,0x0F2B441FUL,0x734825F6UL, + 0x9B06EB42UL,0xCF719424UL,0x6F5B6C3BUL,0x6DD36D9DUL,0xEDA98DBEUL, + 0xE5B04B34UL,0x375756BEUL,0xBEF07044UL,0x24335B55UL,0xFB7F0360UL, + 0x01E8004EUL,0x80346017UL,0x680EAE84UL,0x7C6361E9UL,0xE84ECEB4UL, + 0x54777F66UL,0xA02AF81FUL,0x028801A6UL,0x807AE023UL,0x0819C68AUL, + 0xD2E71D8AUL,0x89A726FAUL,0x9AC32B11UL,0xDF4C5835UL,0xFA97032EUL, + 0x81DC6059UL,0xE83ACE93UL,0x146DCF6DUL,0x942DAF5DUL,0xBC39B1D2UL, + 0xF45D8779UL,0xA2A2F9B9UL,0x82F2E185UL,0x886326A9UL,0xDAFEDB00UL, + 0x5B403B70UL,0x13640DEBUL,0x458F7324UL,0x25DB5B1BUL,0x7B4B6377UL, + 0x69E6AECAUL,0xFC5701FEUL,0x80406030UL,0x28141E8FUL,0x486436ABUL, + 0x56FF7EC0UL,0x2050183CUL,0x0A91C72CUL,0x529DFDA9UL,0x81BEE070UL, + 0x4824369BUL,0x56EB7ECFUL,0x6054283FUL,0x5E90386CUL,0x12ADCDBDUL, + 0x95B1AF34UL,0x7C1761CEUL,0xA8547EBFUL,0x60702824UL,0x1E9B486BUL, + 0x76AF66FCUL,0x2AC1DF10UL,0x580C3A85UL,0xD3231DD9UL,0xC99AD6EBUL, + 0x1ECF4854UL,0x36BF56F0UL,0x3EC41053UL,0x4C3DF5D1UL,0x871C6289UL, + 0xE9A6CEFAUL,0xD4431F71UL,0xC824569BUL,0x7EEB604FUL,0x68342E97UL, + 0x5C6EB9ECUL,0x72CDE595UL,0x8B2F275CUL,0x1AB9CB32UL,0xD7559EBFUL, + 0x28701EA4UL,0x087B46A3UL,0x72F9E582UL,0xCB219758UL,0x6EBAAC73UL, + 0x3DE5D18BUL,0x1C6749EAUL,0xB6CF36D4UL,0x16DF4ED8UL,0x345A977BUL, + 0x2EA35C79UL,0xF9E2C2C9UL,0x9196EC6EUL,0xCDEC558DUL,0xFF25801BUL, + 0x200B5807UL,0x7A82A321UL,0xB9D872DAUL,0xA59B3B2BUL,0x535F7DF8UL, + 0x21829861UL,0xAAA87F3EUL,0xA010780CUL,0x2285D9A3UL,0x1AF9CB02UL, + 0xD7419EB0UL,0x68742EA7UL,0x5C7AB9E3UL,0x32C9D596UL,0xDF2ED81CUL, + 0x5A89FB26UL,0xC35AD1FBUL,0x1C4349F1UL,0xF6C446D3UL,0x72DDE599UL, + +}; +# endif + +#else /* PROTOTYPES */ + +# if !defined WORDS_BIGENDIAN +/* little endian */ +static const uint32_t yellowbook_scrambler_uint32[2340/4] = { + 0x60008001,0x1E002800,0x06600880,0x81FE02A8,0x28606080, + 0x889E1E28,0xAAAE6668,0xE0017FFC,0x36004800,0x0EE01680, + 0x835604C8,0x48E0E17E,0x96B63648,0xCCC6EEF6,0x9FFDD552, + 0x7E00A801,0x18602080,0x879E0A28,0xA99E6228,0xA0FE7EA8, + 0x22307840,0x4AAF1994,0xD60137FC,0x38E05E80,0x8DB61248, + 0xCBB6E5B6,0xDE56D736,0x5A70D8BE,0x533B3BA4,0xE1FD7D53, + 0x66608881,0x9FFE2AA8,0x2E006800,0x09601C80,0x82CE06E8, + 0x689F61D4,0x9CAE2E68,0xEEE1697C,0xB5564CC8,0x4600F7FE, + 0x15E03280,0x84260F88,0x094BE31A,0xB2C646F7,0x879DF5D2, + 0xF99EA229,0xB1FE42A8,0x27607480,0x8BAE1A68,0xEA51673C, + 0xF4314FBC,0x724F4714,0x5BB725B4,0xF356BB36,0x53E0C57E, + 0x91C63D08,0x8D6DEC92,0xBB8DA5ED,0x355BB325,0x7E0357FB, + 0x4860E081,0x969E3628,0xACCE6EE8,0x61FF7D54,0x1E602880, + 0x867E08A8,0x29F862A0,0xA8E19E82,0xA0B67E48,0xC226F876, + 0x1CABD19A,0x36E0497F,0x8ED616C8,0x4B58E4DE,0x3663B77A, + 0xDEFED6A9,0x3A5058C0,0xCD3113BC,0x7F9F55D4,0x981E2028, + 0xAF866A08,0x8119FC22,0x0857E0CA,0x6290863E,0xDE8D29EC, + 0x2A4B98E5,0xB8365FB7,0xC58EF216,0x7D3B53A4,0xE89D61D3, + 0xE4AE8E69,0xF7614B7C,0xB2AE4668,0xE78175FC,0x37984A20, + 0x2E9F962A,0x894E1CE8,0x6AC766F4,0xBC1DAFD2,0xF4C6B109, + 0x927DC752,0x7DB8ADA1,0xB8B5A1B2,0x95A63277,0x0C33EFBA, + 0x13CFC515,0x45CF0D14,0x552F3394,0xD0193FDC,0x1907DC0A, + 0xA7D18AC2,0xE3897A1C,0xD6DAC926,0x48DB1EDB,0x66BB765B, + 0xEFC56AF3,0xC50D0C13,0x2D1393C5,0x9995DDCD,0x1FFC2AAF, + 0x5600C801,0x10E03E80,0x85360C48,0xC91EE3D6,0xBED656C8, + 0x4458F0DE,0x3553B33A,0x9E01D7FD,0x2E606880,0x897E1CA8, + 0x2AC866E0,0xE81E9FD6,0xB4864E08,0x8669F762,0x49FCE2AE, + 0x46E0F681,0x95D632C8,0x4C28EF9E,0x77C8B51E,0xFA8EA616, + 0x710B43E4,0xAB5264C7,0xB061BF7D,0xA71E7428,0xA3B67A48, + 0xC2D6F936,0x5C98D1DE,0x32EFB96A,0xCF9515CC,0x0F1C142F, + 0xD336C449,0xD9FEDD56,0x3BE05A80,0x8D461308,0x8B85E5F2, + 0xDA592723,0x1B33DBBA,0x177FCB55,0x04A80E60,0x6160837E, + 0x9E4E28E8,0x6E7768B4,0xFD7AACA6,0xC08901E3,0xDC2AD066, + 0x0AC8191F,0xE21E87D6,0xB6A64988,0x06C3F6FA,0x51DCC2D1, + 0xC16AFC99,0x0C4C10EF,0x13D7C535,0x65C88D1E,0xFF2EAB96, + 0xF039405C,0x930DC412,0x3DF3AD45,0x1CA3D185,0xD6E2C979, + 0xE8D69EC9,0x54B8CE5E,0xB065BF72,0x571F342B,0x90B63E48, + 0xCD26EC76,0x1F9BD5DA,0x761F482B,0x9AE62688,0x0F17EBCA, + 0x6334844E,0xAEFE6957,0x21507CC0,0xCA4118FC,0x3E3457B0, + 0xBC6E5097,0xE4DD712C,0xE77A8B59,0xC7A90A63,0x5D90D23E, + 0xD2BD39AC,0x69849DF1,0xECF96EA3,0x95F1CD42,0x6C236F84, + 0xCDCAED19,0x8FAE1597,0xEB11643C,0xF4754F4C,0x825A0727, + 0x58B321BB,0x03A7FA75,0x20D3813A,0x9A39D85D,0x8F2DEB92, + 0xBB39A45D,0x857DF352,0x7908A3E1,0xF9D2A2C6,0xA1E9829D, + 0x4264F88E,0x64BF71AB,0x1F642B70,0x762F486B,0xDAE9269C, + 0x5B14DBCE,0x23747B4F,0xBAEA5967,0x151433CF,0x34144FCF, + 0x3E44570F,0xFC7550B3,0x80DA0127,0x583B205B,0xE38D7A13, + 0x26DB8925,0x7BDB5ADB,0x694B631B,0xACC66EF7,0x81FDFD52, + 0x7860A081,0x999E2228,0xAFFE6AA8,0x21007C00,0x0A5018C0, + 0xC23107BC,0x7CAF5194,0xD8E1217C,0xBBB65A48,0xC556F336, + 0x5D00D3FE,0x129039C0,0xC58D0DEC,0x2D3B93A5,0xF99D5DD3, + 0xE1FE82A9,0x36604880,0x8EFE16A8,0x2B5064C0,0xC8611F7C, + 0xBE9E5628,0xA44E70E8,0x63577B34,0x7EE0A97E,0x985620C8, + 0x4F90EA3E,0xD71D342C,0xE8B69E49,0xD4A6CE76,0x1863DF7A, + 0xD79ECA29,0xB89E5E28,0xA5AE7268,0xE3317BBC,0x76FF4954, + 0x1AD026C0,0xC7190BDC,0x1DB7D24A,0xE6B689B6,0xD7C6CAF6, + 0x988DDE12,0x3FABAA65,0x3C10503F,0xCCC5110C,0xCFFD1553, + 0x6F009401,0x1D302C40,0x469F09D4,0x95CE32E8,0x6C2F6F94, + 0xDDC92D1C,0xDAAED996,0xFB015BFC,0x31704340,0x4F4B14E4, + 0xA7267477,0x03BBFA5A,0xF0D54133,0x0338045F,0xA0FD8152, + 0x7230B841,0x5BAF2594,0xD3513B3C,0xF9E15D7C,0xB1E64288, + 0x0767F48A,0x21AF826A,0xCA7118BC,0x7E3B57A4,0xE86D6093, + 0xA49D8E2D,0xF36EBB69,0xF3ED456C,0xA3C5850D,0xD2CD3913, + 0x299F9DD5,0x88FE1EA8,0x2AB06640,0x48071FF4,0xB681B602, + 0x26C876E0,0xEBDE9AD6,0xB44A4F18,0x96563737,0x4CF0EEBE, + 0x57F33544,0x0083FE05,0x5028C061,0x7108BC1E,0xFB52A4C6, + 0xA161837D,0xA24E78E8,0x62B779B4,0xFE86A9F6,0x9049C0E2, + 0xCD16EC36,0x5F94D5CE,0x221C782F,0xDAA6D989,0x1B03DBFA, + 0x5770CB41,0x50AB3E64,0x21207C7F,0x8A5A18D8,0x5A3327BB, + 0x032FFB95,0xC0F9015C,0x9C31D042,0x6ECF6914,0x5D5F2CD4, + 0x928239F8,0x7D88ADE1,0xF8BAA1A6,0xC1A50273,0x4C7310BB, + 0x07DBF525,0x718B421B,0xAB7A64A7,0xD0693F63,0x591CDC2E, + 0xC3D6FAC9,0x5CC8D11E,0xF2FEB956,0x339045C0,0xCFDD152C, + 0xEF0A9419,0x85320C47,0x391FA3D5,0x8DD612C8,0x4BA8E59E, + 0x7650B73E,0xDAF126BC,0x7B135BC4,0x8975E34D,0x9ACA26E7, + 0x9F1E2BD7,0xAE366848,0xC16EFC96,0xFC4D50EC,0x20D78135, + 0x6A38985E,0xBC2DAF92,0xB4C9B11D,0xC67EF756,0x3DF852A0, + 0xACA19182,0xA1E27D78,0xF266B889,0x13BFC5AA,0x05D40D30, + 0x3128439F,0x6F5894DE,0x3D23AC7A,0xDC9AD1D9,0x4AEF196B, + 0xD61537CC,0x08E41E8F,0x72B7464B,0xFB86A5F6,0x9159C322, + 0x0D43ECFA,0x5384C5F1,0xE1D97D23,0x166BC89A,0x34FC4EAF, + 0x5E70D741,0x527B38A4,0xE1B97DA3,0x9675C8B2,0x9CFA2EA7, + 0xDEF12943,0x7A5358C4,0x8931E3BD,0x6ADF66D4,0x9C1A2FD8, + 0x5EC7290B,0xB25DB8D2,0xF7B2B5B9,0x22978635,0x6A8C99EE, + 0x0C0BEFE5,0xB3C24507,0x77CCB511,0x0A8FE615,0x420B07E4, + 0xA4A27187,0xF362BB79,0xE3EE8569,0xF6C5490C,0xC2DD06D3, + 0xEC9A91D9,0x45EF0D6B,0xD525338C,0x481B1FDB,0x6687760B, + 0xBFC9AAE2,0xC40EF016,0x7D435304,0x4884E1F1,0xE6A97663, + 0x57C0CAFE,0x108C3E10,0x152BCC65,0x34184FDF,0x2E47970A, + 0xA9759CB2,0x90CA3EE7,0x9D3E2C57,0x2E9C69D0,0xD94EDCE9, + 0x7BC75AF4,0xB94DA312,0x35C7B2F5,0xAE2D9792,0xB169BC9D, + 0x474CF4EE,0x05A7F275,0x213383BA,0x1A5FD8D5,0x87320BB8, + 0x39BFA255,0x0DF412B0,0xB3A24587,0xF7D2B539,0xA289861D, + 0xC28AF9E6,0x8C8A11E7,0x9BEA2567,0x1F442B0F,0xF6254873, + 0x42EB069B,0x249471CF,0x3B6C5B6F,0x9D6DD36D,0xBE8DA9ED, + 0x344BB0E5,0xBE565737,0x4470F0BE,0x555B3324,0x60037FFB, + 0x4E00E801,0x17603480,0x84AE0E68,0xE961637C,0xB4CE4EE8, + 0x667F7754,0x1FF82AA0,0xA6018802,0x23E07A80,0x8AC61908, + 0x8A1DE7D2,0xFA26A789,0x112BC39A,0x35584CDF,0x2E0397FA, + 0x5960DC81,0x93CE3AE8,0x6DCF6D14,0x5DAF2D94,0xD2B139BC, + 0x79875DF4,0xB9F9A2A2,0x85E1F282,0xA9266388,0x00DBFEDA, + 0x703B405B,0xEB0D6413,0x24738F45,0x1B5BDB25,0x77634B7B, + 0xCAAEE669,0xFE0157FC,0x30604080,0x8F1E1428,0xAB366448, + 0xC07EFF56,0x3C185020,0x2CC7910A,0xA9FD9D52,0x70E0BE81, + 0x9B362448,0xCF7EEB56,0x3F285460,0x6C38905E,0xBDCDAD12, + 0x34AFB195,0xCE61177C,0xBF7E54A8,0x24287060,0x6B489B1E, + 0xFC66AF76,0x10DFC12A,0x853A0C58,0xD91D23D3,0xEBD69AC9, + 0x5448CF1E,0xF056BF36,0x5310C43E,0xD1F53D4C,0x89621C87, + 0xFACEA6E9,0x711F43D4,0x9B5624C8,0x4F60EB7E,0x972E3468, + 0xECB96E5C,0x95E5CD72,0x5C272F8B,0x32CBB91A,0xBF9E55D7, + 0xA41E7028,0xA3467B08,0x82E5F972,0x589721CB,0x73ACBA6E, + 0x8BD1E53D,0xEA49671C,0xD436CFB6,0xD84EDF16,0x7B975A34, + 0x795CA32E,0xC9C2E2F9,0x6EEC9691,0x8D55ECCD,0x1B8025FF, + 0x07580B20,0x21A3827A,0xDA72D8B9,0x2B3B9BA5,0xF87D5F53, + 0x61988221,0x3E7FA8AA,0x0C7810A0,0xA3D98522,0x02CBF91A, + 0xB09E41D7,0xA72E7468,0xE3B97A5C,0x96D5C932,0x1CD82EDF, + 0x26FB895A,0xFBD15AC3,0xF149431C,0xD346C4F6,0x99E5DD72, + +}; +# endif +# if defined WORDS_BIGENDIAN +/* big endian */ +static const uint32_t yellowbook_scrambler_uint32[2340/4] = { + 0x01800060,0x0028001E,0x80086006,0xA802FE81,0x80606028, + 0x281E9E88,0x6866AEAA,0xFC7F01E0,0x00480036,0x8016E00E, + 0xC8045683,0x7EE1E048,0x4836B696,0xF6EEC6CC,0x52D5FD9F, + 0x01A8007E,0x80206018,0x280A9E87,0x28629EA9,0xA87EFEA0, + 0x40783022,0x9419AF4A,0xFC3701D6,0x805EE038,0x4812B68D, + 0xB6E5B6CB,0x36D756DE,0xBED8705A,0xA43B3B53,0x537DFDE1, + 0x81886066,0xA82AFE9F,0x0068002E,0x801C6009,0xE806CE82, + 0xD4619F68,0x682EAE9C,0x7C69E1EE,0xC84C56B5,0xFEF70046, + 0x8032E015,0x880F2684,0x1AE34B09,0xF746C6B2,0xD2F59D87, + 0x29A29EF9,0xA842FEB1,0x80746027,0x681AAE8B,0x3C6751EA, + 0xBC4F31F4,0x14474F72,0xB425B75B,0x36BB56F3,0x7EC5E053, + 0x083DC691,0x92EC6D8D,0xEDA58DBB,0x25B35B35,0xFB57037E, + 0x81E06048,0x28369E96,0xE86ECEAC,0x547DFF61,0x8028601E, + 0xA8087E86,0xA062F829,0x829EE1A8,0x487EB6A0,0x76F826C2, + 0x9AD1AB1C,0x7F49E036,0xC816D68E,0xDEE4584B,0x7AB76336, + 0xA9D6FEDE,0xC058503A,0xBC1331CD,0xD4559F7F,0x28201E98, + 0x086A86AF,0x22FC1981,0xCAE05708,0x3E869062,0xEC298DDE, + 0xE5984B2A,0xB75F36B8,0x16F28EC5,0xA4533B7D,0xD3619DE8, + 0x698EAEE4,0x7C4B61F7,0x6846AEB2,0xFC7581E7,0x204A9837, + 0x2A969F2E,0xE81C4E89,0xF466C76A,0xD2AF1DBC,0x09B1C6F4, + 0x52C77D92,0xA1ADB87D,0xB2A1B5B8,0x7732A695,0xBAEF330C, + 0x15C5CF13,0x140DCF45,0x94332F55,0xDC3F19D0,0x0ADC0719, + 0xC28AD1A7,0x1C7A89E3,0x26C9DAD6,0xDB1EDB48,0x5B76BB66, + 0xF36AC5EF,0x130C0DC5,0xC593132D,0xCDDD9599,0xAF2AFC1F, + 0x01C80056,0x803EE010,0x480C3685,0xD6E31EC9,0xC856D6BE, + 0xDEF05844,0x3AB35335,0xFDD7019E,0x8068602E,0xA81C7E89, + 0xE066C82A,0xD69F1EE8,0x084E86B4,0x62F76986,0xAEE2FC49, + 0x81F6E046,0xC832D695,0x9EEF284C,0x1EB5C877,0x16A68EFA, + 0xE4430B71,0xC76452AB,0x7DBF61B0,0x28741EA7,0x487AB6A3, + 0x36F9D6C2,0xDED1985C,0x6AB9EF32,0xCC1595CF,0x2F141C0F, + 0x49C436D3,0x56DDFED9,0x805AE03B,0x0813468D,0xF2E5858B, + 0x232759DA,0xBADB331B,0x55CB7F17,0x600EA804,0x7E836061, + 0xE8284E9E,0xB468776E,0xA6AC7AFD,0xE30189C0,0x66D02ADC, + 0x1F19C80A,0xD6871EE2,0x8849A6B6,0xFAF6C306,0xD1C2DC51, + 0x99FC6AC1,0xEF104C0C,0x35C5D713,0x1E8DC865,0x96AB2EFF, + 0x5C4039F0,0x12C40D93,0x45ADF33D,0x85D1A31C,0x79C9E2D6, + 0xC99ED6E8,0x5ECEB854,0x72BF65B0,0x2B341F57,0x483EB690, + 0x76EC26CD,0xDAD59B1F,0x2B481F76,0x8826E69A,0xCAEB170F, + 0x4E843463,0x5769FEAE,0xC07C5021,0xFC1841CA,0xB057343E, + 0x97506EBC,0x2C71DDE4,0x598B7AE7,0x630AA9C7,0x3ED2905D, + 0xAC39BDD2,0xF19D8469,0xA36EF9EC,0x42CDF195,0x846F236C, + 0x19EDCACD,0x9715AE8F,0x3C6411EB,0x4C4F75F4,0x27075A82, + 0xBB21B358,0x75FAA703,0x3A81D320,0x5DD8399A,0x92EB2D8F, + 0x5DA439BB,0x52F37D85,0xE1A30879,0xC6A2D2F9,0x9D82E9A1, + 0x8EF86442,0xAB71BF64,0x702B641F,0x6B482F76,0x9C26E9DA, + 0xCEDB145B,0x4F7B7423,0x6759EABA,0xCF331415,0xCF4F1434, + 0x0F57443E,0xB35075FC,0x2701DA80,0x5B203B58,0x137A8DE3, + 0x2589DB26,0xDB5ADB7B,0x1B634B69,0xF76EC6AC,0x52FDFD81, + 0x81A06078,0x28229E99,0xA86AFEAF,0x007C0021,0xC018500A, + 0xBC0731C2,0x9451AF7C,0x7C21E1D8,0x485AB6BB,0x36F356C5, + 0xFED3005D,0xC0399012,0xEC0D8DC5,0xA5933B2D,0xD35D9DF9, + 0xA982FEE1,0x80486036,0xA816FE8E,0xC064502B,0x7C1F61C8, + 0x28569EBE,0xE8704EA4,0x347B5763,0x7EA9E07E,0xC8205698, + 0x3EEA904F,0x2C341DD7,0x499EB6E8,0x76CEA6D4,0x7ADF6318, + 0x29CA9ED7,0x285E9EB8,0x6872AEA5,0xBC7B31E3,0x5449FF76, + 0xC026D01A,0xDC0B19C7,0x4AD2B71D,0xB689B6E6,0xF6CAC6D7, + 0x12DE8D98,0x65AAAB3F,0x3F50103C,0x0C11C5CC,0x5315FDCF, + 0x0194006F,0x402C301D,0xD4099F46,0xE832CE95,0x946F2F6C, + 0x1C2DC9DD,0x96D9AEDA,0xFC5B01FB,0x40437031,0xE4144B4F, + 0x777426A7,0x5AFABB03,0x3341D5F0,0x5F043803,0x5281FDA0, + 0x41B83072,0x9425AF5B,0x3C3B51D3,0x7C5DE1F9,0x8842E6B1, + 0x8AF46707,0x6A82AF21,0xBC1871CA,0xA4573B7E,0x93606DE8, + 0x2D8E9DA4,0x69BB6EF3,0x6C45EDF3,0x0D85C5A3,0x1339CDD2, + 0xD59D9F29,0xA81EFE88,0x4066B02A,0xF41F0748,0x02B681B6, + 0xE076C826,0xD69ADEEB,0x184F4AB4,0x37375696,0xBEEEF04C, + 0x4435F357,0x05FE8300,0x61C02850,0x1EBC0871,0xC6A452FB, + 0x7D8361A1,0xE8784EA2,0xB479B762,0xF6A986FE,0xE2C04990, + 0x36EC16CD,0xCED5945F,0x2F781C22,0x89D9A6DA,0xFADB031B, + 0x41CB7057,0x643EAB50,0x7F7C2021,0xD8185A8A,0xBB27335A, + 0x95FB2F03,0x5C01F9C0,0x42D0319C,0x1469CF6E,0xD42C5F5D, + 0xF8398292,0xE1AD887D,0xA6A1BAF8,0x7302A5C1,0xBB10734C, + 0x25F5DB07,0x1B428B71,0xA7647AAB,0x633F69D0,0x2EDC1C59, + 0xC9FAD6C3,0x1ED1C85C,0x56B9FEF2,0xC0459033,0x2C15DDCF, + 0x19940AEF,0x470C3285,0xD5A31F39,0xC812D68D,0x9EE5A84B, + 0x3EB75076,0xBC26F1DA,0xC45B137B,0x4DE37589,0xE726CA9A, + 0xD72B1E9F,0x486836AE,0x96FC6EC1,0xEC504DFC,0x3581D720, + 0x5E98386A,0x92AF2DBC,0x1DB1C9B4,0x56F77EC6,0xA052F83D, + 0x8291A1AC,0x787DE2A1,0x89B866F2,0xAAC5BF13,0x300DD405, + 0x9F432831,0xDE94586F,0x7AAC233D,0xD9D19ADC,0x6B19EF4A, + 0xCC3715D6,0x8F1EE408,0x4B46B772,0xF6A586FB,0x22C35991, + 0xFAEC430D,0xF1C58453,0x237DD9E1,0x9AC86B16,0xAF4EFC34, + 0x41D7705E,0xA4387B52,0xA37DB9E1,0xB2C87596,0xA72EFA9C, + 0x4329F1DE,0xC458537A,0xBDE33189,0xD466DF6A,0xD82F1A9C, + 0x0B29C75E,0xD2B85DB2,0xB9B5B2F7,0x35869722,0xEE998C6A, + 0xE5EF0B0C,0x0745C2B3,0x11B5CC77,0x15E68F0A,0xE4070B42, + 0x8771A2A4,0x79BB62F3,0x6985EEE3,0x0C49C5F6,0xD306DDC2, + 0xD9919AEC,0x6B0DEF45,0x8C3325D5,0xDB1F1B48,0x0B768766, + 0xE2AAC9BF,0x16F00EC4,0x0453437D,0xF1E18448,0x6376A9E6, + 0xFECAC057,0x103E8C10,0x65CC2B15,0xDF4F1834,0x0A97472E, + 0xB29C75A9,0xE73ECA90,0x572C3E9D,0xD0699C2E,0xE9DC4ED9, + 0xF45AC77B,0x12A34DB9,0xF5B2C735,0x92972DAE,0x9DBC69B1, + 0xEEF44C47,0x75F2A705,0xBA833321,0xD5D85F1A,0xB80B3287, + 0x55A2BF39,0xB012F40D,0x8745A2B3,0x39B5D2F7,0x1D8689A2, + 0xE6F98AC2,0xE7118A8C,0x6725EA9B,0x0F2B441F,0x734825F6, + 0x9B06EB42,0xCF719424,0x6F5B6C3B,0x6DD36D9D,0xEDA98DBE, + 0xE5B04B34,0x375756BE,0xBEF07044,0x24335B55,0xFB7F0360, + 0x01E8004E,0x80346017,0x680EAE84,0x7C6361E9,0xE84ECEB4, + 0x54777F66,0xA02AF81F,0x028801A6,0x807AE023,0x0819C68A, + 0xD2E71D8A,0x89A726FA,0x9AC32B11,0xDF4C5835,0xFA97032E, + 0x81DC6059,0xE83ACE93,0x146DCF6D,0x942DAF5D,0xBC39B1D2, + 0xF45D8779,0xA2A2F9B9,0x82F2E185,0x886326A9,0xDAFEDB00, + 0x5B403B70,0x13640DEB,0x458F7324,0x25DB5B1B,0x7B4B6377, + 0x69E6AECA,0xFC5701FE,0x80406030,0x28141E8F,0x486436AB, + 0x56FF7EC0,0x2050183C,0x0A91C72C,0x529DFDA9,0x81BEE070, + 0x4824369B,0x56EB7ECF,0x6054283F,0x5E90386C,0x12ADCDBD, + 0x95B1AF34,0x7C1761CE,0xA8547EBF,0x60702824,0x1E9B486B, + 0x76AF66FC,0x2AC1DF10,0x580C3A85,0xD3231DD9,0xC99AD6EB, + 0x1ECF4854,0x36BF56F0,0x3EC41053,0x4C3DF5D1,0x871C6289, + 0xE9A6CEFA,0xD4431F71,0xC824569B,0x7EEB604F,0x68342E97, + 0x5C6EB9EC,0x72CDE595,0x8B2F275C,0x1AB9CB32,0xD7559EBF, + 0x28701EA4,0x087B46A3,0x72F9E582,0xCB219758,0x6EBAAC73, + 0x3DE5D18B,0x1C6749EA,0xB6CF36D4,0x16DF4ED8,0x345A977B, + 0x2EA35C79,0xF9E2C2C9,0x9196EC6E,0xCDEC558D,0xFF25801B, + 0x200B5807,0x7A82A321,0xB9D872DA,0xA59B3B2B,0x535F7DF8, + 0x21829861,0xAAA87F3E,0xA010780C,0x2285D9A3,0x1AF9CB02, + 0xD7419EB0,0x68742EA7,0x5C7AB9E3,0x32C9D596,0xDF2ED81C, + 0x5A89FB26,0xC35AD1FB,0x1C4349F1,0xF6C446D3,0x72DDE599, + +}; +# endif + +#endif /* PROTOTYPES */ --- a/src/gdrom/gdi.c Tue Feb 26 01:10:48 2008 +0000 +++ b/src/gdrom/gdi.c Sun Mar 02 11:38:08 2008 +0000 @@ -114,8 +114,8 @@ /* Data track */ switch(size) { case 2048: image->track[i].mode = GDROM_MODE1; break; - case 2336: image->track[i].mode = GDROM_GD; break; - case 2352: image->track[i].mode = GDROM_RAW; break; + case 2336: image->track[i].mode = GDROM_SEMIRAW_MODE2; break; + case 2352: image->track[i].mode = GDROM_RAW_XA; break; default: gdrom_image_destroy_no_close(disc); g_free(dirname); --- a/src/gdrom/gdimage.c Tue Feb 26 01:10:48 2008 +0000 +++ b/src/gdrom/gdimage.c Sun Mar 02 11:38:08 2008 +0000 @@ -16,10 +16,12 @@ * GNU General Public License for more details. */ +#include #include #include "gdrom/gdrom.h" #include "gdrom/packet.h" +#include "ecc.h" #include "bootstrap.h" static void gdrom_image_destroy( gdrom_disc_t disc ); @@ -30,10 +32,21 @@ static gdrom_error_t gdrom_image_read_position( gdrom_disc_t disc, uint32_t lba, unsigned char *buf ); static int gdrom_image_drive_status( gdrom_disc_t disc ); +static uint8_t gdrom_default_sync[12] = { 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0 }; + +#define SECTOR_HEADER_SIZE 16 +#define SECTOR_SUBHEADER_SIZE 8 + +/* Data offset (from start of raw sector) by sector mode */ +static int gdrom_data_offset[] = { 16, 16, 16, 24, 24, 0, 8, 0, 0 }; + + + struct cdrom_sector_header { uint8_t sync[12]; uint8_t msf[3]; uint8_t mode; + uint8_t subhead[8]; // Mode-2 XA sectors only }; /** @@ -58,7 +71,7 @@ if( image == NULL ) { return NULL; } - image->disc_type = IDE_DISC_CDROM; + image->disc_type = IDE_DISC_CDROMXA; image->file = f; gdrom_disc_t disc = (gdrom_disc_t)image; gdrom_image_init(disc); @@ -132,7 +145,7 @@ * Read a block from an image file, handling negative file offsets * with 0-fill. */ -static void gdrom_read_block( unsigned char *buf, int file_offset, int length, FILE *f ) +static gboolean gdrom_read_block( unsigned char *buf, int file_offset, int length, FILE *f ) { if( file_offset < 0 ) { int size = -file_offset; @@ -146,9 +159,88 @@ } } fseek( f, file_offset, SEEK_SET ); - fread( buf, length, 1, f ); + return fread( buf, length, 1, f ) == 1; } +static void gdrom_build_sector_header( unsigned char *buf, uint32_t lba, + gdrom_track_mode_t sector_mode ) +{ + memcpy( buf, gdrom_default_sync, 12 ); + cd_build_address( buf, sector_mode, lba ); +} + +/** + * Return TRUE if the given read mode + track modes are compatible, + * otherwise FALSE. + * @param track_mode one of the GDROM_MODE* constants + * @param read_mode the READ_CD_MODE from the read request + */ +static gboolean gdrom_is_compatible_read_mode( int track_mode, int read_mode ) +{ + switch( read_mode ) { + case READ_CD_MODE_ANY: + return TRUE; + case READ_CD_MODE_CDDA: + return track_mode == GDROM_CDDA; + case READ_CD_MODE_1: + return track_mode == GDROM_MODE1 || track_mode == GDROM_MODE2_FORM1; + case READ_CD_MODE_2_FORM_1: + return track_mode == GDROM_MODE1 || track_mode == GDROM_MODE2_FORM1; + case READ_CD_MODE_2_FORM_2: + return track_mode == GDROM_MODE2_FORM2; + case READ_CD_MODE_2: + return track_mode == GDROM_MODE2_FORMLESS; + default: + return FALSE; + } +} + +/** + * Determine the start position in a raw sector, and the amount of data to read + * in bytes, for a given combination of sector mode and read mode. + */ +static void gdrom_get_read_bounds( int sector_mode, int read_mode, int *start, int *size ) +{ + if( READ_CD_RAW(read_mode) ) { + // whole sector + *start = 0; + *size = 2352; + } else { + *size = 0; + if( READ_CD_DATA(read_mode) ) { + *start = gdrom_data_offset[sector_mode]; + *size = gdrom_sector_size[sector_mode]; + } + + if( READ_CD_SUBHEAD(read_mode) && + (sector_mode == GDROM_MODE2_FORM1 || sector_mode == GDROM_MODE2_FORM2) ) { + *start = SECTOR_HEADER_SIZE; + *size += SECTOR_SUBHEADER_SIZE; + } + + if( READ_CD_HEADER(read_mode) ) { + *size += SECTOR_HEADER_SIZE; + *start = 0; + } + + } +} + +/** + * Read a single sector from a disc image. If you thought this would be simple, + * I have just one thing to say to you: Bwahahahahahahahah. + * + * Once we've decided that there's a real sector at the requested lba, there's + * really two things we need to care about: + * 1. Is the sector mode compatible with the requested read mode + * 2. Which parts of the sector do we need to return? + * (header/subhead/data/raw sector) + * + * Also note that the disc image may supply us with just the data (most common + * case), or may have the full raw sector. In the former case we may need to + * generate the missing data on the fly, for which we use libedc to compute the + * data correction codes. + */ static gdrom_error_t gdrom_image_read_sector( gdrom_disc_t disc, uint32_t lba, int mode, unsigned char *buf, uint32_t *length ) { @@ -171,47 +263,109 @@ f = image->file; } - - - switch( mode ) { - case 0x20: /* Actually, read anything, but for now... */ - case 0x24: - case 0x28: - read_len = 2048; - switch( track->mode ) { - case GDROM_MODE1: - case GDROM_MODE2_XA1: - gdrom_read_block( buf, file_offset, track->sector_size, f ); - break; - case GDROM_MODE2: - file_offset += 8; /* skip the subheader */ - gdrom_read_block( buf, file_offset, 2048, f ); - break; - case GDROM_RAW: - gdrom_read_block( (unsigned char *)(§head), file_offset, sizeof(secthead), f ); - switch( secthead.mode ) { - case 1: - file_offset += 16; - break; - case 2: - file_offset += 24; - break; - default: - return PKT_ERR_BADREADMODE; - } - gdrom_read_block( buf, file_offset, 2048, f ); - break; - default: - return PKT_ERR_BADREADMODE; + /* First figure out what the real sector mode is for raw/semiraw sectors */ + int sector_mode; + switch( track->mode ) { + case GDROM_RAW_NONXA: + gdrom_read_block( (unsigned char *)(§head), file_offset, sizeof(secthead), f ); + sector_mode = (secthead.mode == 1) ? GDROM_MODE1 : GDROM_MODE2_FORMLESS; + break; + case GDROM_RAW_XA: + gdrom_read_block( (unsigned char *)(§head), file_offset, sizeof(secthead), f ); + if( secthead.mode == 1 ) { + sector_mode = GDROM_MODE1; + } else { + sector_mode = ((secthead.subhead[2] & 0x20) == 0 ) ? GDROM_MODE2_FORM1 : GDROM_MODE2_FORM2; } break; + case GDROM_SEMIRAW_MODE2: + gdrom_read_block( secthead.subhead, file_offset, 8, f ); + sector_mode = ((secthead.subhead[2] & 0x20) == 0 ) ? GDROM_MODE2_FORM1 : GDROM_MODE2_FORM2; + break; default: + /* In the other cases, the track mode completely defines the sector mode */ + sector_mode = track->mode; + break; + } + + int mode_restrict = READ_CD_MODE(mode); + if( !gdrom_is_compatible_read_mode(sector_mode, READ_CD_MODE(mode)) ) { return PKT_ERR_BADREADMODE; } - + + /* Ok, we've got a valid sector, check what parts of the sector we need to + * return - header | subhead | data | everything + */ + int channels = READ_CD_CHANNELS(mode); + + if( channels == 0 ) { + // legal, if weird + *length = 0; + return PKT_ERR_OK; + } else if( channels == 0xA0 && + (sector_mode == GDROM_MODE2_FORM1 || sector_mode == GDROM_MODE2_FORM2 )) { + // caller requested a non-contiguous region + return PKT_ERR_BADFIELD; + } else if( READ_CD_RAW(channels) ) { + channels = 0xF0; // implies everything + } + + read_len = 0; + int start, size; + switch( track->mode ) { + case GDROM_CDDA: + // audio is nice and simple (assume perfect reads for now) + *length = 2352; + gdrom_read_block( buf, file_offset, track->sector_size, f ); + return PKT_ERR_OK; + case GDROM_RAW_XA: + case GDROM_RAW_NONXA: + gdrom_get_read_bounds( sector_mode, channels, &start, &size ); + gdrom_read_block( buf, file_offset+start, size, f ); + read_len = size; + break; + case GDROM_SEMIRAW_MODE2: + gdrom_get_read_bounds( sector_mode, channels, &start, &size ); + if( READ_CD_HEADER(channels) ) { + gdrom_build_sector_header( buf, lba, sector_mode ); + read_len += SECTOR_HEADER_SIZE; + size -= SECTOR_HEADER_SIZE; + } else { + start -= SECTOR_HEADER_SIZE; + } + gdrom_read_block( buf + read_len, file_offset+start, size, f ); + read_len += size; + break; + default: // Data track w/ data only in file + if( READ_CD_RAW(channels) ) { + gdrom_read_block( buf + gdrom_data_offset[track->mode], file_offset, + track->sector_size, f ); + do_encode_L2( buf, sector_mode, lba ); + read_len = 2352; + } else { + if( READ_CD_HEADER(channels) ) { + gdrom_build_sector_header( buf, lba, sector_mode ); + read_len += SECTOR_HEADER_SIZE; + } + if( READ_CD_SUBHEAD(channels) && + (sector_mode == GDROM_MODE2_FORM1 || sector_mode == GDROM_MODE2_FORM2) ) { + if( sector_mode == GDROM_MODE2_FORM1 ) { + *((uint32_t *)(buf+read_len)) = 0; + *((uint32_t *)(buf+read_len+4)) = 0; + } else { + *((uint32_t *)(buf+read_len)) = 0x00200000; + *((uint32_t *)(buf+read_len+4)) = 0x00200000; + } + read_len += 8; + } + if( READ_CD_DATA(channels) ) { + gdrom_read_block( buf+read_len, file_offset, track->sector_size, f ); + read_len += track->sector_size; + } + } + } *length = read_len; return PKT_ERR_OK; - } static gdrom_error_t gdrom_image_read_toc( gdrom_disc_t disc, unsigned char *buf ) --- a/src/gdrom/gdrom.c Tue Feb 26 01:10:48 2008 +0000 +++ b/src/gdrom/gdrom.c Sun Mar 02 11:38:08 2008 +0000 @@ -33,8 +33,9 @@ &gdi_image_class, NULL }; -char *gdrom_mode_names[] = { "Mode1", "Mode2", "XA 1", "XA2", "Audio", "GD-Rom" }; -uint32_t gdrom_sector_size[] = { 2048, 2336, 2048, 2324, 2352, 2336 }; +char *gdrom_mode_names[] = { "Mode 0", "Mode 1", "Mode 2", "Mode 2 Form 1", "Mode 2 Form 2", "Audio", + "Mode 2 semiraw", "XA Raw", "Non-XA Raw" }; +uint32_t gdrom_sector_size[] = { 0, 2048, 2336, 2048, 2324, 2352, 2336, 2352, 2352 }; gdrom_disc_t gdrom_image_open( const gchar *filename ) { --- a/src/gdrom/gdrom.h Tue Feb 26 01:10:48 2008 +0000 +++ b/src/gdrom/gdrom.h Sun Mar 02 11:38:08 2008 +0000 @@ -37,25 +37,42 @@ extern uint32_t gdrom_sector_size[]; #define GDROM_SECTOR_SIZE(x) gdrom_sector_size[x] +/** + * Track data type enumeration for cd images and devices. This somewhat + * conflates the real track mode with the format of the image file, but + * it manages to make sense so far. + */ typedef enum { - GDROM_MODE1, - GDROM_MODE2, - GDROM_MODE2_XA1, - GDROM_MODE2_XA2, - GDROM_CDDA, - GDROM_GD, - GDROM_RAW + GDROM_MODE0, // Mode 0 - should never actually see this +/* Data-only modes (image file contains only the user data) */ + GDROM_MODE1, // Standard CD-Rom Mode 1 data track + GDROM_MODE2_FORMLESS, // Mode 2 data track with no sub-structure (rare) + GDROM_MODE2_FORM1, // Mode 2/Form 1 data track (standard for multisession) + GDROM_MODE2_FORM2, // Mode 2/Form 2 data track (also fairly uncommon). + GDROM_CDDA, // Standard audio track + +/* This one is somewhat special - the image file contains the 2336 bytes of + * "extended user data", which in turn contains either a form 1 or form 2 + * sector. In other words it's a raw mode2 XA sector without the 16-byte header. + */ + GDROM_SEMIRAW_MODE2, +/* Raw modes (image contains the full 2352-byte sector). Split into XA/Non-XA + * here for convenience, although it's really a session level flag. */ + GDROM_RAW_XA, + GDROM_RAW_NONXA, } gdrom_track_mode_t; /* The disc register indicates the current contents of the drive. When open * contains 0x06. */ -#define IDE_DISC_AUDIO 0x00 -#define IDE_DISC_NONE 0x06 -#define IDE_DISC_CDROM 0x20 -#define IDE_DISC_GDROM 0x80 #define IDE_DISC_READY 0x01 /* ored with above */ #define IDE_DISC_IDLE 0x02 /* ie spun-down */ +#define IDE_DISC_NONE 0x06 + +#define IDE_DISC_AUDIO 0x00 +#define IDE_DISC_CDROM 0x10 +#define IDE_DISC_CDROMXA 0x20 +#define IDE_DISC_GDROM 0x80 #define TRACK_PRE_EMPHASIS 0x10 #define TRACK_COPY_PERMITTED 0x20 --- a/src/gdrom/nrg.c Tue Feb 26 01:10:48 2008 +0000 +++ b/src/gdrom/nrg.c Sun Mar 02 11:38:08 2008 +0000 @@ -154,8 +154,8 @@ { switch( mode ) { case 0: return GDROM_MODE1; - case 2: return GDROM_MODE2_XA1; - case 3: return GDROM_MODE2; + case 2: return GDROM_MODE2_FORM1; + case 3: return GDROM_SEMIRAW_MODE2; case 7: return GDROM_CDDA; default: ERROR( "Unrecognized track mode %d in Nero image", mode ); --- a/src/gdrom/packet.h Tue Feb 26 01:10:48 2008 +0000 +++ b/src/gdrom/packet.h Sun Mar 02 11:38:08 2008 +0000 @@ -66,5 +66,17 @@ #define PKT_ERR_BADREADMODE 0x6405 /* Illegal mode for this track */ #define PKT_ERR_RESET 0x2906 -#define IDE_READ_MODE1 0x20 -#define IDE_READ_RAW 0x30 +/* Parse CD read */ +#define READ_CD_MODE(x) ((x)&0x0E) +#define READ_CD_MODE_ANY 0x00 +#define READ_CD_MODE_CDDA 0x02 +#define READ_CD_MODE_1 0x04 +#define READ_CD_MODE_2 0x06 +#define READ_CD_MODE_2_FORM_1 0x08 +#define READ_CD_MODE_2_FORM_2 0x0A + +#define READ_CD_CHANNELS(x) ((x)&0xF0) +#define READ_CD_HEADER(x) ((x)&0x80) +#define READ_CD_SUBHEAD(x) ((x)&0x40) +#define READ_CD_DATA(x) ((x)&0x20) +#define READ_CD_RAW(x) ((x)&0x10)