home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 311.lha / Wipedemo_v4.0 / wipedemo.c < prev    next >
Encoding:
C/C++ Source or Header  |  1980-12-10  |  6.8 KB  |  302 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,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,1,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.          continue;
  208.       if (!ustrcmp(get1,"cycle"))
  209.          {
  210.          if (!ustrcmp(get2,"off"))
  211.             cycsel = 0;
  212.          else
  213.             cycsel = 1;
  214.          continue;
  215.          }
  216.       break;
  217.       }
  218.    TheEnd();
  219. }
  220.  
  221. TheEnd()
  222. {
  223.    StopCringe();
  224.    if (WaitCB && WaitCB->tr_node.io_Device)
  225.       CloseDevice(WaitCB);
  226.    if (TalkCB && TalkCB->message.io_Device)
  227.       CloseDevice(TalkCB);
  228.    if (TalkCB)
  229.       {
  230.       DeletePort(TalkCB->message.io_Message.mn_ReplyPort);
  231.       DeleteExtIO(TalkCB,(long) sizeof(struct narrator_rb));
  232.       }
  233.    if (WaitCB)
  234.       {
  235.       DeletePort(WaitCB->tr_node.io_Message.mn_ReplyPort);
  236.       DeleteExtIO(WaitCB,(long) sizeof(struct timerequest));
  237.       }
  238.    if (Control)
  239.       CloseWindow(Control);
  240.    if (Picture)
  241.       CloseScreen(Picture);
  242.    if (script)
  243.       fclose(script);
  244.    if (GfxBase)
  245.       CloseLibrary(GfxBase);
  246.    if (IntuitionBase)
  247.       CloseLibrary(IntuitionBase);
  248.    exit(0L);
  249. }
  250.  
  251. Say(whattosay)
  252. char *whattosay;
  253. {
  254.    TalkCB->message.io_Data = (APTR) whattosay;
  255.    TalkCB->message.io_Length = strlen(whattosay);
  256.    DoIO(TalkCB);
  257. }
  258.  
  259. Sit(howstr)
  260. char *howstr;
  261. {
  262. int secs;
  263. struct Message *Mess;
  264.  
  265.    ModifyIDCMP(Control,CLOSEWINDOW);
  266.    secs = atoi(howstr);
  267.    WaitCB->tr_time.tv_secs = secs;
  268.    SendIO(WaitCB);
  269.    Wait((1L << WaitCB->tr_node.io_Message.mn_ReplyPort->mp_SigBit) |
  270.         (1L << Control->UserPort->mp_SigBit));
  271.    if (Mess = GetMsg(Control->UserPort))
  272.       {
  273.       AbortIO(WaitCB);
  274.       ReplyMsg(Mess);
  275.       TheEnd();
  276.       }
  277.    GetMsg(WaitCB->tr_node.io_Message.mn_ReplyPort);
  278.    ModifyIDCMP(Control,0L);
  279. }
  280.  
  281. char *GetLin(handle)
  282. FILE *handle;
  283. {
  284. static char buf[90];
  285.  
  286. if (fgets(buf,90,handle) == NULL)
  287.    return(NULL);
  288.  
  289. buf[strlen(buf)-1] = NULL;
  290.  
  291. return(buf);
  292. }
  293.  
  294. ustrcmp(x,y)
  295. char *x,*y;
  296. {
  297.    while (*x)
  298.       if (toupper(*(x++)) != toupper(*(y++)))
  299.          return(1);
  300.    return(0);
  301. }
  302.