/*==========================================================================*\
 | DESQDEMO.C                                             ver 2.0, 12-03-88 |
 |                                                                          |
 | Demo for DESQview interface routines                                     |
 |                                                                          |
 |  It is assumed that you are an operator of DESQview and that you are     |
 |  familiar with its operation.                                            |
 |                                                                          |
 |  TO TEST:                                                                |
 |    1. Build the project file DESQDEMO.PRJ.                               |
 |    2. Build the project file DESQLOOP.PRJ.                               |
 |    3. Add these programs to DV with Direct video = "N".                  |
 |    4. Run DESQloop in one or more windows, say 1 and 2.                  |
 |    5. Run this program in another one, say 3.                            |
 |    6. Observe results.                                                   |
 |                                                                          |
 |  TO USE:                                                                 |
 |    1. Follow instruction provided by DESQview.                           |
 |    2. For high speed buffer writing to a DESQview window, use            |
 |       QWIKC20.ARC.                                                       |
 |                                                                          |
 |  by  James H. LeMay                                                      |
 |                                                                          |
 | converted to Turbo C by                                                  |
 |     Jordan Gallagher                                                     |
 | for Eagle Performance Software                                           |
 |     TC Products                                                          |
 |     P.O. Box 292786                                                      |
 |     Lewisville, TX  75029-2786                                           |
 |                                                                          |
 | Conversion to Turbo C by Jordan Gallagher / Wisdom Research              |
\*==========================================================================*/

#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <dos.h>

#include "desqc20.h"

#define LO_CHAR(v) (v & 0x0f)
#define HI_CHAR(v) (v >> 4)
#define LO_INT(v) (v & 0xff)
#define HI_INT(v) (v >> 8)

char far *videomode=(char far *) 0x00400049L;
int videoseg;
int dv_version;
char str[30];


/********************************| htoa |************************************\
Converts a long to a string.  The target string contains the long in
hexadecimal form, i.e. "21CF89A5".
The parameter hcnt specifies the amount of characters the target
string should contain.
The return value is a pointer to the target string.
\****************************************************************************/
char *htoa( long val, char hcnt, char *string )
{
    if(hcnt > 4)
        sprintf( string, "0x%*lX", hcnt, val );
    else
    if(hcnt > 2)
        sprintf( string, "0x%0*X", hcnt, (int) val );
    else
    if(hcnt <= 2)
        sprintf( string, "0x%0*hX", hcnt, (unsigned char) val );

    return(string);
}


main()
{
    directvideo=0;                /* use BIOS writes */

    if(*videomode == 7) {         /* set to mono or color segment */
        videoseg=0xB000;
    } else {
        videoseg=0xB800;
    }

    videoseg=dv_get_video_buffer( videoseg );
    dv_version=dv_get_version();   /* Optional */

    clrscr();

    if(!in_dv) {
        printf( "DESQview not active\n" );
    } else {
        sprintf( str, "%4.2f", (float) (HI_INT(dv_version) +
                 (float) LO_INT(dv_version) / 100 ) );
        printf( "DESQview version = %s\n", str );
        printf( "Video Segment = %s\n", htoa( videoseg, 4, str ) );
        printf( "First character in row 1 is = %c\n", peekb( videoseg, 0 ) );
        printf( "All windows should now freeze for 3 seconds\n" );
        delay(1000);
        dv_begin_critical();
        delay(3000);
        dv_end_critical();
        printf( "Now all windows will continue.\n" );
        printf( "Test completed.  Scroll back to see row 1." );
    }

    return;
}
