[MN-dev] [mndiff]: r46 - in trunk/2010: 2010.cc 2010.h 2_71x6.cc 2_71x6.h 2_all.h 2_crypt.cc 2_hw.cc 2_hw_asm.s 2_mfunc.cc 2_nag.cc 2_nag.h 2_nag_a.asm 2_nag_a.h makefile

michael subversion at mplayerhq.hu
Wed Jul 4 03:59:17 CEST 2007


Author: michael
Date: Wed Jul  4 03:59:17 2007
New Revision: 46

Log:
version from july 1998


Modified:
   trunk/2010/2010.cc
   trunk/2010/2010.h
   trunk/2010/2_71x6.cc
   trunk/2010/2_71x6.h
   trunk/2010/2_all.h
   trunk/2010/2_crypt.cc
   trunk/2010/2_hw.cc
   trunk/2010/2_hw_asm.s
   trunk/2010/2_mfunc.cc
   trunk/2010/2_nag.cc
   trunk/2010/2_nag.h
   trunk/2010/2_nag_a.asm
   trunk/2010/2_nag_a.h
   trunk/2010/makefile

Modified: trunk/2010/2010.cc
==============================================================================
--- trunk/2010/2010.cc	(original)
+++ trunk/2010/2010.cc	Wed Jul  4 03:59:17 2007
@@ -19,10 +19,11 @@
 #include "2_menu.h"
 #include "2_grafix.h"
 #include "2_71x6.h"
+#include "2_nag.h"
 
  extern mouse_sprites cursor;
  extern int g_mode;
- extern xxx dispbuf, grab_dispbuf;
+ extern xxx dispbuf, *doubleBuff;
  extern byte *vidbuf;
  extern int mouse_x, mouse_y, mouse_b;
  extern volatile int page_flip;
@@ -34,6 +35,10 @@
  extern int single;
  extern int grabf;
  extern int mmx;
+ extern int *best1;
+ extern BEST2 *best2;
+ extern KEYSLIST *keysList;
+ extern bool manualPhaseStart;
 
 int _crt0_startup_flags = _CRT0_FLAG_NEARPTR | _CRT0_FLAG_NONMOVE_SBRK;
  int buttons=0, xpos=0, ypos=0, lxpos=0, lypos=0;
