Annotation of src/whvfx1.c, revision 1.1.1.1

1.1       root        1: #define   TEKWAR
                      2: /***************************************************************************
                      3: *    NAME: EXAMPLE.C
                      4: **   COPYRIGHT:
                      5: **   "Copyright (c) 1994, by FORTE"
                      6: **
                      7: **       "This software is furnished under a license and may be used,
                      8: **       copied, or disclosed only in accordance with the terms of such
                      9: **       license and with the inclusion of the above copyright notice.
                     10: **       This software or any other copies thereof may not be provided or
                     11: **       otherwise made available to any other person. No title to and
                     12: **       ownership of the software is hereby transfered."
                     13: ****************************************************************************
                     14: *  CREATION DATE: 06/01/94
                     15: *--------------------------------------------------------------------------*
                     16: *     VERSION  DATE    NAME        DESCRIPTION
                     17: *             06/20/94     Example  SENSE example interface code.
                     18: *             06/27/94              Modified for support for Windows
                     19: *                                   Tracking support.
                     20: *                                   (plus example video mode changes)
                     21: ***************************************************************************/
                     22: 
                     23: #ifndef TEKWAR
                     24: #ifdef __WATCOMC__
                     25: #include <graph.h>
                     26: 
                     27: #elif defined(_WINDOWS)
                     28: #include <windows.h>
                     29: unsigned long win_memory;
                     30: #endif
                     31: 
                     32: #if defined(__WATCOMC__)  || defined(_WINDOWS)
                     33: #include "dpmi.h"
                     34: #endif
                     35: #endif
                     36: 
                     37: #include <stddef.h>
                     38: #include <stdio.h>
                     39: #include <stdlib.h>
                     40: #include <string.h>
                     41: #include <conio.h>
                     42: #include <dos.h>
                     43: 
                     44: #include "vfx1.h"
                     45: #ifndef TEKWAR
                     46: #include "vesa.h"
                     47: #endif
                     48: 
                     49: #define MAX_CONFIG_SIZE     256
                     50: #define MAX_REPORT_SIZE     256
                     51: 
                     52: #define DOS_ERROR           0xFF
                     53: 
                     54: #define PALETTE_SIZE        768 
                     55: #define MONO_320_200        0x13    
                     56: 
                     57: #define LEFT_EYE            0
                     58: #define RIGHT_EYE           1
                     59: #define BOTH_EYES           2
                     60: 
                     61: #define MAX_HTDS            6
                     62: #define MAX_HPDS            6
                     63: 
                     64: SYSTEM_CPKT *system_cfg;
                     65: VENDOR_CPKT *vendor_cfg;
                     66: HMS_CPKT    *hms_cfg;
                     67: HTD_CPKT    *htd_cfg;
                     68: HPD_CPKT    *hpd_cfg;
                     69: 
                     70: // Structures specific to what the application enables
                     71: // Set Video Mode for a "Something" mounted display 
                     72: struct svm_struct
                     73: {
                     74: SVM_CPKT    cfg;
                     75: NULL_CPKT   null_end;
                     76: };
                     77: typedef struct svm_struct SVM_STRUCT;
                     78: 
                     79: // Head tracker devices
                     80: struct htd_struct
                     81: {
                     82: short     yaw;
                     83: short     pitch;
                     84: short     roll;
                     85: };
                     86: typedef struct htd_struct HTD_STRUCT;
                     87: 
                     88: // Hand held devices
                     89: struct hpd_struct
                     90: {
                     91: short     yaw;
                     92: short     pitch;
                     93: short     roll;
                     94: char      buttons;
                     95: };
                     96: typedef struct hpd_struct HPD_STRUCT;
                     97: 
                     98: SVM_STRUCT      svm;
                     99: HTD_STRUCT far *htd_data[ MAX_HTDS ];
                    100: HPD_STRUCT far *hpd_data[ MAX_HPDS ];
                    101: 
                    102: //#ifndef TEKWAR
                    103: union  REGS     regs;
                    104: struct SREGS    sregs;
                    105: //#endif
                    106: 
                    107: // Fields required for ISA bus io.
                    108: int             vip_air_port;
                    109: int             vip_csr_port;
                    110: 
                    111: #ifndef TEKWAR
                    112: // Holding array for current VGA palette
                    113: char    vga_palette[ PALETTE_SIZE ];
                    114: 
                    115: // Fields required for MONO video example.
                    116: char    mono_colors[ PALETTE_SIZE ];
                    117: 
                    118: // Fields required for STEREO video example.
                    119: char    left_colors[ PALETTE_SIZE ];
                    120: char    right_colors[ PALETTE_SIZE ];
                    121: #endif
                    122: 
                    123: int     SenseStatus( void );
                    124: int     SenseGetConfiguration( int function, int *count, char *config_buffer);
                    125: int     SenseSetConfiguration( int function, char *config_buffer );
                    126: int     SenseReport( int function, int *count, char *report_buffer );
                    127: #ifndef TEKWAR
                    128: void    ShowMonoPattern( void );
                    129: void    PutPalette( int which_eye, char *pPalette );
                    130: void    GetPalette( char *pPalette );
                    131: void    VideoChannel( int stereo_mode, int page );
                    132: void    ShowStereoPattern( void );
                    133: void    BuildPalettes( void );
                    134: void    CleanUp( void );
                    135: #endif
                    136: 
                    137: #ifdef TEKWAR
                    138: #include "keydefs.h"
                    139: 
                    140: #define DPMI_INT    0x31
                    141: #define MOUSE_INT   0x33
                    142: 
                    143: #define AX(r) ((r).x.eax)
                    144: #define BX(r) ((r).x.ebx)
                    145: #define CX(r) ((r).x.ecx)
                    146: #define DX(r) ((r).x.edx)
                    147: #define SI(r) ((r).x.esi)
                    148: #define DI(r) ((r).x.edi)
                    149: 
                    150: static void *pdosmem;
                    151: 
                    152: short segment,
                    153:        selector;
                    154: 
                    155: int  sense_function;
                    156: 
                    157: char vfx1_cyberpuck;
                    158: char config_buffer[MAX_CONFIG_SIZE];
                    159: char *report_offset;
                    160: char report_buffer[MAX_REPORT_SIZE];
                    161: 
                    162: enum {
                    163:        OPT_RUN,
                    164:        OPT_SHOOT,
                    165:        OPT_USEOPEN,
                    166:        OPT_JUMP,
                    167:        OPT_CROUCH,
                    168:        OPT_MAP,
                    169:        OPT_MAPZOOMIN,
                    170:        OPT_MAPZOOMOUT,
                    171:        NUMBUTOPTIONS
                    172: };
                    173: 
                    174: char *butkeystr[]={
                    175:        "BUTTON1:",
                    176:        "BUTTON2:",
                    177:        "BUTTON3:"
                    178: };
                    179: 
                    180: char *butoptstr[]={
                    181:        "RUN",
                    182:        "SHOOT",
                    183:        "USE_OPEN",
                    184:        "JUMP",
                    185:        "CROUCH",
                    186:        "MAP",
                    187:        "MAP_ZOOM_IN",
                    188:        "MAP_ZOOM_OUT",
                    189: };
                    190: 
                    191: char puckbuttons;
                    192: 
                    193: short butoptval[]={
                    194:         KEYRUN,KEYFIRE,KEYUSE,KEYJUMP,KEYCROUCH,
                    195:         KEYMAP,KEYZOOMI,KEYZOOMO
                    196: };
                    197: 
                    198: #define   NUMPUCKBUTTONS      3
                    199: 
                    200: short puckpitch,
                    201:        puckroll,
                    202:        puckbutton[NUMPUCKBUTTONS];
                    203: 
                    204: FILE *fp;
                    205: char buf[256];
                    206: 
                    207: extern
                    208: union REGS regs;
                    209: extern
                    210: struct SREGS sregs;
                    211: 
                    212: //extern
                    213: int  vfx1enabled;
                    214: 
                    215: static struct rminfo {
                    216:        long di;
                    217:     long si;
                    218:        long bp;
                    219:        long reserved_by_system;
                    220:        long bx;
                    221:        long dx;
                    222:        long cx;
                    223:        long ax;
                    224:        short flags;
                    225:        short es, ds, fs, gs, ip, cs, sp, ss;
                    226: } SENSE;
                    227: 
                    228: void *
                    229: allocDOS(unsigned nbytes, short *pseg, short *psel)
                    230: {
                    231:        unsigned npara=(nbytes+15)/16;
                    232:        void *pprot;
                    233: 
                    234:        pprot=NULL;
                    235:        *pseg=0;
                    236:        *psel=0;
                    237:        segread(&sregs);
                    238:        AX(regs)=0x0100;           // DPMI: Allocate DOS Memory
                    239:        BX(regs)=npara;            // number of paragraphs to alloc
                    240:        int386( DPMI_INT, &regs, &regs);
                    241:        if (regs.w.cflag == 0) {
                    242:                *pseg=AX(regs);
                    243:                *psel=DX(regs);
                    244:                pprot=(void *)((unsigned)*pseg<<4);
                    245:        }
                    246:        return(pprot);
                    247: }
                    248: 
                    249: void
                    250: VFX1MouseInt(struct rminfo *prmi)
                    251: {
                    252:        memset(&sregs,0,sizeof (sregs));
                    253:        memset(&regs,0,sizeof (regs));
                    254:        AX(regs)=0x0300;       // DPMI: simulate interrupt
                    255:        BX(regs)=MOUSE_INT;
                    256:        CX(regs)=0;
                    257:        DI(regs)=FP_OFF(prmi);
                    258:        sregs.es=FP_SEG(prmi);
                    259:        int386x(DPMI_INT,&regs,&regs,&sregs);
                    260: }
                    261: 
                    262: void
                    263: vfx1_read(short *tyaw,short *tpitch,short *troll,
                    264:        short *ppitch,short *proll,char *pbuttons)
                    265: {
                    266:        int  count,ret;
                    267: 
                    268:        if (ret=SenseReport(sense_function,&count,report_buffer)) {
                    269:                return;
                    270:        }
                    271:        *tyaw=htd_data[0]->yaw;
                    272:        *tpitch=htd_data[0]->pitch;
                    273:        *troll=htd_data[0]->roll;
                    274:        *ppitch=hpd_data[0]->pitch;
                    275:        *proll=hpd_data[0]->roll;
                    276:        *pbuttons=hpd_data[0]->buttons;
                    277: }
                    278: #endif
                    279: #include <memcheck.h>
                    280: 
                    281: int     SenseStatus( void )
                    282: {
                    283: int function, result, i;
                    284: 
                    285:     for( i=MIN_SENSE_FUNCTION; i <= MAX_SENSE_FUNCTION; i++ )
                    286:           {
                    287:           result    = i;
                    288:           result   |= (SENSE_DRIVER_STATUS << 8);
                    289:           function  = SENSE_DRIVER_STATUS;
                    290:           function |= (i << 8);        
                    291: 
                    292: #if defined(__WATCOMC__)  || defined(_WINDOWS)
                    293: 
                    294:           memset(&SENSE, 0, sizeof(SENSE));
                    295:           SENSE.ax = function;            
                    296:           SENSE.bx = 0;
                    297:           SENSE.cx = 0;
                    298:        SENSE.dx = 0;
                    299:           VFX1MouseInt( &SENSE ); // Generate the INT 33
                    300: 
                    301:           if( SENSE.ax == result )        
                    302:                  return( function & 0xFF00 );                   
                    303: #else           
                    304:           regs.x.cx = 0;
                    305:           regs.x.dx = 0;
                    306:           regs.x.bx = 0;
                    307:           regs.x.ax = function;
                    308:           int86( SENSE_VECTOR, &regs, &regs );
                    309:           
                    310:           if( regs.x.ax == result )
                    311:                  return( function & 0xFF00 );
                    312: #endif         
                    313:           }
                    314:     
                    315:     return( 0 );
                    316: }
                    317: 
                    318: int     SenseGetConfiguration( int function, int *count, char *config_buffer )
                    319: {
                    320: #if defined(__WATCOMC__) || defined(_WINDOWS)    
                    321: char           *src,*dest;
                    322: int                 i;
                    323: 
                    324:     memset(&SENSE, 0, sizeof(SENSE));
                    325:     SENSE.ax = function | GET_CONFIGURATION;           
                    326:     SENSE.cx = 0;
                    327:     SENSE.es = segment;
                    328:     SENSE.dx = 0;        
                    329:     VFX1MouseInt( &SENSE );
                    330: 
                    331:     src = (char *)pdosmem;  
                    332:     for( i=0; i < SENSE.cx; i++ )
                    333:           config_buffer[i] = src[i];
                    334:     
                    335:     *count = SENSE.cx;
                    336:     
                    337:     return( SENSE.ax );
                    338: #else    
                    339:     regs.x.ax = function | GET_CONFIGURATION;
                    340:     regs.x.cx = 0;
                    341:     regs.x.dx = FP_OFF( config_buffer );    
                    342:     sregs.es  = FP_SEG( config_buffer );
                    343: 
                    344:     int86x( SENSE_VECTOR, &regs, &regs, &sregs);
                    345: 
                    346:     *count = regs.x.cx;
                    347: 
                    348:     return( regs.x.ax );
                    349: #endif    
                    350: }
                    351: 
                    352: int     SenseSetConfiguration( int function, char *config_buffer )
                    353: {
                    354: #if defined(__WATCOMC__) || defined(_WINDOWS) 
                    355: char           *src,*dest;
                    356: int                 i;
                    357: 
                    358:     dest = (char *)pdosmem;
                    359:     for (i = 0; i < MAX_CONFIG_SIZE; i++)
                    360:           dest[i] = config_buffer[i];
                    361: 
                    362:     memset(&SENSE, 0, sizeof(SENSE));
                    363:     SENSE.ax = function | SET_CONFIGURATION;           
                    364:     SENSE.cx = 0;
                    365:     SENSE.es = segment;
                    366:     SENSE.dx = 0;        
                    367: 
                    368:     VFX1MouseInt( &SENSE );
                    369: 
                    370:     return( SENSE.ax );
                    371: #else        
                    372:     regs.x.ax = function | SET_CONFIGURATION;
                    373:     regs.x.cx = 0;
                    374:     regs.x.dx = FP_OFF( config_buffer );    
                    375:     sregs.es  = FP_SEG( config_buffer );
                    376:     
                    377:     int86x( SENSE_VECTOR, &regs, &regs, &sregs);
                    378: 
                    379:     return( regs.x.ax );
                    380: #endif    
                    381: }
                    382: 
                    383: int     SenseReport( int function, int *count, char *report_buffer )
                    384: {
                    385: #if defined(__WATCOMC__)  || defined(_WINDOWS) 
                    386: char           *src;
                    387: int                 i;
                    388: 
                    389:     memset(&SENSE, 0, sizeof(SENSE));
                    390:     SENSE.ax = function | REPORT;
                    391:     SENSE.cx = 0;
                    392:     SENSE.es = segment;
                    393:     SENSE.dx = 0;        
                    394:     VFX1MouseInt( &SENSE );
                    395: 
                    396:     src = (char *)pdosmem;
                    397:     for (i = 0; i < SENSE.cx; i++)
                    398:           report_buffer[i] = src[i];
                    399:           
                    400:     *count = SENSE.cx;
                    401:     
                    402:     return( SENSE.ax );
                    403: #else            
                    404:     regs.x.ax = function | REPORT;
                    405:     regs.x.cx = 0;
                    406:     regs.x.dx = FP_OFF( report_buffer );    
                    407:     sregs.es  = FP_SEG( report_buffer );
                    408:     
                    409:     int86x( SENSE_VECTOR, &regs, &regs, &sregs );
                    410: 
                    411:     *count = regs.x.cx;
                    412:     
                    413:     return( regs.x.ax );
                    414: #endif    
                    415: }
                    416: 
                    417: #ifndef TEKWAR
                    418: void    ShowMonoPattern( void )
                    419: {
                    420: int     color;
                    421: int     i,j;
                    422: char    *vga_screen;
                    423: 
                    424: // While waiting for a key press show a simple pattern    
                    425:     color      = 0;    
                    426:     vga_screen = (char *) SCREEN_BASE_LA;
                    427:     for( j=0; j < 199; j++ ) {
                    428:           for( i=0; i < 320; i++ )
                    429:                  vga_screen[ j*320 + i ] = color;
                    430:           color++;
                    431:           }
                    432:           
                    433:     getch();
                    434: }
                    435: 
                    436: void    PutPalette( int which_eye, char *pPalette )
                    437: {
                    438: int       i;
                    439: char *pTmp = pPalette;
                    440: char    palette_control_bits;
                    441: 
                    442:        /* turn on palette */
                    443:        outp( vip_air_port,VIP_PPMR );
                    444:        outp( vip_csr_port, 0xFF );
                    445: 
                    446:        // Enable write of proper selected palettes (right and/or left eyes)
                    447:           
                    448:        outp( vip_air_port, VIP_PCR );
                    449:     palette_control_bits = inp( vip_csr_port );
                    450:     if( which_eye == LEFT_EYE )// Left eye update only.
                    451:           {
                    452:           palette_control_bits |= 0x02; // Select left.
                    453:           palette_control_bits &= ~0x04;// Turn off update of both.
                    454:           palette_control_bits |= 0x01;// Turn off snoop.
                    455:           }
                    456:     else
                    457:     if( which_eye == RIGHT_EYE )// Right eye update only.
                    458:           {
                    459:           palette_control_bits &= ~0x02;// Select right.
                    460:           palette_control_bits &= ~0x04;// Turn off update of both.
                    461:           palette_control_bits |= 0x01;// Turn off snoop.            
                    462:           }
                    463:     else
                    464:           { // Enable both eye updates.
                    465:           palette_control_bits |= 0x04;// Turn on update of both.
                    466:           palette_control_bits &= ~0x01;// Turn on snoop.            
                    467:           }
                    468:     
                    469:        outp( vip_csr_port, palette_control_bits );
                    470: 
                    471:     // Setup the VGA's video palette.
                    472:     outp(0x3c8,0);    
                    473:     for (i=0; i<256; i++) {
                    474:           outp(0x3c9,*pPalette++);
                    475:           outp(0x3c9,*pPalette++);
                    476:           outp(0x3c9,*pPalette++);
                    477:           }
                    478:          
                    479:        // Setup the VIP video palette or palettes 
                    480:        outp(vip_air_port,VIP_PWAR);
                    481:        outp(vip_csr_port,0);
                    482:        outp(vip_air_port,VIP_PCRR);
                    483:     
                    484:        for (i=0; i < 256; i++)  {
                    485:                outp(vip_csr_port,*pTmp++);
                    486:                outp(vip_csr_port,*pTmp++);
                    487:                outp(vip_csr_port,*pTmp++);
                    488:                }
                    489: }
                    490: 
                    491: void    GetPalette( char *pPalette )
                    492: {
                    493: int       i;
                    494:     // Read the VGA's video palette.
                    495:     outp(0x3c8,0);    
                    496:     for (i=0; i<PALETTE_SIZE; i++) pPalette[i] = inp( 0x3c9 );
                    497: }
                    498: 
                    499: void    VideoChannel( int stereo_mode, int page )
                    500: {    
                    501: // This procedure will use the ISA bus to set which quardrant the
                    502: // left and right eyes will be looking at. 
                    503:        outp( vip_air_port, VIP_PSR );
                    504: 
                    505:        if( page )
                    506:                {
                    507:                if( stereo_mode )
                    508:                  // Stereo on page one is defined as lower left(left eye), 
                    509:                  // lower right(right eye).            
                    510:                        outp( vip_csr_port, 0x23);            
                    511:                else
                    512:                  {
                    513:                  // Mono on page one is defined as lower left corner both eyes.
                    514:                        outp( vip_csr_port, 0x22);        
                    515:                  }
                    516:                }
                    517:        else
                    518:                {
                    519:                if( stereo_mode )
                    520:                  // Stereo on page zero is defined as upper left(left eye), 
                    521:                  // upper right(right eye).
                    522:                        outp( vip_csr_port, 0x01);
                    523:                else
                    524:                  {
                    525:                  // Mono on page zero is defined as upper left corner both eyes.
                    526:                        outp( vip_csr_port, 0x00);                    
                    527:                  }
                    528:                }
                    529: }
                    530: 
                    531: void    ShowStereoPattern( void )
                    532: {
                    533: long            Offset;
                    534: long            over;
                    535: int                 VESAWriteWindow = 0;    
                    536: int             SubWindow;
                    537: int             RetVal;
                    538: int             sPageOffset;
                    539: int             stereo_mode = 0;
                    540: int             i,j;
                    541: int             left_index;
                    542: int             right_index;
                    543: char            key;
                    544: char            *pDst;
                    545: char            *pPageBase;
                    546: char            *vga_screen;
                    547: 
                    548:        RetVal = VESAExists();
                    549: 
                    550:        if (RetVal == VESA_NO_SUPPORT) {
                    551:                printf("VESA Function 00h: Super VGA Information not supported.");
                    552:           return;
                    553:                }
                    554: 
                    555:        if (RetVal == VESA_BAD_INFO) {
                    556:                printf("VESA Function 00h: Super VGA Information failed.\n");
                    557:           return;
                    558:                }
                    559:     
                    560:        if( VESAGetModeInfo( VESA_G640x480x256 ) ) {
                    561:           printf("VESA mode %x is NOT supported\n", VESA_G640x480x256 );        
                    562:           return;
                    563:           }
                    564:     
                    565:        if (!(VesaModeInfo.ModeAttributes & VESA_MA_MODE_SUPPORTED)) {
                    566:           printf("VESA mode %x is NOT supported\n", VESA_G640x480x256 );
                    567:           return;
                    568:                }
                    569: 
                    570:        if ((VesaModeInfo.WinAAttributes & VESA_WA_MODE_SUPPORTED)
                    571:         && (VesaModeInfo.WinAAttributes & VESA_WA_WRITABLE)) {
                    572:                VESAWriteWindow = 0;
                    573:                }
                    574:        else
                    575:                {
                    576:                if ((VesaModeInfo.WinBAttributes & VESA_WA_MODE_SUPPORTED)
                    577:                 && (VesaModeInfo.WinBAttributes & VESA_WA_WRITABLE)) {
                    578:                        VESAWriteWindow = 1;
                    579:                        }
                    580:                else {
                    581:                  printf("Cannot write to VESA Windows\n");
                    582:                        return;
                    583:                        }
                    584:                }
                    585: 
                    586:     stereo_mode = 1;
                    587:     sPageOffset = 0;
                    588:     vga_screen  = (char *) SCREEN_BASE_LA;
                    589: 
                    590: // Now show the same pattern only in stereo
                    591: while( 1 ) {            
                    592:     VESASetMode( VESA_G640x480x256 );    
                    593:     
                    594:     VideoChannel( stereo_mode, sPageOffset / 640 );
                    595: 
                    596:     PutPalette( LEFT_EYE, left_colors );    
                    597:     PutPalette( RIGHT_EYE, right_colors );
                    598: 
                    599:     SubWindow   = 0;    
                    600:     Offset      = sPageOffset;
                    601:     pPageBase   = (char *)(vga_screen + sPageOffset);
                    602:     pDst        = (char *)pPageBase;              /* start address on VGA */
                    603:     left_index  = 0;
                    604:     right_index = 200;
                    605:           
                    606:     VESASetWin( VESAWriteWindow, SubWindow );
                    607: 
                    608:     for (i = 0; i < 200; i++) {
                    609:           if (Offset + 640L < 65536L) {
                    610:                  for (j = 0; j < 320; j++) *pDst++ = left_index;
                    611:                  for (j = 0; j < 320; j++) *pDst++ = right_index;
                    612:                  
                    613:                  pDst   += 640;
                    614:                  Offset += 1280L;
                    615: 
                    616:                  if (Offset >= 65536L) {
                    617:                         Offset &= 0x0000FFFF;
                    618:                         pDst = (char *)(pPageBase + Offset);
                    619:                         VESASetWin( VESAWriteWindow, ++SubWindow );
                    620:                         }
                    621:                  }
                    622:           else {
                    623:                  if (Offset + 320L < 65536L) {
                    624:                         for (j = 0; j < 320; j++) *pDst++ = left_index;
                    625:                         over = (Offset + 640L) - 65536L;
                    626:                         for (j = 0; j < (320L - over); j++) *pDst++ = right_index;
                    627: 
                    628:                         pDst = (char *)pPageBase;
                    629:                         VESASetWin( VESAWriteWindow,++SubWindow );
                    630: 
                    631:                         for (j = 0; j < over; j++) *pDst++ = right_index;
                    632:                         
                    633:                         pDst  += 640;
                    634:                         Offset = 640L + over;
                    635:                         }
                    636:                  else {
                    637:                         over = (Offset + 320L) - 65536L;
                    638:                         for (j = 0; j < (320L - over); j++) *pDst++ = left_index;
                    639: 
                    640:                         pDst = (char *)pPageBase;
                    641:                         VESASetWin( VESAWriteWindow, ++SubWindow );
                    642: 
                    643:                         for (j = 0; j < over; j++ ) *pDst++ = left_index;
                    644:                         for (j = 0; j < 320; j++ )  *pDst++ = right_index;
                    645:                         
                    646:                         pDst  += 640;
                    647:                         Offset = 960L + over;
                    648:                         }
                    649:                  }
                    650:           left_index++;
                    651:           right_index--;
                    652:           pPageBase = (char *)(vga_screen);
                    653:           }
                    654:     
                    655:     #ifdef __WATCOMC__
                    656:           _settextposition( 1,1 );
                    657:     #else
                    658:           gotoxy( 1,1 );
                    659:     #endif        
                    660:     printf("Enter: Toggle stereo/mono  Space: Toggle page 0/1  Esc: exit\n");
                    661:     printf("Current settings:\n");    
                    662:     if( sPageOffset ) printf("Page 1:  ");
                    663:     else              printf("Page 0:  ");                    
                    664:     if( stereo_mode ) printf("Stereo mode:\n");
                    665:     else              printf("Mono mode:\n");
                    666:     
                    667:     key = getch();
                    668:     if( key == 27 ) break;// Simply exit this example code.    
                    669:     if( key == 13 )  // Simply toggle to and from stereo/mono mode.
                    670:           stereo_mode = !stereo_mode;    
                    671:     if( key == 32 ) // Simply flip to other page on press of space bar
                    672:           {
                    673:           if( sPageOffset ) sPageOffset = 0;            
                    674:           else              sPageOffset = 640;
                    675:           }        
                    676:     }    
                    677: }
                    678: 
                    679: void    BuildPalettes( void )
                    680: {
                    681: int i;
                    682: 
                    683: // Both eyes palette (mono test)
                    684:     for( i = 0; i < PALETTE_SIZE; ) {
                    685:           mono_colors[i++] = 0x0;
                    686:           mono_colors[i++] = 0x0;
                    687:           mono_colors[i++] = i % 100;                
                    688:           }            
                    689:     
                    690: // All red in left eye (stereo test)
                    691:     for( i=0; i<PALETTE_SIZE; i++ ) {
                    692:           if( !(i % 3) ) left_colors[i] = i;    
                    693:           else           left_colors[i] = 0;                
                    694:           }    
                    695: // All green in right eye (stereo test)
                    696:     for( i=0; i<PALETTE_SIZE; i++ ) {
                    697:           if( !((i+2) % 3) ) right_colors[i] = i;    
                    698:           else               right_colors[i] = 0;                
                    699: 
                    700:           }
                    701: }
                    702: 
                    703: void    CleanUp( void )
                    704: {
                    705: #if defined(__WATCOMC__) || defined(_WINDOWS) 
                    706: // Free the dos memory.
                    707:         if (pdosmem) {
                    708:            freeDOS(selector);
                    709:            pdosmem = 0;
                    710:         }
                    711: #endif  
                    712: }
                    713: #endif                                                      // Les 09/29/95
                    714: 
                    715: void    vfx1_init(void)
                    716: {
                    717: #ifndef TEKWAR
                    718: int     sense_function;
                    719: int     current_video_mode;
                    720: #endif
                    721: int     htd_index, hpd_index;
                    722: int     count, i, j;
                    723: int     packet_size;
                    724: int     ret;
                    725: #ifndef TEKWAR
                    726: char    vfx1_cyberpuck;
                    727: char    config_buffer[ MAX_CONFIG_SIZE ];
                    728: char    *report_offset;
                    729: char    report_buffer[ MAX_REPORT_SIZE ];
                    730: #endif
                    731: char    *env_ptr, *dptr;
                    732: 
                    733: #if defined(__WATCOMC__)  || defined(_WINDOWS) 
                    734:    // allocate a DOS real-mode buffer
                    735:    pdosmem = allocDOS(MAX_CONFIG_SIZE, &segment, &selector);
                    736:    if (!pdosmem) {
                    737:         printf("Error getting DOS memory!\n");
                    738:         exit(0);
                    739:    }
                    740: #endif
                    741: 
                    742: // Should use environment string here.
                    743: // Get the VIPPORT Environment string and setup the port variables.
                    744:     env_ptr = getenv("VIPPORT");
                    745:     if (env_ptr == NULL) {
                    746: #ifndef TEKWAR
                    747:           printf("VIPPORT Environment string not setup, using default.\n");
                    748: #endif
                    749:           vip_air_port = 0x300;
                    750:           }
                    751:     else {
                    752:           vip_air_port = strtol( env_ptr, &dptr, 16 );
                    753:           }
                    754:     
                    755:     vip_csr_port = vip_air_port + VIP_CSR;            
                    756:           
                    757:     if( (sense_function = SenseStatus()) == 0 ) {
                    758: #ifndef TEKWAR
                    759:           printf("No Sense devices installed\n");
                    760:           CleanUp();
                    761:           exit(2);        
                    762: #endif
                    763:           }
                    764: 
                    765: #ifndef TEKWAR
                    766:     printf("Sense devices installed on function %x\n", sense_function );
                    767: #endif
                    768: 
                    769:     if( ret=SenseGetConfiguration( sense_function, &count, config_buffer ) ) {
                    770: #ifndef TEKWAR
                    771:           printf("Error#(%d) getting configuration packets\n", ret );
                    772:           CleanUp();        
                    773:           exit(3);
                    774: #endif
                    775:           }
                    776: 
                    777: #ifndef TEKWAR
                    778:     printf("Configuration packet sizes %d\n", count );
                    779: #endif
                    780: 
                    781:     report_offset = report_buffer;    
                    782:     htd_index = hpd_index = 0;
                    783:     
                    784:     for( i=0; i < count; i += packet_size ) {
                    785:           packet_size = (int)config_buffer[i];        
                    786: 
                    787:           switch( config_buffer[i+1] )
                    788:                  {
                    789:                  case NULLP:
                    790: // All done packets break out                
                    791:                         i = count; 
                    792:                  break;
                    793:                  case SYSI:              
                    794:                         system_cfg = (SYSTEM_CPKT *) &config_buffer[i];
                    795: 
                    796:                  break;
                    797:                  case VNDI:
                    798:                         vendor_cfg = (VENDOR_CPKT *) &config_buffer[i];
                    799: #ifndef TEKWAR
                    800:                         printf("%s\n", vendor_cfg->prdm );
                    801:                         printf("%s\n", vendor_cfg->prdn );
                    802:                         printf("Serial #: %s\n", vendor_cfg->prdsn );
                    803:                         printf("Revision level: %s\n", vendor_cfg->prdrl );
                    804: #endif
                    805:                         if( !strcmp( vendor_cfg->prdn, PRDN ) )
                    806:                                vfx1_cyberpuck = 1;
                    807:                         else
                    808:                                vfx1_cyberpuck = 0;
                    809:                  break;
                    810:                  case HMS:
                    811:                         hms_cfg = (HMS_CPKT *) &config_buffer[i];
                    812:                         
                    813:                         svm.cfg.psiz = sizeof( SVM_CPKT );
                    814:                         svm.cfg.ptyp = SVM;
                    815:                         svm.cfg.dcls = hms_cfg->dcls;
                    816:                         svm.cfg.dnum = hms_cfg->dnum;
                    817: 
                    818:                  break;
                    819:                  case HTD:
                    820:                         if( htd_index >= MAX_HTDS ) break;                 
                    821:                         htd_data[htd_index++] = (HTD_STRUCT far *) report_offset;
                    822:                         report_offset += sizeof( HTD_STRUCT );
                    823: 
                    824:                         htd_cfg = (HTD_CPKT *) &config_buffer[i];
                    825:                         // Only enable if Head tracker is for a Vfx1 Cyberbuck
                    826:                         if( vfx1_cyberpuck )                    
                    827:                                {// Vfx1 Cyberpuck Head tracker.                
                    828:                                htd_cfg->ywcd.rcf.den = 1;
                    829:                                htd_cfg->ptcd.rcf.den = 1;
                    830:                                htd_cfg->rlcd.rcf.den = 1;                
                    831:                                }
                    832:                  break;
                    833:                  case HPD:    
                    834:                         if( hpd_index >= MAX_HPDS ) break;               
                    835:                         hpd_data[hpd_index++] = (HPD_STRUCT far *) report_offset;
                    836:                         report_offset += sizeof( HPD_STRUCT );
                    837:                         
                    838:                         hpd_cfg = (HPD_CPKT *) &config_buffer[i];
                    839: 
                    840:                         if( vfx1_cyberpuck )                    
                    841:                                {// Vfx1 Cyberpuck Head tracker.                
                    842:                                hpd_cfg->ywcd.rcf.den = 1;
                    843:                                hpd_cfg->ptcd.rcf.den = 1;
                    844:                                hpd_cfg->rlcd.rcf.den = 1;
                    845:                                hpd_cfg->btcd.den     = 1;
                    846:                                }
                    847:                  break;
                    848:                  default:
                    849: #ifndef TEKWAR
                    850:                         printf("Strange packet type here\n");
                    851: #endif
                    852:                  break;
                    853:                  }
                    854:           }
                    855: 
                    856:     if( ret=SenseSetConfiguration( sense_function, config_buffer ) ) {
                    857: #ifndef TEKWAR
                    858:           printf("Error#(%d) enabling configuration packets\n",ret);
                    859:           CleanUp();                
                    860:           exit(4);
                    861: #endif
                    862:           }   
                    863: 
                    864: #ifndef TEKWAR
                    865:     getch();
                    866: 
                    867:     #ifdef __WATCOMC__
                    868:           _clearscreen( 0 );
                    869:     #else
                    870:           clrscr();
                    871:     #endif
                    872: #endif    
                    873:                  
                    874: // Configuration packets are now enabled and ready for reporting
                    875: #ifndef TEKWAR
                    876:     if( htd_index )
                    877:           printf("VFX1 Head tracker device installed\n" );
                    878:     if( hpd_index )
                    879:           printf("CyberPuck Pointing device installed\n" );    
                    880: 
                    881:     while( !kbhit() ) {       
                    882:           if( ret=SenseReport( sense_function, &count, report_buffer ) ) {
                    883:                  printf("Error#(%d) during reporting packets\n",ret);
                    884:                  CleanUp();                    
                    885:                  exit(5);                            
                    886:                  }
                    887:           
                    888:           #ifdef __WATCOMC__
                    889:                  _settextposition( 1,5 );
                    890:           #else
                    891:                  gotoxy( 1,5 );
                    892:           #endif
                    893: 
                    894:           if( htd_index )
                    895:                  printf("VFX1: yaw(%-05d) pitch(%-05d) roll(%-05d)  \n",
                    896:                         htd_data[0]->yaw, htd_data[0]->pitch, htd_data[0]->roll);
                    897:                  
                    898:           if( hpd_index )
                    899:                  printf("CyberPuck: pitch(%-05d) roll(%-05d) Buttons(%03x)    \n",
                    900:                         hpd_data[0]->pitch, hpd_data[0]->roll, hpd_data[0]->buttons);
                    901:           }
                    902:     getch();
                    903: #endif
                    904: 
                    905: #ifndef TEKWAR
                    906: #ifndef _WINDOWS    
                    907: // Now let's do both a stero and a mono video test.
                    908: // First build the palettes for both tests.    
                    909:     BuildPalettes();
                    910: 
                    911: // Store current VGA mode.
                    912:     current_video_mode = VESAGetMode( );
                    913: 
                    914: // First let's do a simple MONO video test.        
                    915:     VESASetMode( MONO_320_200 );
                    916: 
                    917: // Get the VGA palette
                    918:     GetPalette( vga_palette );    
                    919: 
                    920: // Now put the "Something" mounted display in mono mode.
                    921:     svm.cfg.vmod = 0;
                    922:     if( ret=SenseSetConfiguration( sense_function, (char *)&svm ) ) {
                    923:           VESASetMode( current_video_mode );            
                    924:           printf("Error#(%d) setting mono video mode\n",ret);
                    925:           }    
                    926:     else {
                    927:           PutPalette( BOTH_EYES, mono_colors );
                    928: 
                    929: // Put up a mono screen.    
                    930:           ShowMonoPattern( );
                    931:           }
                    932:     
                    933: // Finally let's do a simple STEREO video test.        
                    934:     VESASetMode( VESA_G640x480x256 );
                    935: 
                    936: // Now put the "Something" mounted display in stereo mode.
                    937:     svm.cfg.vmod = 1;
                    938:     if( ret=SenseSetConfiguration( sense_function, (char *)&svm ) ) {
                    939:           VESASetMode( current_video_mode );                    
                    940:           printf("Error#(%d) setting mono video mode\n",ret);
                    941:           }
                    942:     else {  
                    943:           PutPalette( LEFT_EYE, left_colors );    
                    944:           PutPalette( RIGHT_EYE, right_colors );    
                    945: 
                    946: // Put up a stereo screen. This routine also performs stereo tests.   
                    947:           ShowStereoPattern();
                    948:           }
                    949:     
                    950: // Now put the "Something" mounted display back in mono mode.
                    951:     VESASetMode( MONO_320_200 );
                    952:     svm.cfg.vmod = 0;
                    953:     if( ret=SenseSetConfiguration( sense_function, (char *)&svm ) ) {
                    954:           VESASetMode( current_video_mode );                    
                    955:           printf("Error#(%d) setting mono video mode\n",ret);
                    956:           }
                    957:     
                    958: // Reset the VGA palette
                    959:     PutPalette( BOTH_EYES, vga_palette );    
                    960: 
                    961: // Reset VGA mode
                    962:     VESASetMode( current_video_mode );        
                    963: #else
                    964: // Now put the "Something" mounted display in stereo mode.
                    965:     svm.cfg.vmod = 1;
                    966:     if( ret=SenseSetConfiguration( sense_function, (char *)&svm ) ) {
                    967:           VESASetMode( current_video_mode );            
                    968:           printf("Error#(%d) setting mono video mode\n",ret);
                    969:           }    
                    970:     else {
                    971:           printf("Now in STEREO Mode\n");
                    972:           getch();
                    973:           }
                    974:     
                    975: // Now put the "Something" mounted display in mono mode.
                    976:     svm.cfg.vmod = 0;
                    977:     if( ret=SenseSetConfiguration( sense_function, (char *)&svm ) ) {
                    978:           VESASetMode( current_video_mode );            
                    979:           printf("Error#(%d) setting mono video mode\n",ret);
                    980:           }    
                    981:     else {
                    982:           printf("Now in MONO Mode\n");
                    983:           getch();
                    984:           }
                    985: #endif
                    986: 
                    987:     CleanUp();
                    988: #else
                    989:        vfx1enabled=1;
                    990: #if 0
                    991:        fp=fopen("VFX1.CFG","r");
                    992:        if (fp != NULL) {
                    993:                while (fgets(buf,256,fp) != NULL) {
                    994:                        for (i=0 ; i < NUMPUCKBUTTONS ; i++) {
                    995:                                if (strstr(buf,butkeystr[i]) != NULL) {
                    996:                                        for (j=0 ; j < NUMBUTOPTIONS ; j++) {
                    997:                                                if (strstr(buf,butoptstr[j]) != NULL) {
                    998:                                                        switch (j) {
                    999:                                                        case OPT_RUN:
                   1000:                                                        case OPT_SHOOT:
                   1001:                                                        case OPT_USEOPEN:
                   1002:                                                        case OPT_JUMP:
                   1003:                                                        case OPT_CROUCH:
                   1004:                                                        case OPT_MAP:
                   1005:                                                        case OPT_MAPZOOMIN:
                   1006:                                                        case OPT_MAPZOOMOUT:
                   1007:                                                                puckbutton[i]=butoptval[j];
                   1008:                                                                break;
                   1009:                                                        }
                   1010:                                                }
                   1011:                                        }
                   1012:                                }
                   1013:                        }
                   1014:                }
                   1015:                fclose(fp);
                   1016:        }
                   1017: #endif
                   1018: #endif
                   1019: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.