home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / coders / mesa-1.2.8 / mondello / graphics.c < prev    next >
C/C++ Source or Header  |  1996-05-27  |  11KB  |  421 lines

  1. /* 
  2.   file: graphics.c
  3. */
  4.  
  5. #include <stdio.h>
  6. #include <string.h>  /* memcpy() in tritemp.h */
  7.  
  8. #include "mondello/graphics.h"
  9. #include "mondello/davinci.h"
  10. #include "mondello/clgd5470.h"
  11. #include "mondello/clgd547x.h"
  12. #include "mondello/compiler.h" /* inb(), outb() */
  13. #include "mondello/type.h"
  14.  
  15. #include "../src/vb.h"
  16. #include "../src/config.h"
  17.  
  18. /* uncomment the following to insert debugging code */
  19. /*  #define DEBUG_clgd547x */
  20.  
  21. /* uncomment the following to cause each primitive to be immediately
  22.  * executed.  This is useful for debugging and significantly slows
  23.  * down execution as it busy-waits for each instruction to finish 
  24.  */
  25. /* #define IMMEDIATE_EXECUTION */
  26.  
  27. /* uncomment the following to have bypass actually executing the 
  28.  * instruction and instead have information about what would have
  29.  * be done dumped to the screen (this only works for polygons)
  30.  */
  31. /* #define DUMP_ON_EXEC */
  32.  
  33. #define COMPILE_MESA_STUBS  
  34.  
  35. #define BUSY (!(inWarp(0x24)&0x80000000))
  36.  
  37. #define EXEC                                \
  38.         { *listPtr++=IDLE;                        \
  39.       *listPtr++=IDLE;                        \
  40.       *listPtr++=IDLE;                        \
  41.       outWarp(HOST_INSTRUCTION_REG,branch_ro(0x00000000));        \
  42.       while(BUSY);                            \
  43.       listPtr=clgd5470LogicalBase;                    \
  44.     }
  45.  
  46. #define EXEC2 { while(BUSY);                        \
  47.             *listPtr++=IDLE;                    \
  48.             *listPtr++=IDLE;                    \
  49.             *listPtr++=IDLE;                    \
  50.                 if (listNum==0) {                    \
  51.                   outWarp(HOST_INSTRUCTION_REG,branch_ro(0x00000000));    \
  52.                   listPtr=listPtr1;                    \
  53.                   listMax=listMax1;                    \
  54.                   listNum=1;                        \
  55.                 }                            \
  56.                 else {                            \
  57.                   outWarp(HOST_INSTRUCTION_REG,branch_ro(0x00080000));    \
  58.                   listPtr=listPtr0;                    \
  59.                   listMax=listMax0;                    \
  60.                   listNum=0;                        \
  61.                 }                            \
  62.               }
  63.  
  64. #ifdef DUMP_ON_EXEC
  65. #  define CHKEXECPOLY dumpContents();
  66. #else
  67. #  define CHKEXECPOLY CHKEXEC
  68. #endif
  69.  
  70. #ifdef IMMEDIATE_EXECUTION
  71. #  ifndef CHKEXEC
  72. #    define CHKEXEC EXEC
  73. #  endif
  74. #endif
  75.  
  76. #ifndef CHKEXEC
  77. #  define CHKEXEC { if (listPtr >= listMax) {                 \
  78.                     EXEC2;                        \
  79.                   }                            \
  80.                 }
  81. #endif
  82.  
  83. #define SPINWAIT { while(BUSY); }                  
  84. #define SPINWARP EXEC SPINWAIT
  85.  
  86. #define FRACT 12
  87. #define ONESLOPE 1<<FRACT
  88.  
  89. #define ASL(x,count) (x<<count)
  90.  
  91. #define FN(z) (( (-z) & 0x7fff ) >> 1)
  92.  
  93. uint cx1, cy1, cx2, cy2;
  94. uint zlev=0;
  95. uint yoffs=0;
  96.  
  97. uint flipHeight=1023;
  98.   
  99. /**************** UTILITY FUNCTIONS ******************/
  100.  
  101. /* used in tritemp.h for flipping y's */
  102. #define FLIP(Y) (flipHeight-(Y))
  103.  
  104. void setMondelloHeight(int h)
  105. {
  106.   flipHeight = h-1;
  107. }
  108.  
  109. #ifdef DUMP_ON_EXEC
  110. void dumpContents()
  111. {
  112.   uint i;
  113.   for(i=0; i<16; i++) {
  114.     printf("R%2d: %8X\n",i+1,*(clgd5470LogicalBase+2+i));
  115.   }
  116.   /* listPtr=clgd5470LogicalBase; */
  117. }
  118. #endif
  119.  
  120. void clgd547x_flush()
  121. {
  122. #ifdef DEBUG_clgd547x
  123.   printf("clgd547x_flush()\n");
  124. #endif
  125.   EXEC;
  126. }
  127.  
  128. void clgd547x_finish()
  129. {
  130. #ifdef DEBUG_clgd547x
  131.   printf("clgd547x_finish()\n");
  132. #endif
  133.   EXEC;
  134. }
  135.  
  136. void clgd547x_setBuffer(int buffer)            /* 0=front, 1=back */
  137. {
  138.   int i;
  139.   
  140. #ifdef DEBUG_clgd547x
  141.   printf("clgd547x_setBuffer(%d)\n",buffer);
  142. #endif
  143.  
  144.   *listPtr++ = SNOP;
  145.   *listPtr++ = SNOP;
  146.   for(i=0; i<22; i++) {
  147.     *listPtr++ = IDLE;
  148.   }
  149.  
  150.   EXEC;
  151.   SPINWAIT;
  152.     
  153.   outWarp(MASK_B_REG, ~0x02000000 );
  154.  
  155.   if (buffer==0) {
  156.     outWarp(REF0_REG,0x00800000);
  157.     yoffs=512;
  158.   }
  159.   else { 
  160.     outWarp(REF0_REG,0x00A00000);
  161.     yoffs=0;    
  162.   }
  163.   
  164.   outWarp(MASK_B_REG, 0xf7ffffff );
  165.   outWarp(MASK_REG, 0xffffffff );  
  166.  
  167. }
  168.  
  169. /******************* Area Blit Functions ********************/
  170. #define BLIT_VARS                \
  171.   int r1, r2;                    \
  172.   int y_count = y2-y1;
  173.  
  174. #define BLIT_CODE_1                \
  175. /*  listPtr=clgd5470LogicalBase; */         \
  176.   r1=(y_count >> 8) << 24 | (y1+yoffs) << FRACT;\
  177.   r2=y_count<<24 | 0x1000;
  178.  
  179. #define BLIT_CODE_2                \
  180.   *listPtr++=r1;                \
  181.   *listPtr++=r2;                \
  182.   *listPtr++=x1 << FRACT;            \
  183.   *listPtr++=(x2-x1) << FRACT;
  184.  
  185.  
  186. void clgd547x_clearDepthBuffer()
  187. {
  188.   uint x1=0;
  189.   uint y1=0;
  190.   uint x2=clgd547xStateInfo->width;
  191.   uint y2=clgd547xStateInfo->height;
  192.   BLIT_VARS
  193.  
  194. #ifdef DEBUG_clgd547x
  195.   printf("clgd547x_clearDepthBuffer\n");
  196. #endif
  197.   
  198.   BLIT_CODE_1 
  199.  
  200.   *listPtr++=SNOP;  
  201.   *listPtr++=load_long_ro(C_AND_A_REG,1);  /* load long */
  202.   *listPtr++=0xffff0000;           
  203.   *listPtr++=load_long_ro(MASK_B_REG, 1);
  204.   *listPtr++=0xf7ffffff;
  205.   *listPtr++=load_short_ro(BANK_MASK_REG, RED_BANK|GREEN_BANK|BLUE_BANK);
  206.   *listPtr++=SNOP;
  207.   *listPtr++=blit_ro(BLTFZ,PRAMPAT+PATA_PATB+PRAMALF,A_ONLY); 
  208.   
  209.   BLIT_CODE_2
  210.  
  211.   CHKEXEC;
  212.   
  213. }
  214.  
  215. void clearArea8_2c(uint x1, uint y1, uint x2, uint y2, uint cindex)
  216. {
  217.   BLIT_VARS
  218.  
  219. #ifdef DEBUG_clgd547x
  220.   printf("clearArea8_2c(%d,%d,%d,%d,%d)\n",x1,y1,x2,y2,cindex);
  221. #endif
  222.  
  223.   BLIT_CODE_1 
  224.  
  225.   cindex &= 0x000000ff;
  226.   
  227.   *listPtr++=SNOP;
  228.   *listPtr++=load_long_ro(C_AND_A_REG,1);
  229.   *listPtr++=0xffff0000 | cindex << 8 | cindex;                  
  230.   *listPtr++=load_long_ro(MASK_B_REG, 1);
  231.   *listPtr++=0xf7ffffff;
  232.   *listPtr++=load_short_ro(BANK_MASK_REG, BLUE_BANK );  
  233.   *listPtr++=SNOP;
  234.   *listPtr++=blit_ro(BLTF,PRAMPAT+PATA_PATB+PRAMALF, A_ONLY); 
  235.  
  236.   BLIT_CODE_2
  237.  
  238.   CHKEXEC;
  239. }
  240.  
  241. void clearArea8_3c(uint x1, uint y1, uint x2, uint y2, uint z, uint cindex)
  242. {
  243.   BLIT_VARS
  244.  
  245. #ifdef DEBUG_clgd547x
  246.   printf("clearArea8_3c(%d,%d,%d,%d,%d,%d)\n",x1,y1,x2,y2,z,cindex);
  247. #endif
  248.   
  249.   BLIT_CODE_1 
  250.  
  251.   cindex &= 0x000000ff;
  252.   
  253.   *listPtr++=load_short_ro(BANK_MASK_REG, BLUE_BANK );  
  254.   *listPtr++=load_long_ro(C_AND_A_REG,1);  /* load long */
  255.   *listPtr++=0xffff0000 | cindex << 8 | cindex;                  
  256.   *listPtr++=blit_ro(BLTF,PRAMPAT+PATA_PATB+PRAMALF, A_ONLY); 
  257.  
  258.   BLIT_CODE_2
  259.  
  260.   /* TOTEST:
  261.   
  262.   *listPtr++=load_long_ro(C_AND_A_REG,1);  
  263.   *listPtr++=0xffff0000 | z;                  
  264.   *listPtr++=(blit_ro(BLTZ,PRAMPAT+PATA_PATB+PRAMALF, A_ONLY) & ~0x0f);     
  265.  
  266.   */
  267.  
  268.   CHKEXEC;
  269.   
  270. }
  271.  
  272. void clear8c(uint cindex)
  273. {
  274. #ifdef DEBUG_clgd547x
  275.   printf("clear8(%d)\n",cindex);
  276. #endif
  277.   clearArea8_2c(0,0,clgd547xStateInfo->width,clgd547xStateInfo->height,cindex);
  278. }
  279.  
  280. void clearArea24_2c(uint cx1, uint cy1, uint cx2, uint cy2,
  281.             uint r, uint g, uint b, uint a)
  282. #define RGBA
  283. #include "clrtemp.h"
  284.  
  285. void clearArea24_3c(uint cx1, uint cy1, uint cx2, uint cy2, uint cz,
  286.             uint r, uint g, uint b, uint a)
  287. #define RGBA
  288. #include "clrtemp.h"
  289.  
  290. void clear24(uint r, uint g, uint b)
  291. #define SETUP                 \
  292.     cx1=cy1=0;             \
  293.     cx2=clgd547xStateInfo->width;     \
  294.     cy2=clgd547xStateInfo->height;
  295. #define RGBA
  296. #include "clrtemp.h"
  297.  
  298. void clear24c(uint r, uint g, uint b, uint a)
  299. {
  300.   clearArea24_2c(0,0,clgd547xStateInfo->width,clgd547xStateInfo->height,
  301.            r,g,b,a);
  302. }
  303.  
  304. /*************** LINE FUNCTIONS *******************/  
  305. void line8_2fc(uint x1, uint y1, uint x2, uint y2, uint cindex)
  306. #define FLAT_INDEX
  307. #define OPCODE make_ro(VECTFZG2P,IOUTPAT+PATA_OFFB+PRAMALF,ZFLAT,A_ONLY)
  308. #include "linetemp.h"
  309.  
  310. void line8_2s(uint x1, uint y1, uint i1, uint x2, uint y2, uint i2)
  311. #define INTERP_INDEX
  312. #define OPCODE make_ro(VECTFZG2P,IOUTPAT+PATA_OFFB+PRAMALF,ZFLAT,A_ONLY)
  313. #include "linetemp.h"
  314.  
  315. void line8_3fc(uint x1, uint y1, uint z1, uint x2, uint y2, uint z2, uint cindex)
  316. #define THREED
  317. #define FLAT_INDEX
  318. #define OPCODE make_ro(VECTFZG2P,IOUTPAT+PATA_OFFB+PRAMALF,ZNORMAL,A_ONLY)
  319. #include "linetemp.h"
  320.  
  321. void line8_3s(uint x1, uint y1, uint z1, uint i1, uint x2, uint y2, uint z2, uint i2)
  322. #define THREED
  323. #define INTERP_INDEX
  324. #define OPCODE make_ro(VECTFZG2P,IOUTPAT+PATA_OFFB+PRAMALF,ZNORMAL,A_ONLY)
  325. #include "linetemp.h"
  326.  
  327. void line24_2fc(uint x1, uint y1, uint x2, uint y2, uint r, uint g, uint b, uint a)
  328. #define FLAT_COLOR
  329. #define OPCODE make_ro(VECTFZG2P,IOUTPAT+PATA_OFFB+PRAMALF,ZNORMAL,A_ONLY)
  330. #include "linetemp.h"
  331.  
  332. void line24_2s(uint x1, uint y1, uint r1, uint g1, uint b1, uint a1, 
  333.                uint x2, uint y2, uint r2, uint g2, uint b2, uint a2)
  334. #define INTERP_COLOR
  335. #define OPCODE make_ro(VECTFZG2P,IOUTPAT+PATA_OFFB+PRAMALF,ZNORMAL,A_ONLY)
  336. #include "linetemp.h"
  337.  
  338. void line24_3fc(uint x1, uint y1, uint z1, uint x2, uint y2, uint z2, 
  339.                uint r, uint g, uint b, uint a)
  340. #define THREED
  341. #define FLAT_COLOR
  342. #define OPCODE make_ro(VECTFZG2P,IOUTPAT+PATA_OFFB+PRAMALF,ZNORMAL,A_ONLY)
  343. #include "linetemp.h"
  344.  
  345. void line24_3s(uint x1, uint y1, uint z1, uint r1, uint g1, uint b1, uint a1, 
  346.                uint x2, uint y2, uint z2, uint r2, uint g2, uint b2, uint a2)
  347. #define THREED
  348. #define INTERP_COLOR
  349. #define OPCODE make_ro(VECTFZG2P,IOUTPAT+PATA_OFFB+PRAMALF,ZNORMAL,A_ONLY)
  350. #include "linetemp.h"
  351.  
  352. /************** TRIANGLE FUNCTIONS *********************/
  353. #ifndef COMPILE_MESA_STUBS
  354.  
  355. void triangle8_3fc(uint x1, uint y1, uint z1,
  356.                    uint x2, uint y2, uint z2,
  357.                    uint x3, uint y3, uint z3,
  358.                    uint cindex)
  359. #define NOVB
  360. #define FLAT_INDEX
  361. #define OPCODE make_ro(POLYFZG2P, PATA_PATB+IOUTPAT+PRAMALF,ZNORMAL,A_ONLY)
  362. #include "tritemp.h"
  363.  
  364. void triangle8_3s(uint x1, uint y1, uint z1, uint i1,
  365.                   uint x2, uint y2, uint z2, uint i2,
  366.                   uint x3, uint y3, uint z3, uint i3)
  367. #define NOVB
  368. #define INTERP_INDEX
  369. #define OPCODE make_ro(POLYFZG2P,PATA_PATB+IOUTPAT+PRAMALF,ZNORMAL,A_ONLY)
  370. #include "tritemp.h"
  371.  
  372.  
  373. void triangle24_3fc(uint x1, uint y1, uint z1,
  374.                     uint x2, uint y2, uint z2,
  375.                     uint x3, uint y3, uint z3,
  376.                     uint r, uint g, uint b, uint a)
  377. #define NOVB
  378. #define OPCODE make_ro(POLYFZG2P,IOUTPAT+PATA_PATB+PRAMALF,ZMASK,A_ONLY)
  379. #define OPCODE2 make_ro(POLYFZG2P,IOUTPAT+PATA_PATB+PRAMALF,ZNORMAL,A_ONLY)
  380. #define FLAT_COLOR
  381. #include "tritemp.h"
  382.  
  383. void triangle24_3s(uint x1, uint y1, uint z1, uint r1, uint g1, uint b1, uint a1,
  384.                    uint x2, uint y2, uint z2, uint r2, uint g2, uint b2, uint a2,
  385.                    uint x3, uint y3, uint z3, uint r3, uint g3, uint b3, uint a3)
  386. #define NOVB
  387. #define OPCODE make_ro(POLYFZG2P,IOUTPAT+PATA_PATB+PRAMALF,ZMASK,A_ONLY)
  388. #define OPCODE2 make_ro(POLYFZG2P,IOUTPAT+PATA_PATB+PRAMALF,ZNORMAL,A_ONLY)
  389. #define INTERP_COLOR
  390. #include "tritemp.h"
  391.  
  392. #endif
  393.  
  394. #ifdef COMPILE_MESA_STUBS
  395.  
  396. /* function called by MESA */
  397.  
  398. void triangle8_3fcv(uint v0, uint v1, uint v2, uint pv)
  399. #define FLAT_INDEX
  400. #define OPCODE make_ro(POLYFZG2P, PATA_PATB+IOUTPAT+PRAMALF,ZNORMAL,A_ONLY)
  401. #include "tritemp.h"
  402.  
  403. void triangle8_3sv(uint v0, uint v1, uint v2)
  404. #define INTERP_INDEX
  405. #define OPCODE make_ro(POLYFZG2P,PATA_PATB+IOUTPAT+PRAMALF,ZNORMAL,A_ONLY)
  406. #include "tritemp.h"
  407.  
  408. void triangle24_3fcv(uint v0, uint v1, uint v2, uint pv)
  409. #define OPCODE make_ro(POLYFZG2P,IOUTPAT+PATA_PATB+PRAMALF,ZMASK,A_ONLY)
  410. #define OPCODE2 make_ro(POLYFZG2P,IOUTPAT+PATA_PATB+PRAMALF,ZNORMAL,A_ONLY)
  411. #define FLAT_COLOR
  412. #include "tritemp.h"
  413.  
  414. void triangle24_3sv(uint v0, uint v1, uint v2)
  415. #define OPCODE make_ro(POLYFZG2P,IOUTPAT+PATA_PATB+PRAMALF,ZMASK,A_ONLY)
  416. #define OPCODE2 make_ro(POLYFZG2P,IOUTPAT+PATA_PATB+PRAMALF,ZNORMAL,A_ONLY)
  417. #define INTERP_COLOR
  418. #include "tritemp.h"
  419.  
  420. #endif
  421.