home *** CD-ROM | disk | FTP | other *** search
/ Amiga Elysian Archive / AmigaElysianArchive.iso / commod / sdark14b.lha / programmer.lha / prog / proc_main.c < prev    next >
C/C++ Source or Header  |  1993-03-21  |  5KB  |  222 lines

  1.  
  2. /*********************************************************/
  3. /* Proc_main.c This file have to be linked with the main */
  4. /* part of a blanker. It contain various and important   */
  5. /* intialisation for blankers...             */
  6. /*********************************************************/
  7.  
  8. #include    <stdio.h>
  9. #include    <exec/types.h>
  10. #include    <exec/tasks.h>
  11. #include    <exec/ports.h>
  12. #include    <graphics/displayinfo.h>
  13. #include    <exec/tasks.h>
  14. #include    <dos/dosextens.h>
  15. #include    <clib/exec_protos.h>
  16. #include    "/includes/struct.h"
  17. #include    "/includes/tom_gadget.h"
  18.  
  19. struct my_data    *p_info;
  20. struct    appel_proc    *p_data_proc;
  21.  
  22. struct    Library    *IntuitionBase;
  23. struct    Library    *GfxBase;
  24. extern    struct    tom_gadget    my_gadg[];
  25. extern    void    __saveds    dark();
  26. extern    void    proc_init();
  27. extern    void    proc_end();
  28. extern    char    *p_text_info;
  29.  
  30. BPTR    hd=0;
  31. char    pr_buff[100];
  32.  
  33. /* Note: The folloing SPrintF Routine is taken from the program "FracBlank " */
  34. /* by:                                         */
  35. UWORD PutChar[2] = {0x16C0,0x4E75};
  36.  
  37. /* dirty hack to avoid assembler part :-)
  38.    16C0: move.b d0,(a3)+
  39.    4E75: rts
  40. */
  41.  
  42. #define VOID_STDARGS   void __stdargs
  43.  
  44. VOID_STDARGS SPrintF(char *pr_buff,char *FormatString,...)
  45.  
  46. {
  47.  RawDoFmt (FormatString,(APTR)((LONG *)&FormatString+1L),
  48.            (void *)PutChar,pr_buff);
  49. }
  50. mystrlen(char    *pc)
  51. {
  52.     int    ret;
  53.     ret=0;
  54.     while(*pc++!=0){
  55.         ret++;
  56.     }
  57.     return    ret;
  58. }
  59.  
  60. void    MyWrite(char    *pc)
  61. {
  62.     if(hd!=0)Write(hd,pc,mystrlen(pc));
  63. }
  64. void    My_Print(struct RastPort *rp,UWORD x,UWORD y,char    *pc)
  65. {
  66.     Move(rp,x,y);
  67.     Text(rp,pc,mystrlen(pc));
  68. }
  69.  
  70. #ifdef    DEBUG
  71. VOID_STDARGS printt(char *FormatString,...)
  72.  
  73. {
  74.     char    buffer[100];
  75.      RawDoFmt (FormatString,(APTR)((LONG *)&FormatString+1L),
  76.            (void *)PutChar,buffer);
  77.     MyWrite(buffer);
  78. }
  79. #endif
  80.  
  81. /* Checrche une resolution correspondant aux mieu a nos demandes */
  82. /* si flg_depth=TRUE, alors on cherche la prof max corresp a la     */
  83. /* resolution demandee                         */
  84.  
  85. int    find_res(USHORT flg_depth,SHORT *p_depth,SHORT *p_tx,SHORT *p_ty,ULONG *p_d_id)
  86. {
  87.  struct ModeNode *ModeNode;
  88.  struct ModeNode *ModeNodeFound;
  89.  
  90.  ModeNode=(struct ModeNode *)p_data_proc->ml->lh_Head;
  91.  ModeNodeFound=ModeNode;
  92.  
  93.  while (ModeNode->mn_Node.ln_Succ)
  94.   {
  95.     if(flg_depth){
  96.         if(*p_depth<ModeNode->MaxDepth){
  97.             *p_depth=ModeNode->MaxDepth;
  98.             if(*p_tx<=ModeNode->MaxX){
  99.                 *p_tx=ModeNode->MaxX;
  100.                 if(*p_ty<=ModeNode->MaxY){
  101.                     *p_ty=ModeNode->MaxY;
  102.                 }
  103.             }
  104.             ModeNodeFound=ModeNode;
  105.         }
  106.     }else{
  107.         if(*p_tx<=ModeNode->MaxX){
  108.             *p_tx=ModeNode->MaxX;
  109.             if(*p_ty<=ModeNode->MaxY){
  110.                 *p_ty=ModeNode->MaxY;
  111.                 if(*p_depth<ModeNode->MaxDepth){
  112.                     *p_depth=ModeNode->MaxDepth;
  113.                 }
  114.             }
  115.             ModeNodeFound=ModeNode;
  116.         }
  117.     }
  118.     ModeNode=(struct ModeNode *)ModeNode->mn_Node.ln_Succ;
  119.   }
  120.   *p_depth=ModeNodeFound->MaxDepth;
  121.  
  122.   *p_tx=ModeNodeFound->MaxX;
  123.   *p_ty=ModeNodeFound->MaxY;
  124.  
  125.   *p_d_id=ModeNodeFound->DisplayID;
  126.  
  127.   return TRUE;
  128. }
  129.  
  130. _main(line)
  131. register    char    *line;
  132. {
  133.     struct    Task    *my_t;
  134.     struct    MsgPort    *mp;
  135.     int        signal;
  136.  
  137.    /****************************************************************/
  138.    /* Recherche du port qui contient les infos relatives a l'ecran */
  139.    /* Ce port permet de passer des donnes de la tache main vers ici*/ 
  140.    /****************************************************************/
  141.  
  142.    IntuitionBase=(struct Library *)OpenLibrary("intuition.library",0);
  143.    GfxBase=(struct Library *)OpenLibrary("graphics.library",0);
  144. #ifdef    DEBUG
  145.    hd=(char *)Open("con:10/10/320/80/",MODE_OLDFILE);
  146. #endif
  147.  
  148.    if((mp=FindPort("That's Dark!"))==0){
  149.         dark();
  150.    }else{
  151.     /*********************************************/
  152.     /* On recupere les informaitons ainsi passee */
  153.     /*********************************************/
  154.     p_data_proc=(struct appel_proc *)mp;
  155.     p_info=p_data_proc->p_info;
  156.     p_data_proc->p_gadg=my_gadg;
  157.     p_data_proc->p_texte=p_text_info;
  158.     p_data_proc->type_screen=SCR_OWN;
  159.     proc_init();
  160.  
  161.     /* Si on n'a pas encore notifie le type de verision */
  162.     if(p_data_proc->code_ret==-1){
  163.         p_data_proc->code_ret=DARK_WB_13;
  164.     }
  165.  
  166.     my_t=FindTask(0);
  167. #ifdef    DEBUG
  168.     MyWrite("Avant le do\n");
  169.     SPrintF(pr_buff,"Tache mt:%lx\n",my_t);
  170.     MyWrite(pr_buff);
  171. #endif
  172.     /* Attend que le main nous reveille */
  173.     do{
  174.         signal=Wait(SIG_MAIN_DARK_DO_DARK|SIG_MAIN_DARK_EXIT|SIGBREAKF_CTRL_C);
  175. #ifdef    DEBUG
  176.         SPrintF(pr_buff,"Signal recu:%lx\n",signal);
  177.         MyWrite(pr_buff);
  178. #endif
  179.         if((signal&SIG_MAIN_DARK_DO_DARK)!=0){
  180. #ifdef    DEBUG
  181.             MyWrite("Signal dark...\n");
  182.             MyWrite("J'attend le ctrl-C\n");
  183. #endif
  184.             /* On efface les eventuels CTRL_C prec */
  185.             SetSignal(0,SIGBREAKF_CTRL_C);
  186.             MyWrite("Signaux remis a 0\n");
  187.             dark();
  188. #ifdef    DEBUG
  189.             MyWrite("ctrl-C recu, j'averti le main\n");
  190. #endif
  191.             Signal(my_t->tc_UserData,SIG_DARK_MAIN_STOPPED);
  192.         }
  193.     }while((signal&SIG_MAIN_DARK_EXIT)==0);
  194.     proc_end();
  195. #ifdef    DEBUG
  196.     MyWrite("Signal Exit..\n");
  197. #endif
  198. /*
  199.     Signal(my_t->tc_UserData,SIG_DARK_MAIN_EXITED);
  200. */
  201.      }
  202. #ifdef    DEBUG
  203.      Close(hd);
  204. #endif
  205.     return 0;
  206. }
  207.  
  208. int    __saveds    tst_end()
  209. {
  210.  
  211.     if((SetSignal(0,0)&SIGBREAKF_CTRL_C)!=0){
  212.         return TRUE;
  213.     }else{
  214.         return FALSE;
  215.     }
  216. }
  217.  
  218. void    __saveds    wait_end()
  219. {
  220.     Wait(SIGBREAKF_CTRL_C);
  221. }
  222.