home *** CD-ROM | disk | FTP | other *** search
/ Amiga Elysian Archive / AmigaElysianArchive.iso / screen / sdark15c.lha / programmer.lha / prog / proc_main_debug.c < prev    next >
C/C++ Source or Header  |  1993-03-27  |  11KB  |  441 lines

  1. #include    <stdio.h>
  2. #include    <exec/types.h>
  3. #include    <exec/tasks.h>
  4. #include    <exec/ports.h>
  5. #include    <exec/memory.h>
  6. #include    <exec/tasks.h>
  7. #include    <graphics/displayinfo.h>
  8. #include    <graphics/displayinfo.h>
  9. #include    <graphics/gfxmacros.h>
  10. #include    <dos/dosextens.h>
  11. #include    <clib/exec_protos.h>
  12. #include    <hardware/custom.h>
  13. #include    <hardware/dmabits.h>
  14. #include    <intuition/intuitionbase.h>
  15. #include    <intuition/screens.h>
  16. #include    "/includes/struct.h"
  17. #include    "/includes/tom_gadget.h"
  18.  
  19. #ifndef custom
  20. #define custom (*(struct Custom *)0xDFF000)
  21. #endif    /* custom */
  22. #define DEF_MODE      0
  23. #define DEF_MODE_NAME "HighRes"
  24.  
  25.  
  26. static    int    s2depth,width,height;
  27.  
  28. struct my_data    *p_info;
  29. struct    appel_proc    *p_data_proc;
  30. struct    appel_proc    data_proc;
  31. struct    BitMap        b;
  32. static    struct    Screen        *s;
  33. static    struct    Window    *wnd;
  34. static    int    flg_end=FALSE;
  35.  
  36. struct    IntuitionBase    *IntuitionBase;
  37. struct    Library    *GfxBase;
  38. extern    struct    tom_gadget    my_gadg[];
  39. extern    void    __saveds    dark();
  40. extern    void    proc_init();
  41. extern    void    proc_end();
  42. extern    char    *p_text_info;
  43. struct ExtNewScreen newscreen = {
  44.   0,0,0,0,0,0,0,NULL,CUSTOMSCREEN|CUSTOMBITMAP,NULL,(UBYTE *)" ",NULL,NULL
  45. };
  46.  
  47. char    pr_buff[100];
  48.  
  49. /* Note: The folloing SPrintF Routine is taken from the program "FracBlank " */
  50. /* by:                                         */
  51. UWORD PutChar[2] = {0x16C0,0x4E75};
  52.  
  53. /* dirty hack to avoid assembler part :-)
  54.    16C0: move.b d0,(a3)+
  55.    4E75: rts
  56. */
  57.  
  58. #define VOID_STDARGS   void __stdargs
  59.  
  60. VOID_STDARGS SPrintF(char *pr_buff,char *FormatString,...)
  61.  
  62. {
  63.  RawDoFmt (FormatString,(APTR)((LONG *)&FormatString+1L),
  64.            (void *)PutChar,pr_buff);
  65. }
  66. mystrlen(char    *pc)
  67. {
  68.     int    ret;
  69.     ret=0;
  70.     while(*pc++!=0){
  71.         ret++;
  72.     }
  73.     return    ret;
  74. }
  75.  
  76. void    MyWrite(char    *pc)
  77. {
  78.     printf(pc);
  79. }
  80. void    My_Print(struct RastPort *rp,UWORD x,UWORD y,char    *pc)
  81. {
  82.     Move(rp,x,y);
  83.     Text(rp,pc,mystrlen(pc));
  84. }
  85.  
  86. #ifdef    DEBUG
  87. VOID_STDARGS printt(char *FormatString,...)
  88.  
  89. {
  90.     char    buffer[100];
  91.      RawDoFmt (FormatString,(APTR)((LONG *)&FormatString+1L),
  92.            (void *)PutChar,buffer);
  93.     MyWrite(buffer);
  94. }
  95. #endif
  96.  
  97. /* Checrche une resolution correspondant aux mieu a nos demandes */
  98. /* si flg_depth=TRUE, alors on cherche la prof max corresp a la     */
  99. /* resolution demandee                         */
  100.  
  101. int    find_res(USHORT flg_depth,SHORT *p_depth,SHORT *p_tx,SHORT *p_ty,ULONG *p_d_id)
  102. {
  103.  struct ModeNode *ModeNode;
  104.  struct ModeNode *ModeNodeFound;
  105.  
  106.  ModeNode=(struct ModeNode *)p_data_proc->ml->lh_Head;
  107.  ModeNodeFound=ModeNode;
  108.  
  109.  while (ModeNode->mn_Node.ln_Succ)
  110.   {
  111.     if(flg_depth){
  112.         if(*p_depth<ModeNode->MaxDepth){
  113.             *p_depth=ModeNode->MaxDepth;
  114.             if(*p_tx<=ModeNode->MaxX){
  115.                 *p_tx=ModeNode->MaxX;
  116.                 if(*p_ty<=ModeNode->MaxY){
  117.                     *p_ty=ModeNode->MaxY;
  118.                 }
  119.             }
  120.             ModeNodeFound=ModeNode;
  121.         }
  122.     }else{
  123.         if(*p_tx<=ModeNode->MaxX){
  124.             *p_tx=ModeNode->MaxX;
  125.             if(*p_ty<=ModeNode->MaxY){
  126.                 *p_ty=ModeNode->MaxY;
  127.                 if(*p_depth<ModeNode->MaxDepth){
  128.                     *p_depth=ModeNode->MaxDepth;
  129.                 }
  130.             }
  131.             ModeNodeFound=ModeNode;
  132.         }
  133.     }
  134.     ModeNode=(struct ModeNode *)ModeNode->mn_Node.ln_Succ;
  135.   }
  136.   *p_depth=ModeNodeFound->MaxDepth;
  137.  
  138.   *p_tx=ModeNodeFound->MaxX;
  139.   *p_ty=ModeNodeFound->MaxY;
  140.  
  141.   *p_d_id=ModeNodeFound->DisplayID;
  142.  
  143.   return TRUE;
  144. }
  145.  
  146. /********************************************************** get_modes() *****/
  147.  
  148. /********************************************************/
  149. /* We get the current modes availables in this computer */
  150. /********************************************************/
  151.  
  152. struct    List    *get_modes()
  153. {
  154.  struct List *ModeList;
  155.  ULONG DisplayID;
  156.  struct DimensionInfo DimInfo;
  157.  struct NameInfo NameInfo;
  158.  struct ModeNode *ModeNode;
  159.  
  160.  if (ModeList=AllocMem(sizeof(struct List),MEMF_PUBLIC)) NewList (ModeList);
  161.  else return NULL;
  162.  
  163.  DisplayID=INVALID_ID;
  164.  while ((DisplayID=NextDisplayInfo(DisplayID))!=INVALID_ID){
  165.   if ((DisplayID&MONITOR_ID_MASK)&&(ModeNotAvailable(DisplayID)==0L)){
  166.    if (GetDisplayInfoData(NULL,(UBYTE *)&DimInfo,sizeof(struct DimensionInfo),
  167.                           DTAG_DIMS,DisplayID)){
  168.     if (DimInfo.MaxDepth>1){
  169.      if (GetDisplayInfoData(NULL,(UBYTE *)&NameInfo,sizeof(struct NameInfo),
  170.                             DTAG_NAME,DisplayID)){
  171.       if (ModeNode=AllocMem(sizeof(struct ModeNode),MEMF_PUBLIC))
  172.        {
  173.  
  174.     ModeNode->MaxDepth=DimInfo.MaxDepth;
  175.     ModeNode->MinX=DimInfo.Nominal.MinX+1;
  176.     ModeNode->MaxX=DimInfo.Nominal.MaxX+1;
  177.     ModeNode->MinY=DimInfo.Nominal.MinY+1;
  178.     ModeNode->MaxY=DimInfo.Nominal.MaxY+1;
  179.  
  180.         (void)strcpy(ModeNode->Name,
  181.                      NameInfo.Name);
  182.     ModeNode->mn_Node.ln_Name=ModeNode->Name;
  183.         ModeNode->DisplayID=DisplayID;
  184.  
  185.     printf("%20s ",NameInfo.Name);
  186.     printf("M.depth:%d mx:%02d my:%02d MX:%03d MY:%03d ",DimInfo.MaxDepth,
  187.                 DimInfo.Nominal.MinX,
  188.                 DimInfo.Nominal.MinY,
  189.                 DimInfo.Nominal.MaxX,
  190.                 DimInfo.Nominal.MaxY);
  191.     printf("Flags:%lx\n",ModeNode->DisplayID);
  192.  
  193.         AddTail (ModeList,&ModeNode->mn_Node);
  194.       }
  195.      }
  196.     }
  197.    }
  198.   }
  199.  }    
  200.  if (ModeList->lh_Head->ln_Succ==NULL)
  201.   if (ModeNode=AllocMem(sizeof(struct ModeNode),MEMF_PUBLIC))
  202.    {
  203.     (void)strcpy(ModeNode->Name,
  204.                      DEF_MODE_NAME);
  205.     ModeNode->mn_Node.ln_Name=ModeNode->Name;
  206.     ModeNode->DisplayID=DEF_MODE;
  207.     ModeNode->MaxX=640;
  208.     ModeNode->MaxY=256;
  209.     ModeNode->MaxDepth=4;
  210.  
  211.     AddTail (ModeList,&ModeNode->mn_Node);
  212.    }
  213.   else
  214.    {
  215.     FreeMem ((APTR)ModeList,sizeof(struct List));
  216.     return NULL;
  217.    }
  218.  return ModeList;
  219. }
  220.  
  221. /************************************************************* free_modes() */
  222.  
  223.  
  224. /***********************************************/
  225. /* We delete the liste of the available modes */
  226. /***********************************************/
  227.  
  228. void free_modes(struct List *ModeList)
  229.  
  230. {
  231.     struct ModeNode *ModeNode;
  232.  
  233.     while (ModeList->lh_Head->ln_Succ){
  234.         ModeNode=(struct ModeNode *)ModeList->lh_Head;
  235.         RemHead (ModeList);
  236.         FreeMem ((APTR)ModeNode,sizeof(struct ModeNode));
  237.     }
  238.     FreeMem ((APTR)ModeList,sizeof(struct List));
  239. }
  240. /*******************************************************************/
  241. /* This function is used instead of CloseScreen, because if we are */
  242. /* in the random mode, we don't close immediatly the screen, but   */
  243. /* we give it back to superdark, so he can use it to create next   */
  244. /* screen                               */
  245. /*******************************************************************/
  246.  
  247. DCloseScreen(struct Screen *s)
  248. {
  249.     if(s)CloseScreen(s);
  250. }
  251. /*******************************************************************/
  252.  
  253. int blank()
  254. {
  255.   int    i,col;
  256.   struct    Screen    *s2;
  257.   struct ViewPort      *vp2;
  258.   static struct TagItem screen_item[2]={{SA_DisplayID,0},TAG_END};
  259.  
  260.   /* We set the sprite off, with 2 different methodes:    */
  261.   /* Software (not always work) and Hardware (tricky..) */
  262.  
  263. /*
  264.   if (my_gadg[GID_SPRITE].value){
  265. */
  266.     OFF_SPRITE
  267.     for (i=0L; i<8L; i++){
  268.          custom.spr[i].ctl=0;
  269.     }
  270. /*
  271.   }else{
  272. */
  273. /*
  274.   }
  275. */
  276.  data_proc.s=0;
  277.  
  278.   s2 = IntuitionBase->FirstScreen;
  279.   vp2 = &s2->ViewPort;
  280.   s2depth = s2->BitMap.Depth;
  281.   
  282.   newscreen.Type|=NS_EXTENDED;
  283.   newscreen.LeftEdge = s2->LeftEdge;
  284.   newscreen.TopEdge = s2->TopEdge;
  285.   newscreen.Width = s2->Width;
  286.   newscreen.Height = s2->Height;
  287.   newscreen.DetailPen = s2->DetailPen;
  288.   newscreen.BlockPen = s2->BlockPen;
  289.   newscreen.Depth = s2depth;
  290.   newscreen.ViewModes = vp2->Modes;
  291.   newscreen.DefaultTitle=NULL;
  292.   newscreen.Extension=screen_item;
  293.  
  294.   width=newscreen.Width;
  295.   height=newscreen.Height;
  296.   
  297.  if(data_proc.type_screen==SCR_GIVEN){
  298.  
  299.   if (s) printf("Error! Screen Exists! Quitting...");
  300.   screen_item[0].ti_Data=GetVPModeID(vp2);
  301.   InitBitMap(&b,s2depth,width,height);
  302.   for(i=0;i<s2depth;i++){
  303.     b.Planes[i]=AllocRaster(width,height);
  304.         if(b.Planes[i]==0){
  305.         printf("Big erreur aVEC alloc raster\n");
  306.         return(1);
  307.     }
  308.   }
  309.   BltBitMap(&(s2->BitMap),0,0,&b,0,0,width,height,0xc0,0xff,NULL);
  310.   newscreen.CustomBitMap=&b;
  311.  
  312.   if ((s = (struct Screen *)OpenScreen(&newscreen)) == NULL)
  313.     printf("[Couldn't Open Screen]",0);
  314.  
  315.   for(i=0;i<(1<<s2depth);i++){
  316.     col=GetRGB4(s2->ViewPort.ColorMap,i);
  317.     SetRGB4(&(s->ViewPort),i,(col&0xf00)>>8,(col&0xf0)>>4,(col&0xf));
  318.   }
  319.  
  320.    data_proc.rp= &(s->RastPort);
  321.    data_proc.rps=&(s2->RastPort);
  322.    data_proc.s=s;
  323.    data_proc.width=width;
  324.    data_proc.height=height;
  325.   }
  326.   
  327. }
  328.  
  329. /**************************************************************************/
  330.  
  331. void    off_blank()
  332. {
  333.    int    i;
  334.    if(data_proc.type_screen==SCR_GIVEN){
  335.  
  336.     if(s!=0)CloseScreen(s);
  337.     for(i=0;i<s2depth;i++){
  338.         if(b.Planes[i]!=0){
  339.             FreeRaster(b.Planes[i],width,height);
  340.         }
  341.     }
  342.   }
  343. /*
  344.   if (my_gadg[GID_SPRITE].value){
  345. */
  346.       ON_SPRITE
  347. /*
  348.   }else{
  349. */
  350. /*
  351.   }
  352. */
  353.   s=0;
  354. }
  355. /**************************************************************************/
  356. open_win()
  357. {
  358.     if ( ! ( wnd = OpenWindowTags( NULL,
  359.                 WA_Left,    100,
  360.                 WA_Top,        100,
  361.                 WA_Width,    200,
  362.                 WA_Height,    100,
  363.                 WA_IDCMP,    IDCMP_CLOSEWINDOW|IDCMP_REFRESHWINDOW,
  364.                 WA_Flags,    WFLG_SIZEGADGET|WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_CLOSEGADGET|WFLG_SMART_REFRESH,
  365.                 WA_Title,    "SuperDark",
  366.                 WA_ScreenTitle,    "SuperDark",
  367.                 TAG_DONE )))
  368.             return (-1);
  369.     return(0L);
  370. }
  371. close_win()
  372. {
  373.     if(wnd)CloseWindow(wnd);
  374. }
  375. /**************************************************************************/
  376.  
  377. main()
  378. {
  379.  
  380.     /****************************************************************/
  381.     /* Recherche du port qui contient les infos relatives a l'ecran */
  382.     /* Ce port permet de passer des donnes de la tache main vers ici*/ 
  383.     /****************************************************************/
  384.  
  385.     IntuitionBase=(struct IntuitionBase *)OpenLibrary("intuition.library",0);
  386.     GfxBase=(struct Library *)OpenLibrary("graphics.library",0);
  387.     
  388.     p_data_proc=&data_proc;
  389.     get_modes();
  390.  
  391.     /*********************************************/
  392.     /* On recupere les informaitons ainsi passee */
  393.     /*********************************************/
  394.     p_info=p_data_proc->p_info;
  395.     p_data_proc->p_gadg=my_gadg;
  396.     p_data_proc->p_texte=p_text_info;
  397.     p_data_proc->type_screen=SCR_OWN;
  398.     proc_init();
  399.  
  400.     /* Si on n'a pas encore notifie le type de verision */
  401.     if(p_data_proc->code_ret==-1){
  402.         p_data_proc->code_ret=DARK_WB_13;
  403.     }
  404.     blank();
  405.  
  406.     MyWrite("Avant le do\n");
  407.     MyWrite(pr_buff);
  408.     /* Attend que le main nous reveille */
  409.  
  410.     if(open_win()==0){
  411.         dark();
  412.     }
  413.     close_win();
  414.     MyWrite("ctrl-C recu, j'averti le main\n");
  415.  
  416.     proc_end();
  417.     off_blank();
  418.     MyWrite("Signal Exit..\n");
  419.     CloseLibrary((struct Library *)IntuitionBase);
  420.     CloseLibrary(GfxBase);
  421.     return 0;
  422. }
  423.  
  424. int    __saveds    tst_end()
  425. {
  426.     struct    message    *msg;
  427.  
  428.     if(flg_end==FALSE){
  429.         if((msg=GetMsg(wnd->UserPort)){
  430.             flg_end=TRUE;
  431.             ReplyMsg(msg);
  432.         }
  433.     }
  434.     return (flg_end);
  435. }
  436.  
  437. void    __saveds    wait_end()
  438. {
  439.     if(flg_end==FALSE)WaitPort(wnd->UserPort);
  440. }
  441.