示例#1
0
/*
 * bpp must be bytes per pixel, not bits!
 */
void et6000aclInit(uint8 bpp) {

    et6000aclTerminate();

    set8(mmRegs+0x31, 0xef, 0x10); /* let ACL to operate */
    set8(mmRegs+0x32, 0x99, 0x00); /* maximize the performance */
    set8(mmRegs+0x8e, 0xcf, (bpp - 1) << 4); /* set pixel color depth */
    set8(mmRegs+0x91, 0x80, 0x00); /* maximize the performance */
    set8(mmRegs+0x9d, 0x00, 0x00); /* maximize the performance */
}
示例#2
0
void CHD61102::cmd_write(qint16 cmd)
{
    if ((pPC->pCPU->fp_log) && (cmd & 0xff))fprintf(pPC->pCPU->fp_log,"LCD Write:%02x\n",cmd & 0xff);
//    if ((pPC->fp_log) && (cmd & 0xff)) fprintf(pPC->fp_log,"LCD Write:x=%02x y=%02x val=%02x\n",Xadr,Yadr,cmd & 0xff);
    set8( (info.Xadr * 0x40) + info.Yadr , (cmd & 0xff));
    (info.Yadr)++;
    if (info.Yadr == 64) {
        info.Yadr=0;
    }
    updated = true;
    AddLog(LOG_DISPLAY,tr("UPDATED write"));
}
示例#3
0
__inline void et6000aclTerminate(void) {
    set8(mmRegs+0x31, 0xef, 0x10); /* let ACL to operate */
    et6000aclWaitIdle();
    set8(mmRegs+0x30, 0, 0x00);
    set8(mmRegs+0x30, 0, 0x01);
    et6000aclWaitIdle();
    set8(mmRegs+0x30, 0, 0x00);
    set8(mmRegs+0x30, 0, 0x10);
    et6000aclWaitIdle();
    set8(mmRegs+0x30, 0, 0x00);
}
/***********************************************************
  Function:       mem_copy() // 函数名称
  Description:    复制指定内存段到另一位置。
  Calls:          set32 ; set8 ; printf // 被本函数调用的函数清单(建议描述)
  Called By:      // 调用本函数的函数清单(建议描述)
  Table Accessed: 无// 被访问的表(此项仅对于牵扯到数据库操作的程序)
  Table Updated:  无// 被修改的表(此项仅对于牵扯到数据库操作的程序)
  Input:          src_addr:源内存地址,32bit 
				  des_addr:目的内存地址,32bit 
				  num_byte:需要复制的内存的长度,单位byt
  Output:         无 // 对输出参数的说明。
  Return:         无// 函数返回值的说明
  Others:         // 其它说明
***********************************************************/
void mem_copy( UINT32 src_addr,    /* Memory Source Address*/
			   UINT32 des_addr,    /* Memory Destination Address*/
			   int    num_byte)    /* Number of Data in Byte*/
{
int cnt1  ;
int cnt2  ;

UINT32  read_data ;
UINT8   read_data_byte ; 

cnt1 = 0 ;
cnt2 = 0 ;

/*拷贝操作,超过32bits使用32bits 的数据写函数,不足32bits的memory使用8bits 的数据写函数*/	
for (cnt1 = num_byte; cnt1 >0; cnt1 = cnt1 - 0x4)
{       
    if(cnt1 >= 0x4)
    {
        read_data = read32( src_addr );
        set32(des_addr , read_data );
        src_addr = src_addr + 0x4 ;
        des_addr = des_addr + 0x4 ;
    }
    else
    {
        cnt2 = cnt1;
        while ( cnt2 )
        {
            read_data_byte = read8 ( src_addr );
            set8(des_addr, read_data_byte );
            src_addr = src_addr + 0x1 ;
            des_addr = des_addr + 0x1 ;
            cnt2 = cnt2 - 0x1 ;
        }
    }
}
#ifdef _UNIT_DEBUG
    printf("Copy finish!\n"); 
#endif	

return;
}	
示例#5
0
// constructor
MyWindow::MyWindow(int w, int h) : 
  red_active(false),
  red_set(*(new Polygon_set)),
  blue_set(*(new Polygon_set)),
  res_set(*(new Polygon_set))										  
{
  widget = new CGAL::Qt_widget(this); //Constructs a widget which is a child of this window


  /* Sets the central widget for this main window to w.
   * The central widget is surrounded by the left, top, right and bottom dock areas.
   * The menu bar is above the top dock area
   */
  setCentralWidget(widget);

  file_name= QString::null;

  //create a timer for checking if somthing changed
  QTimer *timer = new QTimer( this ); // constructs a timer whose parent is this window

  connect( timer, SIGNAL(timeout()),
           this, SLOT(timer_done()) );  // connects the timer to the window
  timer->start( 200, FALSE ); // Starts the timer with a msec milliseconds timeout

  // file menu
  QPopupMenu * file = new QPopupMenu( this );
  menuBar()->insertItem( "&File", file );
  file->insertItem("&New", this, SLOT(new_instance()), CTRL+Key_N);
  file->insertItem("New &Window", this, SLOT(new_window()), CTRL+Key_W);
  file->insertSeparator();
  file->insertItem("&Open Linear Polygon file", this, SLOT(open_linear_polygon_file()),CTRL+Key_O);
  file->insertItem("&Open DXF file", this, SLOT(open_dxf_file()),CTRL+Key_D);
  file->insertSeparator();
  //file->insertItem("&Save",this ,SLOT(save_file()),CTRL+Key_S);
  //file->insertItem("&Save as",this ,SLOT(save_file_as()));
  file->insertSeparator();
  file->insertItem("Print", widget, SLOT(print_to_ps()), CTRL+Key_P);
  file->insertSeparator();
  file->insertItem( "&Close", this, SLOT(close()), CTRL+Key_X );
  file->insertItem( "&Quit", qApp, SLOT( closeAllWindows() ), CTRL+Key_Q );

  // help menu
  QPopupMenu * help = new QPopupMenu( this );
  menuBar()->insertItem( "&Help", help );
  help->insertItem("How To", this, SLOT(howto()), Key_F1);
  help->insertSeparator();
  help->insertItem("&About", this, SLOT(about()), CTRL+Key_A );
  help->insertItem("About &Qt", this, SLOT(aboutQt()) );

  //the standard toolbar
  stoolbar = new CGAL::Qt_widget_standard_toolbar (widget, this, "ST");

  radiotoolbar = new QToolBar(this, "polygon type");
  blue_pgn = new QRadioButton ("Blue", radiotoolbar);
  blue_pgn->toggle();
  red_pgn = new QRadioButton("Red", radiotoolbar);
  radio_group = new QVButtonGroup(this,"Radios");
  radio_group->insert(blue_pgn);
  radio_group->insert(red_pgn);
  radio_group->setRadioButtonExclusive(true);


  connect(blue_pgn, SIGNAL(toggled (bool)),
	  this, SLOT(radio_selected()));
  connect(red_pgn, SIGNAL(toggled (bool)),
	  this, SLOT(radio_selected()));


  //layers
  //widget->attach(&testlayer);

  //the new tools toolbar
  newtoolbar = new Tools_toolbar(widget, this);

  // voronoi toolbar
  bops_toolbar = new QToolBar(this, "Boolean operations");

  QIconSet set0(QPixmap( (const char**)intersection_xpm ),
		QPixmap( (const char**)intersection_xpm ));

  intersection_but = new QToolButton(bops_toolbar, "Boolean operations");
  intersection_but->setAutoRaise(TRUE);

  intersection_but->setIconSet(set0);
  intersection_but->setTextLabel("Intersection ");
  connect(intersection_but,SIGNAL(pressed()),
	  this, SLOT(perform_intersection()));

  QIconSet set1(QPixmap( (const char**)union_xpm ),
		QPixmap( (const char**)union_xpm ));

  bops_toolbar->addSeparator();
  union_but = new QToolButton(bops_toolbar, "Boolean operations");
  union_but->setAutoRaise(TRUE);

  union_but->setIconSet(set1);
  union_but->setTextLabel("Union ");
  connect(union_but,SIGNAL(pressed()),
	  this, SLOT(perform_union()));

  QIconSet set2(QPixmap( (const char**)diff_PQ_xpm ),
		QPixmap( (const char**)diff_PQ_xpm ));

  bops_toolbar->addSeparator();
  diff_but2 = new QToolButton(bops_toolbar, "Boolean operations");
  diff_but2->setAutoRaise(TRUE);

  diff_but2->setIconSet(set2);
  diff_but2->setTextLabel("Difference between Blue and Red");
  connect(diff_but2, SIGNAL(pressed()),
	  this, SLOT(perform_diff2()));

  QIconSet set3(QPixmap( (const char**)diff_QP_xpm ),
		QPixmap( (const char**)diff_QP_xpm ));

  bops_toolbar->addSeparator();
  diff_but = new QToolButton(bops_toolbar, "Boolean operations");
  diff_but->setAutoRaise(TRUE);

  diff_but->setIconSet(set3);
  diff_but->setTextLabel("Difference between Red and Blue");
  connect(diff_but, SIGNAL(pressed()),
	  this, SLOT(perform_diff()));

  QIconSet set4(QPixmap( (const char**)symm_diff_xpm ),
		QPixmap( (const char**)symm_diff_xpm ));
  bops_toolbar->addSeparator();

  symm_diff_but = new QToolButton(bops_toolbar, "Boolean operations");
  symm_diff_but->setAutoRaise(TRUE);

  symm_diff_but->setIconSet(set4);
  symm_diff_but->setTextLabel("Symmetric Difference ");
  connect(symm_diff_but, SIGNAL(pressed()),
	  this, SLOT(perform_symm_diff()));

  QIconSet set12(QPixmap( (const char**)mink_sum_xpm ),
		 QPixmap( (const char**)mink_sum_xpm ));
  bops_toolbar->addSeparator();
  mink_sum_but = new QToolButton(bops_toolbar, "Boolean operations");
  mink_sum_but->setAutoRaise(TRUE);
  mink_sum_but->setIconSet(set12);
  mink_sum_but->setTextLabel("Minkowski Sum ");
  connect(mink_sum_but, SIGNAL(pressed()),
	  this, SLOT(perform_mink_sum()));

  QIconSet set5(QPixmap( (const char**)comp_P_xpm ),
		QPixmap( (const char**)comp_P_xpm ));
  bops_toolbar->addSeparator();

  blue_complement_but = new QToolButton(bops_toolbar, "Boolean operations");
  blue_complement_but->setAutoRaise(TRUE);

  blue_complement_but->setIconSet(set5);
  blue_complement_but->setTextLabel("Blue Complement ");
  connect(blue_complement_but, SIGNAL(pressed()),
	  this, SLOT(perform_blue_complement()));

  QIconSet set6(QPixmap( (const char**)comp_Q_xpm ),
		QPixmap( (const char**)comp_Q_xpm ));
  bops_toolbar->addSeparator();

  red_complement_but = new QToolButton(bops_toolbar, "Boolean operations");
  red_complement_but->setAutoRaise(TRUE);

  red_complement_but->setIconSet(set6);
  red_complement_but->setTextLabel("Red Complement ");
  connect(red_complement_but, SIGNAL(pressed()),
	  this, SLOT(perform_red_complement()));


  QIconSet set7(QPixmap( (const char**)make_P_xpm ),
		QPixmap( (const char**)make_P_xpm ));
  bops_toolbar->addSeparator();
  make_res_blue_but = new QToolButton(bops_toolbar, "Boolean operations");
  make_res_blue_but->setAutoRaise(TRUE);


  make_res_blue_but->setIconSet(set7);
  make_res_blue_but->setTextLabel("Make Result Blue");
  connect(make_res_blue_but,SIGNAL(pressed()),
	  this, SLOT(make_res_blue()));

  QIconSet set8(QPixmap( (const char**)make_Q_xpm ),
		QPixmap( (const char**)make_Q_xpm ));
  bops_toolbar->addSeparator();
  make_res_red_but = new QToolButton(bops_toolbar, "Boolean operations");
  make_res_red_but->setAutoRaise(TRUE);


  make_res_red_but->setIconSet(set8);
  make_res_red_but->setTextLabel("Make Result Red");
  connect(make_res_red_but,SIGNAL(pressed()),
	  this, SLOT(make_res_red()));

  QIconSet set9(QPixmap( (const char**)refresh_xpm ),
		QPixmap( (const char**)refresh_xpm ));
  bops_toolbar->addSeparator();

  refresh_but = new QToolButton(bops_toolbar, "Boolean operations");
  refresh_but->setAutoRaise(TRUE);

  refresh_but->setIconSet(set9);
  refresh_but->setTextLabel("Refresh ");
  connect(refresh_but,SIGNAL(pressed()),
	  this, SLOT(refresh()));

  QIconSet set10(QPixmap( (const char**)del_P_xpm ),
		 QPixmap( (const char**)del_P_xpm ));
  bops_toolbar->addSeparator();

  delete_blue_but = new QToolButton(bops_toolbar, "Boolean operations");
  delete_blue_but->setAutoRaise(TRUE);

  delete_blue_but->setIconSet(set10);
  delete_blue_but->setTextLabel("Delete Blue Polygons");
  connect(delete_blue_but,SIGNAL(pressed()),
	  this, SLOT(delete_blue_polygons()));


  QIconSet set11(QPixmap( (const char**)del_Q_xpm ),
		 QPixmap( (const char**)del_Q_xpm ));
  bops_toolbar->addSeparator();

  delete_red_but = new QToolButton(bops_toolbar, "Boolean operations");
  delete_red_but->setAutoRaise(TRUE);

  delete_red_but->setIconSet(set11);
  delete_red_but->setTextLabel("Delete Red Polygons");
  connect(delete_red_but,SIGNAL(pressed()),
	  this, SLOT(delete_red_polygons()));




  *widget << CGAL::LineWidth(2) << CGAL::BackgroundColor (CGAL::BLACK);

  resize(w,h);
  widget->set_window(-1, 1, -1, 1);
  widget->setMouseTracking(TRUE);

  //connect the widget to the main function that receives the objects
  connect(widget, SIGNAL(new_cgal_object(CGAL::Object)),
	  this, SLOT(get_new_object(CGAL::Object)));

  //application flag stuff
  old_state = 0;
  current_state = 1;
  red_active = false;
  red_set.clear();
  blue_set.clear();
  res_set.clear();
}
int mem_init( UINT32 src_addr,    /*Memory Address*/
			   int     num_byte,   /* Number of Data in Byte*/
			   UINT32 init_data)   /* Data to initiate */
{
    int cnt1  ;
    int cnt2  ;
    //int cnt3  ;
    UINT32 write_data ;
    //UINT32 read_data;
    UINT8  init_data_byte ;
    //UINT8  read_data_byte ;
    UINT32 addr ;
    
    cnt1  = 0 ;
    cnt2  = 0 ;
    //cnt3  = 0 ;
    addr = src_addr ;
    write_data = init_data;
    
    /*向 以src_addr 为起始地址、以num_byte 为大小的一块memory 内写入初时值init_data */
    for (cnt1 = num_byte; cnt1 >0; cnt1 = cnt1 - 0x4)
    {
        /*如果memory 的大小是否32bits 的倍数,如果不是32bits 的倍数,则将最后空间使用8bits 写函数补全*/
        if(cnt1 >= 0x4)
        {
        	set32(addr, write_data++);//write_data);
            addr = addr + 0x4 ;
        }
        else
        {
            cnt2 = cnt1;
            init_data_byte = write_data  ; 
            while ( cnt2 )
            {
                set8(addr, init_data_byte);
                write_data = write_data >> 8 ;
                init_data_byte = write_data ;
                addr = addr + 0x1 ;
                cnt2 = cnt2 - 0x1 ;
            }
        }	
    }
    //addr = src_addr ;
    //write_data = init_data;

/*如果需要判断memory 初始化是否正确,请define debug*/
//#ifdef _UNIT_DEBUG
    /*读初始化后的memory ,判断初时化是否成功*/
    /*for (cnt1 = num_byte; cnt1 >0; cnt1 = cnt1 - 0x4)
    {
        if(cnt1 >= 0x4)
        {
            read_data = read32( addr );
            addr = addr + 0x4 ;
            if ( init_data++ != read_data )//( init_data != read_data )
            {
            	cnt3 = cnt3 + 0x4 ;
            }
        }
        else
        {       
            cnt2 = cnt1;
            while ( cnt2 )
            {
                read_data_byte = read8 ( addr );
                addr = addr + 0x1 ;
                cnt2 = cnt2 - 0x1 ;				
                init_data_byte = write_data ;
                write_data = write_data >> 8 ;
                if ( init_data_byte != read_data_byte )
                {
                    cnt3 = cnt3 + 0x1 ;
                }
            }
        }
    }       
            
    if ( 0 == cnt3 )
    {
    	printf("EDMAC: Memory Initiation OK!\n"); 
    }
    else
    {
    	printf("EDMAC: Memory Initiation FAILED!\n");
    	return 1;
    }	*/
    
//#endif
	return 0;
}
int mem_clr( UINT32 src_addr,         /*Memory Address*/
			int     num_byte )    /*Number of Data to clear in Byte*/
{
    int cnt1  ;
    int cnt2  ;
    int cnt3  ;
    UINT32 addr ;
	
    cnt1 = 0 ;
    cnt2 = 0 ;
    cnt3 = 0 ;
    addr = src_addr ; 
    

    
    /*将一块 以src_addr 为起始地址、以num_byte 为大小的memory 的值清零 */
    for (cnt1 = num_byte; cnt1 >0; cnt1 = cnt1 - 0x4)
    {
        if(cnt1 >= 0x4)
        {
            set32(addr, 0x0);
            addr = addr + 0x4 ;
        }
        else
        {
            cnt2 = cnt1;
            while ( cnt2 )
            {
                set8(addr, 0x0);
                addr = addr + 0x1 ;
                cnt2 = cnt2 - 0x1 ;
            }
        }
        	
    }
    
    addr = src_addr ; 
	
/*如果需要判断memory 初始化是否正确,请define debug*/	
#ifdef _UNIT_DEBUG	

    /*读清零后的memory ,判断clear 操作是否成功*/
    for (cnt1 = num_byte; cnt1 >0; cnt1 = cnt1 - 0x4)
    {
        if(cnt1 >= 0x4)
        {
            read_data = read32( addr );
            addr = addr + 0x4 ;
            if ( 0x0 != read_data )
            {
            	cnt3 = cnt3 + 0x4 ;
            }
        }
        else
        {
            cnt2 = cnt1;
            while ( cnt2 )
            {
                read_data_byte = read8 ( addr );
                addr = addr + 0x1 ;
                cnt2 = cnt2 - 0x1 ;
                if ( 0x0 != read_data_byte )
                {
                    cnt3 = cnt3 + 0x1 ;
                }
            }
        }
    }
    
    if ( 0 == cnt3 )
    {
		//#ifdef _UNIT_DEBUG
		printf("Memory Clear OK!\n"); 
		return 0;
		//#endif
    }
    else
    {
        printf("Memory Clear FAILED!\n");
        return 1;
    }	
    
#endif	
    
   return 0;
}
示例#8
0
/*
 * Move the specified list of rectangular regions from one location in
 * the frame buffer to another in the order they are specified in the
 * blit_params *list. The list is uint32 count elements in length.
 */
