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

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