home *** CD-ROM | disk | FTP | other *** search
- /*
- * VDI functions
- *
- * Johan Klockars
- * Xavier Joubert
- * Patrice Mandin
- */
-
- #include <osbind.h>
- #include <gemdefs.h>
- #include <vdibind.h>
- #include <aesbind.h>
- #include <common.h>
-
- #include "doomdef.h"
- #include "doomstat.h"
- #include "v_video.h"
- #include "m_argv.h"
-
- #include "r_draw.h"
- #include "am_map.h"
- #include "f_wipe.h"
- #include "f_finale.h"
-
- #include "i_zoom.h"
- #include "i_system.h"
- #include "i_video.h"
- #include "video/vdi.h"
-
- extern byte *orig_colormaps;
-
- static int ap_id=-1;
- static int vdi_handle=0;
- static void *buffer;
- static MFDB src_mfdb, dst_mfdb;
- static int blit_coords[8];
- static int screen_pxy[4];
- static int old_pal[256*3];
- static unsigned char vdi_index[256] = {0, 2, 3, 6, 4, 7, 5, 8, 9, 10, 11, 14, 12, 15, 13, 255, 0};
-
- int VideoInited_vdi=0;
-
- void I_VidInit_vdi(void)
- {
- int bufwidth, bufheight;
- int i,vdipixelsize;
- int work_in[12], work_out[57], dummy;
- int AllocFastRam; /* Alloc preferrably from Fast Ram */
- int rgb[3];
- int screensize;
-
- _global[0] = 0;
- ap_id = appl_init();
-
- work_in[0]=Getrez()+2;
- for(i = 1; i < 10; i++)
- work_in[i] = 1;
- work_in[10] = 2;
-
- vdi_handle = graf_handle(&dummy, &dummy, &dummy, &dummy);
- v_opnvwk(work_in, &vdi_handle, work_out);
-
- if(vdi_handle==0)
- I_Error("Error initializing VDI\n");
-
- videowidth = work_out[0] + 1;
- videoheight = work_out[1] + 1;
- vq_extnd(vdi_handle, 1, work_out);
- bpp = work_out[4];
-
- /* --- Allocate screens */
-
- if ((videowidth<SCREENWIDTH) || (videoheight<SCREENHEIGHT))
- zoomscreen=true;
-
- switch(bpp)
- {
- case 8 :
- vdipixelsize=1;
- break;
- case 15 :
- case 16 :
- vdipixelsize=2;
- break;
- case 24 :
- vdipixelsize=3;
- break;
- case 32 :
- vdipixelsize=4;
- break;
- default :
- vdipixelsize=0;
- break;
- }
-
- if (vdipixelsize==0)
- I_Error("You need a 8, 15, 16, 24 or 32 bits display!\n");
-
- /* Zoom screen ? */
-
- bufwidth=SCREENWIDTH;
- bufheight=SCREENHEIGHT;
- if (zoomscreen)
- {
- bufwidth = videowidth;
- bufheight= videoheight;
- }
-
- /* Allocate buffer */
-
- screensize=bufwidth * bufheight * vdipixelsize;
-
- AllocFastRam=3; /* Alloc from Fast Ram */
- if (M_CheckParm("-nofastblit"))
- AllocFastRam=0; /* Alloc from normal Ram */
-
- buffer = (void *)Mxalloc(screensize, AllocFastRam);
- if (!buffer)
- I_Error("Not enough memory for draw buffer!\n");
-
- /* screens[1] = screens[0] = buffer; */
-
- memset(buffer, 0,screensize);
-
- dst_mfdb.fd_addr = 0;
-
- src_mfdb.fd_addr = (long)buffer;
- src_mfdb.fd_w = bufwidth;
- src_mfdb.fd_h = bufheight;
- src_mfdb.fd_wdwidth = bufwidth / 16;
- src_mfdb.fd_stand = 0;
- src_mfdb.fd_nplanes = bpp;
-
- blit_coords[0] = 0;
- blit_coords[1] = 0;
- blit_coords[2] = bufwidth - 1;
- blit_coords[3] = bufheight - 1;
- blit_coords[4] = (videowidth - bufwidth) / 2;
- blit_coords[5] = (videoheight - bufheight) / 2;
- blit_coords[6] = blit_coords[4] + bufwidth - 1;
- blit_coords[7] = blit_coords[5] + bufheight - 1;
-
- screen_pxy[0]=0;
- screen_pxy[1]=0;
- screen_pxy[2]=videowidth-1;
- screen_pxy[3]=videoheight-1;
-
- /* XJ: Save old palette */
- for(i = 0; i < 256; i++)
- {
- vq_color(vdi_handle, i, 0, rgb);
- old_pal[i*3+0] = rgb[0];
- old_pal[i*3+1] = rgb[1];
- old_pal[i*3+2] = rgb[2];
- }
- VideoInited_vdi=1;
- }
-
- void I_ShutdownGraphics_vdi(void)
- {
- int i,rgb[3];
-
- /* XJ: Old palette */
- if(VideoInited_vdi)
- for(i = 0; i < 256; i++)
- {
- rgb[0] = old_pal[i*3+0];
- rgb[1] = old_pal[i*3+1];
- rgb[2] = old_pal[i*3+2];
- vs_color(vdi_handle, i, rgb);
- }
-
- if(vdi_handle)
- v_clsvwk(vdi_handle);
- appl_exit();
-
- Mfree(buffer);
- }
-
- void I_VidUpdate_vdi(void)
- {
- if (zoomscreen)
- {
- I_Zoom(screens[0],src_mfdb.fd_addr);
- }
-
- vro_cpyfm(vdi_handle, 3, blit_coords, &src_mfdb, &dst_mfdb);
- }
-
- /* */
- /* I_SetPalette */
- /* */
- void I_SetPalette256_vdi(byte *palette)
- {
- int i,rgb[3];
-
- if (!vdi_index[16])
- {
- for(i = 16; i < 255; i++)
- vdi_index[i] = i;
- vdi_index[255] = 1;
- }
-
- for(i = 0; i < 256; i++)
- {
- int r, g, b;
-
- r = gammatable[usegamma][*palette++];
- g = gammatable[usegamma][*palette++];
- b = gammatable[usegamma][*palette++];
-
- rgb[0] = (1000 * r) / 255;
- rgb[1] = (1000 * g) / 255;
- rgb[2] = (1000 * b) / 255;
- vs_color(vdi_handle, vdi_index[i], rgb);
- }
- }
-
- void I_InitGraphics_vdi(void)
- {
- if (zoomscreen)
- I_ZoomInit(videowidth,videoheight);
-
- /* PM: Bug in NOVA VDI on Atari TT : it reports 16 bits for 32K mode */
- /* PM: reported by Guillaume Tello */
- /* PM: so use '-video-15' to force 15 bits routines if 16 bits reported */
-
- if ((bpp==16) && M_CheckParm("-novavdi"))
- {
- bpp=15;
- }
-
- 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;
- pixel_size=2;
- I_Zoom=I_Zoom16;
- 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;
- pixel_size=2;
- I_Zoom=I_Zoom16;
- 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;
- pixel_size=3;
- I_Zoom=I_Zoom24;
- 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;
- }
- }
-
- void I_SetMainScreen_vdi(void)
- {
- int rgb[3]={0,0,0};
-
- if (!zoomscreen)
- {
- /* Directly draw to screen buffer */
- screens[0] = buffer;
- }
-
- /* XJ: Draw black screen */
- vs_color(vdi_handle, vdi_index[0], rgb);
- vsf_color(vdi_handle,0);
- vsf_interior(vdi_handle,1);
- vsf_perimeter(vdi_handle,0);
-
- v_bar(vdi_handle,screen_pxy);
- }
-