home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 113 / EnigmaAmiga113CD.iso / software / sviluppo / quake_src / vid_agaamiga.c < prev    next >
C/C++ Source or Header  |  2000-06-17  |  6KB  |  231 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_AGAamiga.c
  23. **
  24. ** AGA video driver using c2p
  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 <proto/exec.h>
  38. #include <proto/graphics.h>
  39. #include <proto/intuition.h>
  40. #pragma default-align
  41.  
  42. #include "quakedef.h"
  43. #include "amigacompiler.h"
  44.  
  45. #ifdef __PPC__
  46. extern void c2p_8_ppc(UBYTE *,PLANEPTR,UBYTE *,ULONG);
  47. #else
  48. extern void ASM c2p_8_040(REG(a0,UBYTE *),REG(a1,PLANEPTR),REG(a2,UBYTE *),
  49.                           REG(d1,ULONG));
  50. #endif
  51.  
  52.  
  53. extern byte *vid_buffer;
  54. extern unsigned char rawkeyconv[];
  55.  
  56. extern struct GfxBase *GfxBase;
  57. extern struct Screen *QuakeScreen;
  58.  
  59. static struct Window *Window = NULL;
  60. static unsigned short *dummypointer;
  61. static int BytesPerRow;
  62.  
  63. static struct RastPort video_rastport;
  64. static struct BitMap video_bitmap;
  65. static PLANEPTR video_raster = NULL;  /* contiguous bitplanes */
  66. static UBYTE *video_compare_buffer = NULL;
  67.  
  68.  
  69. /* use fixed values for now: NTSC-AGA:320x200 */
  70. static int DispID=0x11000, ScrWidth=320, ScrHeight=200, ScrDepth=8;
  71.  
  72.  
  73.  
  74. void VID_Init_AGA (unsigned char *palette)
  75. {
  76.   char *module = "AGA_Init: ";
  77.   int i;
  78.  
  79.     if (!(GfxBase = (struct GfxBase *) OpenLibrary("graphics.library",36)))
  80.         Sys_Error("%sCan't open graphics.library V36",module);
  81.  
  82.   if ((video_raster = (PLANEPTR)
  83.       AllocRaster (ScrWidth,ScrDepth*ScrHeight)) == NULL)
  84.     Sys_Error("%sAllocRaster() failed",module);
  85.   memset(video_raster,0,ScrDepth*RASSIZE(ScrWidth,ScrHeight));
  86.  
  87.   InitBitMap(&video_bitmap,ScrDepth,ScrWidth,ScrHeight);
  88.   for (i=0; i<ScrDepth; i++)
  89.     video_bitmap.Planes[i] = video_raster + i * RASSIZE(ScrWidth,ScrHeight);
  90.  
  91.   if (!(video_compare_buffer = malloc(ScrWidth*ScrHeight)))
  92.     Sys_Error("%sAllocation of C2P video compare buffer failed",module);
  93.   memset(video_compare_buffer,0,ScrWidth*ScrHeight);
  94.  
  95.   InitRastPort (&video_rastport);
  96.   video_rastport.BitMap = &video_bitmap;
  97.   SetAPen (&video_rastport,(1<<ScrDepth)-1);
  98.   SetBPen (&video_rastport,0);
  99.   SetDrMd (&video_rastport,JAM2);
  100.  
  101.     if (!(QuakeScreen = OpenScreenTags(NULL,
  102.                                      SA_Quiet,TRUE,
  103.                                      SA_Width,ScrWidth,
  104.                                      SA_Height,ScrHeight,
  105.                                      SA_Depth,ScrDepth,
  106.                                      SA_DisplayID,DispID,
  107.                                      SA_BitMap,&video_bitmap,
  108.                                      /* custom bitmap, contiguous planes */
  109.                                      TAG_DONE)))
  110.     Sys_Error("%sCan't open AGA screen",module);
  111.  
  112.     BytesPerRow = ScrWidth/8;
  113.     vid.maxwarpwidth = vid.width = vid.conwidth = ScrWidth;
  114.     vid.maxwarpheight = vid.height = vid.conheight = ScrHeight;
  115.     vid.rowbytes = vid.conrowbytes = ScrWidth;
  116.     vid.aspect = 1.0;
  117.     vid.numpages = 1;
  118.     VID_SetPalette(palette);
  119.  
  120.     if (!(Window = OpenWindowTags(NULL,
  121.                                 WA_Left,0,
  122.                                 WA_Top,0,
  123.                                 WA_Width,ScrWidth,
  124.                                 WA_Height,ScrHeight,
  125.                                 WA_Activate,TRUE,
  126.                                 WA_Borderless,TRUE,
  127.                                 WA_RMBTrap,TRUE,
  128.                                 WA_IDCMP, IDCMP_MOUSEBUTTONS|IDCMP_RAWKEY,
  129.                                 WA_CustomScreen,QuakeScreen,
  130.                                 TAG_DONE,0)))
  131.     Sys_Error("%sCan't open the AGA window",module);
  132.  
  133. #ifdef __PPC__
  134. #ifdef WOS
  135.     if (dummypointer = (unsigned short *)AllocVecPPC(16,MEMF_CLEAR,0))
  136. #else
  137.     if (dummypointer = (unsigned short *)PPCAllocVec(16,MEMF_CLEAR))
  138. #endif
  139. #else
  140.     if (dummypointer = AllocVec(16,MEMF_CLEAR))
  141. #endif
  142.         SetPointer(Window,dummypointer,1,1,0,0);
  143.  
  144.   Con_Printf("graphics.library AGA %d x %d x %d\n",ScrWidth,ScrHeight,8);
  145.   Con_Printf(" %d bpr planar CLUT\n",BytesPerRow);
  146. }
  147.  
  148.  
  149. void VID_SetPalette_AGA (unsigned char *palette)
  150. {
  151.     ULONG rgbtab[3*256+2];
  152.     ULONG *rt = rgbtab;
  153.     ULONG x;
  154.     int i;
  155.  
  156.     *rt++ = 256<<16;
  157.     for (i=0; i<256; i++)
  158.     {
  159.         x = (ULONG)*palette++;
  160.         *rt++ = (x<<24)|(x<<16)|(x<<8)|x;
  161.         x = (ULONG)*palette++;
  162.         *rt++ = (x<<24)|(x<<16)|(x<<8)|x;
  163.         x = (ULONG)*palette++;
  164.         *rt++ = (x<<24)|(x<<16)|(x<<8)|x;
  165.     }
  166.     *rt = 0;
  167.     LoadRGB32(&(QuakeScreen->ViewPort),rgbtab);
  168. }
  169.  
  170.  
  171. void VID_Shutdown_AGA (void)
  172. {
  173.     int i;
  174.  
  175.   if (dummypointer)
  176. #ifdef __PPC__
  177. #ifdef WOS
  178.     FreeVecPPC(dummypointer);
  179. #else
  180.     PPCFreeVec(dummypointer);
  181. #endif
  182. #else
  183.         FreeVec(dummypointer);
  184. #endif
  185.  
  186.   if (Window)
  187.     CloseWindow(Window);
  188.   if (QuakeScreen)
  189.     CloseScreen(QuakeScreen);
  190.   if (video_compare_buffer)
  191.     free(video_compare_buffer);
  192.   if (video_raster)
  193.     FreeRaster(video_raster,ScrWidth,ScrDepth*ScrHeight);
  194.   if (GfxBase)
  195.     CloseLibrary((struct Library *)GfxBase);
  196. }
  197.  
  198.  
  199. void VID_Update_AGA (vrect_t *rects)
  200. {
  201.     int xstop,ystop;
  202.  
  203. #ifdef __PPC__
  204.   c2p_8_ppc(vid_buffer,video_raster,video_compare_buffer,
  205.             (ScrWidth*ScrHeight)>>3);
  206. #else
  207.   c2p_8_040(vid_buffer,video_raster,video_compare_buffer,
  208.             (ScrWidth*ScrHeight)>>3);
  209. #endif
  210. }
  211.  
  212.  
  213. void Sys_SendKeyEvents_AGA (void)
  214. {
  215.   struct IntuiMessage *imsg;
  216.   int kn;
  217.  
  218.   if (Window) {
  219.     while (imsg = (struct IntuiMessage *)GetMsg(Window->UserPort)) {
  220.       if (imsg->Class==IDCMP_RAWKEY || imsg->Class==IDCMP_MOUSEBUTTONS) {
  221.         kn = (int)rawkeyconv[imsg->Code & 0x7f];
  222.         if (imsg->Code & IECODE_UP_PREFIX)
  223.           Key_Event(kn,false);
  224.         else
  225.           Key_Event(kn,true);
  226.       }
  227.       ReplyMsg((struct Message *)imsg);
  228.     }
  229.   }
  230. }
  231.