[MN-dev] [mndiff]: r45 - in trunk/2010: 2010.cc 2010.cur 2010.h 2_7116.h 2_71x6.cc 2_all.h 2_crypt.cc 2_file.cc 2_gfunc.cc 2_hw.cc 2_hw_asm.s 2_hw_mem.cc 2_hw_mem.h 2_menu.cc 2_mfunc.cc 2_move.cc 2_nag.cc 2_nag.h 2_nag_a.asm 2_vc.cc 2do makefile

michael subversion at mplayerhq.hu
Wed Jul 4 03:45:27 CEST 2007


Author: michael
Date: Wed Jul  4 03:45:27 2007
New Revision: 45

Log:
version from june 1998


Added:
   trunk/2010/2010.cur   (contents, props changed)
Removed:
   trunk/2010/2_7116.h
Modified:
   trunk/2010/2010.cc
   trunk/2010/2010.h
   trunk/2010/2_71x6.cc
   trunk/2010/2_all.h
   trunk/2010/2_crypt.cc
   trunk/2010/2_file.cc
   trunk/2010/2_gfunc.cc
   trunk/2010/2_hw.cc
   trunk/2010/2_hw_asm.s
   trunk/2010/2_hw_mem.cc
   trunk/2010/2_hw_mem.h
   trunk/2010/2_menu.cc
   trunk/2010/2_mfunc.cc
   trunk/2010/2_move.cc
   trunk/2010/2_nag.cc
   trunk/2010/2_nag.h
   trunk/2010/2_nag_a.asm
   trunk/2010/2_vc.cc
   trunk/2010/2do
   trunk/2010/makefile

Modified: trunk/2010/2010.cc
==============================================================================
--- trunk/2010/2010.cc	(original)
+++ trunk/2010/2010.cc	Wed Jul  4 03:45:27 2007
@@ -1,4 +1,4 @@
-//2010 0.1 Copyright (C) Michael Niedermayer 1998
+//2010 0.1 Copyright (c) 1998 Michael Niedermayer 
 
 #include <stdlib.h>
 #include <pc.h>
@@ -26,7 +26,7 @@
  extern byte *vidbuf;
  extern int mouse_x, mouse_y, mouse_b;
  extern volatile int page_flip;
- extern int xres, yres, xresvb, xresc, vb, mc;
+ extern int vgax, vgay, xresvb, xresc, vb, mc;
  extern int active_meteor;
  extern int me, mx, my;
  extern int yuvmode;
