home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 113 / EnigmaAmiga113CD.iso / software / sviluppo / quakeworld_src / client / vid_cgfxamiga.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-06-17  |  7.0 KB  |  247 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. /*
  22. ** vid_CGFXamiga.c
  23. **
  24. ** cybergraphics.library
  25. **
  26. ** Written by Frank Wille <frank@phoenix.owl.de>
  27. **
  28. */
  29.  
  30. #pragma amiga-align
  31. #include <exec/types.h>
  32. #include <exec/libraries.h>
  33. #include <exec/memory.h>
  34. #include <graphics/gfx.h>
  35. #include <graphics/gfxbase.h>
  36. #include <intuition/intuition.h>
  37. #include <cybergraphics/cybergraphics.h>
  38. #include <proto/exec.h>
  39. #include <proto/graphics.h>
  40. #include <proto/intuition.h>
  41. #include <proto/cybergraphics.h>
  42. #pragma default-align
  43.  
  44. #include "quakedef.h"
  45. #include "amigacompiler.h"
  46.  
  47. extern byte *vid_buffer;
  48. extern unsigned char rawkeyconv[];
  49.  
  50. extern struct GfxBase *GfxBase;
  51. extern struct Library *CyberGfxBase;
  52. extern struct Screen *QuakeScreen;
  53.  
  54. static struct Window *Window = NULL;
  55. static struct RastPort TempRP;
  56. static unsigned short *dummypointer;
  57. static int BytesPerRow;
  58. static byte *GfxAddr;
  59. static int turbogfx=TRUE;
  60.  
  61. #ifdef __PPC__
  62. extern void TurboUpdatePPC(byte *vid_buffer,byte *GfxAddr,int BytesPerRow,
  63.                            int x,int y,int width,int height);
  64. #else
  65. #ifndef _68881 /* 040/060 only */
  66. extern void ASM TurboUpdate68k(REG(a0,byte *) vid_buffer,
  67.                                REG(a1,byte *) GfxAddr,
  68.                                REG(d4,int) BytesPerRow,
  69.                                REG(d0,int) x, REG(d1,int) y,
  70.                                REG(d2,int) width, REG(d3,int) height);
  71. #endif
  72. #endif
  73.  
  74.  
  75. void VID_SetPalette_CGFX (unsigned char *palette)
  76. {
  77.   ULONG rgbtab[3*256+2];
  78.   ULONG *rt = rgbtab;
  79.   ULONG x;
  80.   int i;
  81.  
  82.   *rt++ = 256<<16;
  83.   for (i=0; i<256; i++) {
  84.     x = (ULONG)*palette++;
  85.     *rt++ = (x<<24)|(x<<16)|(x<<8)|x;
  86.     x = (ULONG)*palette++;
  87.     *rt++ = (x<<24)|(x<<16)|(x<<8)|x;
  88.     x = (ULONG)*palette++;
  89.     *rt++ = (x<<24)|(x<<16)|(x<<8)|x;
  90.   }
  91.   *rt = 0;
  92.   LoadRGB32(&(QuakeScreen->ViewPort),rgbtab);
  93. }
  94.  
  95.  
  96. void VID_Init_CGFX (unsigned char *palette)
  97. {
  98.   char *module = "CGfx_Init: ";
  99.   int DispID, ScrWidth, ScrHeight, i;
  100.   static const short ColorModel[] = {PIXFMT_LUT8,-1};
  101.   struct TagItem CyberModeTags[] =
  102.   {
  103.     CYBRMREQ_CModelArray,(ULONG)ColorModel,
  104.     TAG_DONE,0
  105.   };
  106.  
  107. #ifndef _68881 /* 040/060/PPC only */
  108.   if (COM_CheckParm("-forcewpa8"))
  109.     turbogfx = FALSE;
  110. #endif
  111.   if (!(GfxBase = (struct GfxBase *) OpenLibrary("graphics.library",36)))
  112.     Sys_Error("%sCan't open graphics.library V36",module);
  113.   if (!(CyberGfxBase = (struct Library *)
  114.       OpenLibrary("cybergraphics.library",0)))
  115.     Sys_Error("%sCan't open cybergraphics.library",module);
  116.   if (!(DispID = CModeRequestTagList(NULL,CyberModeTags)))
  117.     Sys_Error("%sCan't open the screenmode requester",module);
  118.   if (DispID==-1)
  119.     Sys_Error("%sScreenmode requester aborted",module);
  120.  
  121.   ScrWidth = GetCyberIDAttr(CYBRIDATTR_WIDTH,DispID);
  122.   ScrHeight = GetCyberIDAttr(CYBRIDATTR_HEIGHT,DispID);
  123.   if (!(QuakeScreen = OpenScreenTags(NULL,
  124.                                      SA_Quiet,TRUE,
  125.                                      SA_Width,ScrWidth,
  126.                                      SA_Height,ScrHeight,
  127.                                      SA_Depth,8,
  128.                                      SA_DisplayID,DispID,
  129.                                      TAG_DONE)))
  130.     Sys_Error("%sCan't open the screen",module);
  131.   BytesPerRow = GetCyberMapAttr(QuakeScreen->RastPort.BitMap,CYBRMATTR_XMOD);
  132.   GfxAddr = (byte *)GetCyberMapAttr(QuakeScreen->RastPort.BitMap,CYBRMATTR_DISPADR);
  133.   vid.maxwarpwidth = vid.width = vid.conwidth = ScrWidth;
  134.   vid.maxwarpheight = vid.height = vid.conheight = ScrHeight;
  135.   vid.rowbytes = vid.conrowbytes = ScrWidth;
  136.   vid.aspect = 1.0;
  137.   vid.numpages = 1;
  138.   VID_SetPalette(palette);
  139.  
  140.   if (!(Window = OpenWindowTags(NULL,
  141.               WA_Left,0,
  142.               WA_Top,0,
  143.               WA_Width,ScrWidth,
  144.               WA_Height,ScrHeight,
  145.               WA_Activate,TRUE,
  146.               WA_Borderless,TRUE,
  147.               WA_RMBTrap,TRUE,
  148.               WA_IDCMP, IDCMP_MOUSEBUTTONS|IDCMP_RAWKEY,
  149.               WA_CustomScreen,QuakeScreen,
  150.               TAG_DONE,0)))
  151.     Sys_Error("%sCan't open the window",module);
  152.  
  153.   if (dummypointer = AllocVec(16,MEMF_CLEAR))
  154.     SetPointer(Window,dummypointer,1,1,0,0);
  155.   InitRastPort(&TempRP);
  156.   if ((GfxBase->LibNode.lib_Version)>=39)
  157.     if (!(TempRP.BitMap = AllocBitMap(ScrWidth,1,8,BMF_MINPLANES,
  158.               QuakeScreen->RastPort.BitMap)))
  159.       Sys_Error("%sCan't allocate temporary bitmap",module);
  160.   else
  161.   {
  162.     InitBitMap(TempRP.BitMap,8,ScrWidth,1);
  163.     for (i=0;i<8;i++)
  164.         if (!(TempRP.BitMap->Planes[i]=AllocRaster(ScrWidth,1)))
  165.       Sys_Error("%sCan't allocate temporary bitmap",module);
  166.   }
  167.   Con_Printf("cybergraphics.library %d x %d x %d\n",ScrWidth,ScrHeight,8);
  168.   Con_Printf(" %dbpr chunky CLUT\n",BytesPerRow);
  169. }
  170.  
  171.  
  172. void VID_Shutdown_CGFX (void)
  173. {
  174.   int i;
  175.  
  176.   if ((GfxBase->LibNode.lib_Version)>=39) {
  177.     if (TempRP.BitMap)
  178.       FreeBitMap(TempRP.BitMap);
  179.   }
  180.   else {
  181.     for (i=0;i<8;i++)
  182.       if (TempRP.BitMap->Planes[i])
  183.         FreeRaster(TempRP.BitMap->Planes[i],vid.width,1);
  184.   }
  185.   if (dummypointer)
  186.     FreeVec(dummypointer);
  187.   if (Window)
  188.     CloseWindow(Window);
  189.   if (QuakeScreen)
  190.     CloseScreen(QuakeScreen);
  191.   if (CyberGfxBase)
  192.     CloseLibrary((struct Library *)CyberGfxBase);
  193.   if (GfxBase)
  194.     CloseLibrary((struct Library *)GfxBase);
  195. }
  196.  
  197.  
  198. void VID_Update_CGFX (vrect_t *rects)
  199. {
  200.   int xstop,ystop;
  201.  
  202.   while (rects) {
  203.     xstop = rects->x+rects->width-1;
  204.     ystop = rects->y+rects->height-1;
  205.  
  206. #ifdef _68881 /* 030/88x */
  207.     WritePixelArray8(&(QuakeScreen->RastPort),rects->x,rects->y,
  208.                      xstop,ystop,vid_buffer,&TempRP);
  209.  
  210. #else
  211.     if (!turbogfx)
  212.       WritePixelArray8(&(QuakeScreen->RastPort),rects->x,rects->y,
  213.                        xstop,ystop,vid_buffer,&TempRP);
  214.     else
  215. #ifdef __PPC__
  216.       TurboUpdatePPC(vid_buffer,GfxAddr,BytesPerRow,
  217.                      rects->x,rects->y,rects->width,rects->height);
  218. #else
  219.       TurboUpdate68k(vid_buffer,GfxAddr,BytesPerRow,
  220.                      rects->x,rects->y,rects->width,rects->height);
  221. #endif
  222. #endif
  223.  
  224.     rects = rects->pnext;
  225.   }
  226. }
  227.  
  228.  
  229. void Sys_SendKeyEvents_CGFX (void)
  230. {
  231.   struct IntuiMessage *imsg;
  232.   int kn;
  233.  
  234.   if (Window) {
  235.     while (imsg = (struct IntuiMessage *)GetMsg(Window->UserPort)) {
  236.       if (imsg->Class==IDCMP_RAWKEY || imsg->Class==IDCMP_MOUSEBUTTONS) {
  237.         kn = (int)rawkeyconv[imsg->Code & 0x7f];
  238.         if (imsg->Code & IECODE_UP_PREFIX)
  239.           Key_Event(kn,false);
  240.         else
  241.           Key_Event(kn,true);
  242.       }
  243.       ReplyMsg((struct Message *)imsg);
  244.     }
  245.   }
  246. }
  247.