home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-12-27 | 55.2 KB | 2,277 lines |
- Newsgroups: comp.sources.misc
- From: tcamp@hercules.acpub.duke.edu (Ted Campbell)
- Subject: v27i002: sfs - Space Flight Simulator, Part02/21
- Message-ID: <1991Dec24.045100.29424@sparky.imd.sterling.com>
- X-Md4-Signature: aaf99196513687f129d79722a80533a3
- Date: Tue, 24 Dec 1991 04:51:00 GMT
- Approved: kent@sparky.imd.sterling.com
-
- Submitted-by: tcamp@hercules.acpub.duke.edu (Ted Campbell)
- Posting-number: Volume 27, Issue 2
- Archive-name: sfs/part02
- Environment: IBMPC && EGA/VGA, UNIX-PC && MGR, UNIX && X,
-
- #!/bin/sh
- # do not concatenate these parts, unpack them in order with /bin/sh
- # file io/gr/gr_def.c continued
- #
- if test ! -r _shar_seq_.tmp; then
- echo 'Please unpack part 1 first!'
- exit 1
- fi
- (read Scheck
- if test "$Scheck" != 2; then
- echo Please unpack part "$Scheck" next!
- exit 1
- else
- exit 0
- fi
- ) < _shar_seq_.tmp || exit 1
- if test ! -f _shar_wnt_.tmp; then
- echo 'x - still skipping io/gr/gr_def.c'
- else
- echo 'x - continuing file io/gr/gr_def.c'
- sed 's/^X//' << 'SHAR_EOF' >> 'io/gr/gr_def.c' &&
- X def_circle( GR_PRIMARY, x * 5, y * 5, (y/2)*3, WHITE, HATCH );
- X gr_text( GR_PRIMARY, x * 10, y * 5, "Hatch circle", WHITE, BLACK );
- X
- X kb_rx();
- X kb_deinit();
- X gr_deinit();
- X }
- X
- #endif
- X
- /****************************************************************
- X
- X def_line()
- X
- ****************************************************************/
- X
- def_line( screen, x1, y1, x2, y2, color, style )
- X int screen;
- X int x1, y1, x2, y2;
- X int color, style;
- X {
- X register int t, dist;
- X int xerr, yerr, dx, dy, incx, incy;
- X int x_val, y_val;
- X
- #if CHECK_PARAMS
- X if ( ( x1 < 0 ) || ( x1 > main_window.xmax ))
- X {
- X sprintf( bw_ebuf, "[pr:] gr_line(): x1 value is %d", x1 );
- X bw_error( bw_ebuf );
- X return BW_ERROR;
- X }
- X if ( ( x2 < 0 ) || ( x2 > main_window.xmax ))
- X {
- X sprintf( bw_ebuf, "[pr:] gr_line(): x2 value is %d", x2 );
- X bw_error( bw_ebuf );
- X return BW_ERROR;
- X }
- X if ( ( y1 < 0 ) || ( y1 > main_window.ymax ))
- X {
- X sprintf( bw_ebuf, "[pr:] gr_line(): y1 value is %d", y1 );
- X bw_error( bw_ebuf );
- X return BW_ERROR;
- X }
- X if ( ( y2 < 0 ) || ( y2 > main_window.ymax ))
- X {
- X sprintf( bw_ebuf, "[pr:] gr_line(): y2 value is %d", y2 );
- X bw_error( bw_ebuf );
- X return BW_ERROR;
- X }
- #endif
- X
- X xerr = yerr = 0;
- X dx = x2 - x1;
- X dy = y2 - y1;
- X x_val = x1;
- X y_val = y1;
- X
- X if ( dx > 0 )
- X {
- X incx = 1;
- X }
- X else if ( dx == 0 )
- X {
- X incx = 0;
- X }
- X else
- X {
- X incx = -1;
- X }
- X
- X if ( dy > 0 )
- X {
- X incy = 1;
- X }
- X else if ( dy == 0 )
- X {
- X incy = 0;
- X }
- X else
- X {
- X incy = -1;
- X }
- X
- X dx = abs(dx);
- X dy = abs(dy);
- X
- X dist = (dx > dy) ? dx : dy;
- X
- X for ( t = 0; t <= ( dist + 1 ); t++ )
- X {
- X switch( style )
- X {
- X case HOLLOW:
- X gr_pixel( screen, x_val, y_val, BLACK );
- X break;
- X case SOLID:
- X gr_pixel( screen, x_val, y_val, color );
- X break;
- X case GRID:
- X case HATCH:
- X if ( ( ( x_val + y_val ) % 2 ) == 1 )
- X {
- X gr_pixel( screen, x_val, y_val, color );
- X }
- X break;
- X }
- X xerr += dx;
- X yerr += dy;
- X if ( xerr > dist )
- X {
- X xerr -= dist;
- X x_val += incx;
- X }
- X if ( yerr > dist )
- X {
- X yerr -= dist;
- X y_val += incy;
- X }
- X }
- X }
- X
- /****************************************************************
- X
- X def_rectangle()
- X
- ****************************************************************/
- X
- def_rectangle( screen, x1, y1, x2, y2, color, style )
- X int screen;
- X int x1, y1, x2, y2;
- X int color, style;
- X {
- X register int x_val, y_val;
- X
- #if CHECK_PARAMS
- X if ( ( x1 < 0 ) || ( x1 > main_window.xmax ))
- X {
- X sprintf( bw_ebuf, "[pr:] gr_rectangle(): x1 value is %d", x1 );
- X bw_error( bw_ebuf );
- X return BW_ERROR;
- X }
- X if ( ( x2 < 0 ) || ( x2 > main_window.xmax ))
- X {
- X sprintf( bw_ebuf, "[pr:] gr_rectangle(): x2 value is %d", x2 );
- X bw_error( bw_ebuf );
- X return BW_ERROR;
- X }
- X if ( ( y1 < 0 ) || ( y1 > main_window.ymax ))
- X {
- X sprintf( bw_ebuf, "[pr:] gr_rectangle(): y1 value is %d", y1 );
- X bw_error( bw_ebuf );
- X return BW_ERROR;
- X }
- X if ( ( y2 < 0 ) || ( y2 > main_window.ymax ))
- X {
- X sprintf( bw_ebuf, "[pr:] gr_rectangle(): y2 value is %d", y2 );
- X bw_error( bw_ebuf );
- X return BW_ERROR;
- X }
- #endif
- X
- X /* First draw border around the rectangle */
- X
- X gr_line( screen, x1, y1, x2, y1, color, SOLID );
- X gr_line( screen, x2, y1, x2, y2, color, SOLID );
- X gr_line( screen, x1, y1, x1, y2, color, SOLID );
- X gr_line( screen, x1, y2, x2, y2, color, SOLID );
- X
- X switch( style )
- X {
- X case HOLLOW:
- X break;
- X case SOLID:
- X for ( y_val = y1 + 1; y_val < y2; ++y_val )
- X {
- X gr_line( screen, x1 + 1, y_val, x2 - 1, y_val, color, SOLID );
- X }
- X break;
- X case GRID:
- X for ( y_val = y1 + 1; y_val < y2; ++y_val )
- X {
- X gr_line( screen, x1 + 1, y_val, x2 - 1, y_val, color, GRID );
- X }
- X break;
- X case HATCH:
- X for ( y_val = y1 + 1; y_val < y2; ++y_val )
- X {
- X if ( ( y_val % 3 ) == 1 )
- X {
- X gr_line( screen, x1 + 1, y_val, x2 - 1, y_val, color, SOLID );
- X }
- X }
- X for ( x_val = x1 + 1; x_val < x2; ++x_val )
- X {
- X if ( ( x_val % 3 ) == 1 )
- X {
- X gr_line( screen, x_val, y1 + 1, x_val, y2 - 1, color, SOLID );
- X }
- X }
- X break;
- X }
- X
- X }
- X
- /****************************************************************
- X
- X def_circle() Draw circle using gr line routines
- X
- ****************************************************************/
- X
- def_circle( screen, x, y, radius, color, style )
- X int screen;
- X int x, y, radius;
- X int color, style;
- X {
- X register int y_val;
- X int top_y, bot_y, prev_ty, prev_by;
- X int x1, x2, prev_x1, prev_x2;
- X int width, x_val;
- X double angle, y_cor;
- X
- #ifdef OLD_DEBUG
- X sprintf( bw_ebuf, "circle: r %d, y %d, x %d ",
- X radius, y, x );
- X bw_error( bw_ebuf );
- #endif
- #if CHECK_PARAMS
- X if ( ( x < 0 ) || ( x > main_window.xmax ))
- X {
- X sprintf( bw_ebuf, "[pr:] def_circle(): x value is %d", x );
- X bw_error( bw_ebuf );
- X return BW_ERROR;
- X }
- X if ( ( y < 0 ) || ( y > main_window.ymax ))
- X {
- X sprintf( bw_ebuf, "[pr:] def_circle(): y value is %d", y );
- X bw_error( bw_ebuf );
- X return BW_ERROR;
- X }
- #endif
- X
- X width = ( radius * gr_pysize * ACCURACY ) / ( gr_pxsize * ACCURACY );
- X prev_by = prev_ty = bot_y = top_y = y;
- X prev_x1 = x1 = x - width;
- X prev_x2 = x2 = x + width;
- X
- X switch( style )
- X {
- X case HOLLOW:
- X break;
- X case SOLID:
- X gr_line( screen, x1 + 1, top_y, x2 - 1, top_y, color, SOLID );
- X gr_line( screen, x1 + 1, bot_y, x2 - 1, bot_y, color, SOLID );
- X break;
- X case GRID:
- X gr_line( screen, x1 + 1, top_y, x2 - 1, top_y, color, GRID );
- X gr_line( screen, x1 + 1, bot_y, x2 - 1, bot_y, color, GRID );
- X break;
- X case HATCH:
- X if ( ( top_y % 2 ) == 1 )
- X {
- X gr_line( screen, x1 + 1, top_y, x2 - 1, top_y, color, SOLID );
- X gr_line( screen, x1 + 1, bot_y, x2 - 1, bot_y, color, SOLID );
- X }
- X break;
- X }
- X for ( y_val = 1; y_val <= ( radius - 1 ); ++y_val )
- X {
- X top_y = y + y_val;
- X bot_y = y - y_val;
- X
- X y_cor = ( y_val * gr_pysize * ACCURACY ) / ( gr_pxsize * ACCURACY );
- X angle = asin( ( y_cor ) / ((double) width ) );
- X
- #ifdef OLD_DEBUG
- X sprintf( bw_ebuf, "angle %.2lf deg ",
- X angle * RAD_DEG );
- X bw_error( bw_ebuf );
- #endif
- X
- #ifdef OLD_DEBUG
- X sprintf( bw_ebuf, "tan( angle ) %.2lf deg ",
- X tan( angle ) );
- X bw_error( bw_ebuf );
- #endif
- X x_val = (int) ( y_cor / tan( angle ));
- #ifdef OLD_DEBUG
- X sprintf( bw_ebuf, "angle %.2lf deg, y %d, x %d ",
- X angle * RAD_DEG, y_val, x_val );
- X bw_error( bw_ebuf );
- #endif
- X
- X x1 = x - x_val;
- X x2 = x + x_val;
- X
- X gr_line( screen, x2, top_y, prev_x2, prev_ty, color, SOLID );
- X gr_line( screen, x1, top_y, prev_x1, prev_ty, color, SOLID );
- X gr_line( screen, x2, bot_y, prev_x2, prev_by, color, SOLID );
- X gr_line( screen, x1, bot_y, prev_x1, prev_by, color, SOLID );
- X
- X switch( style )
- X {
- X case HOLLOW:
- X break;
- X case SOLID:
- X gr_line( screen, x1 + 1, top_y, x2 - 1, top_y, color, SOLID );
- X gr_line( screen, x1 + 1, bot_y, x2 - 1, bot_y, color, SOLID );
- X break;
- X case GRID:
- X gr_line( screen, x1 + 1, top_y, x2 - 1, top_y, color, GRID );
- X gr_line( screen, x1 + 1, bot_y, x2 - 1, bot_y, color, GRID );
- X break;
- X case HATCH:
- X if ( ( top_y % 2 ) == 1 )
- X {
- X gr_line( screen, x1 + 1, top_y, x2 - 1, top_y, color, SOLID );
- X gr_line( screen, x1 + 1, bot_y, x2 - 1, bot_y, color, SOLID );
- X }
- X break;
- X }
- X
- X prev_x1 = x1;
- X prev_x2 = x2;
- X prev_ty = top_y;
- X prev_by = bot_y;
- X
- X }
- X
- X x2 = x1 = x;
- X top_y = y + radius;
- X bot_y = y - radius;
- X
- X gr_line( screen, x2, top_y, prev_x2, prev_ty, color, SOLID );
- X gr_line( screen, x1, top_y, prev_x1, prev_ty, color, SOLID );
- X gr_line( screen, x2, bot_y, prev_x2, prev_by, color, SOLID );
- X gr_line( screen, x1, bot_y, prev_x1, prev_by, color, SOLID );
- X }
- X
- #ifdef STANDALONE
- X
- bw_error( s )
- X char *s;
- X {
- X gr_text( GR_PRIMARY, 10, 10, s, WHITE, BLACK );
- X kb_rx();
- X }
- X
- #endif
- X
- SHAR_EOF
- echo 'File io/gr/gr_def.c is complete' &&
- chmod 0644 io/gr/gr_def.c ||
- echo 'restore of io/gr/gr_def.c failed'
- Wc_c="`wc -c < 'io/gr/gr_def.c'`"
- test 12686 -eq "$Wc_c" ||
- echo 'io/gr/gr_def.c: original size 12686, current size' "$Wc_c"
- rm -f _shar_wnt_.tmp
- fi
- # ============= io/gr/gr_ibmpc.c ==============
- if test -f 'io/gr/gr_ibmpc.c' -a X"$1" != X"-c"; then
- echo 'x - skipping io/gr/gr_ibmpc.c (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting io/gr/gr_ibmpc.c (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'io/gr/gr_ibmpc.c' &&
- /****************************************************************
- X
- X gr_ibmpc.c Implementation of Bywater Graphics Interface
- X for IBM PC (tm) and compatibles
- X utilizing Microsoft QuickC (tm)
- X
- X Copyright (c) 1991, Ted A. Campbell
- X
- X Bywater Software
- X P. O. Box 4023
- X Duke Station
- X Durham, NC 27706
- X
- X email: tcamp@hercules.acpub.duke.edu
- X
- X Copyright and Permissions Information:
- X
- X All U.S. and international copyrights are claimed by the
- X author. The author grants permission to use this code
- X and software based on it under the following conditions:
- X (a) in general, the code and software based upon it may be
- X used by individuals and by non-profit organizations; (b) it
- X may also be utilized by governmental agencies in any country,
- X with the exception of military agencies; (c) the code and/or
- X software based upon it may not be sold for a profit without
- X an explicit and specific permission from the author, except
- X that a minimal fee may be charged for media on which it is
- X copied, and for copying and handling; (d) the code must be
- X distributed in the form in which it has been released by the
- X author; and (e) the code and software based upon it may not
- X be used for illegal activities.
- X
- ****************************************************************/
- X
- #include "stdio.h"
- #include "dos.h"
- #include "graph.h"
- #include "bw.h"
- #include "gr.h"
- #include "malloc.h"
- X
- /*#define DEBUG */ /* Include Debugging info */
- #define SET_MONOVGA FALSE
- #define CHECK_PARAMS TRUE
- #define LINE_BLIT TRUE
- #define SIGNON FALSE
- #define DEF_LINE FALSE
- #define DEF_RECTANGLE FALSE
- #define DEF_CIRCLE FALSE
- #define HMP_RATIO 8 /* Horizontal Mickey/Pixel Ratio */
- #define VMP_RATIO 16 /* Vertical Mickey/Pixel Ratio */
- #define ACC 30
- #define IMAGES 64
- X
- int gr_screens;
- int gr_colors;
- int gr_pxsize;
- int gr_pysize;
- int gr_ismouse;
- int gr_clipping = TRUE;
- int gr_blitting;
- int gr_saving = TRUE;
- X
- struct gr_window *ibm_window; /* structure for window info */
- int ibm_px; /* relative size of pixel, x axis */
- int ibm_py; /* relative size of pixel, y axis */
- int ibm_vmode; /* video mode for IBM equipment */
- int ibm_imode; /* initial video mode */
- int ibm_ishidden = FALSE; /* boolean: is display "hidden" */
- struct videoconfig
- X ibm_vc; /* internal structure for video configuration */
- int msm_exist = FALSE; /* boolean: is there a mouse? */
- long miaddr; /* mouse interupt routine address */
- union REGS ibm_registers; /* cpu register for use of DOS calls */
- struct SREGS segreg; /* cpu segment registers */
- static int msm_buttons; /* number of buttons on the mouse */
- char far *hgc_location; /* location to change for Hercules */
- static int msm_oldbut; /* previous state of mouse buttons */
- static int msm_showcounter; /* keep track of mouse show status */
- static int m_col, m_row; /* current column, row */
- static int m_but; /* right button depressed */
- char fontfile[12] = "*.fon";
- char *ibm_images[ IMAGES ]; /* array of pointers to image buffers */
- X
- #if LINE_BLIT
- char far *xfr_mem;
- #else
- char huge *xfr_mem;
- #endif
- X
- unsigned char fs[ 20 ];
- X
- unsigned char fr[ 40 ];
- X
- struct _fontinfo fi;
- X
- /*** Define fill grids ***/
- X
- char _fill_blank[ 8 ] = { 0, 0, 0, 0, 0, 0, 0, 0 };
- char _fill_grid[ 8 ] = { 170, 85, 170, 85, 170, 85, 170, 85 };
- char _fill_full[ 8 ] = { 255, 255, 255, 255, 255, 255, 255, 255 };
- char _fill_hatch[ 8 ] = { 17, 255, 68, 68, 68, 255, 17, 17 };
- X
- /****************************************************************
- X
- X gr_init()
- X
- ****************************************************************/
- X
- gr_init( window, font_path )
- X struct gr_window *window;
- X char *font_path;
- X {
- X int font_ret;
- X static char ff[ 64 ];
- X register int i;
- X
- X ibm_window = window;
- X
- X /* Set font */
- X
- X if ( font_path != NULL )
- X {
- X sprintf( ff, "%s%s", font_path, fontfile );
- X }
- X else
- X {
- X strcpy( ff, fontfile );
- X }
- X
- X if ( ( font_ret = _registerfonts( ff ) ) <= 0 )
- X {
- X strcpy ( ff, "../../fonts" );
- X if ( ( font_ret = _registerfonts( ff ) ) <= 0 )
- X {
- X fprintf( stderr, "Can't find font files (path: %s).\n", ff );
- X exit( 0 );
- X }
- X }
- X
- X /* Get the video configuration to learn about hardware */
- X
- X _getvideoconfig( &ibm_vc );
- X ibm_imode = ibm_vc.mode;
- X
- X switch( ibm_vc.adapter )
- X {
- X case _HGC:
- X ibm_vmode = _HERCMONO;
- X ibm_px = 30;
- X ibm_py = 45;
- X break;
- X case _CGA:
- X case _OCGA:
- X ibm_vmode = _HRESBW;
- X ibm_px = 29;
- X ibm_py = 69;
- X break;
- X case _VGA:
- X case _OVGA:
- X case _MCGA:
- X case _EGA:
- X case _OEGA:
- X ibm_vmode = _ERESCOLOR;
- #ifdef OLD_DEBUG
- X fprintf( stderr, "VGA: monitor is %d \n", ibm_vc.adapter );
- X getchar();
- #endif
- X ibm_px = 40;
- X ibm_py = 50;
- X break;
- X default:
- X printf( "An appropriate video mode could not be located\n" );
- X exit( 0 );
- X break;
- X }
- X
- X /* If there is a mouse, initialize it now */
- X
- X msm_init();
- X
- X /* set the video mode */
- X
- X if ( ibm_imode != ibm_vmode )
- X {
- X _setvideomode( ibm_vmode );
- #ifdef OLD_DEBUG
- X fprintf( stderr, "INIT....." );
- X getchar();
- #endif
- X }
- X else
- X {
- #ifdef OLD_DEBUG
- X fprintf( stderr, "No need to initialize....." );
- X getchar();
- #endif
- X }
- X
- X /* Get the video configuration again */
- X
- X _getvideoconfig( &ibm_vc );
- X
- X /* allocate transfer memory area */
- X
- #if LINE_BLIT
- X if ( ( xfr_mem = malloc( (size_t) _imagesize( 0, 0,
- X ibm_vc.numxpixels, 1 ) )) == NULL )
- #else
- X if ( ( xfr_mem
- X = halloc( (long) 1, (size_t) _imagesize( 0, ibm_vc.numypixels,
- X ibm_vc.numxpixels, 0 ) )) == NULL )
- #endif
- X {
- X gr_deinit();
- X fprintf( stderr,
- X "gr: failed to allocate memory for transfer buffer\n" );
- X exit( 0 );
- X }
- X
- X /* Reset mouse cursor lines + columns */
- X
- X if ( msm_exist == TRUE )
- X {
- #ifdef WHYDOTHIS
- X msm_position( 0, 0 );
- #endif
- X msm_showcounter = -1;
- X msm_show();
- X gr_ismouse = TRUE;
- #ifdef OLD_DEBUG
- X fprintf( stderr, "yes, virginia, there is a mouse...\n" );
- X kb_rx();
- #endif
- X }
- X else
- X {
- X gr_ismouse = FALSE;
- X }
- X
- #ifdef REALLYLETSDONTDOTHIS
- X _setactivepage ( 0 );
- X _clearscreen( _GCLEARSCREEN );
- X _setactivepage ( 1 );
- X _clearscreen( _GCLEARSCREEN );
- #endif
- X _setactivepage ( 0 );
- X _setvisualpage ( 0 );
- X
- X /* Transfer video configuration information to the gr_window struct */
- X
- X window->initialized = TRUE;
- X window->xmax = ibm_vc.numxpixels - 1;
- X window->ymax = ibm_vc.numypixels - 1;
- X gr_screens = ibm_vc.numvideopages;
- X if ( gr_screens > 1 )
- X {
- X gr_blitting = TRUE;
- X }
- X else
- X {
- X gr_blitting = FALSE;
- X }
- X
- #if SET_MONOVGA
- X if ( ( ibm_vmode == _ERESCOLOR ) && ( ibm_vc.adapter == _ANALOGMONO ))
- X {
- X gr_colors = 2; /* for mono VGA */
- X }
- X else
- X {
- X gr_colors = ibm_vc.numcolors;
- X }
- #else
- X gr_colors = ibm_vc.numcolors;
- #endif
- X
- X gr_pxsize = ibm_px;
- X gr_pysize = ibm_py;
- X
- X /* gr signon message */
- X
- #if SIGNON
- X
- X printf( "Bywater Graphics Interface Standard Implementation\n" );
- X printf( "Copyright (c) 1990, Ted A. Campbell\n" );
- X switch( ibm_vmode )
- X {
- X case _HERCMONO:
- X printf( "Hercules (tm) " );
- X break;
- X case _HRESBW:
- X printf( "CGA " );
- X break;
- X case _ERESCOLOR:
- X printf( "EGA or VGA " );
- X break;
- X }
- X printf( "or compatible graphics detected\n" );
- X printf( "%dx%d pixels resolution in %d colors\n",
- X ibm_vc.numxpixels, ibm_vc.numypixels, ibm_vc.numcolors );
- X printf( "%d kbytes of video RAM in %d video page(s)\n",
- X ibm_vc.memory, ibm_vc.numvideopages );
- X if ( msm_exist != FALSE )
- X {
- X printf( "Mouse device detected. \n" );
- X }
- X printf( "Please wait while font is loaded...\n" );
- X
- #endif
- X
- X /* set image buffer pointers to NULL */
- X
- X for ( i = 0; i < IMAGES; ++i )
- X {
- X ibm_images[ i ] = NULL;
- X }
- X
- X ibm_screen( GR_PRIMARY );
- X gr_font( GR_PRIMARY, F_DEFAULT, ibm_vc.numypixels / 25 );
- X
- X }
- X
- /****************************************************************
- X
- X gr_deinit()
- X
- ****************************************************************/
- X
- gr_deinit()
- X {
- #if LINE_BLIT
- X _ffree( xfr_mem );
- #else
- X hfree( xfr_mem );
- #endif
- X
- X /* hide the mouse in case we are returning to a graphics-based
- X program that uses the mouse */
- X
- X msm_hide();
- X
- X /* reset video mode if necessary */
- X
- X if ( ibm_vmode != ibm_imode )
- X {
- X _setvideomode( _DEFAULTMODE );
- #ifdef OLD_DEBUG
- X fprintf( stderr, "Deinitialized....." );
- X getchar();
- #endif
- X }
- X else
- X {
- #ifdef OLD_DEBUG
- X fprintf( stderr, "No need to deinitialize....." );
- X getchar();
- #endif
- X }
- X }
- X
- /****************************************************************
- X
- X gr_cls()
- X
- ****************************************************************/
- X
- gr_cls( screen )
- X int screen;
- X {
- X ibm_screen( screen );
- X if ( screen != GR_HIDDEN )
- X {
- X msm_hide();
- X }
- X _clearscreen( _GCLEARSCREEN );
- X if ( screen != GR_HIDDEN )
- X {
- X msm_show();
- X }
- X }
- X
- /****************************************************************
- X
- X gr_pixel()
- X
- ****************************************************************/
- X
- gr_pixel( screen, x, y, color )
- X int screen;
- X int x, y;
- X int color;
- X {
- X
- #if CHECK_PARAMS
- X if ( ( x < 0 ) || ( x > ibm_window->xmax ))
- X {
- X sprintf( bw_ebuf, "[pr:] gr_pixel(): x value is %d", x );
- X bw_error( bw_ebuf );
- X return BW_ERROR;
- X }
- X if ( ( y < 0 ) || ( y > ibm_window->ymax ))
- X {
- X sprintf( bw_ebuf, "[pr:] gr_pixel(): y value is %d", y );
- X bw_error( bw_ebuf );
- X return BW_ERROR;
- X }
- #endif
- X
- X ibm_screen( screen );
- X if ( screen != GR_HIDDEN )
- X {
- X msm_hide();
- X }
- X _setcolor( ibm_color( color ) );
- X _setpixel( x, ibm_window->ymax - y );
- X if ( screen != GR_HIDDEN )
- X {
- X msm_show();
- X }
- X }
- X
- /****************************************************************
- X
- X gr_line()
- X
- ****************************************************************/
- X
- gr_line( screen, x1, y1, x2, y2, color, style )
- X int screen;
- X int x1, y1, x2, y2;
- X int color, style;
- X {
- X
- #if CHECK_PARAMS
- X if ( ( x1 < 0 ) || ( x1 > ibm_window->xmax ))
- X {
- X sprintf( bw_ebuf, "[pr:] gr_line(): x1 value is %d", x1 );
- X bw_error( bw_ebuf );
- X return BW_ERROR;
- X }
- X if ( ( x2 < 0 ) || ( x2 > ibm_window->xmax ))
- X {
- X sprintf( bw_ebuf, "[pr:] gr_line(): x2 value is %d", x2 );
- X bw_error( bw_ebuf );
- X return BW_ERROR;
- X }
- X if ( ( y1 < 0 ) || ( y1 > ibm_window->ymax ))
- X {
- X sprintf( bw_ebuf, "[pr:] gr_line(): y1 value is %d", y1 );
- X bw_error( bw_ebuf );
- X return BW_ERROR;
- X }
- X if ( ( y2 < 0 ) || ( y2 > ibm_window->ymax ))
- X {
- X sprintf( bw_ebuf, "[pr:] gr_line(): y2 value is %d", y2 );
- X bw_error( bw_ebuf );
- X return BW_ERROR;
- X }
- #endif
- X
- #if DEF_LINE
- X def_line( screen, x1, y1, x2, y2, color, style );
- #else
- X ibm_screen( screen );
- X _setcolor( ibm_color( color ));
- X switch( style )
- X {
- X case HOLLOW:
- X _setlinestyle( 0 );
- X break;
- X case GRID:
- X case HATCH:
- X _setlinestyle( 85 + (256*85) );
- X break;
- X default: /* SOLID is default */
- X _setlinestyle( 0xffff );
- X break;
- X }
- X _moveto( x1, ibm_window->ymax - y1 );
- X if ( screen != GR_HIDDEN )
- X {
- X msm_hide();
- X }
- X _lineto( x2, ibm_window->ymax - y2 );
- X if ( screen != GR_HIDDEN )
- X {
- X msm_show();
- X }
- #endif
- X }
- X
- /****************************************************************
- X
- X gr_text()
- X
- ****************************************************************/
- X
- gr_text( screen, x, y, string, foreground, background )
- X int screen;
- X int x, y;
- X int foreground, background;
- X char *string;
- X {
- X
- #if CHECK_PARAMS
- X if ( ( x < 0 ) || ( x > ibm_window->xmax ))
- X {
- X sprintf( bw_ebuf, "[pr:] gr_text(): x value is %d", x );
- X bw_error( bw_ebuf );
- X return BW_ERROR;
- X }
- X if ( ( y < 0 ) || ( y > ibm_window->ymax ))
- X {
- X sprintf( bw_ebuf, "[pr:] gr_text(): y value is %d", y );
- X bw_error( bw_ebuf );
- X return BW_ERROR;
- X }
- #endif
- X
- X ibm_screen( screen );
- X
- X _setcolor( ibm_color( background ) );
- X _setbkcolor( (long) ibm_color( background ) );
- X _setfillmask( _fill_full );
- X _setlinestyle( 0xffff );
- X
- X if ( screen != GR_HIDDEN )
- X {
- X msm_hide();
- X }
- X
- X _rectangle( _GFILLINTERIOR, x,
- X ibm_window->ymax - ( y + ibm_window->fysize ),
- X x + ((int) _getgtextextent( ((unsigned char far *) string ) )) + 1,
- X ibm_window->ymax - ( y ) );
- X _moveto( x, ibm_window->ymax - ( y + ibm_window->fysize ) );
- X _setcolor( ibm_color( foreground ) );
- X _outgtext( string );
- X
- X if ( screen != GR_HIDDEN )
- X {
- X msm_show();
- X }
- X }
- X
- /****************************************************************
- X
- X gr_strlen()
- X
- ****************************************************************/
- X
- unsigned int
- gr_strlen( string )
- X char *string;
- X {
- X int r;
- X
- X r = (unsigned int) _getgtextextent( ((unsigned char far *) string ) );
- #ifdef DEBUG
- X if ( r < 0 )
- X {
- X sprintf( bw_ebuf, "_getgtextent() returned error, string [%s]",
- X string );
- X bw_error( bw_ebuf );
- X }
- #endif
- X return r;
- X }
- X
- /****************************************************************
- X
- X gr_rectangle()
- X
- ****************************************************************/
- X
- gr_rectangle( screen, x1, y1, x2, y2, color, style )
- X int screen;
- X int x1, y1, x2, y2;
- X int color, style;
- X {
- X static short _control;
- X char *_fill_interior;
- X
- #if CHECK_PARAMS
- X if ( ( x1 < 0 ) || ( x1 > ibm_window->xmax ))
- X {
- X sprintf( bw_ebuf, "[pr:] gr_rectangle(): x1 value is %d", x1 );
- X bw_error( bw_ebuf );
- X return BW_ERROR;
- X }
- X if ( ( x2 < 0 ) || ( x2 > ibm_window->xmax ))
- X {
- X sprintf( bw_ebuf, "[pr:] gr_rectangle(): x2 value is %d", x2 );
- X bw_error( bw_ebuf );
- X return BW_ERROR;
- X }
- X if ( ( y1 < 0 ) || ( y1 > ibm_window->ymax ))
- X {
- X sprintf( bw_ebuf, "[pr:] gr_rectangle(): y1 value is %d", y1 );
- X bw_error( bw_ebuf );
- X return BW_ERROR;
- X }
- X if ( ( y2 < 0 ) || ( y2 > ibm_window->ymax ))
- X {
- X sprintf( bw_ebuf, "[pr:] gr_rectangle(): y2 value is %d", y2 );
- X bw_error( bw_ebuf );
- X return BW_ERROR;
- X }
- #endif
- X
- #if DEF_RECTANGLE
- X def_rectangle( screen, x1, y1, x2, y2, color, style );
- #else
- X ibm_screen( screen );
- X
- X switch( style )
- X {
- X case 0:
- X _fill_interior = _fill_blank;
- X break;
- X case 2:
- X _fill_interior = _fill_grid;
- X break;
- X case 3:
- X _fill_interior = _fill_hatch;
- X break;
- X default:
- X _fill_interior = _fill_full;
- X break;
- X }
- X if ( style == HOLLOW )
- X {
- X _control = _GBORDER;
- X }
- X else
- X {
- X _control = _GFILLINTERIOR;
- X }
- X _setcolor( ibm_color( color ) );
- X _setfillmask( _fill_interior );
- X if ( screen != GR_HIDDEN )
- X {
- X msm_hide();
- X }
- X _rectangle( _control, x1,
- X ibm_window->ymax - y1,
- X x2,
- X ibm_window->ymax - y2 );
- X if ( screen != GR_HIDDEN )
- X {
- X msm_show();
- X }
- #endif
- X }
- X
- /****************************************************************
- X
- X gr_circle()
- X
- ****************************************************************/
- X
- gr_circle( screen, x, y, radius, color, style )
- X int screen;
- X int x, y, radius;
- X int color, style;
- X {
- X register int xradius;
- X static short _control;
- X char *_fill_interior;
- X
- #if CHECK_PARAMS
- X if ( ( x < 0 ) || ( x > ibm_window->xmax ))
- X {
- X sprintf( bw_ebuf, "[pr:] gr_circle(): x value is %d", x );
- X bw_error( bw_ebuf );
- X return BW_ERROR;
- X }
- X if ( ( y < 0 ) || ( y > ibm_window->ymax ))
- X {
- X sprintf( bw_ebuf, "[pr:] gr_circle(): y value is %d", y );
- X bw_error( bw_ebuf );
- X return BW_ERROR;
- X }
- #endif
- X
- #if DEF_CIRCLE
- X def_circle( screen, x, y, radius, color, style );
- #else
- X ibm_screen( screen );
- X
- X xradius = ( radius * gr_pysize ) / gr_pxsize;
- X
- X switch( style )
- X {
- X case 0:
- X _fill_interior = _fill_blank;
- X break;
- X case 2:
- X _fill_interior = _fill_grid;
- X break;
- X case 3:
- X _fill_interior = _fill_hatch;
- X break;
- X default:
- X _fill_interior = _fill_full;
- X break;
- X }
- X if ( style == HOLLOW )
- X {
- X _control = _GBORDER;
- X }
- X else
- X {
- X _control = _GFILLINTERIOR;
- X }
- X _setcolor( ibm_color( color ) );
- X _setfillmask( _fill_interior );
- X if ( screen != GR_HIDDEN )
- X {
- X msm_hide();
- X }
- X _ellipse( _control, x - xradius,
- X ibm_window->ymax - ( y + radius),
- X x + xradius,
- X ibm_window->ymax - ( y - radius ));
- X if ( screen != GR_HIDDEN )
- X {
- X msm_show();
- X }
- #endif
- X }
- X
- /****************************************************************
- X
- X gr_ellipse()
- X
- ****************************************************************/
- X
- gr_ellipse( screen, x, y, x_radius, y_radius, mode, color, style )
- X int screen;
- X int x, y, x_radius, y_radius;
- X int mode, color, style;
- X {
- X }
- X
- /****************************************************************
- X
- X gr_clip()
- X
- ****************************************************************/
- X
- gr_clip( screen, mode, x1, y1, x2, y2 )
- X int screen;
- X int mode;
- X int x1, y1, x2, y2;
- X {
- X
- #if CHECK_PARAMS
- X if ( ( x1 < 0 ) || ( x1 > ibm_window->xmax ))
- X {
- X sprintf( bw_ebuf, "[pr:] gr_clip(): x1 value is %d", x1 );
- X bw_error( bw_ebuf );
- X return BW_ERROR;
- X }
- X if ( ( x2 < 0 ) || ( x2 > ibm_window->xmax ))
- X {
- X sprintf( bw_ebuf, "[pr:] gr_clip(): x2 value is %d", x2 );
- X bw_error( bw_ebuf );
- X return BW_ERROR;
- X }
- X if ( ( y1 < 0 ) || ( y1 > ibm_window->ymax ))
- X {
- X sprintf( bw_ebuf, "[pr:] gr_clip(): y1 value is %d", y1 );
- X bw_error( bw_ebuf );
- X return BW_ERROR;
- X }
- X if ( ( y2 < 0 ) || ( y2 > ibm_window->ymax ))
- X {
- X sprintf( bw_ebuf, "[pr:] gr_clip(): y2 value is %d", y2 );
- X bw_error( bw_ebuf );
- X return BW_ERROR;
- X }
- #endif
- X
- X ibm_screen( screen );
- X if ( mode == FALSE )
- X {
- X _setcliprgn( 0, 0, ibm_window->xmax - 1,
- X ibm_window->ymax - 1 );
- X ibm_window->clipping = FALSE;
- X return TRUE;
- X }
- X else
- X {
- X _setcliprgn( x1, ibm_window->ymax - y2,
- X x2, ibm_window->ymax - y1 );
- X ibm_window->clipping = TRUE;
- X ibm_window->cl_x1 = x1;
- X ibm_window->cl_y1 = y1;
- X ibm_window->cl_x2 = x2;
- X ibm_window->cl_y2 = y2;
- X return TRUE;
- X }
- X }
- X
- /****************************************************************
- X
- X gr_font()
- X
- ****************************************************************/
- X
- gr_font( screen, type, rq_height )
- X int screen;
- X int type, rq_height;
- X {
- X static char fs[ 48 ];
- X static int current_type = 0;
- X static int current_height = 0;
- X static struct _fontinfo fi;
- X int x;
- X
- X ibm_screen( screen );
- X
- X if ( ( current_type == type ) && ( current_height == rq_height ) )
- X {
- X return BW_ERROR;
- X }
- X
- X /* first try a bit-mapped (raster-mapped) font */
- X
- X sprintf( fs, "h%dw%dbr", rq_height, ( rq_height * 2 ) / 3 );
- X x = _setfont( fs );
- X _getfontinfo( &fi );
- X ibm_window->fysize = fi.pixheight;
- X ibm_window->fxsize = fi.avgwidth;
- X
- X /* if this fails ( greater than 5 pixels different than request),
- X then try a vector font */
- X
- X if ( abs( fi.pixheight - rq_height ) > 3 )
- X {
- X sprintf( fs, "h%dw%dbv", rq_height, ( rq_height * 2 ) / 3 );
- X x = _setfont( fs );
- X _getfontinfo( &fi );
- X ibm_window->fysize = rq_height;
- X ibm_window->fxsize = ( rq_height * 2 ) / 3;
- X }
- X
- #ifdef OLD_DEBUG
- X printf( "Request for font: %s\n", fs );
- X printf( "_setfont() returned: %d\n", x );
- X printf( "fontinfo: Height, %d Width, %d Ascent %d \n",
- X fi.pixheight,
- X fi.avgwidth, fi.ascent );
- X getch();
- #endif
- X }
- X
- /****************************************************************
- X
- X gr_blit()
- X
- ****************************************************************/
- X
- gr_blit( src, dst, x1, y1, x2, y2 )
- X int src, dst;
- X int x1, y1, x2, y2;
- X {
- #if LINE_BLIT
- X register int l;
- #endif
- X
- #if CHECK_PARAMS
- X if ( ( x1 < 0 ) || ( x1 > ibm_window->xmax ))
- X {
- X sprintf( bw_ebuf, "[pr:] gr_blit(): x1 value is %d", x1 );
- X bw_error( bw_ebuf );
- X return BW_ERROR;
- X }
- X if ( ( x2 < 0 ) || ( x2 > ibm_window->xmax ))
- X {
- X sprintf( bw_ebuf, "[pr:] gr_blit(): x2 value is %d", x2 );
- X bw_error( bw_ebuf );
- X return BW_ERROR;
- X }
- X if ( ( y1 < 0 ) || ( y1 > ibm_window->ymax ))
- X {
- X sprintf( bw_ebuf, "[pr:] gr_blit(): y1 value is %d", y1 );
- X bw_error( bw_ebuf );
- X return BW_ERROR;
- X }
- X if ( ( y2 < 0 ) || ( y2 > ibm_window->ymax ))
- X {
- X sprintf( bw_ebuf, "[pr:] gr_blit(): y2 value is %d", y2 );
- X bw_error( bw_ebuf );
- X return BW_ERROR;
- X }
- X if ( src == dst )
- X {
- X sprintf( bw_ebuf, "[pr:] gr_blit(): src == dst" );
- X bw_error( bw_ebuf );
- X return BW_ERROR;
- X }
- #endif
- X
- X if ( ibm_vc.numvideopages > 1 )
- X {
- X msm_hide();
- X
- X /* if the area is the entire screen, use fast blit routine */
- X
- X if ( ( ( x2 - x1 ) == ibm_window->xmax )
- X && ( ( y2 - y1 ) == ibm_window->ymax ))
- X {
- #ifdef OLD_DEBUG
- X fprintf( stderr, "This is the fast blit routine. \n" );
- X getch();
- #endif
- X if ( src == GR_PRIMARY )
- X {
- X if ( ibm_vmode == _HERCMONO )
- X {
- X movedata( (unsigned int) 0xb000, /* source segment */
- X (unsigned int) 0x0000, /* source offset */
- X (unsigned int) 0xb800, /* dest segment */
- X (unsigned int) 0x0000, /* dest offset */
- X (unsigned) 0x8000 ); /* number bytes */
- X }
- X else if ( ibm_vmode == _ERESCOLOR )
- X {
- X outp(0x3ce, 0x05); /* Mode register select */
- X outp(0x3cf, 0x01); /* Select write mode 1 */
- X outp(0x3ce, 0x03); /* Merge mode */
- X outp(0x3cf, 0x00); /* Replace mode */
- X outp(0x3ce, 0x03); /* Bit Mask register */
- X outp(0x3cf, 0xff); /* Select all bits */
- X movedata( 0xA000, 0x0000, 0xA800, 0x0000, 0x8000 );
- X }
- X }
- X else
- X {
- X if ( ibm_vmode == _HERCMONO )
- X {
- X movedata( (unsigned int) 0xb800,
- X (unsigned int) 0x0000,
- X (unsigned int) 0xb000,
- X (unsigned int) 0x0000,
- X (unsigned) 0x8000 );
- X
- X }
- X if ( ibm_vmode == _ERESCOLOR )
- X {
- X outp(0x3ce, 0x05); /* Mode register select */
- X outp(0x3cf, 0x01); /* Select write mode 1 */
- X outp(0x3ce, 0x03); /* Merge mode */
- X outp(0x3cf, 0x00); /* Replace mode */
- X outp(0x3ce, 0x03); /* Bit Mask register */
- X outp(0x3cf, 0xff); /* Select all bits */
- X movedata( 0xA800, 0x0000, 0xA000, 0x0000, 0x8000 );
- X }
- X }
- X }
- X
- X /* The area is not the complete screen; blit only part of it */
- X
- X else
- X {
- #ifdef OLD_DEBUG
- X fprintf( stderr, "DEBUG: imsize will be %ld bytes \n",
- X _imagesize( x1, y2, x2, y1 ) );
- X getch();
- #endif
- X
- #if LINE_BLIT
- X for ( l = y2; l >= y1; --l )
- X {
- X ibm_screen( src );
- X _getimage( x1, ibm_window->ymax - l, x2, ibm_window->ymax - l,
- X xfr_mem );
- X ibm_screen( dst );
- X _putimage( x1, ibm_window->ymax - l, xfr_mem, _GPSET );
- X }
- #else
- X ibm_screen( src );
- X _getimage( x1, ibm_window->ymax - y2, x2, ibm_window->ymax - y1,
- X xfr_mem );
- X ibm_screen( dst );
- X _putimage( x1, ibm_window->ymax - y2, xfr_mem, _GPSET );
- #endif
- X }
- X }
- X msm_show();
- X return TRUE;
- X }
- X
- /****************************************************************
- X
- X gr_imsave()
- X
- ****************************************************************/
- X
- gr_imsave( screen, mode, x1, y1, x2, y2, image )
- X int screen;
- X int mode, x1, y1, x2, y2;
- X int *image;
- X {
- X register int r;
- X int carry_on;
- X
- #if CHECK_PARAMS
- X if ( ( x1 < 0 ) || ( x1 > ibm_window->xmax ))
- X {
- X sprintf( bw_ebuf, "[pr:] gr_save(): x1 value is %d", x1 );
- X bw_error( bw_ebuf );
- X return BW_ERROR;
- X }
- X if ( ( x2 < 0 ) || ( x2 > ibm_window->xmax ))
- X {
- X sprintf( bw_ebuf, "[pr:] gr_save(): x2 value is %d", x2 );
- X bw_error( bw_ebuf );
- X return BW_ERROR;
- X }
- X if ( ( y1 < 0 ) || ( y1 > ibm_window->ymax ))
- X {
- X sprintf( bw_ebuf, "[pr:] gr_save(): y1 value is %d", y1 );
- X bw_error( bw_ebuf );
- X return BW_ERROR;
- X }
- X if ( ( y2 < 0 ) || ( y2 > ibm_window->ymax ))
- X {
- X sprintf( bw_ebuf, "[pr:] gr_save(): y2 value is %d", y2 );
- X bw_error( bw_ebuf );
- X return BW_ERROR;
- X }
- #endif
- X
- X ibm_screen( screen );
- X
- X msm_hide();
- X
- X switch ( mode )
- X {
- X case TRUE: /* TRUE = SAVE image */
- #ifdef OLD_DEBUG
- X printf( "DEBUG: saving screen %d, %d %d %d %d\n", screen, x1, y1,
- X x2, y2 );
- X getch();
- #endif
- X
- X /* find an available buffer */
- X
- X carry_on = TRUE;
- X r = 0;
- X while( ( carry_on == TRUE ) && ( r < IMAGES ) )
- X {
- X if ( ibm_images[ r ] == NULL )
- X {
- X carry_on = FALSE;
- X }
- X else
- X {
- X ++r;
- X }
- X }
- X
- X if ( r >= IMAGES )
- X {
- X bw_error( "No more slots for image storage" );
- X return FALSE;
- X }
- X
- X *image = r;
- X
- X /* get memory */
- X
- X if ( ( ibm_images[ *image ] = malloc( (size_t) _imagesize(
- X x1, ibm_window->ymax - y2,
- X x2, ibm_window->ymax - y1 ) ) ) == NULL )
- X {
- X bw_error( "Out of memory to store image" );
- X return FALSE;
- X }
- X
- X /* save the image */
- X
- X _getimage( x1, ( ibm_window->ymax ) - y2, x2,
- X ( ibm_window->ymax ) - y1,
- X ibm_images[ *image ] );
- X
- X break;
- X
- X case FALSE: /* FALSE = RESTORE image */
- X
- #ifdef OLD_DEBUG
- X printf( "DEBUG: restoring screen %d, %d %d %d %d\n", screen,
- X x1, y1, x2, y2 );
- X getch();
- #endif
- X
- #ifdef DEBUG
- X if ( ibm_images[ *image ] == NULL )
- X {
- X bw_error( "gr_imsave(): NULL image requested" );
- X return FALSE;
- X }
- #endif
- X
- X _putimage( x1, ibm_window->ymax - y2, ibm_images[ *image ], _GPSET );
- X break;
- X default:
- #ifdef DEBUG
- X bw_error( "[pr:] gr_save(): incorrect mode" );
- #endif
- X msm_show();
- X return BW_ERROR;
- X break;
- X }
- X
- X msm_show();
- X }
- X
- /****************************************************************
- X
- X gr_imfree()
- X
- ****************************************************************/
- X
- gr_imfree( image )
- X int image;
- X {
- X
- #ifdef DEBUG
- X if ( ibm_images[ image ] == NULL )
- X {
- X bw_error( "gr_imfree(): NULL image requested" );
- X return FALSE;
- X }
- #endif
- X
- X free( ibm_images[ image ] );
- X ibm_images[ image ] = NULL;
- X
- X }
- X
- /****************************************************************
- X
- X gr_mouse()
- X
- ****************************************************************/
- X
- gr_mouse( mode, x, y, buttons )
- X int mode;
- X int *x, *y;
- X int *buttons;
- X {
- X static int m_pending = FALSE, y_pos = 0, x_pos = 0;
- X
- X switch( mode )
- X {
- X case HIDE:
- X msm_hide();
- X break;
- X case SHOW:
- X msm_show();
- X break;
- X case POSITION:
- X msm_hide();
- X msm_position( ibm_window->ymax - *y, *x );
- X msm_show();
- X break;
- X case STATUS:
- X case SAMPLE:
- X if ( m_pending == TRUE )
- X {
- X return TRUE;
- X }
- X if ( msm_read() == TRUE )
- X {
- X x_pos = *x = m_col;
- X y_pos = *y = m_row;
- X m_pending = TRUE;
- X return TRUE;
- X }
- X else
- X {
- X x_pos = *x = m_col;
- X y_pos = *y = m_row;
- X return BW_ERROR;
- X }
- X break;
- X case WAIT:
- X if ( m_pending == TRUE )
- X {
- X m_pending = FALSE;
- X *x = x_pos;
- X *y = y_pos;
- X return TRUE;
- X }
- X while( msm_read() == FALSE )
- X {
- X ;
- X }
- X *x = x_pos = m_col;
- X *y = y_pos = m_row;
- X return TRUE;
- X break;
- X default:
- X break;
- X }
- X }
- X
- /****************************************************************
- X
- X ibm_ IBM PC (tm) specific routines
- X
- ****************************************************************/
- X
- ibm_screen( screen )
- X int screen;
- X {
- X static int x_screen = 599;
- X
- #if CHECK_PARAMS
- X if ( ( screen < 0 ) || ( screen > GR_HIDDEN ))
- X {
- X sprintf( bw_ebuf, "[pr:] ibm_screen(): incorrect screen number %d",
- X screen );
- X bw_error( bw_ebuf );
- X }
- #endif
- X
- X if ( screen != x_screen )
- X {
- X _setactivepage( screen );
- X x_screen = screen;
- X }
- X }
- X
- ibm_color( color )
- X int color;
- X {
- X switch( color )
- X {
- X case 0:
- X return 0;
- X case 1:
- X return 15;
- X case 2:
- X return 12;
- X case 3:
- X return 10;
- X case 4:
- X return 9;
- X case 5:
- X return 14;
- X case 6:
- X return 11;
- X case 7:
- X return 13;
- X case 8:
- X return 0;
- X case 9:
- X return 15;
- X case 10:
- X return 4;
- X case 11:
- X return 2;
- X case 12:
- X return 1;
- X case 13:
- X return 5;
- X case 14:
- X return 3;
- X case 15:
- X return 6;
- X default:
- X return 1;
- X }
- X }
- X
- /****************************************************************
- X
- X msm_ Microsoft Mouse Routines
- X
- ****************************************************************/
- X
- msm_init()
- X {
- X
- X /* if the video card is hercules, set the appropriate location */
- X
- X if ( ibm_vmode == _HERCMONO )
- X {
- #ifdef OLD_DEBUG
- X fprintf( stderr, "Hercules graphics mouse implementation.\n" );
- X getchar();
- #endif
- X hgc_location = (char far *) 0x00400049;
- X *hgc_location = 6; /* use 5 for HGC CRT page 1 */
- X }
- X
- X /* check if the mouse driver exists first */
- X
- X ibm_registers.x.ax = 0x3533; /* look at the interrupt 33 address */
- X
- X int86x( 0x21, &ibm_registers, &ibm_registers, &segreg);
- X miaddr = (( (long) segreg.es) << 16) + (long) ibm_registers.x.bx;
- X if ( miaddr == 0 || *(char *) miaddr == 0xcf)
- X {
- X msm_exist = FALSE;
- X return BW_ERROR;
- X }
- X
- X /* and then check for the mouse itself */
- X
- X ibm_registers.x.ax = 0; /* mouse status flag */
- X int86( 0x33, &ibm_registers, &ibm_registers); /* check for the mouse interupt */
- X msm_exist = (ibm_registers.x.ax != 0);
- X msm_buttons = ibm_registers.x.bx;
- X if ( msm_exist == FALSE)
- X {
- #ifdef OLD_DEBUG
- X fprintf( stderr, "Found mouse driver, but no mouse\n" );
- X getchar();
- #endif
- X return BW_ERROR;
- X }
- X
- X /* Set minimum/maximum lines, columns */
- X
- X switch ( ibm_vmode )
- X {
- X case _HERCMONO:
- X msm_bounds( 347, 719 );
- X break;
- X case _HRESBW:
- X msm_bounds( 199, 639 );
- X break;
- X case _ERESCOLOR:
- X msm_bounds( 349, 639 );
- X break;
- X default:
- #ifdef DEBUG
- X fprintf( stderr, "Unknown video mode in mouse initialization <%d>\n", ibm_vmode );
- X getchar();
- #endif
- X break;
- X }
- X
- X return TRUE;
- X
- X }
- X
- msm_bounds( lines, columns )
- X int lines, columns;
- X {
- X
- X ibm_registers.x.ax = 7; /* set min/max horizontal cursor position */
- X ibm_registers.x.cx = 0; /* start at 0 */
- X ibm_registers.x.dx = columns - 1;
- X int86( 0x33, &ibm_registers, &ibm_registers);
- X
- X ibm_registers.x.ax = 8; /* set min/max vertical cursor position */
- X ibm_registers.x.cx = 0; /* start at 0 */
- X ibm_registers.x.dx = lines - 1; /* end at the end */
- X int86( 0x33, &ibm_registers, &ibm_registers);
- X
- X }
- X
- msm_show()
- X {
- #ifdef OLD_DEBUG
- X fprintf( stderr, "+" );
- #endif
- X
- X while( msm_showcounter < 0 )
- X {
- X ibm_registers.x.ax = 1; /* show cursor */
- X int86( 0x33, &ibm_registers, &ibm_registers);
- X ++msm_showcounter;
- X }
- X }
- X
- msm_hide()
- X {
- #ifdef OLD_DEBUG
- X fprintf( stderr, "-" );
- #endif
- X while( msm_showcounter >= 0 )
- X {
- X ibm_registers.x.ax = 2; /* hide cursor */
- X int86( 0x33, &ibm_registers, &ibm_registers);
- X --msm_showcounter;
- X }
- X }
- X
- msm_position( line, column )
- X {
- X ibm_registers.x.ax = 4; /* set mouse cursor position */
- X ibm_registers.x.cx = column;
- X ibm_registers.x.dx = line;
- X int86( 0x33, &ibm_registers, &ibm_registers);
- X }
- X
- msm_read()
- X {
- X register int k; /* current bit/button of mouse */
- X register int event; /* encoded mouse event */
- X int newbut; /* new state of the mouse buttons */
- X int mousecol; /* current mouse column */
- X int mouserow; /* current mouse row */
- X int sstate; /* current shift key status */
- X
- X /* check to see if any mouse buttons are different */
- X
- X ibm_registers.x.ax = 3; /* Get button status and mouse position */
- X int86(0x33, &ibm_registers, &ibm_registers);
- X newbut = ibm_registers.x.bx;
- #ifdef OLDSTUFF
- X mousecol = ibm_registers.x.cx >> 3;
- X mouserow = ibm_registers.x.dx >> 3;
- #else
- X mousecol = ibm_registers.x.cx;
- X mouserow = ibm_registers.x.dx;
- #endif
- X m_col = mousecol;
- X m_row = ( ibm_vc.numypixels - 1 ) - ( mouserow );
- X
- X /* get the shift key status as well */
- X
- X sstate = 0;
- X ibm_registers.h.ah = 2; /* return current shift status */
- X int86( 0x16, &ibm_registers, &ibm_registers);
- X sstate = ibm_registers.h.al;
- X
- X for ( k = 1; k != (1 << msm_buttons); k = k<<1)
- X {
- X
- X /* For each button on the mouse */
- X
- X if ((msm_oldbut&k) != (newbut&k))
- X {
- X
- X /* This button changed, generate an event */
- X
- X msm_oldbut = newbut;
- X return ( TRUE );
- X }
- X }
- X return ( FALSE );
- X }
- X
- X
- X
- SHAR_EOF
- chmod 0644 io/gr/gr_ibmpc.c ||
- echo 'restore of io/gr/gr_ibmpc.c failed'
- Wc_c="`wc -c < 'io/gr/gr_ibmpc.c'`"
- test 34235 -eq "$Wc_c" ||
- echo 'io/gr/gr_ibmpc.c: original size 34235, current size' "$Wc_c"
- rm -f _shar_wnt_.tmp
- fi
- # ============= io/gr/gr_mgr.c ==============
- if test -f 'io/gr/gr_mgr.c' -a X"$1" != X"-c"; then
- echo 'x - skipping io/gr/gr_mgr.c (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting io/gr/gr_mgr.c (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'io/gr/gr_mgr.c' &&
- /****************************************************************
- X
- X gr_mgr.c Implementation of Graphics Interface
- X for Bellcore MGR (tm)
- X
- X Copyright (c) 1991, Ted A. Campbell
- X
- X Bywater Software
- X P. O. Box 4023
- X Duke Station
- X Durham, NC 27706
- X
- X email: tcamp@hercules.acpub.duke.edu
- X
- X Copyright and Permissions Information:
- X
- X All U.S. and international copyrights are claimed by the
- X author. The author grants permission to use this code
- X and software based on it under the following conditions:
- X (a) in general, the code and software based upon it may be
- X used by individuals and by non-profit organizations; (b) it
- X may also be utilized by governmental agencies in any country,
- X with the exception of military agencies; (c) the code and/or
- X software based upon it may not be sold for a profit without
- X an explicit and specific permission from the author, except
- X that a minimal fee may be charged for media on which it is
- X copied, and for copying and handling; (d) the code must be
- X distributed in the form in which it has been released by the
- X author; and (e) the code and software based upon it may not
- X be used for illegal activities.
- X
- ****************************************************************/
- X
- #include "stdio.h"
- #include "bw.h"
- #include "gr.h"
- #include "mgrterm.h" /* for Bellcore MGR (tm) */
- X
- #ifdef __STDC__
- #include "malloc.h"
- #else
- extern char * malloc();
- #endif
- X
- #define X_OFFSET 12
- #define Y_OFFSET 12
- #define MAX_X 640
- #define MAX_Y 450
- X
- #define CHECK_PARAMS TRUE
- X
- #define MGR_BLSIZE 32
- X
- #define MGR_FONT0 10
- #define MGR_FONT1 11
- #define MGR_FONT2 12
- #define MGR_FONT3 13
- #define MGR_FONT4 14
- X
- #define MGR_DRAWMAIN 0 /* mgr primary screen */
- #define MGR_DRAWHIDE 1 /* mgr secondary (hidden) screen */
- #define MGR_DRAWGRID 2 /* mgr grid screen */
- #define MGR_DRAWSTART 6 /* start assignable screens */
- X
- #define TINYFONT /* try to use tiny font */
- X
- int gr_screens = 2;
- int gr_colors = 2;
- int gr_pxsize = 287;
- int gr_pysize = 428;
- int gr_ismouse = TRUE;
- int gr_clipping = FALSE;
- int gr_blitting = TRUE;
- int gr_saving = TRUE;
- X
- static int mgr_wno;
- X
- static int mgr_cltarget;
- static int mgr_border;
- static int mgr_hidden = FALSE;
- static int mgr_curwind = MGR_DRAWMAIN;
- static int mgr_xblocks, mgr_yblocks;
- static int mgr_clx1, mgr_cly1, mgr_clx2, mgr_cly2;
- struct gr_window *mgr_grwind;
- X
- extern tam_imsize();
- X
- /****************************************************************
- X
- X gr_init()
- X
- ****************************************************************/
- X
- gr_init( grwindow, font_path )
- X struct gr_window *grwindow;
- X char *font_path;
- X {
- X register int x, y, i;
- X int target_x, target_y;
- X static xmax, ymax;
- X static char _host[ 32 ];
- X
- X mgr_grwind = grwindow;
- X
- X /* set up MGR system */
- X
- X m_setup( M_FLUSH );
- X m_ttyset();
- X
- X /* get maximum sizes from MGR system */
- X
- X get_param( _host, &xmax, &ymax, &mgr_border );
- X
- X /* calculate target size for window, x axis */
- X
- X if ( ( xmax - ( X_OFFSET * 2) ) < MAX_X )
- X {
- X target_x = xmax - ( X_OFFSET * 2 );
- X }
- X else
- X {
- X target_x = MAX_X;
- X }
- X
- X /* calculate target size for window, y axis */
- X
- X if ( ( ymax - ( Y_OFFSET * 2) ) < MAX_Y )
- X {
- X target_y = ymax - ( Y_OFFSET * 2 );
- X }
- X else
- X {
- X target_y = MAX_Y;
- X }
- X
- X /* get new window for this application */
- X
- X mgr_wno = m_makewindow( X_OFFSET, Y_OFFSET, target_x, target_y );
- X m_selectwin( mgr_wno );
- X mgr_grwind->xmax = target_x - ( ( mgr_border * 2 ) + 1 );
- X mgr_grwind->ymax = target_y - ( ( mgr_border * 2 ) + 1 );
- X
- X /* load fonts */
- X
- X
- X x = m_loadfont( MGR_FONT4, "gal12x20r.fnt" );
- #ifdef OLD_DEBUG
- X fprintf( stderr, "load font %d returned %d \n", MGR_FONT4, x );
- X getchar();
- #endif
- X x = m_loadfont( MGR_FONT3, "cour8x16r.fnt" );
- #ifdef OLD_DEBUG
- X fprintf( stderr, "load font %d returned %d \n", MGR_FONT3, x );
- X getchar();
- #endif
- X x = m_loadfont( MGR_FONT2, "cour7x14r.fnt" );
- #ifdef OLD_DEBUG
- X fprintf( stderr, "load font %d returned %d \n", MGR_FONT2, x );
- X getchar();
- #endif
- X x = m_loadfont( MGR_FONT1, "cour6x12r.fnt" );
- #ifdef OLD_DEBUG
- X fprintf( stderr, "load font %d returned %d \n", MGR_FONT1, x );
- X getchar();
- #endif
- X x = m_loadfont( MGR_FONT0, "tiny4x7r.fnt" );
- #ifdef OLD_DEBUG
- X fprintf( stderr, "load font %d returned %d \n", MGR_FONT0, x );
- X getchar();
- #endif
- X
- X
- X gr_font( GR_PRIMARY, F_DEFAULT, 10 );
- X
- X /* set to absolute window coordinate mode */
- X
- X m_setmode( M_ABS );
- /* m_setmode( M_NOWRAP ); */
- X
- X /* calculate number of blocks necessary for fill patterns */
- X
- X mgr_xblocks = ( ( target_x ) / MGR_BLSIZE ) + 1;
- X mgr_yblocks = ( ( target_y ) / MGR_BLSIZE ) + 1;
- X
- #ifdef OLD_DEBUG
- X fprintf( stderr, "x size = %d, x blocks = %d \n", mgr_grwind->xmax, mgr_xblocks );
- X fprintf( stderr, "y size = %d, y blocks = %d \n", mgr_grwind->ymax, mgr_yblocks );
- X kb_rx();
- #endif
- X
- X /* get scratchpad bitmaps */
- X
- X m_bitcreate( MGR_DRAWGRID, mgr_xblocks * MGR_BLSIZE,
- X mgr_yblocks * MGR_BLSIZE );
- X
- #ifdef USEFILL
- X m_bitcreate( MGR_DRAWFILL, mgr_xblocks * MGR_BLSIZE,
- X mgr_yblocks * MGR_BLSIZE );
- #endif
- X
- X m_bitcreate( MGR_DRAWHIDE, target_x, target_y );
- X
- #ifdef OLD_DEBUG
- X fprintf( stderr, "Bitmaps created. \n" );
- #endif
- X
- X /* signon message */
- X
- X fprintf( stderr, "Implementation of Bywater Graphics (gr) Standard\n" );
- X fprintf( stderr, "for Bellcore MGR (tm). This implementation copyright\n" );
- X fprintf( stderr, "(c) 1990, Ted A. Campbell, Bywater Software \n" );
- X fprintf( stderr, "\nInitializing: " );
- X
- #ifdef USEFILL
- X
- X /* fill first block of fill bitmap with solid pattern */
- X
- #ifdef OLD_DEBUG
- X fprintf( stderr, "Initializing SOLID fill: " );
- #endif
- X m_func( B_SET );
- X for ( y = 0; y < MGR_BLSIZE; ++y )
- X {
- X fprintf( stderr, "." );
- X m_lineto( MGR_DRAWFILL, 0, y, MGR_BLSIZE, y );
- X }
- X
- X /* now replicate the block pattern throughout the fill bitmap */
- X
- #ifdef OLD_DEBUG
- X fprintf( stderr, "\nCopying FILL images: " );
- #endif
- X m_func( B_SRC );
- X for ( y = 0; y < mgr_yblocks; ++y )
- X {
- #ifdef OLD_DEBUG
- X fprintf( stderr, "\nFILL line %d: ", y );
- #endif
- X fprintf( stderr, "." );
- X for ( x = 0; x < mgr_xblocks; ++x )
- X {
- X if ( ( x == 0 ) && ( y == 0 ))
- X {
- X }
- X else
- X {
- X m_bitcopyto( x * MGR_BLSIZE, y * MGR_BLSIZE,
- X MGR_BLSIZE, MGR_BLSIZE,
- X 0, 0, MGR_DRAWFILL, MGR_DRAWFILL );
- X }
- X }
- X }
- X
- #endif /* USEFILL */
- X
- X /* fill grid bitmap with solid pattern */
- X
- #ifdef OLD_DEBUG
- X fprintf( stderr, "\nInitializing GRID fill: " );
- #endif
- X for ( y = 0; y < MGR_BLSIZE; y += 2 )
- X {
- X
- #ifdef OLD_DEBUG
- X fprintf( stderr, "\nLine %d: ", y );
- #endif
- X for ( x = 0; x < MGR_BLSIZE; x += 2 )
- X {
- X fprintf( stderr, "." );
- X m_func( B_SET );
- X m_lineto( MGR_DRAWGRID, x, y, x, y );
- X m_func( B_CLEAR );
- X m_lineto( MGR_DRAWGRID, x + 1, y, x + 1, y );
- X m_func( B_CLEAR );
- X m_lineto( MGR_DRAWGRID, x, y + 1, x, y + 1 );
- X m_func( B_SET );
- X m_lineto( MGR_DRAWGRID, x + 1, y + 1, x + 1, y + 1 );
- X }
- X }
- X
- X /* now replicate the block pattern throughout the fill bitmap */
- X
- #ifdef OLD_DEBUG
- X fprintf( stderr, "\nCopying GRID images: " );
- #endif
- X m_func( B_SRC );
- X for ( y = 0; y < mgr_yblocks; ++y )
- X {
- #ifdef OLD_DEBUG
- X fprintf( stderr, "\nGRID line %d: ", y );
- #else
- X fprintf( stderr, "." );
- #endif
- X for ( x = 0; x < mgr_xblocks; ++x )
- X {
- X if ( ( y == 0 ) && ( x == 0 ))
- X {
- X }
- X else
- X {
- #ifdef OLD_DEBUG
- X fprintf( stderr, "." );
- #endif
- X m_bitcopyto( x * MGR_BLSIZE, y * MGR_BLSIZE,
- X MGR_BLSIZE, MGR_BLSIZE,
- X 0, 0, MGR_DRAWGRID, MGR_DRAWGRID );
- X }
- X }
- X }
- X
- #ifdef OLD_DEBUG
- X fprintf( stderr, "\nGRID bitmap filled. \n" );
- #endif
- X
- X /* turn cursor off */
- X
- X m_setcursor( CS_INVIS );
- X
- X /* move cursor to 0,0 to be safe */
- X
- X m_move( 0, 0 );
- X
- X /* note that system is initailized */
- X
- X mgr_grwind->initialized = TRUE;
- X return TRUE;
- X }
- X
- /****************************************************************
- X
- X gr_deinit()
- X
- ****************************************************************/
- X
- gr_deinit( )
- X {
- X m_bitdestroy( MGR_DRAWGRID );
- X m_bitdestroy( MGR_DRAWHIDE );
- X m_destroywin( mgr_wno );
- X m_ttyreset();
- X }
- X
- /****************************************************************
- X
- X gr_cls()
- X
- ****************************************************************/
- X
- gr_cls( screen )
- X int screen;
- X {
- X gr_rectangle( screen, 0, 0, mgr_grwind->xmax, mgr_grwind->ymax,
- X BLACK, SOLID );
- X }
- X
- X
- /****************************************************************
- X
- X gr_pixel()
- X
- ****************************************************************/
- X
- gr_pixel( screen, x, y, color )
- X int screen;
- X int x, y;
- X int color;
- X {
- X
- #if CHECK_PARAMS
- X if ( ( x < 0 ) || ( x > mgr_grwind->xmax ))
- X {
- X sprintf( bw_ebuf, "[pr:] gr_pixel(): x value is %d", x );
- X bw_error( bw_ebuf );
- X return BW_ERROR;
- X }
- X if ( ( y < 0 ) || ( y > mgr_grwind->ymax ))
- X {
- X sprintf( bw_ebuf, "[pr:] gr_pixel(): y value is %d", y );
- X bw_error( bw_ebuf );
- X return BW_ERROR;
- X }
- #endif
- X
- X mgr_color( color );
- X if ( screen == MGR_DRAWMAIN )
- X {
- X m_line( x, mgr_y( y ), x, mgr_y( y ) );
- X }
- X else
- X {
- X m_lineto( screen, x, mgr_y( y ), x, mgr_y( y ) );
- SHAR_EOF
- true || echo 'restore of io/gr/gr_mgr.c failed'
- fi
- echo 'End of part 2'
- echo 'File io/gr/gr_mgr.c is continued in part 3'
- echo 3 > _shar_seq_.tmp
- exit 0
- exit 0 # Just in case...
- --
- Kent Landfield INTERNET: kent@sparky.IMD.Sterling.COM
- Sterling Software, IMD UUCP: uunet!sparky!kent
- Phone: (402) 291-8300 FAX: (402) 291-4362
- Please send comp.sources.misc-related mail to kent@uunet.uu.net.
-