@@ -124,7 +124,7 @@ int main(int argc, char **argv){
  FILE *f;
  int mc2;
 
- printf("2010 0.10 Copyright (C) Michael Niedermayer 1998\n");
+ printf("2010 0.10 Copyright (c) 1998 Michael Niedermayer\n");
 
  atexit(exitt);
 
@@ -269,27 +269,32 @@ int main(int argc, char **argv){
                                                     error(VESA);
 
 
- xres=mib->Xres;
- yres=mib->Yres;
+ vgax=mib->Xres;
+ vgay=mib->Yres;
  if(yuvmode!=0) mc=1;
  else mc=2;
  if(yuvmode==2) mc2=1;
  else mc2=2;
- xresc=xres<<mc;
+ xresc=vgax<<mc;
  bpp=mib->bpp;
  vb=bpp>>3;
- xresvb=xres*vb;
+ xresvb=vgax*vb;
  if(mib->pages>0 && NoFlip==0) page_flip=1;
  else page_flip=0;
 
  printf("Allocating Physical Continous Buffers...\n");
 
-               dispbuf     =alloc_cont(xres * yres << mc2);
- if(single==0) grab_dispbuf=alloc_cont(xres * yres << mc2);
- else grab_dispbuf=dispbuf;
+ xxx *a;
+ if(single==0)
+  a= alloc_cont(vgax * vgay << mc2, 2);
+ else
+  a= alloc_cont(vgax * vgay << mc2, 1);
 
- if(page_flip==0) i= xres * yres * vb;
- else             i= xres * yres * vb << 1;
+ dispbuf     =a[0];
+ grab_dispbuf=a[1];
+
+ if(page_flip==0) i= vgax * vgay * vb;
+ else             i= vgax * vgay * vb << 1;
 
  vidbuf=(byte*)( map(mib->PhysBase, mib->PhysBase+i) - __djgpp_base_address);
   

Added: trunk/2010/2010.cur
==============================================================================
Binary file. No diff available.

Modified: trunk/2010/2010.h
==============================================================================
--- trunk/2010/2010.h	(original)
+++ trunk/2010/2010.h	Wed Jul  4 03:45:27 2007
@@ -31,6 +31,5 @@ typedef enum{
 
 int error(error_code e);
 void exitt(void);
-void find_dup(int num);
 
 #endif

Modified: trunk/2010/2_71x6.cc
==============================================================================
--- trunk/2010/2_71x6.cc	(original)
+++ trunk/2010/2_71x6.cc	Wed Jul  4 03:45:27 2007
@@ -38,18 +38,20 @@ extern volatile int x_field, y_field, on
 extern volatile int xresc, yuvmode, mc;
 extern volatile xxx dispbuf, grab_dispbuf;
 extern volatile int stride;
-extern int xress, yress, yrest, yresst;
+extern int wndx, wndy, outy;
 extern int single;
 extern int init_menu;
 extern int nagra_mode;
 
-extern int xres, yres;
+extern int vgax, vgay;
 
 int v_smooth=1;
 
 int bright=0x80, satur=0x40, contr=0x40;
-int scales_x=0x03, scales_y=0x10;
-int scalee_x=0x00, scalee_y=0x00;
+//int scales_x=0x03, scales_y= 0x10;               3 / 574 / 3 nag 800600
+//int scalee_x=0x03, scalee_y= 0x12;               
+int scales_x=0x03, scales_y= 0x11;           
+int scalee_x=0x03, scalee_y= 0x11;               
 
 int bypass_y=0x0, bypasc_y=0x0;
 
@@ -284,7 +286,7 @@ void grab_next(void){
  }
 
  a_saa7116->dma_end.even=
- a_saa7116->dma_end.odd= grab_dispbuf.phys + xresc*yresst - 1;
+ a_saa7116->dma_end.odd= grab_dispbuf.phys + xresc*outy - 1;
 
     
 }
@@ -309,60 +311,63 @@ void setstd_scale(void){
  init_menu=1;
  if(yuvmode!=0) mc=1;
  else mc=2;
- xresc=xres<<mc;
+ xresc=vgax<<mc;
 
- xress=xres;
+ wndx=vgax;
 
  if(std==NTSC)
-    y_field=240-scales_y+0x10-scalee_y, x_field=640-scales_x+3-scalee_x;
+    y_field=240-scales_y+scalee_y, x_field=640-scales_x+scalee_x;
  else
-    y_field=288-scales_y+0x10-scalee_y, x_field=768-scales_x+3-scalee_x;
+    y_field=288-scales_y+scalee_y, x_field=768-scales_x+scalee_x;
 
- if(yres-70 <= y_field && nagra_mode==0) one_field=1;
+ if(vgay-70 <= y_field && nagra_mode==0) one_field=1;
  else                                    one_field=0;
 
- if(nagra_mode==0 || yres-70 > y_field) yrest= yres;
- else                                   yrest= yres << 1;
+ int yrest;
+ if(nagra_mode==0 || vgay-70 > y_field) yrest= vgay;
+ else                                   yrest= vgay << 1;
 
  if     (one_field==0 && yrest>y_field*2){
-   yresst= y_field*2;
-   xress= int( double(xress) * double(yresst) / double(yrest) );
+   outy= y_field*2;
+   wndx= int( double(wndx) * double(outy) / double(yrest) );
  }
  else if(one_field==1 && yrest>y_field  ){
-   yresst= y_field;
-   xress= int( double(xress) * double(yresst) / double(yrest) );
+   outy= y_field;
+   wndx= int( double(wndx) * double(outy) / double(yrest) );
  }
  else{
-   yresst= yrest;
+   outy= yrest;
  }
 
- if(xress > x_field){
-   yresst= int( double(yresst) * double(x_field) / double(xress) );
-   xress= x_field;
+ if(wndx > vgax){
+//   outy= int( double(outy) * double(x_field) / double(vgax) ); // ?! JOKE
+   wndx= vgax;
  }
 
- xress =(xress  + 7) & 0x3F8;
- yresst=(yresst + 1) & 0x3FE;
+ if(wndx>x_field) wndx=x_field; // no scaling !?
 
- if(xress  > xres ) xres  -=8;
- if(yresst > yrest) yresst-=2;
+ wndx =(wndx  + 7) & 0x3F8;
+ outy=(outy + 1) & 0x3FE;
 
- if(one_field==0) stride=(xres + xres - xress)<<mc;
- else             stride=(xres        - xress)<<mc;
+ if(wndx > vgax ) vgax  -=8;
+ if(outy > yrest) outy-=2;
 
- if(nagra_mode==0 || yres-70 > y_field) yress= yresst;
- else                                   yress= yresst >> 1;
+ if(one_field==0) stride=(vgax + vgax - wndx)<<mc;
+ else             stride=(vgax        - wndx)<<mc;
+
+ if(nagra_mode==0 || vgay-70 > y_field) wndy= outy;
+ else                                   wndy= outy >> 1;
 
 
  if(std==SECAM) write_saa7196(0x0D, 0x85);
- else           write_saa7196(0x0D, 0x84);
+ else           write_saa7196(0x0D, 0x84);  
                            /*   7  VTR/TV mode bit = 1->VTR mode
                                 3  Realtime output mode select bit
                                 2  HREF position select
                                 1  Status byte select
                                 0  SECAM mode bit                          */
  if(std==SECAM) write_saa7196(0x0F, 0xB0);
- else           write_saa7196(0x0F, 0x90);
+ else           write_saa7196(0x0F, 0x90);        
                            /*   7  Automatic Field detection
                                 6  Field Select 0 = 50hz, 1=60hz
                                 5  SECAM cross-colour reduction
@@ -385,26 +390,26 @@ void setstd_scale(void){
                                 4  VRAM port outputs enable
                               3:2  First pixel position in VRO data
                               1:0  FIFO output register select             */
- write_saa7196(0x21, xress & 0xFF);
+ write_saa7196(0x21, wndx & 0xFF);
                            /* 7:0  [7:0] Pixel number per line on output   */
  write_saa7196(0x22, x_field & 0xFF);
                            /* 7:0  [7:0] Pixel number per line on input    */
  write_saa7196(0x23, scales_x);/* 7:0  [7:0] Horizontal start position of scaling win*/
  i=saa7196_buf[0x24] & 0xE0;
- write_saa7196(0x24, i | ((x_field>>6) & 0x0C) | (xress>>8));
+ write_saa7196(0x24, i | ((x_field>>6) & 0x0C) | (wndx>>8));
                            /* 7:5  Horizontal decimation filter
                                 4  [8] Horizontal start position of scaling win
                               3:2  [9:8] Pixel number per line on input
                               1:0  [9:8] Pixel number per line on output   */
- if(one_field==1) write_saa7196(0x25,  yresst     & 0xFF);
- else             write_saa7196(0x25, (yresst>>1) & 0xFF);
+ if(one_field==1) write_saa7196(0x25,  outy     & 0xFF);
+ else             write_saa7196(0x25, (outy>>1) & 0xFF);
                            /* 7:0  [7:0] Line number per output field      */
  write_saa7196(0x26, y_field & 0xFF);
                            /* 7:0  [7:0] Line number per input field       */
  write_saa7196(0x27, scales_y);/* 7:0  [7:0] Vertical start of scaling window  */
  i=saa7196_buf[0x28] & 0xE0;
- if(one_field==1) write_saa7196(0x28, i | ((y_field>>6) & 0x0C) | (yresst>>8));
- else             write_saa7196(0x28, i | ((y_field>>6) & 0x0C) | (yresst>>9));
+ if(one_field==1) write_saa7196(0x28, i | ((y_field>>6) & 0x0C) | (outy>>8));
+ else             write_saa7196(0x28, i | ((y_field>>6) & 0x0C) | (outy>>9));
                            /*   7  Adaptive filter switch
                               6:5  Vertical luminance data processing
                                 4  [8] Vertical start of scaling window 
@@ -414,6 +419,9 @@ void setstd_scale(void){
  write_saa7196(0x29, bypass_y);/* 7:0  [7:0] Vertical bypass start             */
  write_saa7196(0x2A, bypasc_y);/* 7:0  [7:0] Vertical bypass count             */
 
+ printf("%d %d %d %d %d %d %d %d\n",vgax, vgay , wndx, wndy, outy,
+                     y_field , x_field, stride);
+
 }
 
 void init_meteor(void){
@@ -500,7 +508,7 @@ void init_meteor(void){
  write_saa7196(0x05, 0xF4);/* 7:0  Horizontal Sync Start after PH1 for 50hz */
 
 
- write_saa7196(0x06, 0x46);
+ write_saa7196(0x06, 0x46);             //46
                            /*   7  Input mode =0 CVBS, =1 S-Video
                                 6  Pre filter
                               5:4  Aperture Bandpass characteristics
@@ -520,7 +528,8 @@ void init_meteor(void){
                                 2  S-VHS bit
                                 1  GPSW2
                                 0  GPSW1                                   */
- write_saa7196(0x10, 0x00); 
+write_saa7196(0x10, 0x00);   //BAK
+//write_saa7196(0x10, 0x02);   
 // write_saa7196(0x10, 0x04);
                            /*   2  Select HREF Position
                               1:0  Vertical noise reduction                */
@@ -599,7 +608,7 @@ void start_grab(void){
                                                       stride;
  }
  a_saa7116->dma_end.even=
- a_saa7116->dma_end.odd= grab_dispbuf.phys + xresc*yresst - 1;
+ a_saa7116->dma_end.odd= grab_dispbuf.phys + xresc*outy - 1;
 
   
 

Modified: trunk/2010/2_all.h
==============================================================================
--- trunk/2010/2_all.h	(original)
+++ trunk/2010/2_all.h	Wed Jul  4 03:45:27 2007
@@ -7,6 +7,9 @@
 #define is_neg(a) ((a)<0 ?  0 : -1)
 #define is_pos(a) ((a)<0 ? -1 :  0)
 
+#define max(a,b)   ((a)>(b) ? (a) : (b))
+#define min(a,b)   ((a)<(b) ? (a) : (b))
+
 #define u_char unsigned char
 #define u_long unsigned long
 #define u_short unsigned short

Modified: trunk/2010/2_crypt.cc
==============================================================================
--- trunk/2010/2_crypt.cc	(original)
+++ trunk/2010/2_crypt.cc	Wed Jul  4 03:45:27 2007
@@ -9,7 +9,7 @@
 
 extern volatile tv_form std;
 extern volatile crypt_form crypt;
-extern xres, yres, xress, yress, y_field, yresst, yrest;
+extern vgax, vgay, wndx, wndy, y_field, outy;
 extern xxx dispbuf;
 extern volatile int scales_x, scalee_x;
 extern volatile int scales_y, scalee_y;
@@ -41,41 +41,49 @@ static void decomb(void){
  int linep, llinep, line, i, o;
  int j, k;
  int temp[max_x];
- const int yresst1= yresst>>1;
+ int amp[max_x];
+ const int outy1= outy>>1;
 
- const int stride=one_field ? (xres<<1) : (xres<<2);
+ const int stride=one_field ? (vgax<<1) : (vgax<<2);
  const int pass=one_field ? 1 : 2;
- const int end=one_field ? yresst : yresst1;
+ const int end=one_field ? outy : outy1;
 
  for(o=0; o<pass; o++){
 
-   for(i=0; i<max_x; i++) temp[i]=0;
+   for(i=0; i<max_x; i++){
+     temp[i]=0;
+     amp[i]=0;
+   }
 
-   linep=stride * end;
-   if(o) linep+=xres<<1;
-   for(line=end-1; line>=0; line--){
-     linep-=stride;
-     for(i=0; i<xress; i++){
-       j = int(dispbuf.b[linep  + (i<<1)]);
-       k = temp[i] & (~1);
-       if(j>127) j= j - 256;
-       j=(j + j) - k;
-       j-=j>>4;
-       temp[i]=j;
-     }
+   linep=-stride;
+   if(o) linep+=vgax<<1;
+   for(line=0; line<end; line++){
+     linep+=stride;                               
+     for(i=0; i<wndx; i++){                       
+       j = int(dispbuf.b[linep  + (i<<1)]);       
+       k = temp[i];                               
+       if(j>127) j= j - 256;                      
+       j= (j + j) - k;                            
+       temp[i] = j;
+       if(line & 1) amp[i]-=j;
+       else         amp[i]+=j;
+     }                                               
    }
-  
+
+   for(i=0; i<max_x; i++){
+     temp[i]= amp[i]/end;
+   }
+
    linep=-stride;
-   if(o) linep+=xres<<1;
+   if(o) linep+=vgax<<1;
    for(line=0; line<end; line++){
      linep+=stride;
-     for(i=0; i<xress; i++){
+     for(i=0; i<wndx; i++){
        j = int(dispbuf.b[linep  + (i<<1)]);
-       k = temp[i] & (~1);
+       k = temp[i];
        if(j>127) j= j - 256;
        j=(j + j) - k;
        dispbuf.b[linep  + (i<<1)] = (char)(j);
-       j-=j>>4;
        temp[i] = j;
      }                                               
    }
@@ -114,24 +122,24 @@ static void decomb(void){
      " jnz 1b                     \n\t"    // V 1
 
          :
-         : "D" (one_field==1 ? (xres<<1) : (xres<<2)), "S" (dispbuf.b),
-           "d" (xres * yress>>1)
+         : "D" (one_field==1 ? (vgax<<1) : (vgax<<2)), "S" (dispbuf.b),
+           "d" (vgax * wndy>>1)
          : "%eax", "%ebx", "%ecx", "%edx", "%esi");
  */
 }
 
 static void vsmooth(void){
 /*
-     for(int x=0; x < xress; x++){
-       dispbuf.rgb[x + y*xres].r=(  (dispbuf.rgb[x +  y   *xres].r >> 1)
-                                  + (dispbuf.rgb[x + (y+1)*xres].r     )
-                                  + (dispbuf.rgb[x + (y+2)*xres].r >> 1) ) >> 1;
-       dispbuf.rgb[x + y*xres].g=(  (dispbuf.rgb[x +  y   *xres].g >> 1)
-                                  + (dispbuf.rgb[x + (y+1)*xres].g     )
-                                  + (dispbuf.rgb[x + (y+2)*xres].g >> 1) ) >> 1;
-       dispbuf.rgb[x + y*xres].b=(  (dispbuf.rgb[x +  y   *xres].b >> 1)
-                                  + (dispbuf.rgb[x + (y+1)*xres].b     )
-                                  + (dispbuf.rgb[x + (y+2)*xres].b >> 1) ) >> 1;
+     for(int x=0; x < wndx; x++){
+       dispbuf.rgb[x + y*vgax].r=(  (dispbuf.rgb[x +  y   *vgax].r >> 1)
+                                  + (dispbuf.rgb[x + (y+1)*vgax].r     )
+                                  + (dispbuf.rgb[x + (y+2)*vgax].r >> 1) ) >> 1;
+       dispbuf.rgb[x + y*vgax].g=(  (dispbuf.rgb[x +  y   *vgax].g >> 1)
+                                  + (dispbuf.rgb[x + (y+1)*vgax].g     )
+                                  + (dispbuf.rgb[x + (y+2)*vgax].g >> 1) ) >> 1;
+       dispbuf.rgb[x + y*vgax].b=(  (dispbuf.rgb[x +  y   *vgax].b >> 1)
+                                  + (dispbuf.rgb[x + (y+1)*vgax].b     )
+                                  + (dispbuf.rgb[x + (y+2)*vgax].b >> 1) ) >> 1;
      }
   */
 
@@ -155,8 +163,8 @@ static void vsmooth(void){
        "movl %%ebx, -4(%%esi      ) \n\t"    //U         LINE
        " jnz 1b                     \n\t"    // V 1
            :
-           : "D" (xres<<2), "S" (dispbuf.b),
-             "c" (xres * (yress-2) ) 
+           : "D" (vgax<<2), "S" (dispbuf.b),
+             "c" (vgax * (wndy-2) ) 
            : "%eax", "%ebx", "%ecx", "%esi");
 
  }
@@ -188,8 +196,8 @@ static void vsmooth(void){
        "movl %%ebx, -4(%%esi      ) \n\t"    //U         LINE
        " jnz 1b                     \n\t"    // V 1
            :
-           : "D" (xres<<1), "S" (dispbuf.b),
-             "c" (xres * (yress-2) >> 1) 
+           : "D" (vgax<<1), "S" (dispbuf.b),
+             "c" (vgax * (wndy-2) >> 1) 
            : "%eax", "%ebx", "%ecx", "%esi");
 
 

Modified: trunk/2010/2_file.cc
==============================================================================
--- trunk/2010/2_file.cc	(original)
+++ trunk/2010/2_file.cc	Wed Jul  4 03:45:27 2007
@@ -7,7 +7,7 @@
 #include "2_file.h"
 #include "2_hw.h"
 
- extern int xres, yres, xress, yress;
+ extern int vgax, vgay, wndx, wndy;
  extern int fysize;
  extern byte font[4096];
  extern xxx dispbuf;
@@ -29,29 +29,29 @@ void grab(void){
  if((fg=fopen(grab_name, "ab"))==NULL && g_mode==0) error(FileWrite);
 
  bmpi.magic='B'+('M'<<8);
- bmpi.lenght=xress * yress * 3 + 54;
+ bmpi.lenght=wndx * wndy * 3 + 54;
  bmpi.zero1=0;
  bmpi.datstart=54;
  bmpi.palstart=40; //??
- bmpi.xres=xress;
- bmpi.yres=yress;
+ bmpi.xres=wndx;
+ bmpi.yres=wndy;
  bmpi.planes=1;
  bmpi.bits=24;
  bmpi.comp=0;
- bmpi.size=xress * yress * 3;
+ bmpi.size=wndx * wndy * 3;
  bmpi.xpel=0;
  bmpi.ypel=0;
  bmpi.clruse=0;
  bmpi.clrimp=0;
 
  fwrite(&bmpi, sizeof(bmpi), 1, fg);
- for(i=yress-1; i>=0; i--){
-   for(j=0; j<xress; j++){
-     if(yuvmode==0) fwrite((void*)(&dispbuf.rgb[j + i*xres]), 1, 3, fg);
+ for(i=wndy-1; i>=0; i--){
+   for(j=0; j<wndx; j++){
+     if(yuvmode==0) fwrite((void*)(&dispbuf.rgb[j + i*vgax]), 1, 3, fg);
      else {
-       if(j>=xress>>1) break;
+       if(j>=wndx>>1) break;
 
-       mem2vid(fwbuf, dispbuf.yuv + j + (i*xres>>1), 2, 32);
+       mem2vid(fwbuf, dispbuf.yuv + j + (i*vgax>>1), 2, 32);
 
        fwbuf[3]=fwbuf[4];
        fwbuf[4]=fwbuf[5];

Modified: trunk/2010/2_gfunc.cc
==============================================================================
--- trunk/2010/2_gfunc.cc	(original)
+++ trunk/2010/2_gfunc.cc	Wed Jul  4 03:45:27 2007
@@ -5,7 +5,7 @@
 #include "2_all.h"
 #include "2_gfunc.h"
 
- extern int xres, yres, xresc;
+ extern int vgax, vgay, xresc;
  extern int buttons, xpos, ypos, lxpos, lypos;
  extern int fysize;
  extern byte font[4096];
@@ -37,12 +37,12 @@ void xcliped_gprint(int xp, int yp, cons
 
  if(yp>0) iy=0;
  else iy=-yp;
- for(; iy<fysize && (iy+yp<yres); iy++){
+ for(; iy<fysize && (iy+yp<vgay); iy++){
    t1=font[(text<<4)+iy];
-   t3=xp+(yp+iy)*xres;
+   t3=xp+(yp+iy)*vgax;
    if(xp>0) ix=0;
    else ix=-xp;
-   for(; ix<8 && ix+xp<xres; ix++){
+   for(; ix<8 && ix+xp<vgax; ix++){
      if(((t1>>(7-ix)) & 1) == 1){
        if(yuvmode!=0)
          dispbuf.yuv[(ix+t3)/2]=c.yuv;       //FIX ME
@@ -71,17 +71,17 @@ void gprint(int xp, int yp, const s_col 
  }
  else clipym=0;
 
- if(xp+int(strlen(text))*9+1>=xres){
-  if(xp>=xres) return;
-  i=(xres-xp)/9;
+ if(xp+int(strlen(text))*9+1>=vgax){
+  if(xp>=vgax) return;
+  i=(vgax-xp)/9;
   t=text[i];
   tp=i;
   text[i]=0;
  }
 
- if(yp+fysize>yres){
-  if(yp>=yres) return;
-  clipyp=yres-yp;
+ if(yp+fysize>vgay){
+  if(yp>=vgay) return;
+  clipyp=vgay-yp;
  }
  else clipyp=fysize;
 
@@ -156,7 +156,7 @@ void gprint(int xp, int yp, const s_col 
         "popl %%ebp                \n\t"
         :
         : "m" (fysize), "m"(xresc), "m" (&font), "m" (clipyp), "m" (clipym),
-          "a" (c.yuv), "c" (text), "d" (((u_long)dispbuf.cl)+((xp+yp*xres)<<1))
+          "a" (c.yuv), "c" (text), "d" (((u_long)dispbuf.cl)+((xp+yp*vgax)<<1))
         : "%ebx", "%ecx", "%edx", "%esi", "%edi");
  }else{
    asm(//"int $3\n\t"
@@ -215,26 +215,26 @@ void gprint(int xp, int yp, const s_col 
         "9:                        \n\t" 
         :
         : "m" (fysize), "m"(xresc), "m" (&font), "m" (clipyp), "m" (clipym),
-          "a" (c.rgb), "c" (text), "d" (((u_long)dispbuf.cl)+((xp+yp*xres)<<2))
+          "a" (c.rgb), "c" (text), "d" (((u_long)dispbuf.cl)+((xp+yp*vgax)<<2))
         : "%ebx", "%ecx", "%edx", "%esi", "%edi");
    }
  if(t!=0){
-  xcliped_gprint(xres - ((xres-xp) % 9), yp, c, t);
+  xcliped_gprint(vgax - ((vgax-xp) % 9), yp, c, t);
   text[tp]=t;
  }
 }
 
 void dot(const int x, const int y, const s_col c){
 
- if(x>0 && x<xres && y>0 && y<yres){
+ if(x>0 && x<vgax && y>0 && y<vgay){
    if(yuvmode!=0){
-     dispbuf.cl[y*xres+x].lum=c.yuv.y1;
-     dispbuf.cl[(y*xres+x) |   1 ].chrom=c.yuv.v;
-     dispbuf.cl[(y*xres+x) & (~1)].chrom=c.yuv.u;
+     dispbuf.cl[y*vgax+x].lum=c.yuv.y1;
+     dispbuf.cl[(y*vgax+x) |   1 ].chrom=c.yuv.v;
+     dispbuf.cl[(y*vgax+x) & (~1)].chrom=c.yuv.u;
    }else{
-     dispbuf.rgb[y*xres+x].r=c.rgb.r;
-     dispbuf.rgb[y*xres+x].g=c.rgb.g;
-     dispbuf.rgb[y*xres+x].b=c.rgb.b;
+     dispbuf.rgb[y*vgax+x].r=c.rgb.r;
+     dispbuf.rgb[y*vgax+x].g=c.rgb.g;
+     dispbuf.rgb[y*vgax+x].b=c.rgb.b;
    }
  }
 }
@@ -246,27 +246,27 @@ void line(int x1, int y1, int x2, int y2
   if(x2<0) return;
   else y1=(int)((float)(y1-y2)/((float)(x2-x1)+.1E-4)*(float)x2+y2), x1=0;
  }
- else if(x1>=xres){
-  if(x2>=xres) return;
-  else y1=(int)((float)(y1-y2)/((float)(x2-x1)+.1E-4)*(float)(x2-xres+1)+y2), x1=xres-1;
+ else if(x1>=vgax){
+  if(x2>=vgax) return;
+  else y1=(int)((float)(y1-y2)/((float)(x2-x1)+.1E-4)*(float)(x2-vgax+1)+y2), x1=vgax-1;
  }
  if(x2<0) y2=(int)((float)(y2-y1)/((float)(x1-x2)+.1E-4)*(float)x1+y1), x2=0;
- else if(x2>=xres)
-    y2=(int)((float)(y2-y1)/((float)(x1-x2)+.1E-4)*(float)(x1-xres+1)+y1), x2=xres-1;
+ else if(x2>=vgax)
+    y2=(int)((float)(y2-y1)/((float)(x1-x2)+.1E-4)*(float)(x1-vgax+1)+y1), x2=vgax-1;
                                             
 
  if(y1<0){
   if(y2<0) return;
   else x1=(int)((float)(x1-x2)/((float)(y2-y1)+.1E-4)*(float)y2+x2), y1=0;
  }
- else if(y1>=yres){
-  if(y2>=yres) return;
+ else if(y1>=vgay){
+  if(y2>=vgay) return;
   else 
-   x1=(int)((float)(x1-x2)/((float)(y2-y1)+.1E-4)*(float)(y2-yres+1)+x2), y1=yres-1;
+   x1=(int)((float)(x1-x2)/((float)(y2-y1)+.1E-4)*(float)(y2-vgay+1)+x2), y1=vgay-1;
  }
  if(y2<0) x2=(int)((float)(x2-x1)/((float)(y1-y2)+.1E-4)*(float)y1+x1), y2=0;
- else if(y2>=yres)
-    x2=(int)((float)(x2-x1)/((float)(y1-y2)+.1E-4)*(float)(y1-yres+1)+x1), y2=yres-1;
+ else if(y2>=vgay)
+    x2=(int)((float)(x2-x1)/((float)(y1-y2)+.1E-4)*(float)(y1-vgay+1)+x1), y2=vgay-1;
 
  if(x1==x2 && y1==y2) return;
 
@@ -277,13 +277,13 @@ void line(int x1, int y1, int x2, int y2
 
   for(fl=y1<<16; x1<x2; x1++){
    fl+=delta;
-   dispbuf.yuv[(x1+(fl>>16)*xres)>>1]=c; //FIX ME
+   dispbuf.yuv[(x1+(fl>>16)*vgax)>>1]=c; //FIX ME
   }
  }else {
   register int fl,delta;
   if(y1>y2) t=y1,y1=y2,y2=t,t=x1,x1=x2,x2=t,t=1;
-  delta=(x1-x2)*(1<<10)/(y1-y2) + (xres<<10);
-  fl=(x1+y1*xres)<<10;
+  delta=(x1-x2)*(1<<10)/(y1-y2) + (vgax<<10);
+  fl=(x1+y1*vgax)<<10;
   y2-=y1;
   for(; y2!=0; y2--){
    fl+=delta;
@@ -304,14 +304,14 @@ void hline(register int x1, int y1, regi
   x1=0;
   if(x2<0) return;
  }
- if(x2>=xres){
-  x2=xres-1;
-  if(x1>=xres) return;
+ if(x2>=vgax){
+  x2=vgax-1;
+  if(x1>=vgax) return;
  }
- if(y1<0 || y1>=yres) return;
+ if(y1<0 || y1>=vgay) return;
 
- x1+=y1*xres;
- memset(dispbuf.cl + x1, *a, ((x2+y1*xres)-x1+1)<<1);  //FIX HLINE
+ x1+=y1*vgax;
+ memset(dispbuf.cl + x1, *a, ((x2+y1*vgax)-x1+1)<<1);  //FIX HLINE
 }
 /*
 void vline(const int x1, register int y1, register int y2, const s_yuv c){
@@ -323,22 +323,22 @@ void vline(const int x1, register int y1
   y1=0;
   if(y2<0) return;
  }
- if(y2>=yres){
-  y2=yres-1;
-  if(y1>=yres) return;
+ if(y2>=vgay){
+  y2=vgay-1;
+  if(y1>=vgay) return;
  }
- if(x1<0 || x1>=xres) return;
+ if(x1<0 || x1>=vgax) return;
 
- y1=y1*xres+x1;
- y2=(y2-2)*xres+x1;
- for(; y1<y2; y1+=xres){
+ y1=y1*vgax+x1;
+ y2=(y2-2)*vgax+x1;
+ for(; y1<y2; y1+=vgax){
   dispbuf[y1]=c;
-  dispbuf[y1+=xres]=c;
-  dispbuf[y1+=xres]=c;
-  dispbuf[y1+=xres]=c;
+  dispbuf[y1+=vgax]=c;
+  dispbuf[y1+=vgax]=c;
+  dispbuf[y1+=vgax]=c;
  }
- y2+=xres<<1;
- for(; y1<y2; y1+=xres){
+ y2+=vgax<<1;
+ for(; y1<y2; y1+=vgax){
   dispbuf[y1]=c;
  }
 }
@@ -356,17 +356,17 @@ void rect(int x1, int y1, int x2, int y2
   if(x2<0) return;
   x1=0;
  }
- else if(x2>=xres){
-  if(x1>=xres) return;
-  x2=xres-1;
+ else if(x2>=vgax){
+  if(x1>=vgax) return;
+  x2=vgax-1;
  }
  if(y1<0){
   if(y2<0) return;
   y1=0;
  }
- else if(y2>=yres){
-  if(y1>=yres)
-  y2=yres-1;
+ else if(y2>=vgay){
+  if(y1>=vgay)
+  y2=vgay-1;
  }
  y1*=xresc;
  y2*=xresc;

Modified: trunk/2010/2_hw.cc
==============================================================================
--- trunk/2010/2_hw.cc	(original)
+++ trunk/2010/2_hw.cc	Wed Jul  4 03:45:27 2007
@@ -41,7 +41,7 @@
  extern int mouse_x,  mouse_y,  mouse_b;
  extern int mouse_lx, mouse_ly;
  extern byte *vidbuf;
- extern int xres, yres, xresc, xresvb, vb, mc;
+ extern int vgax, vgay, xresc, xresvb, vb, mc;
  extern mouse_sprites cursor;
  extern char *yuv2rgb_lut;
  extern byte *mouse_buff[2];
@@ -188,7 +188,7 @@ void mem2vid(byte *to, s_yuv *from, int 
          "movl (__esp), %%esp               \n\t"
          "popl %%ebp                        \n\t"
          :
-         : "m" (xres<<1),
+         : "m" (vgax<<1),
            "D" (yuv2rgb_lut), "S" (from), "a" (to), "c" (num)
          : "%eax", "%ebx", "%ecx", "%edx", "%esi", "%edi");
 
@@ -269,12 +269,12 @@ void mouse_handler(void){
  mouse_x=mouse_regs.x.cx;
  mouse_y=mouse_regs.x.dx;
 
- if(mouse_x>=xres) mouse_x=xres-1;
- if(mouse_y>=yres) mouse_y=yres-1;
+ if(mouse_x>=vgax) mouse_x=vgax-1;
+ if(mouse_y>=vgay) mouse_y=vgay-1;
                           
- for(j=0; j < cursor.y && mouse_y + j - cursor.hoty < yres; j++){
+ for(j=0; j < cursor.y && mouse_y + j - cursor.hoty < vgay; j++){
    if(j + mouse_y - cursor.hoty>=0){
-     for(i=0  ; i < cursor.x && mouse_x + i - cursor.hotx < xres; i++){
+     for(i=0  ; i < cursor.x && mouse_x + i - cursor.hotx < vgax; i++){
        if(  i + mouse_x - cursor.hotx>=0){
          k=cursor.data[i + (j + mouse_tim*cursor.y)*cursor.x];
    
@@ -298,9 +298,9 @@ void mouse_handler(void){
    }
  }
   
- for(j=0; j < cursor.y && mouse_ly + j - cursor.hoty < yres; j++){
+ for(j=0; j < cursor.y && mouse_ly + j - cursor.hoty < vgay; j++){
    if(j + mouse_ly - cursor.hoty>=0){
-     for(i=0; i < cursor.x && mouse_lx + i - cursor.hotx < xres; i++){
+     for(i=0; i < cursor.x && mouse_lx + i - cursor.hotx < vgax; i++){
        if(  i + mouse_lx - cursor.hotx>=0){
          k=i - mouse_x + mouse_lx;
          l=j - mouse_y + mouse_ly;
@@ -332,7 +332,7 @@ void mouse_handler(void){
 static inline void setdot(int xx, int yy, s_col c){
  int ppvb=xx*vb + yy*xresvb;             
 
- if(page_flip==1) ppvb+=xresvb*yres;
+ if(page_flip==1) ppvb+=xresvb*vgay;
 
   vidbuf[ppvb  ]=c.rgb.b;
   vidbuf[ppvb+1]=c.rgb.g;
@@ -342,7 +342,7 @@ static inline void setdot(int xx, int yy
 static inline s_col getdot(int xx, int yy){
  int ppvb=xx*vb + yy*xresvb;             
 
- if(page_flip==1) ppvb+=xresvb*yres;
+ if(page_flip==1) ppvb+=xresvb*vgay;
 
  return *(s_col* )(vidbuf + ppvb);;
 }
@@ -402,12 +402,12 @@ void init_hw(void){
 
  r.x.ax=7;
  r.x.cx=0;
- r.x.dx=xres;
+ r.x.dx=vgax;
  __dpmi_int(0x33, &r);   //set horizontal cursor range
 
  r.x.ax=8;
  r.x.cx=0;
- r.x.dx=yres;
+ r.x.dx=vgay;
  __dpmi_int(0x33, &r);   //set vertical cursor range
 
  r.x.ax=4;
@@ -506,8 +506,8 @@ void copy_vidbuffer(void){
  int i, j;
 
  if(page_flip==0){
-   for(i=0; i<yres; i++){
-     mem2vid(vidbuf + i*xresvb, (s_yuv*)((byte*)(dispbuf.yuv) + i*xresc), xres, bpp); 
+   for(i=0; i<vgay; i++){
+     mem2vid(vidbuf + i*xresvb, (s_yuv*)((byte*)(dispbuf.yuv) + i*xresc), vgax, bpp); 
 
      if(mouse_y - cursor.hoty <= i && mouse_y + cursor.y - cursor.hoty > i){
        disabled_call_mouse_handler();
@@ -517,29 +517,29 @@ void copy_vidbuffer(void){
        int mouse__ye=mouse_y + cursor.y - cursor.hoty;
 
        if(mouse__x<0) mouse__x=0;
-       else if(mouse__xe>=xres) mouse__xe=xres-1;
-       if(mouse__ye>=yres) mouse__ye=yres-1;
+       else if(mouse__xe>=vgax) mouse__xe=vgax-1;
+       if(mouse__ye>=vgay) mouse__ye=vgay-1;
 
        j=mouse__xe & (~1);
 
-       for(; i < yres && i < mouse__ye; i++ ){
+       for(; i < vgay && i < mouse__ye; i++ ){
          mem2vid(vidbuf + i*xresvb, (s_yuv*)((byte*)(dispbuf.yuv) + i*xresc), mouse__x, bpp);
          mem2vid(vidbuf + i*xresvb + j*vb,
                    (s_yuv*)((byte*)(dispbuf.yuv) + (i*xresc + (j<<mc))),
-                                                            xres - j - 1, bpp);
+                                                            vgax - j - 1, bpp);
        }
        i--;
        mouse_handler_enable=1;
      }
    }
  }else if(page_flip==2){
-   mem2vid(vidbuf+xresvb*yres, dispbuf.yuv, xres*yres, bpp);
+   mem2vid(vidbuf+xresvb*vgay, dispbuf.yuv, vgax*vgay, bpp);
    page_flip=1;
    fresh_cursor=1;
    disabled_call_mouse_handler();
-   set_start_disp(0, yres);
+   set_start_disp(0, vgay);
  }else{
-   mem2vid(vidbuf,            dispbuf.yuv, xres*yres, bpp);
+   mem2vid(vidbuf,            dispbuf.yuv, vgax*vgay, bpp);
    page_flip=2;
    fresh_cursor=1;
    disabled_call_mouse_handler();

Modified: trunk/2010/2_hw_asm.s
==============================================================================
--- trunk/2010/2_hw_asm.s	(original)
+++ trunk/2010/2_hw_asm.s	Wed Jul  4 03:45:27 2007
@@ -25,12 +25,12 @@
 .globl _last_dispbuf
 .globl _grab_dispbuf
 .globl _vidbuf
-.globl _xres
+.globl _vgax
 .globl _xresvb
 .globl _vb
 .globl _mc
 .globl _xresc
-.globl _yres
+.globl _vgay
 .globl _cursor
 .globl _yuvmode
 .globl _locklist
@@ -60,10 +60,9 @@
 .globl _stride
 .globl _single
 .globl _crypt
-.globl _xress
-.globl _yress
-.globl _yrest
-.globl _yresst
+.globl _wndx
+.globl _wndy
+.globl _outy
 .globl _nagra_mode
 .globl _mmx
 .globl _my_cs
@@ -92,12 +91,12 @@ _last_dispbuf: .long 0
 _grab_dispbuf: .long 0
 .long 0
 _vidbuf: .long 0
-_xres: .long 0
+_vgax: .long 0
 _vb: .long 0
 _mc: .long 0
 _xresvb: .long 0
 _xresc: .long 0
-_yres: .long 0
+_vgay: .long 0
 _yuvmode: .long 0
 _locklist: .long 0
 _alloclist: .long 0
@@ -127,10 +126,9 @@ _fresh_cursor: .long 1
 _stride: .long 0
 _single: .long 0
 _crypt: .long 0
-_xress: .long 0
-_yress: .long 0
-_yrest: .long 0
-_yresst: .long 0
+_wndx: .long 0
+_wndy: .long 0
+_outy: .long 0
 _nagra_mode: .long 0
 _mmx: .long 1
 _my_cs: .word 0

Modified: trunk/2010/2_hw_mem.cc
==============================================================================
--- trunk/2010/2_hw_mem.cc	(original)
+++ trunk/2010/2_hw_mem.cc	Wed Jul  4 03:45:27 2007
@@ -17,8 +17,6 @@
  extern volatile VdsList *vdslist;
  extern volatile MapList *maplist;
 
- dds g_vds_info={size: 0, offset: 0, selector: 0, id: 0, phys: 0};
-
 void locklin(void *start, void *end){
  volatile LockList *llp, *llp2;
  __dpmi_meminfo meminfo;
@@ -195,15 +193,9 @@ void dpmi_freeall(volatile AllocList **a
 }
 
 
-xxx alloc_cont(int size){
- int i=0;
- xxx ret;
- u_long lphys, addr, maxaddr;
- int count, maxcount;
- volatile AllocList *llp, *llp2, *temp_al=NULL;
- __dpmi_meminfo meminfo;
- int length;
- dds vds_info;
+xxx *alloc_cont(int size, int num){
+ static xxx ret[2];
+ u_long addr;
 
  size= (size + 4095) & (~4095);     //round up to next 4096 boundray
 
@@ -213,80 +205,72 @@ xxx alloc_cont(int size){
  addr=(u_long)map(2048*1024, 2048*1024 + 1024*1024);  //check if mapping of RAM is ok
  unmap((void*)addr);
 
- if(g_vds_info.phys==0 && g_vds_info.size==0){
-   vds_info=vds_alloc(size<<1);
-   if(vds_info.phys==0xFFFFFFFF)
-     vds_info=vds_alloc(size);
-   else
-     g_vds_info=vds_info;
- }
- else{
-   vds_info=g_vds_info;
-   vds_info.phys+=size;
- }
- if(vds_info.phys==0xFFFFFFFF){
-   length=maxcount=maxaddr=0;
+ bool both;
+ if(num==2){
+   both=true;
+   size<<=1;
+ }else
+   both=false;
 
-   while(size>maxcount){
-     if(dpmi_alloclinlock(&temp_al)==0){
-       dpmi_freeall(&temp_al);
-       error(MemAlloc);
-     }
-  
-     llp=temp_al;
-     lphys=count=addr=0;
-     while(llp!=NULL){
-       if((lphys + 4096) == llp->phys && (llp->phys & (1024*1024*4-1)) != 0)
-         count+=4096;
-       else{
-         count=0;
-         addr=llp->phys;
-       }
-       if(count>maxcount){
-         maxcount=count;
-         maxaddr=addr;
+ dds vds_info;
+ for(int i=0; i<num; i++){
+   int slack=0;
+   for(;;){
+     vds_info= vds_alloc(size + slack);
+
+     if(vds_info.phys==0xFFFFFFFF){
+       if(!both) error(MemAlloc);
+       both=false;
+       size>>=1;
+       slack=0;
+     }else{
+       printf("AllocatedContVDS %d, at Address %lX\n", size + slack , vds_info.phys);
+       fflush(stdout);
+
+       const int j=~(1024*1024*4-1);
+       if(both){
+         if( (  ((vds_info.phys + slack              ) & j)
+              ==((vds_info.phys + slack + (size>>1)-1) & j) )
+          && (  ((vds_info.phys + slack + (size>>1)  ) & j)
+              ==((vds_info.phys + slack + size     -1) & j) )  ) break;
+       }else{
+         if( ((vds_info.phys + slack         ) & j)
+          == ((vds_info.phys + slack + size-1) & j) ) break;
        }
-       lphys=llp->phys;
-  
-       llp=llp->next;
+
+       printf("4MB Boundray violation!\n");
+       fflush(stdout);
+
+       vds_free(&vds_info);
      }
-     length+=4096;
-     printf("Allocated %d, MaxCont %d, at Address %lX\r",length , maxcount, maxaddr);
-     fflush(stdout);
+     slack+=4096;
    }
-   printf("\n");
-  
-   llp=temp_al;
-   while(llp!=NULL){
-     llp2=llp;
-     llp=llp->next;
-     if(llp2->phys<maxaddr){
-       dpmi_freelinlock(llp2, &temp_al);
-     }
-     else if(llp2->phys>maxaddr+maxcount){
-       dpmi_freelinlock(llp2, &temp_al);
-     }
-     else{
-       dpmi_addlinlock(llp2, &alloclist);
-     }
+
+   if(both){
+     size>>=1;
+
+     ret[0].b= (byte*)(map(
+      vds_info.phys + slack       , vds_info.phys + slack + size)
+                                                        - __djgpp_base_address);
+
+     ret[1].b= (byte*)(map(
+      vds_info.phys + slack + size, vds_info.phys + slack + size + size)
+                                                        - __djgpp_base_address);
+     ret[0].phys= vds_info.phys + slack;
+     ret[1].phys= vds_info.phys + slack + size;
+     break;
+   }else{
+     ret[i].b= (byte*)(map(
+      vds_info.phys + slack       , vds_info.phys + slack + size)
+                                                      - __djgpp_base_address);
+     ret[i].phys= vds_info.phys + slack;
    }
- }else{
-   maxaddr=vds_info.phys;
-   printf("AllocatedContVDS %d, at Address %lX\n", size , maxaddr);
-   fflush(stdout);
+
  }
- meminfo.size=size;
- meminfo.address=maxaddr;
- ret.b=(byte*)(map(maxaddr, maxaddr+size) - __djgpp_base_address);
 
- memset(ret.b, 0, size);
+ if(num==1) ret[1]= ret[0];
 
- i=~(1024*1024*4-1);
- if( (maxaddr & i) != ((maxaddr+size) & i) ) error(MemAlloc);
- //FIX ME (should be retried until ok)
- ret.phys=maxaddr;
  return ret;
-
 }
                                    
 void checkVDS(void){               
@@ -360,18 +344,38 @@ dds vds_alloc(int size){
  return vds_info;
 }
 
-void vds_free(dds){
+void vds_free(dds *vds_info){
+ __dpmi_regs r;
+ volatile VdsList *vd, *vd2;
 
- error( error_code(-99) );
- // fix me
+ vd=vdslist;
+ while(vd!=NULL && vd->next!=NULL && vd->next->vds_info.phys!=vds_info->phys)
+   vd=vd->next;
+
+ if(vd==vdslist && vd->vds_info.phys==vds_info->phys ){
+   printf("HALLO1\n");
+   vdslist= vdslist->next;
+   delete vd;
+ }else if(vd!=vdslist && vd->next!=NULL){
+   vd2= vd->next;
+   vd->next= vd->next->next;
+   delete vd2;
+ }
+
+ dosmemput(vds_info, sizeof(dds), __tb); // store in buffer
+ r.x.ax=0x8108;
+ r.x.dx=0;
+ r.x.es=__tb >> 4;
+ r.x.di=0;
 
+ __dpmi_int(0x4B, &r);
 }
 
 void vds_freeall(void){
  __dpmi_regs r;
  volatile VdsList *vd, *vd2;
 
- vd=(VdsList*)vdslist;
+ vd=vdslist;
  while(vd!=NULL){
    dosmemput((dds*)(&vd->vds_info), sizeof(dds), __tb); // store in buffer
    r.x.ax=0x8108;

Modified: trunk/2010/2_hw_mem.h
==============================================================================
--- trunk/2010/2_hw_mem.h	(original)
+++ trunk/2010/2_hw_mem.h	Wed Jul  4 03:45:27 2007
@@ -44,11 +44,11 @@ void dpmi_addlinlock(volatile AllocList 
 u_long dpmi_alloclinlock(volatile AllocList **al);
 void dpmi_freelinlock(volatile AllocList *old, volatile AllocList **al);
 void dpmi_freeall(volatile AllocList **al);
-xxx alloc_cont(int size);
+xxx *alloc_cont(int size, int num);
 void checkVDS(void);
 u_long getphys(u_long);
 dds vds_alloc(int size);
-void vds_free(dds vds_info);
+void vds_free(dds *vds_info);
 void vds_freeall(void);
 void *map(u_long start, u_long end);
 void unmap(void *start);

Modified: trunk/2010/2_menu.cc
==============================================================================
--- trunk/2010/2_menu.cc	(original)
+++ trunk/2010/2_menu.cc	Wed Jul  4 03:45:27 2007
@@ -6,7 +6,7 @@
 #include "2_mfunc.h"
 #include "2_gfunc.h"
 
- extern int xres, yres;
+ extern int vgax, vgay;
  extern int buttons, xpos, ypos, lxpos, lypos;
  extern int fysize;
  extern int me, mx, my;
@@ -166,17 +166,17 @@ void disp_menu(menu *m, int mx, int my, 
  l=0;
  j=mx;
  if(level==1) j += sub_xcorr;
- if(j+mxsize*9>xres){
-  j=xres-mxsize*9;
+ if(j+mxsize*9>vgax){
+  j=vgax-mxsize*9;
   k=sub_xcorr;
   sub_xcorr+=j-mx;
   for(i=0; i<level; i++) sub_x[i]+=sub_xcorr-k;
  }
 
  k=my;
- if((fysize+1)*(mysize)<=yres){
-  if(k+(fysize+1)*(mysize)-2>yres){
-   k=yres-(fysize+1)*(mysize)-2;
+ if((fysize+1)*(mysize)<=vgay){
+  if(k+(fysize+1)*(mysize)-2>vgay){
+   k=vgay-(fysize+1)*(mysize)-2;
    sub_y[level-1]=k;
   }
   else if(my<0){
@@ -184,8 +184,8 @@ void disp_menu(menu *m, int mx, int my, 
    sub_y[level-1]=k;
   }
  }else{
-  if(my+(fysize+1)*(mysize)-2<=yres){
-   k=yres-(fysize+1)*(mysize)-2;
+  if(my+(fysize+1)*(mysize)-2<=vgay){
+   k=vgay-(fysize+1)*(mysize)-2;
    sub_y[level-1]=k;
   }
 
@@ -217,7 +217,7 @@ void disp_menu(menu *m, int mx, int my, 
    if(me==2){
     if(m[i].func!=NULL) m[i].func(i);
    }
-   if(me==3 && sub_m==-1 && level!=1 && (fysize+1)*(mysize)>yres){
+   if(me==3 && sub_m==-1 && level!=1 && (fysize+1)*(mysize)>vgay){
     sub_m=level-1;
    }
   }

Modified: trunk/2010/2_mfunc.cc
==============================================================================
--- trunk/2010/2_mfunc.cc	(original)
+++ trunk/2010/2_mfunc.cc	Wed Jul  4 03:45:27 2007
@@ -6,7 +6,7 @@
 #include "2010.h"
 #include "2_71x6.h"
 
- extern int xres, yres, yrest, y_field, x_field;
+ extern int vgax, y_field, x_field, outy;
  extern int buttons, xpos, ypos, lxpos, lypos;
  extern int me, mx, my;
  extern menu menu_main[mainend+1];
@@ -73,7 +73,7 @@ void hdeci(int num){
  i=hdeci_state;
  hdeci_state=num;
  if(i==menuhtapa && vdeci_state==menuvfila && num!=menuhtapa){
-   double d = ( (one_field==0) ? double(yrest>>1) : double(yrest) ) / double(y_field);
+   double d = ( (one_field==0) ? double(outy>>1) : double(outy) ) / double(y_field);
         if( d <=  4.0/15.0) vdeci(menuvfil2);
    else if( d <= 13.0/15.0) vdeci(menuvfil1);
    else                     vdeci(menuvfilb);
@@ -106,7 +106,7 @@ void vdeci(int num){
  i=vdeci_state;
  vdeci_state=num;
  if(i==menuvfila && hdeci_state==menuhtapa && num!=menuvfila){
-   double d = double(xres) / double(x_field);
+   double d = double(vgax) / double(x_field);
         if( d <=  3.0/15.0) hdeci(menuhtap9);
    else if( d <=  7.0/15.0) hdeci(menuhtap5);
    else if( d <= 11.0/15.0) hdeci(menuhtap4);

Modified: trunk/2010/2_move.cc
==============================================================================
--- trunk/2010/2_move.cc	(original)
+++ trunk/2010/2_move.cc	Wed Jul  4 03:45:27 2007
@@ -5,8 +5,8 @@
 #include "2_all.h"
 #include "2010.h"
 
-extern int xpos, ypos, lxpos, lypos, xres, yres;
-extern int yress, xress;
+extern int xpos, ypos, lxpos, lypos, vgax, vgay;
+extern int wndy;
 extern int infox, infoy, istate;
 extern int conty_b, conty_s, conty_c, contx_b, contx_s, contx_c, cstate;
 extern int fysize;
@@ -41,7 +41,7 @@ void pos_tab::move(int relx, int rely){
     xe+=relx;
 
     if(*xs<0   )  xe+=0    - *xs, *xs=0;
-    if( xe>xres) *xs+=xres -  xe,  xe=xres;
+    if( xe>vgax) *xs+=vgax -  xe,  xe=vgax;
 
  }
  if((fixed & 2)==0){
@@ -49,7 +49,7 @@ void pos_tab::move(int relx, int rely){
     ye+=rely;
 
     if(*ys<0   )  ye+=0    - *ys, *ys=0;
-    if( ye>yres) *ys+=yres -  ye,  ye=yres;
+    if( ye>vgay) *ys+=vgay -  ye,  ye=vgay;
  }
 }
 
@@ -84,23 +84,23 @@ pos_tab * pos_tab_list::new_tab(int fixe
 
 void setmpos(void){
 
- infox=xres-20*9;
+ infox=vgax-20*9;
  infoy=2;
  if(mpos_tab_list.new_tab(0, &infox, infox -1,
                              &infoy, infoy -1,
                           &istate, NULL)           ==NULL) error(MemAlloc);
  contx_b=bright;
- conty_b=yress - 20;
+ conty_b=wndy - 20;
  if(mpos_tab_list.new_tab(2, &contx_b, contx_b + 5,
                              &conty_b, conty_b + 15,
                           &cstate, (void (*)())-1)           ==NULL) error(MemAlloc);
  contx_c=contr;
- conty_c=yress - 40;
+ conty_c=wndy - 40;
  if(mpos_tab_list.new_tab(2, &contx_c, contx_c + 5,
                              &conty_c, conty_c + 15,
                           &cstate, (void (*)())-1)           ==NULL) error(MemAlloc);
  contx_s=satur;
- conty_s=yress - 60;
+ conty_s=wndy - 60;
  if(mpos_tab_list.new_tab(2, &contx_s, contx_s + 5,
                              &conty_s, conty_s + 15,
                           &cstate, (void (*)())-1)           ==NULL) error(MemAlloc);

Modified: trunk/2010/2_nag.cc
==============================================================================
--- trunk/2010/2_nag.cc	(original)
+++ trunk/2010/2_nag.cc	Wed Jul  4 03:45:27 2007
@@ -13,13 +13,9 @@
 #include "2_mmx.h"
 #include "2_nag_a.h"
 
-#define nagra_buff 32
-
-#define check 1
-
-//int check=1;     //grrrrrr nix working
+#define dwnSmp 1
 
-extern xres, yres, xress, yress, yrest, yresst, y_field;
+extern vgax, vgay, wndx, wndy, outy, y_field;
 extern xxx dispbuf;
 extern volatile int scales_x, scalee_x;
 extern volatile int scales_y, scalee_y;
@@ -27,62 +23,89 @@ extern int one_field;
 extern u_long asm_temp, asm_temp4;
 extern int istate;
 extern int yuvmode;
-extern int mmx;
+extern bool mmx;
+
+int blackThreshold= 4000;
 
 static int qsort_block(const void *p1, const void *p2);
 
 static int qsort_block(const void *p1, const void *p2){
-  return ( (b_inf*)(p1) )->up_limit - ( (b_inf*)(p2) )->up_limit;
+  return ( (BLOCK*)(p1) )->limit[0] - ( (BLOCK*)(p2) )->limit[0];
 }
 
 void nag_decrypt(void){
- char textbuf[9][128];
+ char textbuf[10][128];
  color c;
- const int yresst1=yresst>>1;
- const int c2end=int(double(nagra_buff-scales_y+0x10)/double(288-scales_y+0x10-scalee_y) * yresst1 + .5);
- byte copy_buff[max_x<<1];
- int i, j, k;
- int line, line2;
- int linep, linep2;
- l_inf line_inf[max_y];
- b_inf block   [max_y];
+ 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;
- const int check2= (mmx==0) ? check-1 : check;
- union{
-   char datbuf[(xress * yresst1 >> check2) + 16]; // + 16 for out of array thingy
-   double nixnixnix; // for alignment
- };
- nixnixnix=0; // for error det ):
+ char lastDwnSmp= 50;
+ const int dwnSmpSize= mmx ? dwnSmp : dwnSmp-1;
 
- const int corr_block= 8000 / ( 3 * ( (xress >> check2 ) + sizeof(l_inf) ) );
+ printf("%d %d %d %d %d %d %d\n", nagStart2, nagEnd2, nagStart1, nagEnd1,
+                                  nagSize1, nagSize2, nagSizeAll);
+
+ const int corrBlock= 16000 / ( 2*( (wndx >> dwnSmpSize ) + sizeof(COEFFSLINE)) + 100);
 
  T1=uclock();
 
-// printf("%d\n\n\n", c2end);
+ char *lowRes= (char*) new double[(wndx * nagSizeAll >> dwnSmpSize)/8 + 3]; // align 8
+ LINEINF     *lineInf=     new LINEINF    [nagSizeAll];
+ BLOCK       *block=       new BLOCK      [nagSizeAll];
+ COEFFSLINE  *coeffsLine=  new COEFFSLINE [nagSizeAll];
+ SORTEDCOEFF *sortedCoeff= new SORTEDCOEFF[nagSizeAll*L_ENT];
+ char        *bufferInfo=  new char       [nagSizeAll];
 
- linep=( xres<<2 )*( yresst1 - c2end - 1 );
- linep2=-(xress >> check2 );
+ for(int i=0; i<nagSizeAll; i++){
+   if(i<=nagSize2) bufferInfo[i]=1; // 31 free slots
+   else            bufferInfo[i]=int(double(i-nagSize2)/nagSize1*NAGRA_BUFFER+.5);
+//   printf("%d %d\n", bufferInfo[i],i);
+ }
+
+ int line= ( vgax<<1 ) * nagStart1;
+ int lowResLine= 0;
  int blockp;
- for(blockp=0; blockp<yresst1; blockp++){
+ for(blockp=0; blockp<nagSizeAll; blockp++){
    block[blockp].end[0]=
-   block[blockp].end[1]=blockp;
-   line_inf[blockp].state=1;
-   line_inf[blockp].block=blockp;
-   line_inf[blockp].next[0]=
-   line_inf[blockp].next[1]=-1;
+   block[blockp].end[1]= blockp;
+   block[blockp].limit[0]=
+   block[blockp].limit[1]= blockp-nagSize1+1;
+   block[blockp].ent= 1;
+   lineInf[blockp].block= blockp;
+   lineInf[blockp].next[0]=
+   lineInf[blockp].next[1]= 0xFFFF;
+   lineInf[blockp].nextCoeff[0]=
+   lineInf[blockp].nextCoeff[1]= 0xFFFF;
 
-   linep+=xres<<2;
-   linep2+=xress >> check2;
-   if(blockp==c2end) linep=xres<<1;
 
-   if(mmx==0){
+   if(blockp==nagSize1) line= ( vgax<<1 ) * nagStart2;
+
+   int avg;
+   if(mmx){
      asm(//"int $3 \n\t"
          "pushl %%ebp          \n\t"
+         "cmpb (%%eax), %%cl   \n\t"
+         " je 5f               \n\t"
+         "movb %%cl, 3f-1      \n\t"
+         "movb %%cl, (%%eax)   \n\t"
+         "movl $1, %%eax       \n\t"
+         "shll %%cl, %%eax     \n\t"
+         "movl %%eax, 4f-4     \n\t"
+
+         "5:                   \n\t"
+         "xor %%ecx, %%ecx     \n\t"
 
          "1:                   \n\t"
-         "movw (%%edi), %%ax   \n\t"   // U        load 32 byte in L1-cache
+         "movb (%%edi), %%al   \n\t"   // U        load 32 byte in L1-cache
          "xorl %%ebx, %%ebx    \n\t"   //  V 1
-         "movl %1, %%ebp       \n\t"   // U
+         "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
@@ -91,29 +114,44 @@ void nag_decrypt(void){
          "addl $2, %%esi       \n\t"   //  V 1
          "decl %%ebp           \n\t"   // U
          " jnz 2b              \n\t"   //  V 1
-         "addl $2, %%edi       \n\t"   // U
+         "incl %%edi           \n\t"   // U
          "addl %%eax, %%ebx    \n\t"   //  V 1
-         "shrl %0, %%ebx       \n\t"   // U 
+         "shrl $5, %%ebx       \n\t"   // U  1
+         "3:                   \n\t"
+         "addl %%ebx, %%ecx    \n\t"   // U
          "decl %%edx           \n\t"   //  V 1
-         "movw %%bx, -2(%%edi) \n\t"   // U
+         "movb %%bl, -1(%%edi) \n\t"   // U
          " jnz 1b              \n\t"   //  V 1
     
          "popl %%ebp            \n\t"
-          : 
-          : "I" (check), "i" (1<<check),
-            "S" (dispbuf.b + linep + 1) ,
-            "d" (xress>>check) ,
-            "D" (datbuf + linep2) 
+          : "=c" (avg)
+          : "c" (dwnSmp), "a"(&lastDwnSmp),
+            "S" (dispbuf.b + line + 1) ,
+            "d" (wndx>>dwnSmp) ,
+            "D" (lowRes + lowResLine) 
           : "%eax", "%ebx", "%edx", "%esi", "%edi");
+
    }
    else{
      asm(//"int $3 \n\t"
          "pushl %%ebp          \n\t"
+         "cmpb (%%eax), %%cl   \n\t"
+         " je 5f               \n\t"
+         "movb %%cl, 3f-1      \n\t"
+         "movb %%cl, (%%eax)   \n\t"
+         "movl $1, %%eax       \n\t"
+         "shll %%cl, %%eax     \n\t"
+         "movl %%eax, 4f-4     \n\t"
+
+         "5:                   \n\t"
+         "xor %%ecx, %%ecx     \n\t"
+
 
          "1:                   \n\t"
-         "movb (%%edi), %%al   \n\t"   // U        load 32 byte in L1-cache
+         "movw (%%edi), %%ax   \n\t"   // U        load 32 byte in L1-cache
          "xorl %%ebx, %%ebx    \n\t"   //  V 1
-         "movl %1, %%ebp       \n\t"   // U
+         "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
@@ -122,428 +160,454 @@ void nag_decrypt(void){
          "addl $2, %%esi       \n\t"   //  V 1
          "decl %%ebp           \n\t"   // U
          " jnz 2b              \n\t"   //  V 1
-         "incl %%edi           \n\t"   // U
+         "addl $2, %%edi       \n\t"   // U
          "addl %%eax, %%ebx    \n\t"   //  V 1
-         "shrl %0, %%ebx       \n\t"   // U 
+         "shrl $5, %%ebx       \n\t"   // U  1
+         "3:                   \n\t"
+         "addl %%ebx, %%ecx    \n\t"   // U
          "decl %%edx           \n\t"   //  V 1
-         "movb %%bl, -1(%%edi) \n\t"   // U
+         "movw %%bx, -2(%%edi) \n\t"   // U
          " jnz 1b              \n\t"   //  V 1
     
          "popl %%ebp            \n\t"
-          : 
-          : "I" (check), "i" (1<<check),
-            "S" (dispbuf.b + linep + 1) ,
-            "d" (xress>>check) ,
-            "D" (datbuf + linep2) 
+          : "=c" (avg)
+          : "c" (dwnSmp), "a"(&lastDwnSmp),
+            "S" (dispbuf.b + line + 1) ,
+            "d" (wndx>>dwnSmp) ,
+            "D" (lowRes + lowResLine) 
           : "%eax", "%ebx", "%edx", "%esi", "%edi");
-
    }
+
+   if(avg>blackThreshold)
+     lineInf[blockp].state= eSingle;
+   else
+     lineInf[blockp].state= eBlack;
+
+   line+= vgax<<2;
+   lowResLine+= wndx >> dwnSmpSize;
  }
 
  if(istate==1){
    T2=uclock();
-   sprintf(textbuf[8],"%f ReSample", (float)(T2-T1)/UCLOCKS_PER_SEC);
+   sprintf(textbuf[9],"%f ReSample", (float)(T2-T1)/UCLOCKS_PER_SEC);
    T1=T2;
  }
 
- for(i=0; i<yresst1; i++){               
-   for(j=0; j<l_ent; j++){
-     line_inf[i].coeff[j]= 0x7FFFFFF;
-//     line_inf[i].line[j]= 1;
-   }
- }
+ printf("HALLO1\n");
 
- int corr_loops=0;
- long T_corr=0, T_merge=0;
- int blockpl;
+ int corrLoops=0;
+
+ bool first=true;
+ bool didSome;
+ long T_corr=0, T_radix=0, T_merge=0;
  do{
-   blockpl= blockp;
-   for(i=0; i<max_y; i++){
-     const int temp=line_inf[i].coeff[l_ent-1];       
-     for(j=0; j<l_ent; j++){
-       line_inf[i].coeff[j]=temp + (temp>>1) ;
+   didSome=false;
+
+   /* clear coeffs */
+   for(int i=0; i<nagSizeAll; i++){
+     for(int j=0; j<L_ENT; j++){
+       if(lineInf[i].state>=eSingle)
+         coeffsLine[i].coeff[j]= DO_COEFF;
+       else
+         coeffsLine[i].coeff[j]= DONT_COEFF;
+       coeffsLine[i].line[j]=  0xFFFF;
      }
    }
+   printf("HALLOA\n");
 
-   int s_line, s_line2;
-   int s_linep, s_linep2;
+   /* corr calc */
 
-   s_linep= -((xress >> check2) * (corr_block + 1) );
-   for(s_line= 0; s_line < yresst1; s_line += corr_block){
-     s_linep2 = s_linep;
-     s_linep += (xress >> check2) * corr_block;
+   int s_line0, s_line1;
+   int s_linep0, s_linep1;
+   int line0, line1;
+   int linep0, linep1;
 
-     for(s_line2= s_line; s_line2 < yresst1; s_line2 += corr_block){
-       s_linep2 += (xress >> check2) * corr_block;
+   s_linep0=0;
+   for(s_line0= 0; s_line0 < nagSizeAll; s_line0 += corrBlock){
+     s_linep1 = s_linep0;
 
-       linep = s_linep;
-       for(line= s_line; line < yresst1 && line < (s_line + corr_block); line++){
-         linep += xress >> check2;
+     for(s_line1= s_line0; s_line1 < nagSizeAll; s_line1 += corrBlock){
 
-         if(line_inf[line].state == 0) continue;
+       linep0 = s_linep1 - (wndx >> dwnSmpSize);
+       for(line0= s_line1; line0 < min(nagSizeAll, s_line1 + corrBlock); line0++){
 
-         if(s_line == s_line2){
-           linep2 = linep;
-           line2 = line + 1;
+         linep0 += wndx >> dwnSmpSize;
+
+         if(coeffsLine[line0].coeff[0]==DONT_COEFF) continue;
+
+         if(s_line0 == s_line1){
+           linep1 = linep0 + (wndx>>dwnSmpSize);
+           line1 = line0 + 1;
+           if(line1 >= nagSizeAll || line1 >= s_line1 + corrBlock) continue;
          }
          else{
-           linep2 = s_linep2;
-           line2 = s_line2;
+           linep1 = s_linep0;
+           line1 = s_line0;
          }
 
-         asm_temp=(u_long)(line_inf + line);
-         asm_temp4=line;
+         asm_temp=(u_long)(coeffsLine + line0);
+         asm_temp4=line0;
+
+//         printf("%d %d %d %d %d %d %d %d %d\n", corrBlock, line0, line1,
+//             linep0, linep1, s_line0, s_line1, s_linep0, s_linep1);
+         nagra_corr(min(nagSizeAll, s_line0 + corrBlock),
+                    wndx >> dwnSmpSize,
+                    linep0,
+                    linep1 - (wndx >> dwnSmpSize),
+                    line1,
+                    int(coeffsLine),
+                    int(lowRes)                             );
 
-         nagra_corr((yresst1 < (s_line2  + corr_block) ) ?
-                     yresst1 : (s_line2  + corr_block),
-                    xress >> check2,
-                    linep,
-                    linep2,
-                    line2,
-                    int(line_inf),
-                    int(datbuf)                             );
        }
+       s_linep1 += (wndx >> dwnSmpSize) * corrBlock;
+
      }
-   }
+     s_linep0 += (wndx >> dwnSmpSize) * corrBlock;
 
-   j=100000 / ( xress>>check );
-   for(i=0; i<yresst1; i++){
-     const int x1 = line_inf[i].coeff[0      ] * j;
-     const int x2 = line_inf[i].coeff[l_ent-1] * j;
-     if(x1+x2 < 500000 && x2-x1 < 30000) line_inf[i].state=0;
    }
 
-   if(mmx!=0) asm("emms  \n\t");
+   if(mmx) asm("emms  \n\t");
+   printf("HALLOB\n");
 
    if(istate==1){
      T2=uclock();
      T_corr+=T2-T1;
      T1=T2;
    }
+      // save line info ...
+    /* radix sort */
+   int coeffSize= 0;
+   int stat[2][257];
+   for(int i=0; i<257; i++){
+     stat[0][i]=
+     stat[1][i]=0;
+   }
+   for(int i=0; i<nagSizeAll; i++){
 
-   int did_some;
-   do{
-     did_some=0;
+     for(int j=0; j<L_ENT; j++){
+       if(coeffsLine[i].line[j]==0xFFFF) break;
+       stat[0][ (  coeffsLine[i].coeff[j] & 0xFF ) + 1 ]++;
+       stat[1][ ( (coeffsLine[i].coeff[j] >> 8)  ) + 1 ]++;
+       coeffSize++;
+     }
+//     if(coeffsLine[i].line[min(j, L_ENT-1)]==0xFFFF) continue;
 
-//   printf("START\n\n");
+     if(first){
+       lineInf[i].nextCoeff[0]= coeffsLine[i].coeff[0];   //
+       lineInf[i].nextCoeff[1]= coeffsLine[i].coeff[1];   // for line integration
+       lineInf[i].next[0]=      coeffsLine[i].line[0];    //
+       lineInf[i].next[1]=      coeffsLine[i].line[1];    //
+     }
+     coeffsLine[i].line[L_ENT-1]|= LAST_MASK;             // mark last coeff per line
+                                  
+   }
+   for(int i=2; i<256; i++){
+     stat[0][i]+= stat[0][i-1];
+     stat[1][i]+= stat[1][i-1];
+   }
+   TEMPSORT *tempSort= new TEMPSORT[coeffSize];
+   for(int i=0; i<nagSizeAll; i++){
+     for(int j=0; j<L_ENT; j++){
+       if(coeffsLine[i].line[j]==0xFFFF) break;
+       tempSort[ stat[0][ coeffsLine[i].coeff[j] & 0xFF ] ].coeff=
+                                                     coeffsLine[i].coeff[j];
+       tempSort[ stat[0][ coeffsLine[i].coeff[j] & 0xFF ] ].line[0]=i;
+       tempSort[ stat[0][ coeffsLine[i].coeff[j] & 0xFF ] ].line[1]=
+                                                  coeffsLine[i].line[j];
 
-     for(int blocki=0; blocki<blockp; blocki++){
-       if(line_inf[ block[blocki].end[0] ].state == 0) continue;
+                 stat[0][ coeffsLine[i].coeff[j] & 0xFF ]++;
+     }
+   }
+   for(int i=0; i<coeffSize; i++){
+     sortedCoeff[ stat[1][ tempSort[i].coeff >> 8 ] ].line[0]=
+                                                     tempSort[i].line[0];
+     sortedCoeff[ stat[1][ tempSort[i].coeff >> 8 ] ].line[1]=
+                                                     tempSort[i].line[1];
 
-       int endlinei[2]={l_ent, l_ent};
-       for(i=0; i<l_ent; i++){
-         if( endlinei[0]==l_ent &&
-             line_inf[ line_inf[ block[blocki].end[0] ].line[i] ].state != 0 &&
-                       line_inf[ block[blocki].end[0] ].line[i] != block[blocki].end[1] ){
-           endlinei[0]=i;
-         }  
-         if( endlinei[1]==l_ent &&
-             line_inf[ line_inf[ block[blocki].end[1] ].line[i] ].state != 0 &&
-                       line_inf[ block[blocki].end[1] ].line[i] != block[blocki].end[0] ){
-           endlinei[1]=i;
-         }  
-       }
-  
-       if(endlinei[0]==l_ent && endlinei[1]==l_ent){
-//         printf("noLines!\n");
-         continue;
-       }
-               // can't handle line + block 
-       if(block[blocki].end[0] == block[blocki].end[1]
-          && line_inf[ line_inf[ block[blocki].end[0] ].line[ endlinei[0] ]
-                      ].state == 2)
-         continue;
-  
-       int endi=0;
-       if(endlinei[0]==l_ent || ( endlinei[1]!=l_ent &&
-            line_inf[ block[blocki].end[0] ].coeff[ endlinei[0] ] >
-            line_inf[ block[blocki].end[1] ].coeff[ endlinei[1] ]   ) ) endi=1;
-       if(endlinei[0]==l_ent || endlinei[1]==l_ent ||
-          block[blocki].end[0] == block[blocki].end[1]) i=1;
-       else                                             i=0;
-       for(; i<2; i++){
-         const int line1= block[blocki].end[endi];
-         const int line2= line_inf[line1].line[ endlinei[endi] ];
-  
-         const int block2= line_inf[line2].block;    //FIX THIS (CRASHED)
-         const int endi2= block[block2].end[0] == line2 ? 0 : 1;   //FIX THIS CRASHED 
-  
-         int backlinei[2]={l_ent, l_ent};
-         for(j=0; j<l_ent; j++){
-           if( backlinei[0]!=l_ent && 
-               line_inf[ line_inf[ line2 ].line[j] ].state != 0 &&
-               line_inf[ line2 ].line[j] != block[block2].end[endi2 ^ 1] ){
-             backlinei[1]=j;
-             break;
-           }  
-           if( backlinei[0]==l_ent && 
-               line_inf[ line_inf[ line2 ].line[j] ].state != 0 &&
-               line_inf[ line2 ].line[j] != block[block2].end[endi2 ^ 1] ){
-             backlinei[0]=j;
-             if(line_inf[ line2 ].line[j] == line1) break;
-           }  
-         }
-         if(backlinei[1] == l_ent) backlinei[1] = backlinei[0];
+                  stat[1][ tempSort[i].coeff >> 8 ]++;
+   }
 
-         else if( line_inf[line2].state == 1 &&
-                  line_inf[line2].line[ backlinei[1] ] == line1 ){
+   delete [] tempSort;
 
-           const int line3=  line_inf[ line2 ].line[ backlinei[0] ];
-           const int block3= line_inf[ line3 ].block;
-           const int endi3=  block[block3].end[0] == line3 ? 0 : 1;
-           for(j=0; j<l_ent; j++){
-             if( line_inf[ line_inf[ line3 ].line[j] ].state != 0 &&
-                 line_inf[ line3 ].line[j] != block[block3].end[endi3 ^ 1] ){
-               if(line_inf[ line3 ].line[j] == line2) backlinei[0]= l_ent;
-               break;
-             }  
-           }
-         }
+   if(istate==1){
+     T2=uclock();
+     T_radix+=T2-T1;
+     T1=T2;
+   }
+   printf("HALLOC\n");
 
-         if(backlinei[0] == l_ent){
-//           printf("noLines2!\n");
-           continue;
-         }
+   for(int coeffp=0; coeffp<coeffSize; coeffp++){
+     if(   sortedCoeff[coeffp].line[0]==0xFFFF
+        || sortedCoeff[coeffp].line[1]==0xFFFF ) break;
 
-         if(line_inf[line2].line[ backlinei[0] ] == line1 ||
-            ( line_inf[line2].state == 1 &&
-              line_inf[line2].line[ backlinei[1] ] == line1 ) ){
-     
-//           printf("%d %d  %d %d  %d %d  %d %d\n", line1, line2, blocki, block2,
-//           line_inf[line1].state, line_inf[line2].state,
-//           block[blocki].end[0], block[blocki].end[1]);
-     
-//           printf("%d %d  %d %d\n",
-//           line_inf[line1].next[1], line_inf[line1].next[0],
-//           line_inf[line2].next[1], line_inf[line2].next[0]);
+     int line0= sortedCoeff[coeffp].line[0];
+     int line1= sortedCoeff[coeffp].line[1];
 
-           did_some=1;
+     STATE state0= lineInf[ line0 & (~LAST_MASK) ].state;
+     STATE state1= lineInf[ line1 & (~LAST_MASK) ].state;
 
-           line_inf[line1].state++;
-           line_inf[line2].state++;
-           if(line_inf[line1].state == 3) line_inf[line1].state= 0;
-           if(line_inf[line2].state == 3) line_inf[line2].state= 0;
+       // last_mask is saved in opposit line 
+     if(line0 & LAST_MASK){
+       if(state1 >= eSingle) break;
+     }
+     if(line1 & LAST_MASK){
+       if(state0 >= eSingle) break;
+     }
 
-           line_inf[line1].next[1] = line_inf[line1].next[0];
-           line_inf[line2].next[1] = line_inf[line2].next[0];
+     line0 &= ~LAST_MASK;
+     line1 &= ~LAST_MASK;
 
-           line_inf[line1].next[0] = line2;
-           line_inf[line2].next[0] = line1;
+     // eBlack eMiddle eSingle eEnd
+     if(state0>state1){
+       const STATE tempS= state0;
+       state0= state1;
+       state1= tempS;
+       const int tempL= line0;
+       line0= line1;
+       line1= tempL;
+     }
 
-//           printf("%d %d  %d %d\n",
-//           line_inf[line1].next[1], line_inf[line1].next[0],
-//           line_inf[line2].next[1], line_inf[line2].next[0]);
+     const int block0= lineInf[ line0 ].block;
+     const int block1= lineInf[ line1 ].block;
 
-           if(blocki != blockp-1){
-             line_inf[ block[blockp-1].end[0] ].block = block2;
-             line_inf[ block[blockp-1].end[1] ].block = block2;
+     if(state0==eBlack) continue;
 
-             line_inf[ block[block2].end[endi2 ^ 1] ].block = blocki;
- 
-             block[blocki].end[endi]= block[block2].end[endi2 ^ 1];
+     if(state0==eMiddle){
+       if(state1==eSingle) continue; // fix line integration
+       else continue;
+     }
 
-             block[block2]= block[blockp - 1];
-           }
-           else{
+     if(line0<0  || line0>=nagSizeAll) printf("line0 %d\n", line0);
+     if(line1<0  || line1>=nagSizeAll) printf("line1 %d\n", line1);
+     if(block0<0 || block0>=blockp   ) printf("block0 %d %d\n", block0, blockp);
+     if(block1<0 || block1>=blockp   ) printf("block1 %d %d\n", block1, blockp);
 
-             line_inf[ block[blocki].end[endi ^ 1] ].block = block2;
+     if(block1==block0) continue;
 
-             block[block2].end[endi2]= block[blocki].end[endi ^ 1];
-           }
- 
-           blockp--;
- 
- 
+     // block + line / line + line / block + block
 
-           break;
-         }
-         endi ^= 1;
+     const int whichEnd[2]= { line0==block[block0].end[0] ? 0 : 1,
+                              line1==block[block1].end[0] ? 0 : 1 };
+
+     const int limit[2]= { max(block[block0].limit[ whichEnd[0] ^ 1 ],
+                               block[block1].limit[ whichEnd[1]     ]
+                                                   -block[block0].ent ),
+                           max(block[block1].limit[ whichEnd[1] ^ 1 ],
+                               block[block0].limit[ whichEnd[0]     ]
+                                                   -block[block1].ent ) };
+
+     const int ori= limit[0] < limit[1] ? 0 : 1;
+
+     const int end=limit[ori] + block[block0].ent + block[block1].ent;
+
+     if(end > nagSizeAll)
+       continue;
+
+     const int start=min( block[block0].limit[0],
+                          block[block1].limit[0] );
+
+     int slots=0;
+     {
+       int i;
+       for(i=start; i<end; i++){
+         if( i >= block[block0].limit[0]
+          && i <  block[block0].limit[0] + block[block0].ent) slots++;
+         if( i >= block[block1].limit[0]
+          && i <  block[block1].limit[0] + block[block1].ent) slots++;
+         if( i >= limit[ori] && i < end                     ) slots--;
+         if(i>=0 && bufferInfo[i] + slots > NAGRA_BUFFER) break;
        }
+       if(i<end) continue;
+     }     
+
+       // from here merge is certain
 
+     for(int i=start; i<end; i++){
+       if( i >= block[block0].limit[0]
+        && i <  block[block0].limit[0] + block[block0].ent) slots++;
+       if( i >= block[block1].limit[0]
+        && i <  block[block1].limit[0] + block[block1].ent) slots++;
+       if( i >= limit[ori] && i < end                     ) slots--;
+       if(i>=0) bufferInfo[i]+= slots;
      }
+             
+     const int newBlock= min(block0, block1);
+     const int freeBlock= max(block0, block1);
 
-   } while(did_some!=0);
+     lineInf[ line0 ].next[1]     = lineInf[ line0 ].next[0];
+     lineInf[ line1 ].next[1]     = lineInf[ line1 ].next[0];
 
-   if(istate==1){
-     T2=uclock();
-     T_merge+=T2-T1;
-     T1=T2;
-   }
+     lineInf[ line0 ].next[0]     = line1;
+     lineInf[ line1 ].next[0]     = line0;
 
-   corr_loops++;
+     lineInf[ line0 ].state=
+     lineInf[ line1 ].state= eMiddle;
 
- } while( blockpl > blockp*3  &&  corr_loops < 2);
+     const int oriBlock[2]= { ori==0 ? block0 : block1,
+                              ori==0 ? block1 : block0 };
 
-// printf("\n%d\n\n", blockp);
+     BLOCK temp;
+     temp.end[0]= block[ oriBlock[0] ].end[ whichEnd[ori    ] ^ 1 ];
+     temp.end[1]= block[ oriBlock[1] ].end[ whichEnd[ori ^ 1] ^ 1 ];
 
- if(istate==1){
-   sprintf(textbuf[0],"%f Corr", (float)(T_corr)/UCLOCKS_PER_SEC);
-   sprintf(textbuf[1],"%f Block Handling", (float)(T_merge)/UCLOCKS_PER_SEC);
-   T2=uclock();
-   T1=T2;
- }
+     lineInf[ temp.end[0] ].state=
+     lineInf[ temp.end[1] ].state= eEnd;
 
+     lineInf[ temp.end[0] ].block=
+     lineInf[ temp.end[1] ].block= newBlock;
 
- for(i=0; i<blockp; i++){
-   line= block[i].end[0];
-   line2=-1;
+     temp.ent= block[block0].ent + block[block1].ent;
+     temp.limit[0]= limit[ori    ];
+     temp.limit[1]= limit[ori ^ 1];
 
-   int avg=0;
-   int num=0;
-   int up_limit=0, up_limit2=0;
-   while(0==0){
-     avg+=line;
-     if(line - num >= up_limit ){
-       up_limit  = line - num;
-     }
-     if(line + num >= up_limit2){
-       up_limit2  = line + num;
-     }
-     num++;
-     if(line_inf[line].next[0] == line2){
-       line2=line;
-       line= line_inf[line].next[1];
-     }
-     else{
-       line2=line;
-       line= line_inf[line].next[0];
+     block[newBlock]= temp;
+
+     blockp--;
+     if(freeBlock != blockp){
+       block[freeBlock]= block[blockp];
+       lineInf[ block[freeBlock].end[0] ].block= freeBlock;     
+       lineInf[ block[freeBlock].end[1] ].block= freeBlock;
      }
-     if(line == -1) break;
-   }
 
-   up_limit2 -=num;
+     didSome= true;
 
-   avg/=num;
-//   printf("%d %d    %d %d\n", num, avg,  up_limit,  up_limit2);
-   if(up_limit > up_limit2){
-     line= block[i].end[1];
-     block[i].end[0]= line;
-     block[i].end[1]= block[i].end[0];
-     up_limit=up_limit2;
    }
-   up_limit -= c2end + 6;
+   printf("HALLOD\n");
 
-   if( up_limit < 0 ) up_limit=0;
-   if( up_limit + num > yresst1 ) up_limit=0;  // FIX ME ?
+   if(istate==1){
+     T2=uclock();
+     T_merge+=T2-T1;
+     T1=T2;
+   }
 
-   if( up_limit > avg ) up_limit = 0;
+   corrLoops++;
+   first= false;
+ }while(didSome==true);
 
-   block[i].up_limit=up_limit;
-   block[i].down_limit=yresst1;
-   block[i].avg=avg;
-   block[i].ent=num;
+ printf("blockp %d\n", blockp);
 
+ if(istate==1){
+   sprintf(textbuf[0],"%f Corr", (float)(T_corr)/UCLOCKS_PER_SEC);
+   sprintf(textbuf[1],"%f Radix Sort", (float)(T_radix)/UCLOCKS_PER_SEC);
+   sprintf(textbuf[2],"%f Block Handling", (float)(T_merge)/UCLOCKS_PER_SEC);
+   T2=uclock();
+   T1=T2;
  }
+ printf("HALLO2\n");
+
 
  if(istate==1){
    T2=uclock();
-   sprintf(textbuf[2],"%f Stat", (float)(T2-T1)/UCLOCKS_PER_SEC);
+   sprintf(textbuf[3],"%f Stat", (float)(T2-T1)/UCLOCKS_PER_SEC);
    T1=T2;
  }
 
- qsort(block, blockp, sizeof(b_inf), qsort_block);
+ qsort(block, blockp, sizeof(BLOCK), qsort_block);
 
  if(istate==1){
    T2=uclock();
-   sprintf(textbuf[3],"%f Sort", (float)(T2-T1)/UCLOCKS_PER_SEC);
+   sprintf(textbuf[4],"%f Sort", (float)(T2-T1)/UCLOCKS_PER_SEC);
    T1=T2;
  }
 
- int forw_vec[yrest];
- int bakw_vec[yrest];
+ int forwVec[outy];
+ int bakwVec[outy];
 
- for(i=0; i<yrest; i++){
-   forw_vec[i]=
-   bakw_vec[i]=-1;
+ for(int i=0; i<outy; i++){
+   forwVec[i]=
+   bakwVec[i]=-1;
  }
 
- int sline=0;
- for(i=0; i<blockp; i++){
-   line= block[i].end[0];
-   line2=-1;
-   int tline;
-   while(0==0){
-     if(line_inf[line].next[0] == line2){
-       line2=line;
-       line= line_inf[line].next[1];
+ int ordLine=0;
+ for(int i=0; i<blockp; i++){
+   int line= block[i].end[0];
+   int linePrev=-3;
+   int trueLine;
+   for(int j=0; j<block[i].ent; j++){
+//     printf(" %d %d\n", i, line);
+     if(lineInf[line].next[0] == linePrev){
+       linePrev=line;
+       line= lineInf[line].next[1];
      }
      else{
-       line2=line;
-       line= line_inf[line].next[0];
+       linePrev=line;
+       line= lineInf[line].next[0];
      }
-     if(line2 < c2end) tline=  (line2 + yresst1 - c2end)<<1;
-     else              tline=( (line2 - c2end          )<<1 ) + 1;
-
-     if(forw_vec[tline] != -1) printf("fatal forw %d\n", tline);
-     if(bakw_vec[sline] != -1) printf("fatal bakw %d\n", sline);
+     if(linePrev < nagSize1) trueLine=( linePrev          <<1) + nagStart1;
+     else                    trueLine=((linePrev-nagSize1)<<1) + nagStart2;
 
-     forw_vec[tline] = sline;
-     bakw_vec[sline] = tline;
+     if(forwVec[trueLine] != -1) printf("fatal forw %d\n", trueLine);
+     if(bakwVec[ordLine ] != -1) printf("fatal bakw %d\n", ordLine);
 
-     if(yres == yrest) sline +=2;
-     else              sline ++;
+     forwVec[trueLine] = ordLine;
+     bakwVec[ordLine ] = trueLine;
 
-     if(line == -1) break;
+     if(wndy == outy) ordLine +=2;
+     else             ordLine ++;
    }
  }
+ printf("HALLO3\n");
 
  if(istate==1){
    T2=uclock();
-   sprintf(textbuf[4],"%f Built Vecs", (float)(T2-T1)/UCLOCKS_PER_SEC);
+   sprintf(textbuf[5],"%f Built Vecs", (float)(T2-T1)/UCLOCKS_PER_SEC);
    T1=T2;
  }
 
+                         // fix stuff below (old)
+ byte copy_buff[max_x<<1];
 
- for(i=0; i<yrest; i++){
-   if(bakw_vec[i] == -1 || bakw_vec[i] == i) continue;
-   j=i;
+ for(int i=0; i<outy; i++){
+   if(bakwVec[i] == -1 || bakwVec[i] == i) continue;
+   int k;
+   int j=i;
    do{
      k = j;
-     j = forw_vec[j];
+     j = forwVec[j];
    } while(j != i && j != -1);
    const int open= ( (j == -1)   ?    1 : 0 );
 
    if(open == 0){
-     memcpy(copy_buff, dispbuf.cl + i * xres, xress << 1);
+     memcpy(copy_buff, dispbuf.cl + i * vgax, wndx << 1);
      j = i;
      do{
        k = j;
-       j = bakw_vec[j];
-       forw_vec[k] = k;
-       bakw_vec[k] = k;
+       j = bakwVec[j];
+       forwVec[k] = k;
+       bakwVec[k] = k;
 //       printf("closed %d %d\n", j, k );
-       if(j != i)  memcpy(dispbuf.cl + k * xres, dispbuf.cl + j * xres, xress << 1);
+       if(j != i)  memcpy(dispbuf.cl + k * vgax, dispbuf.cl + j * vgax, wndx << 1);
      } while(j != i);
-     memcpy(dispbuf.cl + k * xres, copy_buff, xress << 1);
+     memcpy(dispbuf.cl + k * vgax, copy_buff, wndx << 1);
    }
    else{
      j = k;
      do{
        k = j;
-       j = bakw_vec[j];
-       forw_vec[k] = k;
-       bakw_vec[k] = k;
+       j = bakwVec[j];
+       forwVec[k] = k;
+       bakwVec[k] = k;
 //       printf("open %d %d\n", j, k );
-       if(j != -1) memcpy(dispbuf.cl + k * xres, dispbuf.cl + j * xres, xress << 1);
+       if(j != -1) memcpy(dispbuf.cl + k * vgax, dispbuf.cl + j * vgax, wndx << 1);
      } while(j != -1);
    }
 
  }
 
- if(yrest == yres){
-   for(i=0; i<yrest; i+=2){
-     memcpy(dispbuf.cl + (i+1) * xres, dispbuf.cl + i * xres, xress << 1);
+ if(outy == wndy){
+   for(int i=0; i<outy; i+=2){
+     memcpy(dispbuf.cl + (i+1) * vgax, dispbuf.cl + i * vgax, wndx << 1);
    }
  }
 
 /*
  linep=0;
  for(line=0; line<yresst1; line++){
-   linep+=xres<<1;
+   linep+=vgax<<1;
    int allnor=0;
    int allinv=0;
-   for(i=0; i<xress; i+=2){
-     register int x=dispbuf.b[ linep + (i<<1) - (xres<<1) + 2 ];
+   for(i=0; i<wndx; i+=2){
+     register int x=dispbuf.b[ linep + (i<<1) - (vgax<<1) + 2 ];
      register int y=dispbuf.b[ linep + (i<<1)             + 2 ];
      if(x>127) x-=256;
      if(y>127) y-=256;
@@ -551,9 +615,9 @@ void nag_decrypt(void){
      allinv+=mabs(x+y);
    }
    if(allinv < allnor){
-     dispbuf.cl[line  * xres + 4          ].lum=255;
-     dispbuf.cl[line  * xres + 5          ].lum=0;
-     for(i=0; i<xress; i+=2){
+     dispbuf.cl[line  * vgax + 4          ].lum=255;
+     dispbuf.cl[line  * vgax + 5          ].lum=0;
+     for(i=0; i<wndx; i+=2){
        register int x=dispbuf.b[ linep + (i<<1) + 2 ];
        if(x>127) x-=256;
        dispbuf.b[ 2 + linep + (i<<1) ]=char(-x);
@@ -561,14 +625,15 @@ void nag_decrypt(void){
    }
 
  }
+ printf("HALLO4\n");
 
  linep=0;
  for(line=0; line<yresst1; line++){
-   linep+=xres<<1;
+   linep+=vgax<<1;
    int allnor=0;
    int allinv=0;
-   for(i=0; i<xress; i+=2){
-     register int x=dispbuf.b[ linep + (i<<1) - (xres<<1) ];
+   for(i=0; i<wndx; i+=2){
+     register int x=dispbuf.b[ linep + (i<<1) - (vgax<<1) ];
      register int y=dispbuf.b[ linep + (i<<1)             ];
      if(x>127) x-=256;
      if(y>127) y-=256;
@@ -576,9 +641,9 @@ void nag_decrypt(void){
      allinv+=mabs(x+y);
    }
    if(allinv < allnor){
-     dispbuf.cl[line  * xres + 6          ].lum=255;
-     dispbuf.cl[line  * xres + 7          ].lum=0;
-     for(i=0; i<xress; i+=2){
+     dispbuf.cl[line  * vgax + 6          ].lum=255;
+     dispbuf.cl[line  * vgax + 7          ].lum=0;
+     for(i=0; i<wndx; i+=2){
        register int x=dispbuf.b[ linep + (i<<1) ];
        if(x>127) x-=256;
        dispbuf.b[ linep + (i<<1) ]=char(-x);
@@ -587,11 +652,27 @@ void nag_decrypt(void){
 
  }
 */  
+
+ line=0;
+ int block_noblack= blockp;
+ for(int i=0; i<blockp; i++){
+//   printf("%d %d %d\n", i, block[i].up_limit, block[i].avg);
+   line+= block[i].ent;
+
+   dispbuf.cl[line  * vgax              ].lum=255;
+   dispbuf.cl[line  * vgax + 1          ].lum=0;
+   if(lineInf[ block[i].end[0] ].state == 0){
+     dispbuf.cl[line  * vgax + 2          ].lum=255;
+     dispbuf.cl[line  * vgax + 3          ].lum=0;
+     block_noblack--;
+   }
+ }
+
  if(istate==1){
    T2=uclock();
-   sprintf(textbuf[5],"%f Move", (float)(T2-T1)/UCLOCKS_PER_SEC);
-   sprintf(textbuf[6],"%d Blocks", blockp);
-   sprintf(textbuf[7],"%d Loops", corr_loops);
+   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]);
@@ -602,20 +683,16 @@ void nag_decrypt(void){
    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;
  }
 
- line=0;
- for(i=0; i<blockp; i++){
-//   printf("%d %d %d\n", i, block[i].up_limit, block[i].avg);
-   line+= block[i].ent;
+ delete [] lowRes;
+ delete [] block;
+ delete [] lineInf;
+ delete [] coeffsLine;
+ delete [] sortedCoeff;
+ delete [] bufferInfo;
 
-   dispbuf.cl[line  * xres              ].lum=255;
-   dispbuf.cl[line  * xres + 1          ].lum=0;
-   if(line_inf[ block[i].end[0] ].state == 0){
-     dispbuf.cl[line  * xres + 2          ].lum=255;
-     dispbuf.cl[line  * xres + 3          ].lum=0;
-   }
- }
 }
 

Modified: trunk/2010/2_nag.h
==============================================================================
--- trunk/2010/2_nag.h	(original)
+++ trunk/2010/2_nag.h	Wed Jul  4 03:45:27 2007
@@ -2,24 +2,49 @@
 #ifndef n2_nag_h
 #define n2_nag_h
 
-#define l_ent 14
+#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
 
-struct l_inf{
- int line[l_ent];
- int coeff[l_ent];
- int state;
+enum STATE{
+  eBlack,
+  eMiddle,
+  eSingle,
+  eEnd,
+};
+
+struct BLOCK;
+
+struct LINEINF{
+ STATE state;    
  int block;
  int next[2];
+ int nextCoeff[2];
 };
 
-struct b_inf{
+struct BLOCK{
  int end[2];
- int up_limit;
- int down_limit;
- int avg;
+ int limit[2];
  int ent;
 };
 
+struct COEFFSLINE{
+ int line[L_ENT];
+ int coeff[L_ENT];
+};
+
+struct TEMPSORT{
+  int line[2];
+  int coeff;
+};
+
+struct SORTEDCOEFF{
+  int line[2];
+};
+
 void nag_decrypt(void);
 
 #endif

Modified: trunk/2010/2_nag_a.asm
==============================================================================
--- trunk/2010/2_nag_a.asm	(original)
+++ trunk/2010/2_nag_a.asm	Wed Jul  4 03:45:27 2007
@@ -18,9 +18,27 @@ global _nagra_corr__Fiiiiiii
 %define linep        par3
 %define linep2       par4
 %define line2        par5
-%define line_inf     par6
+%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)
+
+%define bs1   (2*L_ENT)
+%define bs2   (  L_ENT)
+%define bs3   (  L_ENT/2)
+
+
 _nagra_corr__Fiiiiiii:
 ; push eax
  push ebx
@@ -37,9 +55,9 @@ _nagra_corr__Fiiiiiii:
 loopi:
 
  mov [_asm_temp2], ebx
- mov ebp, [line_inf]
+ mov ebp, [coeffsLine]
 
- shl ebx, 7
+ shl ebx, ld_L_ENT
  mov edx, [xress_check2]
 
  add ebx, ebp
@@ -48,14 +66,14 @@ loopi:
  mov [_asm_temp3], ebx
  add ecx, edx
 
- mov ebx, [ebx + 112]
+ mov ebx, [ebx + firstCoeff]
  mov [linep2], ecx
 
  mov esi, [databuf]
- test ebx, ebx
+ cmp ebx, 0xFFFF
 
  mov edi, esi
-  jz NEAR End
+  jz NEAR End_NoEsp
 
  add esi, edx
  add edi, edx
@@ -75,6 +93,7 @@ loopi:
  test eax, eax
   jz NoMMX
 
+ int 3
  movq mm3, [mmx_zero]
 
  movq mm0, [esp + esi]
@@ -100,7 +119,7 @@ MMXloop:
  movq mm2, mm0               ;  V 1
  add esp, 8                  ; U
   jnc MMXloop                ;  V 1
-
+ int 3
  movq mm0, mm5
  psrlq mm5, 32
 
@@ -164,45 +183,39 @@ NoMMXloop:            
 
 EndMMX: 
 
- mov eax, [ebx + 108]        ; U | V 1
+ mov eax, [ebx + lastCoeff]  ; U | V 1
  cmp ebp, eax                ; U
   jg TryNext                 ;  V 1
 
- mov eax, [ebx + 84]         ; U 1
+ mov eax, [ebx + bs1Coeff]   ; U 1
  cmp eax, ebp                ; U 
  mov esp, [_asm_temp2]       ;  V 1  line2
  sbb ecx, ecx                ; U 
- mov edx, 48                 ;  V 1
- and ecx, 32                 ; U 1
-
- mov eax, [ebx + ecx + 68]   ; U 2 AGI 
- cmp eax, ebp                ; U 1
- sbb esi, esi                ; U 1
- and esi, 16                 ; U 1
- or  ecx, esi                ; U 1
+ mov edx, L_ENT*4-8          ;  V 1
+ and ecx, bs1                ; U 1
 
- mov eax, [ebx + ecx + 60]   ; U 2 AGI 
+ mov eax, [ebx + ecx + bs2Coeff]; U 2 AGI 
  cmp eax, ebp                ; U 1
  sbb esi, esi                ; U 1
- and esi, 8                  ; U 1
+ and esi, bs2                ; U 1
  or  ecx, esi                ; U 1
 
- mov eax, [ebx + ecx + 56]   ; U 2 AGI 
+ mov eax, [ebx + ecx + bs3Coeff]; U 2 AGI 
  cmp eax, ebp                ; U 1
  sbb esi, esi                ; U 1
- and esi, 4                  ; U 1
+ and esi, bs3                ; U 1
  or  ecx, esi                ; U 1
 
 Copy1:  
- mov esi, [ebx + edx     ]    ; U
- mov edi, [ebx + edx + 56]    ;  V 1
- mov [ebx + edx + 4 ], esi    ; U
- mov [ebx + edx + 60], edi    ;  V 1
- sub edx, 4                   ; U
- cmp edx, ecx                 ;  V 1
-  jge Copy1                   ; U  1
- mov [ebx + ecx     ], esp    ; U
- mov [ebx + ecx + 56], ebp    ;  V 1
+ 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:  
@@ -210,51 +223,46 @@ TryNext:  
 
  mov ebx, [_asm_temp3]       ; U 1  line_inf[line2]
 
- mov eax, [ebx + 108]        ; U 2  AGI
+ mov eax, [ebx + lastCoeff]  ; U 2 AGI
  cmp ebp, eax                ; U
   jg End                     ;  V 1
 
- mov eax, [ebx + 84]         ; U 1
+ mov eax, [ebx + bs1Coeff]   ; U 1
  cmp eax, ebp                ; U 
  mov esp, [_asm_temp4]       ;  V 1  line
  sbb ecx, ecx                ; U 
- mov edx, 48                 ;  V 1
- and ecx, 32                 ; U 1
-
- mov eax, [ebx + ecx + 68]   ; U 2 AGI 
- cmp eax, ebp                ; U 1
- sbb esi, esi                ; U 1
- and esi, 16                 ; U 1
- or  ecx, esi                ; U 1
+ mov edx, L_ENT*4-8          ;  V 1
+ and ecx, bs1                ; U 1
 
- mov eax, [ebx + ecx + 60]   ; U 2 AGI 
+ mov eax, [ebx + ecx + bs2Coeff]; U 2 AGI 
  cmp eax, ebp                ; U 1
  sbb esi, esi                ; U 1
- and esi, 8                  ; U 1
+ and esi, bs2                ; U 1
  or  ecx, esi                ; U 1
 
- mov eax, [ebx + ecx + 56]   ; U 2 AGI 
+ mov eax, [ebx + ecx + bs3Coeff]; U 2 AGI 
  cmp eax, ebp                ; U 1
  sbb esi, esi                ; U 1
- and esi, 4                  ; U 1
+ and esi, bs3                ; U 1
  or  ecx, esi                ; U 1
 
 Copy2:  
- mov esi, [ebx + edx     ]    ; U
- mov edi, [ebx + edx + 56]    ;  V 1
- mov [ebx + edx + 4 ], esi    ; U
- mov [ebx + edx + 60], edi    ;  V 1
- sub edx, 4                   ; U
- cmp edx, ecx                 ;  V 1
-  jge Copy2                   ; U  1
- mov [ebx + ecx     ], esp    ; U
- mov [ebx + ecx + 56], ebp    ;  V 1
+ 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]
 

Modified: trunk/2010/2_vc.cc
==============================================================================
--- trunk/2010/2_vc.cc	(original)
+++ trunk/2010/2_vc.cc	Wed Jul  4 03:45:27 2007
@@ -15,7 +15,7 @@
 #define vc_dead 7.5
 #define check 1
 
-extern xres, yres, xress, yress;
+extern vgax, vgay, wndx, wndy;
 extern xxx dispbuf;
 extern volatile int scales_x, scalee_x;
 extern volatile int scales_y, scalee_y;
@@ -49,12 +49,12 @@ void vc_decrypt(void){
  long alg1=0, alg2=0, alg3=0;
  color c;
 
- const int vc_endx=xress;
- const int vc_startx=int(double(22-scales_x+3)/double(768-scales_x+3-scalee_x)*xress);
+ const int vc_endx=wndx;
+ const int vc_startx=int(double(22-scales_x+3)/double(768-scales_x+scalee_x)*wndx);
 
  const int vc_diff=vc_endx - vc_startx;
 
- int *dir=new int[vc_diff*(yress + 1)];
+ int *dir=new int[vc_diff*(wndy + 1)];
 
  const int mindist=int(double(vc_diff) / vc_dead);
 
@@ -71,12 +71,12 @@ void vc_decrypt(void){
 
  for(i = 0; i < vc_diff; i++) last_val[i]=1;
 
- llinep=-(xres<<2);
- linep=-(xres<<1);
+ llinep=-(vgax<<2);
+ linep=-(vgax<<1);
  edgep=0;
- for(line=0; line<yress; line++){
-   llinep+=xres<<1;
-   linep+=xres<<1;
+ for(line=0; line<wndy; line++){
+   llinep+=vgax<<1;
+   linep+=vgax<<1;
    bestdiff=0x1FFFFFFF;
    diffall=0;
    start_step=0;
@@ -159,7 +159,7 @@ void vc_decrypt(void){
    cutpoint[line]=bestp;
    if(bestdiff==0) bestdiff++;
    temp=diffall * addap_start * 32 / (vc_diff * bestdiff);
-        if(temp<42) drift=xress;
+        if(temp<42) drift=wndx;
    else if(temp<56) drift=addap_end;
    else             drift=(addap_end>>1) | 1;
 
@@ -181,7 +181,7 @@ void vc_decrypt(void){
        new_val[i]=0;
        dir[edgep + i]=best_edge;    //FIX ME (not nes)
      }
-     else if(drift==xress){
+     else if(drift==wndx){
        new_val[i]=1;
        dir[edgep + i]=best_edge;
      }
@@ -247,7 +247,7 @@ void vc_decrypt(void){
          }              
          if(i >=  vc_diff && best_edge_val==0){
            i=0;
-           drift=xress;
+           drift=wndx;
          }
        }
      }
@@ -274,7 +274,7 @@ void vc_decrypt(void){
  }
 
  i=best_edge;
- for(line=yress-1; line>0; line--){
+ for(line=wndy-1; line>0; line--){
    if(show_points==0){
      cutpoint[line]+=i;
      if(cutpoint[line] >= vc_diff) cutpoint[line]-= vc_diff;
@@ -282,8 +282,8 @@ void vc_decrypt(void){
    else{
      j=cutpoint[line]+i;
      if(j >= vc_diff) j-= vc_diff;
-     dispbuf.b[(line * xres<<1) + ((vc_startx + j)<<1)+1]=255;
-     dispbuf.b[(line * xres<<1) + ((vc_startx + j)<<1)+3]=0;
+     dispbuf.b[(line * vgax<<1) + ((vc_startx + j)<<1)+1]=255;
+     dispbuf.b[(line * vgax<<1) + ((vc_startx + j)<<1)+3]=0;
    }
    i=dir[vc_diff*line + i];
  }
@@ -294,13 +294,13 @@ void vc_decrypt(void){
    T1=T2;
  }
 
- linep=-(xres<<1);
+ linep=-(vgax<<1);
 // vc_diff&= ~1;
- for(line=0; line<yress; line++){
+ for(line=0; line<wndy; line++){
 
 //   cutpoint[line]&= ~1;
 
-   linep+=xres<<1;
+   linep+=vgax<<1;
    if(show_points!=0){
      dispbuf.b[linep+(vc_startx<<1)+1]=255;
      dispbuf.b[linep+(vc_startx<<1)+3]=0;

Modified: trunk/2010/2do
==============================================================================
--- trunk/2010/2do	(original)
+++ trunk/2010/2do	Wed Jul  4 03:45:27 2007
@@ -2,23 +2,20 @@ clear boarder
 center pic if not xres x yres
 fix all yuv g_funcs
 add mil cont buf
-fix dpmi no page alignes
-vds mem not checked for 4mb violations
 switch between inputs
 teletext
 load pix for decoding
-fix no page flips
-  mouse out at buttom freezes everything
-  mouse area not updated
-fix mouse if int 8
+
 imp nagra
  color ?
  block integration
- better sorting (no QSort)
+ better sorting (no QSort) 
  c2end +-1 error (up_limit not correct)
- variable check
  imp black line det
- up/down limit check in block merge
+ up/down limit and orientation check in block merge
+ keep limit and orintation (or unknowenness) during merge loop
+ keep block list sorted (use linked list)
+ buffer for buffer-freeness (0-32)
 
 imp vc
  color ?
@@ -30,3 +27,4 @@ imp vc
 fix 24-bits   ?
 
 
+check modifications during prog

Modified: trunk/2010/makefile
==============================================================================
--- trunk/2010/makefile	(original)
+++ trunk/2010/makefile	Wed Jul  4 03:45:27 2007
@@ -32,7 +32,7 @@ clean: ; del $(O) 2010
                              2_71x6.h 2_mmx.h
 2_hw_mem.o : 2_hw_mem.cc 2_all.h 2_hw_mem.h 2010.h 
 2_move.o   : 2_move.cc   2_all.h 2_move.h 2010.h
-2_71x6.o   : 2_71x6.cc   2_all.h 2_71x6.h 2_hw.h 2_hw_mem.h 2010.h
+2_71x6.o   : 2_71x6.cc   2_all.h 2_71x6.h 2_hw.h 2_hw_mem.h 2010.h 2_hw_asm.h
 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



More information about the Mndiff-dev mailing list