-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathINITGRAP.C
137 lines (126 loc) · 2.96 KB
/
INITGRAP.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/* START GRAPHIX MODULE */
#include <graphics.h> /* MODUL ZALEZNY OD BIBLIOTEKI GRAFICZNEJ - NIEPRZENOSNY */
#include <dos.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
#include "pipek.hpp"
int gdriver = DETECT; /* GRAPHICS DRIVER NUMBER & MODE NUMBER */
int gmode=0,mx=0,my=0,sx=0,sy=0,maxcol=0; /* SCREEN PARAMETERS */
int ingraph=0;/* znacznik przebywania w trybie graficznym */
int FORCE_GRAY=0;/* znacznik monitora szarego */
char *cards[]={"None","MDA mono","CGA color",
"3-reserved","EGA color","EGA mono",
"PGC","VGA mono","VGA color",
"9-reserved"};
int GrayMonitor()
{
unsigned char test;
//return 1;
_AH=0x1A;
_AL=0x0;
geninterrupt(0x10);
test=_AL;
if( test==0x1A )
return (_BL==7);
else
return 0;
return 0;
}
void grexit(void)
{
closegraph();
printf("\n BGI Graphics shut down");
}
void GrayCorection()
{
_BX=0;
_CX=256;
_AL=0x1B;// korekcja szarosci
_AH=0x10;// funkcja 10H "kolory i atrybuty"
geninterrupt(0x10);
}
int huge mydetect()
{
return gmode;
}
int StartGraphix()
{
int errorcode=0;
FILE* config=NULL;
char startup[128];
char iobuf[256];
char* ptr=NULL;
/* Check startup directory */
strcpy(startup,_argv[0]);
if( (ptr=strrchr(startup,'\\'))!=NULL)
startup[(ptr-startup)]='\0';
else
*startup='\0';
/* Check Config.scr */
strcpy(iobuf,startup);
strcat(iobuf,"\\config.scr");
if((config=fopen(iobuf,"r"))!=NULL)
{
/* init graph in user driver & mode */
fscanf(config,"%s\n",iobuf);
fscanf(config,"%d",&gmode);
fscanf(config,"%d%d%d",&maxcol,&mx,&my);
gdriver=installuserdriver(iobuf,mydetect);
if((errorcode = graphresult()) !=grOk) goto ON_ERROR;
printf("If not in graph.mode press Q !\n");
initgraph(&gdriver, &gmode,startup);
if((errorcode = graphresult()) !=grOk) goto ON_ERROR;
if(mx==0) mx=getmaxx();
if(my==0) my=getmaxy();
if(maxcol<0)
{ maxcol=-maxcol;FORCE_GRAY=1;}
if(maxcol==0) maxcol=getmaxcolor();
}
else
{
/* init graph in detected mode */
printf("If not in graph.mode press Q !\n");
initgraph(&gdriver, &gmode,startup);
if((errorcode = graphresult()) !=grOk) goto ON_ERROR;
*iobuf='\0';
mx=getmaxx();
my=getmaxy();
maxcol=getmaxcolor();
}
/* If Sukces */
atexit(grexit);
if(FORCE_GRAY==0)
FORCE_GRAY=GrayMonitor();
if(FORCE_GRAY)
GrayCorection();/* Konwersja kolorow */
Interface::MouseToVideo(mx,my);/* Inicjacje pakietu obslugi myszy */
/* Usable parameters */
sx=mx/2;
sy=my/2;
ingraph=1;
return 0;/* OK */
ON_ERROR:
if (errorcode != grOk) /* an error occurred */
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1); /* return with error code */
}
}
void RestoreCrtMode()
{
ingraph=0;
restorecrtmode();
}
void SetGraphMode(int M)
{
setgraphmode(M);
if(graphresult() ==grOk)
{
ingraph=1;
if(FORCE_GRAY) GrayCorection();/* Konwersja kolorow */
}
}