Subversion Repositories Kolibri OS

Rev

Rev 829 | Blame | Last modification | View Log | Download | RSS feed

  1.  
  2. //ld -T ld.x -s --shared --image-base 0 --file-alignment 32 -o test.exe test.obj core.lib
  3.  
  4. #include "common.h"
  5. #include "ati2d.h"
  6. #include "accel_2d.h"
  7.  
  8. RHD_t rhd;
  9.  
  10. pixmap_t scr_pixmap;
  11.  
  12. static clip_t  clip;
  13.  
  14.  
  15. void STDCALL (*SelectHwCursor)(cursor_t*)__asm__("SelectHwCursor");
  16. void STDCALL (*SetHwCursor)(cursor_t*,int x,int y)__asm__("SetHwCursor");
  17. void STDCALL (*HwCursorRestore)(int x, int y)__asm("HwCursorRestore");
  18. cursor_t* IMPORT (*HwCursorCreate)(void)__asm("HwCursorCreate"); //params eax, ebx, ecx
  19.  
  20. void (__stdcall *old_select)(cursor_t*);
  21. void (__stdcall *old_set)(cursor_t*,int x,int y);
  22. void (__stdcall *old_restore)(int x, int y);
  23. cursor_t* (*old_create)(void);
  24. cursor_t* __create_cursor(void);
  25.  
  26. static void Init3DEngine(RHDPtr rhdPtr);
  27.  
  28. u32 __stdcall drvEntry(int action)
  29. {
  30.   RHDPtr rhdPtr;
  31.   u32 retval;
  32.  
  33.   int i;
  34.  
  35.   if(action != 1)
  36.     return 0;
  37.  
  38.   if(!dbg_open("/hd0/2/ati2d.log"))
  39.   {
  40.      printf("Can't open /rd/1/drivers/ati2d.log\nExit\n");
  41.      return 0;
  42.   }
  43.  
  44.   if((rhdPtr=FindPciDevice())==NULL)
  45.   {
  46.     dbgprintf("Device not found\n");
  47.     return 0;
  48.   };
  49.  
  50.   for(i=0;i<6;i++)
  51.   {
  52.     if(rhd.memBase[i])
  53.       dbgprintf("Memory base_%d 0x%x size 0x%x\n",
  54.                 i,rhd.memBase[i],(1<<rhd.memsize[i]));
  55.   };
  56.   for(i=0;i<6;i++)
  57.   {
  58.     if(rhd.ioBase[i])
  59.       dbgprintf("Io base_%d 0x%x size 0x%x\n",
  60.                 i,rhd.ioBase[i],(1<<rhd.memsize[i]));
  61.   };
  62.   if(!RHDPreInit())
  63.     return 0;
  64.  
  65. //  old_select = SelectHwCursor;
  66. //  old_set = SetHwCursor;
  67. //  old_restore = HwCursorRestore ;
  68. //  old_create = HwCursorCreate;
  69.  
  70.   R5xx2DInit();
  71.   rhd.has_tcl = 1;
  72. //  Init3DEngine(&rhd);
  73.  
  74.   //init_r500();
  75.  
  76.  // SelectHwCursor  = r500_SelectCursor;
  77.  // SetHwCursor     = r500_SetCursor;
  78.  // HwCursorCreate  = __create_cursor;
  79.  // HwCursorRestore = r500_CursorRestore;
  80.  
  81.   retval = RegService("HDRAW", srv_2d);
  82.   dbgprintf("reg service %s as: %x\n", "HDRAW", retval);
  83.  
  84. //  retval = RegService("HWCURSOR", srv_cursor);
  85.   return retval;
  86. };
  87.  
  88.  
  89. #pragma pack (push,1)
  90.  
  91. #pragma pack (pop)
  92.  
  93. #define API_VERSION     0x01000100
  94.  
  95. #define SRV_GETVERSION  0
  96.  
  97. int _stdcall srv_cursor(ioctl_t *io)
  98. {
  99.   u32 *inp;
  100.   u32 *outp;
  101.  
  102.   inp = io->input;
  103.   outp = io->output;
  104.  
  105.   switch(io->io_code)
  106.   {
  107.     case SRV_GETVERSION:
  108.       if(io->out_size==4)
  109.       {
  110.         *(u32*)io->output = API_VERSION;
  111.         return 0;
  112.       }
  113.       break;
  114.  
  115.     default:
  116.       return ERR_PARAM;
  117.   };
  118.   return ERR_PARAM;
  119. }
  120.  
  121.  
  122. int _stdcall srv_2d(ioctl_t *io)
  123. {
  124.   u32 *inp;
  125.   u32 *outp;
  126.  
  127.   inp = io->input;
  128.   outp = io->output;
  129.  
  130.   switch(io->io_code)
  131.   {
  132.     case SRV_GETVERSION:
  133.       if(io->out_size==4)
  134.       {
  135.         *outp = API_VERSION;
  136.         return 0;
  137.       }
  138.       break;
  139.  
  140.       case DRAW_RECT:
  141.         if(io->inp_size==6)
  142.           return DrawRect((draw_t*)inp);
  143.         break;
  144.  
  145.       case FILL_RECT:
  146.         if(io->inp_size==9)
  147.           return FillRect((fill_t*)inp);
  148.         break;
  149.  
  150.       case LINE_2P:
  151.         if(io->inp_size==5)
  152.           return Line2P((line2p_t*)inp);
  153.         break;
  154.  
  155.       case BLIT:
  156.         if(io->inp_size==6)
  157.           return Blit((blit_t*)inp);
  158.         break;
  159.  
  160.       case COMPIZ:
  161.         if(io->inp_size==6)
  162.           return RadeonComposite((blit_t*)inp);
  163.         break;
  164.  
  165.       case PIXMAP:
  166.         if(io->inp_size==6)
  167.           return CreatePixmap((userpixmap_t*)inp);
  168.         break;
  169.  
  170.       case PIXBLIT:
  171.         if(io->inp_size==8)
  172.           return PixBlit((pixblit_t*)inp);
  173.         break;
  174.  
  175.       case PIXLOCK:
  176.         if(io->inp_size==6)
  177.           return LockPixmap((userpixmap_t*)inp);
  178.         break;
  179.  
  180.       case PIXUNLOCK:
  181.         if(io->inp_size==6)
  182.           return UnlockPixmap((userpixmap_t*)inp);
  183.         break;
  184.  
  185.       case PIXDESTROY:
  186.         if(io->inp_size==6)
  187.           return DestroyPixmap((userpixmap_t*)inp);
  188.         break;
  189.  
  190.      case  TRANSBLIT:
  191.         if(io->inp_size==8)
  192.           return TransBlit((pixblit_t*)inp);
  193.         break;
  194.  
  195.  
  196.     default:
  197.       return ERR_PARAM;
  198.   };
  199.   return ERR_PARAM;
  200. }
  201.  
  202.  
  203. #include "init.c"
  204. #include "pci.c"
  205. #include "ati_mem.c"
  206. //#include "cursor.inc"
  207.  
  208. #include "r500.inc"
  209. #include "accel_2d.inc"
  210. #include "accel_3d.inc"
  211.  
  212. #define CLIP_TOP        1
  213. #define CLIP_BOTTOM     2
  214. #define CLIP_RIGHT      4
  215. #define CLIP_LEFT       8
  216.  
  217.  
  218. char _L1OutCode( int x, int y )
  219. /*=================================
  220.  
  221.     Verify that a point is inside or outside the active viewport.   */
  222. {
  223.     char            flag;
  224.  
  225.     flag = 0;
  226.     if( x < clip.xmin ) {
  227.         flag |= CLIP_LEFT;
  228.     } else if( x > clip.xmax ) {
  229.         flag |= CLIP_RIGHT;
  230.     }
  231.     if( y < clip.ymin ) {
  232.         flag |= CLIP_TOP;
  233.     } else if( y > clip.ymax ) {
  234.         flag |= CLIP_BOTTOM;
  235.     }
  236.     return( flag );
  237. }
  238.  
  239.  
  240. static void line_inter( int * x1, int* y1, int x2, int y2, int x )
  241. /*===========================================================================
  242.  
  243.     Find the intersection of a line with a boundary of the viewport.
  244.     (x1, y1) is outside and ( x2, y2 ) is inside the viewport.
  245.     NOTE : the signs of denom and ( x - *x1 ) cancel out during division
  246.            so make both of them positive before rounding.   */
  247. {
  248.     int            numer;
  249.     int            denom;
  250.  
  251.     denom = abs( x2 - *x1 );
  252.     numer = 2L * (long)( y2 - *y1 ) * abs( x - *x1 );
  253.     if( numer > 0 ) {
  254.         numer += denom;                     /* round to closest pixel   */
  255.     } else {
  256.         numer -= denom;
  257.     }
  258.     *y1 += numer / ( denom << 1 );
  259.     *x1 = x;
  260. }
  261.  
  262.  
  263. int LineClip( int *x1, int *y1, int *x2, int *y2 )
  264. /*=============================================================
  265.  
  266.     Clips the line with end points (x1,y1) and (x2,y2) to the active
  267.     viewport using the Cohen-Sutherland clipping algorithm. Return the
  268.     clipped coordinates and a decision drawing flag.    */
  269. {
  270.     char            flag1;
  271.     char            flag2;
  272.  
  273.     flag1 = _L1OutCode( *x1, *y1 );
  274.     flag2 = _L1OutCode( *x2, *y2 );
  275.     for( ;; ) {
  276.         if( flag1 & flag2 ) break;                  /* trivially outside    */
  277.         if( flag1 == flag2 ) break;                 /* completely inside    */
  278.         if( flag1 == 0 ) {                          /* first point inside   */
  279.             if( flag2 & CLIP_TOP ) {
  280.                 line_inter( y2, x2, *y1, *x1, clip.ymin );
  281.             } else if( flag2 & CLIP_BOTTOM ) {
  282.                 line_inter( y2, x2, *y1, *x1, clip.ymax );
  283.             } else if( flag2 & CLIP_RIGHT ) {
  284.                 line_inter( x2, y2, *x1, *y1, clip.xmax );
  285.             } else if( flag2 & CLIP_LEFT ) {
  286.                 line_inter( x2, y2, *x1, *y1, clip.xmin );
  287.             }
  288.             flag2 = _L1OutCode( *x2, *y2 );
  289.         } else {                                    /* second point inside  */
  290.             if( flag1 & CLIP_TOP ) {
  291.                 line_inter( y1, x1, *y2, *x2, clip.ymin );
  292.             } else if( flag1 & CLIP_BOTTOM ) {
  293.                 line_inter( y1, x1, *y2, *x2, clip.ymax );
  294.             } else if( flag1 & CLIP_RIGHT ) {
  295.                 line_inter( x1, y1, *x2, *y2, clip.xmax );
  296.             } else if( flag1 & CLIP_LEFT ) {
  297.                 line_inter( x1, y1, *x2, *y2, clip.xmin );
  298.             }
  299.             flag1 = _L1OutCode( *x1, *y1 );
  300.         }
  301.     }
  302.     return( flag1 & flag2 );
  303. }
  304.  
  305.  
  306. static void block_inter( int *x, int *y, int flag )
  307. /*======================================================
  308.  
  309.     Find the intersection of a block with a boundary of the viewport.   */
  310. {
  311.     if( flag & CLIP_TOP ) {
  312.         *y = clip.ymin;
  313.     } else if( flag & CLIP_BOTTOM ) {
  314.         *y = clip.ymax;
  315.     } else if( flag & CLIP_RIGHT ) {
  316.         *x = clip.xmax;
  317.     } else if( flag & CLIP_LEFT ) {
  318.         *x = clip.xmin;
  319.     }
  320. }
  321.  
  322.  
  323. int BlockClip( int *x1, int *y1, int *x2, int* y2 )
  324. /*==============================================================
  325.  
  326.     Clip a block with opposite corners (x1,y1) and (x2,y2) to the
  327.     active viewport based on the Cohen-Sutherland algorithm for line
  328.     clipping. Return the clipped coordinates and a decision drawing
  329.     flag ( 0 draw : 1 don't draw ). */
  330. {
  331.     char            flag1;
  332.     char            flag2;
  333.  
  334.     flag1 = _L1OutCode( *x1, *y1 );
  335.     flag2 = _L1OutCode( *x2, *y2 );
  336.     for( ;; ) {
  337.         if( flag1 & flag2 ) break;                  /* trivially outside    */
  338.         if( flag1 == flag2 ) break;                 /* completely inside    */
  339.         if( flag1 == 0 ) {
  340.             block_inter( x2, y2, flag2 );
  341.             flag2 = _L1OutCode( *x2, *y2 );
  342.         } else {
  343.             block_inter( x1, y1, flag1 );
  344.             flag1 = _L1OutCode( *x1, *y1 );
  345.         }
  346.     }
  347.     return( flag1 & flag2 );
  348. }
  349.  
  350. #if 0
  351. typedef struct
  352. {
  353.    int left;
  354.    int top;
  355.    int right;
  356.    int bottom;
  357. }rect_t;
  358.  
  359. typedef struct _window
  360. {
  361.    struct _window *fd;
  362.    struct _window *bk;
  363.  
  364.    rect_t pos;
  365.    int width;
  366.    int height;
  367.  
  368.    int level;
  369. }win_t, *WINPTR;
  370.  
  371.  
  372. WINPTR top    = NULL;
  373. WINPTR bottom = NULL;
  374.  
  375. WINPTR alloc_window()
  376. {
  377.     WINPTR pwin = malloc(sizeof(win_t));
  378.  
  379.     return pwin;
  380. };
  381.  
  382.  
  383. WINPTR create_win(int l, int t, int w, int h, int level)
  384. {
  385.    WINPTR pwin = alloc_window();
  386.  
  387.    pwin->pos.left   = l;
  388.    pwin->pos.top    = t;
  389.    pwin->pos.right  = l+w-1;
  390.    pwin->pos.bottom = t+h-1;
  391.    pwin->width      = w;
  392.    pwin->height     = h;
  393.  
  394.    pwin->level      = level;
  395.  
  396.    return pwin;
  397. };
  398.  
  399. void insert_window(WINPTR pwin)
  400. {
  401.    WINPTR p = top;
  402.  
  403.    if(p)
  404.    {
  405.      if(pwin->level <= p->level)
  406.      {
  407.         pwin->fd = p;
  408.         pwin->bk = p->bk;
  409.         pwin->bk->fd = pwin;
  410.         p->bk = pwin;
  411.      }
  412.      else
  413.        p = p->fd;
  414.    }
  415.    else
  416.      top = pwin;
  417. }
  418.  
  419. #endif
  420.