home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 311.lha / Wipedemo_v4.0 / Wipedemo2.c < prev    next >
C/C++ Source or Header  |  1980-12-10  |  7KB  |  308 lines

  1. #include "wipecount.h"
  2.  
  3. struct NewWindow NewWindow = {
  4. 250,160,145,10,
  5. 1,2,
  6. NULL,   /* IDCMP flags ... later CLOSEWINDOW */
  7. WINDOWCLOSE|WINDOWDRAG|SMART_REFRESH|NOCAREREFRESH|WINDOWDEPTH|ACTIVATE,
  8. NULL,
  9. NULL,
  10. (STRPTR) "Demo",
  11. NULL,
  12. NULL,
  13. 0,0,0,0,
  14. WBENCHSCREEN
  15. };
  16.  
  17. struct NewScreen NewScreen = {
  18. 0,0,384,240,5,
  19. 0,1,
  20. NULL,
  21. CUSTOMSCREEN,
  22. NULL,
  23. (STRPTR) "Please wait...",
  24. NULL,
  25. NULL
  26. };
  27.  
  28. struct Screen *Picture;
  29. struct Window *Control;
  30. struct IntuitionBase *IntuitionBase;
  31. struct GfxBase *GfxBase;
  32. struct Library *IconBase;
  33. struct narrator_rb *TalkCB = 0;
  34. struct timerequest *WaitCB;
  35. FILE *script;
  36. long numplanes;
  37. extern struct WBStartup *WBenchMsg;
  38.  
  39. main(argc,argv)
  40. int argc;
  41. char **argv;
  42. {
  43. char *get1,*get2,*GetLin(),*scrfln;
  44. static UBYTE chmasks[4] = {3,5,10,12};
  45. static UWORD ptr[6] = {0,0,0,0,0,0};
  46. struct narrator_rb *CreateExtIO();
  47. long time(),nzx,nzy;
  48. int wipesel = -1,fadesel = 1,cycsel = 0,arg = 1,t0;
  49. BOOL hires = FALSE,lace = FALSE;
  50. static BOOL exclmap[WIPECOUNT];
  51. struct DiskObject *diskobj;
  52. char *value;
  53.  
  54.    scrfln = "wipedemo.s";
  55.    if (!argc)
  56.       {
  57.       IconBase = OpenLibrary("icon.library",0L);
  58.       if (WBenchMsg->sm_NumArgs == 2)
  59.          {
  60.          scrfln = WBenchMsg->sm_ArgList[1].wa_Name;
  61.          diskobj = GetDiskObject(scrfln);
  62.          }
  63.       else
  64.          diskobj = GetDiskObject(WBenchMsg->sm_ArgList[0].wa_Name);
  65.       if (value = FindToolType(diskobj->do_ToolTypes,"FLAGS"))
  66.          {
  67.          lace = MatchToolValue(value,"LACE");
  68.          hires = MatchToolValue(value,"HIRES");
  69.          }
  70.       FreeDiskObject(diskobj);
  71.       CloseLibrary(IconBase);
  72.       }
  73.    else
  74.       {
  75.       if (!ustrcmp("?",argv[1]))
  76.          {
  77.          printf("Usage: %s [LACE] [HIRES] [FILENAME]\n",argv[0]);
  78.          exit(0L);
  79.          }
  80.       if (arg < argc)
  81.          if (!ustrcmp("lace",argv[arg]))
  82.             {
  83.             lace = TRUE;
  84.             arg++;
  85.             }
  86.       if (arg < argc)
  87.          if (!ustrcmp("hires",argv[arg]))
  88.             {
  89.             hires = TRUE;
  90.             arg++;
  91.             }
  92.       if (arg < argc)
  93.          if (!ustrcmp("lace",argv[arg]))
  94.             {
  95.             lace = TRUE;
  96.             arg++;
  97.             }
  98.       if (arg < argc)
  99.          scrfln = argv[arg];
  100.       }
  101.    nzx = 32;
  102.    nzy = 20;
  103.    if (lace)
  104.       {
  105.       NewScreen.Height = 480;
  106.       NewScreen.ViewModes |= INTERLACE;
  107.       nzy = 40;
  108.       }
  109.    if (hires)
  110.       {
  111.       NewScreen.Width = 768;
  112.       NewScreen.ViewModes |= HIRES;
  113.       nzx = 64;
  114.       }
  115.    Check0(IntuitionBase = (struct IntuitionBase *) OpenLibrary("intuition.library",0L));
  116.    Check0(GfxBase = (struct GfxBase *) OpenLibrary("graphics.library",0L));
  117.    numplanes = (hires) ? 4 : 6;
  118.    NewScreen.Depth = numplanes;
  119.    Check0(script = fopen(scrfln,"r"));
  120.    Check0(Picture = OpenScreen(&NewScreen));
  121.    Picture->ViewPort.DxOffset = -nzx;
  122.    Picture->ViewPort.DyOffset = -nzy;
  123.    Check0(Control = OpenWindow(&NewWindow));
  124.    SetPointer(Control,ptr,1L,1L,0L,0L);
  125.    srand((unsigned int) time(0L));
  126.    Check0(WaitCB = (struct timerequest *) CreateExtIO(CreatePort(0L,0L),(long)
  127.                   sizeof(struct timerequest)));
  128.    OpenDevice(TIMERNAME,UNIT_VBLANK,WaitCB,0L);
  129.    WaitCB->tr_node.io_Command = TR_ADDREQUEST;
  130.    WaitCB->tr_time.tv_micro = 0;
  131.  
  132.    FOREVER
  133.       {
  134.       get1 = GetLin(script);
  135.       if (!get1)
  136.          break;
  137.       if (*get1 == '#')
  138.          continue;
  139.       for (get2 = get1; *get2 != ' '; get2++)
  140.          if (!(*get2))
  141.             break;
  142.       if (*get2)
  143.          *(get2++) = NULL;
  144.       if (!ustrcmp(get1,"show"))
  145.          {
  146.          LoadPict(get2,Picture,wipesel,cycsel,fadesel,exclmap,hires,lace);
  147.          continue;
  148.          }
  149.       if (!ustrcmp(get1,"say"))
  150.          {
  151.          if (!TalkCB)
  152.             {
  153.             Check0(TalkCB = CreateExtIO(CreatePort(0L,0L),
  154.                (long) sizeof(struct narrator_rb)));
  155.             TalkCB->ch_masks = chmasks;
  156.             TalkCB->nm_masks = 4;
  157.             TalkCB->message.io_Command = CMD_WRITE;
  158.             TalkCB->mouths = 0;
  159.             if (OpenDevice("narrator.device",0L,TalkCB,0L))
  160.                TheEnd();
  161.             }
  162.          Say(get2);
  163.          continue;
  164.          }
  165.       if (!ustrcmp(get1,"wait"))
  166.          {
  167.          Sit(get2);
  168.          continue;
  169.          }
  170.       if (!ustrcmp(get1,"loop"))
  171.          {
  172.          fseek(script,0L,0);
  173.          continue;
  174.          }
  175.       if (!ustrcmp(get1,"random"))
  176.          {
  177.          wipesel = -1;
  178.          continue;
  179.          }
  180.       if (!ustrcmp(get1,"select"))
  181.          {
  182.          wipesel = atoi(get2);
  183.          continue;
  184.          }
  185.       if (!ustrcmp(get1,"exclude"))
  186.          {
  187.          if (!ustrcmp(get2,"all"))
  188.             {
  189.             for (t0 = 0; t0 != WIPECOUNT; t0++)
  190.                exclmap[t0] = TRUE;
  191.             continue;
  192.             }
  193.          if (!exclmap[t0 = atoi(get2)])
  194.             exclmap[t0] = TRUE;
  195.          continue;
  196.          }
  197.       if (!ustrcmp(get1,"include"))
  198.          {
  199.          if (!ustrcmp(get2,"all"))
  200.             for (t0 = 0; t0 != WIPECOUNT; t0++)
  201.                exclmap[t0] = FALSE;
  202.          if (exclmap[t0 = atoi(get2)])
  203.             exclmap[t0] = FALSE;
  204.          continue;
  205.          }
  206.       if (!ustrcmp(get1,"fades"))
  207.          {
  208.          if (!ustrcmp(get2,"off"))
  209.             fadesel = 0;
  210.          else
  211.             fadesel = 1;
  212.          continue;
  213.          }
  214.       if (!ustrcmp(get1,"cycle"))
  215.          {
  216.          if (!ustrcmp(get2,"off"))
  217.             cycsel = 0;
  218.          else
  219.             cycsel = 1;
  220.          continue;
  221.          }
  222.       break;
  223.       }
  224.    TheEnd();
  225. }
  226.  
  227. TheEnd()
  228. {
  229.    StopCringe();
  230.    if (WaitCB && WaitCB->tr_node.io_Device)
  231.       CloseDevice(WaitCB);
  232.    if (TalkCB && TalkCB->message.io_Device)
  233.       CloseDevice(TalkCB);
  234.    if (TalkCB)
  235.       {
  236.       DeletePort(TalkCB->message.io_Message.mn_ReplyPort);
  237.       DeleteExtIO(TalkCB,(long) sizeof(struct narrator_rb));
  238.       }
  239.    if (WaitCB)
  240.       {
  241.       DeletePort(WaitCB->tr_node.io_Message.mn_ReplyPort);
  242.       DeleteExtIO(WaitCB,(long) sizeof(struct timerequest));
  243.       }
  244.    if (Control)
  245.       CloseWindow(Control);
  246.    if (Picture)
  247.       CloseScreen(Picture);
  248.    if (script)
  249.       fclose(script);
  250.    if (GfxBase)
  251.       CloseLibrary(GfxBase);
  252.    if (IntuitionBase)
  253.       CloseLibrary(IntuitionBase);
  254.    exit(0L);
  255. }
  256.  
  257. Say(whattosay)
  258. char *whattosay;
  259. {
  260.    TalkCB->message.io_Data = (APTR) whattosay;
  261.    TalkCB->message.io_Length = strlen(whattosay);
  262.    DoIO(TalkCB);
  263. }
  264.  
  265. Sit(howstr)
  266. char *howstr;
  267. {
  268. int secs;
  269. struct Message *Mess;
  270.  
  271.    ModifyIDCMP(Control,CLOSEWINDOW);
  272.    secs = atoi(howstr);
  273.    WaitCB->tr_time.tv_secs = secs;
  274.    SendIO(WaitCB);
  275.    Wait((1L << WaitCB->tr_node.io_Message.mn_ReplyPort->mp_SigBit) |
  276.         (1L << Control->UserPort->mp_SigBit));
  277.    if (Mess = GetMsg(Control->UserPort))
  278.       {
  279.       AbortIO(WaitCB);
  280.       ReplyMsg(Mess);
  281.       TheEnd();
  282.       }
  283.    GetMsg(WaitCB->tr_node.io_Message.mn_ReplyPort);
  284.    ModifyIDCMP(Control,0L);
  285. }
  286.  
  287. char *GetLin(handle)
  288. FILE *handle;
  289. {
  290. static char buf[90];
  291.  
  292. if (fgets(buf,90,handle) == NULL)
  293.    return(NULL);
  294.  
  295. buf[strlen(buf)-1] = NULL;
  296.  
  297. return(buf);
  298. }
  299.  
  300. ustrcmp(x,y)
  301. char *x,*y;
  302. {
  303.    while (*x)
  304.       if (toupper(*(x++)) != toupper(*(y++)))
  305.          return(1);
  306.    return(0);
  307. }
  308.