home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 113 / EnigmaAmiga113CD.iso / software / sviluppo / quake_src / vid_cppcstatic.c < prev    next >
C/C++ Source or Header  |  2000-06-17  |  48KB  |  1,651 lines

  1. /* 
  2. Copyright (C) 1996-1997 Id Software, Inc. 
  3.  
  4. This program is free software; you can redistribute it and/or 
  5. modify it under the terms of the GNU General Public License 
  6. as published by the Free Software Foundation; either version 2 
  7. of the License, or (at your option) any later version. 
  8.  
  9. This program is distributed in the hope that it will be useful, 
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of 
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.   
  12.  
  13. See the GNU General Public License for more details. 
  14.  
  15. You should have received a copy of the GNU General Public License 
  16. along with this program; if not, write to the Free Software 
  17. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. 
  18.  
  19. */ 
  20.  
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23. #include <string.h>
  24. #include <stdarg.h>
  25.  
  26. #pragma amiga-align
  27. #include <exec/exec.h>
  28. #include <exec/nodes.h>
  29. #include <exec/lists.h>
  30. #include <exec/memory.h>
  31. #include <exec/libraries.h>
  32. #include <dos/stdio.h>
  33. #include <dos/dos.h>
  34. #include <utility/tagitem.h>
  35. #include <graphics/gfx.h>
  36. #include <graphics/gfxbase.h>
  37. #include <graphics/gfxmacros.h>
  38. #include <intuition/intuition.h>
  39. #include <intuition/intuitionbase.h>
  40. #include <libraries/asl.h>
  41. #include <libraries/lowlevel.h>
  42. #include <libraries/Picasso96.h>
  43. #include <cybergraphics/cybergraphics.h>
  44. #include <devices/timer.h>
  45.  
  46. #include <clib/alib_protos.h>
  47. #include <clib/Picasso96_protos.h>
  48. #include <proto/exec.h>
  49. #include <proto/dos.h>
  50. #include <proto/utility.h>
  51. #include <proto/graphics.h>
  52. #include <proto/intuition.h>
  53. #include <proto/cybergraphics.h>
  54. #include <proto/timer.h>
  55. #include <proto/asl.h>
  56. #pragma default-align
  57.  
  58. #include "amigacompiler.h"
  59.  
  60. #if defined(__PPC__) && !defined(WOS)
  61. #define ELF
  62. #endif
  63.  
  64. /* for symbols which are shared between ELF and 68k objects */
  65. #ifdef ELF
  66. #define CNAME(x) _##x
  67. #else
  68. #define CNAME(x) x
  69. #endif
  70.  
  71.  
  72. struct Mode_Screen
  73. {
  74.     struct Screen *video_screen;
  75.     struct Window *video_window;
  76.     int bpr;
  77.     int wb_int;
  78.     int pip_int;
  79.     int dbuf_int;
  80.     int oldstyle_int;
  81.     char pubscreenname[512];
  82.     int mode;
  83.     int SCREENWIDTH;
  84.     int SCREENHEIGHT;
  85.     int MAXWIDTH;
  86.     int MAXHEIGHT;
  87.     int MINDEPTH;
  88.     int MAXDEPTH;
  89.     int format;
  90.     int video_depth;
  91.     UWORD *emptypointer;
  92.     struct BitMap *video_tmp_bm;
  93.     int video_is_native_mode;
  94.     int video_is_cyber_mode;
  95.     unsigned char *screen;
  96.     int video_oscan_height;
  97.     int bufnum;
  98.     struct RastPort *video_rastport;
  99.     struct BitMap *bitmapa;
  100.     struct BitMap *bitmapb;
  101.     struct BitMap *bitmapc;
  102.     struct BitMap *thebitmap;
  103.     struct RastPort *video_temprp;
  104.     struct ScreenModeRequester *video_smr;
  105.     int ham_int;
  106.     UBYTE *wbcolors;
  107.     UBYTE *transtable;
  108.     unsigned long *WBColorTable;
  109.     unsigned long *ColorTable;
  110.     int pal_changed;
  111.     int pen_obtained;
  112.     unsigned char *screenb;
  113.     unsigned char *screenc;
  114.     int numbuffers;
  115.     int rtgm_int;
  116.     struct ScreenBuffer *Buf1;
  117.     struct ScreenBuffer *Buf2;
  118.     struct ScreenBuffer *Buf3;
  119.     void * (*algo)(struct Mode_Screen *ms,unsigned char *dest,
  120.                    unsigned char *src, int srcformat,
  121.                    void *(*hook68k)(unsigned char *data),unsigned char *data);
  122.     void (*Internal1)(void);
  123.     void (*Internal2)(void);
  124.     int onlyptr;
  125.     int likecgx;
  126.     UBYTE *c2p_compare_buffer;  /* AGA c2p extension (phx) */
  127. };
  128.  
  129.  
  130. int CNAME(cppc_minwidth);
  131. int CNAME(cppc_minheight);
  132. int CNAME(cppc_maxwidth);
  133. int CNAME(cppc_maxheight);
  134. int CNAME(cppc_mindepth);
  135. int CNAME(cppc_maxdepth);
  136.  
  137. static int locked=0;
  138. static int lockingmode=1;
  139.  
  140. extern struct ExecBase *SysBase;
  141. extern struct Library *P96Base;
  142. extern struct Library *RtgBase;
  143. extern struct Library *CyberGfxBase;
  144. extern struct Library *AslBase;
  145. extern struct GfxBase *GfxBase;
  146. extern struct IntuitionBase *IntuitionBase;
  147. #ifdef ELF
  148. struct GfxBase *_GfxBase;
  149. #endif
  150.  
  151. /* ASL filter M68k(!) function */
  152. extern ULONG CNAME(filterfunc)();
  153. struct Hook filterfunc_hook = {
  154.   {NULL, NULL}, (void *)&CNAME(filterfunc), NULL, NULL
  155. };
  156.  
  157.  
  158. #ifdef __PPC__
  159. extern void TurboUpdatePPC(unsigned char *,unsigned char *,int,
  160.                            int,int,int,int);
  161. extern void c2p_8_ppc(UBYTE *,PLANEPTR,UBYTE *,ULONG);
  162. #else
  163. #ifndef _68881 /* 040/060 only */
  164. extern void ASM TurboUpdate68k(REG(a0,unsigned char *),
  165.                                REG(a1,unsigned char *), REG(d4,int),
  166.                                REG(d0,int), REG(d1,int),
  167.                                REG(d2,int), REG(d3,int));
  168. #endif
  169. extern void ASM c2p_8_040(REG(a0,UBYTE *),REG(a1,PLANEPTR),REG(a2,UBYTE *),
  170.                           REG(d1,ULONG));
  171. #endif
  172.  
  173.  
  174.  
  175. static void error (char *myerror, struct Mode_Screen *ms, ...)
  176. {
  177.   va_list aptr;
  178.   char text[2048];
  179.   int i,depth;
  180.  
  181.   if (myerror!=0) {
  182.     va_start (aptr, myerror);
  183.     vsprintf (text, myerror, aptr);
  184.     va_end (aptr);
  185.   }
  186.   if (locked) UnlockPubScreen(0,ms->video_screen);
  187.  
  188.   if ((ms->dbuf_int)&&((!ms->oldstyle_int))) {
  189.     if (ms->video_screen) {
  190.       if (ms->Buf1) {
  191.         (((ms->Buf1)->sb_DBufInfo)->dbi_SafeMessage).mn_ReplyPort = NULL;
  192.         while (!ChangeScreenBuffer(ms->video_screen, ms->Buf1));
  193.       }
  194.       if (ms->Buf1) FreeScreenBuffer(ms->video_screen, ms->Buf1);
  195.       if (ms->Buf2) FreeScreenBuffer(ms->video_screen, ms->Buf2);
  196.       if (ms->Buf3) FreeScreenBuffer(ms->video_screen, ms->Buf3);
  197.     }
  198.   }
  199.  
  200.   if (ms->likecgx) {
  201.     FreeScreenBuffer(ms->video_screen,ms->Buf1);
  202.     ms->Buf1=0;
  203.   }
  204.  
  205.   if ((ms->wb_int)&&(!(ms->pip_int))&&(ms->pal_changed)) {
  206.     struct ColorMap *ColorMap=((ms->video_screen)->ViewPort).ColorMap;
  207.  
  208.     for (i=0;i<256;i++) ReleasePen(ColorMap,ms->transtable[i]);
  209.     LoadRGB32(&(((ms->video_window)->WScreen)->ViewPort),ms->WBColorTable);
  210.   }
  211.  
  212.   if (ms->video_window) {
  213.     if (!(ms->pip_int)) CloseWindow(ms->video_window);
  214.     else p96PIP_Close(ms->video_window);
  215.   }
  216.   ms->video_window=0;
  217.  
  218.   if (!ms->wb_int) {
  219.     if (ms->video_screen) CloseScreen(ms->video_screen);
  220.   }
  221.   ms->video_screen=0;
  222.  
  223.   if (ms->emptypointer) FreeVec(ms->emptypointer);
  224.   ms->emptypointer=0;
  225.  
  226.   if (ms->video_depth!=0) {
  227.     if (ms->format==PIXFMT_LUT8) {
  228.       for (depth = 0; depth < ms->video_depth; depth++) {
  229.         if (ms->video_tmp_bm->Planes[depth] != NULL) {
  230. #if 0 /*@@@ ??? Crash on Rearrange? */
  231.           FreeRaster (ms->video_tmp_bm->Planes[depth], ms->SCREENWIDTH, 1);
  232. #endif
  233.           ms->video_tmp_bm->Planes[depth] = NULL;
  234.         }
  235.       }
  236.     }
  237.   }
  238.  
  239.   if (ms->wbcolors) FreeVec(ms->wbcolors);
  240.   if (ms->transtable) FreeVec(ms->transtable);
  241.   if (ms->WBColorTable) FreeVec(ms->WBColorTable);
  242.   if (ms->ColorTable) FreeVec(ms->ColorTable);
  243.   ms->wbcolors=0;
  244.   ms->transtable=0;
  245.   ms->WBColorTable=0;
  246.   ms->ColorTable=0;
  247. }
  248.  
  249.  
  250. static void Rearrange(struct Mode_Screen *ms)
  251. {
  252.   error(0,ms);
  253. }
  254.  
  255.  
  256. static int acceptmode(struct Mode_Screen *ms, int mode)
  257. {
  258.   DisplayInfoHandle handle;
  259.   int nbytes;
  260.   int mydepth;
  261.   struct DimensionInfo dimsinfo;
  262.   int SW,SH;
  263.  
  264.   if ((handle = FindDisplayInfo (mode)) == NULL) {
  265.     error ("Can't FindDisplayInfo() for mode %08x", ms,mode);
  266.     return 0;
  267.   }
  268.  
  269.   if ((nbytes = GetDisplayInfoData (handle, (UBYTE *)&dimsinfo,
  270.                                     sizeof(dimsinfo), DTAG_DIMS,
  271.                                     0)) < 66) {
  272.     error ("Can't GetDisplayInfoData() for mode %08x, got %d bytes",
  273.            ms,mode, nbytes);
  274.     return 0;
  275.   }
  276.   SW = dimsinfo.Nominal.MaxX-dimsinfo.Nominal.MinX+1;
  277.   SH = dimsinfo.Nominal.MaxY-dimsinfo.Nominal.MinY+1;
  278.  
  279.   if (ms->SCREENWIDTH!=SW) return 0;
  280.   if (ms->SCREENHEIGHT!=SH) return 0;
  281.  
  282.   if (CyberGfxBase)
  283.     mydepth=GetCyberIDAttr(CYBRIDATTR_DEPTH,mode);
  284.   else mydepth=16;
  285.  
  286.   if (ms->MINDEPTH>mydepth) return 0;
  287.   if (ms->MAXDEPTH<mydepth) return 0;
  288.  
  289.   return 1;
  290. }
  291.  
  292.  
  293. static int existsmode(char *envvar,char *base,int modeid, int num)
  294. {
  295.   int f;
  296.   int id;
  297.   char temp[1024];
  298.   char temp2[1024];
  299.   char tb[1024];
  300.  
  301.   strcpy(temp,base);
  302.   strcpy(temp2,envvar);
  303.   sprintf(temp,"%s",temp);
  304.  
  305.   if (GetVar(temp,tb,1024,0)!=-1) {
  306.     sprintf(temp2,"%s/modeid",temp2);
  307.     GetVar(temp2,tb,1024,0);
  308.     id=atoi(tb);
  309.     if (id==modeid) return 1;
  310.   }
  311.  
  312.   for (f=1;f<=num;f++) {
  313.     strcpy(temp,base);
  314.     sprintf(temp,"%s%i",temp,f);
  315.     if (GetVar(temp,tb,1024,0)!=-1) {
  316.       strcpy(temp2,envvar);
  317.       sprintf(temp2,"%s/modeid%i",temp2,f);
  318.       GetVar(temp2,tb,1024,0);
  319.       id=atoi(tb);
  320.       if (id==modeid) return 1;
  321.     }
  322.   }
  323.  
  324.   return 0;
  325. }
  326.  
  327.  
  328. static APTR LockBitMapTags68k(struct Mode_Screen *ms, unsigned char **screen)
  329. {
  330.   APTR video_bitmap_handle;
  331.   struct BitMap *bm;
  332.   if (ms->bufnum==2) bm=ms->bitmapa;
  333.   else if (ms->bufnum==0) bm=ms->bitmapb;
  334.   else bm=ms->bitmapc;
  335.   if (ms->oldstyle_int) bm=ms->bitmapa;
  336.   if (ms->numbuffers==1) bm=ms->bitmapa;
  337.   video_bitmap_handle = (APTR)LockBitMapTags (bm,
  338.                                               LBMI_BASEADDRESS, screen,
  339.                                               TAG_DONE);
  340.   return video_bitmap_handle;
  341. }
  342.  
  343.  
  344. static APTR LockBitMapTags68k_b(struct Mode_Screen *ms,unsigned char **screen)
  345. {
  346.   APTR video_bitmap_handle = (APTR)LockBitMapTags (ms->bitmapa,
  347.                                                    LBMI_BASEADDRESS, screen,
  348.                                                    TAG_DONE);
  349.   return video_bitmap_handle;
  350. }
  351.  
  352.  
  353. static void UnLockBitMap68k(APTR lock)
  354. {
  355.   UnLockBitMap(lock);
  356. }
  357.  
  358.  
  359. static void *c2p(struct Mode_Screen *ms,unsigned char *dest,
  360.                  unsigned char *src, int srcformat,
  361.                  void *(*hook68k)(unsigned char *data), unsigned char *data)
  362. {
  363. #ifdef __PPC__
  364.   c2p_8_ppc(src,dest,ms->c2p_compare_buffer,ms->bpr*ms->SCREENHEIGHT);
  365. #else
  366.   c2p_8_040(src,dest,ms->c2p_compare_buffer,ms->bpr*ms->SCREENHEIGHT);
  367. #endif
  368.   return NULL;
  369. }
  370.  
  371.  
  372. static void *Chunky8(struct Mode_Screen *ms,unsigned char *dest,
  373.                      unsigned char *src, int srcformat,
  374.                      void *(*hook68k)(unsigned char *data),
  375.                      unsigned char *data)
  376. {
  377.   unsigned char *screen;
  378.   APTR video_bitmap_handle;
  379.  
  380.   if (lockingmode&&(!(ms->pip_int))) {
  381.     if (ms->video_is_cyber_mode) {
  382.       video_bitmap_handle = (APTR)LockBitMapTags68k (ms,&screen);
  383.       if (ms->oldstyle_int&&(ms->bufnum==0))
  384.         screen+=(ms->bpr*ms->SCREENHEIGHT);
  385.     }
  386.   }
  387.   else
  388.     screen=dest;
  389.  
  390. #ifdef __PPC__
  391.   TurboUpdatePPC(src,screen,ms->bpr,0,0,ms->SCREENWIDTH,ms->SCREENHEIGHT);
  392. #else
  393. #ifdef _68881 /* 030/88x */
  394.   /* sorry, no 030 support yet */
  395. #else /* 040/060 */
  396.   TurboUpdate68k(src,screen,ms->bpr,0,0,ms->SCREENWIDTH,ms->SCREENHEIGHT);
  397. #endif
  398. #endif
  399.  
  400.   if (lockingmode&&(ms->video_is_cyber_mode) && (!(ms->pip_int)))
  401.     UnLockBitMap68k (video_bitmap_handle);
  402.   /* @@@ hook function will never be called! */
  403.   return NULL;
  404. }
  405.  
  406.  
  407. static void *WbChunky8(struct Mode_Screen *ms,unsigned char *dest,
  408.                        unsigned char *src, int srcformat,
  409.                        void *(*hook68k)(unsigned char *d),
  410.                        unsigned char *data)
  411. {
  412.   int f;
  413.  
  414.   for (f=0;f<(ms->SCREENWIDTH*ms->SCREENHEIGHT);f++)
  415.     src[f]=ms->transtable[src[f]];
  416.  
  417.   WritePixelArray8((ms->video_window)->RPort,(ms->video_window)->BorderLeft,
  418.                    (ms->video_window)->BorderTop,
  419.                    (UWORD)((ms->video_window)->BorderLeft+ms->SCREENWIDTH-1),
  420.                    (UWORD)((ms->video_window)->BorderTop+ms->SCREENHEIGHT-1),
  421.                    (UBYTE *)src,ms->video_temprp);
  422.  /* @@@ hook function will never be called! */
  423.   return NULL;
  424. }
  425.  
  426.  
  427. void CloseGraphics (struct Mode_Screen *ms,int shutdownlibs)
  428. {
  429.   if (ms->onlyptr==0) error(0,ms);
  430.   if (ms->video_is_native_mode && ms->c2p_compare_buffer) /* phx */
  431.     free(ms->c2p_compare_buffer);
  432.  
  433.   if (shutdownlibs) {
  434.     if (P96Base) CloseLibrary(P96Base);
  435.     P96Base = NULL;
  436.     if (CyberGfxBase) CloseLibrary(CyberGfxBase);
  437.     CyberGfxBase = NULL;
  438.     if (AslBase) CloseLibrary(AslBase);
  439.     AslBase = NULL;
  440.     if (GfxBase) CloseLibrary((struct Library *)GfxBase);
  441.     GfxBase = NULL;
  442.     if (IntuitionBase) CloseLibrary((struct Library *)IntuitionBase);
  443.     IntuitionBase = NULL;
  444.   }
  445.   memset(ms,0,sizeof(struct Mode_Screen));
  446. }
  447.  
  448.  
  449. struct Mode_Screen *OpenGraphics (char *title,struct Mode_Screen *ms,
  450.                                   int override)
  451. {
  452.   static struct TagItem aslreq[]= {
  453.     ASLSM_TitleText,        0,
  454.     ASLSM_InitialDisplayID, 0,
  455.     ASLSM_MinWidth,         0,
  456.     ASLSM_MinHeight,        0,
  457.     ASLSM_MaxWidth,         1280,
  458.     ASLSM_MaxHeight,        1024,
  459.     ASLSM_MinDepth,         8,
  460.     ASLSM_MaxDepth,         16,
  461.     ASLSM_PropertyMask,     0,
  462.     ASLSM_PropertyFlags,    0,
  463.     ASLSM_FilterFunc,       0,
  464.     0,0
  465.   };
  466.   struct TagItem aslreqtags[]= {
  467.     0,0
  468.   };
  469.   static struct BitMap video_tmp_bm = {
  470.      0, 0, 0, 0, 0, {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}
  471.   };
  472.   static struct RastPort video_rastport[3];
  473.   static struct RastPort video_temprp;
  474.   static void *thehook=(void *)(&filterfunc_hook);
  475.   int i;
  476.   int mode;
  477.   struct ScreenReq *sreq=0;
  478.   APTR video_bitmap_handle;
  479.   int video_depth;
  480.   struct BitMap *bitmap;
  481.   ULONG propertymask, idcmp, wflags, width, pixfmt;
  482.   struct Rectangle rect;
  483.   char reqtitle[256];
  484.   int  depth, nbytes;
  485.   DisplayInfoHandle handle;
  486.   struct DisplayInfo dispinfo;
  487.   struct DimensionInfo dimsinfo;
  488.   int mode_num;
  489.   float resize_int;
  490.   char tb[1024];
  491.   char realid[1024];
  492.   char title2[512];
  493.   char wb[512];
  494.   char pip[512];
  495.   char dbuf[512];
  496.   char modeid3[512];
  497.   char oldstyle[512];
  498.   char psn[512];
  499.   char pubscreenname[512];
  500.   char pipnoclear[512];
  501.   char modeid2[512];
  502.   char ham[512];
  503.   char likecgx[512];
  504.   int likecgx_int=0;
  505.   int wb_int=0;
  506.   int pip_int=0;
  507.   int dbuf_int=0;
  508.   int oldstyle_int=0;
  509.   int pipnoclear_int=0;
  510.   int ham_int=ms->ham_int;
  511.   int reqwidth;
  512.   int reqheight;
  513.   UWORD *emptypointer;
  514.   int SCREENWIDTH=320;
  515.   int SCREENHEIGHT=200;
  516.   int different;
  517.   int bpr;
  518.   struct ScreenModeRequester *video_smr = NULL;
  519.   BOOL video_is_native_mode = FALSE;
  520.   BOOL video_is_cyber_mode = FALSE;
  521.   int mydepth=8;
  522.   int numbuffers=1;
  523.   unsigned char *screen=0;
  524.   unsigned char *screenb=0;
  525.   unsigned char *screenc=0;
  526.   int video_oscan_height;
  527.   int mode2_changed;
  528.   struct Screen *video_screen=ms->video_screen;
  529.   struct Window *video_window=ms->video_window;
  530.   BPTR mylock;
  531.   locked=0;
  532.  
  533.   ms->onlyptr=0;
  534.   if (override==3)
  535.   {
  536.     ms->Internal1=0; /* No input handler support here! */
  537.     ms->Internal2=0; /* Outdated Code */
  538.     ms->onlyptr=1;
  539.     return ms;
  540.   }
  541.  
  542.   sprintf(title2,"%s%s","ENV:",title);
  543.   mylock = Lock(title2,ACCESS_READ);
  544.   if (!mylock) UnLock(CreateDir(title2));
  545.   else UnLock(mylock);
  546.  
  547.   sprintf(title2,"%s%s","ENVARC:",title);
  548.   mylock = Lock(title2,ACCESS_READ);
  549.   if (!mylock) UnLock(CreateDir(title2));
  550.   else UnLock(mylock);
  551.  
  552.   strcpy(title2,title);
  553.  
  554.   if (video_window || video_screen) Rearrange(ms);
  555.   else {
  556.     ms->Buf1=0;
  557.     ms->Buf2=0;
  558.     ms->Buf3=0;
  559.     ms->video_smr=0;
  560.     ms->emptypointer=0;
  561.     ms->video_screen=0;
  562.     ms->video_window=0;
  563.     ms->video_depth=0;
  564.     ms->transtable=0;
  565.     ms->wbcolors=0;
  566.     ms->WBColorTable=0;
  567.     ms->ColorTable=0;
  568.   }
  569.  
  570.   SCREENWIDTH=ms->SCREENWIDTH;
  571.   SCREENHEIGHT=ms->SCREENHEIGHT;
  572.  
  573.   reqwidth=SCREENWIDTH;
  574.   reqheight=SCREENHEIGHT;
  575.   different=0;
  576.  
  577.   ms->Internal1=0; /* No input handler support here! */
  578.   ms->Internal2=0; /* Outdated Code */
  579.  
  580.   if ((AslBase = OpenLibrary ("asl.library", 37L)) != 0) {
  581.     video_smr = (void *)AllocAslRequest(ASL_ScreenModeRequest, aslreqtags);
  582.     ms->video_smr=video_smr;
  583.     if (!video_smr) {
  584.       error ("AllocAslRequest failed!\n",ms);
  585.       return 0;
  586.     }
  587.   }
  588.   else {
  589.     error("asl.library V37 could not be opened\n",ms);
  590.     return(0);
  591.   }
  592.  
  593.   if (GfxBase==0) {
  594.     if ((GfxBase = (struct GfxBase *)
  595.                     OpenLibrary("graphics.library",36)) == 0) {
  596.       error("graphics.library V36 could not be opened\n",ms);
  597.       return(0);
  598.     }
  599. #ifdef ELF
  600.     _GfxBase = GfxBase;  /* to make it visible for the 68k part */
  601. #endif
  602.   }
  603.  
  604.   if (IntuitionBase==0) {
  605.     if ((IntuitionBase = (struct IntuitionBase *)
  606.                           OpenLibrary("intuition.library",36)) == 0) {
  607.       error("intuition.library V36 could not be opened\n",ms);
  608.       return 0;
  609.     }
  610.   }
  611.  
  612.   if (RtgBase=OpenLibrary("Picasso96/rtg.library",0)) {
  613.     CloseLibrary(RtgBase);
  614.     if (P96Base==0)
  615.       P96Base = OpenLibrary("Picasso96API.library",0);
  616.   }
  617.  
  618.   if (CyberGfxBase==0)
  619.     CyberGfxBase = OpenLibrary ("cybergraphics.library", 0);
  620.  
  621.   propertymask =DIPF_IS_DUALPF | DIPF_IS_PF2PRI | DIPF_IS_HAM;
  622.  
  623.   sprintf(reqtitle,title2);
  624.   strcpy(title2,"ENV:");
  625.   strcat(title2,reqtitle);
  626.   strcpy(modeid2,"ENVARC:");
  627.   strcat(modeid2,reqtitle);
  628.   strcpy(modeid3,title2);
  629.   strcpy(wb,title2);
  630.   strcpy(dbuf,title2);
  631.   strcpy(ham,title2);
  632.   strcpy(pip,title2);
  633.   strcpy(oldstyle,title2);
  634.   strcpy(psn,title2);
  635.   strcpy(pipnoclear,title2);
  636.   strcpy(likecgx,title2);
  637.   strcat(likecgx,"/resize");
  638.   strcat(modeid2,"/modeid");
  639.   strcat(ham,"/ham");
  640.   strcat(wb,"/wb");
  641.   strcat(dbuf,"/dbuf");
  642.   strcat(pip,"/pip");
  643.   strcat(oldstyle,"/oldstyle");
  644.   strcat(title2,"/modeid");
  645.   strcat(psn,"/pubscreenname");
  646.   strcat(pipnoclear,"/pipnoclear");
  647.   if (GetVar(dbuf,tb,1024,0)!=-1) {
  648.     dbuf_int=atoi(tb);
  649.   }
  650.   lockingmode=1;
  651.   if (GetVar("env:lockingmode",tb,1024,0)!=-1)
  652.     lockingmode=atoi(tb);
  653.  
  654.   resize_int=1.0;
  655.   if (GetVar(likecgx,tb,1024,0)!=-1)
  656.     resize_int=atof(tb);
  657.   likecgx_int=1;
  658.  
  659.   if (GetVar(ham,tb,1024,0)!=-1)
  660.     ham_int=atoi(tb);
  661.  
  662.   if (GetVar(oldstyle,tb,1024,0)!=-1) {
  663.     oldstyle_int=atoi(tb);
  664.     if (oldstyle_int) dbuf_int=1;
  665.   }
  666.  
  667.   if (GetVar(wb,tb,1024,0)!=-1) {
  668.     wb_int=atoi(tb);
  669.     if (wb_int) dbuf_int=0;
  670.   }
  671.  
  672.   if ((GetVar(pip,tb,1024,0)!=-1)&&(P96Base)) {
  673.     pip_int=atoi(tb);
  674.     if (pip_int) dbuf_int=0;
  675.     if (pip_int) wb_int=1;
  676.   }
  677.  
  678.   if ((GetVar(pipnoclear,tb,1024,0)!=-1)&&(P96Base)) {
  679.     pipnoclear_int=atoi(tb);
  680.     if (pipnoclear_int) pip_int=1;
  681.     if (pipnoclear_int) dbuf_int=0;
  682.     if (pip_int) wb_int=1;
  683.   }
  684.  
  685.   strcpy(pubscreenname,"Workbench");
  686.   if (GetVar(psn,tb,1024,0)!=-1)
  687.     strcpy(pubscreenname,tb);
  688.  
  689.   mode2_changed=0;
  690.   mode_num=-1;
  691.  
  692.   if ((GetVar(title2,tb,1024,0)!=-1)&&(override!=1)) {
  693.     char modeid[512];
  694.     int f=0;
  695.     mode2_changed=2;
  696.     strcpy(modeid,title2);
  697.     mode=atoi(tb);
  698.     if ((!acceptmode(ms,mode))&&(override==2)) {
  699.       mode=0;
  700.       mode2_changed=1;
  701.       while (f<20) {
  702.         int found;
  703.         mode_num=f+1;
  704.         sprintf(realid,"%s%i",modeid,f+1);
  705.         found=GetVar(realid,tb,1024,0);
  706.         mode=0;
  707.         if (found==-1) break;
  708.         mode=atoi(tb);
  709.         if (!acceptmode(ms,mode))
  710.           mode=0;
  711.         else goto found;
  712.         f++;
  713.       }
  714.     }
  715.     if (!mode) goto request;
  716. found:
  717.     mode2_changed=2;
  718.   }
  719.  
  720.   else {
  721.     char help[100];
  722.  
  723. request:   
  724.     sprintf(help," %dx%d",SCREENWIDTH,SCREENHEIGHT);
  725.     strcat(reqtitle, help);
  726.     aslreq[0].ti_Data=(ULONG)reqtitle;
  727.     aslreq[1].ti_Data=mode;
  728.     aslreq[2].ti_Data=ms->SCREENWIDTH;
  729.     aslreq[3].ti_Data=ms->SCREENHEIGHT;
  730.     aslreq[4].ti_Data=ms->MAXWIDTH;
  731.     aslreq[5].ti_Data=ms->MAXHEIGHT;
  732.     aslreq[6].ti_Data=ms->MINDEPTH;
  733.     aslreq[7].ti_Data=ms->MAXDEPTH;
  734.     aslreq[8].ti_Data=propertymask;
  735.     aslreq[10].ti_Data=(ULONG)thehook;
  736.     CNAME(cppc_minwidth)=ms->SCREENWIDTH;
  737.     CNAME(cppc_minheight)=ms->SCREENHEIGHT;
  738.     CNAME(cppc_maxwidth)=ms->MAXWIDTH;
  739.     CNAME(cppc_maxheight)=ms->MAXHEIGHT;
  740.     CNAME(cppc_mindepth)=ms->MINDEPTH;
  741.     CNAME(cppc_maxdepth)=ms->MAXDEPTH;
  742.     if (!AslRequest (video_smr, aslreq)) {
  743.       error ("AslRequest() failed",ms);
  744.       return 0;
  745.     }
  746.     mode = video_smr->sm_DisplayID;
  747.  
  748.     if (mode2_changed==0) {
  749.       char modeid[512];
  750.       FILE *fil;
  751.  
  752.       sprintf(modeid,"%i",mode);
  753.       //SetVar(title2,modeid,1024,0);
  754.       //SetVar(modeid2,modeid,1024,0);
  755.       fil=fopen(title2,"w");
  756.       fprintf(fil,modeid);
  757.       fclose(fil);
  758.       fil=fopen(modeid2,"w");
  759.       fprintf(fil,modeid);
  760.       fclose(fil);
  761.     }
  762.     else if (mode2_changed==1) {
  763.       int num;
  764.       char modeid[512];
  765.       FILE *fil;
  766.  
  767.       if (strcmp(realid,"modeid20")==0) num=20;
  768.       else num=mode_num;
  769.       if (existsmode(modeid3,title2,mode,mode_num)) goto out;
  770.       sprintf(title2,"%s%i",title2,num);
  771.       sprintf(modeid2,"%s%i",modeid2,num);
  772.       sprintf(modeid,"%i",mode);
  773.       //SetVar(title2,modeid,1024,0);
  774.       //SetVar(modeid2,modeid,1024,0);
  775.       fil=fopen(title2,"w");
  776.       fprintf(fil,modeid);
  777.       fclose(fil);
  778.       fil=fopen(modeid2,"w");
  779.       fprintf(fil,modeid);
  780.       fclose(fil);
  781.     }
  782.   }
  783. out:
  784.   ms->ham_int=ham_int;
  785.   ms->wb_int=wb_int;
  786.   ms->pip_int=pip_int;
  787.   ms->dbuf_int=dbuf_int;
  788.   ms->oldstyle_int=oldstyle_int;
  789.   ms->likecgx=likecgx_int;
  790.   if (ms->pip_int) {
  791.     strcpy(ms->pubscreenname,"Workbench");
  792.     strcpy(pubscreenname,ms->pubscreenname);
  793.   }
  794.   else strcpy(ms->pubscreenname,pubscreenname);
  795.   ms->rtgm_int=0;
  796.   ms->mode=mode;
  797.  
  798.   if (wb_int) {
  799.     locked=1;
  800.     video_screen=LockPubScreen(pubscreenname);
  801.   }
  802.   if ((handle = FindDisplayInfo (mode)) == NULL) {
  803.     error ("Can't FindDisplayInfo() for mode %08x", ms,mode);
  804.     return 0;
  805.   }
  806.  
  807.   if ((nbytes = GetDisplayInfoData (handle, (UBYTE *)&dispinfo,
  808.                                     sizeof(struct DisplayInfo), DTAG_DISP,
  809.                                     0)) < 40 ) {
  810.     error ("Can't GetDisplayInfoData() for mode %08x, got %d bytes",
  811.            ms,mode, nbytes);
  812.     return 0;
  813.   }
  814.  
  815.   if ((nbytes = GetDisplayInfoData (handle, (UBYTE *)&dimsinfo,
  816.                                     sizeof(dimsinfo), DTAG_DIMS,
  817.                                     0)) < 66) {
  818.     error ("Can't GetDisplayInfoData() for mode %08x, got %d bytes",
  819.            ms,mode, nbytes);
  820.     return 0;
  821.   }
  822.  
  823.   if ((ms->dbuf_int)&&(ms->oldstyle_int)) numbuffers=2;
  824.   else if (ms->dbuf_int) numbuffers=3;
  825.   else numbuffers=1;
  826.  
  827.   ms->numbuffers=numbuffers; 
  828.   ms->SCREENWIDTH=SCREENWIDTH;
  829.   ms->SCREENHEIGHT=SCREENHEIGHT;
  830.   video_oscan_height = dimsinfo.MaxOScan.MaxY - dimsinfo.MaxOScan.MinY + 1;
  831.   ms->video_oscan_height=video_oscan_height;
  832.   video_is_cyber_mode = 0;
  833.   if (CyberGfxBase != NULL)
  834.     video_is_cyber_mode = IsCyberModeID (mode);
  835.  
  836.   video_is_native_mode = ((GfxBase->LibNode.lib_Version < 39 ||
  837.                           (dispinfo.PropertyFlags & DIPF_IS_EXTRAHALFBRITE) != 0 ||
  838.                           (dispinfo.PropertyFlags & DIPF_IS_AA) != 0 ||
  839.                           (dispinfo.PropertyFlags & DIPF_IS_ECS) != 0 ||
  840.                           (dispinfo.PropertyFlags & DIPF_IS_DBUFFER) != 0) &&
  841.                           !video_is_cyber_mode &&
  842.                           (dispinfo.PropertyFlags & DIPF_IS_FOREIGN) == 0);
  843.  
  844.   if (!video_is_native_mode) {
  845.     ham_int=0;
  846.     ms->ham_int=0;
  847.   }
  848.   else {
  849.     pip_int=0;
  850.     pipnoclear_int=0;
  851.     ms->pip_int=0;
  852.     if (wb_int) {
  853.       video_is_native_mode=0;
  854.       ham_int=0;
  855.       ms->ham_int=0;
  856.     }
  857.   }
  858.   video_depth = 8;
  859.   ms->video_depth=video_depth;
  860.   ms->video_is_cyber_mode=video_is_cyber_mode;
  861.   ms->video_is_native_mode=video_is_native_mode;
  862.   SCREENWIDTH= dimsinfo.Nominal.MaxX-dimsinfo.Nominal.MinX+1;
  863.   SCREENHEIGHT=dimsinfo.Nominal.MaxY-dimsinfo.Nominal.MinY+1;
  864.   if (video_is_cyber_mode) {
  865.     mydepth=GetCyberIDAttr(CYBRIDATTR_DEPTH,mode);
  866.     SCREENWIDTH=GetCyberIDAttr(CYBRIDATTR_WIDTH,mode);
  867.     SCREENHEIGHT=GetCyberIDAttr(CYBRIDATTR_HEIGHT,mode);
  868.   }
  869.   if (!(video_is_native_mode)) {
  870.    if (reqwidth<SCREENWIDTH) {
  871.      SCREENWIDTH=reqwidth;
  872.      SCREENHEIGHT=reqheight;
  873.      different=1;
  874.    }
  875.   }
  876.   ms->SCREENWIDTH=SCREENWIDTH;
  877.   ms->SCREENHEIGHT=SCREENHEIGHT;
  878.   rect.MinX = 0;
  879.   rect.MinY = 0;
  880.   if ((ms->ham_int)&&(ms->video_is_native_mode)) rect.MaxX = 2*SCREENWIDTH-1;
  881.   else rect.MaxX = SCREENWIDTH - 1;
  882.   rect.MaxY = SCREENHEIGHT - 1;
  883.  
  884.   ms->format=-1;
  885.   if (video_is_native_mode) {
  886.     ms->c2p_compare_buffer = malloc(SCREENWIDTH*SCREENHEIGHT); /* phx */
  887.  
  888.     if (!ham_int) ms->format=PIXFMT_LUT8;
  889.     else ms->format=PIXFMT_RGB15;
  890.  
  891.     if (ms->format==PIXFMT_RGB15) {
  892.       for (i = 0; i < numbuffers; i++) {
  893.         InitRastPort (&video_rastport[i]);
  894.       }
  895.       ms->video_rastport=video_rastport;
  896.       if (wb_int) video_screen=IntuitionBase->FirstScreen;
  897.       else {
  898.         if (SCREENWIDTH<640) mode=mode|HIRESHAM_KEY;
  899.         else mode=mode|SUPERHAM_KEY;
  900.         if ((ms->dbuf_int)&&(ms->oldstyle_int)) {
  901.           if ((video_screen = OpenScreenTags (NULL,
  902.                SA_DisplayID,   mode,
  903.                SA_DClip,       (ULONG)&rect,
  904.                SA_Width,       2*SCREENWIDTH,
  905.                SA_Height,      2*SCREENHEIGHT,
  906.                SA_Depth,       8,
  907.                SA_Title,       FALSE,
  908.                SA_Quiet,       TRUE,
  909.                TAG_DONE,       0)) == NULL) {
  910.             error ("OpenScreen() failed",ms);
  911.             return 0;
  912.           }
  913.         }
  914.         else {
  915.           if ((video_screen = OpenScreenTags (NULL,
  916.                SA_DisplayID,   mode,
  917.                SA_DClip,       (ULONG)&rect,
  918.                SA_Width,       2*SCREENWIDTH,
  919.                SA_Height,      SCREENHEIGHT,
  920.                SA_Depth,       8,
  921.                SA_Title,       FALSE,
  922.                SA_Quiet,       TRUE,
  923.                TAG_DONE,       0)) == NULL) {
  924.             error ("OpenScreen() failed",ms);
  925.             return 0;
  926.           }
  927.         }
  928.       }
  929.       ms->video_screen=video_screen;
  930.     }
  931.  
  932.     else {
  933.       for (i = 0; i < numbuffers; i++)
  934.         InitRastPort (&video_rastport[i]);
  935.       ms->video_rastport=video_rastport;
  936.  
  937.       if (wb_int) video_screen=IntuitionBase->FirstScreen;
  938.       else {
  939.         if ((ms->dbuf_int)&&(ms->oldstyle_int)) {
  940.           if ((video_screen = OpenScreenTags (NULL,
  941.                SA_DisplayID,   mode,
  942.                SA_DClip,       (ULONG)&rect,
  943.                SA_Width,       SCREENWIDTH,
  944.                SA_Height,      2*SCREENHEIGHT,
  945.                SA_Depth,       8,
  946.                SA_Title,       FALSE,
  947.                SA_Quiet,       TRUE,
  948.                TAG_DONE,       0)) == NULL) {
  949.             error ("OpenScreen() failed",ms);
  950.             return 0;
  951.           }
  952.         }
  953.         else {
  954.           if ((video_screen = OpenScreenTags (NULL,
  955.                SA_DisplayID,   mode,
  956.                SA_DClip,       (ULONG)&rect,
  957.                SA_Width,       SCREENWIDTH,
  958.                SA_Height,      SCREENHEIGHT,
  959.                SA_Depth,       8,
  960.                SA_Quiet,       TRUE,
  961.                SA_Title,       FALSE,
  962.                TAG_DONE,       0)) == NULL) {
  963.             error ("OpenScreen() failed",ms);
  964.             return 0;
  965.           }
  966.         }
  967.       }
  968.       ms->video_screen=video_screen;
  969.     }
  970.   }
  971.  
  972.   else {
  973.     if (wb_int) video_screen=IntuitionBase->FirstScreen;
  974.     else {
  975.       if ((ms->dbuf_int)&&(ms->oldstyle_int)) {
  976.         if ((video_screen = OpenScreenTags (NULL,
  977.              SA_DisplayID,   mode,
  978.              SA_DClip,       (ULONG)&rect,
  979.              SA_Width,       SCREENWIDTH,
  980.              SA_Height,      2*SCREENHEIGHT,
  981.              SA_Depth,       mydepth,
  982.              SA_Quiet,       TRUE,
  983.              SA_ShowTitle,FALSE,
  984.              SA_Draggable,FALSE,
  985.              TAG_DONE,       0)) == NULL) {
  986.           error ("OpenScreen() failed",ms);
  987.           return 0;
  988.         }
  989.       }
  990.       else {
  991.         if ((video_screen = OpenScreenTags (NULL,
  992.              SA_DisplayID,   mode,
  993.              SA_DClip,       (ULONG)&rect,
  994.              SA_Width,       SCREENWIDTH,
  995.              SA_Height,      SCREENHEIGHT,
  996.              SA_Depth,       mydepth,
  997.              SA_Quiet,       TRUE,
  998.              SA_Title,       FALSE,
  999.              TAG_DONE,       0)) == NULL) {
  1000.           error ("OpenScreen() failed",ms);
  1001.           return 0;
  1002.         }
  1003.       }
  1004.     }
  1005.     ms->video_screen=video_screen;
  1006.   }
  1007.  
  1008.   ms->SCREENWIDTH=SCREENWIDTH;
  1009.   ms->SCREENHEIGHT=SCREENHEIGHT;
  1010.  
  1011.   if (CyberGfxBase&&(video_is_cyber_mode)) {
  1012.     video_bitmap_handle = (APTR)LockBitMapTags (video_screen->ViewPort.RasInfo->BitMap,
  1013.                                                 LBMI_WIDTH,       &width,
  1014.                                                 LBMI_DEPTH,       &depth,
  1015.                                                 LBMI_PIXFMT,      &pixfmt,
  1016.                                                 LBMI_BYTESPERROW, &bpr,
  1017.                                                 LBMI_BASEADDRESS, &screen,
  1018.                                                 TAG_DONE);
  1019.     if (wb_int==0)
  1020.       ms->bpr=bpr;
  1021.     UnLockBitMap (video_bitmap_handle);
  1022.     ms->screen=screen;
  1023.  
  1024.     if (pixfmt==PIXFMT_LUT8) ms->format=PIXFMT_LUT8;
  1025.     else if (pixfmt==PIXFMT_RGB16) ms->format=PIXFMT_RGB16;
  1026.     else if (pixfmt==PIXFMT_BGR16) ms->format=PIXFMT_BGR16;
  1027.     else if (pixfmt==PIXFMT_RGB16PC) ms->format=PIXFMT_RGB16PC;
  1028.     else if (pixfmt==PIXFMT_BGR16PC) ms->format=PIXFMT_BGR16PC;
  1029.     else if (pixfmt==PIXFMT_RGB15) ms->format=PIXFMT_RGB15;
  1030.     else {
  1031.       error("Unsupported Screen format",ms);
  1032.       return 0;
  1033.     }
  1034.     if ((ms->dbuf_int)&&(ms->oldstyle_int)) {
  1035.       screenb=screen+SCREENHEIGHT*(ms->bpr);
  1036.       screenc=0;
  1037.       ms->screenb=screenb;
  1038.       ms->screenc=screenc;
  1039.     }
  1040.     if (wb_int==1) {
  1041.       if (pixfmt==PIXFMT_LUT8) bpr=SCREENWIDTH;
  1042.       else bpr=SCREENWIDTH*2;
  1043.       ms->bpr=bpr;
  1044.     }
  1045.   }
  1046.   if (ms->format==-1) {
  1047.     error("Unsupported Screen format",ms);
  1048.     return 0;
  1049.   }
  1050.  
  1051.   idcmp = IDCMP_RAWKEY;
  1052.   wflags = WFLG_ACTIVATE | WFLG_RMBTRAP | WFLG_NOCAREREFRESH |
  1053.            WFLG_SIMPLE_REFRESH;
  1054.   idcmp |= IDCMP_MOUSEMOVE | IDCMP_DELTAMOVE | IDCMP_MOUSEBUTTONS;
  1055.   wflags |= WFLG_REPORTMOUSE;
  1056.  
  1057.   if (!pip_int) {   
  1058.     if (wb_int) {
  1059.       if ((video_window = OpenWindowTags (NULL,
  1060.           WA_Left,         0,
  1061.           WA_Top,          0,
  1062.           WA_InnerWidth,        SCREENWIDTH,
  1063.           WA_InnerHeight,       SCREENHEIGHT,
  1064.           WA_IDCMP,        idcmp,
  1065.           WA_DragBar, TRUE,
  1066.           WA_RMBTrap, TRUE,
  1067.           WA_DepthGadget,TRUE,
  1068.           WA_Flags,        wflags,
  1069.           WA_CustomScreen, video_screen,
  1070.           WA_PubScreenName,(ULONG)pubscreenname,
  1071.           TAG_DONE)) == NULL) {
  1072.         error ("OpenWindow() failed",ms);
  1073.         return 0;
  1074.       }
  1075.     }
  1076.     else {
  1077.       if ((ms->dbuf_int)&&(ms->oldstyle_int)) {
  1078.         int w;
  1079.         if ((ms->video_is_native_mode)&&(ms->ham_int)) w=2*SCREENWIDTH;
  1080.         else w=SCREENWIDTH;
  1081.         if ((video_window = OpenWindowTags (NULL,
  1082.             WA_Left,         0,
  1083.             WA_Top,          0,
  1084.             WA_Width,        w,
  1085.             WA_Height,       2*SCREENHEIGHT,
  1086.             WA_IDCMP,        idcmp,
  1087.             WA_Flags,        wflags,
  1088.             WA_Borderless,   TRUE,
  1089.             WA_DepthGadget,0,
  1090.             WA_CloseGadget,0,
  1091.             WA_DragBar,0,
  1092.             WA_SizeGadget,0,
  1093.             WA_CustomScreen, video_screen,
  1094.             WA_DepthGadget,TRUE,
  1095.             WA_PubScreenName,(ULONG)pubscreenname,
  1096.             TAG_DONE)) == NULL) {
  1097.           error ("OpenWindow() failed",ms);
  1098.           return 0;
  1099.         }
  1100.       }
  1101.       else {
  1102.         int w;
  1103.         if ((ms->video_is_native_mode)&&(ms->ham_int)) w=2*SCREENWIDTH;
  1104.         else w=SCREENWIDTH;
  1105.         if ((video_window = OpenWindowTags (NULL,
  1106.             WA_Left,         0,
  1107.             WA_Top,          0,
  1108.             WA_InnerWidth,        w,
  1109.             WA_InnerHeight,       SCREENHEIGHT,
  1110.             WA_IDCMP,        idcmp,
  1111.             WA_Flags,        wflags,
  1112.             WA_CustomScreen, video_screen,
  1113.             WA_Borderless,   TRUE,
  1114.             WA_DepthGadget,0,
  1115.             WA_CloseGadget,0,
  1116.             WA_DragBar,0,
  1117.             WA_SizeGadget,0,
  1118.             WA_PubScreenName,(ULONG)pubscreenname,
  1119.             TAG_DONE)) == NULL) {
  1120.           error ("OpenWindow() failed",ms);
  1121.           return 0;
  1122.         }
  1123.       }
  1124.     }   
  1125.   }
  1126.   else {
  1127.     struct TagItem piptags[]= {
  1128.       P96PIP_SourceFormat, 0,
  1129.       P96PIP_SourceWidth, 0,
  1130.       P96PIP_SourceHeight, 0,
  1131.       WA_Title, (ULONG)"PIP",
  1132.       WA_Flags,0,
  1133.       WA_Activate,TRUE,
  1134.       WA_RMBTrap, TRUE,
  1135.       WA_Width, 0,
  1136.       WA_Height, 0,
  1137.       WA_DragBar,TRUE,
  1138.       WA_DepthGadget,TRUE,
  1139.       WA_IDCMP,0,
  1140.       WA_NewLookMenus,TRUE,
  1141.       WA_PubScreenName, 0,
  1142.       P96PIP_AllowCropping,TRUE,
  1143.       TAG_DONE,0
  1144.     };
  1145.     APTR vbhandle;
  1146.     vbhandle = (APTR)LockBitMapTags (video_screen->ViewPort.RasInfo->BitMap,
  1147.                                             LBMI_PIXFMT,      (ULONG)&pixfmt,
  1148.                                             TAG_DONE);
  1149.     UnLockBitMap (vbhandle);
  1150.  
  1151.     piptags[0].ti_Data=(ULONG)RGBFB_CLUT;
  1152.     piptags[1].ti_Data=(ULONG)SCREENWIDTH;
  1153.     piptags[2].ti_Data=(ULONG)SCREENHEIGHT;
  1154.     piptags[4].ti_Data=wflags;
  1155.     piptags[7].ti_Data=SCREENWIDTH;
  1156.     piptags[8].ti_Data=SCREENHEIGHT;
  1157.     piptags[11].ti_Data=idcmp;
  1158.     piptags[13].ti_Data=(ULONG)pubscreenname;   
  1159.     piptags[7].ti_Data=SCREENWIDTH*resize_int;
  1160.     piptags[8].ti_Data=SCREENHEIGHT*resize_int;
  1161.     if (video_screen->Width+20<piptags[7].ti_Data) piptags[7].ti_Data=video_screen->Width;
  1162.     if (video_screen->Height+20<piptags[8].ti_Data) piptags[8].ti_Data=video_screen->Height;
  1163.  
  1164.     ms->format=PIXFMT_LUT8;
  1165.     if (mydepth==8) 
  1166.     {
  1167.      ms->format=PIXFMT_LUT8;
  1168.      pixfmt=PIXFMT_LUT8;
  1169.     }
  1170.     if (pixfmt==PIXFMT_RGB16) 
  1171.     {
  1172.       piptags[0].ti_Data=RGBFB_R5G6B5;
  1173.       ms->format=pixfmt=PIXFMT_RGB16;
  1174.     }
  1175.     else if (pixfmt==PIXFMT_RGB16PC) 
  1176.     {
  1177.       piptags[0].ti_Data=RGBFB_R5G6B5PC;
  1178.       ms->format=pixfmt=PIXFMT_RGB16PC;
  1179.     }
  1180.     else if (pixfmt==PIXFMT_BGR16PC) 
  1181.     {
  1182.       piptags[0].ti_Data=RGBFB_B5G6R5PC;
  1183.       ms->format=pixfmt=PIXFMT_BGR16PC;
  1184.     }
  1185.     else 
  1186.     {
  1187.      piptags[0].ti_Data=RGBFB_CLUT;
  1188.      ms->format=pixfmt=PIXFMT_LUT8;
  1189.     }
  1190.  
  1191.     piptags[13].ti_Data=(ULONG)pubscreenname;
  1192.     video_window = p96PIP_OpenTagList(piptags);
  1193.     if (!(video_window)) {
  1194.       UnlockPubScreen(0,video_screen);
  1195.       strcpy(pubscreenname,"Workbench");
  1196.       video_screen=LockPubScreen(pubscreenname);
  1197.       piptags[13].ti_Data=(ULONG)pubscreenname;
  1198.       video_window = p96PIP_OpenTagList(piptags);
  1199.     }
  1200.     if (video_window) {
  1201.       struct TagItem gtTags[] = { {P96PIP_SourceBitMap,0},{TAG_DONE, 0} };
  1202.       struct RenderInfo renderinfo;
  1203.       LONG lock;
  1204.  
  1205.       gtTags[0].ti_Data = (ULONG)&bitmap;
  1206.       p96PIP_GetTagList(video_window, gtTags);
  1207.       lock = p96LockBitMap(bitmap, (UBYTE *) &renderinfo, sizeof(struct RenderInfo));
  1208.       screen = (unsigned char *) renderinfo.Memory;
  1209.       p96UnlockBitMap(bitmap, lock);
  1210.       bpr=p96GetBitMapAttr(bitmap,P96BMA_BYTESPERROW);
  1211.       ms->bpr=bpr;
  1212.       if (!(pipnoclear_int)) memset(screen,0,SCREENWIDTH*SCREENHEIGHT*p96GetBitMapAttr(bitmap,P96BMA_BYTESPERPIXEL));
  1213.     }
  1214.     else {
  1215.       error("Could not initialize PIP\n",ms,0);
  1216.       return 0;
  1217.     }
  1218.   }
  1219.  
  1220.   ms->video_window=video_window;
  1221.   ms->video_tmp_bm=&video_tmp_bm;
  1222.   if (wb_int) UnlockPubScreen(0,video_screen);
  1223.   locked=0;
  1224.   InitBitMap (&video_tmp_bm, video_depth, SCREENWIDTH, 1);
  1225.   video_temprp=*(video_window->RPort);
  1226.   ms->video_temprp=&video_temprp;
  1227.   for (depth = 0; depth < video_depth; depth++) {
  1228.     video_tmp_bm.Planes[depth]=AllocRaster(SCREENWIDTH,1);
  1229.     if (video_tmp_bm.Planes[depth] == 0) {
  1230.       error ("AllocRaster() failed",ms);
  1231.       return 0;
  1232.     }
  1233.   }
  1234.   video_temprp.Layer = NULL;
  1235.   video_temprp.BitMap = &video_tmp_bm;
  1236.  
  1237.   ms->wbcolors=(UBYTE *)AllocVec(1024,MEMF_FAST|MEMF_CLEAR);
  1238.   if (!(ms->wbcolors)) {
  1239.     error("Out of memory",ms);
  1240.     return 0;
  1241.   }
  1242.   ms->pen_obtained=0;
  1243.   ms->transtable=(UBYTE *)AllocVec(256*sizeof(UBYTE),MEMF_FAST|MEMF_CLEAR);
  1244.   ms->WBColorTable=(unsigned long *)AllocVec(770*sizeof(unsigned long),MEMF_FAST|MEMF_CLEAR);
  1245.   ms->ColorTable=(unsigned long *)AllocVec(770*sizeof(unsigned long),MEMF_FAST|MEMF_CLEAR);
  1246.   if (!(ms->transtable)) {
  1247.     error("Out of memory",ms);
  1248.     return 0;
  1249.   }
  1250.   if (!(ms->WBColorTable)) {
  1251.     error("Out of memory",ms);
  1252.     return 0;
  1253.   }
  1254.   if (!(ms->ColorTable)) {
  1255.     error("Out of memory",ms);
  1256.     return 0;
  1257.   }
  1258.   ms->WBColorTable[0] = 0x01000000;
  1259.   ms->WBColorTable[3*256+1] = 0;
  1260.   GetRGB32(((video_screen)->ViewPort).ColorMap,0,256,ms->WBColorTable+1);
  1261.   ms->pal_changed=0;
  1262.   emptypointer=(UWORD *)AllocVec(sizeof(UWORD)*6,MEMF_CHIP|MEMF_CLEAR);
  1263.  
  1264.   ms->emptypointer=emptypointer;
  1265.   if (!emptypointer) {
  1266.     error("Not enough memory!\n",ms);
  1267.     return 0;
  1268.   }
  1269.   SetPointer (video_window, emptypointer, 1, 16, 0, 0);
  1270.   ms->bufnum=0;
  1271.  
  1272.   if (video_smr) {
  1273.     FreeAslRequest(video_smr);
  1274.     video_smr=0;
  1275.   }
  1276.  
  1277.   if (ms->dbuf_int) {
  1278.     ms->bitmapa=(&((ms->video_screen)->RastPort))->BitMap;
  1279.     if (video_is_native_mode) {
  1280.       if (ham_int) {
  1281.         if (ms->oldstyle_int) {
  1282.           ULONG *ppr;
  1283.  
  1284.           ppr=(ULONG *)(ms->bitmapa)->Planes[6];
  1285.           for (depth=0;depth<((SCREENWIDTH*SCREENHEIGHT)/16);depth++)
  1286.             *ppr++=0xBBBBBBBB;
  1287.           ppr=(ULONG *)(ms->bitmapa)->Planes[7];
  1288.           for (depth=0;depth<((SCREENWIDTH*SCREENHEIGHT)/16);depth++)
  1289.             *ppr++=0xEEEEEEEE;
  1290.           ms->bitmapb=0;
  1291.           ms->bitmapc=0;
  1292.           ms->screen=(ms->bitmapa)->Planes[0];
  1293.           ms->screenb=(ms->screen)+(SCREENWIDTH/4)*SCREENHEIGHT;
  1294.           ms->screenc=0;
  1295.           ms->Buf1=0;
  1296.           ms->Buf2=0;
  1297.           ms->Buf3=0;
  1298.         }
  1299.  
  1300.         else {
  1301.           ULONG *ppr;
  1302.  
  1303.           ms->Buf1 = AllocScreenBuffer(ms->video_screen, NULL, SB_SCREEN_BITMAP);
  1304.           if (!(ms->Buf1)) {
  1305.             error("ScreenBuffer allocation failed",ms);
  1306.             return 0;
  1307.           }
  1308.           ms->Buf2 = AllocScreenBuffer(ms->video_screen, NULL, 0);
  1309.           if (!(ms->Buf2)) {
  1310.             error("ScreenBuffer 2 allocation failed",ms);
  1311.             return 0;
  1312.           }
  1313.           ms->Buf3 = AllocScreenBuffer(ms->video_screen, NULL, 0);
  1314.           if (!(ms->Buf3)) {
  1315.             error("ScreenBuffer 3 allocation failed",ms);
  1316.             return 0;
  1317.           }
  1318.           ms->bitmapa=(ms->Buf1)->sb_BitMap;
  1319.           ms->bitmapb=(ms->Buf2)->sb_BitMap;
  1320.           ms->bitmapc=(ms->Buf3)->sb_BitMap;
  1321.           ms->screen=(ms->bitmapa)->Planes[0];
  1322.           ms->screenb=(ms->bitmapb)->Planes[0];
  1323.           ms->screenc=(ms->bitmapc)->Planes[0];
  1324.           ppr=(ULONG *)(ms->bitmapa)->Planes[6];
  1325.           for (depth=0;depth<((SCREENWIDTH*SCREENHEIGHT)/16);depth++)
  1326.             *ppr++=0xBBBBBBBB;
  1327.           ppr=(ULONG *)(ms->bitmapa)->Planes[7];
  1328.           for (depth=0;depth<((SCREENWIDTH*SCREENHEIGHT)/16);depth++)
  1329.             *ppr++=0xEEEEEEEE;
  1330.  
  1331.           if (numbuffers>1) {
  1332.             ppr=(ULONG *)(ms->bitmapb)->Planes[6];
  1333.             for (depth=0;depth<((SCREENWIDTH*SCREENHEIGHT)/16);depth++)
  1334.               *ppr++=0xBBBBBBBB;
  1335.             ppr=(ULONG *)(ms->bitmapb)->Planes[7];
  1336.             for (depth=0;depth<((SCREENWIDTH*SCREENHEIGHT)/16);depth++)
  1337.               *ppr++=0xEEEEEEEE;
  1338.  
  1339.             if (numbuffers>2) {
  1340.               ppr=(ULONG *)(ms->bitmapc)->Planes[6];
  1341.               for (depth=0;depth<((SCREENWIDTH*SCREENHEIGHT)/16);depth++)
  1342.                 *ppr++=0xBBBBBBBB;
  1343.               ppr=(ULONG *)(ms->bitmapc)->Planes[7];
  1344.               for (depth=0;depth<((SCREENWIDTH*SCREENHEIGHT)/16);depth++)
  1345.                 *ppr++=0xEEEEEEEE;
  1346.             }
  1347.           }
  1348.         }
  1349.       }
  1350.  
  1351.       else {
  1352.         if (ms->oldstyle_int) {
  1353.           ms->Buf1=0;
  1354.           ms->Buf2=0;
  1355.           ms->Buf3=0;
  1356.           ms->bitmapb=0;
  1357.           ms->bitmapc=0;
  1358.           ms->screen=(ms->bitmapa)->Planes[0];
  1359.           ms->screenb=(ms->screen)+(SCREENWIDTH/8)*SCREENHEIGHT;
  1360.           ms->screenc=0;
  1361.         }
  1362.         else {
  1363.           ms->Buf1 = AllocScreenBuffer(ms->video_screen, NULL, SB_SCREEN_BITMAP);
  1364.           if (!(ms->Buf1)) {
  1365.             error("ScreenBuffer allocation failed",ms);
  1366.             return 0;
  1367.           }
  1368.           ms->Buf2 = AllocScreenBuffer(ms->video_screen, NULL, 0);
  1369.           if (!(ms->Buf2)) {
  1370.             error("ScreenBuffer 2 allocation failed",ms);
  1371.             return 0;
  1372.           }
  1373.           ms->Buf3 = AllocScreenBuffer(ms->video_screen, NULL, 0);
  1374.           if (!(ms->Buf3)) {
  1375.             error("ScreenBuffer 3 allocation failed",ms);
  1376.             return 0;
  1377.           }
  1378.           ms->bitmapa=(ms->Buf1)->sb_BitMap;
  1379.           ms->bitmapb=(ms->Buf2)->sb_BitMap;
  1380.           ms->bitmapc=(ms->Buf3)->sb_BitMap;
  1381.           ms->screen=(ms->bitmapa)->Planes[0];
  1382.           ms->screenb=(ms->bitmapb)->Planes[0];
  1383.           ms->screenc=(ms->bitmapc)->Planes[0];
  1384.         }
  1385.       }
  1386.     }
  1387.  
  1388.     else {
  1389.       if (ms->oldstyle_int) {
  1390.         ms->Buf1=0;
  1391.         ms->Buf2=0;
  1392.         ms->Buf3=0;
  1393.         ms->bitmapb=0;
  1394.         ms->bitmapc=0;
  1395.       }
  1396.       else {
  1397.         ms->Buf1 = AllocScreenBuffer(ms->video_screen, NULL, SB_SCREEN_BITMAP);
  1398.         if (!(ms->Buf1)) {
  1399.           error("ScreenBuffer allocation failed",ms);
  1400.           return 0;
  1401.         }
  1402.         ms->Buf2 = AllocScreenBuffer(ms->video_screen, NULL, 0);
  1403.         if (!(ms->Buf2)) {
  1404.           error("ScreenBuffer 2 allocation failed",ms);
  1405.           return 0;
  1406.         }
  1407.         ms->Buf3 = AllocScreenBuffer(ms->video_screen, NULL, 0);
  1408.         if (!(ms->Buf3)) {
  1409.           error("ScreenBuffer 3 allocation failed",ms);
  1410.           return 0;
  1411.         }
  1412.         ms->bitmapa=(ms->Buf1)->sb_BitMap;
  1413.         ms->bitmapb=(ms->Buf2)->sb_BitMap;
  1414.         ms->bitmapc=(ms->Buf3)->sb_BitMap;
  1415.         video_bitmap_handle = (APTR)LockBitMapTags(ms->bitmapb,
  1416.                                                    LBMI_BASEADDRESS, &screenb,
  1417.                                                    TAG_DONE);
  1418.         UnLockBitMap (video_bitmap_handle);
  1419.         video_bitmap_handle = (APTR)LockBitMapTags (ms->bitmapc,
  1420.                                                     LBMI_BASEADDRESS, &screenc,
  1421.                                                     TAG_DONE);
  1422.         UnLockBitMap (video_bitmap_handle);
  1423.         ms->screenb=screenb;
  1424.         ms->screenc=screenc;
  1425.       }
  1426.     }
  1427.  
  1428.     if (ms->oldstyle_int) {
  1429.       video_rastport[0].BitMap = ms->bitmapa;
  1430.       ms->thebitmap=ms->bitmapa;
  1431.       SetAPen (&video_rastport[0], (1 << 8) - 1);
  1432.       SetBPen (&video_rastport[0], 0);
  1433.       SetDrMd (&video_rastport[0], JAM2);
  1434.     }
  1435.     else {
  1436.       video_rastport[0].BitMap = ms->bitmapa;
  1437.       video_rastport[1].BitMap = ms->bitmapb;
  1438.       video_rastport[2].BitMap = ms->bitmapc;
  1439.       ms->thebitmap=ms->bitmapa;
  1440.       for (i=0;i<2;i++) {
  1441.         SetAPen (&video_rastport[i], (1 << 8) - 1);
  1442.         SetBPen (&video_rastport[i], 0);
  1443.         SetDrMd (&video_rastport[i], JAM2);
  1444.       }
  1445.     }
  1446.   }
  1447.  
  1448.   else {
  1449.     ms->bitmapa=((ms->video_window)->RPort)->BitMap;
  1450.     if (video_is_native_mode) {
  1451.       ms->Buf1=0;
  1452.       ms->Buf2=0;
  1453.       ms->Buf3=0;
  1454.       ms->bitmapb=0;
  1455.       ms->bitmapc=0;
  1456.       ms->screen=(ms->bitmapa)->Planes[0];
  1457.       if (ms->ham_int) {
  1458.         ULONG *ppr;
  1459.         ppr=(ULONG *)(ms->bitmapa)->Planes[6];
  1460.         for (depth=0;depth<((SCREENWIDTH*SCREENHEIGHT)/16);depth++)
  1461.           *ppr++=0xBBBBBBBB;
  1462.         ppr=(ULONG *)(ms->bitmapa)->Planes[7];
  1463.         for (depth=0;depth<((SCREENWIDTH*SCREENHEIGHT)/16);depth++)
  1464.           *ppr++=0xEEEEEEEE;
  1465.       }
  1466.     }
  1467.     else {
  1468.       ms->Buf1=0;
  1469.       ms->Buf2=0;
  1470.       ms->Buf3=0;
  1471.       ms->bitmapb=0;
  1472.       ms->bitmapc=0;
  1473.     }
  1474.  
  1475.     video_rastport[0].BitMap = ms->bitmapa;
  1476.     ms->thebitmap=ms->bitmapa;
  1477.     SetAPen (&video_rastport[0], (1 << 8) - 1);
  1478.     SetBPen (&video_rastport[0], 0);
  1479.     SetDrMd (&video_rastport[0], JAM2);
  1480.   }
  1481.   
  1482.   if (ms->pip_int) {
  1483.     struct TagItem gtTags[] = { {P96PIP_SourceBitMap,0},{TAG_DONE, 0} };
  1484.     struct RenderInfo renderinfo;
  1485.     LONG lock;
  1486.  
  1487.     gtTags[0].ti_Data = (ULONG)&bitmap;
  1488.     p96PIP_GetTagList(video_window, gtTags);
  1489.     lock = p96LockBitMap(bitmap, (UBYTE *) &renderinfo, sizeof(struct RenderInfo));
  1490.     screen = (unsigned char *) renderinfo.Memory;
  1491.     p96UnlockBitMap(bitmap, lock);
  1492.     ms->screen=screen;
  1493.     if (!(pipnoclear_int)) memset(screen,0,SCREENWIDTH*SCREENHEIGHT*p96GetBitMapAttr(bitmap,P96BMA_BYTESPERPIXEL));
  1494.   }
  1495.  
  1496.   if (ms->bpr==0) {
  1497.     if (ms->format==PIXFMT_LUT8) ms->bpr=ms->SCREENWIDTH;
  1498.     else ms->bpr=2*(ms->SCREENWIDTH);
  1499.   }
  1500.  
  1501.   if (different&&(ms->video_is_cyber_mode)) {
  1502.     UnLockBitMap(LockBitMapTags (ms->bitmapa,
  1503.                                  LBMI_BYTESPERROW, &bpr,
  1504.                                  TAG_DONE));
  1505.     ms->bpr=bpr;
  1506.   }
  1507.  
  1508.   if (!ms->video_is_cyber_mode) likecgx_int=0;
  1509.   if ((ms->wb_int)&&(!P96Base)) likecgx_int=1;
  1510.   if (ms->pip_int) likecgx_int=0;
  1511.   if (ms->format==PIXFMT_LUT8) likecgx_int=0;
  1512.   if (!(ms->wb_int)) likecgx_int=0;
  1513.   ms->likecgx=likecgx_int;
  1514.  
  1515.   if (likecgx_int) {
  1516.     ms->Buf1 = AllocScreenBuffer(ms->video_screen, NULL, 0);
  1517.     if (!(ms->Buf1)) {
  1518.       error("Back Screen Buffer allocation failed",ms);
  1519.       return 0;
  1520.     }
  1521.     ms->bitmapa=(ms->Buf1)->sb_BitMap;
  1522.     video_bitmap_handle = (APTR)LockBitMapTags (ms->bitmapa,
  1523.                                                 LBMI_BASEADDRESS, &(ms->screen),
  1524.                                                 LBMI_BYTESPERROW,&(ms->bpr),
  1525.                                                 TAG_DONE);
  1526.     UnLockBitMap (video_bitmap_handle);
  1527.   }
  1528.  
  1529.   if (pixfmt==PIXFMT_LUT8) ms->video_depth=8;
  1530.   else if (pixfmt==PIXFMT_RGB16) ms->video_depth=16;
  1531.   else if (pixfmt==PIXFMT_BGR16) ms->video_depth=16;
  1532.   else if (pixfmt==PIXFMT_RGB16PC) ms->video_depth=16;
  1533.   else if (pixfmt==PIXFMT_BGR16PC) ms->video_depth=16;
  1534.   else if (pixfmt==PIXFMT_RGB15) ms->video_depth=15;
  1535.   if ((ms->video_depth==15)&&(ms->video_is_native_mode)) ms->video_depth=16;
  1536.  
  1537.   return(ms);
  1538. }
  1539.  
  1540.  
  1541. void LoadColors(struct Mode_Screen *ms, ULONG Table[])
  1542. {
  1543.   struct TagItem EmptyTags[] = {
  1544.     TAG_DONE,0
  1545.   };
  1546.   int i,r,g,b;
  1547.   struct ViewPort *VPort;
  1548.   struct Window *Window;
  1549.   struct ColorMap *ColorMap;
  1550.  
  1551.   Window=ms->video_window;
  1552.   ColorMap = Window->WScreen->ViewPort.ColorMap;
  1553.   VPort = &Window->WScreen->ViewPort;
  1554.  
  1555.   if ((!(ms->wb_int))||(ms->pip_int)) {
  1556.     LoadRGB32(VPort,Table);
  1557.     return;
  1558.   }
  1559.  
  1560.   if (!(ms->pen_obtained)) {
  1561.     ms->WBColorTable[0] = 0x01000000;
  1562.     ms->WBColorTable[3*256+1] = 0;
  1563.     GetRGB32(ColorMap,0,256,ms->WBColorTable+1);
  1564.     for (i=0;i<(3*256+2);i++)
  1565.       ms->ColorTable[i] = ms->WBColorTable[i];
  1566.     for (i=0; i<256; i++) {
  1567.       r = Table[3*i+1];
  1568.       g = Table[3*i+2];
  1569.       b = Table[3*i+3];
  1570.       r=r&0xFF000000;
  1571.       g=g&0xFF000000;
  1572.       b=b&0xFF000000;
  1573.       ms->transtable[i] = ObtainBestPenA(ColorMap,r,g,b,EmptyTags);
  1574.     }
  1575.   }
  1576.  
  1577.   for (i=0; i<256; i++) {
  1578.           ms->ColorTable[3*ms->transtable[i]+1] = Table[3*i+1];
  1579.           ms->ColorTable[3*ms->transtable[i]+2] = Table[3*i+2];
  1580.           ms->ColorTable[3*ms->transtable[i]+3] = Table[3*i+3];
  1581.   }
  1582.  
  1583.   LoadRGB32(VPort,ms->ColorTable);
  1584.   ms->pen_obtained = TRUE;
  1585.   ms->pal_changed=1;
  1586. }
  1587.  
  1588.  
  1589. void DoubleBufferOld(struct Mode_Screen *ms)
  1590. {
  1591.   struct ViewPort *vp = &((ms->video_screen)->ViewPort);
  1592.   int bufnum=ms->bufnum;
  1593.  
  1594.   if (bufnum == 0) {
  1595.     vp->RasInfo->RyOffset = ms->SCREENHEIGHT;
  1596.     ScrollVPort(vp);
  1597.     WaitBOVP(vp);
  1598.     ms->bufnum = 1-ms->bufnum;
  1599.   }
  1600.   else {
  1601.     vp->RasInfo->RyOffset = 0;
  1602.     ScrollVPort(vp);
  1603.     WaitBOVP(vp);
  1604.     ms->bufnum = 1-ms->bufnum;
  1605.   }
  1606. }
  1607.  
  1608.  
  1609. void DoubleBuffer(struct Mode_Screen *ms)
  1610. {
  1611.   struct ViewPort *vp = &((ms->video_screen)->ViewPort);
  1612.  
  1613.   if (ms->dbuf_int==0) return;
  1614.   if (ms->oldstyle_int) {
  1615.     DoubleBufferOld(ms);
  1616.     return;
  1617.   }
  1618.  
  1619.   if (ms->bufnum == 0) {
  1620.     ms->thebitmap=ms->bitmapb;
  1621.     (ms->Buf2)->sb_DBufInfo->dbi_SafeMessage.mn_ReplyPort = NULL;
  1622.     while (!ChangeScreenBuffer(ms->video_screen, ms->Buf2));
  1623.     ms->bufnum = 1;
  1624.   }
  1625.   else if (ms->bufnum==1) {
  1626.     ms->thebitmap=ms->bitmapc;
  1627.     (ms->Buf3)->sb_DBufInfo->dbi_SafeMessage.mn_ReplyPort = NULL;
  1628.     while (!ChangeScreenBuffer(ms->video_screen, ms->Buf3));
  1629.     ms->bufnum=2;
  1630.   }
  1631.   else {
  1632.     ms->thebitmap=ms->bitmapa;
  1633.     (ms->Buf1)->sb_DBufInfo->dbi_SafeMessage.mn_ReplyPort = NULL;
  1634.     while (!ChangeScreenBuffer(ms->video_screen, ms->Buf1));
  1635.     ms->bufnum=0;
  1636.   }
  1637. }
  1638.  
  1639.  
  1640. #ifdef __PPC__
  1641. int ChunkyInit(struct Mode_Screen *ms,int srcformat)
  1642. #else
  1643. int ChunkyInit68k(struct Mode_Screen *ms,int srcformat)
  1644. #endif
  1645. {
  1646.   if (ms->video_is_native_mode) ms->algo=c2p;
  1647.   if (ms->wb_int) ms->algo=WbChunky8;
  1648.   else ms->algo=Chunky8;
  1649.   return 1;
  1650. }
  1651.