void SCREEN_TO_SCREEN_BLIT(engine_token *et,
                           blit_params *list,
                           uint32 count)
{
uint16 screenWidth = si->dm.virtual_width;
uint8 bpp = si->bytesPerPixel;
uint8 bltDir;
uint16 src_left, src_top, dest_left, dest_top, width, height;
uint32 srcAddr, destAddr;

    et6000aclWaitQueueNotFull();

    set8(mmRegs+0x92, 0x80, 0x77); /* no source wrap */    
    set8(mmRegs+0x9c, 0x00, 0x33); /* mask=1 always, always use FGR */
    set8(mmRegs+0x9f, 0x00, 0xcc); /* FGR ROP = copy of source */

    /* Set the source Y offset */
    *((vuint16 *)(mmRegs+0x8a)) = screenWidth * bpp - 1;
        
    /* Set the destination Y offset */
    *((vuint16 *)(mmRegs+0x8c)) = screenWidth * bpp - 1;
    
    while(count--) {
        src_left = list->src_left;
        src_top = list->src_top;
        dest_left = list->dest_left;
        dest_top = list->dest_top;
        width = list->width;
        height = list->height;

        et6000aclWaitQueueNotFull();

        /* Set the direction and opcode(BitBLT) register */
        bltDir = 0x00;
        if (src_left < dest_left) bltDir |= 0x01;
        if (src_top < dest_top) bltDir |= 0x02;
        set8(mmRegs+0x8f, 0x3c, bltDir);

        /* Set the X count register */
        *((vuint16 *)(mmRegs+0x98)) = (width + 1) * bpp - 1;
        
        /* Set the Y count register */
        *((vuint16 *)(mmRegs+0x9a)) = height;

        switch (bltDir & 0x03) {
        case 0x00:
            srcAddr = (src_top * screenWidth + src_left) * bpp;
            destAddr = (dest_top * screenWidth + dest_left) * bpp;
            break;

        case 0x01:
            srcAddr =  (src_top * screenWidth + src_left + width) * bpp + bpp-1;
            destAddr = (dest_top * screenWidth + dest_left + width) * bpp + bpp-1;
            break;

        case 0x02:
            srcAddr = ((src_top + height)*screenWidth + src_left) * bpp;
            destAddr = ((dest_top + height)*screenWidth + dest_left) * bpp;
            break;

        case 0x03:
            srcAddr = ((src_top + height)*screenWidth + src_left + width) * bpp + bpp-1;
            destAddr = ((dest_top + height)*screenWidth + dest_left + width) * bpp + bpp-1;
            break;
        }

        /* Set the source address */
        *((vuint32 *)(mmRegs+0x84)) = srcAddr;

        /*
         * Set the destination address -
         * this action starts the BitBLT operation.
         */
        *((vuint32 *)(mmRegs+0xa0)) = destAddr;

        list++;
    }

    si->engine.count++;
}
示例#9
0
/*
 * Fill the specified list of rectangular regions with the specified color.
 * The list is uint32 count elements in length. The rectangular regions are
 * inclusive. The uint32 color is specified in the same configuration and
 * byte order as the current display_mode. All coordinates in the list of
 * rectangles is guaranteed to have been clipped to the virtual limits of
 * the display_mode.
 */
