home *** CD-ROM | disk | FTP | other *** search
/ Amiga ACS 1998 #6 / amigaacscoverdisc1998-061998.iso / games / descent / source / main / vfx.c < prev    next >
Text File  |  1998-06-08  |  6KB  |  275 lines

  1. /*
  2. THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
  3. SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
  4. END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
  5. ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
  6. IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
  7. SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
  8. FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
  9. CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
  10. AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.  
  11. COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
  12. */
  13. /*
  14.  * $Source: f:/miner/source/main/rcs/vfx.c $
  15.  * $Revision: 2.4 $
  16.  * $Author: john $
  17.  * $Date: 1995/05/11 13:28:59 $
  18.  * 
  19.  * Routines to access VR helmet.
  20.  * 
  21.  * $Log: vfx.c $
  22.  * Revision 2.4  1995/05/11  13:28:59  john
  23.  * Made so no -vfx doesnt' check for VIPPORT.
  24.  * 
  25.  * Revision 2.3  1995/05/11  13:08:28  john
  26.  * Made code print bomb out with error if it can't find VIPPORT.
  27.  * 
  28.  * 
  29.  * Revision 2.2  1995/05/08  13:53:32  john
  30.  * Added code to read the vipport environment variable.
  31.  * 
  32.  * Revision 2.1  1995/03/10  13:05:50  john
  33.  * Added code so that palette is correct for VFX1 helmets.
  34.  * 
  35.  * Revision 2.0  1995/02/27  11:30:29  john
  36.  * New version 2.0, which has no anonymous unions, builds with
  37.  * Watcom 10.0, and doesn't require parsing BITMAPS.TBL.
  38.  * 
  39.  * Revision 1.5  1994/12/28  10:26:42  john
  40.  * Fixed some VFX problems.
  41.  * 
  42.  * Revision 1.4  1994/11/19  15:20:34  mike
  43.  * rip out unused code and data
  44.  * 
  45.  * Revision 1.3  1994/09/20  19:36:11  matt
  46.  * Added seperate function to set palette
  47.  * 
  48.  * Revision 1.2  1994/06/24  17:03:50  john
  49.  * Added VFX support. Also took all game sequencing stuff like
  50.  * EndGame out and put it into gameseq.c
  51.  * 
  52.  * Revision 1.1  1994/06/23  09:14:06  john
  53.  * Initial revision
  54.  * 
  55.  * 
  56.  */
  57.  
  58.  
  59. #pragma off (unreferenced)
  60. static char rcsid[] = "$Id: vfx.c 2.4 1995/05/11 13:28:59 john Exp $";
  61. #pragma on (unreferenced)
  62.  
  63.  
  64.  
  65. #include <stdlib.h>
  66. #include <stdio.h>
  67. #include <conio.h>
  68. #include <string.h>
  69.  
  70. #include "gr.h"
  71. #include "error.h"
  72. #include "mono.h"
  73.  
  74. #define INDEX_SCR     0
  75. #define INDEX_SRR     1
  76. #define INDEX_ICR     2
  77. #define INDEX_ISR     3
  78. #define INDEX_PSR        4
  79. #define INDEX_VRR        5
  80. #define INDEX_PCR        6
  81. #define INDEX_PPRR    7
  82. #define INDEX_PRAR    8
  83. #define INDEX_PWAR    9
  84. #define INDEX_PCRR    10
  85.  
  86. #define PORT_AIR        (vfx_base_port)
  87. #define PORT_CSR        (vfx_base_port+1)
  88. #define PORT_DFIN        (vfx_base_port+2)
  89. #define PORT_DFOUT    (vfx_base_port+4)
  90.  
  91. typedef struct DATA_SCR    {
  92.     union {
  93.         struct {
  94.             ubyte cmd     : 6;    //Command Code 
  95.             ubyte cchk     : 1;    //Command Check Condition
  96.             ubyte cpnd     : 1;    //Command Pending
  97.         };
  98.         ubyte value;
  99.     };
  100. } DATA_SCR;
  101.  
  102. typedef struct DATA_SSR    {
  103.     ubyte ssc    : 6;    // Software Status Code
  104.     ubyte rsvd    : 2;    // Reserved
  105. } DATA_SSR;
  106.  
  107. typedef struct DATA_ICR    {
  108.     ubyte ien    : 1;    // Interrupt Enable
  109.     ubyte cor    : 1;    // Clear On Read
  110.     ubyte sfmd    : 2;    // Sync/Flip Mode
  111.     ubyte rsvd    : 4;    // Reserved
  112. } DATA_ICR;
  113.  
  114. typedef struct DATA_ISR    {
  115.     ubyte sfip    : 1;    // Sync/Flip Interrupt Pending
  116.     ubyte rsvd    : 6;    // Reserved
  117.     ubyte flpp    : 1;    // Flip Pending
  118. } DATA_ISR;
  119.  
  120. typedef struct DATA_PSR    {
  121.     union {
  122.         struct {
  123.             ubyte reps    : 4;    // Right Eye Page Select
  124.             ubyte leps    : 4;    // Left Eye Page Select
  125.         };
  126.         ubyte value;
  127.     };
  128. } DATA_PSR;
  129.  
  130. typedef struct DATA_VRR    {
  131.     union {
  132.         struct {
  133.             ubyte vipr    : 1;    // VIPP Ready
  134.             ubyte rsvd    : 7;    // Reserved
  135.         };
  136.         ubyte value;
  137.     };
  138. } DATA_VRR;
  139.  
  140. typedef struct DATA_PCR    {
  141.     ubyte dps    : 1;    // Disable Palette Snoop
  142.     ubyte lrps    : 1;    // Left/Right Palette Select
  143.     ubyte wrbp    : 1;    // WRite Both Palettes
  144.     ubyte rsvd    : 5;    // Reserved
  145. } DATA_PCR;
  146.  
  147.  
  148. extern int Game_vfx_flag;
  149. static int vfx_base_port = 0x260;
  150.  
  151. static int vfx_initialized = 0;
  152.  
  153. void vfx_init()
  154. {
  155.     char * vipport;
  156.  
  157.     if (vfx_initialized) return;
  158.     vfx_initialized = 1;
  159.     
  160.     vipport = getenv( "VIPPORT" );
  161.     if ( vipport )    {
  162.         sscanf( vipport, "%x", &vfx_base_port );
  163.     } else {
  164.         Error( "Couldn't find VIPPORT environment variable.\n" );
  165.     }
  166. }
  167.  
  168. //download palette into VFX
  169. void vfx_set_palette_sub(ubyte * palette)
  170. {
  171.     int i;
  172.  
  173.     if (!vfx_initialized) return;
  174.  
  175.     if ( Game_vfx_flag )    {
  176.         outp( PORT_AIR, INDEX_PCR );
  177.         outp( PORT_CSR, 1+0+4 );                // Enable palette snoop
  178.     
  179.         outp( PORT_AIR, 7 );
  180.         outp( PORT_CSR, 0xFF );                // Disable palette masking
  181.     
  182.         outp( PORT_AIR, 9 );                    //start palette copy
  183.         outp( PORT_CSR, 0 );
  184.     
  185.         for (i=0; i<768; i++ )    {
  186.             outp( PORT_AIR, 10 );
  187.             outp( PORT_CSR, palette[i] );
  188.         }
  189.     }
  190. }
  191.  
  192. void vfx_set_palette()
  193. {
  194.     if (!vfx_initialized) return;
  195.     vfx_set_palette_sub(gr_palette);
  196. }
  197.  
  198. void vfx_init_graphics()
  199. {
  200.     int overscan, overscan_flag;
  201.  
  202.     if (!vfx_initialized) return;
  203.  
  204.     vfx_set_palette();        //download palette into VFX
  205.  
  206.     //0xFF
  207.     outp( 0x3d4, 0x6);
  208.     overscan = 0x01 & inp( 0x3d5 );
  209.     outp( 0x3d4, 0x16 );
  210.     overscan ^= 0x01 & inp( 0x3d5 );
  211.     
  212.     if ( overscan )
  213.         overscan_flag = 0;
  214.     else
  215.         overscan_flag = 0x8;
  216.  
  217.     //odd/even mode...
  218.     
  219.     outp( vfx_base_port+2, 0x2 );         // Index/data
  220.     // stereo
  221.     outp( vfx_base_port+3, overscan_flag & 0xFE );
  222.     // mono
  223.     //outp( vfx_base_port+3, overscan_flag | 0x01 );
  224.  
  225. }
  226.  
  227.  
  228. void vfx_close_graphics()
  229. {
  230.     int overscan, overscan_flag;
  231.  
  232.     if (!vfx_initialized) return;
  233.  
  234.     outp( 0x3d4, 0x6);
  235.     overscan = 0x01 & inp( 0x3d5 );
  236.     outp( 0x3d4, 0x16 );
  237.     overscan ^= 0x01 & inp( 0x3d5 );
  238.     
  239.     if ( overscan )
  240.         overscan_flag = 0;
  241.     else
  242.         overscan_flag = 0x8;
  243.  
  244.     //odd/even mode...
  245.     
  246.     //
  247.     outp( vfx_base_port + 2, 0x2 );         // Index/data
  248.     // mono
  249.     outp( vfx_base_port + 3, overscan_flag | 0x01 );
  250. }
  251.  
  252.  
  253.  
  254. void vfx_set_page(ubyte page)
  255. {
  256.     DATA_PSR page_register;
  257.  
  258.     if (!vfx_initialized) return;
  259.     
  260.     if ( page == 0 )    {
  261.         page_register.leps = 0;
  262.         page_register.reps = 1;
  263.     } else {
  264.         page_register.leps = 2;
  265.         page_register.reps = 3;
  266.     }
  267.  
  268.     outp( PORT_AIR, INDEX_PSR );
  269.     outp( PORT_CSR, page_register.value );
  270. }
  271.  
  272.  
  273.  
  274. 
  275.