home *** CD-ROM | disk | FTP | other *** search
/ ST-Computer Leser-CD 2000 January / LCD_01_2000.iso / games / doom / pmdoom / src / video / xbios.c < prev   
C/C++ Source or Header  |  1999-12-17  |  11KB  |  507 lines

  1. /*
  2.  * Xbios functions
  3.  *
  4.  * Patrice Mandin
  5.  */
  6.  
  7. #include "doomdef.h"
  8. #include "doomstat.h"
  9. #include "v_video.h"
  10.  
  11. #include "r_draw.h"
  12. #include "am_map.h"
  13. #include "f_wipe.h"
  14. #include "f_finale.h"
  15. #include "z_zone.h"
  16.  
  17. #include "i_system.h"
  18. #include "i_video.h"
  19. #include "i_zoom.h"
  20. #include "i_cookies.h"
  21. #include "video/xbios.h"
  22.  
  23. int VideoInited=0;
  24.  
  25. unsigned short    atari_oldvmode;        /* saved video mode */
  26. void            *atari_oldvbase;    /* saved video adress */
  27.  
  28. unsigned long    atari_screen[2];    /* game screen */
  29. void            *atari_ecralloc[2];
  30.  
  31. unsigned long    atari_offset;    /* offset for game screen in real screen */
  32.  
  33. unsigned short    oldTTpalette[256]; /* saved old TT palette */
  34. unsigned long    oldF30palette[256];    /* saved old falcon palette */
  35.  
  36. void *atari_zoombuffer;    /* Buffer for zoomed screen */
  37.  
  38. /* List of video modes */
  39.  
  40. typedef struct
  41. {
  42.     int number;            /* Video mode number */
  43.     int width;
  44.     int height;
  45.     int depth;            /* bits per plane */
  46. } xbiosmode_t;
  47.  
  48. xbiosmode_t *xbiosmodelist;
  49. int xbiosnummodes;
  50.  
  51. int xbiosnummodes_tt=1;
  52. xbiosmode_t xbiosmodelist_tt[]={
  53.     {TT_LOW,320,480,8}
  54. };
  55.  
  56. int xbiosnummodes_f30rvb=16;
  57. xbiosmode_t xbiosmodelist_f30rvb[]={
  58.     {BPS8,320,200,8},
  59.     {BPS16,320,200,16},
  60.     {BPS8|VERTFLAG,320,400,8},
  61.     {BPS16|VERTFLAG,320,400,16},
  62.  
  63.     {BPS8|OVERSCAN,384,240,8},
  64.     {BPS16|OVERSCAN,384,240,16},
  65.     {BPS8|OVERSCAN|VERTFLAG,384,480,8},
  66.     {BPS16|OVERSCAN|VERTFLAG,384,480,16},
  67.  
  68.     {BPS8|COL80,640,200,8},
  69.     {BPS16|COL80,640,200,16},
  70.     {BPS8|COL80|VERTFLAG,640,400,8},
  71.     {BPS16|COL80|VERTFLAG,640,400,16},
  72.  
  73.     {BPS8|COL80|OVERSCAN,768,240,8},
  74.     {BPS16|COL80|OVERSCAN,768,240,16},
  75.     {BPS8|COL80|OVERSCAN|VERTFLAG,768,480,8},
  76.     {BPS16|COL80|OVERSCAN|VERTFLAG,768,480,16}
  77. };
  78.  
  79. int xbiosnummodes_f30vga=6;
  80. xbiosmode_t xbiosmodelist_f30vga[]={
  81.     {BPS8|VERTFLAG,320,240,8},
  82.     {BPS16|VERTFLAG,320,240,16},
  83.     {BPS8,320,480,8},
  84.     {BPS16,320,480,16},
  85.  
  86.     {BPS8|COL80|VERTFLAG,640,240,8},
  87.     {BPS8|COL80,640,480,8}    
  88. };
  89.  
  90. void BuildModeList_TT(void)
  91. {
  92.     xbiosnummodes=xbiosnummodes_tt;
  93.     xbiosmodelist=xbiosmodelist_tt;
  94. }
  95.  
  96. void BuildModeList_F30(void)
  97. {
  98.     switch (Montype())
  99.     {
  100.         case 0:        /* MONO */
  101.             I_Error("Doom does not work on a monochrome monitor\n");
  102.             break;
  103.         case 1:        /* RVB */
  104.         case 3:        /* TV */
  105.             xbiosnummodes = xbiosnummodes_f30rvb;
  106.             xbiosmodelist = xbiosmodelist_f30rvb;
  107.             break;
  108.         case 2:        /* VGA */
  109.             xbiosnummodes = xbiosnummodes_f30vga;
  110.             xbiosmodelist = xbiosmodelist_f30vga;
  111.             break;
  112.     }
  113.  
  114.     /* Now you can add dynamically other modes */
  115. }
  116.  
  117. void I_VidInit_xbios(void)
  118. {
  119.     int xbiospixelsize;
  120.     int i;
  121.     int screensize;
  122.     xbiosmode_t *curmode;
  123.  
  124.     /* Read available video modes */
  125.  
  126.     switch (cookie_vdo)
  127.     {
  128.         case VDO_TT:
  129.             BuildModeList_TT();
  130.             break;
  131.         case VDO_F30:
  132.             BuildModeList_F30();
  133.             break;
  134.     }
  135.  
  136.     /* Display video modes */
  137.  
  138.     printf("Available Xbios video modes:\n");
  139.     for (i=0;i<xbiosnummodes;i++)
  140.     {
  141.         xbiosmode_t *curmode;
  142.  
  143.         curmode=&xbiosmodelist[i];
  144.         printf("%d: %dx%d %d bits\n",i,curmode->width,curmode->height,curmode->depth);
  145.     }
  146.     printf("\n");
  147.             
  148.     /* Check video mode */
  149.  
  150.     if (videomode<0 || videomode>=xbiosnummodes)
  151.     {
  152.         /* Default mode */
  153.         switch(cookie_vdo)
  154.         {
  155.             /* TT : 320x480x8 */
  156.             case VDO_TT:
  157.                 videomode=0;    
  158.                 break;
  159.             /* F30rvb: 320x200x16 */
  160.             /* F30vga: 320x240x16 */
  161.             case VDO_F30:
  162.                 videomode=1;
  163.                 break;
  164.         }
  165.     }
  166.  
  167.     /* Init asked mode */
  168.     curmode=&xbiosmodelist[videomode];
  169.     videowidth=curmode->width;
  170.     videoheight=curmode->height;
  171.     bpp=curmode->depth;
  172.     dblbuffer=true;
  173.  
  174.     if (videowidth<SCREENWIDTH || videoheight<SCREENHEIGHT)
  175.         zoomscreen=true;
  176.  
  177.     if (zoomscreen || bpp==8)
  178.         dblbuffer=false;
  179.  
  180.     xbiospixelsize=1;
  181.     if (bpp==16)
  182.         xbiospixelsize=2;
  183.  
  184.     /* --- Allocate screens --- */
  185.  
  186.     screensize=videowidth*videoheight*xbiospixelsize;
  187.  
  188.     for (i=0;i<2;i++)
  189.     {
  190.         atari_ecralloc[i]=Mxalloc(screensize+256,0);
  191.  
  192.         if (atari_ecralloc[i]==NULL)
  193.             I_Error("Not enough memory for screens.\n");
  194.  
  195.         atari_screen[i]=(unsigned long )(atari_ecralloc[i]+16UL) & 0xFFFFFFF0UL;
  196.  
  197.         memset( (byte *)atari_screen[i],0,screensize);
  198.     }
  199. }
  200.  
  201. void I_ShutdownGraphics_xbios(void)
  202. {
  203.     Mfree(atari_ecralloc[0]);
  204.     Mfree(atari_ecralloc[1]);
  205.  
  206.     /* Switch back to old video mode */
  207.  
  208.     if (!VideoInited)
  209.         return;
  210.  
  211.     switch(cookie_vdo)
  212.     {
  213.         case VDO_TT:
  214.             Setscreen(-1,atari_oldvbase,-1,-1);
  215.             EsetShift(atari_oldvmode);
  216.             Vsync();
  217.  
  218.             EsetPalette(0,256,oldTTpalette);
  219.             break;
  220.         case VDO_F30:
  221.             Setscreen(-1,atari_oldvbase,-1,-1);
  222.             Vsetmode(atari_oldvmode);
  223.             Vsync();
  224.  
  225.             VsetRGB(0,256,oldF30palette);
  226.             break;
  227.     }
  228. }
  229.  
  230. void I_VidUpdate_xbios (void)
  231. {
  232.     if (pixel_size==1)
  233.     {
  234.         if (zoomscreen)
  235.         {
  236.             I_Zoom(screens[0],atari_zoombuffer);
  237.             convert_c2p(
  238.                 atari_zoombuffer,
  239.                 (byte *)atari_screen[fbnum],
  240.                 videowidth,videoheight,
  241.                 false,
  242.                 videowidth*pixel_size
  243.             );
  244.         }
  245.         else
  246.         {
  247.             convert_c2p(
  248.                 screens[0],
  249.                 (byte *)(atari_screen[fbnum]+atari_offset),
  250.                 SCREENWIDTH,SCREENHEIGHT,
  251.                 (cookie_vdo==VDO_TT),
  252.                 videowidth*pixel_size
  253.             );
  254.         }
  255.     }
  256.     else
  257.     {
  258.         if (zoomscreen)
  259.         {
  260.             I_Zoom(screens[0], (byte *)atari_screen[fbnum] );
  261.         }
  262.         else if (videowidth!=SCREENWIDTH)
  263.         {
  264.             unsigned short *source;
  265.             unsigned short *dest;
  266.             int x,y;
  267.  
  268.             source=screens[0];
  269.             dest=(byte *)atari_screen[fbnum]+atari_offset;
  270.     
  271.             for (y=0;y<SCREENHEIGHT;y++)
  272.             {
  273.                 unsigned short *destligne;
  274.  
  275.                 destligne=dest;
  276.                 for (x=0;x<SCREENWIDTH;x++)
  277.                 {
  278.                     *destligne++=*source++;
  279.                 }
  280.                 dest+=videowidth;
  281.             }
  282.         }
  283.     }
  284.  
  285.     Setscreen(-1,atari_screen[fbnum],-1,-1);
  286.     Vsync();
  287.  
  288.     fbnum ^= 1;                
  289.     if (pixel_size>1 && !zoomscreen && videowidth==SCREENWIDTH)
  290.     {
  291.         screens[0]=(byte *)(atari_screen[fbnum]+atari_offset);
  292.         R_InitBuffer(scaledviewwidth,viewheight); /* mettre a jour ylookup */
  293.     }
  294. }
  295.  
  296. /*  */
  297. /*  I_SetPalette */
  298. /*  */
  299. void I_SetPalette256_xbios(byte *palette)
  300. {
  301.     int        i;
  302.     int        r,v,b;
  303.     unsigned long    tc=0;
  304.     unsigned short    TT_palette[256];
  305.     unsigned long    F30_palette[256];
  306.  
  307.     switch(cookie_vdo)
  308.     {
  309.         case VDO_TT:
  310.             for (i=0;i<256;i++)
  311.             {
  312.                 r = gammatable[usegamma][*palette++];    
  313.                 v = gammatable[usegamma][*palette++];    
  314.                 b = gammatable[usegamma][*palette++];    
  315.                     
  316.                 tc=((r>>4)<<8)|((v>>4)<<4)|(b>>4);
  317.                 TT_palette[i]=tc;
  318.             }
  319.             EsetPalette(0,256,TT_palette);
  320.             break;
  321.         case VDO_F30:
  322.             for(i = 0; i < 256; i++)
  323.             {
  324.                 r = gammatable[usegamma][*palette++];    
  325.                 v = gammatable[usegamma][*palette++];
  326.                 b = gammatable[usegamma][*palette++];
  327.  
  328.                 F30_palette[i]=(r<<16)|(v<<8)|b;
  329.             }
  330.             VsetRGB(0,256,F30_palette);
  331.             break;
  332.     }
  333. }
  334.  
  335. void I_InitGraphics_xbios(void)
  336. {
  337.     int        i;
  338.     unsigned long palettezero[256];
  339.     xbiosmode_t    *curmode;
  340.  
  341.     for (i=0;i<256;i++)
  342.         palettezero[i]=0;
  343.  
  344.     init_c2p();
  345.  
  346.     /* Init video mode */
  347.     curmode=&xbiosmodelist[videomode];
  348.  
  349.     switch(cookie_vdo)
  350.     {
  351.         case VDO_TT:
  352.             EgetPalette(0,256,oldTTpalette);
  353.  
  354.             atari_oldvbase=Logbase();
  355.             atari_oldvmode=EgetShift();
  356.  
  357.             Setscreen(-1,atari_screen[1],-1,-1);
  358.             EsetShift(curmode->number);
  359.  
  360.             EsetPalette(0,256,palettezero);
  361.             break;
  362.         case VDO_F30:
  363.             VgetRGB(0,256,oldF30palette);
  364.  
  365.             atari_oldvbase=Logbase();    
  366.             atari_oldvmode=Vsetmode(-1);
  367.  
  368.             Setscreen(-1,atari_screen[1],-1,-1);
  369.             Vsetmode(curmode->number | (atari_oldvmode & ( VGA + PAL )) );
  370.  
  371.             VsetRGB(0,256,palettezero);
  372.             break;
  373.     }
  374.  
  375.     /* Init routines d'affichage */
  376.  
  377.     switch (bpp)
  378.     {
  379.         case 8:
  380.             R_DrawColumn=R_DrawColumn8;
  381.             R_DrawColumnLow=R_DrawColumnLow8;
  382.             R_DrawFuzzColumn=R_DrawFuzzColumn8;
  383.             R_DrawFuzzColumnLow=R_DrawFuzzColumnLow8;
  384.             R_DrawTranslatedColumn=R_DrawTranslatedColumn8;
  385.             R_DrawTranslatedColumnLow=R_DrawTranslatedColumnLow8;
  386.             R_DrawSpan=R_DrawSpan8;
  387.             R_DrawSpanLow=R_DrawSpanLow8;
  388.             AM_DrawFline=AM_drawFline8;
  389.             wipe_doMelt=wipe_doMelt8;
  390.             V_DrawPatch=V_DrawPatch8;
  391.             V_DrawPatchFlipped=V_DrawPatchFlipped8;
  392.             F_DrawPatchCol=F_DrawPatchCol8;
  393.             I_Zoom=I_Zoom8;
  394.             pixel_size=1;
  395.             break;
  396.         case 15:
  397.             R_DrawColumn=R_DrawColumn16;
  398.             R_DrawColumnLow=R_DrawColumnLow16;
  399.             R_DrawFuzzColumn=R_DrawFuzzColumn16;
  400.             R_DrawFuzzColumnLow=R_DrawFuzzColumnLow16;
  401.             R_DrawTranslatedColumn=R_DrawTranslatedColumn16;
  402.             R_DrawTranslatedColumnLow=R_DrawTranslatedColumnLow16;
  403.             R_DrawSpan=R_DrawSpan16;
  404.             R_DrawSpanLow=R_DrawSpanLow16;
  405.             AM_DrawFline=AM_drawFline16;
  406.             wipe_doMelt=wipe_doMelt16;
  407.             V_DrawPatch=V_DrawPatch16;
  408.             V_DrawPatchFlipped=V_DrawPatchFlipped16;
  409.             F_DrawPatchCol=F_DrawPatchCol16;
  410.             I_Zoom=I_Zoom16;
  411.             pixel_size=2;
  412.             fuzzmask=0x3DEF3DEF;
  413.             break;
  414.         case 16:
  415.             R_DrawColumn=R_DrawColumn16;
  416.             R_DrawColumnLow=R_DrawColumnLow16;
  417.             R_DrawFuzzColumn=R_DrawFuzzColumn16;
  418.             R_DrawFuzzColumnLow=R_DrawFuzzColumnLow16;
  419.             R_DrawTranslatedColumn=R_DrawTranslatedColumn16;
  420.             R_DrawTranslatedColumnLow=R_DrawTranslatedColumnLow16;
  421.             R_DrawSpan=R_DrawSpan16;
  422.             R_DrawSpanLow=R_DrawSpanLow16;
  423.             AM_DrawFline=AM_drawFline16;
  424.             wipe_doMelt=wipe_doMelt16;
  425.             V_DrawPatch=V_DrawPatch16;
  426.             V_DrawPatchFlipped=V_DrawPatchFlipped16;
  427.             F_DrawPatchCol=F_DrawPatchCol16;
  428.             I_Zoom=I_Zoom16;
  429.             pixel_size=2;
  430.             fuzzmask=0x7BEF7BEF;
  431.             break;
  432.         case 24:
  433.             R_DrawColumn=R_DrawColumn24;
  434.             R_DrawColumnLow=R_DrawColumnLow24;
  435.             R_DrawFuzzColumn=R_DrawFuzzColumn24;
  436.             R_DrawFuzzColumnLow=R_DrawFuzzColumnLow24;
  437.             R_DrawTranslatedColumn=R_DrawTranslatedColumn24;
  438.             R_DrawTranslatedColumnLow=R_DrawTranslatedColumnLow24;
  439.             R_DrawSpan=R_DrawSpan24;
  440.             R_DrawSpanLow=R_DrawSpanLow24;
  441.             AM_DrawFline=AM_drawFline24;
  442.             wipe_doMelt=wipe_doMelt24;
  443.             V_DrawPatch=V_DrawPatch24;
  444.             V_DrawPatchFlipped=V_DrawPatchFlipped24;
  445.             F_DrawPatchCol=F_DrawPatchCol24;
  446.             I_Zoom=I_Zoom24;
  447.             pixel_size=3;
  448.             break;
  449.         case 32:
  450.             R_DrawColumn=R_DrawColumn32;
  451.             R_DrawColumnLow=R_DrawColumnLow32;
  452.             R_DrawFuzzColumn=R_DrawFuzzColumn32;
  453.             R_DrawFuzzColumnLow=R_DrawFuzzColumnLow32;
  454.             R_DrawTranslatedColumn=R_DrawTranslatedColumn32;
  455.             R_DrawTranslatedColumnLow=R_DrawTranslatedColumnLow32;
  456.             R_DrawSpan=R_DrawSpan32;
  457.             R_DrawSpanLow=R_DrawSpanLow32;
  458.             AM_DrawFline=AM_drawFline32;
  459.             wipe_doMelt=wipe_doMelt32;
  460.             V_DrawPatch=V_DrawPatch32;
  461.             V_DrawPatchFlipped=V_DrawPatchFlipped32;
  462.             F_DrawPatchCol=F_DrawPatchCol32;
  463.             I_Zoom=I_Zoom32;
  464.             pixel_size=4;
  465.             fuzzmask=0x007F7F7F;
  466.             break;
  467.     }
  468.  
  469.     /* --- Zoom ? --- */
  470.  
  471.     if (zoomscreen)
  472.     {
  473.         if (pixel_size==1)
  474.         {
  475.             atari_zoombuffer=Z_Malloc(videowidth*videoheight*pixel_size, PU_STATIC, NULL);
  476.             if (!atari_zoombuffer)
  477.                 I_Error("Not enough memory for zoom screen\n");
  478.         }
  479.  
  480.         I_ZoomInit(videowidth,videoheight);
  481.         atari_offset=0;
  482.     }
  483.     else
  484.     {
  485.         int offsety,offsetx;
  486.  
  487.         if (cookie_vdo==VDO_TT)
  488.         {
  489.             /* C2P does double line */
  490.             offsety=(videoheight-(SCREENHEIGHT<<1))>>1;
  491.         }
  492.         else
  493.         {
  494.             /* Normal */
  495.             offsety=(videoheight-SCREENHEIGHT)>>1;
  496.         }
  497.  
  498.         offsetx=(videowidth-SCREENWIDTH)>>1;
  499.         if (pixel_size==1)
  500.             offsetx &= 0xFFFFFFF0UL;
  501.  
  502.         atari_offset=((offsety*videowidth)+offsetx)*pixel_size;
  503.     }
  504.  
  505.     VideoInited=1;
  506. }
  507.