home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware 1 2 the Maxx
/
sw_1.zip
/
sw_1
/
PROGRAM
/
CBGRX100.ZIP
/
CONTRIB
/
LIBGRX
/
SRC
/
SETMODE.C
< prev
next >
Wrap
Text File
|
1992-04-10
|
6KB
|
215 lines
/**
** SETMODE.C
**
** Copyright (C) 1992, Csaba Biegl
** 820 Stirrup Dr, Nashville, TN, 37221
** csaba@vuse.vanderbilt.edu
**
** This file is distributed under the terms listed in the document
** "copying.cb", available from the author at the address above.
** A copy of "copying.cb" should accompany this file; if not, a copy
** should be available from where this file was obtained. This file
** may not be distributed without a verbatim copy of "copying.cb".
** You should also have received a copy of the GNU General Public
** License along with this program (it is in the file "copying");
** if not, write to the Free Software Foundation, Inc., 675 Mass Ave,
** Cambridge, MA 02139, USA.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**/
#define _SETMODE_C_
#include "grx.h"
#include "libgrx.h"
#include "grdriver.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
GrContext _GrContext; /* current graphics context */
GrContext _GrVidPage; /* the whole screen */
int _GrCurrentMode = GR_default_text; /* current video mode */
int _GrCanBcopyInBlit = FALSE; /* separate R/W pages in adapter */
int _GrBigFrameBuffer = FALSE; /* set if frame buffer > 64K */
int _GrNumColors = 256; /* number of colors */
int _GrAdapterType = GR_VGA; /* type of video adapter */
int _GrDriverIndex = 0; /* low-level video routine selector */
int _GrRdOnlyOffset = 0; /* add for read-only video page */
int _GrWrOnlyOffset = 0; /* add for write-only video page */
int _GrScreenX = 80; /* screen width */
int _GrScreenY = 25; /* screen height */
char _GrMouseDrawn = 0; /* set if mouse drawn */
char _GrMouseCheck = 0; /* set if mouse blocking needed */
static void dummy(void) {}
int (*_GrMouseBlock)(GrContext *c,int x1,int y1,int x2,int y2);
void (*_GrMouseUnBlock)(void);
void (*_GrMouseUnInit)(void) = dummy;
static void (*setmodehook)(void) = NULL;
#ifndef _SINGLE_MODE_
handler _GrResetValues[NumOfHandlers] = { NULL };
handler *_GrResetAddresses[NumOfHandlers] = { NULL };
#endif
void GrSetMode(int mode,int width,int height,int colors)
{
long planesize;
int flags;
(*_GrMouseUnInit)();
#ifndef _SINGLE_MODE_
for(flags = 0; flags < NumOfHandlers; flags++) {
if(_GrResetValues[flags] == NULL) continue;
*(_GrResetAddresses[flags]) = _GrResetValues[flags];
}
#endif
if((mode >= GR_80_25_text) && (mode <= GR_width_height_color_graphics)) {
memset(&_GrVidPage,0,sizeof(GrContext));
flags = _GrLowSetMode(mode,width,height,colors);
_GrCurrentMode = mode;
switch(flags & GRD_TYPE_MASK) {
case GRD_VGA:
_GrVidPage.gc_baseaddr = (char far *)VGA_FRAME;
_GrAdapterType = GR_VGA;
break;
case GRD_EGA:
_GrVidPage.gc_baseaddr = (char far *)EGA_FRAME;
_GrAdapterType = GR_EGA;
break;
case GRD_HERC:
_GrVidPage.gc_baseaddr = (char far *)HERC_FRAME;
_GrAdapterType = GR_HERC;
break;
default:
_GrLowSetMode(GR_default_text,0,0,0);
fputs("GrSetMode: unknown adapter type in driver\n",stderr);
exit(1);
}
switch(flags & GRD_PLANE_MASK) {
#if (GRXPLANES & 8)
case GRD_8_PLANES:
if(_GrAdapterType != GR_VGA) goto Default;
_GrDriverIndex = VGA256_DRIVER;
_GrNumColors = 256;
break;
#endif
#if (GRXPLANES & 4)
case GRD_4_PLANES:
if(_GrAdapterType == GR_HERC) goto Default;
_GrDriverIndex = VGA16_DRIVER;
_GrNumColors = 16;
break;
#endif
#if (GRXPLANES & 1)
case GRD_1_PLANE:
if(_GrAdapterType != GR_HERC) goto Default;
_GrDriverIndex = HERC_DRIVER;
_GrNumColors = 2;
break;
#endif
default:
Default:
_GrLowSetMode(GR_default_text,0,0,0);
fputs("GrSetMode: bad color plane # in driver\n",stderr);
exit(1);
}
if(mode >= GR_320_200_graphics) {
planesize = GrPlaneSize(_GrScreenX,_GrScreenY);
#ifdef _MAXVIDPLANESIZE
if(planesize > _MAXVIDPLANESIZE) {
_GrLowSetMode(GR_default_text,0,0,0);
fputs("GrSetMode: graphics mode too big\n",stderr);
exit(1);
}
#endif
if(planesize < 0x10000L) {
_GrCanBcopyInBlit = TRUE;
_GrBigFrameBuffer = FALSE;
_GrRdOnlyOffset = 0;
_GrWrOnlyOffset = 0;
}
else if((flags & GRD_PAGING_MASK) == GRD_RW_64K) {
_GrCanBcopyInBlit = TRUE;
_GrBigFrameBuffer = TRUE;
_GrRdOnlyOffset = RDONLY_OFF;
_GrWrOnlyOffset = WRONLY_OFF;
}
else {
_GrCanBcopyInBlit = FALSE;
_GrBigFrameBuffer = TRUE;
_GrRdOnlyOffset = 0;
_GrWrOnlyOffset = 0;
}
_GrVidPage.gc_onscreen = TRUE;
_GrVidPage.gc_frameaddr = BASE_ADDRESS(&_GrVidPage);
_GrVidPage.gc_lineoffset = GrLineOffset(_GrScreenX);
_GrVidPage.gc_xmax = _GrVidPage.gc_xcliphi = _GrScreenX - 1;
_GrVidPage.gc_ymax = _GrVidPage.gc_ycliphi = _GrScreenY - 1;
_GrContext = _GrVidPage;
if(_GrNumColors == 16) _GrP4Init(flags & GRD_MEM_MASK);
GrRefreshColors();
_GrMouseDrawn = 0;
_GrMouseCheck = 0;
}
if(setmodehook != NULL) (*setmodehook)();
}
}
void GrSetModeHook(void (*hookfunc)(void))
{
setmodehook = hookfunc;
}
int GrCurrentMode(void)
{
return(_GrCurrentMode);
}
int GrAdapterType(void)
{
return(_GrAdapterType);
}
int GrScreenX(void)
{
return(_GrScreenX);
}
int GrScreenY(void)
{
return(_GrScreenY);
}
int GrSizeX(void)
{
return(_GrContext.gc_xmax + 1);
}
int GrSizeY(void)
{
return(_GrContext.gc_ymax + 1);
}
int GrMaxX(void)
{
return(_GrContext.gc_xmax);
}
int GrMaxY(void)
{
return(_GrContext.gc_ymax);
}