@@ -93,6 +98,14 @@ int error(error_code e){
                      break;
   case SAA7196     : printg_t("\nPhilips SAA7196 error!\n");
                      break;
+  case KeyFile     : printg_t("\nKeyFile error!\n");
+                     break;
+  case DatWrite    : printg_t("\nDatWrite error!\n");
+                     break;
+  case Align       : printg_t("\nAlign error!\n");
+                     break;
+  case Nagra       : printg_t("\nNagra error!\n");
+                     break;
   case CommLine    : printg_t("\nCommand-Line error!\n");
   case Help        : printg_t("\n2010 [<optons>]\n"
                             "options: -v n (Video-mode)\n"
@@ -111,6 +124,9 @@ int error(error_code e){
 
 void exitt(void){
  close_hw();
+ delete [] best1;
+ delete [] best2;
+ delete [] keysList;
 }
 
 int main(int argc, char **argv){
@@ -290,8 +306,12 @@ int main(int argc, char **argv){
  else
   a= alloc_cont(vgax * vgay << mc2, 1);
 
- dispbuf     =a[0];
- grab_dispbuf=a[1];
+ doubleBuff=(xxx*)(int(&doubleBuff)+4);
+ dispbuf=                               // dispbuf just cheap copy 
+ doubleBuff[0]= a[0];
+ doubleBuff[1]= a[1];
+ doubleBuff[0].state= 
+ doubleBuff[1].state= Empty;
 
  if(page_flip==0) i= vgax * vgay * vb;
  else             i= vgax * vgay * vb << 1;
@@ -324,6 +344,7 @@ int main(int argc, char **argv){
 
   if(kbhit()) key=getkey();
   if(key=='g' || key=='G') key=0, grabf=1;
+  if(key=='p' || key=='P') key=0, manualPhaseStart^=1;
  }
  
  exit(0);

Modified: trunk/2010/2010.h
==============================================================================
--- trunk/2010/2010.h	(original)
+++ trunk/2010/2010.h	Wed Jul  4 03:59:17 2007
@@ -27,6 +27,10 @@ typedef enum{
  FileMax,
  Lock,
  SAA7196,
+ DatWrite,
+ KeyFile,
+ Align,
+ Nagra,
 } error_code;
 
 int error(error_code e);

Modified: trunk/2010/2_71x6.cc
==============================================================================
--- trunk/2010/2_71x6.cc	(original)
+++ trunk/2010/2_71x6.cc	Wed Jul  4 03:59:17 2007
@@ -24,7 +24,6 @@ extern u_short my_ds;
 extern dword old_intmet_vect_offset;
 extern  word old_intmet_vect_selector;
 extern  byte meteor_handler;
-extern volatile grstate grab_state;
 extern volatile int metmode;
 extern volatile int active_meteor;
 extern int latency;
@@ -36,7 +35,7 @@ extern volatile tv_form std;
 extern volatile crypt_form crypt;
 extern volatile int x_field, y_field, one_field;
 extern volatile int xresc, yuvmode, mc;
-extern volatile xxx dispbuf, grab_dispbuf;
+extern volatile xxx dispbuf, *doubleBuff;
 extern volatile int stride;
 extern int wndx, wndy, outy;
 extern int single;
@@ -58,7 +57,7 @@ int bypass_y=0x0, bypasc_y=0x0;
 static inline int write_i2c(u_char dev, u_char reg, u_char data);
 static inline void wait(double);
 static inline void reset_7116(void);
-
+static void start_grab(void);
 
 int scan_pci_meteors(void){
  int i, dev, bus;
@@ -200,41 +199,46 @@ void meteor_int_handler(void){
    addr_errors++;
  }
 
- if(a_saa7116->ints_ctl.stat_even != 1 || a_saa7116->ints_ctl.stat_odd != 1){
-   frames++;
-   fields++;
- }
+ fields+= a_saa7116->ints_ctl.stat_even + a_saa7116->ints_ctl.stat_odd;
+ frames+= a_saa7116->ints_ctl.stat_start;
+
+// asm("int $3\n\t");
 
  a_saa7116->capt_ctl_a|=0x0F30;
- if( (    (one_field==0 && nagra_mode==0)
-       || a_saa7116->ints_ctl.stat_even == 0) && fields>=2){
+ if(    ( a_saa7116->ints_ctl.stat_odd   == 1 && fields>=2     )
+    ||  ( a_saa7116->ints_ctl.stat_start == 1 && fields>=11111 )  ){
    fields=0;
 
-   if(grab_state==Waiting){
-     if(single==1){
-       a_saa7116->capt_ctl=(capt_c){
-           cont_even: 0, cont_odd: 0, sing_even: 0, sing_odd: 0,
-           done_even: 1, done_odd: 1, VRSTN:     1, fifo_en:  1,
-           corr_even: 1, corr_odd: 1, aerr_even: 1, aerr_odd: 1,
-           res1:      0, corr_dis: 0, range_en:  1, res2:     0};
-     }
-     else{
-       volatile xxx temp=dispbuf;
-       dispbuf=grab_dispbuf;
-       grab_dispbuf=temp;
+   int grabbingOne=0;
+   while(doubleBuff[grabbingOne].state != Grabbing && grabbingOne<2)
+     grabbingOne++;
+   if(grabbingOne!=2) doubleBuff[grabbingOne].state= Grabbed;
 
-       grab_next();
-     }
-     grab_state=NotReady;
-   }else{
+   int emptyOne=0;
+   while(doubleBuff[emptyOne].state!=Empty && emptyOne<2) emptyOne++;
+
+   if(emptyOne!=2){
      if(single==0){
-       a_saa7116->capt_ctl=(capt_c){
-           cont_even: 0, cont_odd: 0, sing_even: 0, sing_odd: 0,
-           done_even: 1, done_odd: 1, VRSTN:     1, fifo_en:  1,
-           corr_even: 1, corr_odd: 1, aerr_even: 1, aerr_odd: 1,
-           res1:      0, corr_dis: 0, range_en:  1, res2:     0};
-       grab_state=Skiped;
+       doubleBuff[emptyOne].state= Grabbing;
+     }
+     else{
+       doubleBuff[0].state=
+       doubleBuff[1].state= Grabbing;
      }
+     grab_next(doubleBuff[emptyOne]);
+     a_saa7116->capt_ctl=(capt_c){
+         cont_even: 1, cont_odd: 1, sing_even: 0, sing_odd: 0,
+         done_even: 1, done_odd: 1, VRSTN:     1, fifo_en:  1,
+         corr_even: 1, corr_odd: 1, aerr_even: 1, aerr_odd: 1,
+         res1:      0, corr_dis: 0, range_en:  1, res2:     0};
+   }
+   else{
+     fields=11111;
+     a_saa7116->capt_ctl=(capt_c){
+         cont_even: 0, cont_odd: 0, sing_even: 0, sing_odd: 0,
+         done_even: 1, done_odd: 1, VRSTN:     1, fifo_en:  1,
+         corr_even: 1, corr_odd: 1, aerr_even: 1, aerr_odd: 1,
+         res1:      0, corr_dis: 0, range_en:  1, res2:     0};
    }
  }
  a_saa7116->ints_ctl_a|=0x7;
@@ -272,23 +276,39 @@ void close_meteor(void){
   metmode=0;
 }
 
-void grab_next(void){
+void grab_next(xxx x){
  saa7116 *a_saa7116=(saa7116*)meteors[active_meteor].saa7116;
 
- a_saa7116->dma_end.even=
- a_saa7116->dma_end.odd= 0;
-
  if(one_field==1){
-   a_saa7116->dma.even[0]= a_saa7116->dma.odd [0]= grab_dispbuf.phys;
+   a_saa7116->dma.even[0]= a_saa7116->dma.odd [0]= 
+   a_saa7116->dma.even[1]= a_saa7116->dma.odd [1]= 
+   a_saa7116->dma.even[2]= a_saa7116->dma.odd [2]= x.phys;
  }else{                                               
-   a_saa7116->dma.even[0]= grab_dispbuf.phys;
-   a_saa7116->dma.odd [0]= grab_dispbuf.phys + xresc;
+   a_saa7116->dma.even[0]= 
+   a_saa7116->dma.even[1]= 
+   a_saa7116->dma.even[2]= x.phys;
+   a_saa7116->dma.odd [0]=
+   a_saa7116->dma.odd [1]=
+   a_saa7116->dma.odd [2]= x.phys + xresc;
  }
 
  a_saa7116->dma_end.even=
- a_saa7116->dma_end.odd= grab_dispbuf.phys + xresc*outy - 1;
+ a_saa7116->dma_end.odd= x.phys + xresc*outy - 1;
+
+}
+
+void grab_nix(){
+ saa7116 *a_saa7116=(saa7116*)meteors[active_meteor].saa7116;
+
+ xxx x= doubleBuff[0];
+
+ a_saa7116->dma.even[0]= a_saa7116->dma.odd [0]= 
+ a_saa7116->dma.even[1]= a_saa7116->dma.odd [1]= 
+ a_saa7116->dma.even[2]= a_saa7116->dma.odd [2]= x.phys;
+
+ a_saa7116->dma_end.even=
+ a_saa7116->dma_end.odd= x.phys + xresc*4;
 
-    
 }
 
 
@@ -575,7 +595,7 @@ write_saa7196(0x10, 0x00);   //BAK
  start_grab();
 }
 
-void start_grab(void){
+static void start_grab(void){
  saa7116 *a_saa7116=(saa7116*)meteors[active_meteor].saa7116;
 
  a_saa7116->ints_ctl=(ints_c){
@@ -584,6 +604,10 @@ void start_grab(void){
 
  wait(wait_time);
 
+ xxx grab_dispbuf= doubleBuff[0].phys==dispbuf.phys ?
+                                               doubleBuff[1] : doubleBuff[0];
+
+
  if(one_field==1){
    a_saa7116->dma.even[0]= a_saa7116->dma.odd [0]=
    a_saa7116->dma.even[1]= a_saa7116->dma.odd [1]=
@@ -621,7 +645,34 @@ void start_grab(void){
        res1:      0, corr_dis: 0, range_en:  1, res2:     0};
  a_saa7116->ints_ctl=(ints_c){
        stat_even: 1, stat_odd: 1, stat_start: 1, res1: 0,
-       mask_even: 1, mask_odd: 1, mask_start: 0, res2: 0};
+       mask_even: 1, mask_odd: 1, mask_start: 1, res2: 0};
  
 }
 
+void cont_grab(void){
+ saa7116 *a_saa7116=(saa7116*)meteors[active_meteor].saa7116;
+
+ if(one_field==1){
+   a_saa7116->stride.even[0]=a_saa7116->stride.odd[0]= 
+   a_saa7116->stride.even[1]=a_saa7116->stride.odd[1]= 
+   a_saa7116->stride.even[2]=a_saa7116->stride.odd[2]=
+                                                      stride;
+ }else{                                               
+   a_saa7116->dma.odd [0]=
+   a_saa7116->dma.odd [1]=
+   a_saa7116->dma.odd [2]=
+                     a_saa7116->dma.even[0] + xresc;
+   a_saa7116->stride.even[0]=a_saa7116->stride.odd[0]= 
+   a_saa7116->stride.even[1]=a_saa7116->stride.odd[1]= 
+   a_saa7116->stride.even[2]=a_saa7116->stride.odd[2]=
+                                                      stride;
+ }
+ a_saa7116->dma_end.even=
+ a_saa7116->dma_end.odd= a_saa7116->dma.even[0] + xresc*outy - 1;
+
+  
+
+ wait(wait_time);
+
+}
+

Modified: trunk/2010/2_71x6.h
==============================================================================
--- trunk/2010/2_71x6.h	(original)
+++ trunk/2010/2_71x6.h	Wed Jul  4 03:59:17 2007
@@ -21,12 +21,6 @@ typedef enum{
  nag,
 } crypt_form;
 
-typedef enum{
- NotReady=0,
- Skiped,
- Waiting,
-} grstate;
-
 /*
  pci_cmd;   //04-05
  pci_sts;   //06-07
@@ -216,11 +210,12 @@ void init_meteor(void);
 void close_meteor(void);
 void meteor_int_handler(void);
 void meteor_int_handler_end(void);
-void start_grab(void);
+void cont_grab(void);
 void write_saa7196(u_char reg, u_char data);
 u_char read_saa7196(u_char reg);
 void setcont(void);
 void setstd_scale(void);
-void grab_next(void);
+void grab_next(xxx x);
+void grab_nix();
 
 #endif

Modified: trunk/2010/2_all.h
==============================================================================
--- trunk/2010/2_all.h	(original)
+++ trunk/2010/2_all.h	Wed Jul  4 03:59:17 2007
@@ -36,6 +36,13 @@ union s_col{
   u_long a;
 };
 
+typedef enum{
+  Empty,
+  Working,
+  Grabbing,
+  Grabbed,
+} BUFFSTATE;
+
 struct xxx{
   union{
     s_yuv *yuv;
@@ -44,6 +51,7 @@ struct xxx{
     byte  *b;
   };
   int phys;
+  BUFFSTATE state; 
 };
 
 class color{

Modified: trunk/2010/2_crypt.cc
==============================================================================
--- trunk/2010/2_crypt.cc	(original)
+++ trunk/2010/2_crypt.cc	Wed Jul  4 03:59:17 2007
@@ -26,7 +26,7 @@ int show_points=0;
 void decrypt(void){
 
 // if( (crypt == vc || crypt == nag) && satur!=0 ) decomb();
-// decomb();
+ decomb();
 
  if(crypt==vc)       vc_decrypt();
  else if(crypt==nag) nag_decrypt();

Modified: trunk/2010/2_hw.cc
==============================================================================
--- trunk/2010/2_hw.cc	(original)
+++ trunk/2010/2_hw.cc	Wed Jul  4 03:59:17 2007
@@ -8,6 +8,7 @@
 #include <sys/nearptr.h>
 #include <signal.h>
 #include <errno.h>
+#include <time.h>
 #include "2_all.h"
 #include "2_hw.h"
 #include "2_hw_asm.h"
@@ -31,9 +32,8 @@
  extern volatile int page_flip;
  extern volatile int yuvmode;
  extern volatile AllocList *alloclist;
- extern volatile grstate grab_state;
  extern volatile int fresh_cursor;
- extern volatile xxx dispbuf, grab_dispbuf;
+ extern volatile xxx dispbuf, *doubleBuff;
  extern volatile int one_field;
  extern volatile int active_meteor;
  extern volatile meteor meteors[8];
@@ -546,33 +546,26 @@ void copy_vidbuffer(void){
    set_start_disp(0, 0);
  }
 
- if(grab_state==Skiped){
-   volatile xxx temp=dispbuf;
-   dispbuf=grab_dispbuf;
-   grab_dispbuf=temp;
 
-   grab_next();
-   fields=0;  //FIX ME ? -1 or what       
-   meteors[active_meteor].saa7116->capt_ctl=(capt_c){
-       cont_even: 1, cont_odd: 1, sing_even: 0, sing_odd: 0,
-       done_even: 1, done_odd: 1, VRSTN:     1, fifo_en:  1,
-       corr_even: 1, corr_odd: 1, aerr_even: 1, aerr_odd: 1,
-       res1:      0, corr_dis: 0, range_en:  1, res2:     0};
-                                    //   0x8FF3 resume grab
-   grab_state=NotReady;
- }
- else{
-   meteors[active_meteor].saa7116->capt_ctl=(capt_c){
-       cont_even: 1, cont_odd: 1, sing_even: 0, sing_odd: 0,
-       done_even: 1, done_odd: 1, VRSTN:     1, fifo_en:  1,
-       corr_even: 1, corr_odd: 1, aerr_even: 1, aerr_odd: 1,
-       res1:      0, corr_dis: 0, range_en:  1, res2:     0};
-                                    //   0x8FF3 resume grab
-   grab_state=Waiting;
-   while(grab_state==Waiting);
+ if(single==0){
+
+   int workingOne=0;
+   while(doubleBuff[workingOne].state!=Working && workingOne<2) workingOne++;
+   if(workingOne==2) workingOne=0; // should be only at start
+   doubleBuff[workingOne].state=Empty;
+
+   int nextOne= workingOne^1;
+   if(doubleBuff[nextOne].state==Empty) nextOne=0;    // not critical 
+
+//   meteors[active_meteor].saa7116->ints_ctl_a |= 0x7;
+//   meteors[active_meteor].saa7116->capt_ctl_a |= 0x0F30;
+
+   printf("%X, %X\n", meteors[active_meteor].saa7116->capt_ctl_a,
+                      meteors[active_meteor].saa7116->ints_ctl_a );
+
+   printf("%X, %X\n", doubleBuff[0].state,
+                      doubleBuff[1].state );
 
- }
-/*
  printf("X\nDMA E0 START %X\n",  meteors[active_meteor].saa7116->dma.even[0]);
  printf("DMA E1 START %X\n",  meteors[active_meteor].saa7116->dma.even[1]);
  printf("DMA E2 START %X\n",  meteors[active_meteor].saa7116->dma.even[2]);
@@ -589,7 +582,26 @@ void copy_vidbuffer(void){
 
  printf("DMA E END %X\n",  meteors[active_meteor].saa7116->dma_end.even);
  printf("DMA O END %X\n",  meteors[active_meteor].saa7116->dma_end.odd);
-  */
+
+   while(doubleBuff[nextOne].state != Grabbed);
+
+   doubleBuff[nextOne].state= Working;
+
+   dispbuf= doubleBuff[nextOne];
+ }
+ else{
+   doubleBuff[0].state=
+   doubleBuff[1].state=Empty;
+
+   while(doubleBuff[0].state != Grabbed);
+
+   doubleBuff[0].state=
+   doubleBuff[1].state=Working;
+
+   dispbuf= doubleBuff[0];
+ }
+
+
 }
 
 u_long read_pci(int bus, int dev, int func, int reg, int size){

Modified: trunk/2010/2_hw_asm.s
==============================================================================
--- trunk/2010/2_hw_asm.s	(original)
+++ trunk/2010/2_hw_asm.s	Wed Jul  4 03:59:17 2007
@@ -22,8 +22,7 @@
 .globl _mouse_b
 .globl _page_flip
 .globl _dispbuf
-.globl _last_dispbuf
-.globl _grab_dispbuf
+.globl _doubleBuff
 .globl _vidbuf
 .globl _vgax
 .globl _xresvb
@@ -41,7 +40,6 @@
 .globl _old_intmet_vect
 .globl _old_intmet_vect_offset
 .globl _old_intmet_vect_selector
-.globl _grab_state
 .globl _metmode
 .globl _active_meteor
 .globl _latency
@@ -86,10 +84,17 @@ _mouse_b: .long 0
 _page_flip: .long 0
 _dispbuf: .long 0
 .long 0
-_last_dispbuf: .long 0
 .long 0
-_grab_dispbuf: .long 0
 .long 0
+_doubleBuff: .long 1234
+.long 0
+.long 0
+.long 0
+.long 0
+.long 0
+.long 0
+.long 0
+.long 4321
 _vidbuf: .long 0
 _vgax: .long 0
 _vb: .long 0
@@ -106,7 +111,6 @@ _old_intmet_vect:
 _old_intmet_vect_offset: .long 0
 _old_intmet_vect_selector: .word 0
 .align 4
-_grab_state: .long 0
 _metmode: .long 0
 _active_meteor: .long 0
 _latency: .long 32

Modified: trunk/2010/2_mfunc.cc
==============================================================================
--- trunk/2010/2_mfunc.cc	(original)
+++ trunk/2010/2_mfunc.cc	Wed Jul  4 03:59:17 2007
@@ -160,6 +160,6 @@ void mstd(int num){
 
  setstd_scale();
 
- start_grab();
+ cont_grab();
 
 }

Modified: trunk/2010/2_nag.cc
==============================================================================
--- trunk/2010/2_nag.cc	(original)
+++ trunk/2010/2_nag.cc	Wed Jul  4 03:59:17 2007
@@ -12,6 +12,7 @@
 #include "2_gfunc.h"
 #include "2_mmx.h"
 #include "2_nag_a.h"
+#include "2010.h"
 
 #define dwnSmp 1
 
@@ -24,30 +25,671 @@ extern u_long asm_temp, asm_temp4;
 extern int istate;
 extern int yuvmode;
 extern bool mmx;
+extern volatile int frames;
+
+bool manualPhaseStart=false;
+int *decoLine;
+int decoLines;
+int keyTable[256];
+int *best1=NULL;
+BEST2 *best2=NULL;              // FIX DELETE
+KEYSLIST *keysList=NULL;
+static int outy1;
+static int nagStart2;
+static int nagEnd2;
+static int nagStart1;
+static int nagEnd1;
+static int nagSize1;
+static int nagSize2;
+static int nagSizeAll;
+
+bool checkAlign(void *p, int align){         // FIX SHOULD BE SOMEWHERE ELSE
+  if(int(p) & (align-1)) return false;
+  else                   return true;
+}
+
+
+void *newAlign(int size, int align){         // FIX SHOULD BE SOMEWHERE ELSE
+  int v= int(new char[size + align + 3]);
+  int v2= ( (v+align-1+4) & ~(align-1) );
+  ((int*)v2)[-1]= v;
+  return (void*)v2;
+}
+
+void deleteAlign(void *v){         // FIX SHOULD BE SOMEWHERE ELSE
+  delete [] ((char**)v)[-1];
+}
+
+static inline void getPerm(const int key, int * const perm){
+  int keyNdx= key >> 7;
+  const int keyInc= ((key & 0x7F) << 1) + 1;
+  int buffer[32];
+
+  for(int i=0; i<32; i++) buffer[i]= i;
+
+  for(int i=0; i<255; i++){
+    perm[i]= buffer[ keyTable[keyNdx] ];
+    buffer[ keyTable[keyNdx] ]= i + 32;
+    keyNdx= (keyNdx + keyInc) & 0xFF;
+  }
+
+  for(int i=0; i<32; i++){
+    perm[i+255]= buffer[i];
+  }
+}
+
+static inline void doDwnSmp(byte * const lowRes, byte * const highRes){
+
+ if(mmx){
+   asm(//"int $3 \n\t"
+         "pushl %%ebp          \n\t"
+         "cmpb 3f-1, %%cl      \n\t"
+         " je 5f               \n\t"
+         "movb %%cl, 3f-1      \n\t"
+         "movl $1, %%eax       \n\t"
+         "shll %%cl, %%eax     \n\t"
+         "movl %%eax, 4f-4     \n\t"
+
+         "5:                   \n\t"
+
+         "1:                   \n\t"
+         "movb (%%edi), %%al   \n\t"   // U        load 32 byte in L1-cache
+         "xorl %%ebx, %%ebx    \n\t"   //  V 1
+         "movl $0xFFFF, %%ebp  \n\t"   // U
+         "4:                   \n\t"
+         "xorl %%eax, %%eax    \n\t"   //  V 1
+         "2:                   \n\t"
+         "addl %%eax, %%ebx    \n\t"   // U
+         "xorl %%eax, %%eax    \n\t"   //  V 1
+         "movb (%%esi), %%al   \n\t"   // U
+         "addl $2, %%esi       \n\t"   //  V 1
+         "decl %%ebp           \n\t"   // U
+         " jnz 2b              \n\t"   //  V 1
+         "incl %%edi           \n\t"   // U
+         "addl %%eax, %%ebx    \n\t"   //  V 1
+         "shrl $50, %%ebx      \n\t"   // U  1
+         "3:                   \n\t"
+         "decl %%edx           \n\t"   //  V 1
+         "movb %%bl, -1(%%edi) \n\t"   // U
+         " jnz 1b              \n\t"   //  V 1
+    
+         "popl %%ebp            \n\t"
+          : 
+          : "c" (dwnSmp), 
+            "S" (highRes + 1) ,
+            "d" (wndx>>dwnSmp) ,
+            "D" (lowRes) 
+          : "%eax", "%ebx", "%ecx", "%edx", "%esi", "%edi");
+
+ }
+ else{
+     asm(//"int $3 \n\t"
+         "pushl %%ebp          \n\t"
+         "cmpb 3f-1, %%cl      \n\t"
+         " je 5f               \n\t"
+         "movb %%cl, 3f-1      \n\t"
+         "movl $1, %%eax       \n\t"
+         "shll %%cl, %%eax     \n\t"
+         "movl %%eax, 4f-4     \n\t"
+
+         "5:                   \n\t"
+
+
+         "1:                   \n\t"
+         "movw (%%edi), %%ax   \n\t"   // U        load 32 byte in L1-cache
+         "xorl %%ebx, %%ebx    \n\t"   //  V 1
+         "movl $0xFFFF, %%ebp  \n\t"   // U
+         "4:                   \n\t"
+         "xorl %%eax, %%eax    \n\t"   //  V 1
+         "2:                   \n\t"
+         "addl %%eax, %%ebx    \n\t"   // U
+         "xorl %%eax, %%eax    \n\t"   //  V 1
+         "movb (%%esi), %%al   \n\t"   // U
+         "addl $2, %%esi       \n\t"   //  V 1
+         "decl %%ebp           \n\t"   // U
+         " jnz 2b              \n\t"   //  V 1
+         "addl $2, %%edi       \n\t"   // U
+         "addl %%eax, %%ebx    \n\t"   //  V 1
+         "shrl $50, %%ebx      \n\t"   // U  1
+         "3:                   \n\t"
+         "decl %%edx           \n\t"   //  V 1
+         "movw %%bx, -2(%%edi) \n\t"   // U
+         " jnz 1b              \n\t"   //  V 1
+    
+         "popl %%ebp            \n\t"
+          : 
+          : "c" (dwnSmp), 
+            "S" (highRes + 1) ,
+            "d" (wndx>>dwnSmp) ,
+            "D" (lowRes) 
+          : "%eax", "%ebx", "%ecx", "%edx", "%esi", "%edi");
+ }
+
+
+
+
+}
+
+static inline int nagLineLogi2Phys(const int logi){
+  int phys;
+
+  if(logi<32) phys= nagStart1 + ( logi    <<1);
+  else        phys= nagStart2 + ((logi-32)<<1);
+  return phys;
+}
+
+void mod4Fix(byte * p, int cleMod4, int encMod4){
+  const bool xchg[16]={false,  true, false,  true, 
+                        true, false,  true, false, 
+                       false,  true, false,  true,
+                        true, false,  true, false };
+                
+  const byte  neg[16]={    0,     0,  0xFF,  0xFF,
+                           0,     0,  0xFF,  0xFF,
+                        0xFF,  0xFF,     0,     0,
+                        0xFF,  0xFF,     0,     0 };
+  const int ndx= cleMod4 | (encMod4<<2);
+
+  for(int x=0; x<(vgax<<1); x+=4){
+    byte u= p[x  ];            // perhaps u><v 
+    byte v= p[x+2];
+
+    if(xchg[ndx]){
+      const int t=u;
+      u=v;
+      v=t;
+    }
+
+    p[x  ]= (u^neg[ndx]) - neg[ndx];
+    p[x+2]= (v^neg[ndx]) - neg[ndx];
+  }
 
-int blackThreshold= 4000;
 
-static int qsort_block(const void *p1, const void *p2);
 
-static int qsort_block(const void *p1, const void *p2){
-  return ( (BLOCK*)(p1) )->limit[0] - ( (BLOCK*)(p2) )->limit[0];
 }
 
 void nag_decrypt(void){
+ outy1= outy>>1;
+ nagStart2= int(double(17+0   - scales_y)/y_field*outy1 + .5)*2+1;
+ nagEnd2  = int(double(17+254 - scales_y)/y_field*outy1 + .5)*2+1;
+ nagStart1= int(double(17+255 - scales_y)/y_field*outy1 + .5)*2+2;
+ nagEnd1  = int(double(17+286 - scales_y)/y_field*outy1 + .5)*2+2;
+ nagSize1= (nagEnd1 - nagStart1)/2 + 1;
+ nagSize2= (nagEnd2 - nagStart2)/2 + 1;
+ nagSizeAll= nagSize1 + nagSize2;
  char textbuf[10][128];
  color c;
- const int outy1= outy>>1;
- const int nagStart2= int(double(17+0   - scales_y)/y_field*outy1 + .5)*2+1;
- const int nagEnd2  = int(double(17+254 - scales_y)/y_field*outy1 + .5)*2+1;
- const int nagStart1= int(double(17+255 - scales_y)/y_field*outy1 + .5)*2+2;
- const int nagEnd1  = int(double(17+286 - scales_y)/y_field*outy1 + .5)*2+2;
- const int nagSize1= (nagEnd1 - nagStart1)/2 + 1;
- const int nagSize2= (nagEnd2 - nagStart2)/2 + 1;
- const int nagSizeAll= nagSize1 + nagSize2;
  long T1, T2;
- char lastDwnSmp= 50;
  const int dwnSmpSize= mmx ? dwnSmp : dwnSmp-1;
 
+ if(nagSizeAll!=NAG_LINES) error(Nagra);
+
+ T1=uclock();
+
+// if(frames&1) frames++;
+ const int vPhase= (((frames & 2)==2) ^ manualPhaseStart) ? 1 : 0;
+
+// printf("%d %d\n", sizeof(KEYSLIST), sizeof(BEST2) );
+
+// printf("HALLOX\n");
+ static bool first=true;
+
+ if(first){
+   decoLines=14;
+   decoLine=new int[decoLines];
+   decoLine[ 0]= 91;
+   decoLine[ 1]=103;
+   decoLine[ 2]=112;
+   decoLine[ 3]=124;
+   decoLine[ 4]=131;
+   decoLine[ 5]=145;
+   decoLine[ 6]=152;
+   decoLine[ 7]=163;
+   decoLine[ 8]=175;
+   decoLine[ 9]=181;
+   decoLine[10]=194;
+   decoLine[11]=200;
+   decoLine[12]=213;
+   decoLine[13]=222;
+
+   FILE *f= fopen("key.txt", "r");
+   if(f==NULL) error(KeyFile);
+   for(int i=0; i<256; i++)
+     if( fscanf(f, "%d", &keyTable[i])!=1 ) error(KeyFile);
+   fclose(f);
+
+   f=fopen("2010.dat", "rb");
+   if(f!=NULL){
+     int decoLines2;
+     fread(&decoLines2,   sizeof(int), 1, f);
+     if(decoLines2!=decoLines) goto badFile;
+
+     int decoLine2[NAG_LINES];
+     fread(decoLine2,     sizeof(int), decoLines2, f);
+     if( memcmp(decoLine, decoLine2, decoLines) ) goto badFile;
+
+     int best2Size;
+     int keysListSize;
+     fread(&best2Size,    sizeof(int), 1, f);
+     fread(&keysListSize, sizeof(int), 1, f);
+
+     best1=    new int[decoLines * NAG_LINES];
+     best2=    new BEST2[best2Size];
+     keysList= new KEYSLIST[keysListSize];
+
+     fread(best1,    sizeof(int),      decoLines * NAG_LINES, f);
+     fread(best2,    sizeof(BEST2),    best2Size            , f);
+     fread(keysList, sizeof(KEYSLIST), keysListSize         , f);
+
+     badFile:;
+       fclose(f);
+       f=NULL;
+   }
+
+   if(best1==NULL){
+
+     bool *state= new bool[NAG_LINES * NAG_LINES * decoLines];
+     int *keysTempStart= new int[NAG_LINES * NAG_LINES * decoLines];
+     int *keysTemp= new int[KEYS * decoLines];
+     int best2Size=0;
+
+     for(int i=0; i<NAG_LINES * NAG_LINES * decoLines; i++){
+       state[i]=false;
+       keysTempStart[i]=-1;
+     }
+
+
+     for(int key=KEYS-1; key>=0; key--){
+       int perm[NAG_LINES];
+       getPerm(key, perm);
+       for(int clearLine=0; clearLine<NAG_LINES; clearLine++){
+         for(int dL=0; dL<decoLines; dL++){
+           if(perm[clearLine]==decoLine[dL]){
+             int goodLine[2]={
+                clearLine>0           ? perm[clearLine-1] : perm[clearLine+2],
+                clearLine<NAG_LINES-1 ? perm[clearLine+1] : perm[clearLine-2] };
+
+             if(goodLine[1]<goodLine[0]){
+               const int t= goodLine[0];
+               goodLine[0]= goodLine[1];
+               goodLine[1]= t;
+             }
+
+             const int ndx=
+                   dL*NAG_LINES*NAG_LINES + goodLine[0]*NAG_LINES + goodLine[1];
+
+             if(!state[ndx]) best2Size++;
+             state[ndx]=true;
+             keysTemp[key + dL*KEYS]= keysTempStart[ndx];
+             keysTempStart[ndx]= key + dL*KEYS;
+
+           }
+         }
+       }
+     }
+
+     // fix compression for keysList
+     int keysListSize= KEYS*decoLines;
+
+     best1= new int[NAG_LINES * decoLines];
+     best2= new BEST2[best2Size];
+     keysList= new KEYSLIST[keysListSize];
+
+     for(int i=0; i<NAG_LINES * decoLines; i++){
+       best1[i]=-1;
+     }
+
+     int best2Pos=0;
+     int keysListPos=0;
+
+     for(int dL=0; dL<decoLines; dL++){
+       for(int line0=0; line0<NAG_LINES; line0++){
+         const int ndx1= dL*NAG_LINES + line0;
+         for(int line1=line0; line1<NAG_LINES; line1++){
+           const int ndx2= dL*NAG_LINES*NAG_LINES + line0*NAG_LINES + line1;
+
+           if(best1[ndx1]==-1) best1[ndx1]= best2Pos;
+
+           if(keysTempStart[ndx2] == -1) continue;
+
+           best2[best2Pos]= (BEST2){ line:line1, keyNdx:keysListPos };
+
+//           printf("B2 %d %d\n", line1, keysListPos);
+
+
+           int keyP=keysTempStart[ndx2];
+           while(keyP!=-1){
+             keysList[keysListPos]=(KEYSLIST){last:0, key:(keyP & (KEYS-1))};
+             keysListPos++;
+//             printf("KL %d\n", keyP);
+             keyP=keysTemp[keyP];
+           }
+           if(keysListPos>0) keysList[keysListPos-1].last=1;
+//           printf("KL END\n");
+
+           best2Pos++;
+         }
+//         printf("B2 END\n");
+       }
+     }
+
+     delete [] keysTemp;
+     delete [] keysTempStart;
+     delete [] state;
+
+     f=fopen("2010.dat", "wb");
+     if(f==NULL) error(DatWrite);
+
+     fwrite(&decoLines,    sizeof(int), 1, f);
+     fwrite(decoLine,      sizeof(int), decoLines, f);
+
+     fwrite(&best2Size,    sizeof(int), 1, f);
+     fwrite(&keysListSize, sizeof(int), 1, f);
+
+     fwrite(best1,    sizeof(int),      decoLines * NAG_LINES, f);
+     fwrite(best2,    sizeof(BEST2),    best2Size            , f);
+     fwrite(keysList, sizeof(KEYSLIST), keysListSize         , f);
+
+     fclose(f);
+
+   }
+ }
+ first=false;
+
+ BESTCOEFFS *bestCoeffs= new BESTCOEFFS[decoLines];
+ for(int i=0; i<decoLines; i++){
+   bestCoeffs[i].coeff[0]=
+   bestCoeffs[i].coeff[1]=0xFFFFF;
+ }
+
+ byte * const decoLowRes=(byte*) newAlign( (wndx>>dwnSmpSize) * decoLines, 8);
+// printf("%d\n", int(decoLowRes));
+ for(int dL=0; dL<decoLines; dL++){
+   byte * const linep= dispbuf.b + nagLineLogi2Phys(decoLine[dL])*(vgax<<1);
+   byte * const lowResp= decoLowRes + dL*(wndx>>dwnSmpSize);
+   doDwnSmp(lowResp ,linep);
+//   printf("%X\n", int(lowResp));    // FIX alignment (fine now but...)
+ }
+
+ if(istate==1){
+   T2=uclock();
+   sprintf(textbuf[0],"%f ReSample decoLines", (float)(T2-T1)/UCLOCKS_PER_SEC);
+   T1=T2;
+ }
+
+ byte * const lowRes=(byte*) newAlign( (wndx>>dwnSmpSize) * decoLines, 8);
+// printf("%d\n", int(lowRes));
+ for(int line=0; line<NAG_LINES; line++){
+   byte * const linep= dispbuf.b + nagLineLogi2Phys(line)*(vgax<<1);
+//   printf("%d\n", line);
+   doDwnSmp(lowRes, linep);
+//   printf("xxX\n");
+   byte *decoLowResp=decoLowRes;
+   for(int dL=0; dL<decoLines; dL++){
+     if(decoLine[dL]!=line)
+       nagraCorr(int(lowRes), int(decoLowResp), wndx>>dwnSmpSize, int(&bestCoeffs[dL]), line);
+     decoLowResp+= wndx>>dwnSmpSize;
+   }
+ }
+ if(mmx) asm("emms\n\t");
+// printf("H1\n");
+
+ deleteAlign(decoLowRes);
+ deleteAlign(lowRes);
+// printf("H2\n");
+
+ if(istate==1){
+   T2=uclock();
+   sprintf(textbuf[1],"%f Corr", (float)(T2-T1)/UCLOCKS_PER_SEC);
+   T1=T2;
+ }
+
+ int *keysListPos= new int[decoLines];
+ int keysListPoses= 0;
+ for(int dL=0; dL<decoLines; dL++){
+   if(bestCoeffs[dL].line[1] < bestCoeffs[dL].line[0]){
+     const int t= bestCoeffs[dL].line[1];
+     bestCoeffs[dL].line[1]= bestCoeffs[dL].line[0];
+     bestCoeffs[dL].line[0]= t;
+   }
+
+   int l= best1[ bestCoeffs[dL].line[0]     + dL*NAG_LINES ];
+   int r= best1[ bestCoeffs[dL].line[0] + 1 + dL*NAG_LINES ];
+   if(l == r) continue;
+   r--;
+
+   while(l != r){
+     if( int(best2[ (l+r)>>1 ].line) < bestCoeffs[dL].line[1] ) l= (l+r+2)>>1;
+     else                                                       r= (l+r  )>>1;
+   }
+
+   if( int(best2[l].line) != bestCoeffs[dL].line[1] ) continue;
+
+   keysListPos[keysListPoses]= best2[l].keyNdx;
+   keysListPoses++;
+ }
+// printf("H3\n");
+
+ if(istate==1){
+   T2=uclock();
+   sprintf(textbuf[2],"%f GenKeyPointers", (float)(T2-T1)/UCLOCKS_PER_SEC);
+   T1=T2;
+ }
+
+ bool didSome;
+ int lastLowKey=-1;
+ int bestKey=0;
+ int bestNum=0;
+ do{
+   didSome=false;
+   int lowKey=0xFFFF;
+   int lowNum=0;
+   for(int kLP=0; kLP<keysListPoses; kLP++){
+     if(keysListPos[kLP]==-1) continue;
+
+     if( int(keysList[ keysListPos[kLP] ].key)==lastLowKey ){
+       if( keysList[ keysListPos[kLP] ].last==1 ){
+         keysListPos[kLP]=-1;
+         continue;
+       }
+       keysListPos[kLP]++;
+     }
+
+     if( int(keysList[ keysListPos[kLP] ].key) == lowKey ){
+       lowNum++;
+     }
+     if( int(keysList[ keysListPos[kLP] ].key) < lowKey ){
+       lowKey= int(keysList[ keysListPos[kLP] ].key);
+       lowNum=0;
+     }
+     didSome= true;
+   }
+   lastLowKey=lowKey;
+//   printf(" %d %d\n", lowNum, lowKey);
+   if(lowNum>bestNum){
+     bestNum=lowNum;
+     bestKey=lowKey;
+   }
+ }while(didSome);
+
+ delete [] keysListPos;
+
+ int perm[NAG_LINES];
+ getPerm(bestKey, perm);
+ printf("%X\n", bestKey);
+
+ if(istate==1){
+   T2=uclock();
+   sprintf(textbuf[3],"%f FindKey", (float)(T2-T1)/UCLOCKS_PER_SEC);
+   T1=T2;
+ }
+
+ sprintf(textbuf[6],"%d %d vPhase", vPhase, int(frames));
+
+ byte *lowDriftLinep= NULL;
+ for(int i=0; i<NAG_LINES; i++){
+   if(perm[i]>=32 && mabs(perm[i]-32 - i)<5){
+     const cleMod4= (i       + vPhase ) & 3;
+     const encMod4= (perm[i] + vPhase ) & 3;
+
+     lowDriftLinep= dispbuf.b + nagLineLogi2Phys( perm[i] ) * (vgax<<1);
+
+     if(cleMod4!=encMod4) mod4Fix(lowDriftLinep, cleMod4, encMod4);
+
+     break;
+   }
+ }
+
+ for(int clearLine=0 ;clearLine<NAG_LINES; clearLine++){
+   byte * const linep= dispbuf.b + nagLineLogi2Phys( perm[clearLine] ) * (vgax<<1);
+
+   if(perm[clearLine]>=32 && mabs(perm[clearLine]-32 - clearLine)<5){
+     const cleMod4= (clearLine       + vPhase ) & 3;
+     const encMod4= (perm[clearLine] + vPhase ) & 3;
+
+     lowDriftLinep= dispbuf.b + nagLineLogi2Phys( perm[clearLine] ) * (vgax<<1);
+
+     if(cleMod4!=encMod4) mod4Fix(lowDriftLinep, cleMod4, encMod4);
+   }
+   else{
+     for(int x=0; x<(vgax<<1); x+=2){
+       linep[x]= lowDriftLinep[x];
+     }
+   }
+ }
+
+
+
+ if(istate==1){
+   T2=uclock();
+   sprintf(textbuf[5],"%f ColorDeco", (float)(T2-T1)/UCLOCKS_PER_SEC);
+   T1=T2;
+ }
+
+// printf("H4\n");
+/*
+ for(int i=0; i<NAG_LINES; i++){
+   const int p=nagLineLogi2Phys(i);
+   dispbuf.b[p*(vgax<<1)+i*2+1]=255;
+ }
+
+ for(int i=0; i<decoLines; i++){
+   const int p1=nagLineLogi2Phys(decoLine[i]);
+   const int p2=nagLineLogi2Phys(bestCoeffs[i].line[0]);
+   const int p3=nagLineLogi2Phys(bestCoeffs[i].line[1]);
+   for(int j=0; j<20; j++){
+     dispbuf.b[p1*(vgax<<1)+i*20+101+j]=255;
+     dispbuf.b[p2*(vgax<<1)+i*20+101+j]=255;
+     dispbuf.b[p3*(vgax<<1)+i*20+101+j]=255;
+   }
+ }
+*/
+ delete [] bestCoeffs;
+
+ int enc2cleVec[outy];
+ int cle2encVec[outy];
+
+ for(int i=0; i<outy; i++){
+   enc2cleVec[i]=
+   cle2encVec[i]=-1;
+ }
+
+ for(int i=0; i<NAG_LINES; i++){
+   const int encodLine= nagLineLogi2Phys(perm[i]);
+   const int clearLine= i;
+
+   enc2cleVec[ encodLine ]= clearLine;
+   cle2encVec[ clearLine ]= encodLine;
+ }
+
+ byte *copyBuff= new byte[vgax<<1];
+
+ for(int i=0; i<outy; i++){
+   if(cle2encVec[i] == -1 || cle2encVec[i] == i) continue;
+   int k;
+   int j=i;
+   do{
+     k = j;
+     j = enc2cleVec[j];
+   } while(j != i && j != -1);
+   const bool open= (j == -1);
+
+   if(!open){
+     memcpy(copyBuff, dispbuf.cl + i * vgax, wndx << 1);
+     j = i;
+     do{
+       k = j;
+       j = cle2encVec[j];
+       enc2cleVec[k] = k;
+       cle2encVec[k] = k;
+//       printf("closed %d %d\n", j, k );
+       if(j != i)  memcpy(dispbuf.cl + k * vgax, dispbuf.cl + j * vgax, wndx << 1);
+     } while(j != i);
+     memcpy(dispbuf.cl + k * vgax, copyBuff, wndx << 1);
+   }
+   else{
+     j = k;
+     do{
+       k = j;
+       j = cle2encVec[j];
+       enc2cleVec[k] = k;
+       cle2encVec[k] = k;
+//       printf("open %d %d\n", j, k );
+       if(j != -1) memcpy(dispbuf.cl + k * vgax, dispbuf.cl + j * vgax, wndx << 1);
+     } while(j != -1);
+   }
+
+ }
+
+ if(outy == wndy){
+   for(int i=0; i<outy; i+=2){
+     memcpy(dispbuf.cl + (i+1) * vgax, dispbuf.cl + i * vgax, wndx << 1);
+   }
+ }
+
+ delete [] copyBuff;
+
+ if(istate==1){
+   T2=uclock();
+   sprintf(textbuf[4],"%f ReOrder", (float)(T2-T1)/UCLOCKS_PER_SEC);
+   T1=T2;
+ }
+
+
+
+
+
+
+ if(istate==1){
+   T2=uclock();
+   c.init(255, 0, 0, yuvmode);
+   gprint(80,  80,  c.c, textbuf[0]);
+   gprint(90,  90,  c.c, textbuf[1]);
+   gprint(100, 100, c.c, textbuf[2]);
+   gprint(110, 110, c.c, textbuf[3]);
+   gprint(120, 120, c.c, textbuf[4]);
+   gprint(130, 130, c.c, textbuf[5]);
+   gprint(140, 140, c.c, textbuf[6]);
+/*   gprint(150, 150, c.c, textbuf[7]);
+   gprint(160, 160, c.c, textbuf[8]);
+   gprint(170, 170, c.c, textbuf[9]);*/
+   T1=T2;
+ }
+
+
+
+
+#ifdef 0
+
+
+
+
+
+
+
+
+
+
  printf("%d %d %d %d %d %d %d\n", nagStart2, nagEnd2, nagStart1, nagEnd1,
                                   nagSize1, nagSize2, nagSizeAll);
 
@@ -187,11 +829,6 @@ void nag_decrypt(void){
    lowResLine+= wndx >> dwnSmpSize;
  }
 
- if(istate==1){
-   T2=uclock();
-   sprintf(textbuf[9],"%f ReSample", (float)(T2-T1)/UCLOCKS_PER_SEC);
-   T1=T2;
- }
 
  printf("HALLO1\n");
 
@@ -668,24 +1305,6 @@ void nag_decrypt(void){
    }
  }
 
- if(istate==1){
-   T2=uclock();
-   sprintf(textbuf[6],"%f Move", (float)(T2-T1)/UCLOCKS_PER_SEC);
-   sprintf(textbuf[7],"%d Blocks", block_noblack);
-   sprintf(textbuf[8],"%d Loops", corrLoops);
-   c.init(255, 0, 0, yuvmode);
-   gprint(80,  80,  c.c, textbuf[0]);
-   gprint(90,  90,  c.c, textbuf[1]);
-   gprint(100, 100, c.c, textbuf[2]);
-   gprint(110, 110, c.c, textbuf[3]);
-   gprint(120, 120, c.c, textbuf[4]);
-   gprint(130, 130, c.c, textbuf[5]);
-   gprint(140, 140, c.c, textbuf[6]);
-   gprint(150, 150, c.c, textbuf[7]);
-   gprint(160, 160, c.c, textbuf[8]);
-   gprint(170, 170, c.c, textbuf[9]);
-   T1=T2;
- }
 
  delete [] lowRes;
  delete [] block;
@@ -694,5 +1313,7 @@ void nag_decrypt(void){
  delete [] sortedCoeff;
  delete [] bufferInfo;
 
+#endif
+
 }
 

Modified: trunk/2010/2_nag.h
==============================================================================
--- trunk/2010/2_nag.h	(original)
+++ trunk/2010/2_nag.h	Wed Jul  4 03:59:17 2007
@@ -2,47 +2,23 @@
 #ifndef n2_nag_h
 #define n2_nag_h
 
-#define L_ENT 8
 #define MIN_DWN_SMP 1
-#define LAST_MASK 0x8000
-#define NAGRA_BUFFER 32
-#define DO_COEFF 0xFFFE
-#define DONT_COEFF 0xFFFF
-
-enum STATE{
-  eBlack,
-  eMiddle,
-  eSingle,
-  eEnd,
-};
-
-struct BLOCK;
-
-struct LINEINF{
- STATE state;    
- int block;
- int next[2];
- int nextCoeff[2];
-};
-
-struct BLOCK{
- int end[2];
- int limit[2];
- int ent;
-};
+#define KEYS 32768
+#define NAG_LINES 287
 
-struct COEFFSLINE{
- int line[L_ENT];
- int coeff[L_ENT];
+struct BEST2{
+  unsigned line:9;
+  unsigned keyNdx:23;
 };
 
-struct TEMPSORT{
-  int line[2];
-  int coeff;
+struct KEYSLIST{
+  unsigned last:1;
+  unsigned key:15;
 };
 
-struct SORTEDCOEFF{
+struct BESTCOEFFS{
   int line[2];
+  int coeff[2];
 };
 
 void nag_decrypt(void);

Modified: trunk/2010/2_nag_a.asm
==============================================================================
--- trunk/2010/2_nag_a.asm	(original)
+++ trunk/2010/2_nag_a.asm	Wed Jul  4 03:59:17 2007
@@ -8,38 +8,17 @@ extern _mmx
 extern esp_save   
 extern _asm_temp  
 extern _asm_temp2 
-extern _asm_temp3 
-extern _asm_temp4 
-
-global _nagra_corr__Fiiiiiii
-
-%define line2_end    par1
-%define xress_check2 par2
-%define linep        par3
-%define linep2       par4
-%define line2        par5
-%define coeffsLine   par6
-%define databuf      par7
-
 
-%define L_ENT 8
-%define ld_L_ENT 3+2+1
-; 1<<3=8 1<<2=4 1<<1=2     (  line + coeff ) * 4 * L_ENT
-%define firstLine   0
-%define firstCoeff (4*L_ENT)
-%define lastLine   (4*L_ENT-4)
-%define lastCoeff  (8*L_ENT-4)
-
-%define bs1Coeff   (4*L_ENT + 2*L_ENT  -4)
-%define bs2Coeff   (4*L_ENT +   L_ENT  -4)
-%define bs3Coeff   (4*L_ENT +   L_ENT/2-4)
+global _nagraCorr__Fiiiii
 
-%define bs1   (2*L_ENT)
-%define bs2   (  L_ENT)
-%define bs3   (  L_ENT/2)
+%define buf1    par1
+%define buf2    par2
+%define bufSize par3
+%define best    par4
+%define line    par5
 
 
-_nagra_corr__Fiiiiiii:
+_nagraCorr__Fiiiii:
 ; push eax
  push ebx
 
@@ -50,50 +29,31 @@ _nagra_corr__Fiiiiiii:
  push edi
 
  push ebp
- mov ebx, [line2]
-
-loopi:
-
- mov [_asm_temp2], ebx
- mov ebp, [coeffsLine]
-
- shl ebx, ld_L_ENT
- mov edx, [xress_check2]
-
- add ebx, ebp
- mov ecx, [linep2]
-
- mov [_asm_temp3], ebx
- add ecx, edx
-
- mov ebx, [ebx + firstCoeff]
- mov [linep2], ecx
-
- mov esi, [databuf]
- cmp ebx, 0xFFFF
+ mov esi, [buf1]
 
- mov edi, esi
-  jz NEAR End_NoEsp
+ mov edx, [bufSize]
+ mov edi, [buf2]
 
  add esi, edx
  add edi, edx
 
- add esi, ecx
- mov ecx, [linep]
-
  xor edx, -1
- add edi, ecx
-
- inc edx
  mov eax, [_mmx]
 
+ add edx, 8
+ mov ebx, [best]
+
+ mov [_asm_temp], ebx
+ mov ebx, [line]
+
+ mov [_asm_temp2], ebx
+
  mov [esp_save], esp
  mov esp, edx
 
  test eax, eax
   jz NoMMX
 
- int 3
  movq mm3, [mmx_zero]
 
  movq mm0, [esp + esi]
@@ -119,7 +79,7 @@ MMXloop:
  movq mm2, mm0               ;  V 1
  add esp, 8                  ; U
   jnc MMXloop                ;  V 1
- int 3
+
  movq mm0, mm5
  psrlq mm5, 32
 
@@ -183,97 +143,31 @@ NoMMXloop:            
 
 EndMMX: 
 
- mov eax, [ebx + lastCoeff]  ; U | V 1
- cmp ebp, eax                ; U
-  jg TryNext                 ;  V 1
-
- mov eax, [ebx + bs1Coeff]   ; U 1
- cmp eax, ebp                ; U 
- mov esp, [_asm_temp2]       ;  V 1  line2
- sbb ecx, ecx                ; U 
- mov edx, L_ENT*4-8          ;  V 1
- and ecx, bs1                ; U 1
-
- mov eax, [ebx + ecx + bs2Coeff]; U 2 AGI 
- cmp eax, ebp                ; U 1
- sbb esi, esi                ; U 1
- and esi, bs2                ; U 1
- or  ecx, esi                ; U 1
-
- mov eax, [ebx + ecx + bs3Coeff]; U 2 AGI 
- cmp eax, ebp                ; U 1
- sbb esi, esi                ; U 1
- and esi, bs3                ; U 1
- or  ecx, esi                ; U 1
-
-Copy1:  
- mov esi, [ebx + edx + firstLine]      ; U
- mov edi, [ebx + edx + firstCoeff]     ;  V 1
- mov [ebx + edx + 4 + firstLine], esi  ; U
- mov [ebx + edx + 4 + firstCoeff], edi ;  V 1
- sub edx, 4                            ; U
- cmp edx, ecx                          ;  V 1
-  jge Copy1                            ; U  1
- mov [ebx + ecx + firstLine], esp      ; U
- mov [ebx + ecx + firstCoeff], ebp     ;  V 1
-    
-
-TryNext:  
- 
-
- mov ebx, [_asm_temp3]       ; U 1  line_inf[line2]
-
- mov eax, [ebx + lastCoeff]  ; U 2 AGI
+ mov eax, [ebx + 12]         ; U | V 1
  cmp ebp, eax                ; U
   jg End                     ;  V 1
 
- mov eax, [ebx + bs1Coeff]   ; U 1
- cmp eax, ebp                ; U 
- mov esp, [_asm_temp4]       ;  V 1  line
- sbb ecx, ecx                ; U 
- mov edx, L_ENT*4-8          ;  V 1
- and ecx, bs1                ; U 1
+ mov eax, [ebx + 8 ]         ; U
+ mov edx, [_asm_temp2]       ;  V 1
+ cmp ebp, eax                ; U
+  jg JustLast                ;  V 1
 
- mov eax, [ebx + ecx + bs2Coeff]; U 2 AGI 
- cmp eax, ebp                ; U 1
- sbb esi, esi                ; U 1
- and esi, bs2                ; U 1
- or  ecx, esi                ; U 1
+ mov ecx, [ebx     ]         ; U
+ mov [ebx + 12], eax         ;  V 1
+ mov [ebx + 4 ], ecx         ; U
+ mov [ebx     ], edx         ;  V 1
+ mov [ebx + 8 ], ebp         ; U  1
 
- mov eax, [ebx + ecx + bs3Coeff]; U 2 AGI 
- cmp eax, ebp                ; U 1
- sbb esi, esi                ; U 1
- and esi, bs3                ; U 1
- or  ecx, esi                ; U 1
+ jmp End                     ; U  1
+JustLast:
+ 
+ mov [ebx + 4 ], edx         ; U
+ mov [ebx + 12], ebp         ;  V 1
 
-Copy2:  
- mov esi, [ebx + edx + firstLine]      ; U
- mov edi, [ebx + edx + firstCoeff]     ;  V 1
- mov [ebx + edx + 4 + firstLine], esi  ; U
- mov [ebx + edx + 4 + firstCoeff], edi ;  V 1
- sub edx, 4                            ; U
- cmp edx, ecx                          ;  V 1
-  jge Copy2                            ; U  1
- mov [ebx + ecx + firstLine], esp      ; U
- mov [ebx + ecx + firstCoeff], ebp     ;  V 1
-    
 End:  
  
  mov esp, [esp_save]
 
-End_NoEsp:
-
- mov ebx, [line2]
- mov ecx, [line2_end]
-
- inc ebx
-
- cmp ebx, ecx
- mov [line2], ebx
-
-  jl NEAR loopi
-
-
  pop ebp
  pop edi
  pop esi

Modified: trunk/2010/2_nag_a.h
==============================================================================
--- trunk/2010/2_nag_a.h	(original)
+++ trunk/2010/2_nag_a.h	Wed Jul  4 03:59:17 2007
@@ -2,6 +2,6 @@
 #ifndef n2_nag_a_h
 #define n2_nag_a_h
 
-void nagra_corr(int, int, int, int, int, int, int);
+void nagraCorr(int, int, int, int, int);
 
 #endif

Modified: trunk/2010/makefile
==============================================================================
--- trunk/2010/makefile	(original)
+++ trunk/2010/makefile	Wed Jul  4 03:59:17 2007
@@ -20,7 +20,8 @@ O = 2010.o 2_file.o 2_menu.o 2_grafix.o 
 clean: ; del $(O) 2010
 
 2010.o     : 2010.cc     2_all.h 2010.h 2_file.h 2_mouse.h 2_hw.h 2_grafix.h\
-                             2_menu.h 2_mfunc.h 2_move.h 2_71x6.h 2_hw_mem.h
+                             2_menu.h 2_mfunc.h 2_move.h 2_71x6.h 2_hw_mem.h\
+                             2_nag.h
 2_file.o   : 2_file.cc   2_all.h 2_file.h 2010.h 2_hw.h
 2_gfunc.o  : 2_gfunc.cc  2_all.h 2_gfunc.h 2010.h 
 2_grafix.o : 2_grafix.cc 2_all.h 2_grafix.h 2_gfunc.h 2_menu.h 2_hw.h 2_file.h\
@@ -36,7 +37,8 @@ clean: ; del $(O) 2010
 2_wins.o   : 2_wins.cc   2_all.h 2_wins.h 2_gfunc.h 2_71x6.h
 2_crypt.o  : 2_crypt.cc  2_all.h 2_crypt.h 2_71x6.h 2_vc.h 2_nag.h
 2_vc.o     : 2_vc.cc     2_all.h 2_vc.h 2_crypt.h 2_gfunc.h 2_vc_a.h
-2_nag.o    : 2_nag.cc    2_all.h 2_nag.h 2_crypt.h 2_gfunc.h 2_mmx.h 2_nag_a.h
+2_nag.o    : 2_nag.cc    2_all.h 2_nag.h 2_crypt.h 2_gfunc.h 2_mmx.h 2_nag_a.h\
+                             2010.h
 
 2_hw_asm.o : 2_hw_asm.s
 



More information about the Mndiff-dev mailing list