home *** CD-ROM | disk | FTP | other *** search
/ 17 Bit Software 1: Collection A / 17Bit_Collection_A.iso / files / 282.dms / 282.adf / SourceCode / master.c < prev    next >
C/C++ Source or Header  |  2004-11-28  |  9KB  |  294 lines

  1. #include <intuition/intuition.h>
  2. #include <graphics/gfxbase.h>
  3. #include <graphics/view.h>
  4. #include <exec/memory.h>
  5.  
  6. struct IntuitionBase *IntuitionBase;
  7. struct GfxBase *GfxBase;
  8. char *OpenLibrary();
  9. short menubreite;
  10. APTR AllocMem();
  11.  
  12. struct  GFill
  13. {
  14.    SHORT    LeftEdge,TopEdge;
  15.    UBYTE    FrontPen,BackPen,DrawMode;
  16.    BYTE     Count;
  17.    SHORT    *XY;
  18.    struct   Border *NextBorder;
  19.    SHORT    data[10];
  20.    UBYTE    FPen,BPen,DMode;
  21.    SHORT    LEdge,TEdge;
  22.    struct   TextAttr *ITextFont;
  23.    UBYTE    *IText;
  24.    struct   IntuiText *NextText;
  25. };
  26.  
  27. OpenMaster ()
  28. {
  29.  if (!(IntuitionBase=(struct IntuitionBase *)
  30.        OpenLibrary ("intuition.library",0l)))
  31.  return (FALSE);
  32.  if (!(GfxBase=(struct GfxBase *) 
  33.        OpenLibrary ("graphics.library",0l)))
  34.  { CloseLibrary (IntuitionBase); return (FALSE); }
  35.  menubreite=20;
  36.  return (TRUE);
  37. }
  38.  
  39. CloseMaster (scr,win)
  40. struct Screen *scr;
  41. struct Window *win;
  42. {
  43.  if (win)           CloseWindow (win);
  44.  if (scr)           CloseScreen (scr);
  45.  if (GfxBase)       CloseLibrary (GfxBase);
  46.  if (IntuitionBase) CloseLibrary (IntuitionBase);
  47.  exit(TRUE);
  48. }
  49.  
  50. struct Screen *MasterScreen (xweite,yweite,farbzahl,title)
  51. short xweite,yweite,farbzahl;   UBYTE title[];
  52. {
  53.  struct NewScreen nws;
  54.  struct Screen *scr,*OpenScreen();
  55.  short modus=0,tiefe=1;
  56.  if (farbzahl>2)  tiefe=2; if (farbzahl>4)  tiefe=3;
  57.  if (farbzahl>8)  tiefe=4; if (farbzahl>16) tiefe=5;
  58.  if (farbzahl>32) { tiefe=6; modus=EXTRA_HALFBRITE; }
  59.  if (farbzahl>64) { tiefe=6; modus=HAM; }
  60.  if ((xweite>330)&&(tiefe>4)) return (FALSE);
  61.  if (xweite>330) modus|=HIRES;
  62.  if (yweite>256) modus|=LACE; /* oder INTERLACE !!!!!*/
  63.  if ((title[0]==0)||(title==0)) nws.BlockPen=0; else nws.BlockPen=1;
  64.   nws.LeftEdge=0;                 nws.TopEdge=0;
  65.   nws.Width=xweite;               nws.Height=yweite;
  66.   nws.Depth=tiefe;                nws.DetailPen= 0;
  67.   nws.ViewModes=modus | SPRITES;  
  68.   nws.Type=CUSTOMSCREEN;
  69.   nws.Font=NULL;                  nws.DefaultTitle=title;
  70.   nws.Gadgets=NULL;               nws.CustomBitMap=NULL;
  71.  if (!(scr=OpenScreen(&nws))) return (FALSE);
  72.  if ((title[0]==0)||(title==0)) SetRast (&(scr->RastPort),0l);
  73.  return(scr);
  74. }
  75. struct Window *MasterWindow (scr,x,y,xlaenge,ylaenge,idcmp,flags,title)
  76. struct Screen *scr;
  77. short x,y,xlaenge,ylaenge;
  78. long idcmp,flags;
  79. UBYTE title[];
  80. {
  81.  struct NewWindow nww;
  82.  struct Window *win,*OpenWindow();
  83.  nww.LeftEdge=x;           nww.TopEdge=y;
  84.  nww.Width=xlaenge;        nww.Height=ylaenge;
  85.  nww.DetailPen=0;          nww.BlockPen=1;
  86.  nww.IDCMPFlags=idcmp | MOUSEBUTTONS | CLOSEWINDOW | MENUPICK; 
  87.  if (flags&WINDOWSIZING)   nww.IDCMPFlags|=NEWSIZE;
  88.  nww.Flags=flags | REPORTMOUSE;
  89.  nww.FirstGadget=NULL;     nww.CheckMark=NULL;
  90.  nww.Title=title;          nww.Screen=scr;
  91.  nww.BitMap=NULL;          nww.MinWidth=xlaenge/10;
  92.  nww.MinHeight=ylaenge/10; nww.MaxWidth=scr->Width;
  93.  nww.MaxHeight=scr->Height;
  94.  if ((scr->Flags)&CUSTOMSCREEN) nww.Type=CUSTOMSCREEN;
  95.  else nww.Type=WBENCHSCREEN;
  96.  if (!(win=OpenWindow(&nww))) return (FALSE);
  97.  return(win);
  98. }
  99.  
  100. MasterRequest(win,htext,ltext,rtext)
  101. struct Window *win;
  102. UBYTE htext[],ltext[],rtext[];
  103. {
  104.  struct IntuiText ht,lt,rt;
  105.  ht.FrontPen=0;  ht.BackPen=1;  ht.DrawMode=JAM1;
  106.  ht.LeftEdge=10; ht.TopEdge=10; ht.ITextFont=NULL;
  107.  ht.IText=htext; ht.NextText=NULL; 
  108.  
  109.  lt.FrontPen=0;  lt.BackPen=1;  lt.DrawMode=JAM1;
  110.  lt.LeftEdge=5;  lt.TopEdge=3;  lt.ITextFont=NULL;
  111.  lt.IText=ltext; lt.NextText=NULL;
  112.  
  113.  rt.FrontPen=0;  rt.BackPen=1;  rt.DrawMode=JAM1;
  114.  rt.LeftEdge=5;  rt.TopEdge=3;  rt.ITextFont=NULL;
  115.  rt.IText=rtext; rt.NextText=NULL;
  116.  return (AutoRequest(win,&ht,<,&rt,0l,0l,(long)(10*strlen(htext)),70l));
  117. }
  118.  
  119. AddMenu (win,title)
  120. struct Window *win;
  121. BYTE title[];
  122. {
  123.  struct Menu *menu,**wo;
  124.  if (menubreite+10*strlen(title)+20>(win->WScreen->Width)) return(FALSE);
  125.  if (!(menu=(struct Menu *) AllocMem((long)(sizeof(struct Menu)),
  126.                      MEMF_CLEAR | MEMF_CHIP | MEMF_PUBLIC ))) return(FALSE);
  127.  Forbid();
  128.  menu->LeftEdge=menubreite;      menu->Width=10*strlen(title);
  129.  menu->Height=10;                menu->Flags=1;
  130.  menu->MenuName=title;
  131.  menubreite+=10*strlen(title)+20;
  132.  wo=&(win->MenuStrip);
  133.  while (*wo!=NULL) wo= &((*wo)->NextMenu);
  134.  *wo=menu;
  135.  SetMenuStrip (win,win->MenuStrip);
  136.  Permit();
  137.  return(TRUE);
  138. }
  139.  
  140. AddItem (win,menunummer,title,commseq)
  141. struct Window *win;
  142. short menunummer;
  143. char title[],commseq;
  144. {
  145.  struct Menu *menu;
  146.  struct MenuItem *mitem,**wo;
  147.  struct IntuiText *itext;
  148.  short count=0;
  149.  menu=win->MenuStrip;
  150.  while (menunummer--) { if (menu==NULL) return(FALSE); menu=menu->NextMenu; }
  151.  if (menu==NULL) return(FALSE);
  152.  if (!(mitem=(struct MenuItem *) AllocMem((long)(sizeof(struct MenuItem)),
  153.                       MEMF_CLEAR | MEMF_CHIP | MEMF_PUBLIC ))) return(FALSE);
  154.  if (!(itext=(struct IntuiText *) AllocMem((long)(sizeof(struct IntuiText)),
  155.                       MEMF_CLEAR | MEMF_CHIP | MEMF_PUBLIC ))) return(FALSE);
  156.  Forbid();
  157.  wo=&(menu->FirstItem);
  158.  if (!(*wo)) menu->FirstItem=mitem;
  159.  else 
  160.  { 
  161.   count=1;
  162.   while ((*wo)->NextItem) { count++; wo=&((*wo)->NextItem); }
  163.   (*wo)->NextItem=mitem;
  164.  }
  165.  itext->BackPen=1;  itext->LeftEdge=5;   itext->TopEdge=3;
  166.  itext->IText=(UBYTE *) title;
  167.  mitem->LeftEdge=5;                mitem->TopEdge=count*13;
  168.  mitem->Width=10*strlen(title)+30;  mitem->Height=12;
  169.  mitem->Flags=ITEMTEXT | ITEMENABLED | HIGHBOX;
  170.  if (commseq) mitem->Flags|=COMMSEQ;
  171.  mitem->ItemFill=(APTR) itext;      mitem->Command=(BYTE) commseq;
  172.  SetMenuStrip (win,win->MenuStrip);
  173.  Permit();
  174.  return(TRUE);
  175. }
  176. AddSubItem (win,menunummer,itemnummer,title,commseq)
  177. struct Window *win;
  178. short menunummer,itemnummer;
  179. char title[],commseq;
  180. {
  181.  struct Menu *menu;
  182.  struct MenuItem *mitem,*item,**wo;
  183.  struct IntuiText *itext;
  184.  short count=0;
  185.  menu=win->MenuStrip;
  186.  while (menunummer--) { if (menu==NULL) return(FALSE); menu=menu->NextMenu; }
  187.  if (menu==NULL) return(FALSE);
  188.  mitem=menu->FirstItem;
  189.  while (itemnummer--) { if(mitem==NULL) return(FALSE); mitem=mitem->NextItem;}
  190.  if (mitem==NULL) return(FALSE);
  191.  if (!(item=(struct MenuItem *) AllocMem((long)(sizeof(struct MenuItem)),
  192.                       MEMF_CLEAR | MEMF_CHIP | MEMF_PUBLIC ))) return(FALSE);
  193.  if (!(itext=(struct IntuiText *) AllocMem((long)(sizeof(struct IntuiText)),
  194.                       MEMF_CLEAR | MEMF_CHIP | MEMF_PUBLIC ))) return(FALSE);
  195.  Forbid();
  196.  mitem->Flags&=(~(HIGHBOX|COMMSEQ));
  197.  wo=&(mitem->SubItem);
  198.  if (!(*wo)) mitem->SubItem=item;
  199.  else 
  200.  { 
  201.   count=1;
  202.   while ((*wo)->NextItem) { count++; wo=&((*wo)->NextItem); }
  203.   (*wo)->NextItem=item;
  204.  }
  205.  itext->BackPen=1;  itext->LeftEdge=5;   itext->TopEdge=3;
  206.  itext->IText=(UBYTE *) title;
  207.  item->LeftEdge=5+mitem->Width;   item->TopEdge=count*13;
  208.  item->Width=10*strlen(title)+30;  item->Height=12;
  209.  item->Flags=ITEMTEXT | ITEMENABLED | HIGHBOX;
  210.  if (commseq) item->Flags|=COMMSEQ;
  211.  item->ItemFill=(APTR) itext;      item->Command=(BYTE) commseq;
  212.  SetMenuStrip (win,win->MenuStrip);
  213.  Permit();
  214.  return(TRUE);
  215. }
  216. ControlMenu (win,mn,in,sn,cflag,eflag)
  217. struct Window *win;
  218. short mn,in,sn,cflag,eflag;
  219. {
  220.  struct Menu *menu;
  221.  struct MenuItem *item;
  222.  menu=win->MenuStrip;
  223.  while (mn--) { if (menu==NULL) return(FALSE); menu=menu->NextMenu; }
  224.  if (menu==NULL) return(FALSE);
  225.  if (in!=-1) 
  226.  {
  227.   item=menu->FirstItem;
  228.   while (in--) { if(item==NULL) return(FALSE); item=item->NextItem;}
  229.   if (item==NULL) return(FALSE);
  230.   if (sn!=-1)
  231.   {
  232.    item=item->SubItem;
  233.    while (sn--) { if(item==NULL) return(FALSE); item=item->NextItem;}
  234.    if (item==NULL) return(FALSE);
  235.   }
  236.   if (eflag) item->Flags|=ITEMENABLED;
  237.   else       item->Flags&=(~ITEMENABLED);
  238.   if (cflag) item->Flags|=(CHECKED|CHECKIT);
  239.   else       item->Flags&=(~(CHECKED|CHECKIT));
  240.  }
  241.  else menu->Flags=eflag;
  242.  return (TRUE);
  243. }
  244. CloseMenu (win)
  245. struct Window *win;
  246. {
  247.  struct MenuItem *item,*item1,*sitem,*sitem1;
  248.  struct Menu *menu,*menu1;
  249.  menu=win->MenuStrip;
  250.  ClearMenuStrip(win);
  251.  while (menu)
  252.  {
  253.   item=menu->FirstItem;
  254.   while(item)
  255.   {
  256.    sitem=(item->SubItem);
  257.    while (sitem)
  258.    {
  259.     sitem1=sitem;
  260.     sitem=sitem->NextItem;
  261.     FreeMem (sitem1,34l);
  262.     FreeMem ((sitem1->ItemFill),20l);
  263.    }
  264.    item1=item;
  265.    item=item->NextItem;
  266.    FreeMem (item1,34l);
  267.    FreeMem ((item1->ItemFill),20l);
  268.   }
  269.   menu1=menu;
  270.   menu=menu->NextMenu;
  271.   FreeMem (menu1,30l);
  272.  }
  273. MasterSound (start,laenge,rate)
  274. ULONG *start;
  275. UWORD laenge,rate;
  276. {
  277.  USHORT *ctlw,*c0tl,*c0per,*c0vol;
  278.  ULONG  *c0thi;
  279.  c0thi = (ULONG  *) 0xdff0a0;
  280.  c0tl  = (USHORT *) 0xdff0a4;
  281.  c0per = (USHORT *) 0xdff0a6;
  282.  c0vol = (USHORT *) 0xdff0a8;
  283.  ctlw  = (USHORT *) 0xdff096;
  284.  *ctlw =1;
  285.  if (!(laenge)) return();
  286.  *c0thi = (long) start;
  287.  *c0tl  = laenge/2;
  288.  *c0per = rate;
  289.  *c0vol = 63;
  290.  *ctlw  = 0x8201;
  291. }
  292.  
  293.