home *** CD-ROM | disk | FTP | other *** search
/ The CDPD Public Domain Collection for CDTV 3 / CDPDIII.bin / pd / commodities / superdark / blankers / proc_main.c < prev    next >
C/C++ Source or Header  |  1993-03-21  |  5KB  |  215 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. _main(line)
  124. register    char    *line;
  125. {
  126.     struct    Task    *my_t;
  127.     struct    MsgPort    *mp;
  128.     int        signal;
  129.  
  130.    /****************************************************************/
  131.    /* Recherche du port qui contient les infos relatives a l'ecran */
  132.    /* Ce port permet de passer des donnes de la tache main vers ici*/ 
  133.    /****************************************************************/
  134.  
  135.    IntuitionBase=(struct Library *)OpenLibrary("intuition.library",0);
  136.    GfxBase=(struct Library *)OpenLibrary("graphics.library",0);
  137. #ifdef    DEBUG
  138.    hd=(char *)Open("con:10/10/320/80/",MODE_OLDFILE);
  139. #endif
  140.  
  141.    if((mp=FindPort("That's Dark!"))==0){
  142.         dark();
  143.    }else{
  144.     /*********************************************/
  145.     /* On recupere les informaitons ainsi passee */
  146.     /*********************************************/
  147.     p_data_proc=(struct appel_proc *)mp;
  148.     p_info=p_data_proc->p_info;
  149.     p_data_proc->p_gadg=my_gadg;
  150.     p_data_proc->p_texte=p_text_info;
  151.     p_data_proc->type_screen=SCR_OWN;
  152.     proc_init();
  153.  
  154.     /* Si on n'a pas encore notifie le type de verision */
  155.     if(p_data_proc->code_ret==-1){
  156.         p_data_proc->code_ret=DARK_WB_13;
  157.     }
  158.  
  159.     my_t=FindTask(0);
  160. #ifdef    DEBUG
  161.     MyWrite("Avant le do\n");
  162.     SPrintF(pr_buff,"Tache mt:%lx\n",my_t);
  163.     MyWrite(pr_buff);
  164. #endif
  165.     /* Attend que le main nous reveille */
  166.     do{
  167.         signal=Wait(SIG_MAIN_DARK_DO_DARK|SIG_MAIN_DARK_EXIT|SIGBREAKF_CTRL_C);
  168. #ifdef    DEBUG
  169.         SPrintF(pr_buff,"Signal recu:%lx\n",signal);
  170.         MyWrite(pr_buff);
  171. #endif
  172.         if((signal&SIG_MAIN_DARK_DO_DARK)!=0){
  173. #ifdef    DEBUG
  174.             MyWrite("Signal dark...\n");
  175.             MyWrite("J'attend le ctrl-C\n");
  176. #endif
  177.             /* On efface les eventuels CTRL_C prec */
  178.             SetSignal(0,SIGBREAKF_CTRL_C);
  179.             MyWrite("Signaux remis a 0\n");
  180.             dark();
  181. #ifdef    DEBUG
  182.             MyWrite("ctrl-C recu, j'averti le main\n");
  183. #endif
  184.             Signal(my_t->tc_UserData,SIG_DARK_MAIN_STOPPED);
  185.         }
  186.     }while((signal&SIG_MAIN_DARK_EXIT)==0);
  187.     proc_end();
  188. #ifdef    DEBUG
  189.     MyWrite("Signal Exit..\n");
  190. #endif
  191. /*
  192.     Signal(my_t->tc_UserData,SIG_DARK_MAIN_EXITED);
  193. */
  194.      }
  195. #ifdef    DEBUG
  196.      Close(hd);
  197. #endif
  198.     return 0;
  199. }
  200.  
  201. int    __saveds    tst_end()
  202. {
  203.  
  204.     if((SetSignal(0,0)&SIGBREAKF_CTRL_C)!=0){
  205.         return TRUE;
  206.     }else{
  207.         return FALSE;
  208.     }
  209. }
  210.  
  211. void    __saveds    wait_end()
  212. {
  213.     Wait(SIGBREAKF_CTRL_C);
  214. }
  215.