home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 106 / EnigmaAmiga106CD.iso / indispensabili / grafica / amipeg_1.1 / src / pivpip.c < prev    next >
C/C++ Source or Header  |  1997-12-06  |  5KB  |  224 lines

  1.  
  2. /* this source implements aMiPEG's interface to PicassoIVPIP */
  3.  
  4.  
  5. #include <string.h>
  6. #include <stdlib.h>
  7.  
  8. #include <exec/exec.h>
  9. #include <intuition/intuition.h>
  10. #include <intuition/screens.h>
  11. #include <dos/dos.h>
  12.  
  13. #include <proto/graphics.h>
  14. #include <proto/exec.h>
  15. #include <proto/intuition.h>
  16. #include <proto/dos.h>
  17. #include <proto/Picasso96.h>
  18. #include <proto/asyncio.h>
  19.  
  20. #include "video.h"
  21. #include "proto.h"
  22.  
  23. extern int doneFlag;
  24. extern int fullFlag;
  25. extern int ditherType;
  26. extern int cyber_pub;
  27. extern struct GfxBase *GfxBase;
  28.  
  29. struct Library *P96Base;
  30.  
  31. extern ULONG cyber_mode;
  32. extern ULONG depth;
  33. extern struct Screen *cyber_screen;
  34. extern struct Window *cyber_window;
  35. struct RenderInfo RI;
  36. extern int original_x, original_y;
  37.  
  38.  
  39. static void Quit(char *why, int failcode)
  40. {
  41.     puts(why);
  42.     exit(failcode);
  43. }
  44.  
  45. static void output_term(void)
  46. {
  47.     close_timer();
  48.     if(input)
  49.     {
  50.         CloseAsync(input);
  51.         input = NULL;
  52.     }
  53.  
  54.     if(cyber_window)
  55.         p96PIP_Close(cyber_window);
  56.  
  57.     if(!cyber_pub && cyber_screen)
  58.         CloseScreen(cyber_screen);
  59.  
  60.     if (GfxBase) CloseLibrary((struct Library *)GfxBase);
  61.     if (P96Base) CloseLibrary(P96Base);
  62.     if (IntuitionBase) CloseLibrary((struct Library *) IntuitionBase);
  63. }
  64.  
  65. void DrawP96Image(UWORD *data, int x, int y)
  66. {
  67.     LONG lock;
  68.     
  69.     struct BitMap *BM;
  70.     UWORD *address;
  71.  
  72.     p96PIP_GetTags(cyber_window, P96PIP_SourceBitMap, (ULONG)&BM, TAG_END);
  73.  
  74.     lock = p96LockBitMap(BM, (UBYTE *)&RI, sizeof(struct RenderInfo));
  75.  
  76.     address = (UWORD *) RI.Memory;
  77.  
  78.     for(; y > 0; y--)
  79.     {
  80.         memcpy(address, data, x << 1);
  81.         address += RI.BytesPerRow/2;
  82.         data += ((x + 15) >> 4) << 4;
  83.     }
  84.  
  85.     p96UnlockBitMap(BM, lock);
  86. }
  87.  
  88. int p96_handle_window(void)
  89. {
  90.     struct IntuiMessage *imsg;
  91.     struct IntuiMessage msg;
  92.     static ULONG last_secs, last_micros;
  93.  
  94.     if(cyber_window)
  95.     {
  96.         while(imsg = p96PIP_GetIMsg(cyber_window->UserPort))
  97.         {
  98.             CopyMem((char *)imsg, (char *)&msg, (long)sizeof(struct IntuiMessage));
  99.             p96PIP_ReplyIMsg(imsg);
  100.  
  101.             switch(msg.Class)
  102.             {
  103.                 case IDCMP_VANILLAKEY:
  104.                     if(msg.Code == '\x1b' || msg.Code == 'q')
  105.                     {
  106.                         
  107.                                 doneFlag = DONE_REALLY;
  108.                                 return(FALSE);
  109.                     }
  110.                     if(msg.Code == 13 || msg.Code == 32)    /* space & return */
  111.                         return(FALSE);
  112.                     break;
  113.  
  114.                 case IDCMP_CLOSEWINDOW:
  115.                 {
  116.                     doneFlag = DONE_NOT_REALLY;
  117.                     return(FALSE);
  118.                 }
  119.  
  120.                 case IDCMP_MOUSEBUTTONS:
  121.                     if(!fullFlag && msg.Code == SELECTDOWN)
  122.                     {
  123.                         if(DoubleClick(last_secs, last_micros, msg.Seconds, msg.Micros))
  124.                             ChangeWindowBox(cyber_window, cyber_window->LeftEdge, cyber_window->TopEdge, original_x, original_y);
  125.  
  126.                         last_secs = msg.Seconds;
  127.                         last_micros = msg.Micros;
  128.                     }
  129.                 break;
  130.  
  131.                 default:
  132.                 break;
  133.             }
  134.         }
  135.     }
  136.     return(TRUE);
  137. }
  138.  
  139.  
  140. BOOL init_P96(void)
  141. {
  142.     if(IntuitionBase = (struct IntuitionBase *) OpenLibrary("intuition.library",37))
  143.         if(P96Base = OpenLibrary("Picasso96API.library", 2))
  144.             if(P96Base->lib_Revision >= 165)
  145.                 if(GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", 39))
  146.                     return(TRUE);
  147.                 else
  148.                     Quit("graphics.library v39+ not present", 25);
  149.             else
  150.                 Quit("Picasso96API.library v2.165 or higher not present", 25);
  151.         else
  152.             Quit("Picasso96API.library v2+ not present", 25);
  153.     else
  154.         Quit("intuition.library is too old, <V39", 25);
  155. }
  156.  
  157. void CheckPIV(void)
  158. {
  159.     if(!OpenResource("PicassoIV.resource"))
  160.     {
  161.         Quit("Sorry, but the option 'dither=pivpip' requires a PicassoIV graphicsboard !\n",25);
  162.     }
  163. }
  164.  
  165. int get_P96_mode(void)
  166. {
  167.     return((int)p96RequestModeIDTags(
  168.                                 P96MA_WindowTitle, "Select a screenmode for MPEG window",
  169.                                 P96MA_MinDepth, 8,
  170.                                 TAG_DONE));
  171. }
  172.  
  173.  
  174. unsigned long InitP96Display(unsigned long modeid)
  175. {
  176.     WORD pens[] = { ~0 };
  177.  
  178.     atexit(output_term);
  179.  
  180.     if(init_P96())
  181.     {
  182.         if(cyber_pub || (modeid != 0xffffffff) || (modeid = get_P96_mode()) != 0xffffffff)
  183.         {
  184.             if(cyber_pub)
  185.             {
  186.                 cyber_screen = LockPubScreen(pubname_ptr);
  187.                 modeid = GetVPModeID(&cyber_screen->ViewPort);
  188.                 ScreenToFront(cyber_screen);
  189.                 UnlockPubScreen(NULL, cyber_screen);
  190.             }
  191.  
  192.             cyber_mode = modeid;
  193.             depth = p96GetModeIDAttr(cyber_mode, P96IDA_DEPTH);
  194.             if(depth < 8 )
  195.                 Quit("aMiPEG: this screen is not deep enough (needed at least 8 bits).", 25);
  196.  
  197.             if(cyber_screen || (cyber_screen = OpenScreenTags(NULL,
  198.                             SA_DisplayID, cyber_mode,
  199.                             SA_Title, (UBYTE *)"aMiPEG 1.0 by Michael Rausch and Miloslaw Smyk",
  200.                             SA_Depth, depth,
  201.                             SA_Pens, &pens,
  202.                             SA_SharePens, TRUE,
  203.                             TAG_DONE)))
  204.             {
  205.                 if(cyber_window = p96PIP_OpenTags(P96PIP_SourceFormat, RGBFB_Y4U2V2,
  206.                     P96PIP_SourceWidth, 160,
  207.                     P96PIP_SourceHeight, 128,
  208.                     (cyber_pub ? WA_PubScreenName : WA_CustomScreen), (cyber_pub ? (ULONG)pubname_ptr : (ULONG)cyber_screen),
  209.                     WA_Flags, WFLG_ACTIVATE | (fullFlag ? WFLG_BORDERLESS : WFLG_DEPTHGADGET | WFLG_CLOSEGADGET | WFLG_DRAGBAR | WFLG_SIZEGADGET | WFLG_SIZEBBOTTOM),
  210.                     WA_IDCMP, CLOSEWINDOW | MOUSEBUTTONS | VANILLAKEY | NEWSIZE,
  211.                     (fullFlag ? WA_Width : TAG_IGNORE), -1,
  212.                     (fullFlag ? WA_Height : TAG_IGNORE), -1,
  213.                     (fullFlag ? TAG_SKIP : TAG_IGNORE), 8,
  214.                     WA_Title, "Playing MPEG animation",
  215.                     WA_ScreenTitle, (UBYTE *)"aMiPEG 1.0 by Michael Rausch, Miloslaw Smyk and Tobias Seiler",
  216.                     TAG_DONE))
  217.  
  218.                     return(modeid);
  219.             }
  220.         }
  221.     }
  222.     Quit("aMiPEG: unable to open screen/window...", 25);
  223. }
  224.