home *** CD-ROM | disk | FTP | other *** search
/ ST-Computer Leser-CD 2000 January / LCD_01_2000.iso / games / doom / pmdoom / src / video / vdi.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-12-17  |  7.9 KB  |  344 lines

  1. /*
  2.  *    VDI functions
  3.  *
  4.  *    Johan Klockars
  5.  *    Xavier Joubert
  6.  *    Patrice Mandin
  7.  */
  8.  
  9. #include <osbind.h>
  10. #include <gemdefs.h>
  11. #include <vdibind.h>
  12. #include <aesbind.h>
  13. #include <common.h>
  14.  
  15. #include "doomdef.h"
  16. #include "doomstat.h"
  17. #include "v_video.h"
  18. #include "m_argv.h"
  19.  
  20. #include "r_draw.h"
  21. #include "am_map.h"
  22. #include "f_wipe.h"
  23. #include "f_finale.h"
  24.  
  25. #include "i_zoom.h"
  26. #include "i_system.h"
  27. #include "i_video.h"
  28. #include "video/vdi.h"
  29.  
  30. extern byte     *orig_colormaps;
  31.  
  32. static int      ap_id=-1;
  33. static int      vdi_handle=0;
  34. static void     *buffer;
  35. static MFDB     src_mfdb, dst_mfdb;
  36. static int      blit_coords[8];
  37. static int        screen_pxy[4];
  38. static int        old_pal[256*3];
  39. static unsigned char    vdi_index[256] = {0, 2, 3, 6, 4, 7, 5, 8, 9, 10, 11, 14, 12, 15, 13, 255, 0};
  40.  
  41. int VideoInited_vdi=0;
  42.  
  43. void I_VidInit_vdi(void)
  44. {
  45.     int bufwidth, bufheight;
  46.     int i,vdipixelsize;
  47.     int work_in[12], work_out[57], dummy;
  48.     int AllocFastRam; /* Alloc preferrably from Fast Ram */
  49.     int rgb[3];
  50.     int screensize;
  51.  
  52.     _global[0] = 0;
  53.     ap_id = appl_init();
  54.  
  55.     work_in[0]=Getrez()+2;
  56.     for(i = 1; i < 10; i++)
  57.         work_in[i] = 1;
  58.     work_in[10] = 2;
  59.  
  60.     vdi_handle = graf_handle(&dummy, &dummy, &dummy, &dummy);
  61.     v_opnvwk(work_in, &vdi_handle, work_out);
  62.  
  63.     if(vdi_handle==0)
  64.         I_Error("Error initializing VDI\n");
  65.  
  66.     videowidth = work_out[0] + 1;
  67.     videoheight = work_out[1] + 1;
  68.     vq_extnd(vdi_handle, 1, work_out);
  69.     bpp = work_out[4];
  70.  
  71.     /* --- Allocate screens */
  72.  
  73.     if ((videowidth<SCREENWIDTH) || (videoheight<SCREENHEIGHT))
  74.         zoomscreen=true;
  75.  
  76.     switch(bpp)
  77.     {
  78.         case 8 :
  79.             vdipixelsize=1;
  80.             break;
  81.         case 15 :
  82.         case 16 :
  83.             vdipixelsize=2;
  84.             break;
  85.         case 24 :
  86.             vdipixelsize=3;
  87.             break;
  88.         case 32 :
  89.             vdipixelsize=4;
  90.             break;
  91.         default :
  92.             vdipixelsize=0;
  93.             break;
  94.     }
  95.  
  96.     if (vdipixelsize==0)
  97.         I_Error("You need a 8, 15, 16, 24 or 32 bits display!\n");
  98.  
  99.     /* Zoom screen ? */
  100.  
  101.     bufwidth=SCREENWIDTH;
  102.     bufheight=SCREENHEIGHT;
  103.     if (zoomscreen)
  104.     {
  105.         bufwidth = videowidth;
  106.         bufheight= videoheight;
  107.     }
  108.  
  109.     /* Allocate buffer */
  110.  
  111.     screensize=bufwidth * bufheight * vdipixelsize;
  112.  
  113.     AllocFastRam=3;        /* Alloc from Fast Ram */
  114.     if (M_CheckParm("-nofastblit"))
  115.         AllocFastRam=0;    /* Alloc from normal Ram */
  116.  
  117.     buffer = (void *)Mxalloc(screensize, AllocFastRam);
  118.     if (!buffer)
  119.         I_Error("Not enough memory for draw buffer!\n");
  120.  
  121.     /* screens[1] = screens[0] = buffer; */
  122.  
  123.     memset(buffer, 0,screensize);
  124.  
  125.     dst_mfdb.fd_addr = 0;
  126.  
  127.     src_mfdb.fd_addr = (long)buffer;
  128.     src_mfdb.fd_w = bufwidth;
  129.     src_mfdb.fd_h = bufheight;
  130.     src_mfdb.fd_wdwidth = bufwidth / 16;
  131.     src_mfdb.fd_stand = 0;
  132.     src_mfdb.fd_nplanes = bpp;
  133.  
  134.     blit_coords[0] = 0;
  135.     blit_coords[1] = 0;
  136.     blit_coords[2] = bufwidth - 1;
  137.     blit_coords[3] = bufheight - 1;
  138.     blit_coords[4] = (videowidth - bufwidth) / 2;
  139.     blit_coords[5] = (videoheight - bufheight) / 2;
  140.     blit_coords[6] = blit_coords[4] + bufwidth - 1;
  141.     blit_coords[7] = blit_coords[5] + bufheight - 1;
  142.  
  143.     screen_pxy[0]=0;
  144.     screen_pxy[1]=0;
  145.     screen_pxy[2]=videowidth-1;
  146.     screen_pxy[3]=videoheight-1;
  147.  
  148.     /* XJ: Save old palette */
  149.     for(i = 0; i < 256; i++)
  150.     {
  151.         vq_color(vdi_handle, i, 0, rgb);
  152.         old_pal[i*3+0] = rgb[0];
  153.         old_pal[i*3+1] = rgb[1];
  154.         old_pal[i*3+2] = rgb[2];
  155.     }
  156.     VideoInited_vdi=1;
  157. }
  158.  
  159. void I_ShutdownGraphics_vdi(void)
  160. {    
  161.     int i,rgb[3];
  162.     
  163.     /* XJ: Old palette */
  164.     if(VideoInited_vdi)
  165.         for(i = 0; i < 256; i++)
  166.         {
  167.             rgb[0] = old_pal[i*3+0];
  168.             rgb[1] = old_pal[i*3+1];
  169.             rgb[2] = old_pal[i*3+2];
  170.             vs_color(vdi_handle, i, rgb);
  171.         }
  172.  
  173.     if(vdi_handle)
  174.         v_clsvwk(vdi_handle);
  175.     appl_exit();
  176.  
  177.     Mfree(buffer);
  178. }
  179.  
  180. void I_VidUpdate_vdi(void)
  181. {
  182.     if (zoomscreen)
  183.     {
  184.         I_Zoom(screens[0],src_mfdb.fd_addr);
  185.     }
  186.  
  187.     vro_cpyfm(vdi_handle, 3, blit_coords, &src_mfdb, &dst_mfdb);
  188. }
  189.  
  190. /*  */
  191. /*  I_SetPalette */
  192. /*  */
  193. void I_SetPalette256_vdi(byte *palette)
  194. {
  195.     int i,rgb[3];
  196.  
  197.     if (!vdi_index[16])
  198.     {
  199.         for(i = 16; i < 255; i++)
  200.             vdi_index[i] = i;
  201.         vdi_index[255] = 1;
  202.     }
  203.  
  204.     for(i = 0; i < 256; i++)
  205.     {
  206.         int r, g, b;
  207.  
  208.         r = gammatable[usegamma][*palette++];
  209.         g = gammatable[usegamma][*palette++];
  210.         b = gammatable[usegamma][*palette++];
  211.  
  212.         rgb[0] = (1000 * r) / 255;
  213.         rgb[1] = (1000 * g) / 255;
  214.         rgb[2] = (1000 * b) / 255;
  215.         vs_color(vdi_handle, vdi_index[i], rgb);
  216.     }
  217. }
  218.  
  219. void I_InitGraphics_vdi(void)
  220. {
  221.     if (zoomscreen)
  222.         I_ZoomInit(videowidth,videoheight);
  223.  
  224.     /* PM: Bug in NOVA VDI on Atari TT : it reports 16 bits for 32K mode */
  225.     /* PM: reported by Guillaume Tello */
  226.     /* PM: so use '-video-15' to force 15 bits routines if 16 bits reported */
  227.  
  228.     if ((bpp==16) && M_CheckParm("-novavdi"))
  229.     {
  230.         bpp=15;
  231.     }
  232.  
  233.     switch (bpp)
  234.     {
  235.         case 8:
  236.             R_DrawColumn=R_DrawColumn8;
  237.             R_DrawColumnLow=R_DrawColumnLow8;
  238.             R_DrawFuzzColumn=R_DrawFuzzColumn8;
  239.             R_DrawFuzzColumnLow=R_DrawFuzzColumnLow8;
  240.             R_DrawTranslatedColumn=R_DrawTranslatedColumn8;
  241.             R_DrawTranslatedColumnLow=R_DrawTranslatedColumnLow8;
  242.             R_DrawSpan=R_DrawSpan8;
  243.             R_DrawSpanLow=R_DrawSpanLow8;
  244.             AM_DrawFline=AM_drawFline8;
  245.             wipe_doMelt=wipe_doMelt8;
  246.             V_DrawPatch=V_DrawPatch8;
  247.             V_DrawPatchFlipped=V_DrawPatchFlipped8;
  248.             F_DrawPatchCol=F_DrawPatchCol8;
  249.             I_Zoom=I_Zoom8;
  250.             pixel_size=1;
  251.             break;
  252.         case 15:
  253.             R_DrawColumn=R_DrawColumn16;
  254.             R_DrawColumnLow=R_DrawColumnLow16;
  255.             R_DrawFuzzColumn=R_DrawFuzzColumn16;
  256.             R_DrawFuzzColumnLow=R_DrawFuzzColumnLow16;
  257.             R_DrawTranslatedColumn=R_DrawTranslatedColumn16;
  258.             R_DrawTranslatedColumnLow=R_DrawTranslatedColumnLow16;
  259.             R_DrawSpan=R_DrawSpan16;
  260.             R_DrawSpanLow=R_DrawSpanLow16;
  261.             AM_DrawFline=AM_drawFline16;
  262.             wipe_doMelt=wipe_doMelt16;
  263.             V_DrawPatch=V_DrawPatch16;
  264.             V_DrawPatchFlipped=V_DrawPatchFlipped16;
  265.             F_DrawPatchCol=F_DrawPatchCol16;
  266.             pixel_size=2;
  267.             I_Zoom=I_Zoom16;
  268.             fuzzmask=0x3DEF3DEF;
  269.             break;
  270.         case 16:
  271.             R_DrawColumn=R_DrawColumn16;
  272.             R_DrawColumnLow=R_DrawColumnLow16;
  273.             R_DrawFuzzColumn=R_DrawFuzzColumn16;
  274.             R_DrawFuzzColumnLow=R_DrawFuzzColumnLow16;
  275.             R_DrawTranslatedColumn=R_DrawTranslatedColumn16;
  276.             R_DrawTranslatedColumnLow=R_DrawTranslatedColumnLow16;
  277.             R_DrawSpan=R_DrawSpan16;
  278.             R_DrawSpanLow=R_DrawSpanLow16;
  279.             AM_DrawFline=AM_drawFline16;
  280.             wipe_doMelt=wipe_doMelt16;
  281.             V_DrawPatch=V_DrawPatch16;
  282.             V_DrawPatchFlipped=V_DrawPatchFlipped16;
  283.             F_DrawPatchCol=F_DrawPatchCol16;
  284.             pixel_size=2;
  285.             I_Zoom=I_Zoom16;
  286.             fuzzmask=0x7BEF7BEF;
  287.             break;
  288.         case 24:
  289.             R_DrawColumn=R_DrawColumn24;
  290.             R_DrawColumnLow=R_DrawColumnLow24;
  291.             R_DrawFuzzColumn=R_DrawFuzzColumn24;
  292.             R_DrawFuzzColumnLow=R_DrawFuzzColumnLow24;
  293.             R_DrawTranslatedColumn=R_DrawTranslatedColumn24;
  294.             R_DrawTranslatedColumnLow=R_DrawTranslatedColumnLow24;
  295.             R_DrawSpan=R_DrawSpan24;
  296.             R_DrawSpanLow=R_DrawSpanLow24;
  297.             AM_DrawFline=AM_drawFline24;
  298.             wipe_doMelt=wipe_doMelt24;
  299.             V_DrawPatch=V_DrawPatch24;
  300.             V_DrawPatchFlipped=V_DrawPatchFlipped24;
  301.             F_DrawPatchCol=F_DrawPatchCol24;
  302.             pixel_size=3;
  303.             I_Zoom=I_Zoom24;
  304.             break;
  305.         case 32:
  306.             R_DrawColumn=R_DrawColumn32;
  307.             R_DrawColumnLow=R_DrawColumnLow32;
  308.             R_DrawFuzzColumn=R_DrawFuzzColumn32;
  309.             R_DrawFuzzColumnLow=R_DrawFuzzColumnLow32;
  310.             R_DrawTranslatedColumn=R_DrawTranslatedColumn32;
  311.             R_DrawTranslatedColumnLow=R_DrawTranslatedColumnLow32;
  312.             R_DrawSpan=R_DrawSpan32;
  313.             R_DrawSpanLow=R_DrawSpanLow32;
  314.             AM_DrawFline=AM_drawFline32;
  315.             wipe_doMelt=wipe_doMelt32;
  316.             V_DrawPatch=V_DrawPatch32;
  317.             V_DrawPatchFlipped=V_DrawPatchFlipped32;
  318.             F_DrawPatchCol=F_DrawPatchCol32;
  319.             I_Zoom=I_Zoom32;
  320.             pixel_size=4;
  321.             fuzzmask=0x007F7F7F;
  322.             break;
  323.     }
  324. }
  325.  
  326. void I_SetMainScreen_vdi(void)
  327. {
  328.     int rgb[3]={0,0,0};
  329.  
  330.     if (!zoomscreen)
  331.     {
  332.         /* Directly draw to screen buffer */
  333.         screens[0] = buffer;
  334.     }
  335.  
  336.     /* XJ: Draw black screen */
  337.     vs_color(vdi_handle, vdi_index[0], rgb);
  338.     vsf_color(vdi_handle,0);
  339.     vsf_interior(vdi_handle,1);
  340.     vsf_perimeter(vdi_handle,0);
  341.  
  342.     v_bar(vdi_handle,screen_pxy);
  343. }
  344.