home *** CD-ROM | disk | FTP | other *** search
- /*
- * Xbios functions
- *
- * Patrice Mandin
- */
-
- #include "doomdef.h"
- #include "doomstat.h"
- #include "v_video.h"
-
- #include "r_draw.h"
- #include "am_map.h"
- #include "f_wipe.h"
- #include "f_finale.h"
- #include "z_zone.h"
-
- #include "i_system.h"
- #include "i_video.h"
- #include "i_zoom.h"
- #include "i_cookies.h"
- #include "video/xbios.h"
-
- int VideoInited=0;
-
- unsigned short atari_oldvmode; /* saved video mode */
- void *atari_oldvbase; /* saved video adress */
-
- unsigned long atari_screen[2]; /* game screen */
- void *atari_ecralloc[2];
-
- unsigned long atari_offset; /* offset for game screen in real screen */
-
- unsigned short oldTTpalette[256]; /* saved old TT palette */
- unsigned long oldF30palette[256]; /* saved old falcon palette */
-
- void *atari_zoombuffer; /* Buffer for zoomed screen */
-
- /* List of video modes */
-
- typedef struct
- {
- int number; /* Video mode number */
- int width;
- int height;
- int depth; /* bits per plane */
- } xbiosmode_t;
-
- xbiosmode_t *xbiosmodelist;
- int xbiosnummodes;
-
- int xbiosnummodes_tt=1;
- xbiosmode_t xbiosmodelist_tt[]={
- {TT_LOW,320,480,8}
- };
-
- int xbiosnummodes_f30rvb=16;
- xbiosmode_t xbiosmodelist_f30rvb[]={
- {BPS8,320,200,8},
- {BPS16,320,200,16},
- {BPS8|VERTFLAG,320,400,8},
- {BPS16|VERTFLAG,320,400,16},
-
- {BPS8|OVERSCAN,384,240,8},
- {BPS16|OVERSCAN,384,240,16},
- {BPS8|OVERSCAN|VERTFLAG,384,480,8},
- {BPS16|OVERSCAN|VERTFLAG,384,480,16},
-
- {BPS8|COL80,640,200,8},
- {BPS16|COL80,640,200,16},
- {BPS8|COL80|VERTFLAG,640,400,8},
- {BPS16|COL80|VERTFLAG,640,400,16},
-
- {BPS8|COL80|OVERSCAN,768,240,8},
- {BPS16|COL80|OVERSCAN,768,240,16},
- {BPS8|COL80|OVERSCAN|VERTFLAG,768,480,8},
- {BPS16|COL80|OVERSCAN|VERTFLAG,768,480,16}
- };
-
- int xbiosnummodes_f30vga=6;
- xbiosmode_t xbiosmodelist_f30vga[]={
- {BPS8|VERTFLAG,320,240,8},
- {BPS16|VERTFLAG,320,240,16},
- {BPS8,320,480,8},
- {BPS16,320,480,16},
-
- {BPS8|COL80|VERTFLAG,640,240,8},
- {BPS8|COL80,640,480,8}
- };
-
- void BuildModeList_TT(void)
- {
- xbiosnummodes=xbiosnummodes_tt;
- xbiosmodelist=xbiosmodelist_tt;
- }
-
- void BuildModeList_F30(void)
- {
- switch (Montype())
- {
- case 0: /* MONO */
- I_Error("Doom does not work on a monochrome monitor\n");
- break;
- case 1: /* RVB */
- case 3: /* TV */
- xbiosnummodes = xbiosnummodes_f30rvb;
- xbiosmodelist = xbiosmodelist_f30rvb;
- break;
- case 2: /* VGA */
- xbiosnummodes = xbiosnummodes_f30vga;
- xbiosmodelist = xbiosmodelist_f30vga;
- break;
- }
-
- /* Now you can add dynamically other modes */
- }
-
- void I_VidInit_xbios(void)
- {
- int xbiospixelsize;
- int i;
- int screensize;
- xbiosmode_t *curmode;
-
- /* Read available video modes */
-
- switch (cookie_vdo)
- {
- case VDO_TT:
- BuildModeList_TT();
- break;
- case VDO_F30:
- BuildModeList_F30();
- break;
- }
-
- /* Display video modes */
-
- printf("Available Xbios video modes:\n");
- for (i=0;i<xbiosnummodes;i++)
- {
- xbiosmode_t *curmode;
-
- curmode=&xbiosmodelist[i];
- printf("%d: %dx%d %d bits\n",i,curmode->width,curmode->height,curmode->depth);
- }
- printf("\n");
-
- /* Check video mode */
-
- if (videomode<0 || videomode>=xbiosnummodes)
- {
- /* Default mode */
- switch(cookie_vdo)
- {
- /* TT : 320x480x8 */
- case VDO_TT:
- videomode=0;
- break;
- /* F30rvb: 320x200x16 */
- /* F30vga: 320x240x16 */
- case VDO_F30:
- videomode=1;
- break;
- }
- }
-
- /* Init asked mode */
- curmode=&xbiosmodelist[videomode];
- videowidth=curmode->width;
- videoheight=curmode->height;
- bpp=curmode->depth;
- dblbuffer=true;
-
- if (videowidth<SCREENWIDTH || videoheight<SCREENHEIGHT)
- zoomscreen=true;
-
- if (zoomscreen || bpp==8)
- dblbuffer=false;
-
- xbiospixelsize=1;
- if (bpp==16)
- xbiospixelsize=2;
-
- /* --- Allocate screens --- */
-
- screensize=videowidth*videoheight*xbiospixelsize;
-
- for (i=0;i<2;i++)
- {
- atari_ecralloc[i]=Mxalloc(screensize+256,0);
-
- if (atari_ecralloc[i]==NULL)
- I_Error("Not enough memory for screens.\n");
-
- atari_screen[i]=(unsigned long )(atari_ecralloc[i]+16UL) & 0xFFFFFFF0UL;
-
- memset( (byte *)atari_screen[i],0,screensize);
- }
- }
-
- void I_ShutdownGraphics_xbios(void)
- {
- Mfree(atari_ecralloc[0]);
- Mfree(atari_ecralloc[1]);
-
- /* Switch back to old video mode */
-
- if (!VideoInited)
- return;
-
- switch(cookie_vdo)
- {
- case VDO_TT:
- Setscreen(-1,atari_oldvbase,-1,-1);
- EsetShift(atari_oldvmode);
- Vsync();
-
- EsetPalette(0,256,oldTTpalette);
- break;
- case VDO_F30:
- Setscreen(-1,atari_oldvbase,-1,-1);
- Vsetmode(atari_oldvmode);
- Vsync();
-
- VsetRGB(0,256,oldF30palette);
- break;
- }
- }
-
- void I_VidUpdate_xbios (void)
- {
- if (pixel_size==1)
- {
- if (zoomscreen)
- {
- I_Zoom(screens[0],atari_zoombuffer);
- convert_c2p(
- atari_zoombuffer,
- (byte *)atari_screen[fbnum],
- videowidth,videoheight,
- false,
- videowidth*pixel_size
- );
- }
- else
- {
- convert_c2p(
- screens[0],
- (byte *)(atari_screen[fbnum]+atari_offset),
- SCREENWIDTH,SCREENHEIGHT,
- (cookie_vdo==VDO_TT),
- videowidth*pixel_size
- );
- }
- }
- else
- {
- if (zoomscreen)
- {
- I_Zoom(screens[0], (byte *)atari_screen[fbnum] );
- }
- else if (videowidth!=SCREENWIDTH)
- {
- unsigned short *source;
- unsigned short *dest;
- int x,y;
-
- source=screens[0];
- dest=(byte *)atari_screen[fbnum]+atari_offset;
-
- for (y=0;y<SCREENHEIGHT;y++)
- {
- unsigned short *destligne;
-
- destligne=dest;
- for (x=0;x<SCREENWIDTH;x++)
- {
- *destligne++=*source++;
- }
- dest+=videowidth;
- }
- }
- }
-
- Setscreen(-1,atari_screen[fbnum],-1,-1);
- Vsync();
-
- fbnum ^= 1;
- if (pixel_size>1 && !zoomscreen && videowidth==SCREENWIDTH)
- {
- screens[0]=(byte *)(atari_screen[fbnum]+atari_offset);
- R_InitBuffer(scaledviewwidth,viewheight); /* mettre a jour ylookup */
- }
- }
-
- /* */
- /* I_SetPalette */
- /* */
- void I_SetPalette256_xbios(byte *palette)
- {
- int i;
- int r,v,b;
- unsigned long tc=0;
- unsigned short TT_palette[256];
- unsigned long F30_palette[256];
-
- switch(cookie_vdo)
- {
- case VDO_TT:
- for (i=0;i<256;i++)
- {
- r = gammatable[usegamma][*palette++];
- v = gammatable[usegamma][*palette++];
- b = gammatable[usegamma][*palette++];
-
- tc=((r>>4)<<8)|((v>>4)<<4)|(b>>4);
- TT_palette[i]=tc;
- }
- EsetPalette(0,256,TT_palette);
- break;
- case VDO_F30:
- for(i = 0; i < 256; i++)
- {
- r = gammatable[usegamma][*palette++];
- v = gammatable[usegamma][*palette++];
- b = gammatable[usegamma][*palette++];
-
- F30_palette[i]=(r<<16)|(v<<8)|b;
- }
- VsetRGB(0,256,F30_palette);
- break;
- }
- }
-
- void I_InitGraphics_xbios(void)
- {
- int i;
- unsigned long palettezero[256];
- xbiosmode_t *curmode;
-
- for (i=0;i<256;i++)
- palettezero[i]=0;
-
- init_c2p();
-
- /* Init video mode */
- curmode=&xbiosmodelist[videomode];
-
- switch(cookie_vdo)
- {
- case VDO_TT:
- EgetPalette(0,256,oldTTpalette);
-
- atari_oldvbase=Logbase();
- atari_oldvmode=EgetShift();
-
- Setscreen(-1,atari_screen[1],-1,-1);
- EsetShift(curmode->number);
-
- EsetPalette(0,256,palettezero);
- break;
- case VDO_F30:
- VgetRGB(0,256,oldF30palette);
-
- atari_oldvbase=Logbase();
- atari_oldvmode=Vsetmode(-1);
-
- Setscreen(-1,atari_screen[1],-1,-1);
- Vsetmode(curmode->number | (atari_oldvmode & ( VGA + PAL )) );
-
- VsetRGB(0,256,palettezero);
- break;
- }
-
- /* Init routines d'affichage */
-
- switch (bpp)
- {
- case 8:
- R_DrawColumn=R_DrawColumn8;
- R_DrawColumnLow=R_DrawColumnLow8;
- R_DrawFuzzColumn=R_DrawFuzzColumn8;
- R_DrawFuzzColumnLow=R_DrawFuzzColumnLow8;
- R_DrawTranslatedColumn=R_DrawTranslatedColumn8;
- R_DrawTranslatedColumnLow=R_DrawTranslatedColumnLow8;
- R_DrawSpan=R_DrawSpan8;
- R_DrawSpanLow=R_DrawSpanLow8;
- AM_DrawFline=AM_drawFline8;
- wipe_doMelt=wipe_doMelt8;
- V_DrawPatch=V_DrawPatch8;
- V_DrawPatchFlipped=V_DrawPatchFlipped8;
- F_DrawPatchCol=F_DrawPatchCol8;
- I_Zoom=I_Zoom8;
- pixel_size=1;
- break;
- case 15:
- R_DrawColumn=R_DrawColumn16;
- R_DrawColumnLow=R_DrawColumnLow16;
- R_DrawFuzzColumn=R_DrawFuzzColumn16;
- R_DrawFuzzColumnLow=R_DrawFuzzColumnLow16;
- R_DrawTranslatedColumn=R_DrawTranslatedColumn16;
- R_DrawTranslatedColumnLow=R_DrawTranslatedColumnLow16;
- R_DrawSpan=R_DrawSpan16;
- R_DrawSpanLow=R_DrawSpanLow16;
- AM_DrawFline=AM_drawFline16;
- wipe_doMelt=wipe_doMelt16;
- V_DrawPatch=V_DrawPatch16;
- V_DrawPatchFlipped=V_DrawPatchFlipped16;
- F_DrawPatchCol=F_DrawPatchCol16;
- I_Zoom=I_Zoom16;
- pixel_size=2;
- fuzzmask=0x3DEF3DEF;
- break;
- case 16:
- R_DrawColumn=R_DrawColumn16;
- R_DrawColumnLow=R_DrawColumnLow16;
- R_DrawFuzzColumn=R_DrawFuzzColumn16;
- R_DrawFuzzColumnLow=R_DrawFuzzColumnLow16;
- R_DrawTranslatedColumn=R_DrawTranslatedColumn16;
- R_DrawTranslatedColumnLow=R_DrawTranslatedColumnLow16;
- R_DrawSpan=R_DrawSpan16;
- R_DrawSpanLow=R_DrawSpanLow16;
- AM_DrawFline=AM_drawFline16;
- wipe_doMelt=wipe_doMelt16;
- V_DrawPatch=V_DrawPatch16;
- V_DrawPatchFlipped=V_DrawPatchFlipped16;
- F_DrawPatchCol=F_DrawPatchCol16;
- I_Zoom=I_Zoom16;
- pixel_size=2;
- fuzzmask=0x7BEF7BEF;
- break;
- case 24:
- R_DrawColumn=R_DrawColumn24;
- R_DrawColumnLow=R_DrawColumnLow24;
- R_DrawFuzzColumn=R_DrawFuzzColumn24;
- R_DrawFuzzColumnLow=R_DrawFuzzColumnLow24;
- R_DrawTranslatedColumn=R_DrawTranslatedColumn24;
- R_DrawTranslatedColumnLow=R_DrawTranslatedColumnLow24;
- R_DrawSpan=R_DrawSpan24;
- R_DrawSpanLow=R_DrawSpanLow24;
- AM_DrawFline=AM_drawFline24;
- wipe_doMelt=wipe_doMelt24;
- V_DrawPatch=V_DrawPatch24;
- V_DrawPatchFlipped=V_DrawPatchFlipped24;
- F_DrawPatchCol=F_DrawPatchCol24;
- I_Zoom=I_Zoom24;
- pixel_size=3;
- break;
- case 32:
- R_DrawColumn=R_DrawColumn32;
- R_DrawColumnLow=R_DrawColumnLow32;
- R_DrawFuzzColumn=R_DrawFuzzColumn32;
- R_DrawFuzzColumnLow=R_DrawFuzzColumnLow32;
- R_DrawTranslatedColumn=R_DrawTranslatedColumn32;
- R_DrawTranslatedColumnLow=R_DrawTranslatedColumnLow32;
- R_DrawSpan=R_DrawSpan32;
- R_DrawSpanLow=R_DrawSpanLow32;
- AM_DrawFline=AM_drawFline32;
- wipe_doMelt=wipe_doMelt32;
- V_DrawPatch=V_DrawPatch32;
- V_DrawPatchFlipped=V_DrawPatchFlipped32;
- F_DrawPatchCol=F_DrawPatchCol32;
- I_Zoom=I_Zoom32;
- pixel_size=4;
- fuzzmask=0x007F7F7F;
- break;
- }
-
- /* --- Zoom ? --- */
-
- if (zoomscreen)
- {
- if (pixel_size==1)
- {
- atari_zoombuffer=Z_Malloc(videowidth*videoheight*pixel_size, PU_STATIC, NULL);
- if (!atari_zoombuffer)
- I_Error("Not enough memory for zoom screen\n");
- }
-
- I_ZoomInit(videowidth,videoheight);
- atari_offset=0;
- }
- else
- {
- int offsety,offsetx;
-
- if (cookie_vdo==VDO_TT)
- {
- /* C2P does double line */
- offsety=(videoheight-(SCREENHEIGHT<<1))>>1;
- }
- else
- {
- /* Normal */
- offsety=(videoheight-SCREENHEIGHT)>>1;
- }
-
- offsetx=(videowidth-SCREENWIDTH)>>1;
- if (pixel_size==1)
- offsetx &= 0xFFFFFFF0UL;
-
- atari_offset=((offsety*videowidth)+offsetx)*pixel_size;
- }
-
- VideoInited=1;
- }
-