home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 113 / EnigmaAmiga113CD.iso / software / sviluppo / quake_src / vid_chunkyppcamiga.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-06-17  |  6.6 KB  |  253 lines

  1. #define CallChunkyCopy ms.algo
  2. /* 
  3. Copyright (C) 1996-1997 Id Software, Inc. 
  4.  
  5. This program is free software; you can redistribute it and/or 
  6. modify it under the terms of the GNU General Public License 
  7. as published by the Free Software Foundation; either version 2 
  8. of the License, or (at your option) any later version. 
  9.  
  10. This program is distributed in the hope that it will be useful, 
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of 
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.   
  13.  
  14. See the GNU General Public License for more details. 
  15.  
  16. You should have received a copy of the GNU General Public License 
  17. along with this program; if not, write to the Free Software 
  18. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. 
  19.  
  20. */ 
  21.  
  22. /*
  23. ** vid_ChunkyPPCamiga.c
  24. **
  25. ** chunkyppc.library
  26. **
  27. ** Written by Steffen Häuser <magicSN@BIRDLAND.es.bawue.de>
  28. **
  29. */
  30.  
  31. #pragma amiga-align
  32. #include <exec/libraries.h>
  33. #include <intuition/screens.h>
  34. #include <cybergraphics/cybergraphics.h>
  35. #include <proto/exec.h>
  36. #include <proto/chunkyppc.h>
  37. #pragma default-align
  38.  
  39. #include "quakedef.h"
  40. #include "amigacompiler.h"
  41.  
  42. extern byte *vid_buffer;
  43. extern unsigned char rawkeyconv[];
  44. extern int modearray_x[11];
  45. extern int modearray_y[11];
  46. extern cvar_t vid_mode;
  47. extern int shutdown_keyboard;
  48.  
  49. extern struct Library *ChunkyPPCBase;
  50. extern struct Screen *QuakeScreen;
  51.  
  52. static struct Mode_Screen *mode_screen = NULL;
  53. static struct Mode_Screen ms;
  54.  
  55. #ifdef __PPC__
  56. extern void ChunkyCopyPPC(struct Mode_Screen *,unsigned char *,
  57.                           unsigned char *,int,
  58.                           void *(*)(unsigned char *),unsigned char *);
  59. #else
  60. #ifndef _68881 /* 040/060 only */
  61. extern void ChunkyCopy68k(struct Mode_Screen *,unsigned char *,
  62.                           unsigned char *,int,
  63.                           void *(*)(unsigned char *),unsigned char *);
  64. #endif
  65. #endif
  66.  
  67.  
  68.  
  69. void VID_SetPalette_ChunkyPPC(unsigned char *palette)
  70. {
  71.   ULONG colors[3*256+2];
  72.   ULONG *ptr = colors;
  73.   ULONG x;
  74.   int i;
  75.  
  76.   *ptr++ = 256<<16;
  77.   for (i=0; i<256; i++) {
  78.     x = (ULONG)*palette++;
  79.     *ptr++ = (x<<24)|(x<<16)|(x<<8)|x;
  80.     x = (ULONG)*palette++;
  81.     *ptr++ = (x<<24)|(x<<16)|(x<<8)|x;
  82.     x = (ULONG)*palette++;
  83.     *ptr++ = (x<<24)|(x<<16)|(x<<8)|x;
  84.   }
  85.   *ptr = 0;
  86.   LoadColors(mode_screen,colors);
  87. }
  88.  
  89. void VID_Init_ChunkyPPC(unsigned char *palette)
  90. {
  91.   char *module = "ChunkyPPC_Init: ";
  92.  
  93. #ifdef WOS  /* PowerUp and M68k ports use static CPPC linking */
  94.   if (!(ChunkyPPCBase = OpenLibrary("chunkyppc.library",19)))
  95.     Sys_Error("%sCan't open chunkyppc.library V19",module);
  96. #endif
  97.  
  98.   if (!mode_screen) {
  99.     mode_screen = &ms;
  100.     ms.video_screen = NULL;
  101.     ms.video_window = NULL;
  102.   }
  103.   
  104.   ms.SCREENWIDTH = modearray_x[(int)(vid_mode.value)];
  105.   ms.SCREENHEIGHT = modearray_y[(int)(vid_mode.value)];
  106.   ms.MS_MAXWIDTH = 1600;
  107.   ms.MS_MAXHEIGHT = 1200;
  108.   ms.MINDEPTH = 8;
  109.   ms.MAXDEPTH = 8;
  110.  
  111.   if (!(mode_screen = OpenGraphics("Quake1",&ms,2)))
  112.     Sys_Error("%sCouldn't create window",module);
  113.  
  114. #ifndef __PPC__
  115.   if (!(ChunkyInit68k(&ms,PIXFMT_LUT8)))
  116.     Sys_Error("%sInvalid video format",module);
  117. #else
  118.   if (!(ChunkyInit(&ms,PIXFMT_LUT8)))
  119.     Sys_Error("%sInvalid video format",module);
  120. #endif
  121. #ifndef _68881 /* 040/060/PPC only */
  122.   if ((ms.SCREENWIDTH & 31) == 0) {
  123.     /* 32-byte alignment allows better speed (phx) */
  124.     if (!(ms.video_is_native_mode) && !(ms.wb_int))
  125. #ifndef __PPC__
  126.       ms.algo = (void *)ChunkyCopy68k;
  127. #else
  128.       ms.algo = (void *)ChunkyCopyPPC;
  129. #endif
  130.   }
  131. #endif
  132.  
  133.   vid.width = vid.conwidth = ms.SCREENWIDTH;
  134.   vid.height = vid.conheight = ms.SCREENHEIGHT;
  135.   vid.rowbytes = vid.conrowbytes = ms.bpr;
  136.   vid.aspect = 1.0;
  137.   vid.numpages = 1;
  138.   if (ms.wb_int!=1) {
  139.     if (ms.bpr > ms.SCREENWIDTH) {
  140.       vid.rowbytes = ms.SCREENWIDTH;
  141.       vid.conrowbytes= ms.SCREENWIDTH;
  142.     }
  143.   }
  144.   else {
  145.     if (ms.likecgx) {
  146.       vid.rowbytes = ms.SCREENWIDTH;
  147.       vid.conrowbytes = ms.SCREENWIDTH;
  148.     }
  149.   }
  150.  
  151.   QuakeScreen = ms.video_screen;
  152.   VID_SetPalette(palette);
  153.   Con_Printf("chunkyppc.library %d x %d x %d\n",vid.width,vid.height,8);
  154. }
  155.  
  156.  
  157. void VID_Shutdown_ChunkyPPC(void)
  158. {
  159. #ifdef WOS
  160.   if (ChunkyPPCBase)
  161. #endif
  162.   {
  163.     if (mode_screen)
  164.       CloseGraphics(mode_screen,1);
  165.     mode_screen = NULL;
  166. #ifdef WOS
  167.     CloseLibrary(ChunkyPPCBase);
  168. #endif
  169.     ChunkyPPCBase = NULL;
  170.   }
  171. }
  172.  
  173.  
  174. void VID_Update_ChunkyPPC(vrect_t *rects)
  175. {
  176.   int temp = ms.SCREENHEIGHT;
  177.  
  178.   while (rects) {
  179.     if ((!ms.video_is_native_mode)&&(ms.wb_int)) ms.SCREENHEIGHT = rects->height;
  180.     if (ms.video_is_native_mode) {
  181.       switch (ms.numbuffers) {
  182.         case 1:
  183.           CallChunkyCopy(&ms,(void *)(ms.bitmapa),vid_buffer,PIXFMT_LUT8,0,0);
  184.           break;
  185.         case 2:
  186.           if (ms.bufnum==0)
  187.             CallChunkyCopy(&ms,(void *)(ms.bitmapb),vid_buffer,PIXFMT_LUT8,0,0);
  188.           else
  189.             CallChunkyCopy(&ms,(void *)(ms.bitmapa),vid_buffer,PIXFMT_LUT8,0,0);
  190.           DoubleBuffer(&ms);
  191.           break;
  192.         case 3:
  193.           if (ms.bufnum==0)
  194.             CallChunkyCopy(&ms,(void *)(ms.bitmapb),vid_buffer,PIXFMT_LUT8,0,0);
  195.           else if (ms.bufnum==1)
  196.             CallChunkyCopy(&ms,(void *)(ms.bitmapc),vid_buffer,PIXFMT_LUT8,0,0);
  197.           else
  198.             CallChunkyCopy(&ms,(void *)(ms.bitmapa),vid_buffer,PIXFMT_LUT8,0,0);
  199.           DoubleBuffer(&ms);
  200.           break;
  201.       }
  202.     }
  203.     else {
  204.       switch (ms.numbuffers) {
  205.         case 1:
  206.           CallChunkyCopy(&ms,ms.screen,vid_buffer,PIXFMT_LUT8,0,0);
  207.           break;
  208.         case 2:
  209.           if (ms.bufnum==0)
  210.             CallChunkyCopy(&ms,ms.screenb,vid_buffer,PIXFMT_LUT8,0,0);
  211.           else
  212.             CallChunkyCopy(&ms,ms.screen,vid_buffer,PIXFMT_LUT8,0,0);
  213.                   DoubleBuffer(&ms);
  214.           break;
  215.         case 3:
  216.           if (ms.bufnum==0)
  217.             CallChunkyCopy(&ms,ms.screenb,vid_buffer,PIXFMT_LUT8,0,0);
  218.           else if (ms.bufnum==1)
  219.             CallChunkyCopy(&ms,ms.screenc,vid_buffer,PIXFMT_LUT8,0,0);
  220.           else
  221.             CallChunkyCopy(&ms,ms.screen,vid_buffer,PIXFMT_LUT8,0,0);
  222.           DoubleBuffer(&ms);
  223.           break;
  224.       }
  225.     }
  226.     rects = rects->pnext;
  227.   }
  228.   ms.SCREENHEIGHT = temp;
  229. }
  230.  
  231. void Sys_SendKeyEvents_ChunkyPPC (void)
  232. {
  233.   struct IntuiMessage *imsg;
  234.   int kn;
  235.  
  236.   while (imsg = (struct IntuiMessage *)
  237.          GetMsg((mode_screen->video_window)->UserPort)) {
  238.     if (imsg->Class==IDCMP_RAWKEY || imsg->Class==IDCMP_MOUSEBUTTONS) {
  239.       kn = (int)rawkeyconv[imsg->Code & 0x7f];
  240.       if (imsg->Code & IECODE_UP_PREFIX)
  241.         Key_Event(kn,false);
  242.       else
  243.         Key_Event(kn,true);
  244.         }
  245.     if (shutdown_keyboard) 
  246.     {
  247.       shutdown_keyboard=0;  
  248.       return;
  249.     }
  250.     if (mode_screen->video_window) ReplyMsg((struct Message *)imsg);
  251.     }
  252. }
  253.