home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 28 / amigaformatcd28.iso / -screenplay- / otherstuff / adoomppc_src / v_video.c < prev    next >
C/C++ Source or Header  |  1998-04-23  |  18KB  |  668 lines

  1. // Emacs style mode select   -*- C++ -*- 
  2. //-----------------------------------------------------------------------------
  3. //
  4. // $Id:$
  5. //
  6. // Copyright (C) 1993-1996 by id Software, Inc.
  7. //
  8. // This source is available for distribution and/or modification
  9. // only under the terms of the DOOM Source Code License as
  10. // published by id Software. All rights reserved.
  11. //
  12. // The source is distributed in the hope that it will be useful,
  13. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. // FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License
  15. // for more details.
  16. //
  17. // $Log:$
  18. //
  19. // DESCRIPTION:
  20. //    Gamma correction LUT stuff.
  21. //    Functions to draw patches (by post) directly to screen.
  22. //    Functions to blit a block to the screen.
  23. //
  24. //-----------------------------------------------------------------------------
  25.  
  26.  
  27. static const char
  28. rcsid[] = "$Id: v_video.c,v 1.5 1997/02/03 22:45:13 b1 Exp $";
  29.  
  30. #include <exec/exec.h>
  31. #include <powerup/clib/ppc_protos.h>
  32. #include <powerup/ppclib/memory.h>
  33.  
  34. #include "i_system.h"
  35. #include "i_video.h"
  36. #include "r_local.h"
  37.  
  38. #include "doomdef.h"
  39. #include "doomstat.h"
  40. #include "doomdata.h"
  41.  
  42. #include "m_bbox.h"
  43. #include "m_swap.h"
  44. #include "m_argv.h"
  45. #include "am_map.h"
  46. #include "r_draw.h"
  47.  
  48. #include "v_video.h"
  49.  
  50. #include "st_stuff.h"
  51.  
  52. // Screen buffer memory
  53. byte *vid_mem;
  54.  
  55. // Each screen is [SCREENWIDTH*SCREENHEIGHT]; 
  56. byte* screens[5];    
  57.  
  58. int dirtybox[4]; 
  59.  
  60.  
  61.  
  62. // Now where did these came from?
  63. byte gammatable[5][256] =
  64. {
  65.     {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,
  66.      17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,
  67.      33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,
  68.      49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,
  69.      65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,
  70.      81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,
  71.      97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,
  72.      113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,
  73.      128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,
  74.      144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,
  75.      160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,
  76.      176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,
  77.      192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,
  78.      208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,
  79.      224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,
  80.      240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255},
  81.  
  82.     {2,4,5,7,8,10,11,12,14,15,16,18,19,20,21,23,24,25,26,27,29,30,31,
  83.      32,33,34,36,37,38,39,40,41,42,44,45,46,47,48,49,50,51,52,54,55,
  84.      56,57,58,59,60,61,62,63,64,65,66,67,69,70,71,72,73,74,75,76,77,
  85.      78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,
  86.      99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,
  87.      115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,129,
  88.      130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,
  89.      146,147,148,148,149,150,151,152,153,154,155,156,157,158,159,160,
  90.      161,162,163,163,164,165,166,167,168,169,170,171,172,173,174,175,
  91.      175,176,177,178,179,180,181,182,183,184,185,186,186,187,188,189,
  92.      190,191,192,193,194,195,196,196,197,198,199,200,201,202,203,204,
  93.      205,205,206,207,208,209,210,211,212,213,214,214,215,216,217,218,
  94.      219,220,221,222,222,223,224,225,226,227,228,229,230,230,231,232,
  95.      233,234,235,236,237,237,238,239,240,241,242,243,244,245,245,246,
  96.      247,248,249,250,251,252,252,253,254,255},
  97.  
  98.     {4,7,9,11,13,15,17,19,21,22,24,26,27,29,30,32,33,35,36,38,39,40,42,
  99.      43,45,46,47,48,50,51,52,54,55,56,57,59,60,61,62,63,65,66,67,68,69,
  100.      70,72,73,74,75,76,77,78,79,80,82,83,84,85,86,87,88,89,90,91,92,93,
  101.      94,95,96,97,98,100,101,102,103,104,105,106,107,108,109,110,111,112,
  102.      113,114,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,
  103.      129,130,131,132,133,133,134,135,136,137,138,139,140,141,142,143,144,
  104.      144,145,146,147,148,149,150,151,152,153,153,154,155,156,157,158,159,
  105.      160,160,161,162,163,164,165,166,166,167,168,169,170,171,172,172,173,
  106.      174,175,176,177,178,178,179,180,181,182,183,183,184,185,186,187,188,
  107.      188,189,190,191,192,193,193,194,195,196,197,197,198,199,200,201,201,
  108.      202,203,204,205,206,206,207,208,209,210,210,211,212,213,213,214,215,
  109.      216,217,217,218,219,220,221,221,222,223,224,224,225,226,227,228,228,
  110.      229,230,231,231,232,233,234,235,235,236,237,238,238,239,240,241,241,
  111.      242,243,244,244,245,246,247,247,248,249,250,251,251,252,253,254,254,
  112.      255},
  113.  
  114.     {8,12,16,19,22,24,27,29,31,34,36,38,40,41,43,45,47,49,50,52,53,55,
  115.      57,58,60,61,63,64,65,67,68,70,71,72,74,75,76,77,79,80,81,82,84,85,
  116.      86,87,88,90,91,92,93,94,95,96,98,99,100,101,102,103,104,105,106,107,
  117.      108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,
  118.      125,126,127,128,129,130,131,132,133,134,135,135,136,137,138,139,140,
  119.      141,142,143,143,144,145,146,147,148,149,150,150,151,152,153,154,155,
  120.      155,156,157,158,159,160,160,161,162,163,164,165,165,166,167,168,169,
  121.      169,170,171,172,173,173,174,175,176,176,177,178,179,180,180,181,182,
  122.      183,183,184,185,186,186,187,188,189,189,190,191,192,192,193,194,195,
  123.      195,196,197,197,198,199,200,200,201,202,202,203,204,205,205,206,207,
  124.      207,208,209,210,210,211,212,212,213,214,214,215,216,216,217,218,219,
  125.      219,220,221,221,222,223,223,224,225,225,226,227,227,228,229,229,230,
  126.      231,231,232,233,233,234,235,235,236,237,237,238,238,239,240,240,241,
  127.      242,242,243,244,244,245,246,246,247,247,248,249,249,250,251,251,252,
  128.      253,253,254,254,255},
  129.  
  130.     {16,23,28,32,36,39,42,45,48,50,53,55,57,60,62,64,66,68,69,71,73,75,76,
  131.      78,80,81,83,84,86,87,89,90,92,93,94,96,97,98,100,101,102,103,105,106,
  132.      107,108,109,110,112,113,114,115,116,117,118,119,120,121,122,123,124,
  133.      125,126,128,128,129,130,131,132,133,134,135,136,137,138,139,140,141,
  134.      142,143,143,144,145,146,147,148,149,150,150,151,152,153,154,155,155,
  135.      156,157,158,159,159,160,161,162,163,163,164,165,166,166,167,168,169,
  136.      169,170,171,172,172,173,174,175,175,176,177,177,178,179,180,180,181,
  137.      182,182,183,184,184,185,186,187,187,188,189,189,190,191,191,192,193,
  138.      193,194,195,195,196,196,197,198,198,199,200,200,201,202,202,203,203,
  139.      204,205,205,206,207,207,208,208,209,210,210,211,211,212,213,213,214,
  140.      214,215,216,216,217,217,218,219,219,220,220,221,221,222,223,223,224,
  141.      224,225,225,226,227,227,228,228,229,229,230,230,231,232,232,233,233,
  142.      234,234,235,235,236,236,237,237,238,239,239,240,240,241,241,242,242,
  143.      243,243,244,244,245,245,246,246,247,247,248,248,249,249,250,250,251,
  144.      251,252,252,253,254,254,255,255}
  145. };
  146.  
  147.  
  148.  
  149. int    usegamma;
  150.              
  151. //
  152. // V_MarkRect 
  153. // 
  154. /*
  155. void
  156. V_MarkRect
  157. ( int        x,
  158.   int        y,
  159.   int        width,
  160.   int        height ) 
  161.     M_AddToBox (dirtybox, x, y); 
  162.     M_AddToBox (dirtybox, x+width-1, y+height-1); 
  163. */
  164.  
  165.  
  166. //
  167. // V_CopyRect 
  168. // 
  169. void
  170. V_CopyRect
  171. ( int        srcx,
  172.   int        srcy,
  173.   int        srcscrn,
  174.   int        width,
  175.   int        height,
  176.   int        destx,
  177.   int        desty,
  178.   int        destscrn ) 
  179.     byte*    src;
  180.     byte*    dest; 
  181.      
  182. #ifdef RANGECHECK 
  183.     if (srcx<0
  184.     ||srcx+width >SCREENWIDTH
  185.     || srcy<0
  186.     || srcy+height>SCREENHEIGHT 
  187.     ||destx<0||destx+width >SCREENWIDTH
  188.     || desty<0
  189.     || desty+height>SCREENHEIGHT 
  190.     || (unsigned)srcscrn>4
  191.     || (unsigned)destscrn>4)
  192.     {
  193.     I_Error ("Bad V_CopyRect");
  194.     }
  195. #endif 
  196.     src = screens[srcscrn]+SCREENWIDTH*srcy+srcx; 
  197.     dest = screens[destscrn]+SCREENWIDTH*desty+destx; 
  198.  
  199.     for ( ; height>0 ; height--) 
  200.     { 
  201.     memcpy (dest, src, width); 
  202.     src += SCREENWIDTH; 
  203.     dest += SCREENWIDTH; 
  204.     } 
  205.  
  206.     if (destscrn == 0)
  207.         I_MarkRect (destx, desty, width, height);
  208.  
  209.  
  210. //
  211. // V_DrawPatch
  212. // Masks a column based masked pic to the screen. 
  213. //
  214. void
  215. V_DrawPatch
  216. ( int        x,
  217.   int        y,
  218.   int        scrn,
  219.   patch_t*    patch ) 
  220.  
  221.     int        count;
  222.     int        col; 
  223.     column_t*    column; 
  224.     byte*    desttop;
  225.     byte*    dest;
  226.     byte*    source; 
  227.     int        w; 
  228.     int        x0;
  229.      
  230.     y -= SWAPSHORT(patch->topoffset); 
  231.     x -= SWAPSHORT(patch->leftoffset); 
  232. #ifdef RANGECHECK 
  233.     if (x<0
  234.     ||x+SWAPSHORT(patch->width) >SCREENWIDTH
  235.     || y<0
  236.     || y+SWAPSHORT(patch->height)>SCREENHEIGHT 
  237.     || (unsigned)scrn>4)
  238.     {
  239.       fprintf( stderr, "Patch at %d,%d exceeds LFB\n", x,y );
  240.       // No I_Error abort - what is up with TNT.WAD?
  241.       fprintf( stderr, "V_DrawPatch: bad patch (ignored)\n");
  242.       return;
  243.     }
  244. #endif 
  245.  
  246.     x0 = x;
  247.     col = 0; 
  248.     desttop = screens[scrn]+y*SCREENWIDTH+x; 
  249.      
  250.     w = SWAPSHORT(patch->width); 
  251.  
  252.     for ( ; col<w ; x++, col++, desttop++)
  253.     { 
  254.     column = (column_t *)((byte *)patch + SWAPLONG(patch->columnofs[col])); 
  255.  
  256.     // step through the posts in a column 
  257.     while (column->topdelta != 0xff ) 
  258.     { 
  259.         source = (byte *)column + 3; 
  260.         dest = desttop + column->topdelta*SCREENWIDTH; 
  261.         count = column->length; 
  262.              
  263.         while (count--) 
  264.         { 
  265.         *dest = *source++; 
  266.         dest += SCREENWIDTH; 
  267.         } 
  268.         column = (column_t *)(  (byte *)column + column->length 
  269.                     + 4 ); 
  270.     } 
  271.     }             
  272.     if (scrn == 0)
  273.     I_MarkRect (x0, y, SWAPSHORT(patch->width), SWAPSHORT(patch->height));
  274.  
  275. //
  276. // V_DrawPatchFlipped 
  277. // Masks a column based masked pic to the screen.
  278. // Flips horizontally, e.g. to mirror face.
  279. //
  280. void
  281. V_DrawPatchFlipped
  282. ( int        x,
  283.   int        y,
  284.   int        scrn,
  285.   patch_t*    patch ) 
  286.  
  287.     int        count;
  288.     int        col; 
  289.     column_t*    column; 
  290.     byte*    desttop;
  291.     byte*    dest;
  292.     byte*    source; 
  293.     int        w; 
  294.     int        x0;
  295.      
  296.     y -= SWAPSHORT(patch->topoffset); 
  297.     x -= SWAPSHORT(patch->leftoffset); 
  298. #ifdef RANGECHECK 
  299.     if (x<0
  300.     ||x+SWAPSHORT(patch->width) >SCREENWIDTH
  301.     || y<0
  302.     || y+SWAPSHORT(patch->height)>SCREENHEIGHT 
  303.     || (unsigned)scrn>4)
  304.     {
  305.       fprintf( stderr, "Patch origin %d,%d exceeds LFB\n", x,y );
  306.       I_Error ("Bad V_DrawPatch in V_DrawPatchFlipped");
  307.     }
  308. #endif 
  309.  
  310.     x0 = x;
  311.     col = 0; 
  312.     desttop = screens[scrn]+y*SCREENWIDTH+x; 
  313.      
  314.     w = SWAPSHORT(patch->width); 
  315.  
  316.     for ( ; col<w ; x++, col++, desttop++) 
  317.     { 
  318.     column = (column_t *)((byte *)patch + SWAPLONG(patch->columnofs[w-1-col])); 
  319.  
  320.     // step through the posts in a column 
  321.     while (column->topdelta != 0xff ) 
  322.     { 
  323.         source = (byte *)column + 3; 
  324.         dest = desttop + column->topdelta*SCREENWIDTH; 
  325.         count = column->length; 
  326.              
  327.         while (count--) 
  328.         { 
  329.         *dest = *source++; 
  330.         dest += SCREENWIDTH; 
  331.         } 
  332.         column = (column_t *)(  (byte *)column + column->length 
  333.                     + 4 ); 
  334.     } 
  335.     }             
  336.     if (scrn == 0)
  337.     I_MarkRect (x0, y, SWAPSHORT(patch->width), SWAPSHORT(patch->height));
  338.  
  339.  
  340.  
  341. //
  342. // V_DrawPatchDirect
  343. // Draws directly to the screen on the pc. 
  344. //
  345. void
  346. V_DrawPatchDirect
  347. ( int        x,
  348.   int        y,
  349.   int        scrn,
  350.   patch_t*    patch ) 
  351. {
  352.     V_DrawPatch (x,y,scrn, patch); 
  353. }
  354.  
  355. void    //stretches bitmap to fill screen
  356. V_DrawPatchInDirect
  357. ( int        x,
  358.   int        y,
  359.   int        scrn,
  360.   patch_t*    patch    )
  361. {
  362.     int        count;
  363.     int        col; 
  364.     column_t*    column; 
  365.     byte*    desttop;
  366.     byte*    dest;
  367.     byte*    source; 
  368.     int        w; 
  369.     int        x0;
  370.  
  371.   int deltax,deltay,deltaxi,deltayi,stretchx,stretchy;
  372.   int srccol,collen;
  373.      
  374.   y -= SWAPSHORT(patch->topoffset); 
  375.   x -= SWAPSHORT(patch->leftoffset); 
  376.  
  377. #ifdef RANGECHECK 
  378.   if (x<0
  379.       ||x+SWAPSHORT(patch->width)>320
  380.       || y<0
  381.       || y+SWAPSHORT(patch->height)>200
  382.       || (unsigned)scrn>4)
  383.     {
  384.     fprintf(    stderr, "Patch at %d,%d exceeds LFB\n", x,y );
  385.     // No I_Error abort - what is up with TNT.WAD?
  386.     fprintf(    stderr, "V_DrawPatch: bad patch (ignored)\n");
  387.     return;
  388.     }
  389. #endif 
  390.  
  391.   deltax=(SCREENWIDTH<<16)/320;
  392.   deltaxi=(320<<16)/SCREENWIDTH;
  393.   deltay=(SCREENHEIGHT<<16)/200;
  394.   deltayi=(200<<16)/SCREENHEIGHT;
  395.   stretchx=(x*deltax)>>16;
  396.   stretchy=(y*deltay)>>16;
  397.  
  398.   x0 = x;
  399.   col = 0;
  400.   desttop = screens[scrn]+stretchy*SCREENWIDTH+stretchx;
  401.      
  402.   w = SWAPSHORT(patch->width)<<16;
  403.  
  404.   for ( ; col < w; x++, col += deltaxi, desttop++) {
  405.     column = (column_t *)((byte *)patch + SWAPLONG(patch->columnofs[col>>16]));
  406.  
  407.     // step through the posts in a column
  408.     while (column->topdelta != 0xff ) {
  409.       source = (byte *)column +    3;
  410.       dest = desttop+((column->topdelta*deltay)>>16)*SCREENWIDTH;
  411.       collen = count = (column->length*deltay)>>16;
  412.       srccol = 0;
  413.       while (count--) {
  414.         *dest = source[srccol>>16];
  415.         dest += SCREENWIDTH;
  416.         srccol += deltayi;
  417.       }
  418.       column = (column_t *)((byte *)column + (column->length)+4);
  419.     }
  420.   }
  421.   if (scrn == 0)
  422.       I_MarkRect (x0, y, SWAPSHORT(patch->width), SWAPSHORT(patch->height)); 
  423. }
  424.  
  425.  
  426. void    //stretches bitmap to fill screen
  427. V_DrawPatchInDirectFlipped
  428. ( int        x,
  429.   int        y,
  430.   int        scrn,
  431.   patch_t*    patch    )
  432.   {
  433.   int        count;
  434.   int        col;
  435.   column_t*    column;
  436.   byte*    desttop;
  437.   byte*    dest;
  438.   byte*    source;
  439.   int        w;
  440.  
  441.   int deltax,deltay,deltaxi,deltayi,stretchx,stretchy;
  442.   int srccol,collen;
  443.      
  444.   y    -=    SWAPSHORT(patch->topoffset);
  445.   x    -=    SWAPSHORT(patch->leftoffset);
  446. #ifdef RANGECHECK
  447.   if (x<0
  448.       ||x+SWAPSHORT(patch->width)    >320
  449.       ||    y<0
  450.       ||    y+SWAPSHORT(patch->height)>200
  451.       ||    (unsigned)scrn>4)
  452.   {
  453.     fprintf(    stderr, "Patch at %d,%d exceeds LFB\n", x,y );
  454.     // No I_Error abort - what is up with TNT.WAD?
  455.     fprintf(    stderr, "V_DrawPatch: bad patch (ignored)\n");
  456.     return;
  457.   }
  458. #endif 
  459.  
  460.   deltax=(SCREENWIDTH<<16)/320;
  461.   deltaxi=(320<<16)/SCREENWIDTH;
  462.   deltay=(SCREENHEIGHT<<16)/200;
  463.   deltayi=(200<<16)/SCREENHEIGHT;
  464.   stretchx=(x*deltax)>>16;
  465.   stretchy=(y*deltay)>>16;
  466.  
  467.   col = 0;
  468.   desttop    = screens[scrn]+stretchy*SCREENWIDTH+stretchx;
  469.  
  470.   w = SWAPSHORT(patch->width)<<16;
  471.  
  472.   for ( ; col < w; x++, col += deltaxi, desttop++) {
  473.     column = (column_t *)((byte *)patch    +
  474.                SWAPLONG(patch->columnofs[SWAPSHORT(patch->width)-1-(col>>16)]));
  475.  
  476.     // step through the posts in a column
  477.     while (column->topdelta != 0xff) {
  478.       source = (byte *)column +    3;
  479.       dest = desttop+((column->topdelta*deltay)>>16)*SCREENWIDTH;
  480.       collen = count = (column->length*deltay)>>16;
  481.       srccol=0;
  482.       while (count--) {
  483.         *dest=source[srccol>>16];
  484.         dest += SCREENWIDTH;
  485.         srccol+=deltayi;
  486.       }
  487.       column = (column_t *)((byte *)column+(column->length)+4);
  488.     }
  489.   }
  490.   if (scrn == 0)
  491.       I_MarkRect (stretchx,stretchy,(SWAPSHORT(patch->width)*deltax)>>16,
  492.                   (SWAPSHORT(patch->height)*deltax)>>16);
  493. }
  494.  
  495.  
  496.  
  497. //
  498. // V_DrawBlock
  499. // Draw a linear block of pixels into the view buffer.
  500. //
  501. void
  502. V_DrawBlock
  503. ( int        x,
  504.   int        y,
  505.   int        scrn,
  506.   int        width,
  507.   int        height,
  508.   byte*        src ) 
  509.     byte*    dest; 
  510.     int        height0;
  511.      
  512. #ifdef RANGECHECK 
  513.     if (x<0
  514.     ||x+width >SCREENWIDTH
  515.     || y<0
  516.     || y+height>SCREENHEIGHT 
  517.     || (unsigned)scrn>4 )
  518.     {
  519.     I_Error ("Bad V_DrawBlock");
  520.     }
  521. #endif 
  522.  
  523.     height0 = height;
  524.     dest = screens[scrn] + y*SCREENWIDTH+x; 
  525.  
  526.     while (height--) 
  527.     { 
  528.     memcpy (dest, src, width); 
  529.     src += width; 
  530.     dest += SCREENWIDTH; 
  531.     } 
  532.     if (scrn == 0)
  533.         I_MarkRect (x, y, width, height0);
  534. }
  535.  
  536.  
  537.  
  538. //
  539. // V_GetBlock
  540. // Gets a linear block of pixels from the view buffer.
  541. //
  542. void
  543. V_GetBlock
  544. ( int        x,
  545.   int        y,
  546.   int        scrn,
  547.   int        width,
  548.   int        height,
  549.   byte*        dest ) 
  550.     byte*    src; 
  551.      
  552. #ifdef RANGECHECK 
  553.     if (x<0
  554.     ||x+width >SCREENWIDTH
  555.     || y<0
  556.     || y+height>SCREENHEIGHT 
  557.     || (unsigned)scrn>4 )
  558.     {
  559.     I_Error ("Bad V_DrawBlock");
  560.     }
  561. #endif 
  562.  
  563.     src = screens[scrn] + y*SCREENWIDTH+x; 
  564.  
  565.     while (height--) 
  566.     { 
  567.     memcpy (dest, src, width); 
  568.     src += SCREENWIDTH; 
  569.     dest += width; 
  570.     } 
  571.  
  572.  
  573. #ifdef GRAFFITI
  574. extern int video_graffiti;
  575. #endif
  576.  
  577.  
  578. //
  579. // V_Init
  580. // 
  581. void V_Init (void) 
  582.     int i;
  583.     int p;
  584.     int vid_flags;
  585.     int vid_size;
  586.  
  587. #ifdef GRAFFITI
  588.     video_graffiti = 0;
  589.     if (M_CheckParm ("-graffitilo")) {
  590.       video_graffiti = 1;
  591.       SCREENWIDTH = 320;
  592.       SCREENHEIGHT = 200;
  593.     } else if (M_CheckParm ("-graffitihi")) {
  594.       video_graffiti = 2;
  595.       SCREENWIDTH = 640;
  596.       SCREENHEIGHT = 400;
  597.     } else {
  598. #endif
  599.  
  600.       p = M_CheckParm ("-width");
  601.       if (p && p < myargc-1)
  602.         SCREENWIDTH = atoi(myargv[p+1]);
  603.       else
  604.         SCREENWIDTH = 320;
  605.  
  606.       p = M_CheckParm ("-height");
  607.       if (p && p < myargc-1)
  608.         SCREENHEIGHT = atoi(myargv[p+1]);
  609.       else
  610.         SCREENHEIGHT = 200;
  611.  
  612. #ifdef GRAFFITI
  613.     }
  614. #endif
  615.  
  616.     printf ("Resolution: %d x %d\n", SCREENWIDTH, SCREENHEIGHT);
  617.  
  618.     if (SCREENWIDTH < 320 || SCREENWIDTH > MAXSCREENWIDTH ||
  619.         SCREENWIDTH % 32 != 0 ||
  620.         SCREENHEIGHT < 200 || SCREENHEIGHT > MAXSCREENHEIGHT)
  621.       I_Error ("Resolution out of range or width is not a multiple of 32");
  622.  
  623.     if ((SCREENHEIGHT*8) == (SCREENWIDTH*5))      // 640x400, 320x200
  624.       weirdaspect = 1;
  625.     else if ((SCREENHEIGHT*4) == (SCREENWIDTH*3)) // 640x480, 320x240
  626.       weirdaspect = 0;
  627.     else {
  628.       weirdaspect = 0;
  629.       printf("Warning: Bad aspect ratio, things might look screwy\n");
  630.     }
  631.  
  632.  
  633.     //allocate all the res-dependant vars
  634.     resinit_r_plane ();
  635.     resinit_am_map ();
  636.     resinit_r_draw ();
  637.     xtoviewangle = (angle_t *)I_calloc (SCREENWIDTH+1, sizeof(angle_t));
  638.     negonearray = (short *)I_calloc (SCREENWIDTH, sizeof(short));
  639.     screenheightarray = (short *)I_calloc (SCREENWIDTH, sizeof(short));
  640.  
  641.     // stick these in low dos memory on PCs
  642.  
  643.     vid_flags = MEMF_FAST+MEMF_PUBLIC;
  644.     if (M_CheckParm ("-mmu"))
  645.       vid_flags += MEMF_NOCACHESYNCPPC+MEMF_NOCACHESYNCM68K;
  646.     vid_size = SCREENWIDTH*SCREENHEIGHT*4+SCREENWIDTH*ST_HEIGHT;
  647.     vid_mem = PPCAllocVec (vid_size, vid_flags);
  648.     if (vid_mem == NULL)
  649.       I_Error ("Couldn't allocate memory for screens\n");
  650.     printf ("Screen memory located at $%08x\n", vid_mem);
  651.  
  652.     for (i=0 ; i<4 ; i++)
  653.     screens[i] = vid_mem + i*SCREENWIDTH*SCREENHEIGHT;
  654.     screens[4] = vid_mem + SCREENWIDTH*SCREENHEIGHT*4;
  655. }
  656.