void FILL_RECTANGLE(engine_token *et,
                    uint32 color,
                    fill_rect_params *list,
                    uint32 count)
{
uint16 screenWidth = si->dm.virtual_width;
uint8 bpp = si->bytesPerPixel;
uint16 left, top, right, bottom;
uint32 srcAddr;
uint8 i;

    /*
     * Normally WaitQueueNotFull should be required & enough, but in reality
     * this is somewhy sometimes not enough for pixel depth of 3 bytes.
     */
    if (bpp == 2)
        et6000aclWaitQueueNotFull();
    else
        et6000aclWaitIdle();

    /*
     * We'll put the color at 4 bytes just after the framebuffer.
     * The srcAddr must be 4 bytes aligned and is always for standard
     * resolutions.
     */
    srcAddr = (uint32)si->framebuffer - (uint32)si->memory +
        si->dm.virtual_width * si->dm.virtual_height * bpp;

    switch(bpp) {
        case 2:
            set8(mmRegs+0x92, 0x80, 0x02); /* 4x1 source wrap */
            for (i = 0; i < 2; i++) /* copy the color to source address */
                ((vuint16 *)((uint32)si->memory + srcAddr))[i] = (uint16)color;
            break;
        case 3:
            set8(mmRegs+0x92, 0x80, 0x0a); /* 3x1 source wrap */
            for (i = 0; i < 3; i++) /* copy the color to source address */
                ((vuint8 *)((uint32)si->memory + srcAddr))[i] = ((uint8 *)&color)[i];

            break;
    }

    set8(mmRegs+0x9c, 0x00, 0x33); /* mask=1 always, always use FGR */
    set8(mmRegs+0x9f, 0x00, 0xcc); /* FGR ROP = copy of source */

    /* Set the source Y offset */
    *((vuint16 *)(mmRegs+0x8a)) = screenWidth * bpp - 1;
    /* Set the destination Y offset */
    *((vuint16 *)(mmRegs+0x8c)) = screenWidth * bpp - 1;

    /* Set the direction and opcode(trapezoid) register (primary edge) */
    set8(mmRegs+0x8f, 0x18, 0x40);
    /* Set the secondary edge register */
    set8(mmRegs+0x93, 0x1a, 0x00);

    /* Set the primary delta minor register */
    *((vuint16 *)(mmRegs+0xac)) = 0;
    /* Set the secondary delta minor register */
    *((vuint16 *)(mmRegs+0xb4)) = 0;

    while(count--) {
        left = list->left;
        top = list->top;
        right = list->right;
        bottom = list->bottom;

        et6000aclWaitQueueNotFull();

        /* Set the X count register */
        *((vuint16 *)(mmRegs+0x98)) = (right-left+1)*bpp - 1;
        /* Set the Y count register */
        *((vuint16 *)(mmRegs+0x9a)) = bottom-top;

        /* Set the primary delta major register */
        *((vuint16 *)(mmRegs+0xae)) = bottom-top;

        /* Set the secondary delta major register */
        *((vuint16 *)(mmRegs+0xb6)) = bottom-top;

        /* Set the source address */
        *((vuint32 *)(mmRegs+0x84)) = srcAddr;

        /*
         * Set the destination address -
         * this action starts the trapezoid operation.
         */
        *((vuint32 *)(mmRegs+0xa0)) = (top * screenWidth + left) * bpp;

        list++;
    }

    si->engine.count++;
}
示例#10
0
文件: main.cpp 项目: dibery/Dorm-IP
LRESULT CALLBACK WinProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam)
{
    switch(msg)
    {
    case WM_CREATE:
    {
        // Create an edit box
        SendMessage( CreateWindowEx(0,
                                    "STATIC",
                                    "Step 1. 取得網路卡卡號",
                                    WS_CHILD|WS_VISIBLE|SS_LEFT,
                                    50,
                                    40,
                                    200,
                                    100,
                                    hWnd,
                                    (HMENU)STEP1,
                                    GetModuleHandle(NULL),
                                    NULL), WM_SETFONT, WPARAM( GetStockObject(DEFAULT_GUI_FONT) ), MAKELPARAM(FALSE,0) );
        SendMessage( CreateWindowEx(0,
                                    "STATIC",
                                    "Step 2. 網路卡卡號",
                                    WS_CHILD|WS_VISIBLE|SS_LEFT,
                                    50,
                                    100,
                                    200,
                                    100,
                                    hWnd,
                                    (HMENU)STEP2,
                                    GetModuleHandle(NULL),
                                    NULL), WM_SETFONT, WPARAM( GetStockObject(DEFAULT_GUI_FONT) ), MAKELPARAM(FALSE,0) );
        SendMessage( CreateWindowEx(0,
                                    "STATIC",
                                    "Step 3. 複製網路卡卡號",
                                    WS_CHILD|WS_VISIBLE|SS_LEFT,
                                    50,
                                    160,
                                    200,
                                    100,
                                    hWnd,
                                    (HMENU)STEP3,
                                    GetModuleHandle(NULL),
                                    NULL), WM_SETFONT, WPARAM( GetStockObject(DEFAULT_GUI_FONT) ), MAKELPARAM(FALSE,0) );
        SendMessage( CreateWindowEx(0,
                                    "STATIC",
                                    "Step 4. 開啟註網註冊頁面",
                                    WS_CHILD|WS_VISIBLE|SS_LEFT,
                                    50,
                                    220,
                                    200,
                                    100,
                                    hWnd,
                                    (HMENU)STEP4,
                                    GetModuleHandle(NULL),
                                    NULL), WM_SETFONT, WPARAM( GetStockObject(DEFAULT_GUI_FONT) ), MAKELPARAM(FALSE,0) );
        SendMessage( CreateWindowEx(0,
                                    "STATIC",
                                    "Step 5. 選擇作業系統版本",
                                    WS_CHILD|WS_VISIBLE|SS_LEFT,
                                    50,
                                    280,
                                    200,
                                    100,
                                    hWnd,
                                    (HMENU)STEP5,
                                    GetModuleHandle(NULL),
                                    NULL), WM_SETFONT, WPARAM( GetStockObject(DEFAULT_GUI_FONT) ), MAKELPARAM(FALSE,0) );
        SendMessage( CreateWindowEx(0,
                                    "STATIC",
                                    "Step 6. 輸入註冊好的 IP",
                                    WS_CHILD|WS_VISIBLE|SS_LEFT,
                                    50,
                                    340,
                                    200,
                                    100,
                                    hWnd,
                                    (HMENU)STEP6,
                                    GetModuleHandle(NULL),
                                    NULL), WM_SETFONT, WPARAM( GetStockObject(DEFAULT_GUI_FONT) ), MAKELPARAM(FALSE,0) );
        SendMessage( CreateWindowEx(0,
                                    "STATIC",
                                    "Step 7. 設定 IP",
                                    WS_CHILD|WS_VISIBLE|SS_LEFT,
                                    50,
                                    400,
                                    200,
                                    100,
                                    hWnd,
                                    (HMENU)STEP7,
                                    GetModuleHandle(NULL),
                                    NULL), WM_SETFONT, WPARAM( GetStockObject(DEFAULT_GUI_FONT) ), MAKELPARAM(FALSE,0) );
        SendMessage( CreateWindowEx(0,
                                    "STATIC",
                                    "Step 8. 設定完成",
                                    WS_CHILD|WS_VISIBLE|SS_LEFT,
                                    50,
                                    460,
                                    200,
                                    100,
                                    hWnd,
                                    (HMENU)STEP8,
                                    GetModuleHandle(NULL),
                                    NULL), WM_SETFONT, WPARAM( GetStockObject(DEFAULT_GUI_FONT) ), MAKELPARAM(FALSE,0) );
        SendMessage( CreateWindowEx(0,
                                    "STATIC",
                                    "離宿後欲清除 IP 設定,請點這裡",
                                    WS_CHILD|WS_VISIBLE|SS_LEFT,
                                    50,
                                    520,
                                    200,
                                    100,
                                    hWnd,
                                    (HMENU)STEP_CLEAR,
                                    GetModuleHandle(NULL),
                                    NULL), WM_SETFONT, WPARAM( GetStockObject(DEFAULT_GUI_FONT) ), MAKELPARAM(FALSE,0) );
        TCHAR A[160];
        hEdit=CreateWindowEx(0,
                             "STATIC",
                             "",
                             WS_CHILD|WS_VISIBLE|SS_LEFT,
                             //ES_MULTILINE|ES_AUTOVSCROLL|ES_AUTOHSCROLL,
                             300,
                             100,
                             200,
                             50,
                             hWnd,
                             (HMENU)IDC_MAIN_EDIT,
                             GetModuleHandle(NULL),
                             NULL);
        HGDIOBJ hfDefault=GetStockObject(DEFAULT_GUI_FONT);
        SendMessage(hEdit,
                    WM_SETFONT,
                    (WPARAM)hfDefault,
                    MAKELPARAM(FALSE,0));
        SendMessage(hEdit,
                    WM_SETTEXT,
                    0,
                    (LPARAM)"00:00:00:00:00:00");

        // Create a push button
        HWND hWndButton=CreateWindowEx(0,
                                       "BUTTON",
                                       "複製網路卡卡號",
                                       WS_TABSTOP|WS_VISIBLE|
                                       WS_CHILD|BS_PUSHBUTTON,
                                       300,
                                       156,
                                       200,
                                       24,
                                       hWnd,
                                       (HMENU)IDC_MAIN_BUTTON,
                                       GetModuleHandle(NULL),
                                       NULL);
        SendMessage(hWndButton,
                    WM_SETFONT,
                    (WPARAM)hfDefault,
                    MAKELPARAM(FALSE,0));
        HWND MAC_Button=CreateWindowEx(0,
                                       "BUTTON",
                                       "取得網路卡號",
                                       WS_TABSTOP|WS_VISIBLE|
                                       WS_CHILD|BS_PUSHBUTTON,
                                       300,
                                       36,
                                       200,
                                       24,
                                       hWnd,
                                       (HMENU)IDC_MAC_BUTTON,
                                       GetModuleHandle(NULL),
                                       NULL);
        SendMessage(MAC_Button,
                    WM_SETFONT,
                    (WPARAM)hfDefault,
                    MAKELPARAM(FALSE,0));
        HWND web_Button=CreateWindowEx(0,
                                       "BUTTON",
                                       "開啟宿網註冊頁面",
                                       WS_TABSTOP|WS_VISIBLE|
                                       WS_CHILD|BS_PUSHBUTTON,
                                       300,
                                       216,
                                       200,
                                       24,
                                       hWnd,
                                       (HMENU)IDC_WEB_BUTTON,
                                       GetModuleHandle(NULL),
                                       NULL);
        SendMessage(web_Button,
                    WM_SETFONT,
                    (WPARAM)hfDefault,
                    MAKELPARAM(FALSE,0));
        HWND ver_Combo=CreateWindowEx(0,
                                      "COMBOBOX",
                                      "",
                                      CBS_DROPDOWNLIST | CBS_HASSTRINGS | WS_CHILD | WS_OVERLAPPED | WS_VISIBLE,
                                      300,
                                      276,
                                      200,
                                      24,
                                      hWnd,
                                      (HMENU)IDC_VER_DROP,
                                      GetModuleHandle(NULL),
                                      NULL);
        SendMessage(ver_Combo,
                    WM_SETFONT,
                    (WPARAM)hfDefault,
                    MAKELPARAM(FALSE,0));
        TCHAR Planets[][30] =
        {
            TEXT("Windows XP"), TEXT("Windows Vista"), TEXT("Windows 7"), TEXT("Windows 8")
        };


        int  k = 0;

        memset(&A,0,sizeof(A));
        for (k = 0; k < 4; k += 1)
        {
            strcpy(A, Planets[k]);

            // Add string to combobox.
            SendMessage(ver_Combo,(UINT) CB_ADDSTRING,(WPARAM) 0,(LPARAM) A);
        }

        SendMessage( CreateWindowEx(0,
                                    "STATIC",
                                    "140 . 119 .                 .",
                                    WS_CHILD|WS_VISIBLE|SS_LEFT,
                                    300,
                                    340,
                                    200,
                                    100,
                                    hWnd,
                                    (HMENU)IPFIX,
                                    GetModuleHandle(NULL),
                                    NULL), WM_SETFONT, WPARAM( GetStockObject(DEFAULT_GUI_FONT) ), MAKELPARAM(FALSE,0) );

        hIPa=CreateWindowEx(0,
                            "COMBOBOX",
                            "",
                            CBS_DROPDOWNLIST | CBS_HASSTRINGS | WS_CHILD | WS_OVERLAPPED | WS_VISIBLE | WS_VSCROLL,
                            355,
                            336,
                            41,
                            24,
                            hWnd,
                            (HMENU)IDC_IPA,
                            GetModuleHandle(NULL),
                            NULL);
        SendMessage(hIPa,
                    WM_SETFONT,
                    (WPARAM)hfDefault,
                    MAKELPARAM(FALSE,0));



        memset(&A,0,sizeof(A));
        for (int k = 0; k < 256; k += 1)
        {
            //strcpy(A, Planets[k]);
            sprintf( A, "%d", k );

            // Add string to combobox.
            SendMessage(hIPa,(UINT) CB_ADDSTRING,(WPARAM) 0,(LPARAM) A);
        }
// Send the CB_SETCURSEL message to display an initial item
//  in the selection field
//        SendMessage( ver_Combo, CB_SETCURSEL, (WPARAM)2, (LPARAM)0);

        hIPb=CreateWindowEx(0,
                            "COMBOBOX",
                            "",
                            CBS_DROPDOWNLIST | CBS_HASSTRINGS | WS_CHILD | WS_OVERLAPPED | WS_VISIBLE | WS_VSCROLL	,
                            410,
                            336,
                            41,
                            24,
                            hWnd,
                            (HMENU)IDC_IPB,
                            GetModuleHandle(NULL),
                            NULL);
        SendMessage(hIPb,
                    WM_SETFONT,
                    (WPARAM)hfDefault,
                    MAKELPARAM(FALSE,0));



        memset(&A,0,sizeof(A));
        for (int k = 0; k < 256; k += 1)
        {
            //strcpy(A, Planets[k]);
            sprintf( A, "%d", k );

            // Add string to combobox.
            SendMessage(hIPb,(UINT) CB_ADDSTRING,(WPARAM) 0,(LPARAM) A);
        }

        HWND set_Button=CreateWindowEx(0,
                                       "BUTTON",
                                       "設定 IP 位置,點選後請稍等數秒",
                                       WS_TABSTOP|WS_VISIBLE|
                                       WS_CHILD|BS_PUSHBUTTON,
                                       300,
                                       396,
                                       200,
                                       24,
                                       hWnd,
                                       (HMENU)IDC_SET_BUTTON,
                                       GetModuleHandle(NULL),
                                       NULL);
        SendMessage(set_Button,
                    WM_SETFONT,
                    (WPARAM)hfDefault,
                    MAKELPARAM(FALSE,0));
        HWND clear_Button=CreateWindowEx(0,
                                         "BUTTON",
                                         "清除 IP 設定,點選後請稍等數秒",
                                         WS_TABSTOP|WS_VISIBLE|
                                         WS_CHILD|BS_PUSHBUTTON,
                                         300,
                                         516,
                                         200,
                                         24,
                                         hWnd,
                                         (HMENU)IDC_CLEAR_BUTTON,
                                         GetModuleHandle(NULL),
                                         NULL);
        SendMessage(clear_Button,
                    WM_SETFONT,
                    (WPARAM)hfDefault,
                    MAKELPARAM(FALSE,0));

        HWND quit_Button=CreateWindowEx(0,
                                        "BUTTON",
                                        "離開",
                                        WS_TABSTOP|WS_VISIBLE|
                                        WS_CHILD|BS_PUSHBUTTON,
                                        300,
                                        456,
                                        200,
                                        24,
                                        hWnd,
                                        (HMENU)IDC_QUIT_BUTTON,
                                        GetModuleHandle(NULL),
                                        NULL);
        SendMessage(quit_Button,
                    WM_SETFONT,
                    (WPARAM)hfDefault,
                    MAKELPARAM(FALSE,0));
    }
    break;

    case WM_COMMAND:
        switch(LOWORD(wParam))
        {
        case IDC_VER_DROP:
        {
            int ItemIndex = SendMessage((HWND) lParam, (UINT) CB_GETCURSEL,
                                        (WPARAM) 0, (LPARAM) 0);
            TCHAR  ListItem[256];
            SendMessage((HWND) lParam, (UINT) CB_GETLBTEXT, (WPARAM) ItemIndex, (LPARAM) ListItem);
            if( !strcmp( ListItem, "Windows XP" ) )
                ver = 1;
            else if( !strcmp( ListItem, "Windows Vista" ) )
                ver = 2;
            else if( !strcmp( ListItem, "Windows 7" ) )
                ver = 3;
            else
                ver = 4;
            //MessageBox(hWnd, (LPCSTR) ListItem, TEXT("Item Selected"), MB_OK);
        }
        break;
        case IDC_IPA:
        {
            int ItemIndex = SendMessage((HWND) lParam, (UINT) CB_GETCURSEL,
                                        (WPARAM) 0, (LPARAM) 0);
            TCHAR  ListItem[256];
            SendMessage((HWND) lParam, (UINT) CB_GETLBTEXT, (WPARAM) ItemIndex, (LPARAM) ListItem);
            ipa = atoi( ListItem );//printf("%d %d\n",ipa,ipb);
            //MessageBox(hWnd, (LPCSTR) ListItem, TEXT("Item Selected"), MB_OK);
        }
        break;
        case IDC_IPB:
        {
            int ItemIndex = SendMessage((HWND) lParam, (UINT) CB_GETCURSEL,
                                        (WPARAM) 0, (LPARAM) 0);
            TCHAR  ListItem[256];
            SendMessage((HWND) lParam, (UINT) CB_GETLBTEXT, (WPARAM) ItemIndex, (LPARAM) ListItem);
            ipb = atoi( ListItem );//printf("%d %d\n",ipa,ipb);
            //MessageBox(hWnd, (LPCSTR) ListItem, TEXT("Item Selected"), MB_OK);
        }
        break;
        case IDC_MAIN_BUTTON:
        {
            char buffer[256];
            SendMessage(hEdit,
                        WM_GETTEXT,
                        sizeof(buffer)/sizeof(buffer[0]),
                        reinterpret_cast<LPARAM>(buffer));
			if( *buffer == 'S' )
				MessageBox( hWnd,"抱歉,我無法找到卡號,請由命令提示字元中輸入 ipconfig /all 來查看卡號","OOPS!",MB_ICONERROR );
            else if( strcmp( buffer, "00:00:00:00:00:00" ) )
            {
                const size_t len = strlen(buffer) + 1;
                HGLOBAL hMem =  GlobalAlloc(GMEM_MOVEABLE, len);
                memcpy(GlobalLock(hMem), buffer, len);
                GlobalUnlock(hMem);
                OpenClipboard(hEdit);
                EmptyClipboard();
                SetClipboardData(CF_TEXT, hMem);
                CloseClipboard();
                MessageBox(hWnd,"已複製到剪貼簿","Copy",MB_ICONINFORMATION);
                //MessageBox(hWnd,buffer,"Copy",MB_ICONINFORMATION);
            }
            else
                MessageBox(hWnd, "複製前請先於步驟一取得網路卡卡號","Nothing to copy...",MB_ICONWARNING);
        }
        break;
        case IDC_MAC_BUTTON:
        {
            //system( "@ipconfig /all > mac.txt" );
            SECURITY_ATTRIBUTES sa;
            sa.nLength = sizeof(sa);
            sa.lpSecurityDescriptor = NULL;
            sa.bInheritHandle = TRUE;
            HANDLE h = CreateFile("mac.txt",
                                  FILE_APPEND_DATA,
                                  FILE_SHARE_WRITE | FILE_SHARE_READ,
                                  &sa,
                                  CREATE_ALWAYS,
                                  FILE_ATTRIBUTE_NORMAL,
                                  NULL );
            STARTUPINFO si;
            ZeroMemory(&si, sizeof(si));
            si.dwFlags |= STARTF_USESTDHANDLES;
            si.hStdInput = NULL;
            si.hStdError = h;
            si.hStdOutput = h;
            si.cb = sizeof(si);

            PROCESS_INFORMATION pi;
            ZeroMemory(&pi, sizeof(pi));

            //creating new process
            //system("ipconfig /all > mac.txt");
            //printf(LPSTR("ipconfig /all > mac.txt"));
            //char Cmd[] = ;
            if( CreateProcess(NULL, LPSTR("ipconfig /all"), NULL, NULL, TRUE, CREATE_NO_WINDOW, NULL, NULL, &si, &pi) )
            {
                //waiting for process termination
                WaitForSingleObject(pi.hProcess, INFINITE);
                //cleanup
                CloseHandle(pi.hProcess);
                CloseHandle(pi.hThread);
            }
//            else
//                MessageBox(hWnd,"DD","AA",MB_OK);
            //MessageBox(hWnd,"已取得網路卡號","Success",MB_OK);
            SetWindowText(hEdit,get_addr());
            CloseHandle(h);
            DeleteFile(LPCTSTR("mac.txt"));
            //MessageBox(hWnd,"已取得網路卡號","Success",MB_ICONINFORMATION);
//			CreateProcess(NULL, "del mac.txt", NULL, NULL, FALSE, CREATE_NO_WINDOW,
//                                         NULL, NULL, &si, &pi);
//            SendMessage(hEdit,
//                    WM_SETTEXT,
//                    NULL,
//                    (LPARAM)"1.2.3.4");
            break;
        }
        case IDC_WEB_BUTTON:
        {
            STARTUPINFO si;
            ZeroMemory(&si, sizeof(si));

            PROCESS_INFORMATION pi;
            ZeroMemory(&pi, sizeof(pi));

            //creating new process
            //system("ipconfig /all > mac.txt");
            //printf(LPSTR("ipconfig /all > mac.txt"));
            //char Cmd[] = ;

            ShellExecute(NULL, "open", "http://flow2.nccu.edu.tw/Reg/stulogin.php", NULL, NULL, SW_SHOWMAXIMIZED);
            //if( CreateProcess(NULL, LPSTR("cmd /C start http://flow2.nccu.edu.tw/Reg/stulogin.php"), NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi) )
            {
                //waiting for process termination
                WaitForSingleObject(pi.hProcess, INFINITE);
                //cleanup
                CloseHandle(pi.hProcess);
                CloseHandle(pi.hThread);
            }
//            else
//				MessageBox(NULL,"aa","bb",MB_OK);
            break;
        }
        case IDC_SET_BUTTON:
        {
            if( !ver )
            {
                MessageBox( hWnd, "請先於步驟五選擇 Windows 版本", "Which type of Windows?", MB_ICONWARNING );
                break;
            }
            else if( ipa < 0 || ipb < 0 )
            {
                MessageBox( hWnd, "請先於步驟六中輸入註冊好的 IP", "No IP...", MB_ICONWARNING );
                break;
            }
            else if( ver == 2 || ver == 3 )
                set();
            else if( ver == 1 )
                setxp();
            else if( ver == 4 )
                set8();
            MessageBox(hWnd,"設定完成!請稍待整點後設定生效再開始上網","Done", MB_ICONINFORMATION);
        }
        break;
        case IDC_QUIT_BUTTON:
            PostQuitMessage( 0 );
            break;
        case IDC_CLEAR_BUTTON:
        {
            STARTUPINFO si;
            ZeroMemory(&si, sizeof(si));
            PROCESS_INFORMATION pi;
            ZeroMemory(&pi, sizeof(pi));
            if( !ver )
            {
                MessageBox( hWnd, "請先於步驟五選擇 Windows 版本", "Which type of Windows?", MB_ICONWARNING );
                break;
            }
            else if( ver == 2 || ver == 3 )
            {
                CreateProcess(NULL, LPSTR("netsh interface ipv4 set address name=\"區域連線\" source=dhcp"), NULL, NULL, TRUE, CREATE_NO_WINDOW, NULL, NULL, &si, &pi);
                WaitForSingleObject(pi.hProcess, INFINITE);
                CloseHandle(pi.hProcess);
                CloseHandle(pi.hThread);
                CreateProcess(NULL, LPSTR("netsh interface ipv4 set dnsservers name=\"區域連線\" source=dhcp"), NULL, NULL, TRUE, CREATE_NO_WINDOW, NULL, NULL, &si, &pi);
                WaitForSingleObject(pi.hProcess, INFINITE);
                CloseHandle(pi.hProcess);
                CloseHandle(pi.hThread);
            }
            else if( ver == 1 )
            {
                CreateProcess(NULL, LPSTR("netsh interface ip set address \"區域連線\" DHCP"), NULL, NULL, TRUE, CREATE_NO_WINDOW, NULL, NULL, &si, &pi);
                WaitForSingleObject(pi.hProcess, INFINITE);
                CloseHandle(pi.hProcess);
                CloseHandle(pi.hThread);
                CreateProcess(NULL, LPSTR("netsh interface ip set dns \"區域連線\" DHCP"), NULL, NULL, TRUE, CREATE_NO_WINDOW, NULL, NULL, &si, &pi);
                WaitForSingleObject(pi.hProcess, INFINITE);
                CloseHandle(pi.hProcess);
                CloseHandle(pi.hThread);
            }
            else if( ver == 4 )
            {
                if( MessageBox(hWnd,"清除 IP 前,請先插入網路線,否則可能無法清除","Did you plug in?",MB_OKCANCEL|MB_ICONWARNING) == IDCANCEL )
                    break;
                CreateProcess(NULL, LPSTR("netsh interface ipv4 set dnsservers name=\"乙太網路\" source=dhcp"), NULL, NULL, TRUE, CREATE_NO_WINDOW, NULL, NULL, &si, &pi);
                WaitForSingleObject(pi.hProcess, INFINITE);
                CloseHandle(pi.hProcess);
                CloseHandle(pi.hThread);
                CreateProcess(NULL, LPSTR("netsh interface set interface name=\"乙太網路\" admin=DISABLED"), NULL, NULL, TRUE, CREATE_NO_WINDOW, NULL, NULL, &si, &pi);
                WaitForSingleObject(pi.hProcess, INFINITE);
                CloseHandle(pi.hProcess);
                CloseHandle(pi.hThread);
                CreateProcess(NULL, LPSTR("netsh interface ipv4 set address name=\"乙太網路\" source=dhcp"), NULL, NULL, TRUE, CREATE_NO_WINDOW, NULL, NULL, &si, &pi);
                WaitForSingleObject(pi.hProcess, INFINITE);
                CloseHandle(pi.hProcess);
                CloseHandle(pi.hThread);
                CreateProcess(NULL, LPSTR("netsh interface set interface name=\"乙太網路\" admin=ENABLED"), NULL, NULL, TRUE, CREATE_NO_WINDOW, NULL, NULL, &si, &pi);
                WaitForSingleObject(pi.hProcess, INFINITE);
                CloseHandle(pi.hProcess);
                CloseHandle(pi.hThread);
            }
            MessageBox( hWnd, "已清除 IP 設定,如要再次設定,請再次操作", "Cleared", MB_ICONINFORMATION );
            break;
        }
        }
        break;

    case WM_DESTROY:
    {
        PostQuitMessage(0);
        return 0;
    }
    break;
    }

    return DefWindowProc(hWnd,msg,wParam,lParam);
}
示例#11
0
RTPPacket* FECDecoder::Recover()
{
	BYTE aux[8];
	QWORD lostMask = 0;

	//Check we have media pacekts
	if (!medias.size())
		//Exit
		return NULL;
	//Get First packet
	RTPPacket* first = medias.begin()->second;
	//Get the SSRC
	DWORD ssrc = first->GetSSRC();
	//Get first media packet
	DWORD minSeq = first->GetExtSeqNum();
	//Iterator on seq
	DWORD lastSeq = minSeq;

	//Set to 0
	memset(aux,0,8);
	//Create writter
	BitWritter w(aux,8);
	//vector of lost pacekt seq
	std::vector<DWORD> losts;

	//For each media packet
	for (RTPOrderedPackets::iterator it=medias.begin();it!=medias.end();++it)
	{
		//Get seq
		DWORD cur = it->first;
		//Insert lost
		for (DWORD i=lastSeq+1;i<cur;++i)
		{
			//set mask bit to not present
			w.Put(1,0);
			//Add to the vecotr
			losts.push_back(i);
		}
		//Set last seq
		lastSeq = cur;
		//set mask bit to present
		w.Put(1,1);
	}

	//End it
	w.Flush();

	//Get mask
	lostMask = get8(aux,0);

	//Check we have lost pacekts
	if (!losts.size())
		//Exit
		return NULL;

	//For each lost packet
	for(std::vector<DWORD>::iterator it=losts.begin();it!=losts.end();++it)
	{
		//Get lost packet sequence
		DWORD seq = *it;

		//Search FEC packets associated this media packet
		for (FECOrderedData::iterator it2 = codes.begin();it2!=codes.end();++it2)
		{
			//Get FEC packet
			FECData *fec = it2->second;

			//Check if it is associated with this media pacekt in level 0
			if (!fec->IsProtectedAtLevel0(seq))
				//Next
				continue;

			//Get the seq difference between fec data and the media
			// fec seq has to be <= media seq it fec data protect media data)
			DWORD diff = seq-fec->GetBaseExtSeq();
			//Shit mask of the lost packets to check the present ones from the base seq
			QWORD mediaMask = lostMask << (fec->GetBaseExtSeq()-minSeq);
			//Remove lost packet bit from the fec mask
			QWORD fecMask = fec->GetLevel0Mask() & ~(((QWORD)1)<<(64-diff-1));

			//Compare needed pacekts with actual pacekts, to check if we have all of them except the missing
			if ((fecMask & mediaMask) == fecMask)
			{
				//Rocovered media data
				BYTE	recovered[MTU+SRTP_MAX_TRAILER_LEN] ZEROALIGNEDTO32;
				//Get attributes
				bool  p  = fec->GetRecoveryP();
				bool  x  = fec->GetRecoveryX();
				BYTE  cc = fec->GetRecoveryCC();
				bool  m  = fec->GetRecoveryM();
				BYTE  pt = fec->GetRecoveryType();
				DWORD ts = fec->GetRecoveryTimestamp();
				WORD  l  = fec->GetRecoveryLength();
				//Get protection length
				DWORD level0Size = fec->GetLevel0Size();
				//Ensure there is enought size
				if (level0Size>MTU)
				{
					//Error
					Error("-FEC level 0 data size too big [%d]\n",level0Size);
					//Skip this one
					continue;
				}
				//Copy data
				memcpy(recovered,fec->GetLevel0Data(),level0Size);
				//Set value in temp buffer
				set8(aux,0,fecMask);
				//Get bit reader
				BitReader r(aux,8);
				//Read all media packet
				while(r.Left())
				{
					//If the media packet is used to reconstrud the packet
					if (r.Get(1))
					{
						//Get media packet
						RTPPacket* media = medias[fec->GetBaseExtSeq()+r.GetPos()-1];
						//Calculate receovered attributes
						p  ^= media->GetP();
						x  ^= media->GetX();
						cc ^= media->GetCC();
						m  ^= media->GetMark();
						pt ^= media->GetType();
						ts ^= media->GetTimestamp();
						l  ^= media->GetMediaLength();
						//Get data
						BYTE *payload = media->GetMediaData();
						//Calculate the xor
						for (int i=0;i<fmin(media->GetMediaLength(),level0Size);++i)
							//XOR
							recovered[i] ^= payload[i];
					}
				}
				//Create new video packet
				RTPPacket* packet = new RTPPacket(MediaFrame::Video,pt);
				//Set values
				packet->SetP(p);
				packet->SetX(x);
				packet->SetMark(m);
				packet->SetTimestamp(ts);
				//Set sequence number
				packet->SetSeqNum(seq);
				//Set seq cycles
				packet->SetSeqCycles(fec->GetBaseSeqCylcles());
				//Set ssrc
				packet->SetSSRC(ssrc);
				//Set payload and recovered length
				if (!packet->SetPayloadWithExtensionData(recovered,l))
				{
					//Delete packet
					delete(packet);
					//Error
					Error("-FEC payload of recovered packet to big [%u]\n",(unsigned int)l);
					//Skip
					continue;
				}

				Debug("-recovered packet len:%u ts:%u pts:%u seq:%d\n",l,ts,packet->GetTimestamp() ,packet->GetSeqNum());

				//Append the packet to the media packet list
				if (AddPacket(packet))
					//Return it if contained media
					return packet;
				else
					//Discard and continue
					delete(packet);
			}
		}
	}
	//Nothing found
	return NULL;
}