Subversion Repositories Kolibri OS

Rev

Rev 815 | Go to most recent revision | 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.     default:
  181.       return ERR_PARAM;
  182.   };
  183.   return ERR_PARAM;
  184. }
  185.  
  186.  
  187. #include "init.c"
  188. #include "pci.c"
  189. #include "ati_mem.c"
  190. //#include "cursor.inc"
  191.  
  192. #include "r500.inc"
  193. #include "accel_2d.inc"
  194. #include "accel_3d.inc"
  195.  
  196. #define CLIP_TOP        1
  197. #define CLIP_BOTTOM     2
  198. #define CLIP_RIGHT      4
  199. #define CLIP_LEFT       8
  200.  
  201.  
  202. char _L1OutCode( int x, int y )
  203. /*=================================
  204.  
  205.     Verify that a point is inside or outside the active viewport.   */
  206. {
  207.     char            flag;
  208.  
  209.     flag = 0;
  210.     if( x < clip.xmin ) {
  211.         flag |= CLIP_LEFT;
  212.     } else if( x > clip.xmax ) {
  213.         flag |= CLIP_RIGHT;
  214.     }
  215.     if( y < clip.ymin ) {
  216.         flag |= CLIP_TOP;
  217.     } else if( y > clip.ymax ) {
  218.         flag |= CLIP_BOTTOM;
  219.     }
  220.     return( flag );
  221. }
  222.  
  223.  
  224. static void line_inter( int * x1, int* y1, int x2, int y2, int x )
  225. /*===========================================================================
  226.  
  227.     Find the intersection of a line with a boundary of the viewport.
  228.     (x1, y1) is outside and ( x2, y2 ) is inside the viewport.
  229.     NOTE : the signs of denom and ( x - *x1 ) cancel out during division
  230.            so make both of them positive before rounding.   */
  231. {
  232.     int            numer;
  233.     int            denom;
  234.  
  235.     denom = abs( x2 - *x1 );
  236.     numer = 2L * (long)( y2 - *y1 ) * abs( x - *x1 );
  237.     if( numer > 0 ) {
  238.         numer += denom;                     /* round to closest pixel   */
  239.     } else {
  240.         numer -= denom;
  241.     }
  242.     *y1 += numer / ( denom << 1 );
  243.     *x1 = x;
  244. }
  245.  
  246.  
  247. int LineClip( int *x1, int *y1, int *x2, int *y2 )
  248. /*=============================================================
  249.  
  250.     Clips the line with end points (x1,y1) and (x2,y2) to the active
  251.     viewport using the Cohen-Sutherland clipping algorithm. Return the
  252.     clipped coordinates and a decision drawing flag.    */
  253. {
  254.     char            flag1;
  255.     char            flag2;
  256.  
  257.     flag1 = _L1OutCode( *x1, *y1 );
  258.     flag2 = _L1OutCode( *x2, *y2 );
  259.     for( ;; ) {
  260.         if( flag1 & flag2 ) break;                  /* trivially outside    */
  261.         if( flag1 == flag2 ) break;                 /* completely inside    */
  262.         if( flag1 == 0 ) {                          /* first point inside   */
  263.             if( flag2 & CLIP_TOP ) {
  264.                 line_inter( y2, x2, *y1, *x1, clip.ymin );
  265.             } else if( flag2 & CLIP_BOTTOM ) {
  266.                 line_inter( y2, x2, *y1, *x1, clip.ymax );
  267.             } else if( flag2 & CLIP_RIGHT ) {
  268.                 line_inter( x2, y2, *x1, *y1, clip.xmax );
  269.             } else if( flag2 & CLIP_LEFT ) {
  270.                 line_inter( x2, y2, *x1, *y1, clip.xmin );
  271.             }
  272.             flag2 = _L1OutCode( *x2, *y2 );
  273.         } else {                                    /* second point inside  */
  274.             if( flag1 & CLIP_TOP ) {
  275.                 line_inter( y1, x1, *y2, *x2, clip.ymin );
  276.             } else if( flag1 & CLIP_BOTTOM ) {
  277.                 line_inter( y1, x1, *y2, *x2, clip.ymax );
  278.             } else if( flag1 & CLIP_RIGHT ) {
  279.                 line_inter( x1, y1, *x2, *y2, clip.xmax );
  280.             } else if( flag1 & CLIP_LEFT ) {
  281.                 line_inter( x1, y1, *x2, *y2, clip.xmin );
  282.             }
  283.             flag1 = _L1OutCode( *x1, *y1 );
  284.         }
  285.     }
  286.     return( flag1 & flag2 );
  287. }
  288.  
  289.  
  290. static void block_inter( int *x, int *y, int flag )
  291. /*======================================================
  292.  
  293.     Find the intersection of a block with a boundary of the viewport.   */
  294. {
  295.     if( flag & CLIP_TOP ) {
  296.         *y = clip.ymin;
  297.     } else if( flag & CLIP_BOTTOM ) {
  298.         *y = clip.ymax;
  299.     } else if( flag & CLIP_RIGHT ) {
  300.         *x = clip.xmax;
  301.     } else if( flag & CLIP_LEFT ) {
  302.         *x = clip.xmin;
  303.     }
  304. }
  305.  
  306.  
  307. int BlockClip( int *x1, int *y1, int *x2, int* y2 )
  308. /*==============================================================
  309.  
  310.     Clip a block with opposite corners (x1,y1) and (x2,y2) to the
  311.     active viewport based on the Cohen-Sutherland algorithm for line
  312.     clipping. Return the clipped coordinates and a decision drawing
  313.     flag ( 0 draw : 1 don't draw ). */
  314. {
  315.     char            flag1;
  316.     char            flag2;
  317.  
  318.     flag1 = _L1OutCode( *x1, *y1 );
  319.     flag2 = _L1OutCode( *x2, *y2 );
  320.     for( ;; ) {
  321.         if( flag1 & flag2 ) break;                  /* trivially outside    */
  322.         if( flag1 == flag2 ) break;                 /* completely inside    */
  323.         if( flag1 == 0 ) {
  324.             block_inter( x2, y2, flag2 );
  325.             flag2 = _L1OutCode( *x2, *y2 );
  326.         } else {
  327.             block_inter( x1, y1, flag1 );
  328.             flag1 = _L1OutCode( *x1, *y1 );
  329.         }
  330.     }
  331.     return( flag1 & flag2 );
  332. }
  333.  
  334. #if 0
  335. typedef struct
  336. {
  337.    int left;
  338.    int top;
  339.    int right;
  340.    int bottom;
  341. }rect_t;
  342.  
  343. typedef struct _window
  344. {
  345.    struct _window *fd;
  346.    struct _window *bk;
  347.  
  348.    rect_t pos;
  349.    int width;
  350.    int height;
  351.  
  352.    int level;
  353. }win_t, *WINPTR;
  354.  
  355.  
  356. WINPTR top    = NULL;
  357. WINPTR bottom = NULL;
  358.  
  359. WINPTR alloc_window()
  360. {
  361.     WINPTR pwin = malloc(sizeof(win_t));
  362.  
  363.     return pwin;
  364. };
  365.  
  366.  
  367. WINPTR create_win(int l, int t, int w, int h, int level)
  368. {
  369.    WINPTR pwin = alloc_window();
  370.  
  371.    pwin->pos.left   = l;
  372.    pwin->pos.top    = t;
  373.    pwin->pos.right  = l+w-1;
  374.    pwin->pos.bottom = t+h-1;
  375.    pwin->width      = w;
  376.    pwin->height     = h;
  377.  
  378.    pwin->level      = level;
  379.  
  380.    return pwin;
  381. };
  382.  
  383. void insert_window(WINPTR pwin)
  384. {
  385.    WINPTR p = top;
  386.  
  387.    if(p)
  388.    {
  389.      if(pwin->level <= p->level)
  390.      {
  391.         pwin->fd = p;
  392.         pwin->bk = p->bk;
  393.         pwin->bk->fd = pwin;
  394.         p->bk = pwin;
  395.      }
  396.      else
  397.        p = p->fd;
  398.    }
  399.    else
  400.      top = pwin;
  401. }
  402.  
  403. #endif
  404.