home *** CD-ROM | disk | FTP | other *** search
/ The CDPD Public Domain Collection for CDTV 3 / CDPDIII.bin / pd / commodities / superdark / blankers / spot.dark.c < prev    next >
C/C++ Source or Header  |  1993-03-19  |  10KB  |  466 lines

  1.  
  2. /* Fichier line.dark.c                */
  3. /* Module appele par le programme principal    */
  4. /* pour effectuer un effet defini..appele par    */
  5. /* loadseg                    */
  6.  
  7. #include <exec/types.h>
  8. #include <intuition/intuition.h>
  9. #include <intuition/intuitionbase.h>
  10. #include <graphics/gfx.h>
  11. #include <graphics/gfxmacros.h>
  12. #include <graphics/rastport.h>
  13. #include <graphics/displayinfo.h>
  14. #include <graphics/gfxbase.h>
  15. #include <libraries/gadtools.h>
  16. #include <hardware/custom.h>
  17. #include <hardware/blit.h>
  18. #include <clib/exec_protos.h>
  19. #include <clib/intuition_protos.h>
  20. #include <clib/graphics_protos.h>
  21. #include "/includes/struct.h"
  22. #include "/includes/tom_gadget.h"
  23.  
  24. #ifndef custom
  25. #define custom (*(struct Custom *)0xDFF000)
  26. #endif    /* custom */
  27.  
  28. extern    struct    IntuitionBase    *IntuitionBase;
  29. extern    struct    GfxBase        *GfxBase;
  30. extern    struct my_data    *p_info;
  31. extern    struct    appel_proc    *p_data_proc;
  32. struct    RastPort    *rp,*rps;
  33. struct    RastPort    ras2;
  34. struct    BitMap        bitmap;
  35. struct    Screen    *s;
  36. UWORD    width,height;
  37. UWORD    bpr;
  38.  
  39. #define    WIDTH    320
  40. #define    HEIGHT    320
  41.  
  42. #define    TRUE    1
  43. #define    FALSE    0
  44.  
  45. int    max_depth=0;
  46. int    flg_deux=FALSE;
  47. int    flg_un=FALSE;
  48.  
  49. WORD    areabuffer[25];
  50. struct    AreaInfo    myarea;
  51. struct    TmpRas    tmpras;
  52. char    *p_text_info="   Spot\n\nThis effect show you Spots on your screen\n\n  Lightning the background...\n\nYou can select the number of spots,\nher size and speed.\nIf SuperDark can open a screen of a\ndeeper size than the actual one,\nto be continued\n   by Thomas LANDSPURG \n";
  53.  
  54. int    bx,by;
  55. int    flg_dblbuff;
  56.     
  57. #define    MAX_NB    10
  58.  
  59. #define    GID_TAILLE    0
  60. #define    GID_SPEED    1
  61. #define    GID_NOMBRE    2
  62. #define    GID_DBLBUFF    3
  63. #define    GID_SHADOW    4
  64.  
  65. struct tom_gadget my_gadg[]={
  66.     {"Si_ze",    SLIDER,60,20,100,10,40,20,100,0,0},
  67.     {"_Speed",    SLIDER,60,35,100,10,2,1,10,0,0},
  68.     {"_Number",    SLIDER,60,50,100,10,1,1,5,0,0},
  69.     {"_DoubleBuffer",CHECKBOX,370,20,10,10,FALSE,0,0,0,0},
  70.     {"S_hadow",    SLIDER,255,50,100,10,50,0,90,0,0},
  71.     {0,        END_LISTE,  0,  0,   0, 0, 0,0,0,0,0}
  72. };
  73.  
  74. int    tx=20;
  75. int    ty=20;
  76. UWORD    flg_clear;
  77. int    val;
  78.  
  79. long    s2depth;
  80. struct ViewPort      *vp2;
  81. struct    Screen    *s2;
  82. int    num=0;
  83.  
  84. struct NewScreen newscreen = {
  85.   0,0,0,0,0,0,0,NULL,CUSTOMSCREEN,NULL,(UBYTE *)" ",NULL,NULL
  86. };
  87.  
  88. struct    RasInfo    ri;
  89. struct    BitMap    b1,b2,*b;
  90. struct ViewPort vp;
  91. struct    View    v,*oldview;
  92. struct RastPort rp1,rp2,*rp;
  93.  
  94. void    my_text(rp,x,y,p_c)
  95. struct    RastPort    *rp;
  96. int    x,y;
  97. char    *p_c;
  98. {
  99.     if(rp!=0){
  100.         Move(rp,x,y);
  101.         Text(rp,p_c,strlen(p_c));
  102.     }
  103. }
  104. /*************************************************************************/
  105.  
  106. ULONG __regargs
  107. Rand(ULONG MaxValue)
  108. {
  109.     STATIC ULONG RandomSeed = 0xDEAD0123;
  110.  
  111.     RandomSeed = RandomSeed * custom . vhposr + 0xE153766F;
  112.  
  113.     return(RandomSeed % MaxValue);
  114. }
  115.  
  116. /*************************************************************************/
  117.  
  118. void    blit_func()
  119. {
  120.  
  121.     UWORD    sx,sy,decal,mod;
  122.     ULONG    mask;
  123.     ULONG    offset,code_ret;
  124.     static    WORD    num_plan=0;
  125.     APTR    p_dest;
  126.     UWORD    bltcon0;
  127.  
  128.   for(num_plan=0;(num_plan<s2depth)||((flg_un==TRUE)&&(num_plan==0));num_plan++){
  129.     WaitBlit();
  130.     code_ret=0;
  131.     sx=(tx+16)&0xfff0;
  132.     sy=ty;
  133.     custom.bltapt=bitmap.Planes[0];    /* Masque */
  134.     offset=(by*bpr+bx/8)&0xFFFE;
  135.     decal=(bx)&0xF;        /* DEcalage sur 16 */
  136.     decal=decal<<12;
  137.     custom.bltadat=0;
  138.     if(flg_un==TRUE){
  139.         p_dest = b->Planes[max_depth-1]+offset;
  140.         if(flg_clear){
  141.             bltcon0=(DEST)|(decal)|(A_TO_D);
  142.         }else{
  143.             bltcon0=(DEST|SRCC|SRCA)|(decal)|(A_OR_C);
  144.         }
  145.     }else{
  146.         custom.bltbpt=rps->BitMap->Planes[num_plan]+offset;
  147.         p_dest = rp->BitMap->Planes[num_plan]+offset;
  148.         if(flg_clear){
  149.             bltcon0=(DEST)|(decal)|(A_TO_D);
  150.         }else{
  151.             bltcon0=(DEST|SRCC|SRCB|SRCA)|(decal)|(ABC|ABNC|NABC|NANBC);
  152.         }
  153.     }
  154.     
  155.     custom.bltcpt= p_dest;
  156.     custom.bltdpt= p_dest;
  157.     custom.bltcon0=bltcon0;
  158.     mod=(bpr/2-sx/16)*2-2;
  159.     custom.bltamod=(WIDTH/16-sx/16)*2-2;
  160.     custom.bltbmod=mod;
  161.     custom.bltcmod=mod;
  162.     custom.bltdmod=mod;
  163.     custom.bltcon1=0;
  164.     decal=(~bx)&0xF;
  165.     decal=decal<<12;
  166.     mask=0xFFFF0000>>decal;
  167.     custom.bltafwm=mask;
  168.     custom.bltalwm=mask>>0xF;
  169.     custom.bltafwm=0xffff;
  170.     custom.bltalwm=0;
  171.  
  172.     custom.bltsize=(sy<<HSIZEBITS)|(sx/16+1);
  173.    }
  174. }
  175.  
  176. /***************************************************************************/
  177.  
  178. /* Effectue un fading */
  179.  
  180. UWORD    fade_one_digit(UWORD    n,USHORT    val)
  181. {
  182.     return((n*val/100)&0x00f);
  183. }
  184.  
  185. /*************************************************************************/
  186.  
  187. void    spot()
  188. {
  189.     WORD    x[MAX_NB],y[MAX_NB];
  190.     WORD    sx[MAX_NB],sy[MAX_NB];
  191.     WORD    oldx[MAX_NB],oldy[MAX_NB];
  192.     
  193.     UWORD    mx,my,i,nb;
  194.  
  195.  
  196.     if(tx>width*2){
  197.         tx=width/2;
  198.     }
  199.     if(ty>height*2){
  200.         ty=height/2;
  201.     }
  202.     mx=my_gadg[GID_SPEED].value;
  203.     if(mx==0)mx=4;
  204.     my=my_gadg[GID_SPEED].value*height/width;
  205.     if(my==0)my=4;
  206.  
  207.     nb=((my_gadg[GID_NOMBRE].value-1)%MAX_NB)+1;
  208.     if(nb>MAX_NB)nb=MAX_NB;
  209.     if(nb<1)nb=1;
  210.  
  211.     for(i=0;i<nb;i++){
  212.         oldx[i]=0;
  213.         oldy[i]=0;
  214.         x[i]=Rand(width-2*tx);
  215.         y[i]=Rand(height-2*ty);
  216.  
  217.         sx[i]=Rand(mx*2)-mx;
  218.         if(sx[i]==0)sx[i]++;
  219.         sy[i]=Rand(my*2)-my;
  220.         if(sy[i]==0)sy[i]++;
  221.     }
  222.     while(tst_end()==FALSE){
  223.  
  224.         if(flg_un==TRUE){
  225.             ri.BitMap=b;
  226.             MakeVPort(&v,&vp);
  227.             MrgCop(&v);
  228.             LoadView(&v);
  229.             if(num==2){
  230.                 b=&b1;
  231.                 num=0;
  232.             }else{
  233.                 b=&b2;
  234.             }
  235.             num++;
  236.         }
  237.  
  238.         WaitTOF();
  239.         flg_clear=TRUE;
  240.         OwnBlitter();
  241.         for(i=0;i<nb;i++){
  242.             if(flg_dblbuff){
  243.                 bx=oldx[i];
  244.                 by=oldy[i];
  245.                 oldx[i]=x[i];
  246.                 oldy[i]=y[i];
  247.             }else{
  248.                 bx=x[i];
  249.                 by=y[i];
  250.             }
  251.             blit_func();
  252.         }
  253.         flg_clear=FALSE;
  254.         for(i=0;i<nb;i++){
  255.  
  256.             x[i]+=sx[i];
  257.             if(x[i]<=0){
  258.                 x[i]=0;
  259.                 sx[i]=Rand(mx)+1;
  260.             }else if(x[i]>=width-tx-16){
  261.                 x[i]=width-tx-16;
  262.                 sx[i]=-Rand(mx)-1;
  263.             }
  264.             y[i]+=sy[i];
  265.             if(y[i]<=0){
  266.                 y[i]=0;
  267.                 sy[i]=Rand(my)+1;
  268.             }else if(y[i]>=height-ty-1){
  269.                 y[i]=height-ty-1;
  270.                 sy[i]=-Rand(my)-1;
  271.             }
  272.  
  273.             bx=x[i];
  274.             by=y[i];
  275.             blit_func();
  276.         }
  277.         DisownBlitter();
  278.     }
  279.  
  280. }
  281.  
  282. /*************************************************************************/
  283.  
  284. UWORD    plane_avail(ULONG d_id)
  285. {
  286.  UWORD    depth;
  287.  struct ModeNode *ModeNode;
  288.  ModeNode=(struct ModeNode *)p_data_proc->ml->lh_Head;
  289.  
  290.  depth=0;
  291.  while (ModeNode->mn_Node.ln_Succ){
  292.     if(((ModeNode->DisplayID)&0x8FFF)==(d_id&0x8FFF)){
  293.         depth=ModeNode->MaxDepth;
  294.     }
  295.     ModeNode=(struct ModeNode *)ModeNode->mn_Node.ln_Succ;
  296.  }
  297.  return depth;
  298. }
  299. /*************************************************************************/
  300.  
  301. void    dark()
  302. {
  303.     int    i,col;
  304.     LONG    mode_id;
  305.  
  306.     s = NULL;
  307.     s2 = IntuitionBase->FirstScreen;
  308.  
  309.     vp2 = &s2->ViewPort;
  310.     s2depth = s2->BitMap.Depth;
  311.     flg_un=FALSE;
  312.     newscreen.LeftEdge = s2->LeftEdge;
  313.     newscreen.TopEdge = s2->TopEdge;
  314.     newscreen.Width = s2->Width;
  315.     newscreen.Height = s2->Height;
  316.     newscreen.DetailPen = s2->DetailPen;
  317.     newscreen.BlockPen = s2->BlockPen;
  318.     newscreen.Depth = s2depth;
  319.     newscreen.ViewModes = vp2->Modes;
  320.  
  321.     width=newscreen.Width;
  322.     height=newscreen.Height;
  323.     rps=&s2->RastPort;
  324.  
  325.     if(GfxBase->LibNode.lib_Version>=36){
  326.         mode_id=GetVPModeID(vp2);
  327.     }else{
  328.         mode_id=vp2->Modes;
  329.     }
  330.  
  331.     flg_dblbuff=FALSE;
  332.     max_depth=plane_avail(mode_id);
  333.     if(max_depth <= s2depth){
  334.         if ((s = (struct Screen *)OpenScreen(&newscreen)) == NULL){
  335.             return;
  336.         }
  337.         rp = &s->RastPort;
  338.         bpr=rp->BitMap->BytesPerRow;
  339.         SetRast(rp,0);
  340.       }else{
  341.         num=0;
  342.         if(my_gadg[GID_DBLBUFF].value==TRUE){
  343.             flg_dblbuff=TRUE;
  344.         }
  345.         val=my_gadg[GID_SHADOW].value;
  346.         if((val<0)||(val>90)){
  347.             val=50;
  348.         }
  349.  
  350. /*BUG: sous 2.0, vp.Modes ne se fait pas comme ca! */
  351.         oldview=((struct GfxBase *)GfxBase)->ActiView;
  352.             max_depth=s2depth+1;
  353.         InitView(&v);
  354.         v.ViewPort=&vp;
  355.         InitVPort(&vp);
  356.         vp.Modes=((vp2->Modes)&0x7000+0x1000)|((vp2->Modes)&0x8FFF);
  357.  
  358.         vp.DWidth=width;
  359.         vp.DHeight=height;
  360.         vp.RasInfo=&ri;
  361.         vp.ColorMap=(struct    ColorMap *)GetColorMap(1<<max_depth);
  362.         InitBitMap(&b1,max_depth,width,height);
  363.         bpr=b1.BytesPerRow;
  364.         for(i=0;i<s2depth;i++){
  365.             b1.Planes[i]=s2->BitMap.Planes[i];
  366.         }
  367.         b1.Planes[max_depth-1]=(PLANEPTR)AllocRaster(width,height);
  368.         b2=b1;
  369.         if(flg_dblbuff){
  370.             b2.Planes[max_depth-1]=(PLANEPTR)AllocRaster(width,height);
  371.             if(b2.Planes[max_depth-1]==0){
  372.                 flg_dblbuff=FALSE;
  373.             }
  374.         }
  375.         BltClear(b1.Planes[max_depth-1],height*bpr,0);
  376.         BltClear(b2.Planes[max_depth-1],height*bpr,0);
  377.         InitRastPort(&rp1);
  378.         b=&b1;
  379.         rp1.BitMap=&b1;
  380.         ri.BitMap=&b1;
  381.         ri.RxOffset=0;
  382.         ri.RyOffset=0;
  383.         ri.Next=NULL;
  384.  
  385.         rp =&rp1;
  386.         flg_un=TRUE;
  387.       }
  388.     FreeSprite (0);
  389.     GfxBase->SpriteReserved|=1;
  390.  
  391.     for(i=0;i<(1<<s2depth);i++){
  392.      UWORD    r,g,b;
  393.      col=GetRGB4(s2->ViewPort.ColorMap,i);
  394.      r=(col&0xf00)>>8;
  395.      g=(col&0x0f0)>>4;
  396.      b=(col&0x00f);
  397.      if(flg_un==TRUE){
  398.         SetRGB4(    &vp,i,
  399.                 fade_one_digit(r,val),
  400.                 fade_one_digit(g,val),
  401.                 fade_one_digit(b,val));
  402.         SetRGB4(&vp,i+(1<<s2depth),r,g,b);
  403.      }else{
  404.         SetRGB4(&(s->ViewPort),i,r,g,b);
  405.      }
  406.     }
  407.  
  408.     InitBitMap(&bitmap,1,WIDTH,HEIGHT);
  409.     bitmap.Planes[0]=AllocRaster(WIDTH,HEIGHT);
  410.     if(bitmap.Planes[0]){
  411.         InitRastPort(&ras2);
  412.         ras2.BitMap=&bitmap;
  413.  
  414.         InitArea(&myarea,areabuffer,10);
  415.         ras2.AreaInfo=&myarea;
  416.         ras2.TmpRas=(struct TmpRas *)InitTmpRas(&tmpras,AllocRaster(WIDTH,HEIGHT),RASSIZE(WIDTH,HEIGHT));
  417.         if(ras2.TmpRas){
  418.             tx=2*my_gadg[GID_TAILLE].value;
  419.             if((tx==0)||(tx>width/2))tx=20;
  420.         
  421.             ty=tx*height/width;
  422.             if((ty==0)||(ty>height/2))ty=20;
  423.             
  424.             SetRast(&ras2,0);
  425.             SetAPen(&ras2,1L);
  426.             {
  427.                 LONG    tx2,ty2;
  428.                 tx2=tx>>1;
  429.                 ty2=ty>>1;
  430.                 AreaMove(&ras2,tx2,ty2);
  431.                 AreaEllipse(&ras2,tx2,ty2,tx2-1,ty2-1);
  432.                 AreaEnd(&ras2);
  433.             }
  434.             WaitBlit();
  435.             FreeRaster(tmpras.RasPtr,WIDTH,HEIGHT);
  436.         }
  437.     }
  438.     spot();
  439.  
  440.     wait_end();
  441.     if(bitmap.Planes[0])FreeRaster(bitmap.Planes[0],WIDTH,HEIGHT);
  442.     if(flg_un==TRUE){
  443.         FreeRaster(b1.Planes[max_depth-1],width,height);
  444.         if(flg_dblbuff){
  445.             FreeRaster(b2.Planes[max_depth-1],width,height);
  446.         }
  447.         LoadView(oldview);
  448.         FreeColorMap(vp.ColorMap);
  449.         FreeVPortCopLists(&vp);
  450.         FreeCprList(v.LOFCprList);
  451.     }else{
  452.         CloseScreen(s);
  453.     }
  454. }
  455.  
  456. void    proc_init()
  457. {
  458. }
  459. void    proc_save()
  460. {
  461. }
  462. void    proc_end()
  463. {
  464. }
  465.  
  466.